]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.11.6-201310260850.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.11.6-201310260850.patch
CommitLineData
96b095d6
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/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
44041index 331987d..3be1135 100644
44042--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
44043+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
44044@@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
44045 }
44046
44047 /* update the base incval used to calculate frequency adjustment */
44048- ACCESS_ONCE(adapter->base_incval) = incval;
44049+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
44050 smp_mb();
44051
44052 /* need lock to prevent incorrect read while modifying cyclecounter */
44053diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
44054index fbe5363..266b4e3 100644
44055--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
44056+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
44057@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
44058 struct __vxge_hw_fifo *fifo;
44059 struct vxge_hw_fifo_config *config;
44060 u32 txdl_size, txdl_per_memblock;
44061- struct vxge_hw_mempool_cbs fifo_mp_callback;
44062+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
44063+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
44064+ };
44065+
44066 struct __vxge_hw_virtualpath *vpath;
44067
44068 if ((vp == NULL) || (attr == NULL)) {
44069@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
44070 goto exit;
44071 }
44072
44073- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
44074-
44075 fifo->mempool =
44076 __vxge_hw_mempool_create(vpath->hldev,
44077 fifo->config->memblock_size,
44078diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
44079index 345d987..af69721 100644
44080--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
44081+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
44082@@ -2011,7 +2011,9 @@ int qlcnic_83xx_config_default_opmode(struct qlcnic_adapter *adapter)
44083 op_mode = QLC_83XX_DEFAULT_OPMODE;
44084
44085 if (op_mode == QLC_83XX_DEFAULT_OPMODE) {
44086- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
44087+ pax_open_kernel();
44088+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
44089+ pax_close_kernel();
44090 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
44091 } else {
44092 return -EIO;
44093diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
44094index 599d1fd..59868fe 100644
44095--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
44096+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
44097@@ -191,17 +191,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
44098 case QLCNIC_NON_PRIV_FUNC:
44099 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
44100 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
44101- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
44102+ pax_open_kernel();
44103+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
44104+ pax_close_kernel();
44105 break;
44106 case QLCNIC_PRIV_FUNC:
44107 ahw->op_mode = QLCNIC_PRIV_FUNC;
44108 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
44109- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
44110+ pax_open_kernel();
44111+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
44112+ pax_close_kernel();
44113 break;
44114 case QLCNIC_MGMT_FUNC:
44115 ahw->op_mode = QLCNIC_MGMT_FUNC;
44116 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
44117- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
44118+ pax_open_kernel();
44119+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
44120+ pax_close_kernel();
44121 break;
44122 default:
44123 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
44124diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
44125index 7ba68e0..618c73d 100644
44126--- a/drivers/net/ethernet/realtek/r8169.c
44127+++ b/drivers/net/ethernet/realtek/r8169.c
44128@@ -759,22 +759,22 @@ struct rtl8169_private {
44129 struct mdio_ops {
44130 void (*write)(struct rtl8169_private *, int, int);
44131 int (*read)(struct rtl8169_private *, int);
44132- } mdio_ops;
44133+ } __no_const mdio_ops;
44134
44135 struct pll_power_ops {
44136 void (*down)(struct rtl8169_private *);
44137 void (*up)(struct rtl8169_private *);
44138- } pll_power_ops;
44139+ } __no_const pll_power_ops;
44140
44141 struct jumbo_ops {
44142 void (*enable)(struct rtl8169_private *);
44143 void (*disable)(struct rtl8169_private *);
44144- } jumbo_ops;
44145+ } __no_const jumbo_ops;
44146
44147 struct csi_ops {
44148 void (*write)(struct rtl8169_private *, int, int);
44149 u32 (*read)(struct rtl8169_private *, int);
44150- } csi_ops;
44151+ } __no_const csi_ops;
44152
44153 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
44154 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
44155diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
44156index b495394..0748c54 100644
44157--- a/drivers/net/ethernet/sfc/ptp.c
44158+++ b/drivers/net/ethernet/sfc/ptp.c
44159@@ -535,7 +535,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
44160 (u32)((u64)ptp->start.dma_addr >> 32));
44161
44162 /* Clear flag that signals MC ready */
44163- ACCESS_ONCE(*start) = 0;
44164+ ACCESS_ONCE_RW(*start) = 0;
44165 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
44166 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
44167
44168diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
44169index 50617c5..b13724c 100644
44170--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
44171+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
44172@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
44173
44174 writel(value, ioaddr + MMC_CNTRL);
44175
44176- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
44177- MMC_CNTRL, value);
44178+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
44179+// MMC_CNTRL, value);
44180 }
44181
44182 /* To mask all all interrupts.*/
44183diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
44184index e6fe0d8..2b7d752 100644
44185--- a/drivers/net/hyperv/hyperv_net.h
44186+++ b/drivers/net/hyperv/hyperv_net.h
44187@@ -101,7 +101,7 @@ struct rndis_device {
44188
44189 enum rndis_device_state state;
44190 bool link_state;
44191- atomic_t new_req_id;
44192+ atomic_unchecked_t new_req_id;
44193
44194 spinlock_t request_lock;
44195 struct list_head req_list;
44196diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
44197index 0775f0a..d4fb316 100644
44198--- a/drivers/net/hyperv/rndis_filter.c
44199+++ b/drivers/net/hyperv/rndis_filter.c
44200@@ -104,7 +104,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
44201 * template
44202 */
44203 set = &rndis_msg->msg.set_req;
44204- set->req_id = atomic_inc_return(&dev->new_req_id);
44205+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
44206
44207 /* Add to the request list */
44208 spin_lock_irqsave(&dev->request_lock, flags);
44209@@ -752,7 +752,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
44210
44211 /* Setup the rndis set */
44212 halt = &request->request_msg.msg.halt_req;
44213- halt->req_id = atomic_inc_return(&dev->new_req_id);
44214+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
44215
44216 /* Ignore return since this msg is optional. */
44217 rndis_filter_send_request(dev, request);
44218diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
44219index bf0d55e..82bcfbd1 100644
44220--- a/drivers/net/ieee802154/fakehard.c
44221+++ b/drivers/net/ieee802154/fakehard.c
44222@@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
44223 phy->transmit_power = 0xbf;
44224
44225 dev->netdev_ops = &fake_ops;
44226- dev->ml_priv = &fake_mlme;
44227+ dev->ml_priv = (void *)&fake_mlme;
44228
44229 priv = netdev_priv(dev);
44230 priv->phy = phy;
44231diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
44232index 16b43bf..ead0c35 100644
44233--- a/drivers/net/macvlan.c
44234+++ b/drivers/net/macvlan.c
44235@@ -934,13 +934,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
44236 int macvlan_link_register(struct rtnl_link_ops *ops)
44237 {
44238 /* common fields */
44239- ops->priv_size = sizeof(struct macvlan_dev);
44240- ops->validate = macvlan_validate;
44241- ops->maxtype = IFLA_MACVLAN_MAX;
44242- ops->policy = macvlan_policy;
44243- ops->changelink = macvlan_changelink;
44244- ops->get_size = macvlan_get_size;
44245- ops->fill_info = macvlan_fill_info;
44246+ pax_open_kernel();
44247+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
44248+ *(void **)&ops->validate = macvlan_validate;
44249+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
44250+ *(const void **)&ops->policy = macvlan_policy;
44251+ *(void **)&ops->changelink = macvlan_changelink;
44252+ *(void **)&ops->get_size = macvlan_get_size;
44253+ *(void **)&ops->fill_info = macvlan_fill_info;
44254+ pax_close_kernel();
44255
44256 return rtnl_link_register(ops);
44257 };
44258@@ -996,7 +998,7 @@ static int macvlan_device_event(struct notifier_block *unused,
44259 return NOTIFY_DONE;
44260 }
44261
44262-static struct notifier_block macvlan_notifier_block __read_mostly = {
44263+static struct notifier_block macvlan_notifier_block = {
44264 .notifier_call = macvlan_device_event,
44265 };
44266
44267diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
44268index ea53abb..2e4d087 100644
44269--- a/drivers/net/macvtap.c
44270+++ b/drivers/net/macvtap.c
44271@@ -1286,7 +1286,7 @@ static int macvtap_device_event(struct notifier_block *unused,
44272 return NOTIFY_DONE;
44273 }
44274
44275-static struct notifier_block macvtap_notifier_block __read_mostly = {
44276+static struct notifier_block macvtap_notifier_block = {
44277 .notifier_call = macvtap_device_event,
44278 };
44279
44280diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
44281index daec9b0..6428fcb 100644
44282--- a/drivers/net/phy/mdio-bitbang.c
44283+++ b/drivers/net/phy/mdio-bitbang.c
44284@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
44285 struct mdiobb_ctrl *ctrl = bus->priv;
44286
44287 module_put(ctrl->ops->owner);
44288+ mdiobus_unregister(bus);
44289 mdiobus_free(bus);
44290 }
44291 EXPORT_SYMBOL(free_mdio_bitbang);
44292diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
44293index 72ff14b..11d442d 100644
44294--- a/drivers/net/ppp/ppp_generic.c
44295+++ b/drivers/net/ppp/ppp_generic.c
44296@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44297 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
44298 struct ppp_stats stats;
44299 struct ppp_comp_stats cstats;
44300- char *vers;
44301
44302 switch (cmd) {
44303 case SIOCGPPPSTATS:
44304@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44305 break;
44306
44307 case SIOCGPPPVER:
44308- vers = PPP_VERSION;
44309- if (copy_to_user(addr, vers, strlen(vers) + 1))
44310+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
44311 break;
44312 err = 0;
44313 break;
44314diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
44315index 1252d9c..80e660b 100644
44316--- a/drivers/net/slip/slhc.c
44317+++ b/drivers/net/slip/slhc.c
44318@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
44319 register struct tcphdr *thp;
44320 register struct iphdr *ip;
44321 register struct cstate *cs;
44322- int len, hdrlen;
44323+ long len, hdrlen;
44324 unsigned char *cp = icp;
44325
44326 /* We've got a compressed packet; read the change byte */
44327diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
44328index bff7e0b..7315137 100644
44329--- a/drivers/net/team/team.c
44330+++ b/drivers/net/team/team.c
44331@@ -2702,7 +2702,7 @@ static int team_device_event(struct notifier_block *unused,
44332 return NOTIFY_DONE;
44333 }
44334
44335-static struct notifier_block team_notifier_block __read_mostly = {
44336+static struct notifier_block team_notifier_block = {
44337 .notifier_call = team_device_event,
44338 };
44339
44340diff --git a/drivers/net/tun.c b/drivers/net/tun.c
44341index 68b9aa3..b3c20f3 100644
44342--- a/drivers/net/tun.c
44343+++ b/drivers/net/tun.c
44344@@ -1874,7 +1874,7 @@ unlock:
44345 }
44346
44347 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
44348- unsigned long arg, int ifreq_len)
44349+ unsigned long arg, size_t ifreq_len)
44350 {
44351 struct tun_file *tfile = file->private_data;
44352 struct tun_struct *tun;
44353@@ -1886,6 +1886,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
44354 int vnet_hdr_sz;
44355 int ret;
44356
44357+ if (ifreq_len > sizeof ifr)
44358+ return -EFAULT;
44359+
44360 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
44361 if (copy_from_user(&ifr, argp, ifreq_len))
44362 return -EFAULT;
44363diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
44364index 86292e6..8d34433 100644
44365--- a/drivers/net/usb/hso.c
44366+++ b/drivers/net/usb/hso.c
44367@@ -71,7 +71,7 @@
44368 #include <asm/byteorder.h>
44369 #include <linux/serial_core.h>
44370 #include <linux/serial.h>
44371-
44372+#include <asm/local.h>
44373
44374 #define MOD_AUTHOR "Option Wireless"
44375 #define MOD_DESCRIPTION "USB High Speed Option driver"
44376@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
44377 struct urb *urb;
44378
44379 urb = serial->rx_urb[0];
44380- if (serial->port.count > 0) {
44381+ if (atomic_read(&serial->port.count) > 0) {
44382 count = put_rxbuf_data(urb, serial);
44383 if (count == -1)
44384 return;
44385@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
44386 DUMP1(urb->transfer_buffer, urb->actual_length);
44387
44388 /* Anyone listening? */
44389- if (serial->port.count == 0)
44390+ if (atomic_read(&serial->port.count) == 0)
44391 return;
44392
44393 if (status == 0) {
44394@@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
44395 tty_port_tty_set(&serial->port, tty);
44396
44397 /* check for port already opened, if not set the termios */
44398- serial->port.count++;
44399- if (serial->port.count == 1) {
44400+ if (atomic_inc_return(&serial->port.count) == 1) {
44401 serial->rx_state = RX_IDLE;
44402 /* Force default termio settings */
44403 _hso_serial_set_termios(tty, NULL);
44404@@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
44405 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
44406 if (result) {
44407 hso_stop_serial_device(serial->parent);
44408- serial->port.count--;
44409+ atomic_dec(&serial->port.count);
44410 kref_put(&serial->parent->ref, hso_serial_ref_free);
44411 }
44412 } else {
44413@@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
44414
44415 /* reset the rts and dtr */
44416 /* do the actual close */
44417- serial->port.count--;
44418+ atomic_dec(&serial->port.count);
44419
44420- if (serial->port.count <= 0) {
44421- serial->port.count = 0;
44422+ if (atomic_read(&serial->port.count) <= 0) {
44423+ atomic_set(&serial->port.count, 0);
44424 tty_port_tty_set(&serial->port, NULL);
44425 if (!usb_gone)
44426 hso_stop_serial_device(serial->parent);
44427@@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
44428
44429 /* the actual setup */
44430 spin_lock_irqsave(&serial->serial_lock, flags);
44431- if (serial->port.count)
44432+ if (atomic_read(&serial->port.count))
44433 _hso_serial_set_termios(tty, old);
44434 else
44435 tty->termios = *old;
44436@@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
44437 D1("Pending read interrupt on port %d\n", i);
44438 spin_lock(&serial->serial_lock);
44439 if (serial->rx_state == RX_IDLE &&
44440- serial->port.count > 0) {
44441+ atomic_read(&serial->port.count) > 0) {
44442 /* Setup and send a ctrl req read on
44443 * port i */
44444 if (!serial->rx_urb_filled[0]) {
44445@@ -3062,7 +3061,7 @@ static int hso_resume(struct usb_interface *iface)
44446 /* Start all serial ports */
44447 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
44448 if (serial_table[i] && (serial_table[i]->interface == iface)) {
44449- if (dev2ser(serial_table[i])->port.count) {
44450+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
44451 result =
44452 hso_start_serial_device(serial_table[i], GFP_NOIO);
44453 hso_kick_transmit(dev2ser(serial_table[i]));
44454diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
44455index a79e9d3..78cd4fa 100644
44456--- a/drivers/net/usb/sierra_net.c
44457+++ b/drivers/net/usb/sierra_net.c
44458@@ -52,7 +52,7 @@ static const char driver_name[] = "sierra_net";
44459 /* atomic counter partially included in MAC address to make sure 2 devices
44460 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
44461 */
44462-static atomic_t iface_counter = ATOMIC_INIT(0);
44463+static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
44464
44465 /*
44466 * SYNC Timer Delay definition used to set the expiry time
44467@@ -698,7 +698,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
44468 dev->net->netdev_ops = &sierra_net_device_ops;
44469
44470 /* change MAC addr to include, ifacenum, and to be unique */
44471- dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
44472+ dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
44473 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
44474
44475 /* we will have to manufacture ethernet headers, prepare template */
44476diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
44477index 8a05d77..ba8b9c5 100644
44478--- a/drivers/net/vxlan.c
44479+++ b/drivers/net/vxlan.c
44480@@ -1870,7 +1870,7 @@ nla_put_failure:
44481 return -EMSGSIZE;
44482 }
44483
44484-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
44485+static struct rtnl_link_ops vxlan_link_ops = {
44486 .kind = "vxlan",
44487 .maxtype = IFLA_VXLAN_MAX,
44488 .policy = vxlan_policy,
44489diff --git a/drivers/net/wan/farsync.c b/drivers/net/wan/farsync.c
44490index 3f0c4f2..bcfff0d 100644
44491--- a/drivers/net/wan/farsync.c
44492+++ b/drivers/net/wan/farsync.c
44493@@ -1972,6 +1972,7 @@ fst_get_iface(struct fst_card_info *card, struct fst_port_info *port,
44494 }
44495
44496 i = port->index;
44497+ memset(&sync, 0, sizeof(sync));
44498 sync.clock_rate = FST_RDL(card, portConfig[i].lineSpeed);
44499 /* Lucky card and linux use same encoding here */
44500 sync.clock_type = FST_RDB(card, portConfig[i].internalClock) ==
44501diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
44502index 0b60295..b8bfa5b 100644
44503--- a/drivers/net/wimax/i2400m/rx.c
44504+++ b/drivers/net/wimax/i2400m/rx.c
44505@@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
44506 if (i2400m->rx_roq == NULL)
44507 goto error_roq_alloc;
44508
44509- rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
44510+ rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
44511 GFP_KERNEL);
44512 if (rd == NULL) {
44513 result = -ENOMEM;
44514diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
44515index 34c8a33..3261fdc 100644
44516--- a/drivers/net/wireless/at76c50x-usb.c
44517+++ b/drivers/net/wireless/at76c50x-usb.c
44518@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
44519 }
44520
44521 /* Convert timeout from the DFU status to jiffies */
44522-static inline unsigned long at76_get_timeout(struct dfu_status *s)
44523+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
44524 {
44525 return msecs_to_jiffies((s->poll_timeout[2] << 16)
44526 | (s->poll_timeout[1] << 8)
44527diff --git a/drivers/net/wireless/ath/ath10k/core.c b/drivers/net/wireless/ath/ath10k/core.c
44528index 2b3426b..1f564be 100644
44529--- a/drivers/net/wireless/ath/ath10k/core.c
44530+++ b/drivers/net/wireless/ath/ath10k/core.c
44531@@ -507,7 +507,9 @@ EXPORT_SYMBOL(ath10k_core_destroy);
44532
44533 int ath10k_core_register(struct ath10k *ar)
44534 {
44535- struct ath10k_htc_ops htc_ops;
44536+ static struct ath10k_htc_ops htc_ops = {
44537+ .target_send_suspend_complete = ath10k_send_suspend_complete,
44538+ };
44539 struct bmi_target_info target_info;
44540 int status;
44541
44542@@ -536,8 +538,6 @@ int ath10k_core_register(struct ath10k *ar)
44543 if (status)
44544 goto err;
44545
44546- htc_ops.target_send_suspend_complete = ath10k_send_suspend_complete;
44547-
44548 ar->htc = ath10k_htc_create(ar, &htc_ops);
44549 if (IS_ERR(ar->htc)) {
44550 status = PTR_ERR(ar->htc);
44551diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
44552index 74363c9..237b926 100644
44553--- a/drivers/net/wireless/ath/ath10k/htc.c
44554+++ b/drivers/net/wireless/ath/ath10k/htc.c
44555@@ -963,7 +963,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
44556 struct ath10k_htc *ath10k_htc_create(struct ath10k *ar,
44557 struct ath10k_htc_ops *htc_ops)
44558 {
44559- struct ath10k_hif_cb htc_callbacks;
44560+ static struct ath10k_hif_cb htc_callbacks = {
44561+ .rx_completion = ath10k_htc_rx_completion_handler,
44562+ .tx_completion = ath10k_htc_tx_completion_handler,
44563+ };
44564 struct ath10k_htc_ep *ep = NULL;
44565 struct ath10k_htc *htc = NULL;
44566
44567@@ -979,8 +982,6 @@ struct ath10k_htc *ath10k_htc_create(struct ath10k *ar,
44568 ath10k_htc_reset_endpoint_states(htc);
44569
44570 /* setup HIF layer callbacks */
44571- htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
44572- htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
44573 htc->ar = ar;
44574
44575 /* Get HIF default pipe for HTC message exchange */
44576diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44577index 8d78253..bebbb68 100644
44578--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44579+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44580@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44581 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
44582 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
44583
44584- ACCESS_ONCE(ads->ds_link) = i->link;
44585- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
44586+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
44587+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
44588
44589 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
44590 ctl6 = SM(i->keytype, AR_EncrType);
44591@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44592
44593 if ((i->is_first || i->is_last) &&
44594 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
44595- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
44596+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
44597 | set11nTries(i->rates, 1)
44598 | set11nTries(i->rates, 2)
44599 | set11nTries(i->rates, 3)
44600 | (i->dur_update ? AR_DurUpdateEna : 0)
44601 | SM(0, AR_BurstDur);
44602
44603- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
44604+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
44605 | set11nRate(i->rates, 1)
44606 | set11nRate(i->rates, 2)
44607 | set11nRate(i->rates, 3);
44608 } else {
44609- ACCESS_ONCE(ads->ds_ctl2) = 0;
44610- ACCESS_ONCE(ads->ds_ctl3) = 0;
44611+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
44612+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
44613 }
44614
44615 if (!i->is_first) {
44616- ACCESS_ONCE(ads->ds_ctl0) = 0;
44617- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
44618- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
44619+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
44620+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
44621+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
44622 return;
44623 }
44624
44625@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44626 break;
44627 }
44628
44629- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
44630+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
44631 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
44632 | SM(i->txpower, AR_XmitPower)
44633 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
44634@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44635 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
44636 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
44637
44638- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
44639- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
44640+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
44641+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
44642
44643 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
44644 return;
44645
44646- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
44647+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
44648 | set11nPktDurRTSCTS(i->rates, 1);
44649
44650- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
44651+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
44652 | set11nPktDurRTSCTS(i->rates, 3);
44653
44654- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
44655+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
44656 | set11nRateFlags(i->rates, 1)
44657 | set11nRateFlags(i->rates, 2)
44658 | set11nRateFlags(i->rates, 3)
44659diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
44660index 5163abd..3ada4c2 100644
44661--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
44662+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
44663@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44664 (i->qcu << AR_TxQcuNum_S) | desc_len;
44665
44666 checksum += val;
44667- ACCESS_ONCE(ads->info) = val;
44668+ ACCESS_ONCE_RW(ads->info) = val;
44669
44670 checksum += i->link;
44671- ACCESS_ONCE(ads->link) = i->link;
44672+ ACCESS_ONCE_RW(ads->link) = i->link;
44673
44674 checksum += i->buf_addr[0];
44675- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
44676+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
44677 checksum += i->buf_addr[1];
44678- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
44679+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
44680 checksum += i->buf_addr[2];
44681- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
44682+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
44683 checksum += i->buf_addr[3];
44684- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
44685+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
44686
44687 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
44688- ACCESS_ONCE(ads->ctl3) = val;
44689+ ACCESS_ONCE_RW(ads->ctl3) = val;
44690 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
44691- ACCESS_ONCE(ads->ctl5) = val;
44692+ ACCESS_ONCE_RW(ads->ctl5) = val;
44693 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
44694- ACCESS_ONCE(ads->ctl7) = val;
44695+ ACCESS_ONCE_RW(ads->ctl7) = val;
44696 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
44697- ACCESS_ONCE(ads->ctl9) = val;
44698+ ACCESS_ONCE_RW(ads->ctl9) = val;
44699
44700 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
44701- ACCESS_ONCE(ads->ctl10) = checksum;
44702+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
44703
44704 if (i->is_first || i->is_last) {
44705- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
44706+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
44707 | set11nTries(i->rates, 1)
44708 | set11nTries(i->rates, 2)
44709 | set11nTries(i->rates, 3)
44710 | (i->dur_update ? AR_DurUpdateEna : 0)
44711 | SM(0, AR_BurstDur);
44712
44713- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
44714+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
44715 | set11nRate(i->rates, 1)
44716 | set11nRate(i->rates, 2)
44717 | set11nRate(i->rates, 3);
44718 } else {
44719- ACCESS_ONCE(ads->ctl13) = 0;
44720- ACCESS_ONCE(ads->ctl14) = 0;
44721+ ACCESS_ONCE_RW(ads->ctl13) = 0;
44722+ ACCESS_ONCE_RW(ads->ctl14) = 0;
44723 }
44724
44725 ads->ctl20 = 0;
44726@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44727
44728 ctl17 = SM(i->keytype, AR_EncrType);
44729 if (!i->is_first) {
44730- ACCESS_ONCE(ads->ctl11) = 0;
44731- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
44732- ACCESS_ONCE(ads->ctl15) = 0;
44733- ACCESS_ONCE(ads->ctl16) = 0;
44734- ACCESS_ONCE(ads->ctl17) = ctl17;
44735- ACCESS_ONCE(ads->ctl18) = 0;
44736- ACCESS_ONCE(ads->ctl19) = 0;
44737+ ACCESS_ONCE_RW(ads->ctl11) = 0;
44738+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
44739+ ACCESS_ONCE_RW(ads->ctl15) = 0;
44740+ ACCESS_ONCE_RW(ads->ctl16) = 0;
44741+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
44742+ ACCESS_ONCE_RW(ads->ctl18) = 0;
44743+ ACCESS_ONCE_RW(ads->ctl19) = 0;
44744 return;
44745 }
44746
44747- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
44748+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
44749 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
44750 | SM(i->txpower, AR_XmitPower)
44751 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
44752@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44753 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
44754 ctl12 |= SM(val, AR_PAPRDChainMask);
44755
44756- ACCESS_ONCE(ads->ctl12) = ctl12;
44757- ACCESS_ONCE(ads->ctl17) = ctl17;
44758+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
44759+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
44760
44761- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
44762+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
44763 | set11nPktDurRTSCTS(i->rates, 1);
44764
44765- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
44766+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
44767 | set11nPktDurRTSCTS(i->rates, 3);
44768
44769- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
44770+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
44771 | set11nRateFlags(i->rates, 1)
44772 | set11nRateFlags(i->rates, 2)
44773 | set11nRateFlags(i->rates, 3)
44774 | SM(i->rtscts_rate, AR_RTSCTSRate);
44775
44776- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
44777+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
44778 }
44779
44780 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
44781diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
44782index cd74b3a..6a28d24 100644
44783--- a/drivers/net/wireless/ath/ath9k/hw.h
44784+++ b/drivers/net/wireless/ath/ath9k/hw.h
44785@@ -652,7 +652,7 @@ struct ath_hw_private_ops {
44786
44787 /* ANI */
44788 void (*ani_cache_ini_regs)(struct ath_hw *ah);
44789-};
44790+} __no_const;
44791
44792 /**
44793 * struct ath_spec_scan - parameters for Atheros spectral scan
44794@@ -721,7 +721,7 @@ struct ath_hw_ops {
44795 struct ath_spec_scan *param);
44796 void (*spectral_scan_trigger)(struct ath_hw *ah);
44797 void (*spectral_scan_wait)(struct ath_hw *ah);
44798-};
44799+} __no_const;
44800
44801 struct ath_nf_limits {
44802 s16 max;
44803diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
44804index 9581d07..84f6a76 100644
44805--- a/drivers/net/wireless/iwlegacy/3945-mac.c
44806+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
44807@@ -3639,7 +3639,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
44808 */
44809 if (il3945_mod_params.disable_hw_scan) {
44810 D_INFO("Disabling hw_scan\n");
44811- il3945_mac_ops.hw_scan = NULL;
44812+ pax_open_kernel();
44813+ *(void **)&il3945_mac_ops.hw_scan = NULL;
44814+ pax_close_kernel();
44815 }
44816
44817 D_INFO("*** LOAD DRIVER ***\n");
44818diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
44819index d532948..e0d8bb1 100644
44820--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
44821+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
44822@@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
44823 {
44824 struct iwl_priv *priv = file->private_data;
44825 char buf[64];
44826- int buf_size;
44827+ size_t buf_size;
44828 u32 offset, len;
44829
44830 memset(buf, 0, sizeof(buf));
44831@@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
44832 struct iwl_priv *priv = file->private_data;
44833
44834 char buf[8];
44835- int buf_size;
44836+ size_t buf_size;
44837 u32 reset_flag;
44838
44839 memset(buf, 0, sizeof(buf));
44840@@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
44841 {
44842 struct iwl_priv *priv = file->private_data;
44843 char buf[8];
44844- int buf_size;
44845+ size_t buf_size;
44846 int ht40;
44847
44848 memset(buf, 0, sizeof(buf));
44849@@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
44850 {
44851 struct iwl_priv *priv = file->private_data;
44852 char buf[8];
44853- int buf_size;
44854+ size_t buf_size;
44855 int value;
44856
44857 memset(buf, 0, sizeof(buf));
44858@@ -698,10 +698,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
44859 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
44860 DEBUGFS_READ_FILE_OPS(current_sleep_command);
44861
44862-static const char *fmt_value = " %-30s %10u\n";
44863-static const char *fmt_hex = " %-30s 0x%02X\n";
44864-static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
44865-static const char *fmt_header =
44866+static const char fmt_value[] = " %-30s %10u\n";
44867+static const char fmt_hex[] = " %-30s 0x%02X\n";
44868+static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
44869+static const char fmt_header[] =
44870 "%-32s current cumulative delta max\n";
44871
44872 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
44873@@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
44874 {
44875 struct iwl_priv *priv = file->private_data;
44876 char buf[8];
44877- int buf_size;
44878+ size_t buf_size;
44879 int clear;
44880
44881 memset(buf, 0, sizeof(buf));
44882@@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
44883 {
44884 struct iwl_priv *priv = file->private_data;
44885 char buf[8];
44886- int buf_size;
44887+ size_t buf_size;
44888 int trace;
44889
44890 memset(buf, 0, sizeof(buf));
44891@@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
44892 {
44893 struct iwl_priv *priv = file->private_data;
44894 char buf[8];
44895- int buf_size;
44896+ size_t buf_size;
44897 int missed;
44898
44899 memset(buf, 0, sizeof(buf));
44900@@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
44901
44902 struct iwl_priv *priv = file->private_data;
44903 char buf[8];
44904- int buf_size;
44905+ size_t buf_size;
44906 int plcp;
44907
44908 memset(buf, 0, sizeof(buf));
44909@@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
44910
44911 struct iwl_priv *priv = file->private_data;
44912 char buf[8];
44913- int buf_size;
44914+ size_t buf_size;
44915 int flush;
44916
44917 memset(buf, 0, sizeof(buf));
44918@@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
44919
44920 struct iwl_priv *priv = file->private_data;
44921 char buf[8];
44922- int buf_size;
44923+ size_t buf_size;
44924 int rts;
44925
44926 if (!priv->cfg->ht_params)
44927@@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
44928 {
44929 struct iwl_priv *priv = file->private_data;
44930 char buf[8];
44931- int buf_size;
44932+ size_t buf_size;
44933
44934 memset(buf, 0, sizeof(buf));
44935 buf_size = min(count, sizeof(buf) - 1);
44936@@ -2254,7 +2254,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
44937 struct iwl_priv *priv = file->private_data;
44938 u32 event_log_flag;
44939 char buf[8];
44940- int buf_size;
44941+ size_t buf_size;
44942
44943 /* check that the interface is up */
44944 if (!iwl_is_ready(priv))
44945@@ -2308,7 +2308,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
44946 struct iwl_priv *priv = file->private_data;
44947 char buf[8];
44948 u32 calib_disabled;
44949- int buf_size;
44950+ size_t buf_size;
44951
44952 memset(buf, 0, sizeof(buf));
44953 buf_size = min(count, sizeof(buf) - 1);
44954diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
44955index 1531a4f..21d2641 100644
44956--- a/drivers/net/wireless/iwlwifi/dvm/main.c
44957+++ b/drivers/net/wireless/iwlwifi/dvm/main.c
44958@@ -1180,7 +1180,7 @@ static void iwl_option_config(struct iwl_priv *priv)
44959 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
44960 {
44961 struct iwl_nvm_data *data = priv->nvm_data;
44962- char *debug_msg;
44963+ static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
44964
44965 if (data->sku_cap_11n_enable &&
44966 !priv->cfg->ht_params) {
44967@@ -1194,7 +1194,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
44968 return -EINVAL;
44969 }
44970
44971- debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
44972 IWL_DEBUG_INFO(priv, debug_msg,
44973 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
44974 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
44975diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
44976index 390e2f0..75cfbaf 100644
44977--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
44978+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
44979@@ -1350,7 +1350,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
44980 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
44981
44982 char buf[8];
44983- int buf_size;
44984+ size_t buf_size;
44985 u32 reset_flag;
44986
44987 memset(buf, 0, sizeof(buf));
44988@@ -1371,7 +1371,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
44989 {
44990 struct iwl_trans *trans = file->private_data;
44991 char buf[8];
44992- int buf_size;
44993+ size_t buf_size;
44994 int csr;
44995
44996 memset(buf, 0, sizeof(buf));
44997diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
44998index cb34c78..9fec0dc 100644
44999--- a/drivers/net/wireless/mac80211_hwsim.c
45000+++ b/drivers/net/wireless/mac80211_hwsim.c
45001@@ -2195,25 +2195,19 @@ static int __init init_mac80211_hwsim(void)
45002
45003 if (channels > 1) {
45004 hwsim_if_comb.num_different_channels = channels;
45005- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
45006- mac80211_hwsim_ops.cancel_hw_scan =
45007- mac80211_hwsim_cancel_hw_scan;
45008- mac80211_hwsim_ops.sw_scan_start = NULL;
45009- mac80211_hwsim_ops.sw_scan_complete = NULL;
45010- mac80211_hwsim_ops.remain_on_channel =
45011- mac80211_hwsim_roc;
45012- mac80211_hwsim_ops.cancel_remain_on_channel =
45013- mac80211_hwsim_croc;
45014- mac80211_hwsim_ops.add_chanctx =
45015- mac80211_hwsim_add_chanctx;
45016- mac80211_hwsim_ops.remove_chanctx =
45017- mac80211_hwsim_remove_chanctx;
45018- mac80211_hwsim_ops.change_chanctx =
45019- mac80211_hwsim_change_chanctx;
45020- mac80211_hwsim_ops.assign_vif_chanctx =
45021- mac80211_hwsim_assign_vif_chanctx;
45022- mac80211_hwsim_ops.unassign_vif_chanctx =
45023- mac80211_hwsim_unassign_vif_chanctx;
45024+ pax_open_kernel();
45025+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
45026+ *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
45027+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
45028+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
45029+ *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
45030+ *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
45031+ *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
45032+ *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
45033+ *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
45034+ *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
45035+ *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
45036+ pax_close_kernel();
45037 }
45038
45039 spin_lock_init(&hwsim_radio_lock);
45040diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
45041index 8169a85..7fa3b47 100644
45042--- a/drivers/net/wireless/rndis_wlan.c
45043+++ b/drivers/net/wireless/rndis_wlan.c
45044@@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
45045
45046 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
45047
45048- if (rts_threshold < 0 || rts_threshold > 2347)
45049+ if (rts_threshold > 2347)
45050 rts_threshold = 2347;
45051
45052 tmp = cpu_to_le32(rts_threshold);
45053diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
45054index ee3fc57..ed5ddc9 100644
45055--- a/drivers/net/wireless/rt2x00/rt2x00.h
45056+++ b/drivers/net/wireless/rt2x00/rt2x00.h
45057@@ -386,7 +386,7 @@ struct rt2x00_intf {
45058 * for hardware which doesn't support hardware
45059 * sequence counting.
45060 */
45061- atomic_t seqno;
45062+ atomic_unchecked_t seqno;
45063 };
45064
45065 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
45066diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
45067index aa95c6c..a59dd67 100644
45068--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
45069+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
45070@@ -252,9 +252,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
45071 * sequence counter given by mac80211.
45072 */
45073 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
45074- seqno = atomic_add_return(0x10, &intf->seqno);
45075+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
45076 else
45077- seqno = atomic_read(&intf->seqno);
45078+ seqno = atomic_read_unchecked(&intf->seqno);
45079
45080 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
45081 hdr->seq_ctrl |= cpu_to_le16(seqno);
45082diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
45083index e2b3d9c..67a5184 100644
45084--- a/drivers/net/wireless/ti/wl1251/sdio.c
45085+++ b/drivers/net/wireless/ti/wl1251/sdio.c
45086@@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
45087
45088 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
45089
45090- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
45091- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
45092+ pax_open_kernel();
45093+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
45094+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
45095+ pax_close_kernel();
45096
45097 wl1251_info("using dedicated interrupt line");
45098 } else {
45099- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
45100- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
45101+ pax_open_kernel();
45102+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
45103+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
45104+ pax_close_kernel();
45105
45106 wl1251_info("using SDIO interrupt");
45107 }
45108diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
45109index 1c627da..69f7d17 100644
45110--- a/drivers/net/wireless/ti/wl12xx/main.c
45111+++ b/drivers/net/wireless/ti/wl12xx/main.c
45112@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
45113 sizeof(wl->conf.mem));
45114
45115 /* read data preparation is only needed by wl127x */
45116- wl->ops->prepare_read = wl127x_prepare_read;
45117+ pax_open_kernel();
45118+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
45119+ pax_close_kernel();
45120
45121 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
45122 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
45123@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
45124 sizeof(wl->conf.mem));
45125
45126 /* read data preparation is only needed by wl127x */
45127- wl->ops->prepare_read = wl127x_prepare_read;
45128+ pax_open_kernel();
45129+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
45130+ pax_close_kernel();
45131
45132 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
45133 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
45134diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
45135index 7aa0eb8..5a9ef38 100644
45136--- a/drivers/net/wireless/ti/wl18xx/main.c
45137+++ b/drivers/net/wireless/ti/wl18xx/main.c
45138@@ -1730,8 +1730,10 @@ static int wl18xx_setup(struct wl1271 *wl)
45139 }
45140
45141 if (!checksum_param) {
45142- wl18xx_ops.set_rx_csum = NULL;
45143- wl18xx_ops.init_vif = NULL;
45144+ pax_open_kernel();
45145+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
45146+ *(void **)&wl18xx_ops.init_vif = NULL;
45147+ pax_close_kernel();
45148 }
45149
45150 /* Enable 11a Band only if we have 5G antennas */
45151diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
45152index 7ef0b4a..ff65c28 100644
45153--- a/drivers/net/wireless/zd1211rw/zd_usb.c
45154+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
45155@@ -386,7 +386,7 @@ static inline void handle_regs_int(struct urb *urb)
45156 {
45157 struct zd_usb *usb = urb->context;
45158 struct zd_usb_interrupt *intr = &usb->intr;
45159- int len;
45160+ unsigned int len;
45161 u16 int_num;
45162
45163 ZD_ASSERT(in_interrupt());
45164diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
45165index d93b2b6..ae50401 100644
45166--- a/drivers/oprofile/buffer_sync.c
45167+++ b/drivers/oprofile/buffer_sync.c
45168@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
45169 if (cookie == NO_COOKIE)
45170 offset = pc;
45171 if (cookie == INVALID_COOKIE) {
45172- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
45173+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
45174 offset = pc;
45175 }
45176 if (cookie != last_cookie) {
45177@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
45178 /* add userspace sample */
45179
45180 if (!mm) {
45181- atomic_inc(&oprofile_stats.sample_lost_no_mm);
45182+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
45183 return 0;
45184 }
45185
45186 cookie = lookup_dcookie(mm, s->eip, &offset);
45187
45188 if (cookie == INVALID_COOKIE) {
45189- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
45190+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
45191 return 0;
45192 }
45193
45194@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
45195 /* ignore backtraces if failed to add a sample */
45196 if (state == sb_bt_start) {
45197 state = sb_bt_ignore;
45198- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
45199+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
45200 }
45201 }
45202 release_mm(mm);
45203diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
45204index c0cc4e7..44d4e54 100644
45205--- a/drivers/oprofile/event_buffer.c
45206+++ b/drivers/oprofile/event_buffer.c
45207@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
45208 }
45209
45210 if (buffer_pos == buffer_size) {
45211- atomic_inc(&oprofile_stats.event_lost_overflow);
45212+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
45213 return;
45214 }
45215
45216diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
45217index ed2c3ec..deda85a 100644
45218--- a/drivers/oprofile/oprof.c
45219+++ b/drivers/oprofile/oprof.c
45220@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
45221 if (oprofile_ops.switch_events())
45222 return;
45223
45224- atomic_inc(&oprofile_stats.multiplex_counter);
45225+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
45226 start_switch_worker();
45227 }
45228
45229diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
45230index 84a208d..d61b0a1 100644
45231--- a/drivers/oprofile/oprofile_files.c
45232+++ b/drivers/oprofile/oprofile_files.c
45233@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
45234
45235 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
45236
45237-static ssize_t timeout_read(struct file *file, char __user *buf,
45238+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
45239 size_t count, loff_t *offset)
45240 {
45241 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
45242diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
45243index 917d28e..d62d981 100644
45244--- a/drivers/oprofile/oprofile_stats.c
45245+++ b/drivers/oprofile/oprofile_stats.c
45246@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
45247 cpu_buf->sample_invalid_eip = 0;
45248 }
45249
45250- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
45251- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
45252- atomic_set(&oprofile_stats.event_lost_overflow, 0);
45253- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
45254- atomic_set(&oprofile_stats.multiplex_counter, 0);
45255+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
45256+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
45257+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
45258+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
45259+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
45260 }
45261
45262
45263diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
45264index 38b6fc0..b5cbfce 100644
45265--- a/drivers/oprofile/oprofile_stats.h
45266+++ b/drivers/oprofile/oprofile_stats.h
45267@@ -13,11 +13,11 @@
45268 #include <linux/atomic.h>
45269
45270 struct oprofile_stat_struct {
45271- atomic_t sample_lost_no_mm;
45272- atomic_t sample_lost_no_mapping;
45273- atomic_t bt_lost_no_mapping;
45274- atomic_t event_lost_overflow;
45275- atomic_t multiplex_counter;
45276+ atomic_unchecked_t sample_lost_no_mm;
45277+ atomic_unchecked_t sample_lost_no_mapping;
45278+ atomic_unchecked_t bt_lost_no_mapping;
45279+ atomic_unchecked_t event_lost_overflow;
45280+ atomic_unchecked_t multiplex_counter;
45281 };
45282
45283 extern struct oprofile_stat_struct oprofile_stats;
45284diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
45285index 7c12d9c..558bf3bb 100644
45286--- a/drivers/oprofile/oprofilefs.c
45287+++ b/drivers/oprofile/oprofilefs.c
45288@@ -190,7 +190,7 @@ static const struct file_operations atomic_ro_fops = {
45289
45290
45291 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
45292- char const *name, atomic_t *val)
45293+ char const *name, atomic_unchecked_t *val)
45294 {
45295 return __oprofilefs_create_file(sb, root, name,
45296 &atomic_ro_fops, 0444, val);
45297diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
45298index 61be1d9..dec05d7 100644
45299--- a/drivers/oprofile/timer_int.c
45300+++ b/drivers/oprofile/timer_int.c
45301@@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
45302 return NOTIFY_OK;
45303 }
45304
45305-static struct notifier_block __refdata oprofile_cpu_notifier = {
45306+static struct notifier_block oprofile_cpu_notifier = {
45307 .notifier_call = oprofile_cpu_notify,
45308 };
45309
45310diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
45311index 92ed045..62d39bd7 100644
45312--- a/drivers/parport/procfs.c
45313+++ b/drivers/parport/procfs.c
45314@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
45315
45316 *ppos += len;
45317
45318- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
45319+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
45320 }
45321
45322 #ifdef CONFIG_PARPORT_1284
45323@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
45324
45325 *ppos += len;
45326
45327- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
45328+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
45329 }
45330 #endif /* IEEE1284.3 support. */
45331
45332diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
45333index c35e8ad..fc33beb 100644
45334--- a/drivers/pci/hotplug/acpiphp_ibm.c
45335+++ b/drivers/pci/hotplug/acpiphp_ibm.c
45336@@ -464,7 +464,9 @@ static int __init ibm_acpiphp_init(void)
45337 goto init_cleanup;
45338 }
45339
45340- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
45341+ pax_open_kernel();
45342+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
45343+ pax_close_kernel();
45344 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
45345
45346 return retval;
45347diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
45348index a6a71c4..c91097b 100644
45349--- a/drivers/pci/hotplug/cpcihp_generic.c
45350+++ b/drivers/pci/hotplug/cpcihp_generic.c
45351@@ -73,7 +73,6 @@ static u16 port;
45352 static unsigned int enum_bit;
45353 static u8 enum_mask;
45354
45355-static struct cpci_hp_controller_ops generic_hpc_ops;
45356 static struct cpci_hp_controller generic_hpc;
45357
45358 static int __init validate_parameters(void)
45359@@ -139,6 +138,10 @@ static int query_enum(void)
45360 return ((value & enum_mask) == enum_mask);
45361 }
45362
45363+static struct cpci_hp_controller_ops generic_hpc_ops = {
45364+ .query_enum = query_enum,
45365+};
45366+
45367 static int __init cpcihp_generic_init(void)
45368 {
45369 int status;
45370@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
45371 pci_dev_put(dev);
45372
45373 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
45374- generic_hpc_ops.query_enum = query_enum;
45375 generic_hpc.ops = &generic_hpc_ops;
45376
45377 status = cpci_hp_register_controller(&generic_hpc);
45378diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
45379index 449b4bb..257e2e8 100644
45380--- a/drivers/pci/hotplug/cpcihp_zt5550.c
45381+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
45382@@ -59,7 +59,6 @@
45383 /* local variables */
45384 static bool debug;
45385 static bool poll;
45386-static struct cpci_hp_controller_ops zt5550_hpc_ops;
45387 static struct cpci_hp_controller zt5550_hpc;
45388
45389 /* Primary cPCI bus bridge device */
45390@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
45391 return 0;
45392 }
45393
45394+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
45395+ .query_enum = zt5550_hc_query_enum,
45396+};
45397+
45398 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
45399 {
45400 int status;
45401@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
45402 dbg("returned from zt5550_hc_config");
45403
45404 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
45405- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
45406 zt5550_hpc.ops = &zt5550_hpc_ops;
45407 if(!poll) {
45408 zt5550_hpc.irq = hc_dev->irq;
45409 zt5550_hpc.irq_flags = IRQF_SHARED;
45410 zt5550_hpc.dev_id = hc_dev;
45411
45412- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
45413- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
45414- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
45415+ pax_open_kernel();
45416+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
45417+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
45418+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
45419+ pax_open_kernel();
45420 } else {
45421 info("using ENUM# polling mode");
45422 }
45423diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
45424index 76ba8a1..20ca857 100644
45425--- a/drivers/pci/hotplug/cpqphp_nvram.c
45426+++ b/drivers/pci/hotplug/cpqphp_nvram.c
45427@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
45428
45429 void compaq_nvram_init (void __iomem *rom_start)
45430 {
45431+
45432+#ifndef CONFIG_PAX_KERNEXEC
45433 if (rom_start) {
45434 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
45435 }
45436+#endif
45437+
45438 dbg("int15 entry = %p\n", compaq_int15_entry_point);
45439
45440 /* initialize our int15 lock */
45441diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
45442index ec20f74..c1d961e 100644
45443--- a/drivers/pci/hotplug/pci_hotplug_core.c
45444+++ b/drivers/pci/hotplug/pci_hotplug_core.c
45445@@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
45446 return -EINVAL;
45447 }
45448
45449- slot->ops->owner = owner;
45450- slot->ops->mod_name = mod_name;
45451+ pax_open_kernel();
45452+ *(struct module **)&slot->ops->owner = owner;
45453+ *(const char **)&slot->ops->mod_name = mod_name;
45454+ pax_close_kernel();
45455
45456 mutex_lock(&pci_hp_mutex);
45457 /*
45458diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
45459index 7d72c5e..edce02c 100644
45460--- a/drivers/pci/hotplug/pciehp_core.c
45461+++ b/drivers/pci/hotplug/pciehp_core.c
45462@@ -91,7 +91,7 @@ static int init_slot(struct controller *ctrl)
45463 struct slot *slot = ctrl->slot;
45464 struct hotplug_slot *hotplug = NULL;
45465 struct hotplug_slot_info *info = NULL;
45466- struct hotplug_slot_ops *ops = NULL;
45467+ hotplug_slot_ops_no_const *ops = NULL;
45468 char name[SLOT_NAME_SIZE];
45469 int retval = -ENOMEM;
45470
45471diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
45472index c0dbe1f..94cf3d8 100644
45473--- a/drivers/pci/pci-sysfs.c
45474+++ b/drivers/pci/pci-sysfs.c
45475@@ -1073,7 +1073,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
45476 {
45477 /* allocate attribute structure, piggyback attribute name */
45478 int name_len = write_combine ? 13 : 10;
45479- struct bin_attribute *res_attr;
45480+ bin_attribute_no_const *res_attr;
45481 int retval;
45482
45483 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
45484@@ -1258,7 +1258,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
45485 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
45486 {
45487 int retval;
45488- struct bin_attribute *attr;
45489+ bin_attribute_no_const *attr;
45490
45491 /* If the device has VPD, try to expose it in sysfs. */
45492 if (dev->vpd) {
45493@@ -1305,7 +1305,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
45494 {
45495 int retval;
45496 int rom_size = 0;
45497- struct bin_attribute *attr;
45498+ bin_attribute_no_const *attr;
45499
45500 if (!sysfs_initialized)
45501 return -EACCES;
45502diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
45503index d1182c4..2a138ec 100644
45504--- a/drivers/pci/pci.h
45505+++ b/drivers/pci/pci.h
45506@@ -92,7 +92,7 @@ struct pci_vpd_ops {
45507 struct pci_vpd {
45508 unsigned int len;
45509 const struct pci_vpd_ops *ops;
45510- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
45511+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
45512 };
45513
45514 int pci_vpd_pci22_init(struct pci_dev *dev);
45515diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
45516index 403a443..034e050 100644
45517--- a/drivers/pci/pcie/aspm.c
45518+++ b/drivers/pci/pcie/aspm.c
45519@@ -27,9 +27,9 @@
45520 #define MODULE_PARAM_PREFIX "pcie_aspm."
45521
45522 /* Note: those are not register definitions */
45523-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
45524-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
45525-#define ASPM_STATE_L1 (4) /* L1 state */
45526+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
45527+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
45528+#define ASPM_STATE_L1 (4U) /* L1 state */
45529 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
45530 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
45531
45532diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
45533index 46ada5c..20da716 100644
45534--- a/drivers/pci/probe.c
45535+++ b/drivers/pci/probe.c
45536@@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
45537 struct pci_bus_region region, inverted_region;
45538 bool bar_too_big = false, bar_disabled = false;
45539
45540- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
45541+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
45542
45543 /* No printks while decoding is disabled! */
45544 if (!dev->mmio_always_on) {
45545diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
45546index cdc7836..528635c 100644
45547--- a/drivers/pci/proc.c
45548+++ b/drivers/pci/proc.c
45549@@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
45550 static int __init pci_proc_init(void)
45551 {
45552 struct pci_dev *dev = NULL;
45553+
45554+#ifdef CONFIG_GRKERNSEC_PROC_ADD
45555+#ifdef CONFIG_GRKERNSEC_PROC_USER
45556+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
45557+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45558+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
45559+#endif
45560+#else
45561 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
45562+#endif
45563 proc_create("devices", 0, proc_bus_pci_dir,
45564 &proc_bus_pci_dev_operations);
45565 proc_initialized = 1;
45566diff --git a/drivers/platform/x86/chromeos_laptop.c b/drivers/platform/x86/chromeos_laptop.c
45567index 3e5b4497..dcdfb70 100644
45568--- a/drivers/platform/x86/chromeos_laptop.c
45569+++ b/drivers/platform/x86/chromeos_laptop.c
45570@@ -301,7 +301,7 @@ static int __init setup_tsl2563_als(const struct dmi_system_id *id)
45571 return 0;
45572 }
45573
45574-static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
45575+static struct dmi_system_id __initconst chromeos_laptop_dmi_table[] = {
45576 {
45577 .ident = "Samsung Series 5 550 - Touchpad",
45578 .matches = {
45579diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
45580index 62f8030..c7f2a45 100644
45581--- a/drivers/platform/x86/msi-laptop.c
45582+++ b/drivers/platform/x86/msi-laptop.c
45583@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
45584
45585 if (!quirks->ec_read_only) {
45586 /* allow userland write sysfs file */
45587- dev_attr_bluetooth.store = store_bluetooth;
45588- dev_attr_wlan.store = store_wlan;
45589- dev_attr_threeg.store = store_threeg;
45590- dev_attr_bluetooth.attr.mode |= S_IWUSR;
45591- dev_attr_wlan.attr.mode |= S_IWUSR;
45592- dev_attr_threeg.attr.mode |= S_IWUSR;
45593+ pax_open_kernel();
45594+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
45595+ *(void **)&dev_attr_wlan.store = store_wlan;
45596+ *(void **)&dev_attr_threeg.store = store_threeg;
45597+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
45598+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
45599+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
45600+ pax_close_kernel();
45601 }
45602
45603 /* disable hardware control by fn key */
45604diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
45605index 3a1b6bf..b453930 100644
45606--- a/drivers/platform/x86/sony-laptop.c
45607+++ b/drivers/platform/x86/sony-laptop.c
45608@@ -2486,7 +2486,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
45609 }
45610
45611 /* High speed charging function */
45612-static struct device_attribute *hsc_handle;
45613+static device_attribute_no_const *hsc_handle;
45614
45615 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
45616 struct device_attribute *attr,
45617diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
45618index 54d31c0..3f896d3 100644
45619--- a/drivers/platform/x86/thinkpad_acpi.c
45620+++ b/drivers/platform/x86/thinkpad_acpi.c
45621@@ -2093,7 +2093,7 @@ static int hotkey_mask_get(void)
45622 return 0;
45623 }
45624
45625-void static hotkey_mask_warn_incomplete_mask(void)
45626+static void hotkey_mask_warn_incomplete_mask(void)
45627 {
45628 /* log only what the user can fix... */
45629 const u32 wantedmask = hotkey_driver_mask &
45630@@ -2324,11 +2324,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
45631 }
45632 }
45633
45634-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45635- struct tp_nvram_state *newn,
45636- const u32 event_mask)
45637-{
45638-
45639 #define TPACPI_COMPARE_KEY(__scancode, __member) \
45640 do { \
45641 if ((event_mask & (1 << __scancode)) && \
45642@@ -2342,36 +2337,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45643 tpacpi_hotkey_send_key(__scancode); \
45644 } while (0)
45645
45646- void issue_volchange(const unsigned int oldvol,
45647- const unsigned int newvol)
45648- {
45649- unsigned int i = oldvol;
45650+static void issue_volchange(const unsigned int oldvol,
45651+ const unsigned int newvol,
45652+ const u32 event_mask)
45653+{
45654+ unsigned int i = oldvol;
45655
45656- while (i > newvol) {
45657- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
45658- i--;
45659- }
45660- while (i < newvol) {
45661- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
45662- i++;
45663- }
45664+ while (i > newvol) {
45665+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
45666+ i--;
45667 }
45668+ while (i < newvol) {
45669+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
45670+ i++;
45671+ }
45672+}
45673
45674- void issue_brightnesschange(const unsigned int oldbrt,
45675- const unsigned int newbrt)
45676- {
45677- unsigned int i = oldbrt;
45678+static void issue_brightnesschange(const unsigned int oldbrt,
45679+ const unsigned int newbrt,
45680+ const u32 event_mask)
45681+{
45682+ unsigned int i = oldbrt;
45683
45684- while (i > newbrt) {
45685- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
45686- i--;
45687- }
45688- while (i < newbrt) {
45689- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
45690- i++;
45691- }
45692+ while (i > newbrt) {
45693+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
45694+ i--;
45695+ }
45696+ while (i < newbrt) {
45697+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
45698+ i++;
45699 }
45700+}
45701
45702+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45703+ struct tp_nvram_state *newn,
45704+ const u32 event_mask)
45705+{
45706 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
45707 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
45708 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
45709@@ -2405,7 +2406,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45710 oldn->volume_level != newn->volume_level) {
45711 /* recently muted, or repeated mute keypress, or
45712 * multiple presses ending in mute */
45713- issue_volchange(oldn->volume_level, newn->volume_level);
45714+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
45715 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
45716 }
45717 } else {
45718@@ -2415,7 +2416,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45719 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
45720 }
45721 if (oldn->volume_level != newn->volume_level) {
45722- issue_volchange(oldn->volume_level, newn->volume_level);
45723+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
45724 } else if (oldn->volume_toggle != newn->volume_toggle) {
45725 /* repeated vol up/down keypress at end of scale ? */
45726 if (newn->volume_level == 0)
45727@@ -2428,7 +2429,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45728 /* handle brightness */
45729 if (oldn->brightness_level != newn->brightness_level) {
45730 issue_brightnesschange(oldn->brightness_level,
45731- newn->brightness_level);
45732+ newn->brightness_level,
45733+ event_mask);
45734 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
45735 /* repeated key presses that didn't change state */
45736 if (newn->brightness_level == 0)
45737@@ -2437,10 +2439,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45738 && !tp_features.bright_unkfw)
45739 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
45740 }
45741+}
45742
45743 #undef TPACPI_COMPARE_KEY
45744 #undef TPACPI_MAY_SEND_KEY
45745-}
45746
45747 /*
45748 * Polling driver
45749diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
45750index 769d265..a3a05ca 100644
45751--- a/drivers/pnp/pnpbios/bioscalls.c
45752+++ b/drivers/pnp/pnpbios/bioscalls.c
45753@@ -58,7 +58,7 @@ do { \
45754 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
45755 } while(0)
45756
45757-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
45758+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
45759 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
45760
45761 /*
45762@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
45763
45764 cpu = get_cpu();
45765 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
45766+
45767+ pax_open_kernel();
45768 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
45769+ pax_close_kernel();
45770
45771 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
45772 spin_lock_irqsave(&pnp_bios_lock, flags);
45773@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
45774 :"memory");
45775 spin_unlock_irqrestore(&pnp_bios_lock, flags);
45776
45777+ pax_open_kernel();
45778 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
45779+ pax_close_kernel();
45780+
45781 put_cpu();
45782
45783 /* If we get here and this is set then the PnP BIOS faulted on us. */
45784@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
45785 return status;
45786 }
45787
45788-void pnpbios_calls_init(union pnp_bios_install_struct *header)
45789+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
45790 {
45791 int i;
45792
45793@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
45794 pnp_bios_callpoint.offset = header->fields.pm16offset;
45795 pnp_bios_callpoint.segment = PNP_CS16;
45796
45797+ pax_open_kernel();
45798+
45799 for_each_possible_cpu(i) {
45800 struct desc_struct *gdt = get_cpu_gdt_table(i);
45801 if (!gdt)
45802@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
45803 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
45804 (unsigned long)__va(header->fields.pm16dseg));
45805 }
45806+
45807+ pax_close_kernel();
45808 }
45809diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
45810index d95e101..67f0c3f 100644
45811--- a/drivers/pnp/resource.c
45812+++ b/drivers/pnp/resource.c
45813@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
45814 return 1;
45815
45816 /* check if the resource is valid */
45817- if (*irq < 0 || *irq > 15)
45818+ if (*irq > 15)
45819 return 0;
45820
45821 /* check if the resource is reserved */
45822@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
45823 return 1;
45824
45825 /* check if the resource is valid */
45826- if (*dma < 0 || *dma == 4 || *dma > 7)
45827+ if (*dma == 4 || *dma > 7)
45828 return 0;
45829
45830 /* check if the resource is reserved */
45831diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
45832index 0c52e2a..3421ab7 100644
45833--- a/drivers/power/pda_power.c
45834+++ b/drivers/power/pda_power.c
45835@@ -37,7 +37,11 @@ static int polling;
45836
45837 #if IS_ENABLED(CONFIG_USB_PHY)
45838 static struct usb_phy *transceiver;
45839-static struct notifier_block otg_nb;
45840+static int otg_handle_notification(struct notifier_block *nb,
45841+ unsigned long event, void *unused);
45842+static struct notifier_block otg_nb = {
45843+ .notifier_call = otg_handle_notification
45844+};
45845 #endif
45846
45847 static struct regulator *ac_draw;
45848@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
45849
45850 #if IS_ENABLED(CONFIG_USB_PHY)
45851 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
45852- otg_nb.notifier_call = otg_handle_notification;
45853 ret = usb_register_notifier(transceiver, &otg_nb);
45854 if (ret) {
45855 dev_err(dev, "failure to register otg notifier\n");
45856diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
45857index cc439fd..8fa30df 100644
45858--- a/drivers/power/power_supply.h
45859+++ b/drivers/power/power_supply.h
45860@@ -16,12 +16,12 @@ struct power_supply;
45861
45862 #ifdef CONFIG_SYSFS
45863
45864-extern void power_supply_init_attrs(struct device_type *dev_type);
45865+extern void power_supply_init_attrs(void);
45866 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
45867
45868 #else
45869
45870-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
45871+static inline void power_supply_init_attrs(void) {}
45872 #define power_supply_uevent NULL
45873
45874 #endif /* CONFIG_SYSFS */
45875diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
45876index 3b2d5df..3207114 100644
45877--- a/drivers/power/power_supply_core.c
45878+++ b/drivers/power/power_supply_core.c
45879@@ -24,7 +24,10 @@
45880 struct class *power_supply_class;
45881 EXPORT_SYMBOL_GPL(power_supply_class);
45882
45883-static struct device_type power_supply_dev_type;
45884+extern const struct attribute_group *power_supply_attr_groups[];
45885+static struct device_type power_supply_dev_type = {
45886+ .groups = power_supply_attr_groups,
45887+};
45888
45889 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
45890 struct power_supply *supply)
45891@@ -558,7 +561,7 @@ static int __init power_supply_class_init(void)
45892 return PTR_ERR(power_supply_class);
45893
45894 power_supply_class->dev_uevent = power_supply_uevent;
45895- power_supply_init_attrs(&power_supply_dev_type);
45896+ power_supply_init_attrs();
45897
45898 return 0;
45899 }
45900diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
45901index 29178f7..c65f324 100644
45902--- a/drivers/power/power_supply_sysfs.c
45903+++ b/drivers/power/power_supply_sysfs.c
45904@@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
45905 .is_visible = power_supply_attr_is_visible,
45906 };
45907
45908-static const struct attribute_group *power_supply_attr_groups[] = {
45909+const struct attribute_group *power_supply_attr_groups[] = {
45910 &power_supply_attr_group,
45911 NULL,
45912 };
45913
45914-void power_supply_init_attrs(struct device_type *dev_type)
45915+void power_supply_init_attrs(void)
45916 {
45917 int i;
45918
45919- dev_type->groups = power_supply_attr_groups;
45920-
45921 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
45922 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
45923 }
45924diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
45925index 288c75a..065bc84 100644
45926--- a/drivers/regulator/core.c
45927+++ b/drivers/regulator/core.c
45928@@ -3544,7 +3544,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
45929 {
45930 const struct regulation_constraints *constraints = NULL;
45931 const struct regulator_init_data *init_data;
45932- static atomic_t regulator_no = ATOMIC_INIT(0);
45933+ static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
45934 struct regulator_dev *rdev;
45935 struct device *dev;
45936 int ret, i;
45937@@ -3614,7 +3614,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
45938 rdev->dev.of_node = config->of_node;
45939 rdev->dev.parent = dev;
45940 dev_set_name(&rdev->dev, "regulator.%d",
45941- atomic_inc_return(&regulator_no) - 1);
45942+ atomic_inc_return_unchecked(&regulator_no) - 1);
45943 ret = device_register(&rdev->dev);
45944 if (ret != 0) {
45945 put_device(&rdev->dev);
45946diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
45947index d428ef9..fdc0357 100644
45948--- a/drivers/regulator/max8660.c
45949+++ b/drivers/regulator/max8660.c
45950@@ -333,8 +333,10 @@ static int max8660_probe(struct i2c_client *client,
45951 max8660->shadow_regs[MAX8660_OVER1] = 5;
45952 } else {
45953 /* Otherwise devices can be toggled via software */
45954- max8660_dcdc_ops.enable = max8660_dcdc_enable;
45955- max8660_dcdc_ops.disable = max8660_dcdc_disable;
45956+ pax_open_kernel();
45957+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
45958+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
45959+ pax_close_kernel();
45960 }
45961
45962 /*
45963diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
45964index 0c5195a..637a453d 100644
45965--- a/drivers/regulator/max8973-regulator.c
45966+++ b/drivers/regulator/max8973-regulator.c
45967@@ -406,9 +406,11 @@ static int max8973_probe(struct i2c_client *client,
45968 if (!pdata || !pdata->enable_ext_control) {
45969 max->desc.enable_reg = MAX8973_VOUT;
45970 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
45971- max->ops.enable = regulator_enable_regmap;
45972- max->ops.disable = regulator_disable_regmap;
45973- max->ops.is_enabled = regulator_is_enabled_regmap;
45974+ pax_open_kernel();
45975+ *(void **)&max->ops.enable = regulator_enable_regmap;
45976+ *(void **)&max->ops.disable = regulator_disable_regmap;
45977+ *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
45978+ pax_close_kernel();
45979 }
45980
45981 if (pdata) {
45982diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
45983index 1037e07..e64dea1 100644
45984--- a/drivers/regulator/mc13892-regulator.c
45985+++ b/drivers/regulator/mc13892-regulator.c
45986@@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
45987 }
45988 mc13xxx_unlock(mc13892);
45989
45990- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
45991+ pax_open_kernel();
45992+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
45993 = mc13892_vcam_set_mode;
45994- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
45995+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
45996 = mc13892_vcam_get_mode;
45997+ pax_close_kernel();
45998
45999 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
46000 ARRAY_SIZE(mc13892_regulators));
46001diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
46002index be06d71..264aee9 100644
46003--- a/drivers/rtc/rtc-cmos.c
46004+++ b/drivers/rtc/rtc-cmos.c
46005@@ -731,7 +731,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
46006 hpet_rtc_timer_init();
46007
46008 /* export at least the first block of NVRAM */
46009- nvram.size = address_space - NVRAM_OFFSET;
46010+ pax_open_kernel();
46011+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
46012+ pax_close_kernel();
46013 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
46014 if (retval < 0) {
46015 dev_dbg(dev, "can't create nvram file? %d\n", retval);
46016diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
46017index d049393..bb20be0 100644
46018--- a/drivers/rtc/rtc-dev.c
46019+++ b/drivers/rtc/rtc-dev.c
46020@@ -16,6 +16,7 @@
46021 #include <linux/module.h>
46022 #include <linux/rtc.h>
46023 #include <linux/sched.h>
46024+#include <linux/grsecurity.h>
46025 #include "rtc-core.h"
46026
46027 static dev_t rtc_devt;
46028@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
46029 if (copy_from_user(&tm, uarg, sizeof(tm)))
46030 return -EFAULT;
46031
46032+ gr_log_timechange();
46033+
46034 return rtc_set_time(rtc, &tm);
46035
46036 case RTC_PIE_ON:
46037diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
46038index ca18fd1..055e42d 100644
46039--- a/drivers/rtc/rtc-ds1307.c
46040+++ b/drivers/rtc/rtc-ds1307.c
46041@@ -107,7 +107,7 @@ struct ds1307 {
46042 u8 offset; /* register's offset */
46043 u8 regs[11];
46044 u16 nvram_offset;
46045- struct bin_attribute *nvram;
46046+ bin_attribute_no_const *nvram;
46047 enum ds_type type;
46048 unsigned long flags;
46049 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
46050diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
46051index fcb0329..d77b7f2 100644
46052--- a/drivers/rtc/rtc-m48t59.c
46053+++ b/drivers/rtc/rtc-m48t59.c
46054@@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
46055 if (IS_ERR(m48t59->rtc))
46056 return PTR_ERR(m48t59->rtc);
46057
46058- m48t59_nvram_attr.size = pdata->offset;
46059+ pax_open_kernel();
46060+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
46061+ pax_close_kernel();
46062
46063 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
46064 if (ret)
46065diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
46066index e693af6..2e525b6 100644
46067--- a/drivers/scsi/bfa/bfa_fcpim.h
46068+++ b/drivers/scsi/bfa/bfa_fcpim.h
46069@@ -36,7 +36,7 @@ struct bfa_iotag_s {
46070
46071 struct bfa_itn_s {
46072 bfa_isr_func_t isr;
46073-};
46074+} __no_const;
46075
46076 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
46077 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
46078diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
46079index 90814fe..4384138 100644
46080--- a/drivers/scsi/bfa/bfa_ioc.h
46081+++ b/drivers/scsi/bfa/bfa_ioc.h
46082@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
46083 bfa_ioc_disable_cbfn_t disable_cbfn;
46084 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
46085 bfa_ioc_reset_cbfn_t reset_cbfn;
46086-};
46087+} __no_const;
46088
46089 /*
46090 * IOC event notification mechanism.
46091@@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
46092 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
46093 enum bfi_ioc_state fwstate);
46094 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
46095-};
46096+} __no_const;
46097
46098 /*
46099 * Queue element to wait for room in request queue. FIFO order is
46100diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
46101index c9382d6..6619864 100644
46102--- a/drivers/scsi/fcoe/fcoe_sysfs.c
46103+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
46104@@ -33,8 +33,8 @@
46105 */
46106 #include "libfcoe.h"
46107
46108-static atomic_t ctlr_num;
46109-static atomic_t fcf_num;
46110+static atomic_unchecked_t ctlr_num;
46111+static atomic_unchecked_t fcf_num;
46112
46113 /*
46114 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
46115@@ -681,7 +681,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
46116 if (!ctlr)
46117 goto out;
46118
46119- ctlr->id = atomic_inc_return(&ctlr_num) - 1;
46120+ ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
46121 ctlr->f = f;
46122 ctlr->mode = FIP_CONN_TYPE_FABRIC;
46123 INIT_LIST_HEAD(&ctlr->fcfs);
46124@@ -898,7 +898,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
46125 fcf->dev.parent = &ctlr->dev;
46126 fcf->dev.bus = &fcoe_bus_type;
46127 fcf->dev.type = &fcoe_fcf_device_type;
46128- fcf->id = atomic_inc_return(&fcf_num) - 1;
46129+ fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
46130 fcf->state = FCOE_FCF_STATE_UNKNOWN;
46131
46132 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
46133@@ -934,8 +934,8 @@ int __init fcoe_sysfs_setup(void)
46134 {
46135 int error;
46136
46137- atomic_set(&ctlr_num, 0);
46138- atomic_set(&fcf_num, 0);
46139+ atomic_set_unchecked(&ctlr_num, 0);
46140+ atomic_set_unchecked(&fcf_num, 0);
46141
46142 error = bus_register(&fcoe_bus_type);
46143 if (error)
46144diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
46145index df0c3c7..b00e1d0 100644
46146--- a/drivers/scsi/hosts.c
46147+++ b/drivers/scsi/hosts.c
46148@@ -42,7 +42,7 @@
46149 #include "scsi_logging.h"
46150
46151
46152-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
46153+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
46154
46155
46156 static void scsi_host_cls_release(struct device *dev)
46157@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
46158 * subtract one because we increment first then return, but we need to
46159 * know what the next host number was before increment
46160 */
46161- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
46162+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
46163 shost->dma_channel = 0xff;
46164
46165 /* These three are default values which can be overridden */
46166diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
46167index 7f4f790..b75b92a 100644
46168--- a/drivers/scsi/hpsa.c
46169+++ b/drivers/scsi/hpsa.c
46170@@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
46171 unsigned long flags;
46172
46173 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
46174- return h->access.command_completed(h, q);
46175+ return h->access->command_completed(h, q);
46176
46177 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
46178 a = rq->head[rq->current_entry];
46179@@ -3422,7 +3422,7 @@ static void start_io(struct ctlr_info *h)
46180 while (!list_empty(&h->reqQ)) {
46181 c = list_entry(h->reqQ.next, struct CommandList, list);
46182 /* can't do anything if fifo is full */
46183- if ((h->access.fifo_full(h))) {
46184+ if ((h->access->fifo_full(h))) {
46185 dev_warn(&h->pdev->dev, "fifo full\n");
46186 break;
46187 }
46188@@ -3444,7 +3444,7 @@ static void start_io(struct ctlr_info *h)
46189
46190 /* Tell the controller execute command */
46191 spin_unlock_irqrestore(&h->lock, flags);
46192- h->access.submit_command(h, c);
46193+ h->access->submit_command(h, c);
46194 spin_lock_irqsave(&h->lock, flags);
46195 }
46196 spin_unlock_irqrestore(&h->lock, flags);
46197@@ -3452,17 +3452,17 @@ static void start_io(struct ctlr_info *h)
46198
46199 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
46200 {
46201- return h->access.command_completed(h, q);
46202+ return h->access->command_completed(h, q);
46203 }
46204
46205 static inline bool interrupt_pending(struct ctlr_info *h)
46206 {
46207- return h->access.intr_pending(h);
46208+ return h->access->intr_pending(h);
46209 }
46210
46211 static inline long interrupt_not_for_us(struct ctlr_info *h)
46212 {
46213- return (h->access.intr_pending(h) == 0) ||
46214+ return (h->access->intr_pending(h) == 0) ||
46215 (h->interrupts_enabled == 0);
46216 }
46217
46218@@ -4364,7 +4364,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
46219 if (prod_index < 0)
46220 return -ENODEV;
46221 h->product_name = products[prod_index].product_name;
46222- h->access = *(products[prod_index].access);
46223+ h->access = products[prod_index].access;
46224
46225 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
46226 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
46227@@ -4646,7 +4646,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
46228
46229 assert_spin_locked(&lockup_detector_lock);
46230 remove_ctlr_from_lockup_detector_list(h);
46231- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46232+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46233 spin_lock_irqsave(&h->lock, flags);
46234 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
46235 spin_unlock_irqrestore(&h->lock, flags);
46236@@ -4823,7 +4823,7 @@ reinit_after_soft_reset:
46237 }
46238
46239 /* make sure the board interrupts are off */
46240- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46241+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46242
46243 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
46244 goto clean2;
46245@@ -4857,7 +4857,7 @@ reinit_after_soft_reset:
46246 * fake ones to scoop up any residual completions.
46247 */
46248 spin_lock_irqsave(&h->lock, flags);
46249- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46250+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46251 spin_unlock_irqrestore(&h->lock, flags);
46252 free_irqs(h);
46253 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
46254@@ -4876,9 +4876,9 @@ reinit_after_soft_reset:
46255 dev_info(&h->pdev->dev, "Board READY.\n");
46256 dev_info(&h->pdev->dev,
46257 "Waiting for stale completions to drain.\n");
46258- h->access.set_intr_mask(h, HPSA_INTR_ON);
46259+ h->access->set_intr_mask(h, HPSA_INTR_ON);
46260 msleep(10000);
46261- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46262+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46263
46264 rc = controller_reset_failed(h->cfgtable);
46265 if (rc)
46266@@ -4899,7 +4899,7 @@ reinit_after_soft_reset:
46267 }
46268
46269 /* Turn the interrupts on so we can service requests */
46270- h->access.set_intr_mask(h, HPSA_INTR_ON);
46271+ h->access->set_intr_mask(h, HPSA_INTR_ON);
46272
46273 hpsa_hba_inquiry(h);
46274 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
46275@@ -4954,7 +4954,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
46276 * To write all data in the battery backed cache to disks
46277 */
46278 hpsa_flush_cache(h);
46279- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46280+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46281 hpsa_free_irqs_and_disable_msix(h);
46282 }
46283
46284@@ -5122,7 +5122,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
46285 return;
46286 }
46287 /* Change the access methods to the performant access methods */
46288- h->access = SA5_performant_access;
46289+ h->access = &SA5_performant_access;
46290 h->transMethod = CFGTBL_Trans_Performant;
46291 }
46292
46293diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
46294index 9816479..c5d4e97 100644
46295--- a/drivers/scsi/hpsa.h
46296+++ b/drivers/scsi/hpsa.h
46297@@ -79,7 +79,7 @@ struct ctlr_info {
46298 unsigned int msix_vector;
46299 unsigned int msi_vector;
46300 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
46301- struct access_method access;
46302+ struct access_method *access;
46303
46304 /* queue and queue Info */
46305 struct list_head reqQ;
46306diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
46307index 5879929..32b241d 100644
46308--- a/drivers/scsi/libfc/fc_exch.c
46309+++ b/drivers/scsi/libfc/fc_exch.c
46310@@ -100,12 +100,12 @@ struct fc_exch_mgr {
46311 u16 pool_max_index;
46312
46313 struct {
46314- atomic_t no_free_exch;
46315- atomic_t no_free_exch_xid;
46316- atomic_t xid_not_found;
46317- atomic_t xid_busy;
46318- atomic_t seq_not_found;
46319- atomic_t non_bls_resp;
46320+ atomic_unchecked_t no_free_exch;
46321+ atomic_unchecked_t no_free_exch_xid;
46322+ atomic_unchecked_t xid_not_found;
46323+ atomic_unchecked_t xid_busy;
46324+ atomic_unchecked_t seq_not_found;
46325+ atomic_unchecked_t non_bls_resp;
46326 } stats;
46327 };
46328
46329@@ -736,7 +736,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
46330 /* allocate memory for exchange */
46331 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
46332 if (!ep) {
46333- atomic_inc(&mp->stats.no_free_exch);
46334+ atomic_inc_unchecked(&mp->stats.no_free_exch);
46335 goto out;
46336 }
46337 memset(ep, 0, sizeof(*ep));
46338@@ -797,7 +797,7 @@ out:
46339 return ep;
46340 err:
46341 spin_unlock_bh(&pool->lock);
46342- atomic_inc(&mp->stats.no_free_exch_xid);
46343+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
46344 mempool_free(ep, mp->ep_pool);
46345 return NULL;
46346 }
46347@@ -940,7 +940,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46348 xid = ntohs(fh->fh_ox_id); /* we originated exch */
46349 ep = fc_exch_find(mp, xid);
46350 if (!ep) {
46351- atomic_inc(&mp->stats.xid_not_found);
46352+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46353 reject = FC_RJT_OX_ID;
46354 goto out;
46355 }
46356@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46357 ep = fc_exch_find(mp, xid);
46358 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
46359 if (ep) {
46360- atomic_inc(&mp->stats.xid_busy);
46361+ atomic_inc_unchecked(&mp->stats.xid_busy);
46362 reject = FC_RJT_RX_ID;
46363 goto rel;
46364 }
46365@@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46366 }
46367 xid = ep->xid; /* get our XID */
46368 } else if (!ep) {
46369- atomic_inc(&mp->stats.xid_not_found);
46370+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46371 reject = FC_RJT_RX_ID; /* XID not found */
46372 goto out;
46373 }
46374@@ -998,7 +998,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46375 } else {
46376 sp = &ep->seq;
46377 if (sp->id != fh->fh_seq_id) {
46378- atomic_inc(&mp->stats.seq_not_found);
46379+ atomic_inc_unchecked(&mp->stats.seq_not_found);
46380 if (f_ctl & FC_FC_END_SEQ) {
46381 /*
46382 * Update sequence_id based on incoming last
46383@@ -1448,22 +1448,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46384
46385 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
46386 if (!ep) {
46387- atomic_inc(&mp->stats.xid_not_found);
46388+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46389 goto out;
46390 }
46391 if (ep->esb_stat & ESB_ST_COMPLETE) {
46392- atomic_inc(&mp->stats.xid_not_found);
46393+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46394 goto rel;
46395 }
46396 if (ep->rxid == FC_XID_UNKNOWN)
46397 ep->rxid = ntohs(fh->fh_rx_id);
46398 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
46399- atomic_inc(&mp->stats.xid_not_found);
46400+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46401 goto rel;
46402 }
46403 if (ep->did != ntoh24(fh->fh_s_id) &&
46404 ep->did != FC_FID_FLOGI) {
46405- atomic_inc(&mp->stats.xid_not_found);
46406+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46407 goto rel;
46408 }
46409 sof = fr_sof(fp);
46410@@ -1472,7 +1472,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46411 sp->ssb_stat |= SSB_ST_RESP;
46412 sp->id = fh->fh_seq_id;
46413 } else if (sp->id != fh->fh_seq_id) {
46414- atomic_inc(&mp->stats.seq_not_found);
46415+ atomic_inc_unchecked(&mp->stats.seq_not_found);
46416 goto rel;
46417 }
46418
46419@@ -1536,9 +1536,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46420 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
46421
46422 if (!sp)
46423- atomic_inc(&mp->stats.xid_not_found);
46424+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46425 else
46426- atomic_inc(&mp->stats.non_bls_resp);
46427+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
46428
46429 fc_frame_free(fp);
46430 }
46431@@ -2185,13 +2185,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
46432
46433 list_for_each_entry(ema, &lport->ema_list, ema_list) {
46434 mp = ema->mp;
46435- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
46436+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
46437 st->fc_no_free_exch_xid +=
46438- atomic_read(&mp->stats.no_free_exch_xid);
46439- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
46440- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
46441- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
46442- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
46443+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
46444+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
46445+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
46446+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
46447+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
46448 }
46449 }
46450 EXPORT_SYMBOL(fc_exch_update_stats);
46451diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
46452index 161c98e..6d563b3 100644
46453--- a/drivers/scsi/libsas/sas_ata.c
46454+++ b/drivers/scsi/libsas/sas_ata.c
46455@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
46456 .postreset = ata_std_postreset,
46457 .error_handler = ata_std_error_handler,
46458 .post_internal_cmd = sas_ata_post_internal,
46459- .qc_defer = ata_std_qc_defer,
46460+ .qc_defer = ata_std_qc_defer,
46461 .qc_prep = ata_noop_qc_prep,
46462 .qc_issue = sas_ata_qc_issue,
46463 .qc_fill_rtf = sas_ata_qc_fill_rtf,
46464diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
46465index 93f222d..73e977b 100644
46466--- a/drivers/scsi/lpfc/lpfc.h
46467+++ b/drivers/scsi/lpfc/lpfc.h
46468@@ -431,7 +431,7 @@ struct lpfc_vport {
46469 struct dentry *debug_nodelist;
46470 struct dentry *vport_debugfs_root;
46471 struct lpfc_debugfs_trc *disc_trc;
46472- atomic_t disc_trc_cnt;
46473+ atomic_unchecked_t disc_trc_cnt;
46474 #endif
46475 uint8_t stat_data_enabled;
46476 uint8_t stat_data_blocked;
46477@@ -865,8 +865,8 @@ struct lpfc_hba {
46478 struct timer_list fabric_block_timer;
46479 unsigned long bit_flags;
46480 #define FABRIC_COMANDS_BLOCKED 0
46481- atomic_t num_rsrc_err;
46482- atomic_t num_cmd_success;
46483+ atomic_unchecked_t num_rsrc_err;
46484+ atomic_unchecked_t num_cmd_success;
46485 unsigned long last_rsrc_error_time;
46486 unsigned long last_ramp_down_time;
46487 unsigned long last_ramp_up_time;
46488@@ -902,7 +902,7 @@ struct lpfc_hba {
46489
46490 struct dentry *debug_slow_ring_trc;
46491 struct lpfc_debugfs_trc *slow_ring_trc;
46492- atomic_t slow_ring_trc_cnt;
46493+ atomic_unchecked_t slow_ring_trc_cnt;
46494 /* iDiag debugfs sub-directory */
46495 struct dentry *idiag_root;
46496 struct dentry *idiag_pci_cfg;
46497diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
46498index 60084e6..0e2e700 100644
46499--- a/drivers/scsi/lpfc/lpfc_debugfs.c
46500+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
46501@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
46502
46503 #include <linux/debugfs.h>
46504
46505-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
46506+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
46507 static unsigned long lpfc_debugfs_start_time = 0L;
46508
46509 /* iDiag */
46510@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
46511 lpfc_debugfs_enable = 0;
46512
46513 len = 0;
46514- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
46515+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
46516 (lpfc_debugfs_max_disc_trc - 1);
46517 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
46518 dtp = vport->disc_trc + i;
46519@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
46520 lpfc_debugfs_enable = 0;
46521
46522 len = 0;
46523- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
46524+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
46525 (lpfc_debugfs_max_slow_ring_trc - 1);
46526 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
46527 dtp = phba->slow_ring_trc + i;
46528@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
46529 !vport || !vport->disc_trc)
46530 return;
46531
46532- index = atomic_inc_return(&vport->disc_trc_cnt) &
46533+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
46534 (lpfc_debugfs_max_disc_trc - 1);
46535 dtp = vport->disc_trc + index;
46536 dtp->fmt = fmt;
46537 dtp->data1 = data1;
46538 dtp->data2 = data2;
46539 dtp->data3 = data3;
46540- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
46541+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
46542 dtp->jif = jiffies;
46543 #endif
46544 return;
46545@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
46546 !phba || !phba->slow_ring_trc)
46547 return;
46548
46549- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
46550+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
46551 (lpfc_debugfs_max_slow_ring_trc - 1);
46552 dtp = phba->slow_ring_trc + index;
46553 dtp->fmt = fmt;
46554 dtp->data1 = data1;
46555 dtp->data2 = data2;
46556 dtp->data3 = data3;
46557- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
46558+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
46559 dtp->jif = jiffies;
46560 #endif
46561 return;
46562@@ -4168,7 +4168,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
46563 "slow_ring buffer\n");
46564 goto debug_failed;
46565 }
46566- atomic_set(&phba->slow_ring_trc_cnt, 0);
46567+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
46568 memset(phba->slow_ring_trc, 0,
46569 (sizeof(struct lpfc_debugfs_trc) *
46570 lpfc_debugfs_max_slow_ring_trc));
46571@@ -4214,7 +4214,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
46572 "buffer\n");
46573 goto debug_failed;
46574 }
46575- atomic_set(&vport->disc_trc_cnt, 0);
46576+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
46577
46578 snprintf(name, sizeof(name), "discovery_trace");
46579 vport->debug_disc_trc =
46580diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
46581index e0b20fa..30c2c0d 100644
46582--- a/drivers/scsi/lpfc/lpfc_init.c
46583+++ b/drivers/scsi/lpfc/lpfc_init.c
46584@@ -10936,8 +10936,10 @@ lpfc_init(void)
46585 "misc_register returned with status %d", error);
46586
46587 if (lpfc_enable_npiv) {
46588- lpfc_transport_functions.vport_create = lpfc_vport_create;
46589- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
46590+ pax_open_kernel();
46591+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
46592+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
46593+ pax_close_kernel();
46594 }
46595 lpfc_transport_template =
46596 fc_attach_transport(&lpfc_transport_functions);
46597diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
46598index 243de1d..f40e3e5 100644
46599--- a/drivers/scsi/lpfc/lpfc_scsi.c
46600+++ b/drivers/scsi/lpfc/lpfc_scsi.c
46601@@ -353,7 +353,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
46602 uint32_t evt_posted;
46603
46604 spin_lock_irqsave(&phba->hbalock, flags);
46605- atomic_inc(&phba->num_rsrc_err);
46606+ atomic_inc_unchecked(&phba->num_rsrc_err);
46607 phba->last_rsrc_error_time = jiffies;
46608
46609 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
46610@@ -394,7 +394,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
46611 unsigned long flags;
46612 struct lpfc_hba *phba = vport->phba;
46613 uint32_t evt_posted;
46614- atomic_inc(&phba->num_cmd_success);
46615+ atomic_inc_unchecked(&phba->num_cmd_success);
46616
46617 if (vport->cfg_lun_queue_depth <= queue_depth)
46618 return;
46619@@ -438,8 +438,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
46620 unsigned long num_rsrc_err, num_cmd_success;
46621 int i;
46622
46623- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
46624- num_cmd_success = atomic_read(&phba->num_cmd_success);
46625+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
46626+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
46627
46628 /*
46629 * The error and success command counters are global per
46630@@ -467,8 +467,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
46631 }
46632 }
46633 lpfc_destroy_vport_work_array(phba, vports);
46634- atomic_set(&phba->num_rsrc_err, 0);
46635- atomic_set(&phba->num_cmd_success, 0);
46636+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
46637+ atomic_set_unchecked(&phba->num_cmd_success, 0);
46638 }
46639
46640 /**
46641@@ -502,8 +502,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
46642 }
46643 }
46644 lpfc_destroy_vport_work_array(phba, vports);
46645- atomic_set(&phba->num_rsrc_err, 0);
46646- atomic_set(&phba->num_cmd_success, 0);
46647+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
46648+ atomic_set_unchecked(&phba->num_cmd_success, 0);
46649 }
46650
46651 /**
46652diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
46653index 1eb7b028..b2a6080 100644
46654--- a/drivers/scsi/pmcraid.c
46655+++ b/drivers/scsi/pmcraid.c
46656@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
46657 res->scsi_dev = scsi_dev;
46658 scsi_dev->hostdata = res;
46659 res->change_detected = 0;
46660- atomic_set(&res->read_failures, 0);
46661- atomic_set(&res->write_failures, 0);
46662+ atomic_set_unchecked(&res->read_failures, 0);
46663+ atomic_set_unchecked(&res->write_failures, 0);
46664 rc = 0;
46665 }
46666 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
46667@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
46668
46669 /* If this was a SCSI read/write command keep count of errors */
46670 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
46671- atomic_inc(&res->read_failures);
46672+ atomic_inc_unchecked(&res->read_failures);
46673 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
46674- atomic_inc(&res->write_failures);
46675+ atomic_inc_unchecked(&res->write_failures);
46676
46677 if (!RES_IS_GSCSI(res->cfg_entry) &&
46678 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
46679@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
46680 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
46681 * hrrq_id assigned here in queuecommand
46682 */
46683- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
46684+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
46685 pinstance->num_hrrq;
46686 cmd->cmd_done = pmcraid_io_done;
46687
46688@@ -3846,7 +3846,7 @@ static long pmcraid_ioctl_passthrough(
46689 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
46690 * hrrq_id assigned here in queuecommand
46691 */
46692- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
46693+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
46694 pinstance->num_hrrq;
46695
46696 if (request_size) {
46697@@ -4483,7 +4483,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
46698
46699 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
46700 /* add resources only after host is added into system */
46701- if (!atomic_read(&pinstance->expose_resources))
46702+ if (!atomic_read_unchecked(&pinstance->expose_resources))
46703 return;
46704
46705 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
46706@@ -5310,8 +5310,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
46707 init_waitqueue_head(&pinstance->reset_wait_q);
46708
46709 atomic_set(&pinstance->outstanding_cmds, 0);
46710- atomic_set(&pinstance->last_message_id, 0);
46711- atomic_set(&pinstance->expose_resources, 0);
46712+ atomic_set_unchecked(&pinstance->last_message_id, 0);
46713+ atomic_set_unchecked(&pinstance->expose_resources, 0);
46714
46715 INIT_LIST_HEAD(&pinstance->free_res_q);
46716 INIT_LIST_HEAD(&pinstance->used_res_q);
46717@@ -6024,7 +6024,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
46718 /* Schedule worker thread to handle CCN and take care of adding and
46719 * removing devices to OS
46720 */
46721- atomic_set(&pinstance->expose_resources, 1);
46722+ atomic_set_unchecked(&pinstance->expose_resources, 1);
46723 schedule_work(&pinstance->worker_q);
46724 return rc;
46725
46726diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
46727index e1d150f..6c6df44 100644
46728--- a/drivers/scsi/pmcraid.h
46729+++ b/drivers/scsi/pmcraid.h
46730@@ -748,7 +748,7 @@ struct pmcraid_instance {
46731 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
46732
46733 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
46734- atomic_t last_message_id;
46735+ atomic_unchecked_t last_message_id;
46736
46737 /* configuration table */
46738 struct pmcraid_config_table *cfg_table;
46739@@ -777,7 +777,7 @@ struct pmcraid_instance {
46740 atomic_t outstanding_cmds;
46741
46742 /* should add/delete resources to mid-layer now ?*/
46743- atomic_t expose_resources;
46744+ atomic_unchecked_t expose_resources;
46745
46746
46747
46748@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
46749 struct pmcraid_config_table_entry_ext cfg_entry_ext;
46750 };
46751 struct scsi_device *scsi_dev; /* Link scsi_device structure */
46752- atomic_t read_failures; /* count of failed READ commands */
46753- atomic_t write_failures; /* count of failed WRITE commands */
46754+ atomic_unchecked_t read_failures; /* count of failed READ commands */
46755+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
46756
46757 /* To indicate add/delete/modify during CCN */
46758 u8 change_detected;
46759diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
46760index d7a99ae..801df70 100644
46761--- a/drivers/scsi/qla2xxx/qla_attr.c
46762+++ b/drivers/scsi/qla2xxx/qla_attr.c
46763@@ -2004,7 +2004,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
46764 return 0;
46765 }
46766
46767-struct fc_function_template qla2xxx_transport_functions = {
46768+fc_function_template_no_const qla2xxx_transport_functions = {
46769
46770 .show_host_node_name = 1,
46771 .show_host_port_name = 1,
46772@@ -2051,7 +2051,7 @@ struct fc_function_template qla2xxx_transport_functions = {
46773 .bsg_timeout = qla24xx_bsg_timeout,
46774 };
46775
46776-struct fc_function_template qla2xxx_transport_vport_functions = {
46777+fc_function_template_no_const qla2xxx_transport_vport_functions = {
46778
46779 .show_host_node_name = 1,
46780 .show_host_port_name = 1,
46781diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
46782index 2d98232..a84298e 100644
46783--- a/drivers/scsi/qla2xxx/qla_gbl.h
46784+++ b/drivers/scsi/qla2xxx/qla_gbl.h
46785@@ -528,8 +528,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
46786 struct device_attribute;
46787 extern struct device_attribute *qla2x00_host_attrs[];
46788 struct fc_function_template;
46789-extern struct fc_function_template qla2xxx_transport_functions;
46790-extern struct fc_function_template qla2xxx_transport_vport_functions;
46791+extern fc_function_template_no_const qla2xxx_transport_functions;
46792+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
46793 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
46794 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
46795 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
46796diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
46797index 3e21e9f..426ba79 100644
46798--- a/drivers/scsi/qla2xxx/qla_os.c
46799+++ b/drivers/scsi/qla2xxx/qla_os.c
46800@@ -1570,8 +1570,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
46801 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
46802 /* Ok, a 64bit DMA mask is applicable. */
46803 ha->flags.enable_64bit_addressing = 1;
46804- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
46805- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
46806+ pax_open_kernel();
46807+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
46808+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
46809+ pax_close_kernel();
46810 return;
46811 }
46812 }
46813diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
46814index ddf16a8..80f4dd0 100644
46815--- a/drivers/scsi/qla4xxx/ql4_def.h
46816+++ b/drivers/scsi/qla4xxx/ql4_def.h
46817@@ -291,7 +291,7 @@ struct ddb_entry {
46818 * (4000 only) */
46819 atomic_t relogin_timer; /* Max Time to wait for
46820 * relogin to complete */
46821- atomic_t relogin_retry_count; /* Num of times relogin has been
46822+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
46823 * retried */
46824 uint32_t default_time2wait; /* Default Min time between
46825 * relogins (+aens) */
46826diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
46827index b246b3c..897004d 100644
46828--- a/drivers/scsi/qla4xxx/ql4_os.c
46829+++ b/drivers/scsi/qla4xxx/ql4_os.c
46830@@ -2971,12 +2971,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
46831 */
46832 if (!iscsi_is_session_online(cls_sess)) {
46833 /* Reset retry relogin timer */
46834- atomic_inc(&ddb_entry->relogin_retry_count);
46835+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
46836 DEBUG2(ql4_printk(KERN_INFO, ha,
46837 "%s: index[%d] relogin timed out-retrying"
46838 " relogin (%d), retry (%d)\n", __func__,
46839 ddb_entry->fw_ddb_index,
46840- atomic_read(&ddb_entry->relogin_retry_count),
46841+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
46842 ddb_entry->default_time2wait + 4));
46843 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
46844 atomic_set(&ddb_entry->retry_relogin_timer,
46845@@ -5081,7 +5081,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
46846
46847 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
46848 atomic_set(&ddb_entry->relogin_timer, 0);
46849- atomic_set(&ddb_entry->relogin_retry_count, 0);
46850+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
46851 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
46852 ddb_entry->default_relogin_timeout =
46853 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
46854diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
46855index eaa808e..95f8841 100644
46856--- a/drivers/scsi/scsi.c
46857+++ b/drivers/scsi/scsi.c
46858@@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
46859 unsigned long timeout;
46860 int rtn = 0;
46861
46862- atomic_inc(&cmd->device->iorequest_cnt);
46863+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
46864
46865 /* check if the device is still usable */
46866 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
46867diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
46868index 124392f..75eb43e 100644
46869--- a/drivers/scsi/scsi_lib.c
46870+++ b/drivers/scsi/scsi_lib.c
46871@@ -1474,7 +1474,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
46872 shost = sdev->host;
46873 scsi_init_cmd_errh(cmd);
46874 cmd->result = DID_NO_CONNECT << 16;
46875- atomic_inc(&cmd->device->iorequest_cnt);
46876+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
46877
46878 /*
46879 * SCSI request completion path will do scsi_device_unbusy(),
46880@@ -1500,9 +1500,9 @@ static void scsi_softirq_done(struct request *rq)
46881
46882 INIT_LIST_HEAD(&cmd->eh_entry);
46883
46884- atomic_inc(&cmd->device->iodone_cnt);
46885+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
46886 if (cmd->result)
46887- atomic_inc(&cmd->device->ioerr_cnt);
46888+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
46889
46890 disposition = scsi_decide_disposition(cmd);
46891 if (disposition != SUCCESS &&
46892diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
46893index 7e50061..71db7a6 100644
46894--- a/drivers/scsi/scsi_sysfs.c
46895+++ b/drivers/scsi/scsi_sysfs.c
46896@@ -687,7 +687,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
46897 char *buf) \
46898 { \
46899 struct scsi_device *sdev = to_scsi_device(dev); \
46900- unsigned long long count = atomic_read(&sdev->field); \
46901+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
46902 return snprintf(buf, 20, "0x%llx\n", count); \
46903 } \
46904 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
46905diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
46906index 84a1fdf..693b0d6 100644
46907--- a/drivers/scsi/scsi_tgt_lib.c
46908+++ b/drivers/scsi/scsi_tgt_lib.c
46909@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
46910 int err;
46911
46912 dprintk("%lx %u\n", uaddr, len);
46913- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
46914+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
46915 if (err) {
46916 /*
46917 * TODO: need to fixup sg_tablesize, max_segment_size,
46918diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
46919index 4628fd5..a94a1c2 100644
46920--- a/drivers/scsi/scsi_transport_fc.c
46921+++ b/drivers/scsi/scsi_transport_fc.c
46922@@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
46923 * Netlink Infrastructure
46924 */
46925
46926-static atomic_t fc_event_seq;
46927+static atomic_unchecked_t fc_event_seq;
46928
46929 /**
46930 * fc_get_event_number - Obtain the next sequential FC event number
46931@@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
46932 u32
46933 fc_get_event_number(void)
46934 {
46935- return atomic_add_return(1, &fc_event_seq);
46936+ return atomic_add_return_unchecked(1, &fc_event_seq);
46937 }
46938 EXPORT_SYMBOL(fc_get_event_number);
46939
46940@@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
46941 {
46942 int error;
46943
46944- atomic_set(&fc_event_seq, 0);
46945+ atomic_set_unchecked(&fc_event_seq, 0);
46946
46947 error = transport_class_register(&fc_host_class);
46948 if (error)
46949@@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
46950 char *cp;
46951
46952 *val = simple_strtoul(buf, &cp, 0);
46953- if ((*cp && (*cp != '\n')) || (*val < 0))
46954+ if (*cp && (*cp != '\n'))
46955 return -EINVAL;
46956 /*
46957 * Check for overflow; dev_loss_tmo is u32
46958diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
46959index abf7c40..c3240ed 100644
46960--- a/drivers/scsi/scsi_transport_iscsi.c
46961+++ b/drivers/scsi/scsi_transport_iscsi.c
46962@@ -80,7 +80,7 @@ struct iscsi_internal {
46963 struct transport_container session_cont;
46964 };
46965
46966-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
46967+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
46968 static struct workqueue_struct *iscsi_eh_timer_workq;
46969
46970 static DEFINE_IDA(iscsi_sess_ida);
46971@@ -1738,7 +1738,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
46972 int err;
46973
46974 ihost = shost->shost_data;
46975- session->sid = atomic_add_return(1, &iscsi_session_nr);
46976+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
46977
46978 if (target_id == ISCSI_MAX_TARGET) {
46979 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
46980@@ -3956,7 +3956,7 @@ static __init int iscsi_transport_init(void)
46981 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
46982 ISCSI_TRANSPORT_VERSION);
46983
46984- atomic_set(&iscsi_session_nr, 0);
46985+ atomic_set_unchecked(&iscsi_session_nr, 0);
46986
46987 err = class_register(&iscsi_transport_class);
46988 if (err)
46989diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
46990index f379c7f..e8fc69c 100644
46991--- a/drivers/scsi/scsi_transport_srp.c
46992+++ b/drivers/scsi/scsi_transport_srp.c
46993@@ -33,7 +33,7 @@
46994 #include "scsi_transport_srp_internal.h"
46995
46996 struct srp_host_attrs {
46997- atomic_t next_port_id;
46998+ atomic_unchecked_t next_port_id;
46999 };
47000 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
47001
47002@@ -61,7 +61,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
47003 struct Scsi_Host *shost = dev_to_shost(dev);
47004 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
47005
47006- atomic_set(&srp_host->next_port_id, 0);
47007+ atomic_set_unchecked(&srp_host->next_port_id, 0);
47008 return 0;
47009 }
47010
47011@@ -210,7 +210,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
47012 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
47013 rport->roles = ids->roles;
47014
47015- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
47016+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
47017 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
47018
47019 transport_setup_device(&rport->dev);
47020diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
47021index 2783dd7..d20395b 100644
47022--- a/drivers/scsi/sd.c
47023+++ b/drivers/scsi/sd.c
47024@@ -2933,7 +2933,7 @@ static int sd_probe(struct device *dev)
47025 sdkp->disk = gd;
47026 sdkp->index = index;
47027 atomic_set(&sdkp->openers, 0);
47028- atomic_set(&sdkp->device->ioerr_cnt, 0);
47029+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
47030
47031 if (!sdp->request_queue->rq_timeout) {
47032 if (sdp->type != TYPE_MOD)
47033diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
47034index df5e961..df6b97f 100644
47035--- a/drivers/scsi/sg.c
47036+++ b/drivers/scsi/sg.c
47037@@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
47038 sdp->disk->disk_name,
47039 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
47040 NULL,
47041- (char *)arg);
47042+ (char __user *)arg);
47043 case BLKTRACESTART:
47044 return blk_trace_startstop(sdp->device->request_queue, 1);
47045 case BLKTRACESTOP:
47046diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
47047index 978dda2..cb19aa0 100644
47048--- a/drivers/spi/spi.c
47049+++ b/drivers/spi/spi.c
47050@@ -1631,7 +1631,7 @@ int spi_bus_unlock(struct spi_master *master)
47051 EXPORT_SYMBOL_GPL(spi_bus_unlock);
47052
47053 /* portable code must never pass more than 32 bytes */
47054-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
47055+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
47056
47057 static u8 *buf;
47058
47059diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
47060index ee3a57f..18368c1 100644
47061--- a/drivers/staging/android/timed_output.c
47062+++ b/drivers/staging/android/timed_output.c
47063@@ -25,7 +25,7 @@
47064 #include "timed_output.h"
47065
47066 static struct class *timed_output_class;
47067-static atomic_t device_count;
47068+static atomic_unchecked_t device_count;
47069
47070 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
47071 char *buf)
47072@@ -59,7 +59,7 @@ static int create_timed_output_class(void)
47073 timed_output_class = class_create(THIS_MODULE, "timed_output");
47074 if (IS_ERR(timed_output_class))
47075 return PTR_ERR(timed_output_class);
47076- atomic_set(&device_count, 0);
47077+ atomic_set_unchecked(&device_count, 0);
47078 }
47079
47080 return 0;
47081@@ -76,7 +76,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
47082 if (ret < 0)
47083 return ret;
47084
47085- tdev->index = atomic_inc_return(&device_count);
47086+ tdev->index = atomic_inc_return_unchecked(&device_count);
47087 tdev->dev = device_create(timed_output_class, NULL,
47088 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
47089 if (IS_ERR(tdev->dev))
47090diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
47091index 3675020..e80d92c 100644
47092--- a/drivers/staging/media/solo6x10/solo6x10-core.c
47093+++ b/drivers/staging/media/solo6x10/solo6x10-core.c
47094@@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
47095
47096 static int solo_sysfs_init(struct solo_dev *solo_dev)
47097 {
47098- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
47099+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
47100 struct device *dev = &solo_dev->dev;
47101 const char *driver;
47102 int i;
47103diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
47104index 3335941..2b26186 100644
47105--- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
47106+++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
47107@@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
47108
47109 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
47110 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
47111- p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
47112+ p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
47113 if (p2m_id < 0)
47114 p2m_id = -p2m_id;
47115 }
47116diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
47117index 6f91d2e..3f011d2 100644
47118--- a/drivers/staging/media/solo6x10/solo6x10.h
47119+++ b/drivers/staging/media/solo6x10/solo6x10.h
47120@@ -238,7 +238,7 @@ struct solo_dev {
47121
47122 /* P2M DMA Engine */
47123 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
47124- atomic_t p2m_count;
47125+ atomic_unchecked_t p2m_count;
47126 int p2m_jiffies;
47127 unsigned int p2m_timeouts;
47128
47129diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
47130index 34afc16..ffe44dd 100644
47131--- a/drivers/staging/octeon/ethernet-rx.c
47132+++ b/drivers/staging/octeon/ethernet-rx.c
47133@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
47134 /* Increment RX stats for virtual ports */
47135 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
47136 #ifdef CONFIG_64BIT
47137- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
47138- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
47139+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
47140+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
47141 #else
47142- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
47143- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
47144+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
47145+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
47146 #endif
47147 }
47148 netif_receive_skb(skb);
47149@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
47150 dev->name);
47151 */
47152 #ifdef CONFIG_64BIT
47153- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
47154+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
47155 #else
47156- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
47157+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
47158 #endif
47159 dev_kfree_skb_irq(skb);
47160 }
47161diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
47162index c3a90e7..023619a 100644
47163--- a/drivers/staging/octeon/ethernet.c
47164+++ b/drivers/staging/octeon/ethernet.c
47165@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
47166 * since the RX tasklet also increments it.
47167 */
47168 #ifdef CONFIG_64BIT
47169- atomic64_add(rx_status.dropped_packets,
47170- (atomic64_t *)&priv->stats.rx_dropped);
47171+ atomic64_add_unchecked(rx_status.dropped_packets,
47172+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
47173 #else
47174- atomic_add(rx_status.dropped_packets,
47175- (atomic_t *)&priv->stats.rx_dropped);
47176+ atomic_add_unchecked(rx_status.dropped_packets,
47177+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
47178 #endif
47179 }
47180
47181diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
47182index dc23395..cf7e9b1 100644
47183--- a/drivers/staging/rtl8712/rtl871x_io.h
47184+++ b/drivers/staging/rtl8712/rtl871x_io.h
47185@@ -108,7 +108,7 @@ struct _io_ops {
47186 u8 *pmem);
47187 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
47188 u8 *pmem);
47189-};
47190+} __no_const;
47191
47192 struct io_req {
47193 struct list_head list;
47194diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
47195index 1f5088b..0e59820 100644
47196--- a/drivers/staging/sbe-2t3e3/netdev.c
47197+++ b/drivers/staging/sbe-2t3e3/netdev.c
47198@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
47199 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
47200
47201 if (rlen)
47202- if (copy_to_user(data, &resp, rlen))
47203+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
47204 return -EFAULT;
47205
47206 return 0;
47207diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
47208index a863a98..d272795 100644
47209--- a/drivers/staging/usbip/vhci.h
47210+++ b/drivers/staging/usbip/vhci.h
47211@@ -83,7 +83,7 @@ struct vhci_hcd {
47212 unsigned resuming:1;
47213 unsigned long re_timeout;
47214
47215- atomic_t seqnum;
47216+ atomic_unchecked_t seqnum;
47217
47218 /*
47219 * NOTE:
47220diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
47221index d7974cb..d78076b 100644
47222--- a/drivers/staging/usbip/vhci_hcd.c
47223+++ b/drivers/staging/usbip/vhci_hcd.c
47224@@ -441,7 +441,7 @@ static void vhci_tx_urb(struct urb *urb)
47225
47226 spin_lock(&vdev->priv_lock);
47227
47228- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
47229+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
47230 if (priv->seqnum == 0xffff)
47231 dev_info(&urb->dev->dev, "seqnum max\n");
47232
47233@@ -687,7 +687,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
47234 return -ENOMEM;
47235 }
47236
47237- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
47238+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
47239 if (unlink->seqnum == 0xffff)
47240 pr_info("seqnum max\n");
47241
47242@@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
47243 vdev->rhport = rhport;
47244 }
47245
47246- atomic_set(&vhci->seqnum, 0);
47247+ atomic_set_unchecked(&vhci->seqnum, 0);
47248 spin_lock_init(&vhci->lock);
47249
47250 hcd->power_budget = 0; /* no limit */
47251diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
47252index d07fcb5..358e1e1 100644
47253--- a/drivers/staging/usbip/vhci_rx.c
47254+++ b/drivers/staging/usbip/vhci_rx.c
47255@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
47256 if (!urb) {
47257 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
47258 pr_info("max seqnum %d\n",
47259- atomic_read(&the_controller->seqnum));
47260+ atomic_read_unchecked(&the_controller->seqnum));
47261 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
47262 return;
47263 }
47264diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
47265index 57a08c5..5b4bb7c 100644
47266--- a/drivers/staging/vt6655/hostap.c
47267+++ b/drivers/staging/vt6655/hostap.c
47268@@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
47269 *
47270 */
47271
47272+static net_device_ops_no_const apdev_netdev_ops;
47273+
47274 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
47275 {
47276 PSDevice apdev_priv;
47277 struct net_device *dev = pDevice->dev;
47278 int ret;
47279- const struct net_device_ops apdev_netdev_ops = {
47280- .ndo_start_xmit = pDevice->tx_80211,
47281- };
47282
47283 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
47284
47285@@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
47286 *apdev_priv = *pDevice;
47287 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
47288
47289+ /* only half broken now */
47290+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
47291 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
47292
47293 pDevice->apdev->type = ARPHRD_IEEE80211;
47294diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
47295index c699a30..b90a5fd 100644
47296--- a/drivers/staging/vt6656/hostap.c
47297+++ b/drivers/staging/vt6656/hostap.c
47298@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
47299 *
47300 */
47301
47302+static net_device_ops_no_const apdev_netdev_ops;
47303+
47304 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
47305 {
47306 struct vnt_private *apdev_priv;
47307 struct net_device *dev = pDevice->dev;
47308 int ret;
47309- const struct net_device_ops apdev_netdev_ops = {
47310- .ndo_start_xmit = pDevice->tx_80211,
47311- };
47312
47313 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
47314
47315@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
47316 *apdev_priv = *pDevice;
47317 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
47318
47319+ /* only half broken now */
47320+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
47321 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
47322
47323 pDevice->apdev->type = ARPHRD_IEEE80211;
47324diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
47325index d128ce2..fc1f9a1 100644
47326--- a/drivers/staging/zcache/tmem.h
47327+++ b/drivers/staging/zcache/tmem.h
47328@@ -225,7 +225,7 @@ struct tmem_pamops {
47329 bool (*is_remote)(void *);
47330 int (*replace_in_obj)(void *, struct tmem_obj *);
47331 #endif
47332-};
47333+} __no_const;
47334 extern void tmem_register_pamops(struct tmem_pamops *m);
47335
47336 /* memory allocation methods provided by the host implementation */
47337@@ -234,7 +234,7 @@ struct tmem_hostops {
47338 void (*obj_free)(struct tmem_obj *, struct tmem_pool *);
47339 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
47340 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
47341-};
47342+} __no_const;
47343 extern void tmem_register_hostops(struct tmem_hostops *m);
47344
47345 /* core tmem accessor functions */
47346diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
47347index e51b09a..5ebac31 100644
47348--- a/drivers/target/sbp/sbp_target.c
47349+++ b/drivers/target/sbp/sbp_target.c
47350@@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
47351
47352 #define SESSION_MAINTENANCE_INTERVAL HZ
47353
47354-static atomic_t login_id = ATOMIC_INIT(0);
47355+static atomic_unchecked_t login_id = ATOMIC_INIT(0);
47356
47357 static void session_maintenance_work(struct work_struct *);
47358 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
47359@@ -444,7 +444,7 @@ static void sbp_management_request_login(
47360 login->lun = se_lun;
47361 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
47362 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
47363- login->login_id = atomic_inc_return(&login_id);
47364+ login->login_id = atomic_inc_return_unchecked(&login_id);
47365
47366 login->tgt_agt = sbp_target_agent_register(login);
47367 if (IS_ERR(login->tgt_agt)) {
47368diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
47369index 8f4142f..b127f7d 100644
47370--- a/drivers/target/target_core_device.c
47371+++ b/drivers/target/target_core_device.c
47372@@ -1400,7 +1400,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
47373 spin_lock_init(&dev->se_port_lock);
47374 spin_lock_init(&dev->se_tmr_lock);
47375 spin_lock_init(&dev->qf_cmd_lock);
47376- atomic_set(&dev->dev_ordered_id, 0);
47377+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
47378 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
47379 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
47380 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
47381diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
47382index d8e49d7..6fcfdec 100644
47383--- a/drivers/target/target_core_transport.c
47384+++ b/drivers/target/target_core_transport.c
47385@@ -1080,7 +1080,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
47386 * Used to determine when ORDERED commands should go from
47387 * Dormant to Active status.
47388 */
47389- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
47390+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
47391 smp_mb__after_atomic_inc();
47392 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
47393 cmd->se_ordered_id, cmd->sam_task_attr,
47394diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
47395index 33f83fe..d80f8e1 100644
47396--- a/drivers/tty/cyclades.c
47397+++ b/drivers/tty/cyclades.c
47398@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
47399 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
47400 info->port.count);
47401 #endif
47402- info->port.count++;
47403+ atomic_inc(&info->port.count);
47404 #ifdef CY_DEBUG_COUNT
47405 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
47406- current->pid, info->port.count);
47407+ current->pid, atomic_read(&info->port.count));
47408 #endif
47409
47410 /*
47411@@ -3972,7 +3972,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
47412 for (j = 0; j < cy_card[i].nports; j++) {
47413 info = &cy_card[i].ports[j];
47414
47415- if (info->port.count) {
47416+ if (atomic_read(&info->port.count)) {
47417 /* XXX is the ldisc num worth this? */
47418 struct tty_struct *tty;
47419 struct tty_ldisc *ld;
47420diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
47421index eb255e8..f637a57 100644
47422--- a/drivers/tty/hvc/hvc_console.c
47423+++ b/drivers/tty/hvc/hvc_console.c
47424@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
47425
47426 spin_lock_irqsave(&hp->port.lock, flags);
47427 /* Check and then increment for fast path open. */
47428- if (hp->port.count++ > 0) {
47429+ if (atomic_inc_return(&hp->port.count) > 1) {
47430 spin_unlock_irqrestore(&hp->port.lock, flags);
47431 hvc_kick();
47432 return 0;
47433@@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
47434
47435 spin_lock_irqsave(&hp->port.lock, flags);
47436
47437- if (--hp->port.count == 0) {
47438+ if (atomic_dec_return(&hp->port.count) == 0) {
47439 spin_unlock_irqrestore(&hp->port.lock, flags);
47440 /* We are done with the tty pointer now. */
47441 tty_port_tty_set(&hp->port, NULL);
47442@@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
47443 */
47444 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
47445 } else {
47446- if (hp->port.count < 0)
47447+ if (atomic_read(&hp->port.count) < 0)
47448 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
47449- hp->vtermno, hp->port.count);
47450+ hp->vtermno, atomic_read(&hp->port.count));
47451 spin_unlock_irqrestore(&hp->port.lock, flags);
47452 }
47453 }
47454@@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
47455 * open->hangup case this can be called after the final close so prevent
47456 * that from happening for now.
47457 */
47458- if (hp->port.count <= 0) {
47459+ if (atomic_read(&hp->port.count) <= 0) {
47460 spin_unlock_irqrestore(&hp->port.lock, flags);
47461 return;
47462 }
47463
47464- hp->port.count = 0;
47465+ atomic_set(&hp->port.count, 0);
47466 spin_unlock_irqrestore(&hp->port.lock, flags);
47467 tty_port_tty_set(&hp->port, NULL);
47468
47469@@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
47470 return -EPIPE;
47471
47472 /* FIXME what's this (unprotected) check for? */
47473- if (hp->port.count <= 0)
47474+ if (atomic_read(&hp->port.count) <= 0)
47475 return -EIO;
47476
47477 spin_lock_irqsave(&hp->lock, flags);
47478diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
47479index 81e939e..95ead10 100644
47480--- a/drivers/tty/hvc/hvcs.c
47481+++ b/drivers/tty/hvc/hvcs.c
47482@@ -83,6 +83,7 @@
47483 #include <asm/hvcserver.h>
47484 #include <asm/uaccess.h>
47485 #include <asm/vio.h>
47486+#include <asm/local.h>
47487
47488 /*
47489 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
47490@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
47491
47492 spin_lock_irqsave(&hvcsd->lock, flags);
47493
47494- if (hvcsd->port.count > 0) {
47495+ if (atomic_read(&hvcsd->port.count) > 0) {
47496 spin_unlock_irqrestore(&hvcsd->lock, flags);
47497 printk(KERN_INFO "HVCS: vterm state unchanged. "
47498 "The hvcs device node is still in use.\n");
47499@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
47500 }
47501 }
47502
47503- hvcsd->port.count = 0;
47504+ atomic_set(&hvcsd->port.count, 0);
47505 hvcsd->port.tty = tty;
47506 tty->driver_data = hvcsd;
47507
47508@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
47509 unsigned long flags;
47510
47511 spin_lock_irqsave(&hvcsd->lock, flags);
47512- hvcsd->port.count++;
47513+ atomic_inc(&hvcsd->port.count);
47514 hvcsd->todo_mask |= HVCS_SCHED_READ;
47515 spin_unlock_irqrestore(&hvcsd->lock, flags);
47516
47517@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
47518 hvcsd = tty->driver_data;
47519
47520 spin_lock_irqsave(&hvcsd->lock, flags);
47521- if (--hvcsd->port.count == 0) {
47522+ if (atomic_dec_and_test(&hvcsd->port.count)) {
47523
47524 vio_disable_interrupts(hvcsd->vdev);
47525
47526@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
47527
47528 free_irq(irq, hvcsd);
47529 return;
47530- } else if (hvcsd->port.count < 0) {
47531+ } else if (atomic_read(&hvcsd->port.count) < 0) {
47532 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
47533 " is missmanaged.\n",
47534- hvcsd->vdev->unit_address, hvcsd->port.count);
47535+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
47536 }
47537
47538 spin_unlock_irqrestore(&hvcsd->lock, flags);
47539@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
47540
47541 spin_lock_irqsave(&hvcsd->lock, flags);
47542 /* Preserve this so that we know how many kref refs to put */
47543- temp_open_count = hvcsd->port.count;
47544+ temp_open_count = atomic_read(&hvcsd->port.count);
47545
47546 /*
47547 * Don't kref put inside the spinlock because the destruction
47548@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
47549 tty->driver_data = NULL;
47550 hvcsd->port.tty = NULL;
47551
47552- hvcsd->port.count = 0;
47553+ atomic_set(&hvcsd->port.count, 0);
47554
47555 /* This will drop any buffered data on the floor which is OK in a hangup
47556 * scenario. */
47557@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
47558 * the middle of a write operation? This is a crummy place to do this
47559 * but we want to keep it all in the spinlock.
47560 */
47561- if (hvcsd->port.count <= 0) {
47562+ if (atomic_read(&hvcsd->port.count) <= 0) {
47563 spin_unlock_irqrestore(&hvcsd->lock, flags);
47564 return -ENODEV;
47565 }
47566@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
47567 {
47568 struct hvcs_struct *hvcsd = tty->driver_data;
47569
47570- if (!hvcsd || hvcsd->port.count <= 0)
47571+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
47572 return 0;
47573
47574 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
47575diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
47576index 4190199..48f2920 100644
47577--- a/drivers/tty/hvc/hvsi.c
47578+++ b/drivers/tty/hvc/hvsi.c
47579@@ -85,7 +85,7 @@ struct hvsi_struct {
47580 int n_outbuf;
47581 uint32_t vtermno;
47582 uint32_t virq;
47583- atomic_t seqno; /* HVSI packet sequence number */
47584+ atomic_unchecked_t seqno; /* HVSI packet sequence number */
47585 uint16_t mctrl;
47586 uint8_t state; /* HVSI protocol state */
47587 uint8_t flags;
47588@@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
47589
47590 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
47591 packet.hdr.len = sizeof(struct hvsi_query_response);
47592- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47593+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47594 packet.verb = VSV_SEND_VERSION_NUMBER;
47595 packet.u.version = HVSI_VERSION;
47596 packet.query_seqno = query_seqno+1;
47597@@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
47598
47599 packet.hdr.type = VS_QUERY_PACKET_HEADER;
47600 packet.hdr.len = sizeof(struct hvsi_query);
47601- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47602+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47603 packet.verb = verb;
47604
47605 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
47606@@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
47607 int wrote;
47608
47609 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
47610- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47611+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47612 packet.hdr.len = sizeof(struct hvsi_control);
47613 packet.verb = VSV_SET_MODEM_CTL;
47614 packet.mask = HVSI_TSDTR;
47615@@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
47616 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
47617
47618 packet.hdr.type = VS_DATA_PACKET_HEADER;
47619- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47620+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47621 packet.hdr.len = count + sizeof(struct hvsi_header);
47622 memcpy(&packet.data, buf, count);
47623
47624@@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
47625 struct hvsi_control packet __ALIGNED__;
47626
47627 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
47628- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47629+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47630 packet.hdr.len = 6;
47631 packet.verb = VSV_CLOSE_PROTOCOL;
47632
47633diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
47634index ac27671..0f627ee 100644
47635--- a/drivers/tty/hvc/hvsi_lib.c
47636+++ b/drivers/tty/hvc/hvsi_lib.c
47637@@ -9,7 +9,7 @@
47638
47639 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
47640 {
47641- packet->seqno = atomic_inc_return(&pv->seqno);
47642+ packet->seqno = atomic_inc_return_unchecked(&pv->seqno);
47643
47644 /* Assumes that always succeeds, works in practice */
47645 return pv->put_chars(pv->termno, (char *)packet, packet->len);
47646@@ -21,7 +21,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
47647
47648 /* Reset state */
47649 pv->established = 0;
47650- atomic_set(&pv->seqno, 0);
47651+ atomic_set_unchecked(&pv->seqno, 0);
47652
47653 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
47654
47655@@ -265,7 +265,7 @@ int hvsilib_read_mctrl(struct hvsi_priv *pv)
47656 pv->mctrl_update = 0;
47657 q.hdr.type = VS_QUERY_PACKET_HEADER;
47658 q.hdr.len = sizeof(struct hvsi_query);
47659- q.hdr.seqno = atomic_inc_return(&pv->seqno);
47660+ q.hdr.seqno = atomic_inc_return_unchecked(&pv->seqno);
47661 q.verb = VSV_SEND_MODEM_CTL_STATUS;
47662 rc = hvsi_send_packet(pv, &q.hdr);
47663 if (rc <= 0) {
47664diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
47665index 8fd72ff..34a0bed 100644
47666--- a/drivers/tty/ipwireless/tty.c
47667+++ b/drivers/tty/ipwireless/tty.c
47668@@ -29,6 +29,7 @@
47669 #include <linux/tty_driver.h>
47670 #include <linux/tty_flip.h>
47671 #include <linux/uaccess.h>
47672+#include <asm/local.h>
47673
47674 #include "tty.h"
47675 #include "network.h"
47676@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
47677 mutex_unlock(&tty->ipw_tty_mutex);
47678 return -ENODEV;
47679 }
47680- if (tty->port.count == 0)
47681+ if (atomic_read(&tty->port.count) == 0)
47682 tty->tx_bytes_queued = 0;
47683
47684- tty->port.count++;
47685+ atomic_inc(&tty->port.count);
47686
47687 tty->port.tty = linux_tty;
47688 linux_tty->driver_data = tty;
47689@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
47690
47691 static void do_ipw_close(struct ipw_tty *tty)
47692 {
47693- tty->port.count--;
47694-
47695- if (tty->port.count == 0) {
47696+ if (atomic_dec_return(&tty->port.count) == 0) {
47697 struct tty_struct *linux_tty = tty->port.tty;
47698
47699 if (linux_tty != NULL) {
47700@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
47701 return;
47702
47703 mutex_lock(&tty->ipw_tty_mutex);
47704- if (tty->port.count == 0) {
47705+ if (atomic_read(&tty->port.count) == 0) {
47706 mutex_unlock(&tty->ipw_tty_mutex);
47707 return;
47708 }
47709@@ -164,7 +163,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
47710
47711 mutex_lock(&tty->ipw_tty_mutex);
47712
47713- if (!tty->port.count) {
47714+ if (!atomic_read(&tty->port.count)) {
47715 mutex_unlock(&tty->ipw_tty_mutex);
47716 return;
47717 }
47718@@ -206,7 +205,7 @@ static int ipw_write(struct tty_struct *linux_tty,
47719 return -ENODEV;
47720
47721 mutex_lock(&tty->ipw_tty_mutex);
47722- if (!tty->port.count) {
47723+ if (!atomic_read(&tty->port.count)) {
47724 mutex_unlock(&tty->ipw_tty_mutex);
47725 return -EINVAL;
47726 }
47727@@ -246,7 +245,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
47728 if (!tty)
47729 return -ENODEV;
47730
47731- if (!tty->port.count)
47732+ if (!atomic_read(&tty->port.count))
47733 return -EINVAL;
47734
47735 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
47736@@ -288,7 +287,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
47737 if (!tty)
47738 return 0;
47739
47740- if (!tty->port.count)
47741+ if (!atomic_read(&tty->port.count))
47742 return 0;
47743
47744 return tty->tx_bytes_queued;
47745@@ -369,7 +368,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
47746 if (!tty)
47747 return -ENODEV;
47748
47749- if (!tty->port.count)
47750+ if (!atomic_read(&tty->port.count))
47751 return -EINVAL;
47752
47753 return get_control_lines(tty);
47754@@ -385,7 +384,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
47755 if (!tty)
47756 return -ENODEV;
47757
47758- if (!tty->port.count)
47759+ if (!atomic_read(&tty->port.count))
47760 return -EINVAL;
47761
47762 return set_control_lines(tty, set, clear);
47763@@ -399,7 +398,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
47764 if (!tty)
47765 return -ENODEV;
47766
47767- if (!tty->port.count)
47768+ if (!atomic_read(&tty->port.count))
47769 return -EINVAL;
47770
47771 /* FIXME: Exactly how is the tty object locked here .. */
47772@@ -555,7 +554,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
47773 * are gone */
47774 mutex_lock(&ttyj->ipw_tty_mutex);
47775 }
47776- while (ttyj->port.count)
47777+ while (atomic_read(&ttyj->port.count))
47778 do_ipw_close(ttyj);
47779 ipwireless_disassociate_network_ttys(network,
47780 ttyj->channel_idx);
47781diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
47782index 1deaca4..c8582d4 100644
47783--- a/drivers/tty/moxa.c
47784+++ b/drivers/tty/moxa.c
47785@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
47786 }
47787
47788 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
47789- ch->port.count++;
47790+ atomic_inc(&ch->port.count);
47791 tty->driver_data = ch;
47792 tty_port_tty_set(&ch->port, tty);
47793 mutex_lock(&ch->port.mutex);
47794diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
47795index 6422390..49003ac8 100644
47796--- a/drivers/tty/n_gsm.c
47797+++ b/drivers/tty/n_gsm.c
47798@@ -1632,7 +1632,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
47799 spin_lock_init(&dlci->lock);
47800 mutex_init(&dlci->mutex);
47801 dlci->fifo = &dlci->_fifo;
47802- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
47803+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
47804 kfree(dlci);
47805 return NULL;
47806 }
47807@@ -2932,7 +2932,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
47808 struct gsm_dlci *dlci = tty->driver_data;
47809 struct tty_port *port = &dlci->port;
47810
47811- port->count++;
47812+ atomic_inc(&port->count);
47813 dlci_get(dlci);
47814 dlci_get(dlci->gsm->dlci[0]);
47815 mux_get(dlci->gsm);
47816diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
47817index 4bf0fc0..433bd58 100644
47818--- a/drivers/tty/n_tty.c
47819+++ b/drivers/tty/n_tty.c
47820@@ -2217,6 +2217,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
47821 {
47822 *ops = tty_ldisc_N_TTY;
47823 ops->owner = NULL;
47824- ops->refcount = ops->flags = 0;
47825+ atomic_set(&ops->refcount, 0);
47826+ ops->flags = 0;
47827 }
47828 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
47829diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
47830index abfd990..5ab5da9 100644
47831--- a/drivers/tty/pty.c
47832+++ b/drivers/tty/pty.c
47833@@ -796,8 +796,10 @@ static void __init unix98_pty_init(void)
47834 panic("Couldn't register Unix98 pts driver");
47835
47836 /* Now create the /dev/ptmx special device */
47837+ pax_open_kernel();
47838 tty_default_fops(&ptmx_fops);
47839- ptmx_fops.open = ptmx_open;
47840+ *(void **)&ptmx_fops.open = ptmx_open;
47841+ pax_close_kernel();
47842
47843 cdev_init(&ptmx_cdev, &ptmx_fops);
47844 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
47845diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
47846index 354564e..fe50d9a 100644
47847--- a/drivers/tty/rocket.c
47848+++ b/drivers/tty/rocket.c
47849@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
47850 tty->driver_data = info;
47851 tty_port_tty_set(port, tty);
47852
47853- if (port->count++ == 0) {
47854+ if (atomic_inc_return(&port->count) == 1) {
47855 atomic_inc(&rp_num_ports_open);
47856
47857 #ifdef ROCKET_DEBUG_OPEN
47858@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
47859 #endif
47860 }
47861 #ifdef ROCKET_DEBUG_OPEN
47862- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
47863+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
47864 #endif
47865
47866 /*
47867@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
47868 spin_unlock_irqrestore(&info->port.lock, flags);
47869 return;
47870 }
47871- if (info->port.count)
47872+ if (atomic_read(&info->port.count))
47873 atomic_dec(&rp_num_ports_open);
47874 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
47875 spin_unlock_irqrestore(&info->port.lock, flags);
47876diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
47877index e2520ab..034e20b 100644
47878--- a/drivers/tty/serial/ioc4_serial.c
47879+++ b/drivers/tty/serial/ioc4_serial.c
47880@@ -437,7 +437,7 @@ struct ioc4_soft {
47881 } is_intr_info[MAX_IOC4_INTR_ENTS];
47882
47883 /* Number of entries active in the above array */
47884- atomic_t is_num_intrs;
47885+ atomic_unchecked_t is_num_intrs;
47886 } is_intr_type[IOC4_NUM_INTR_TYPES];
47887
47888 /* is_ir_lock must be held while
47889@@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
47890 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
47891 || (type == IOC4_OTHER_INTR_TYPE)));
47892
47893- i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
47894+ i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
47895 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
47896
47897 /* Save off the lower level interrupt handler */
47898@@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
47899
47900 soft = arg;
47901 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
47902- num_intrs = (int)atomic_read(
47903+ num_intrs = (int)atomic_read_unchecked(
47904 &soft->is_intr_type[intr_type].is_num_intrs);
47905
47906 this_mir = this_ir = pending_intrs(soft, intr_type);
47907diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
47908index 1002054..dd644a8 100644
47909--- a/drivers/tty/serial/kgdboc.c
47910+++ b/drivers/tty/serial/kgdboc.c
47911@@ -24,8 +24,9 @@
47912 #define MAX_CONFIG_LEN 40
47913
47914 static struct kgdb_io kgdboc_io_ops;
47915+static struct kgdb_io kgdboc_io_ops_console;
47916
47917-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
47918+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
47919 static int configured = -1;
47920
47921 static char config[MAX_CONFIG_LEN];
47922@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
47923 kgdboc_unregister_kbd();
47924 if (configured == 1)
47925 kgdb_unregister_io_module(&kgdboc_io_ops);
47926+ else if (configured == 2)
47927+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
47928 }
47929
47930 static int configure_kgdboc(void)
47931@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
47932 int err;
47933 char *cptr = config;
47934 struct console *cons;
47935+ int is_console = 0;
47936
47937 err = kgdboc_option_setup(config);
47938 if (err || !strlen(config) || isspace(config[0]))
47939 goto noconfig;
47940
47941 err = -ENODEV;
47942- kgdboc_io_ops.is_console = 0;
47943 kgdb_tty_driver = NULL;
47944
47945 kgdboc_use_kms = 0;
47946@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
47947 int idx;
47948 if (cons->device && cons->device(cons, &idx) == p &&
47949 idx == tty_line) {
47950- kgdboc_io_ops.is_console = 1;
47951+ is_console = 1;
47952 break;
47953 }
47954 cons = cons->next;
47955@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
47956 kgdb_tty_line = tty_line;
47957
47958 do_register:
47959- err = kgdb_register_io_module(&kgdboc_io_ops);
47960+ if (is_console) {
47961+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
47962+ configured = 2;
47963+ } else {
47964+ err = kgdb_register_io_module(&kgdboc_io_ops);
47965+ configured = 1;
47966+ }
47967 if (err)
47968 goto noconfig;
47969
47970@@ -205,8 +214,6 @@ do_register:
47971 if (err)
47972 goto nmi_con_failed;
47973
47974- configured = 1;
47975-
47976 return 0;
47977
47978 nmi_con_failed:
47979@@ -223,7 +230,7 @@ noconfig:
47980 static int __init init_kgdboc(void)
47981 {
47982 /* Already configured? */
47983- if (configured == 1)
47984+ if (configured >= 1)
47985 return 0;
47986
47987 return configure_kgdboc();
47988@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
47989 if (config[len - 1] == '\n')
47990 config[len - 1] = '\0';
47991
47992- if (configured == 1)
47993+ if (configured >= 1)
47994 cleanup_kgdboc();
47995
47996 /* Go and configure with the new params. */
47997@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
47998 .post_exception = kgdboc_post_exp_handler,
47999 };
48000
48001+static struct kgdb_io kgdboc_io_ops_console = {
48002+ .name = "kgdboc",
48003+ .read_char = kgdboc_get_char,
48004+ .write_char = kgdboc_put_char,
48005+ .pre_exception = kgdboc_pre_exp_handler,
48006+ .post_exception = kgdboc_post_exp_handler,
48007+ .is_console = 1
48008+};
48009+
48010 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
48011 /* This is only available if kgdboc is a built in for early debugging */
48012 static int __init kgdboc_early_init(char *opt)
48013diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
48014index 2c6cfb3..048274e 100644
48015--- a/drivers/tty/serial/msm_serial.c
48016+++ b/drivers/tty/serial/msm_serial.c
48017@@ -857,7 +857,7 @@ static struct uart_driver msm_uart_driver = {
48018 .cons = MSM_CONSOLE,
48019 };
48020
48021-static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
48022+static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
48023
48024 static int __init msm_serial_probe(struct platform_device *pdev)
48025 {
48026@@ -867,7 +867,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
48027 int irq;
48028
48029 if (pdev->id == -1)
48030- pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
48031+ pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
48032
48033 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
48034 return -ENXIO;
48035diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
48036index 376079b..d8de7aa 100644
48037--- a/drivers/tty/serial/samsung.c
48038+++ b/drivers/tty/serial/samsung.c
48039@@ -453,11 +453,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
48040 }
48041 }
48042
48043+static int s3c64xx_serial_startup(struct uart_port *port);
48044 static int s3c24xx_serial_startup(struct uart_port *port)
48045 {
48046 struct s3c24xx_uart_port *ourport = to_ourport(port);
48047 int ret;
48048
48049+ /* Startup sequence is different for s3c64xx and higher SoC's */
48050+ if (s3c24xx_serial_has_interrupt_mask(port))
48051+ return s3c64xx_serial_startup(port);
48052+
48053 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
48054 port->mapbase, port->membase);
48055
48056@@ -1124,10 +1129,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
48057 /* setup info for port */
48058 port->dev = &platdev->dev;
48059
48060- /* Startup sequence is different for s3c64xx and higher SoC's */
48061- if (s3c24xx_serial_has_interrupt_mask(port))
48062- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
48063-
48064 port->uartclk = 1;
48065
48066 if (cfg->uart_flags & UPF_CONS_FLOW) {
48067diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
48068index 28cdd28..56f1d60 100644
48069--- a/drivers/tty/serial/serial_core.c
48070+++ b/drivers/tty/serial/serial_core.c
48071@@ -1448,7 +1448,7 @@ static void uart_hangup(struct tty_struct *tty)
48072 uart_flush_buffer(tty);
48073 uart_shutdown(tty, state);
48074 spin_lock_irqsave(&port->lock, flags);
48075- port->count = 0;
48076+ atomic_set(&port->count, 0);
48077 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
48078 spin_unlock_irqrestore(&port->lock, flags);
48079 tty_port_tty_set(port, NULL);
48080@@ -1544,7 +1544,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
48081 goto end;
48082 }
48083
48084- port->count++;
48085+ atomic_inc(&port->count);
48086 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
48087 retval = -ENXIO;
48088 goto err_dec_count;
48089@@ -1572,7 +1572,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
48090 /*
48091 * Make sure the device is in D0 state.
48092 */
48093- if (port->count == 1)
48094+ if (atomic_read(&port->count) == 1)
48095 uart_change_pm(state, UART_PM_STATE_ON);
48096
48097 /*
48098@@ -1590,7 +1590,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
48099 end:
48100 return retval;
48101 err_dec_count:
48102- port->count--;
48103+ atomic_inc(&port->count);
48104 mutex_unlock(&port->mutex);
48105 goto end;
48106 }
48107diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
48108index 8eaf1ab..85c030d 100644
48109--- a/drivers/tty/synclink.c
48110+++ b/drivers/tty/synclink.c
48111@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
48112
48113 if (debug_level >= DEBUG_LEVEL_INFO)
48114 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
48115- __FILE__,__LINE__, info->device_name, info->port.count);
48116+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
48117
48118 if (tty_port_close_start(&info->port, tty, filp) == 0)
48119 goto cleanup;
48120@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
48121 cleanup:
48122 if (debug_level >= DEBUG_LEVEL_INFO)
48123 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
48124- tty->driver->name, info->port.count);
48125+ tty->driver->name, atomic_read(&info->port.count));
48126
48127 } /* end of mgsl_close() */
48128
48129@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
48130
48131 mgsl_flush_buffer(tty);
48132 shutdown(info);
48133-
48134- info->port.count = 0;
48135+
48136+ atomic_set(&info->port.count, 0);
48137 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48138 info->port.tty = NULL;
48139
48140@@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48141
48142 if (debug_level >= DEBUG_LEVEL_INFO)
48143 printk("%s(%d):block_til_ready before block on %s count=%d\n",
48144- __FILE__,__LINE__, tty->driver->name, port->count );
48145+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48146
48147 spin_lock_irqsave(&info->irq_spinlock, flags);
48148 if (!tty_hung_up_p(filp)) {
48149 extra_count = true;
48150- port->count--;
48151+ atomic_dec(&port->count);
48152 }
48153 spin_unlock_irqrestore(&info->irq_spinlock, flags);
48154 port->blocked_open++;
48155@@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48156
48157 if (debug_level >= DEBUG_LEVEL_INFO)
48158 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
48159- __FILE__,__LINE__, tty->driver->name, port->count );
48160+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48161
48162 tty_unlock(tty);
48163 schedule();
48164@@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48165
48166 /* FIXME: Racy on hangup during close wait */
48167 if (extra_count)
48168- port->count++;
48169+ atomic_inc(&port->count);
48170 port->blocked_open--;
48171
48172 if (debug_level >= DEBUG_LEVEL_INFO)
48173 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
48174- __FILE__,__LINE__, tty->driver->name, port->count );
48175+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48176
48177 if (!retval)
48178 port->flags |= ASYNC_NORMAL_ACTIVE;
48179@@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
48180
48181 if (debug_level >= DEBUG_LEVEL_INFO)
48182 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
48183- __FILE__,__LINE__,tty->driver->name, info->port.count);
48184+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
48185
48186 /* If port is closing, signal caller to try again */
48187 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48188@@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
48189 spin_unlock_irqrestore(&info->netlock, flags);
48190 goto cleanup;
48191 }
48192- info->port.count++;
48193+ atomic_inc(&info->port.count);
48194 spin_unlock_irqrestore(&info->netlock, flags);
48195
48196- if (info->port.count == 1) {
48197+ if (atomic_read(&info->port.count) == 1) {
48198 /* 1st open on this device, init hardware */
48199 retval = startup(info);
48200 if (retval < 0)
48201@@ -3446,8 +3446,8 @@ cleanup:
48202 if (retval) {
48203 if (tty->count == 1)
48204 info->port.tty = NULL; /* tty layer will release tty struct */
48205- if(info->port.count)
48206- info->port.count--;
48207+ if (atomic_read(&info->port.count))
48208+ atomic_dec(&info->port.count);
48209 }
48210
48211 return retval;
48212@@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48213 unsigned short new_crctype;
48214
48215 /* return error if TTY interface open */
48216- if (info->port.count)
48217+ if (atomic_read(&info->port.count))
48218 return -EBUSY;
48219
48220 switch (encoding)
48221@@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
48222
48223 /* arbitrate between network and tty opens */
48224 spin_lock_irqsave(&info->netlock, flags);
48225- if (info->port.count != 0 || info->netcount != 0) {
48226+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48227 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
48228 spin_unlock_irqrestore(&info->netlock, flags);
48229 return -EBUSY;
48230@@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48231 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
48232
48233 /* return error if TTY interface open */
48234- if (info->port.count)
48235+ if (atomic_read(&info->port.count))
48236 return -EBUSY;
48237
48238 if (cmd != SIOCWANDEV)
48239diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
48240index 1abf946..1ee34fc 100644
48241--- a/drivers/tty/synclink_gt.c
48242+++ b/drivers/tty/synclink_gt.c
48243@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
48244 tty->driver_data = info;
48245 info->port.tty = tty;
48246
48247- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
48248+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
48249
48250 /* If port is closing, signal caller to try again */
48251 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48252@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
48253 mutex_unlock(&info->port.mutex);
48254 goto cleanup;
48255 }
48256- info->port.count++;
48257+ atomic_inc(&info->port.count);
48258 spin_unlock_irqrestore(&info->netlock, flags);
48259
48260- if (info->port.count == 1) {
48261+ if (atomic_read(&info->port.count) == 1) {
48262 /* 1st open on this device, init hardware */
48263 retval = startup(info);
48264 if (retval < 0) {
48265@@ -715,8 +715,8 @@ cleanup:
48266 if (retval) {
48267 if (tty->count == 1)
48268 info->port.tty = NULL; /* tty layer will release tty struct */
48269- if(info->port.count)
48270- info->port.count--;
48271+ if(atomic_read(&info->port.count))
48272+ atomic_dec(&info->port.count);
48273 }
48274
48275 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
48276@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48277
48278 if (sanity_check(info, tty->name, "close"))
48279 return;
48280- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
48281+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
48282
48283 if (tty_port_close_start(&info->port, tty, filp) == 0)
48284 goto cleanup;
48285@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48286 tty_port_close_end(&info->port, tty);
48287 info->port.tty = NULL;
48288 cleanup:
48289- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
48290+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
48291 }
48292
48293 static void hangup(struct tty_struct *tty)
48294@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
48295 shutdown(info);
48296
48297 spin_lock_irqsave(&info->port.lock, flags);
48298- info->port.count = 0;
48299+ atomic_set(&info->port.count, 0);
48300 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48301 info->port.tty = NULL;
48302 spin_unlock_irqrestore(&info->port.lock, flags);
48303@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48304 unsigned short new_crctype;
48305
48306 /* return error if TTY interface open */
48307- if (info->port.count)
48308+ if (atomic_read(&info->port.count))
48309 return -EBUSY;
48310
48311 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
48312@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
48313
48314 /* arbitrate between network and tty opens */
48315 spin_lock_irqsave(&info->netlock, flags);
48316- if (info->port.count != 0 || info->netcount != 0) {
48317+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48318 DBGINFO(("%s hdlc_open busy\n", dev->name));
48319 spin_unlock_irqrestore(&info->netlock, flags);
48320 return -EBUSY;
48321@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48322 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
48323
48324 /* return error if TTY interface open */
48325- if (info->port.count)
48326+ if (atomic_read(&info->port.count))
48327 return -EBUSY;
48328
48329 if (cmd != SIOCWANDEV)
48330@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
48331 if (port == NULL)
48332 continue;
48333 spin_lock(&port->lock);
48334- if ((port->port.count || port->netcount) &&
48335+ if ((atomic_read(&port->port.count) || port->netcount) &&
48336 port->pending_bh && !port->bh_running &&
48337 !port->bh_requested) {
48338 DBGISR(("%s bh queued\n", port->device_name));
48339@@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48340 spin_lock_irqsave(&info->lock, flags);
48341 if (!tty_hung_up_p(filp)) {
48342 extra_count = true;
48343- port->count--;
48344+ atomic_dec(&port->count);
48345 }
48346 spin_unlock_irqrestore(&info->lock, flags);
48347 port->blocked_open++;
48348@@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48349 remove_wait_queue(&port->open_wait, &wait);
48350
48351 if (extra_count)
48352- port->count++;
48353+ atomic_inc(&port->count);
48354 port->blocked_open--;
48355
48356 if (!retval)
48357diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
48358index dc6e969..5dc8786 100644
48359--- a/drivers/tty/synclinkmp.c
48360+++ b/drivers/tty/synclinkmp.c
48361@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
48362
48363 if (debug_level >= DEBUG_LEVEL_INFO)
48364 printk("%s(%d):%s open(), old ref count = %d\n",
48365- __FILE__,__LINE__,tty->driver->name, info->port.count);
48366+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
48367
48368 /* If port is closing, signal caller to try again */
48369 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48370@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
48371 spin_unlock_irqrestore(&info->netlock, flags);
48372 goto cleanup;
48373 }
48374- info->port.count++;
48375+ atomic_inc(&info->port.count);
48376 spin_unlock_irqrestore(&info->netlock, flags);
48377
48378- if (info->port.count == 1) {
48379+ if (atomic_read(&info->port.count) == 1) {
48380 /* 1st open on this device, init hardware */
48381 retval = startup(info);
48382 if (retval < 0)
48383@@ -796,8 +796,8 @@ cleanup:
48384 if (retval) {
48385 if (tty->count == 1)
48386 info->port.tty = NULL; /* tty layer will release tty struct */
48387- if(info->port.count)
48388- info->port.count--;
48389+ if(atomic_read(&info->port.count))
48390+ atomic_dec(&info->port.count);
48391 }
48392
48393 return retval;
48394@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48395
48396 if (debug_level >= DEBUG_LEVEL_INFO)
48397 printk("%s(%d):%s close() entry, count=%d\n",
48398- __FILE__,__LINE__, info->device_name, info->port.count);
48399+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
48400
48401 if (tty_port_close_start(&info->port, tty, filp) == 0)
48402 goto cleanup;
48403@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48404 cleanup:
48405 if (debug_level >= DEBUG_LEVEL_INFO)
48406 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
48407- tty->driver->name, info->port.count);
48408+ tty->driver->name, atomic_read(&info->port.count));
48409 }
48410
48411 /* Called by tty_hangup() when a hangup is signaled.
48412@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
48413 shutdown(info);
48414
48415 spin_lock_irqsave(&info->port.lock, flags);
48416- info->port.count = 0;
48417+ atomic_set(&info->port.count, 0);
48418 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48419 info->port.tty = NULL;
48420 spin_unlock_irqrestore(&info->port.lock, flags);
48421@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48422 unsigned short new_crctype;
48423
48424 /* return error if TTY interface open */
48425- if (info->port.count)
48426+ if (atomic_read(&info->port.count))
48427 return -EBUSY;
48428
48429 switch (encoding)
48430@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
48431
48432 /* arbitrate between network and tty opens */
48433 spin_lock_irqsave(&info->netlock, flags);
48434- if (info->port.count != 0 || info->netcount != 0) {
48435+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48436 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
48437 spin_unlock_irqrestore(&info->netlock, flags);
48438 return -EBUSY;
48439@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48440 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
48441
48442 /* return error if TTY interface open */
48443- if (info->port.count)
48444+ if (atomic_read(&info->port.count))
48445 return -EBUSY;
48446
48447 if (cmd != SIOCWANDEV)
48448@@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
48449 * do not request bottom half processing if the
48450 * device is not open in a normal mode.
48451 */
48452- if ( port && (port->port.count || port->netcount) &&
48453+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
48454 port->pending_bh && !port->bh_running &&
48455 !port->bh_requested ) {
48456 if ( debug_level >= DEBUG_LEVEL_ISR )
48457@@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48458
48459 if (debug_level >= DEBUG_LEVEL_INFO)
48460 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
48461- __FILE__,__LINE__, tty->driver->name, port->count );
48462+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48463
48464 spin_lock_irqsave(&info->lock, flags);
48465 if (!tty_hung_up_p(filp)) {
48466 extra_count = true;
48467- port->count--;
48468+ atomic_dec(&port->count);
48469 }
48470 spin_unlock_irqrestore(&info->lock, flags);
48471 port->blocked_open++;
48472@@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48473
48474 if (debug_level >= DEBUG_LEVEL_INFO)
48475 printk("%s(%d):%s block_til_ready() count=%d\n",
48476- __FILE__,__LINE__, tty->driver->name, port->count );
48477+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48478
48479 tty_unlock(tty);
48480 schedule();
48481@@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48482 remove_wait_queue(&port->open_wait, &wait);
48483
48484 if (extra_count)
48485- port->count++;
48486+ atomic_inc(&port->count);
48487 port->blocked_open--;
48488
48489 if (debug_level >= DEBUG_LEVEL_INFO)
48490 printk("%s(%d):%s block_til_ready() after, count=%d\n",
48491- __FILE__,__LINE__, tty->driver->name, port->count );
48492+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48493
48494 if (!retval)
48495 port->flags |= ASYNC_NORMAL_ACTIVE;
48496diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
48497index d5cc3ac..3263411 100644
48498--- a/drivers/tty/sysrq.c
48499+++ b/drivers/tty/sysrq.c
48500@@ -1033,7 +1033,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
48501 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
48502 size_t count, loff_t *ppos)
48503 {
48504- if (count) {
48505+ if (count && capable(CAP_SYS_ADMIN)) {
48506 char c;
48507
48508 if (get_user(c, buf))
48509diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
48510index 20689b9..7fd3a31 100644
48511--- a/drivers/tty/tty_io.c
48512+++ b/drivers/tty/tty_io.c
48513@@ -3468,7 +3468,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
48514
48515 void tty_default_fops(struct file_operations *fops)
48516 {
48517- *fops = tty_fops;
48518+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
48519 }
48520
48521 /*
48522diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
48523index 1afe192..73d2c20 100644
48524--- a/drivers/tty/tty_ldisc.c
48525+++ b/drivers/tty/tty_ldisc.c
48526@@ -66,7 +66,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
48527 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
48528 tty_ldiscs[disc] = new_ldisc;
48529 new_ldisc->num = disc;
48530- new_ldisc->refcount = 0;
48531+ atomic_set(&new_ldisc->refcount, 0);
48532 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
48533
48534 return ret;
48535@@ -94,7 +94,7 @@ int tty_unregister_ldisc(int disc)
48536 return -EINVAL;
48537
48538 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
48539- if (tty_ldiscs[disc]->refcount)
48540+ if (atomic_read(&tty_ldiscs[disc]->refcount))
48541 ret = -EBUSY;
48542 else
48543 tty_ldiscs[disc] = NULL;
48544@@ -115,7 +115,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
48545 if (ldops) {
48546 ret = ERR_PTR(-EAGAIN);
48547 if (try_module_get(ldops->owner)) {
48548- ldops->refcount++;
48549+ atomic_inc(&ldops->refcount);
48550 ret = ldops;
48551 }
48552 }
48553@@ -128,7 +128,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
48554 unsigned long flags;
48555
48556 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
48557- ldops->refcount--;
48558+ atomic_dec(&ldops->refcount);
48559 module_put(ldops->owner);
48560 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
48561 }
48562@@ -196,7 +196,7 @@ static inline void tty_ldisc_put(struct tty_ldisc *ld)
48563 /* unreleased reader reference(s) will cause this WARN */
48564 WARN_ON(!atomic_dec_and_test(&ld->users));
48565
48566- ld->ops->refcount--;
48567+ atomic_dec(&ld->ops->refcount);
48568 module_put(ld->ops->owner);
48569 kfree(ld);
48570 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
48571diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
48572index f597e88..b7f68ed 100644
48573--- a/drivers/tty/tty_port.c
48574+++ b/drivers/tty/tty_port.c
48575@@ -232,7 +232,7 @@ void tty_port_hangup(struct tty_port *port)
48576 unsigned long flags;
48577
48578 spin_lock_irqsave(&port->lock, flags);
48579- port->count = 0;
48580+ atomic_set(&port->count, 0);
48581 port->flags &= ~ASYNC_NORMAL_ACTIVE;
48582 tty = port->tty;
48583 if (tty)
48584@@ -390,7 +390,7 @@ int tty_port_block_til_ready(struct tty_port *port,
48585 /* The port lock protects the port counts */
48586 spin_lock_irqsave(&port->lock, flags);
48587 if (!tty_hung_up_p(filp))
48588- port->count--;
48589+ atomic_dec(&port->count);
48590 port->blocked_open++;
48591 spin_unlock_irqrestore(&port->lock, flags);
48592
48593@@ -432,7 +432,7 @@ int tty_port_block_til_ready(struct tty_port *port,
48594 we must not mess that up further */
48595 spin_lock_irqsave(&port->lock, flags);
48596 if (!tty_hung_up_p(filp))
48597- port->count++;
48598+ atomic_inc(&port->count);
48599 port->blocked_open--;
48600 if (retval == 0)
48601 port->flags |= ASYNC_NORMAL_ACTIVE;
48602@@ -466,19 +466,19 @@ int tty_port_close_start(struct tty_port *port,
48603 return 0;
48604 }
48605
48606- if (tty->count == 1 && port->count != 1) {
48607+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
48608 printk(KERN_WARNING
48609 "tty_port_close_start: tty->count = 1 port count = %d.\n",
48610- port->count);
48611- port->count = 1;
48612+ atomic_read(&port->count));
48613+ atomic_set(&port->count, 1);
48614 }
48615- if (--port->count < 0) {
48616+ if (atomic_dec_return(&port->count) < 0) {
48617 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
48618- port->count);
48619- port->count = 0;
48620+ atomic_read(&port->count));
48621+ atomic_set(&port->count, 0);
48622 }
48623
48624- if (port->count) {
48625+ if (atomic_read(&port->count)) {
48626 spin_unlock_irqrestore(&port->lock, flags);
48627 if (port->ops->drop)
48628 port->ops->drop(port);
48629@@ -564,7 +564,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
48630 {
48631 spin_lock_irq(&port->lock);
48632 if (!tty_hung_up_p(filp))
48633- ++port->count;
48634+ atomic_inc(&port->count);
48635 spin_unlock_irq(&port->lock);
48636 tty_port_tty_set(port, tty);
48637
48638diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
48639index a9af1b9a..1e08e7f 100644
48640--- a/drivers/tty/vt/keyboard.c
48641+++ b/drivers/tty/vt/keyboard.c
48642@@ -647,6 +647,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
48643 kbd->kbdmode == VC_OFF) &&
48644 value != KVAL(K_SAK))
48645 return; /* SAK is allowed even in raw mode */
48646+
48647+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48648+ {
48649+ void *func = fn_handler[value];
48650+ if (func == fn_show_state || func == fn_show_ptregs ||
48651+ func == fn_show_mem)
48652+ return;
48653+ }
48654+#endif
48655+
48656 fn_handler[value](vc);
48657 }
48658
48659@@ -1795,9 +1805,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
48660 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
48661 return -EFAULT;
48662
48663- if (!capable(CAP_SYS_TTY_CONFIG))
48664- perm = 0;
48665-
48666 switch (cmd) {
48667 case KDGKBENT:
48668 /* Ensure another thread doesn't free it under us */
48669@@ -1812,6 +1819,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
48670 spin_unlock_irqrestore(&kbd_event_lock, flags);
48671 return put_user(val, &user_kbe->kb_value);
48672 case KDSKBENT:
48673+ if (!capable(CAP_SYS_TTY_CONFIG))
48674+ perm = 0;
48675+
48676 if (!perm)
48677 return -EPERM;
48678 if (!i && v == K_NOSUCHMAP) {
48679@@ -1902,9 +1912,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
48680 int i, j, k;
48681 int ret;
48682
48683- if (!capable(CAP_SYS_TTY_CONFIG))
48684- perm = 0;
48685-
48686 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
48687 if (!kbs) {
48688 ret = -ENOMEM;
48689@@ -1938,6 +1945,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
48690 kfree(kbs);
48691 return ((p && *p) ? -EOVERFLOW : 0);
48692 case KDSKBSENT:
48693+ if (!capable(CAP_SYS_TTY_CONFIG))
48694+ perm = 0;
48695+
48696 if (!perm) {
48697 ret = -EPERM;
48698 goto reterr;
48699diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
48700index 3b96f18..026a9bf 100644
48701--- a/drivers/uio/uio.c
48702+++ b/drivers/uio/uio.c
48703@@ -25,6 +25,7 @@
48704 #include <linux/kobject.h>
48705 #include <linux/cdev.h>
48706 #include <linux/uio_driver.h>
48707+#include <asm/local.h>
48708
48709 #define UIO_MAX_DEVICES (1U << MINORBITS)
48710
48711@@ -32,10 +33,10 @@ struct uio_device {
48712 struct module *owner;
48713 struct device *dev;
48714 int minor;
48715- atomic_t event;
48716+ atomic_unchecked_t event;
48717 struct fasync_struct *async_queue;
48718 wait_queue_head_t wait;
48719- int vma_count;
48720+ local_t vma_count;
48721 struct uio_info *info;
48722 struct kobject *map_dir;
48723 struct kobject *portio_dir;
48724@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
48725 struct device_attribute *attr, char *buf)
48726 {
48727 struct uio_device *idev = dev_get_drvdata(dev);
48728- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
48729+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
48730 }
48731
48732 static struct device_attribute uio_class_attributes[] = {
48733@@ -398,7 +399,7 @@ void uio_event_notify(struct uio_info *info)
48734 {
48735 struct uio_device *idev = info->uio_dev;
48736
48737- atomic_inc(&idev->event);
48738+ atomic_inc_unchecked(&idev->event);
48739 wake_up_interruptible(&idev->wait);
48740 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
48741 }
48742@@ -451,7 +452,7 @@ static int uio_open(struct inode *inode, struct file *filep)
48743 }
48744
48745 listener->dev = idev;
48746- listener->event_count = atomic_read(&idev->event);
48747+ listener->event_count = atomic_read_unchecked(&idev->event);
48748 filep->private_data = listener;
48749
48750 if (idev->info->open) {
48751@@ -502,7 +503,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
48752 return -EIO;
48753
48754 poll_wait(filep, &idev->wait, wait);
48755- if (listener->event_count != atomic_read(&idev->event))
48756+ if (listener->event_count != atomic_read_unchecked(&idev->event))
48757 return POLLIN | POLLRDNORM;
48758 return 0;
48759 }
48760@@ -527,7 +528,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
48761 do {
48762 set_current_state(TASK_INTERRUPTIBLE);
48763
48764- event_count = atomic_read(&idev->event);
48765+ event_count = atomic_read_unchecked(&idev->event);
48766 if (event_count != listener->event_count) {
48767 if (copy_to_user(buf, &event_count, count))
48768 retval = -EFAULT;
48769@@ -596,13 +597,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
48770 static void uio_vma_open(struct vm_area_struct *vma)
48771 {
48772 struct uio_device *idev = vma->vm_private_data;
48773- idev->vma_count++;
48774+ local_inc(&idev->vma_count);
48775 }
48776
48777 static void uio_vma_close(struct vm_area_struct *vma)
48778 {
48779 struct uio_device *idev = vma->vm_private_data;
48780- idev->vma_count--;
48781+ local_dec(&idev->vma_count);
48782 }
48783
48784 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
48785@@ -809,7 +810,7 @@ int __uio_register_device(struct module *owner,
48786 idev->owner = owner;
48787 idev->info = info;
48788 init_waitqueue_head(&idev->wait);
48789- atomic_set(&idev->event, 0);
48790+ atomic_set_unchecked(&idev->event, 0);
48791
48792 ret = uio_get_minor(idev);
48793 if (ret)
48794diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
48795index 8a7eb77..c00402f 100644
48796--- a/drivers/usb/atm/cxacru.c
48797+++ b/drivers/usb/atm/cxacru.c
48798@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
48799 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
48800 if (ret < 2)
48801 return -EINVAL;
48802- if (index < 0 || index > 0x7f)
48803+ if (index > 0x7f)
48804 return -EINVAL;
48805 pos += tmp;
48806
48807diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
48808index 5e0d33a..cc10579 100644
48809--- a/drivers/usb/atm/usbatm.c
48810+++ b/drivers/usb/atm/usbatm.c
48811@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
48812 if (printk_ratelimit())
48813 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
48814 __func__, vpi, vci);
48815- atomic_inc(&vcc->stats->rx_err);
48816+ atomic_inc_unchecked(&vcc->stats->rx_err);
48817 return;
48818 }
48819
48820@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
48821 if (length > ATM_MAX_AAL5_PDU) {
48822 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
48823 __func__, length, vcc);
48824- atomic_inc(&vcc->stats->rx_err);
48825+ atomic_inc_unchecked(&vcc->stats->rx_err);
48826 goto out;
48827 }
48828
48829@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
48830 if (sarb->len < pdu_length) {
48831 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
48832 __func__, pdu_length, sarb->len, vcc);
48833- atomic_inc(&vcc->stats->rx_err);
48834+ atomic_inc_unchecked(&vcc->stats->rx_err);
48835 goto out;
48836 }
48837
48838 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
48839 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
48840 __func__, vcc);
48841- atomic_inc(&vcc->stats->rx_err);
48842+ atomic_inc_unchecked(&vcc->stats->rx_err);
48843 goto out;
48844 }
48845
48846@@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
48847 if (printk_ratelimit())
48848 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
48849 __func__, length);
48850- atomic_inc(&vcc->stats->rx_drop);
48851+ atomic_inc_unchecked(&vcc->stats->rx_drop);
48852 goto out;
48853 }
48854
48855@@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
48856
48857 vcc->push(vcc, skb);
48858
48859- atomic_inc(&vcc->stats->rx);
48860+ atomic_inc_unchecked(&vcc->stats->rx);
48861 out:
48862 skb_trim(sarb, 0);
48863 }
48864@@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
48865 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
48866
48867 usbatm_pop(vcc, skb);
48868- atomic_inc(&vcc->stats->tx);
48869+ atomic_inc_unchecked(&vcc->stats->tx);
48870
48871 skb = skb_dequeue(&instance->sndqueue);
48872 }
48873@@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
48874 if (!left--)
48875 return sprintf(page,
48876 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
48877- atomic_read(&atm_dev->stats.aal5.tx),
48878- atomic_read(&atm_dev->stats.aal5.tx_err),
48879- atomic_read(&atm_dev->stats.aal5.rx),
48880- atomic_read(&atm_dev->stats.aal5.rx_err),
48881- atomic_read(&atm_dev->stats.aal5.rx_drop));
48882+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
48883+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
48884+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
48885+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
48886+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
48887
48888 if (!left--) {
48889 if (instance->disconnected)
48890diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
48891index 2a3bbdf..91d72cf 100644
48892--- a/drivers/usb/core/devices.c
48893+++ b/drivers/usb/core/devices.c
48894@@ -126,7 +126,7 @@ static const char format_endpt[] =
48895 * time it gets called.
48896 */
48897 static struct device_connect_event {
48898- atomic_t count;
48899+ atomic_unchecked_t count;
48900 wait_queue_head_t wait;
48901 } device_event = {
48902 .count = ATOMIC_INIT(1),
48903@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
48904
48905 void usbfs_conn_disc_event(void)
48906 {
48907- atomic_add(2, &device_event.count);
48908+ atomic_add_unchecked(2, &device_event.count);
48909 wake_up(&device_event.wait);
48910 }
48911
48912@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
48913
48914 poll_wait(file, &device_event.wait, wait);
48915
48916- event_count = atomic_read(&device_event.count);
48917+ event_count = atomic_read_unchecked(&device_event.count);
48918 if (file->f_version != event_count) {
48919 file->f_version = event_count;
48920 return POLLIN | POLLRDNORM;
48921diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
48922index 014dc99..4d25fd7 100644
48923--- a/drivers/usb/core/hcd.c
48924+++ b/drivers/usb/core/hcd.c
48925@@ -1551,7 +1551,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
48926 */
48927 usb_get_urb(urb);
48928 atomic_inc(&urb->use_count);
48929- atomic_inc(&urb->dev->urbnum);
48930+ atomic_inc_unchecked(&urb->dev->urbnum);
48931 usbmon_urb_submit(&hcd->self, urb);
48932
48933 /* NOTE requirements on root-hub callers (usbfs and the hub
48934@@ -1578,7 +1578,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
48935 urb->hcpriv = NULL;
48936 INIT_LIST_HEAD(&urb->urb_list);
48937 atomic_dec(&urb->use_count);
48938- atomic_dec(&urb->dev->urbnum);
48939+ atomic_dec_unchecked(&urb->dev->urbnum);
48940 if (atomic_read(&urb->reject))
48941 wake_up(&usb_kill_urb_queue);
48942 usb_put_urb(urb);
48943diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
48944index 17c3785..deffb11 100644
48945--- a/drivers/usb/core/hub.c
48946+++ b/drivers/usb/core/hub.c
48947@@ -27,6 +27,7 @@
48948 #include <linux/freezer.h>
48949 #include <linux/random.h>
48950 #include <linux/pm_qos.h>
48951+#include <linux/grsecurity.h>
48952
48953 #include <asm/uaccess.h>
48954 #include <asm/byteorder.h>
48955@@ -4421,6 +4422,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
48956 goto done;
48957 return;
48958 }
48959+
48960+ if (gr_handle_new_usb())
48961+ goto done;
48962+
48963 if (hub_is_superspeed(hub->hdev))
48964 unit_load = 150;
48965 else
48966diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
48967index e7ee1e4..1dfc9ea4 100644
48968--- a/drivers/usb/core/message.c
48969+++ b/drivers/usb/core/message.c
48970@@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
48971 * method can wait for it to complete. Since you don't have a handle on the
48972 * URB used, you can't cancel the request.
48973 */
48974-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
48975+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
48976 __u8 requesttype, __u16 value, __u16 index, void *data,
48977 __u16 size, int timeout)
48978 {
48979diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
48980index d9284b9..17023c7 100644
48981--- a/drivers/usb/core/sysfs.c
48982+++ b/drivers/usb/core/sysfs.c
48983@@ -239,7 +239,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
48984 struct usb_device *udev;
48985
48986 udev = to_usb_device(dev);
48987- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
48988+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
48989 }
48990 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
48991
48992diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
48993index 7dad603..350f7a9 100644
48994--- a/drivers/usb/core/usb.c
48995+++ b/drivers/usb/core/usb.c
48996@@ -422,7 +422,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
48997 set_dev_node(&dev->dev, dev_to_node(bus->controller));
48998 dev->state = USB_STATE_ATTACHED;
48999 dev->lpm_disable_count = 1;
49000- atomic_set(&dev->urbnum, 0);
49001+ atomic_set_unchecked(&dev->urbnum, 0);
49002
49003 INIT_LIST_HEAD(&dev->ep0.urb_list);
49004 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
49005diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
49006index 14d28d6..5f511ac 100644
49007--- a/drivers/usb/dwc3/gadget.c
49008+++ b/drivers/usb/dwc3/gadget.c
49009@@ -550,8 +550,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
49010 if (!usb_endpoint_xfer_isoc(desc))
49011 return 0;
49012
49013- memset(&trb_link, 0, sizeof(trb_link));
49014-
49015 /* Link TRB for ISOC. The HWO bit is never reset */
49016 trb_st_hw = &dep->trb_pool[0];
49017
49018diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
49019index 5e29dde..eca992f 100644
49020--- a/drivers/usb/early/ehci-dbgp.c
49021+++ b/drivers/usb/early/ehci-dbgp.c
49022@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
49023
49024 #ifdef CONFIG_KGDB
49025 static struct kgdb_io kgdbdbgp_io_ops;
49026-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
49027+static struct kgdb_io kgdbdbgp_io_ops_console;
49028+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
49029 #else
49030 #define dbgp_kgdb_mode (0)
49031 #endif
49032@@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
49033 .write_char = kgdbdbgp_write_char,
49034 };
49035
49036+static struct kgdb_io kgdbdbgp_io_ops_console = {
49037+ .name = "kgdbdbgp",
49038+ .read_char = kgdbdbgp_read_char,
49039+ .write_char = kgdbdbgp_write_char,
49040+ .is_console = 1
49041+};
49042+
49043 static int kgdbdbgp_wait_time;
49044
49045 static int __init kgdbdbgp_parse_config(char *str)
49046@@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
49047 ptr++;
49048 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
49049 }
49050- kgdb_register_io_module(&kgdbdbgp_io_ops);
49051- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
49052+ if (early_dbgp_console.index != -1)
49053+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
49054+ else
49055+ kgdb_register_io_module(&kgdbdbgp_io_ops);
49056
49057 return 0;
49058 }
49059diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
49060index b369292..9f3ba40 100644
49061--- a/drivers/usb/gadget/u_serial.c
49062+++ b/drivers/usb/gadget/u_serial.c
49063@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
49064 spin_lock_irq(&port->port_lock);
49065
49066 /* already open? Great. */
49067- if (port->port.count) {
49068+ if (atomic_read(&port->port.count)) {
49069 status = 0;
49070- port->port.count++;
49071+ atomic_inc(&port->port.count);
49072
49073 /* currently opening/closing? wait ... */
49074 } else if (port->openclose) {
49075@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
49076 tty->driver_data = port;
49077 port->port.tty = tty;
49078
49079- port->port.count = 1;
49080+ atomic_set(&port->port.count, 1);
49081 port->openclose = false;
49082
49083 /* if connected, start the I/O stream */
49084@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
49085
49086 spin_lock_irq(&port->port_lock);
49087
49088- if (port->port.count != 1) {
49089- if (port->port.count == 0)
49090+ if (atomic_read(&port->port.count) != 1) {
49091+ if (atomic_read(&port->port.count) == 0)
49092 WARN_ON(1);
49093 else
49094- --port->port.count;
49095+ atomic_dec(&port->port.count);
49096 goto exit;
49097 }
49098
49099@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
49100 * and sleep if necessary
49101 */
49102 port->openclose = true;
49103- port->port.count = 0;
49104+ atomic_set(&port->port.count, 0);
49105
49106 gser = port->port_usb;
49107 if (gser && gser->disconnect)
49108@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
49109 int cond;
49110
49111 spin_lock_irq(&port->port_lock);
49112- cond = (port->port.count == 0) && !port->openclose;
49113+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
49114 spin_unlock_irq(&port->port_lock);
49115 return cond;
49116 }
49117@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
49118 /* if it's already open, start I/O ... and notify the serial
49119 * protocol about open/close status (connect/disconnect).
49120 */
49121- if (port->port.count) {
49122+ if (atomic_read(&port->port.count)) {
49123 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
49124 gs_start_io(port);
49125 if (gser->connect)
49126@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
49127
49128 port->port_usb = NULL;
49129 gser->ioport = NULL;
49130- if (port->port.count > 0 || port->openclose) {
49131+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
49132 wake_up_interruptible(&port->drain_wait);
49133 if (port->port.tty)
49134 tty_hangup(port->port.tty);
49135@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
49136
49137 /* finally, free any unused/unusable I/O buffers */
49138 spin_lock_irqsave(&port->port_lock, flags);
49139- if (port->port.count == 0 && !port->openclose)
49140+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
49141 gs_buf_free(&port->port_write_buf);
49142 gs_free_requests(gser->out, &port->read_pool, NULL);
49143 gs_free_requests(gser->out, &port->read_queue, NULL);
49144diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
49145index ba6a5d6..f88f7f3 100644
49146--- a/drivers/usb/misc/appledisplay.c
49147+++ b/drivers/usb/misc/appledisplay.c
49148@@ -83,7 +83,7 @@ struct appledisplay {
49149 spinlock_t lock;
49150 };
49151
49152-static atomic_t count_displays = ATOMIC_INIT(0);
49153+static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
49154 static struct workqueue_struct *wq;
49155
49156 static void appledisplay_complete(struct urb *urb)
49157@@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
49158
49159 /* Register backlight device */
49160 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
49161- atomic_inc_return(&count_displays) - 1);
49162+ atomic_inc_return_unchecked(&count_displays) - 1);
49163 memset(&props, 0, sizeof(struct backlight_properties));
49164 props.type = BACKLIGHT_RAW;
49165 props.max_brightness = 0xff;
49166diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
49167index afb50ea..7b0b1cf 100644
49168--- a/drivers/usb/serial/console.c
49169+++ b/drivers/usb/serial/console.c
49170@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
49171
49172 info->port = port;
49173
49174- ++port->port.count;
49175+ atomic_inc(&port->port.count);
49176 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
49177 if (serial->type->set_termios) {
49178 /*
49179@@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
49180 }
49181 /* Now that any required fake tty operations are completed restore
49182 * the tty port count */
49183- --port->port.count;
49184+ atomic_dec(&port->port.count);
49185 /* The console is special in terms of closing the device so
49186 * indicate this port is now acting as a system console. */
49187 port->port.console = 1;
49188@@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
49189 free_tty:
49190 kfree(tty);
49191 reset_open_count:
49192- port->port.count = 0;
49193+ atomic_set(&port->port.count, 0);
49194 usb_autopm_put_interface(serial->interface);
49195 error_get_interface:
49196 usb_serial_put(serial);
49197diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
49198index 75f70f0..d467e1a 100644
49199--- a/drivers/usb/storage/usb.h
49200+++ b/drivers/usb/storage/usb.h
49201@@ -63,7 +63,7 @@ struct us_unusual_dev {
49202 __u8 useProtocol;
49203 __u8 useTransport;
49204 int (*initFunction)(struct us_data *);
49205-};
49206+} __do_const;
49207
49208
49209 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
49210diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
49211index d6bea3e..60b250e 100644
49212--- a/drivers/usb/wusbcore/wa-hc.h
49213+++ b/drivers/usb/wusbcore/wa-hc.h
49214@@ -192,7 +192,7 @@ struct wahc {
49215 struct list_head xfer_delayed_list;
49216 spinlock_t xfer_list_lock;
49217 struct work_struct xfer_work;
49218- atomic_t xfer_id_count;
49219+ atomic_unchecked_t xfer_id_count;
49220 };
49221
49222
49223@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
49224 INIT_LIST_HEAD(&wa->xfer_delayed_list);
49225 spin_lock_init(&wa->xfer_list_lock);
49226 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
49227- atomic_set(&wa->xfer_id_count, 1);
49228+ atomic_set_unchecked(&wa->xfer_id_count, 1);
49229 }
49230
49231 /**
49232diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
49233index d3493ca..0c33b7e 100644
49234--- a/drivers/usb/wusbcore/wa-xfer.c
49235+++ b/drivers/usb/wusbcore/wa-xfer.c
49236@@ -297,7 +297,7 @@ out:
49237 */
49238 static void wa_xfer_id_init(struct wa_xfer *xfer)
49239 {
49240- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
49241+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
49242 }
49243
49244 /*
49245diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
49246index 842f450..d1d7409 100644
49247--- a/drivers/vfio/vfio.c
49248+++ b/drivers/vfio/vfio.c
49249@@ -488,7 +488,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
49250 return 0;
49251
49252 /* TODO Prevent device auto probing */
49253- WARN("Device %s added to live group %d!\n", dev_name(dev),
49254+ WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
49255 iommu_group_id(group->iommu_group));
49256
49257 return 0;
49258diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
49259index 5174eba..86e764a 100644
49260--- a/drivers/vhost/vringh.c
49261+++ b/drivers/vhost/vringh.c
49262@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
49263
49264 static inline int putu16_kern(u16 *p, u16 val)
49265 {
49266- ACCESS_ONCE(*p) = val;
49267+ ACCESS_ONCE_RW(*p) = val;
49268 return 0;
49269 }
49270
49271diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
49272index a4dfe8c..297ddd9 100644
49273--- a/drivers/video/aty/aty128fb.c
49274+++ b/drivers/video/aty/aty128fb.c
49275@@ -149,7 +149,7 @@ enum {
49276 };
49277
49278 /* Must match above enum */
49279-static char * const r128_family[] = {
49280+static const char * const r128_family[] = {
49281 "AGP",
49282 "PCI",
49283 "PRO AGP",
49284diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
49285index 9b0f12c..024673d 100644
49286--- a/drivers/video/aty/atyfb_base.c
49287+++ b/drivers/video/aty/atyfb_base.c
49288@@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
49289 par->accel_flags = var->accel_flags; /* hack */
49290
49291 if (var->accel_flags) {
49292- info->fbops->fb_sync = atyfb_sync;
49293+ pax_open_kernel();
49294+ *(void **)&info->fbops->fb_sync = atyfb_sync;
49295+ pax_close_kernel();
49296 info->flags &= ~FBINFO_HWACCEL_DISABLED;
49297 } else {
49298- info->fbops->fb_sync = NULL;
49299+ pax_open_kernel();
49300+ *(void **)&info->fbops->fb_sync = NULL;
49301+ pax_close_kernel();
49302 info->flags |= FBINFO_HWACCEL_DISABLED;
49303 }
49304
49305diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
49306index 95ec042..e6affdd 100644
49307--- a/drivers/video/aty/mach64_cursor.c
49308+++ b/drivers/video/aty/mach64_cursor.c
49309@@ -7,6 +7,7 @@
49310 #include <linux/string.h>
49311
49312 #include <asm/io.h>
49313+#include <asm/pgtable.h>
49314
49315 #ifdef __sparc__
49316 #include <asm/fbio.h>
49317@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
49318 info->sprite.buf_align = 16; /* and 64 lines tall. */
49319 info->sprite.flags = FB_PIXMAP_IO;
49320
49321- info->fbops->fb_cursor = atyfb_cursor;
49322+ pax_open_kernel();
49323+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
49324+ pax_close_kernel();
49325
49326 return 0;
49327 }
49328diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
49329index bca6ccc..252107e 100644
49330--- a/drivers/video/backlight/kb3886_bl.c
49331+++ b/drivers/video/backlight/kb3886_bl.c
49332@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
49333 static unsigned long kb3886bl_flags;
49334 #define KB3886BL_SUSPENDED 0x01
49335
49336-static struct dmi_system_id __initdata kb3886bl_device_table[] = {
49337+static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
49338 {
49339 .ident = "Sahara Touch-iT",
49340 .matches = {
49341diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
49342index 900aa4e..6d49418 100644
49343--- a/drivers/video/fb_defio.c
49344+++ b/drivers/video/fb_defio.c
49345@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
49346
49347 BUG_ON(!fbdefio);
49348 mutex_init(&fbdefio->lock);
49349- info->fbops->fb_mmap = fb_deferred_io_mmap;
49350+ pax_open_kernel();
49351+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
49352+ pax_close_kernel();
49353 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
49354 INIT_LIST_HEAD(&fbdefio->pagelist);
49355 if (fbdefio->delay == 0) /* set a default of 1 s */
49356@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
49357 page->mapping = NULL;
49358 }
49359
49360- info->fbops->fb_mmap = NULL;
49361+ *(void **)&info->fbops->fb_mmap = NULL;
49362 mutex_destroy(&fbdefio->lock);
49363 }
49364 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
49365diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
49366index 5c3960d..15cf8fc 100644
49367--- a/drivers/video/fbcmap.c
49368+++ b/drivers/video/fbcmap.c
49369@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
49370 rc = -ENODEV;
49371 goto out;
49372 }
49373- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
49374- !info->fbops->fb_setcmap)) {
49375+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
49376 rc = -EINVAL;
49377 goto out1;
49378 }
49379diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
49380index 36e1fe2..c744820 100644
49381--- a/drivers/video/fbmem.c
49382+++ b/drivers/video/fbmem.c
49383@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
49384 image->dx += image->width + 8;
49385 }
49386 } else if (rotate == FB_ROTATE_UD) {
49387- for (x = 0; x < num && image->dx >= 0; x++) {
49388+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
49389 info->fbops->fb_imageblit(info, image);
49390 image->dx -= image->width + 8;
49391 }
49392@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
49393 image->dy += image->height + 8;
49394 }
49395 } else if (rotate == FB_ROTATE_CCW) {
49396- for (x = 0; x < num && image->dy >= 0; x++) {
49397+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
49398 info->fbops->fb_imageblit(info, image);
49399 image->dy -= image->height + 8;
49400 }
49401@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
49402 return -EFAULT;
49403 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
49404 return -EINVAL;
49405- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
49406+ if (con2fb.framebuffer >= FB_MAX)
49407 return -EINVAL;
49408 if (!registered_fb[con2fb.framebuffer])
49409 request_module("fb%d", con2fb.framebuffer);
49410diff --git a/drivers/video/hyperv_fb.c b/drivers/video/hyperv_fb.c
49411index d4d2c5f..ebbd113 100644
49412--- a/drivers/video/hyperv_fb.c
49413+++ b/drivers/video/hyperv_fb.c
49414@@ -233,7 +233,7 @@ static uint screen_fb_size;
49415 static inline int synthvid_send(struct hv_device *hdev,
49416 struct synthvid_msg *msg)
49417 {
49418- static atomic64_t request_id = ATOMIC64_INIT(0);
49419+ static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
49420 int ret;
49421
49422 msg->pipe_hdr.type = PIPE_MSG_DATA;
49423@@ -241,7 +241,7 @@ static inline int synthvid_send(struct hv_device *hdev,
49424
49425 ret = vmbus_sendpacket(hdev->channel, msg,
49426 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
49427- atomic64_inc_return(&request_id),
49428+ atomic64_inc_return_unchecked(&request_id),
49429 VM_PKT_DATA_INBAND, 0);
49430
49431 if (ret)
49432diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
49433index 7672d2e..b56437f 100644
49434--- a/drivers/video/i810/i810_accel.c
49435+++ b/drivers/video/i810/i810_accel.c
49436@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
49437 }
49438 }
49439 printk("ringbuffer lockup!!!\n");
49440+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
49441 i810_report_error(mmio);
49442 par->dev_flags |= LOCKUP;
49443 info->pixmap.scan_align = 1;
49444diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
49445index 285d552..eafa544 100644
49446--- a/drivers/video/logo/logo_linux_clut224.ppm
49447+++ b/drivers/video/logo/logo_linux_clut224.ppm
49448@@ -1,883 +1,1123 @@
49449 P3
49450 80 80
49451 255
49452-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49453-0 0 0 0 0 0 0 0 0 0 0 0 11 15 17 33 49 54 59 85 92 73 97 106
49454-83 116 129 105 131 142 115 114 122 74 88 93 20 29 31 0 0 0 0 0 0 0 0 0
49455-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49456-0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 6 6 6 10 10 10 10 10 10
49457-10 10 10 6 6 6 6 6 6 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
49458-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49459-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49460-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49461-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49462-
49463-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49464-0 0 0 0 0 0 2 3 3 17 23 26 50 67 72 73 97 106 59 85 92 73 97 106
49465-105 131 142 124 127 131 105 131 142 105 131 142 53 75 83 6 8 8 0 0 0 0 0 0
49466-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49467-0 0 0 6 6 6 10 10 10 14 14 14 22 22 22 26 26 26 30 30 30 34 34 34
49468-30 30 30 30 30 30 26 26 26 18 18 18 14 14 14 10 10 10 6 6 6 0 0 0
49469-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49470-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49471-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49472-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49473-
49474-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0
49475-0 0 0 1 1 1 26 35 39 59 85 92 59 85 92 59 85 92 29 43 47 53 75 83
49476-108 122 132 132 98 104 108 122 132 105 131 142 101 101 101 43 45 48 6 8 8 0 0 0
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-6 6 6 14 14 14 26 26 26 42 42 42 54 54 54 66 66 66 78 78 78 78 78 78
49479-78 78 78 74 74 74 66 66 66 54 54 54 42 42 42 26 26 26 18 18 18 10 10 10
49480-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49481-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49482-0 0 0 0 0 0 0 0 0 0 0 0 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-
49485-0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0
49486-11 15 17 27 40 45 59 85 92 59 85 92 27 40 45 31 45 49 73 97 106 93 121 133
49487-108 122 132 108 122 132 105 131 142 108 122 132 105 131 142 73 97 106 26 35 39 0 0 0
49488-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
49489-22 22 22 42 42 42 66 66 66 86 86 86 66 66 66 38 38 38 38 38 38 22 22 22
49490-26 26 26 34 34 34 54 54 54 66 66 66 86 86 86 70 70 70 46 46 46 26 26 26
49491-14 14 14 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49492-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49493-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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-
49496-0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 7 12 13 21 31 35 42 59 64
49497-53 75 83 53 75 83 50 67 72 42 59 64 32 40 45 42 59 64 73 97 106 116 116 116
49498-132 98 104 116 116 116 108 122 132 117 104 110 105 131 142 83 116 129 50 67 72 7 12 13
49499-1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10 26 26 26
49500-50 50 50 82 82 82 58 58 58 6 6 6 2 2 6 2 2 6 2 2 6 2 2 6
49501-2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 54 54 54 86 86 86 66 66 66
49502-38 38 38 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49503-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49504-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49505-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49506-
49507-0 0 0 1 1 1 6 8 8 15 22 25 26 35 39 36 54 60 53 75 83 59 85 92
49508-59 85 92 48 63 69 15 22 25 12 17 20 52 67 79 94 94 94 132 98 104 132 98 104
49509-117 104 110 108 122 132 108 122 132 115 114 122 105 131 142 77 105 114 59 85 92 36 54 60
49510-7 12 13 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22 50 50 50
49511-78 78 78 34 34 34 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49512-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 70 70 70
49513-78 78 78 46 46 46 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
49514-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49515-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49516-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49517-
49518-0 0 0 15 22 25 29 43 47 36 54 60 42 59 64 42 59 64 48 63 69 21 31 35
49519-6 8 8 29 43 47 36 50 56 43 45 48 79 78 84 132 98 104 165 78 79 132 98 104
49520-108 122 132 117 104 110 117 104 110 108 122 132 77 105 114 73 97 106 95 131 149 78 102 129
49521-36 50 56 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18 42 42 42 82 82 82
49522-26 26 26 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49523-2 2 6 2 2 6 2 2 6 14 14 14 46 46 46 34 34 34 6 6 6 2 2 6
49524-42 42 42 78 78 78 42 42 42 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
49525-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49526-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49527-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49528-
49529-27 40 45 53 75 83 48 63 69 24 31 37 6 8 12 0 0 0 18 25 28 26 35 39
49530-12 17 20 26 35 39 65 78 84 112 81 86 152 81 83 137 83 86 132 98 104 117 104 110
49531-117 104 110 132 98 104 132 98 104 115 114 122 73 97 106 53 75 83 95 131 149 93 124 152
49532-68 78 128 15 22 25 0 0 0 0 0 0 10 10 10 30 30 30 66 66 66 58 58 58
49533-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49534-2 2 6 2 2 6 2 2 6 26 26 26 86 86 86 101 101 101 46 46 46 10 10 10
49535-2 2 6 58 58 58 70 70 70 34 34 34 10 10 10 0 0 0 0 0 0 0 0 0
49536-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49537-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49538-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49539-
49540-36 50 56 21 30 33 4 7 7 0 0 0 1 1 1 17 12 12 69 31 31 68 59 64
49541-57 59 63 21 31 35 32 40 45 86 73 69 152 81 83 152 81 83 117 104 110 132 98 104
49542-152 81 83 132 98 104 108 122 132 77 105 114 77 105 114 93 121 133 95 131 149 93 124 152
49543-95 131 149 53 75 83 11 15 17 0 0 0 14 14 14 42 42 42 86 86 86 10 10 10
49544-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49545-2 2 6 2 2 6 2 2 6 30 30 30 94 94 94 94 94 94 58 58 58 26 26 26
49546-2 2 6 6 6 6 78 78 78 54 54 54 22 22 22 6 6 6 0 0 0 0 0 0
49547-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49548-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49549-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49550-
49551-17 23 26 2 3 3 0 0 0 17 12 12 69 31 31 123 55 55 123 55 55 152 81 83
49552-86 73 69 17 23 26 7 12 13 45 54 57 101 101 101 137 83 86 132 98 104 132 98 104
49553-137 83 86 117 104 110 77 105 114 42 59 64 50 67 72 78 102 129 91 117 157 91 117 157
49554-95 131 149 83 116 129 40 48 73 6 6 6 22 22 22 62 62 62 62 62 62 2 2 6
49555-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49556-2 2 6 2 2 6 2 2 6 26 26 26 54 54 54 38 38 38 18 18 18 10 10 10
49557-2 2 6 2 2 6 34 34 34 82 82 82 38 38 38 14 14 14 0 0 0 0 0 0
49558-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49559-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49560-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49561-
49562-1 1 1 1 2 2 2 3 3 28 12 12 123 55 55 174 79 79 174 79 79 174 79 79
49563-152 81 83 68 59 64 26 35 39 27 40 45 79 78 84 137 83 86 165 78 79 137 83 86
49564-94 94 94 48 63 69 36 50 56 50 67 72 73 97 106 93 121 133 93 124 152 93 124 152
49565-95 131 149 91 118 149 78 102 129 27 40 45 30 30 30 78 78 78 30 30 30 2 2 6
49566-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49567-2 2 6 2 2 6 2 2 6 10 10 10 10 10 10 2 2 6 2 2 6 2 2 6
49568-2 2 6 2 2 6 2 2 6 78 78 78 50 50 50 18 18 18 6 6 6 0 0 0
49569-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49570-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49571-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49572-
49573-4 5 3 24 53 24 19 31 15 8 7 3 90 61 47 165 78 79 174 79 79 174 79 79
49574-174 79 79 137 83 86 60 52 57 7 12 13 17 23 26 70 70 70 132 98 104 112 81 86
49575-79 78 84 31 45 49 15 22 25 53 75 83 91 118 149 86 106 160 91 117 157 93 124 152
49576-91 117 157 93 124 152 95 131 149 53 75 83 50 50 50 86 86 86 14 14 14 2 2 6
49577-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49578-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49579-2 2 6 2 2 6 2 2 6 54 54 54 66 66 66 26 26 26 6 6 6 0 0 0
49580-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49581-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49582-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49583-
49584-19 31 15 34 76 34 34 76 34 19 31 15 28 12 12 123 55 55 174 79 79 174 79 79
49585-174 79 79 165 78 79 112 81 86 32 40 45 15 22 25 38 53 58 65 78 84 29 31 32
49586-21 30 33 42 59 64 60 80 103 78 102 129 87 112 149 84 96 162 91 117 157 93 124 152
49587-91 117 157 93 124 152 93 121 133 59 85 92 57 68 71 82 85 86 2 2 6 2 2 6
49588-2 2 6 6 6 6 10 10 10 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49589-2 2 6 2 2 6 2 2 6 6 6 6 14 14 14 10 10 10 2 2 6 2 2 6
49590-2 2 6 2 2 6 2 2 6 18 18 18 82 82 82 34 34 34 10 10 10 0 0 0
49591-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49592-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49593-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49594-
49595-34 76 34 40 89 40 40 89 40 34 76 34 8 15 6 48 26 18 123 55 55 174 79 79
49596-174 79 79 174 79 79 137 83 86 68 59 64 32 40 45 21 30 33 31 45 49 21 31 35
49597-12 17 20 48 63 69 78 102 129 81 88 166 84 96 162 91 117 157 93 124 152 91 117 157
49598-93 124 152 95 131 149 83 116 129 59 85 92 57 68 71 86 86 86 2 2 6 2 2 6
49599-6 6 6 6 6 6 22 22 22 34 34 34 6 6 6 2 2 6 2 2 6 2 2 6
49600-2 2 6 2 2 6 18 18 18 34 34 34 10 10 10 50 50 50 22 22 22 2 2 6
49601-2 2 6 2 2 6 2 2 6 10 10 10 86 86 86 42 42 42 14 14 14 0 0 0
49602-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49603-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49604-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49605-
49606-40 89 40 40 89 40 40 89 40 40 89 40 24 53 24 6 6 6 69 31 31 123 55 55
49607-123 55 55 90 61 47 69 31 31 36 32 33 21 31 35 7 12 13 18 25 28 48 63 69
49608-60 80 103 68 78 128 84 101 153 84 96 162 84 96 162 91 117 157 91 117 157 84 96 162
49609-91 117 157 73 97 106 48 63 69 50 67 72 57 59 63 86 86 86 2 2 6 2 2 6
49610-38 38 38 116 116 116 94 94 94 22 22 22 22 22 22 2 2 6 2 2 6 2 2 6
49611-14 14 14 86 86 86 124 131 137 170 170 170 151 151 151 38 38 38 26 26 26 6 6 6
49612-2 2 6 2 2 6 2 2 6 2 2 6 86 86 86 46 46 46 14 14 14 0 0 0
49613-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49614-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49615-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49616-
49617-34 76 34 40 89 40 40 89 40 40 89 40 34 76 34 19 31 15 17 12 12 48 26 18
49618-48 26 18 8 7 3 10 10 22 23 29 47 51 61 92 42 59 64 21 30 33 34 45 54
49619-68 78 128 81 88 166 81 82 173 86 106 160 86 106 160 84 96 162 86 106 160 87 112 149
49620-91 118 149 77 105 114 52 67 79 32 40 45 50 50 50 86 86 86 2 2 6 14 14 14
49621-124 131 137 198 198 198 195 195 195 116 116 116 10 10 10 2 2 6 2 2 6 6 6 6
49622-101 98 89 187 187 187 210 210 210 218 218 218 214 214 214 124 131 137 14 14 14 6 6 6
49623-2 2 6 2 2 6 2 2 6 2 2 6 86 86 86 50 50 50 18 18 18 6 6 6
49624-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49625-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49626-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49627-
49628-19 31 15 34 76 34 40 89 40 40 89 40 40 89 40 24 53 24 8 7 3 0 0 0
49629-6 8 12 28 32 52 51 61 92 54 54 122 74 77 160 68 78 128 26 35 39 6 8 8
49630-34 45 54 68 78 128 84 96 162 86 106 160 86 106 160 81 88 166 84 96 162 87 112 149
49631-73 97 106 36 50 56 33 49 54 18 18 18 46 46 46 86 86 86 2 2 6 54 54 54
49632-218 218 218 195 195 195 226 226 226 246 246 246 58 58 58 2 2 6 2 2 6 30 30 30
49633-210 210 210 253 253 253 170 170 170 124 127 131 221 221 221 234 234 234 74 74 74 2 2 6
49634-2 2 6 2 2 6 2 2 6 2 2 6 70 70 70 58 58 58 22 22 22 6 6 6
49635-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49636-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49637-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49638-
49639-4 5 3 24 53 24 40 89 40 40 89 40 34 76 34 12 22 15 4 5 3 4 5 3
49640-13 17 26 54 54 122 78 78 174 78 78 174 78 78 174 74 77 160 51 61 92 21 31 35
49641-26 35 39 53 75 83 84 101 153 81 82 173 81 88 166 84 101 153 60 80 103 60 80 103
49642-53 75 83 38 53 58 42 59 64 22 22 22 46 46 46 82 82 82 2 2 6 106 106 106
49643-170 170 170 26 26 26 86 86 86 226 226 226 124 127 131 10 10 10 14 14 14 46 46 46
49644-231 231 231 190 190 190 6 6 6 70 70 70 90 90 90 238 238 238 151 151 151 2 2 6
49645-2 2 6 2 2 6 2 2 6 2 2 6 70 70 70 58 58 58 22 22 22 6 6 6
49646-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49647-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49648-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49649-
49650-1 2 2 8 15 6 24 53 24 34 76 34 19 31 15 8 15 6 63 55 20 63 55 20
49651-18 18 18 40 48 73 74 77 160 78 78 174 78 78 174 81 82 173 74 77 160 52 67 79
49652-17 23 26 21 31 35 60 80 103 81 88 166 74 77 160 78 102 129 36 54 60 12 17 20
49653-42 59 64 48 63 69 21 31 35 18 18 18 42 42 42 86 86 86 6 6 6 116 116 116
49654-106 106 106 6 6 6 70 70 70 151 151 151 124 127 131 18 18 18 38 38 38 54 54 54
49655-221 221 221 106 106 106 2 2 6 14 14 14 46 46 46 190 190 190 198 198 198 2 2 6
49656-2 2 6 2 2 6 2 2 6 2 2 6 74 74 74 62 62 62 22 22 22 6 6 6
49657-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49658-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49659-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49660-
49661-11 15 17 0 0 0 12 22 15 19 31 15 8 15 6 63 55 20 149 139 69 149 139 69
49662-63 55 20 10 10 22 54 54 122 78 78 174 78 78 174 78 78 174 81 82 173 68 78 128
49663-24 31 37 6 6 6 36 50 56 60 80 103 51 61 92 42 59 64 36 50 56 31 45 49
49664-29 43 47 27 40 45 6 8 8 14 14 14 42 42 42 94 94 94 14 14 14 101 101 101
49665-124 127 131 2 2 6 18 18 18 116 116 116 106 107 48 121 92 8 121 92 8 98 70 6
49666-170 170 170 106 106 106 2 2 6 2 2 6 2 2 6 195 195 195 195 195 195 6 6 6
49667-2 2 6 2 2 6 2 2 6 2 2 6 74 74 74 62 62 62 22 22 22 6 6 6
49668-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49669-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49670-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49671-
49672-26 35 39 3 5 6 1 1 1 2 3 3 35 31 12 133 118 54 175 176 80 175 176 80
49673-133 118 54 35 31 12 23 29 47 54 54 122 78 78 174 78 78 174 74 77 160 68 78 128
49674-51 61 92 31 45 49 26 35 39 36 50 56 29 43 47 7 12 13 21 30 33 42 59 64
49675-18 25 28 7 12 13 1 1 1 10 10 10 38 38 38 90 90 90 14 14 14 58 58 58
49676-210 210 210 26 26 26 62 42 6 154 114 10 226 170 11 237 188 10 220 174 15 184 138 11
49677-220 174 15 174 140 55 35 31 12 2 2 6 70 70 70 246 246 246 124 131 137 2 2 6
49678-2 2 6 2 2 6 2 2 6 2 2 6 70 70 70 66 66 66 26 26 26 6 6 6
49679-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49680-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49681-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49682-
49683-27 40 45 17 23 26 2 3 3 1 1 1 56 77 35 165 152 80 175 176 80 175 176 80
49684-175 176 80 106 107 48 22 22 22 28 32 52 54 54 122 54 54 122 51 61 92 28 32 52
49685-20 27 34 31 45 49 11 15 17 7 12 13 36 50 56 31 45 49 29 43 47 36 50 56
49686-6 8 8 0 0 0 0 0 0 10 10 10 38 38 38 86 86 86 14 14 14 10 10 10
49687-195 195 195 198 179 130 192 133 9 220 174 15 239 182 13 237 188 10 232 195 16 239 207 25
49688-237 201 50 241 208 19 232 195 16 184 138 11 198 179 130 208 206 196 42 42 42 2 2 6
49689-2 2 6 2 2 6 2 2 6 2 2 6 50 50 50 74 74 74 30 30 30 6 6 6
49690-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49691-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49692-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49693-
49694-15 22 25 26 35 39 15 22 25 0 0 0 35 31 12 133 118 54 175 176 80 175 176 80
49695-175 176 80 165 152 80 56 77 35 6 8 12 23 29 47 13 17 26 2 2 6 0 0 0
49696-1 2 2 26 35 39 26 35 39 26 35 39 42 59 64 42 59 64 20 29 31 6 8 8
49697-0 0 0 0 0 0 0 0 0 10 10 10 34 34 34 86 86 86 14 14 14 2 2 6
49698-121 92 8 192 133 9 219 162 10 239 182 13 237 188 10 232 195 16 241 208 19 237 201 50
49699-237 201 50 239 207 25 241 208 19 241 208 19 241 208 19 230 187 11 121 92 8 2 2 6
49700-2 2 6 2 2 6 2 2 6 2 2 6 50 50 50 82 82 82 34 34 34 10 10 10
49701-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49702-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49703-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49704-
49705-1 2 2 15 22 25 31 45 49 6 8 12 4 5 3 63 55 20 149 139 69 175 176 80
49706-175 176 80 175 176 80 106 107 48 20 16 6 1 1 1 0 0 0 2 3 3 11 15 17
49707-21 30 33 36 50 56 36 50 56 24 31 37 15 22 25 6 8 8 0 0 0 0 0 0
49708-0 0 0 0 0 0 0 0 0 10 10 10 34 34 34 82 82 82 30 30 30 62 42 6
49709-180 123 7 206 145 10 230 174 11 239 182 13 237 188 10 238 202 15 241 208 19 237 201 50
49710-239 207 25 241 208 19 241 208 19 241 208 19 230 187 11 220 174 15 184 138 11 6 6 6
49711-2 2 6 2 2 6 2 2 6 2 2 6 26 26 26 94 94 94 42 42 42 14 14 14
49712-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49713-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49714-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49715-
49716-0 0 0 1 2 2 29 43 47 26 35 39 3 5 6 8 7 3 106 107 48 165 152 80
49717-175 176 80 149 139 69 63 55 20 4 5 3 2 3 3 12 17 20 26 35 39 26 35 39
49718-17 23 26 7 12 13 6 8 8 3 5 6 1 2 2 0 0 0 0 0 0 0 0 0
49719-0 0 0 0 0 0 0 0 0 10 10 10 30 30 30 78 78 78 50 50 50 104 69 6
49720-192 133 9 216 158 10 236 178 12 237 188 10 232 195 16 241 208 19 237 201 50 237 201 50
49721-241 208 19 241 208 19 241 208 19 204 160 10 200 144 11 216 158 10 156 118 10 2 2 6
49722-2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 90 90 90 54 54 54 18 18 18
49723-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49724-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49725-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49726-
49727-0 0 0 0 0 0 12 17 20 27 40 45 18 25 28 1 1 1 35 31 12 106 107 48
49728-149 139 69 56 77 35 8 7 3 1 2 2 12 17 20 26 35 39 21 31 35 11 15 17
49729-3 5 6 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49730-0 0 0 0 0 0 0 0 0 10 10 10 30 30 30 78 78 78 46 46 46 22 22 22
49731-137 92 6 204 160 10 239 182 13 237 188 10 238 202 15 241 208 19 241 208 19 241 208 19
49732-241 208 19 204 160 10 184 138 11 210 150 10 216 158 10 210 150 10 98 70 6 2 2 6
49733-6 6 6 54 54 54 14 14 14 2 2 6 2 2 6 62 62 62 74 74 74 30 30 30
49734-10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49735-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49736-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49737-
49738-0 0 0 0 0 0 1 1 1 15 22 25 33 49 54 12 17 20 2 3 3 35 31 12
49739-56 77 35 20 16 6 1 1 1 18 25 28 21 31 35 11 15 17 1 1 1 0 0 0
49740-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49741-0 0 0 0 0 0 0 0 0 10 10 10 34 34 34 78 78 78 50 50 50 6 6 6
49742-88 55 22 139 102 15 190 146 13 230 187 11 239 207 25 232 195 16 220 174 15 190 146 13
49743-171 120 8 192 133 9 210 150 10 213 154 11 185 146 40 165 152 80 101 98 89 2 2 6
49744-2 2 6 78 78 78 116 116 116 58 58 58 2 2 6 22 22 22 90 90 90 46 46 46
49745-18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49746-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49747-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49748-
49749-0 0 0 0 0 0 0 0 0 1 1 1 27 40 45 29 43 47 3 5 6 2 3 3
49750-8 7 3 1 1 1 17 23 26 31 45 49 15 22 25 0 0 0 0 0 0 0 0 0
49751-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49752-0 0 0 0 0 0 0 0 0 10 10 10 38 38 38 86 86 86 50 50 50 6 6 6
49753-124 127 131 168 158 138 156 107 11 171 120 8 204 160 10 184 138 11 197 138 11 200 144 11
49754-206 145 10 206 145 10 197 138 11 198 179 130 195 195 195 198 198 198 170 170 170 14 14 14
49755-2 2 6 22 22 22 116 116 116 116 116 116 22 22 22 2 2 6 74 74 74 70 70 70
49756-30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49757-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49758-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49759-
49760-0 0 0 0 0 0 0 0 0 0 0 0 11 15 17 31 45 49 26 35 39 3 5 6
49761-0 0 0 7 12 13 27 40 45 18 25 28 0 0 0 0 0 0 0 0 0 0 0 0
49762-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49763-0 0 0 0 0 0 6 6 6 18 18 18 50 50 50 101 101 101 26 26 26 10 10 10
49764-124 131 137 190 190 190 168 158 138 156 107 11 197 138 11 200 144 11 197 138 11 192 133 9
49765-180 123 7 185 146 40 198 179 130 187 187 187 202 202 202 221 221 221 214 214 214 66 66 66
49766-2 2 6 2 2 6 50 50 50 62 62 62 6 6 6 2 2 6 10 10 10 90 90 90
49767-50 50 50 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49768-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49769-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49770-
49771-0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 15 22 25 36 54 60 18 25 28
49772-0 0 0 21 30 33 27 40 45 2 3 3 0 0 0 0 0 0 0 0 0 0 0 0
49773-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49774-0 0 0 0 0 0 10 10 10 34 34 34 74 74 74 74 74 74 2 2 6 6 6 6
49775-151 151 151 198 198 198 190 190 190 168 158 138 148 132 55 156 107 11 156 107 11 169 125 40
49776-168 158 138 187 187 187 190 190 190 210 210 210 246 246 246 253 253 253 253 253 253 180 180 180
49777-6 6 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 62 62
49778-74 74 74 34 34 34 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49779-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49780-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49781-
49782-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 27 40 45 35 52 58
49783-18 25 28 35 52 58 17 23 26 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49784-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49785-0 0 0 10 10 10 22 22 22 54 54 54 94 94 94 18 18 18 2 2 6 46 46 46
49786-234 234 234 221 221 221 190 190 190 190 190 190 190 190 190 187 187 187 187 187 187 190 190 190
49787-190 190 190 195 195 195 214 214 214 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
49788-82 82 82 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 14 14 14
49789-86 86 86 54 54 54 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
49790-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49791-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49792-
49793-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 12 13 33 49 54
49794-52 72 81 36 54 60 6 8 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49795-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49796-6 6 6 18 18 18 46 46 46 90 90 90 46 46 46 18 18 18 6 6 6 180 180 180
49797-253 253 253 246 246 246 202 202 202 190 190 190 190 190 190 190 190 190 190 190 190 190 190 190
49798-202 202 202 231 231 231 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49799-202 202 202 14 14 14 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49800-42 42 42 86 86 86 42 42 42 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
49801-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49802-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49803-
49804-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 12 17 20
49805-36 54 60 29 43 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49806-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
49807-14 14 14 38 38 38 74 74 74 66 66 66 2 2 6 6 6 6 90 90 90 250 250 250
49808-253 253 253 253 253 253 238 238 238 198 198 198 190 190 190 190 190 190 195 195 195 221 221 221
49809-246 246 246 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49810-253 253 253 82 82 82 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49811-2 2 6 78 78 78 70 70 70 34 34 34 14 14 14 6 6 6 0 0 0 0 0 0
49812-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49813-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49814-
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-21 30 33 35 52 58 6 8 12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49817-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 14 14
49818-34 34 34 66 66 66 78 78 78 6 6 6 2 2 6 18 18 18 218 218 218 253 253 253
49819-253 253 253 253 253 253 253 253 253 246 246 246 226 226 226 231 231 231 246 246 246 253 253 253
49820-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49821-253 253 253 180 180 180 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49822-2 2 6 18 18 18 90 90 90 62 62 62 30 30 30 10 10 10 0 0 0 0 0 0
49823-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49824-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49825-
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-12 17 20 36 54 60 29 43 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49828-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10 26 26 26
49829-58 58 58 90 90 90 18 18 18 2 2 6 2 2 6 106 106 106 253 253 253 253 253 253
49830-253 253 253 253 253 253 253 253 253 253 253 253 250 250 250 253 253 253 253 253 253 253 253 253
49831-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49832-253 253 253 231 231 231 18 18 18 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49833-2 2 6 2 2 6 18 18 18 94 94 94 54 54 54 26 26 26 10 10 10 0 0 0
49834-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49835-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49836-
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 21 30 33 35 52 58 6 8 12 0 0 0 0 0 0 0 0 0 0 0 0
49839-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22 50 50 50
49840-90 90 90 26 26 26 2 2 6 2 2 6 14 14 14 195 195 195 250 250 250 253 253 253
49841-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49842-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49843-250 250 250 242 242 242 54 54 54 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49844-2 2 6 2 2 6 2 2 6 38 38 38 86 86 86 50 50 50 22 22 22 6 6 6
49845-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49846-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49847-
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 12 17 20 36 54 60 29 43 47 0 0 0 0 0 0 0 0 0
49850-0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 14 14 14 38 38 38 82 82 82
49851-34 34 34 2 2 6 2 2 6 2 2 6 42 42 42 195 195 195 246 246 246 253 253 253
49852-253 253 253 253 253 253 253 253 253 250 250 250 242 242 242 242 242 242 250 250 250 253 253 253
49853-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 250 250 250 246 246 246 238 238 238
49854-226 226 226 231 231 231 101 101 101 6 6 6 2 2 6 2 2 6 2 2 6 2 2 6
49855-2 2 6 2 2 6 2 2 6 2 2 6 38 38 38 82 82 82 42 42 42 14 14 14
49856-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49857-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49858-
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 21 30 33 35 52 58 6 8 12 0 0 0 0 0 0
49861-0 0 0 0 0 0 0 0 0 0 0 0 10 10 10 26 26 26 62 62 62 66 66 66
49862-2 2 6 2 2 6 2 2 6 6 6 6 70 70 70 170 170 170 202 202 202 234 234 234
49863-246 246 246 250 250 250 250 250 250 238 238 238 226 226 226 231 231 231 238 238 238 250 250 250
49864-250 250 250 250 250 250 246 246 246 231 231 231 214 214 214 202 202 202 202 202 202 202 202 202
49865-198 198 198 202 202 202 180 180 180 18 18 18 2 2 6 2 2 6 2 2 6 2 2 6
49866-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 62 62 66 66 66 30 30 30
49867-10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49868-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49869-
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 12 17 20 36 54 60 29 43 47 0 0 0 0 0 0
49872-0 0 0 0 0 0 0 0 0 0 0 0 14 14 14 42 42 42 82 82 82 18 18 18
49873-2 2 6 2 2 6 2 2 6 10 10 10 94 94 94 180 180 180 218 218 218 242 242 242
49874-250 250 250 253 253 253 253 253 253 250 250 250 234 234 234 253 253 253 253 253 253 253 253 253
49875-253 253 253 253 253 253 253 253 253 246 246 246 238 238 238 226 226 226 210 210 210 202 202 202
49876-195 195 195 195 195 195 210 210 210 151 151 151 6 6 6 14 14 14 50 50 50 14 14 14
49877-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 86 86 86 46 46 46
49878-18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49879-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49880-
49881-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49882-0 0 0 0 0 0 0 0 0 0 0 0 21 30 33 35 52 58 6 8 12 0 0 0
49883-0 0 0 0 0 0 0 0 0 6 6 6 22 22 22 54 54 54 70 70 70 2 2 6
49884-2 2 6 10 10 10 2 2 6 22 22 22 170 170 170 231 231 231 250 250 250 253 253 253
49885-253 253 253 253 253 253 253 253 253 250 250 250 242 242 242 253 253 253 253 253 253 253 253 253
49886-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 246 246 246
49887-231 231 231 202 202 202 198 198 198 226 226 226 94 94 94 2 2 6 6 6 6 38 38 38
49888-30 30 30 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 62 62 66 66 66
49889-26 26 26 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49890-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49891-
49892-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49893-0 0 0 0 0 0 0 0 0 0 0 0 6 8 8 33 49 54 29 43 47 6 8 12
49894-0 0 0 0 0 0 0 0 0 10 10 10 30 30 30 74 74 74 50 50 50 2 2 6
49895-26 26 26 26 26 26 2 2 6 106 106 106 238 238 238 253 253 253 253 253 253 253 253 253
49896-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49897-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49898-253 253 253 246 246 246 218 218 218 202 202 202 210 210 210 14 14 14 2 2 6 2 2 6
49899-30 30 30 22 22 22 2 2 6 2 2 6 2 2 6 2 2 6 18 18 18 86 86 86
49900-42 42 42 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49901-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49902-
49903-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49904-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 12 17 20 33 49 54 17 23 26
49905-0 0 0 0 0 0 0 0 0 14 14 14 42 42 42 90 90 90 22 22 22 2 2 6
49906-42 42 42 2 2 6 18 18 18 218 218 218 253 253 253 253 253 253 253 253 253 253 253 253
49907-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49908-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49909-253 253 253 253 253 253 250 250 250 221 221 221 218 218 218 101 101 101 2 2 6 14 14 14
49910-18 18 18 38 38 38 10 10 10 2 2 6 2 2 6 2 2 6 2 2 6 78 78 78
49911-58 58 58 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49912-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49913-
49914-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49915-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 15 22 25 36 54 60
49916-0 0 0 0 0 0 0 0 0 18 18 18 54 54 54 82 82 82 2 2 6 26 26 26
49917-22 22 22 2 2 6 124 127 131 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49918-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49919-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49920-253 253 253 253 253 253 253 253 253 250 250 250 238 238 238 198 198 198 6 6 6 38 38 38
49921-58 58 58 26 26 26 38 38 38 2 2 6 2 2 6 2 2 6 2 2 6 46 46 46
49922-78 78 78 30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49923-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49924-
49925-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49926-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 21 30 33
49927-36 54 60 0 0 0 0 0 0 30 30 30 74 74 74 58 58 58 2 2 6 42 42 42
49928-2 2 6 22 22 22 231 231 231 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49929-253 253 253 253 253 253 253 253 253 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253
49930-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49931-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 246 246 246 46 46 46 38 38 38
49932-42 42 42 14 14 14 38 38 38 14 14 14 2 2 6 2 2 6 2 2 6 6 6 6
49933-86 86 86 46 46 46 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49934-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49935-
49936-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49937-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-36 54 60 0 0 0 0 0 0 42 42 42 90 90 90 18 18 18 18 18 18 26 26 26
49939-2 2 6 116 116 116 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49940-253 253 253 253 253 253 250 250 250 238 238 238 253 253 253 253 253 253 253 253 253 253 253 253
49941-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49942-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 94 94 94 6 6 6
49943-2 2 6 2 2 6 10 10 10 34 34 34 2 2 6 2 2 6 2 2 6 2 2 6
49944-74 74 74 58 58 58 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
49945-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49946-
49947-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49948-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-0 0 0 36 54 60 26 26 26 66 66 66 82 82 82 2 2 6 38 38 38 6 6 6
49950-14 14 14 210 210 210 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49951-253 253 253 253 253 253 246 246 246 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
49952-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49953-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 151 151 151 2 2 6
49954-2 2 6 2 2 6 2 2 6 46 46 46 2 2 6 2 2 6 2 2 6 2 2 6
49955-42 42 42 74 74 74 30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0
49956-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49957-
49958-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49959-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-6 6 6 36 54 60 21 30 33 90 90 90 26 26 26 6 6 6 42 42 42 2 2 6
49961-74 74 74 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49962-253 253 253 253 253 253 242 242 242 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
49963-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49964-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 180 180 180 2 2 6
49965-2 2 6 2 2 6 2 2 6 46 46 46 2 2 6 2 2 6 2 2 6 2 2 6
49966-10 10 10 86 86 86 38 38 38 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0
49967-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49968-
49969-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49970-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-10 10 10 26 26 26 36 54 60 82 82 82 2 2 6 22 22 22 18 18 18 2 2 6
49972-151 151 151 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49973-253 253 253 253 253 253 234 234 234 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
49974-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49975-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 202 202 202 2 2 6
49976-2 2 6 2 2 6 2 2 6 38 38 38 2 2 6 2 2 6 2 2 6 2 2 6
49977-6 6 6 86 86 86 46 46 46 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0
49978-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49979-
49980-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49981-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
49982-18 18 18 46 46 46 86 86 86 36 54 60 2 2 6 34 34 34 10 10 10 6 6 6
49983-210 210 210 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49984-253 253 253 253 253 253 234 234 234 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
49985-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49986-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 221 221 221 6 6 6
49987-2 2 6 2 2 6 6 6 6 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6
49988-2 2 6 82 82 82 54 54 54 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
49989-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49990-
49991-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49992-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
49993-26 26 26 66 66 66 62 62 62 2 2 6 2 2 6 38 38 38 10 10 10 26 26 26
49994-238 238 238 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49995-253 253 253 253 253 253 231 231 231 238 238 238 253 253 253 253 253 253 253 253 253 253 253 253
49996-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49997-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 231 231 231 6 6 6
49998-2 2 6 2 2 6 10 10 10 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6
49999-2 2 6 66 66 66 58 58 58 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0
50000-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50001-
50002-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50003-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50004-38 38 38 78 78 78 6 6 6 2 2 6 2 2 6 46 46 46 14 14 14 42 42 42
50005-246 246 246 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50006-253 253 253 253 253 253 231 231 231 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50007-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50008-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 234 234 234 10 10 10
50009-2 2 6 2 2 6 22 22 22 14 14 14 2 2 6 2 2 6 2 2 6 2 2 6
50010-2 2 6 66 66 66 62 62 62 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0
50011-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50012-
50013-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50014-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18
50015-50 50 50 74 74 74 2 2 6 2 2 6 14 14 14 70 70 70 34 34 34 62 62 62
50016-250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50017-253 253 253 253 253 253 231 231 231 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253
50018-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50019-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 234 234 234 14 14 14
50020-2 2 6 2 2 6 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50021-2 2 6 66 66 66 62 62 62 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0
50022-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50023-
50024-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50025-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18
50026-54 54 54 62 62 62 2 2 6 2 2 6 2 2 6 30 30 30 46 46 46 70 70 70
50027-250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50028-253 253 253 253 253 253 231 231 231 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253
50029-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50030-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 226 226 226 10 10 10
50031-2 2 6 6 6 6 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50032-2 2 6 66 66 66 58 58 58 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0
50033-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50034-
50035-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50036-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22
50037-58 58 58 62 62 62 2 2 6 2 2 6 2 2 6 2 2 6 30 30 30 78 78 78
50038-250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50039-253 253 253 253 253 253 231 231 231 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253
50040-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50041-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 202 202 202 2 2 6
50042-22 22 22 34 34 34 20 16 6 22 22 22 26 26 26 18 18 18 6 6 6 2 2 6
50043-2 2 6 82 82 82 54 54 54 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
50044-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50045-
50046-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50047-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 26 26 26
50048-62 62 62 106 106 106 63 55 20 184 138 11 204 160 10 121 92 8 6 6 6 62 62 62
50049-238 238 238 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50050-253 253 253 253 253 253 231 231 231 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253
50051-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50052-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 151 151 151 18 18 18
50053-14 14 14 2 2 6 2 2 6 2 2 6 6 6 6 18 18 18 66 66 66 38 38 38
50054-6 6 6 94 94 94 50 50 50 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
50055-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50056-
50057-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50058-0 0 0 0 0 0 0 0 0 6 6 6 10 10 10 10 10 10 18 18 18 38 38 38
50059-78 78 78 138 132 106 216 158 10 242 186 14 246 190 14 246 190 14 156 118 10 10 10 10
50060-90 90 90 238 238 238 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50061-253 253 253 253 253 253 231 231 231 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253
50062-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50063-253 253 253 253 253 253 253 253 253 246 230 190 214 187 87 214 187 87 185 146 40 35 31 12
50064-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 38 38 38 46 46 46
50065-26 26 26 106 106 106 54 54 54 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
50066-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50067-
50068-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50069-0 0 0 6 6 6 14 14 14 22 22 22 30 30 30 38 38 38 50 50 50 70 70 70
50070-106 106 106 185 146 40 226 170 11 242 186 14 246 190 14 246 190 14 246 190 14 154 114 10
50071-6 6 6 74 74 74 226 226 226 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50072-253 253 253 253 253 253 231 231 231 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253
50073-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50074-253 253 253 253 253 253 253 253 253 237 201 50 241 196 14 241 208 19 232 195 16 35 31 12
50075-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 30 30 30 26 26 26
50076-204 160 10 165 152 80 66 66 66 26 26 26 6 6 6 0 0 0 0 0 0 0 0 0
50077-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50078-
50079-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50080-6 6 6 18 18 18 38 38 38 58 58 58 78 78 78 86 86 86 101 101 101 124 127 131
50081-174 140 55 210 150 10 234 174 13 246 186 14 246 190 14 246 190 14 246 190 14 237 188 10
50082-98 70 6 2 2 6 46 46 46 198 198 198 253 253 253 253 253 253 253 253 253 253 253 253
50083-253 253 253 253 253 253 234 234 234 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50084-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50085-253 253 253 253 253 253 253 253 253 214 187 87 242 186 14 241 196 14 204 160 10 20 16 6
50086-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 121 92 8
50087-238 202 15 232 195 16 82 82 82 34 34 34 10 10 10 0 0 0 0 0 0 0 0 0
50088-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50089-
50090-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50091-14 14 14 38 38 38 70 70 70 148 132 55 185 146 40 200 144 11 197 138 11 197 138 11
50092-213 154 11 226 170 11 242 186 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50093-220 174 15 35 31 12 2 2 6 22 22 22 151 151 151 250 250 250 253 253 253 253 253 253
50094-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50095-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50096-253 253 253 250 250 250 242 242 242 214 187 87 239 182 13 237 188 10 213 154 11 35 31 12
50097-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 42 6 220 174 15
50098-237 188 10 237 188 10 113 101 86 42 42 42 14 14 14 0 0 0 0 0 0 0 0 0
50099-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50100-
50101-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50102-22 22 22 54 54 54 148 132 55 213 154 11 226 170 11 230 174 11 226 170 11 226 170 11
50103-236 178 12 242 186 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50104-241 196 14 184 138 11 10 10 10 2 2 6 6 6 6 116 116 116 242 242 242 253 253 253
50105-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50106-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50107-253 253 253 231 231 231 198 198 198 213 164 39 236 178 12 236 178 12 210 150 10 137 92 6
50108-20 16 6 2 2 6 2 2 6 2 2 6 6 6 6 62 42 6 200 144 11 236 178 12
50109-239 182 13 239 182 13 124 112 88 58 58 58 22 22 22 6 6 6 0 0 0 0 0 0
50110-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50111-
50112-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50113-30 30 30 70 70 70 169 125 40 226 170 11 239 182 13 242 186 14 242 186 14 246 186 14
50114-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50115-246 190 14 232 195 16 98 70 6 2 2 6 2 2 6 2 2 6 66 66 66 221 221 221
50116-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50117-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50118-253 253 253 202 202 202 198 198 198 213 164 39 230 174 11 230 174 11 216 158 10 192 133 9
50119-163 110 8 120 80 7 98 70 6 120 80 7 167 114 7 197 138 11 226 170 11 239 182 13
50120-242 186 14 242 186 14 165 152 80 78 78 78 34 34 34 14 14 14 6 6 6 0 0 0
50121-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50122-
50123-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50124-30 30 30 78 78 78 185 146 40 226 170 11 239 182 13 246 190 14 246 190 14 246 190 14
50125-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50126-246 190 14 241 196 14 204 160 10 20 16 6 2 2 6 2 2 6 2 2 6 38 38 38
50127-218 218 218 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50128-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50129-250 250 250 202 202 202 198 198 198 213 164 39 226 170 11 236 178 12 224 166 10 210 150 10
50130-200 144 11 197 138 11 192 133 9 197 138 11 210 150 10 226 170 11 242 186 14 246 190 14
50131-246 190 14 246 186 14 220 174 15 124 112 88 62 62 62 30 30 30 14 14 14 6 6 6
50132-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50133-
50134-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50135-30 30 30 78 78 78 174 140 55 224 166 10 239 182 13 246 190 14 246 190 14 246 190 14
50136-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50137-246 190 14 246 190 14 241 196 14 139 102 15 2 2 6 2 2 6 2 2 6 2 2 6
50138-78 78 78 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50139-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50140-250 250 250 214 214 214 198 198 198 185 146 40 219 162 10 236 178 12 234 174 13 224 166 10
50141-216 158 10 213 154 11 213 154 11 216 158 10 226 170 11 239 182 13 246 190 14 246 190 14
50142-246 190 14 246 190 14 242 186 14 213 164 39 101 101 101 58 58 58 30 30 30 14 14 14
50143-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50144-
50145-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50146-30 30 30 74 74 74 174 140 55 216 158 10 236 178 12 246 190 14 246 190 14 246 190 14
50147-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50148-246 190 14 246 190 14 241 196 14 230 187 11 62 42 6 2 2 6 2 2 6 2 2 6
50149-22 22 22 238 238 238 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50150-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50151-253 253 253 226 226 226 187 187 187 169 125 40 216 158 10 236 178 12 239 182 13 236 178 12
50152-230 174 11 226 170 11 226 170 11 230 174 11 236 178 12 242 186 14 246 190 14 246 190 14
50153-246 190 14 246 190 14 246 186 14 239 182 13 213 164 39 106 106 106 66 66 66 34 34 34
50154-14 14 14 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50155-
50156-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50157-26 26 26 70 70 70 149 139 69 213 154 11 236 178 12 246 190 14 246 190 14 246 190 14
50158-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50159-246 190 14 246 190 14 246 190 14 241 196 14 190 146 13 20 16 6 2 2 6 2 2 6
50160-46 46 46 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50161-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50162-253 253 253 221 221 221 86 86 86 156 107 11 216 158 10 236 178 12 242 186 14 246 186 14
50163-242 186 14 239 182 13 239 182 13 242 186 14 242 186 14 246 186 14 246 190 14 246 190 14
50164-246 190 14 246 190 14 246 190 14 246 190 14 242 186 14 220 174 15 149 139 69 66 66 66
50165-30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50166-
50167-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50168-26 26 26 70 70 70 149 139 69 210 150 10 236 178 12 246 190 14 246 190 14 246 190 14
50169-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50170-246 190 14 246 190 14 246 190 14 246 190 14 232 195 16 121 92 8 34 34 34 106 106 106
50171-221 221 221 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50172-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50173-242 242 242 82 82 82 20 16 6 163 110 8 216 158 10 236 178 12 242 186 14 246 190 14
50174-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50175-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 242 186 14 149 139 69
50176-46 46 46 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50177-
50178-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50179-30 30 30 78 78 78 149 139 69 210 150 10 236 178 12 246 186 14 246 190 14 246 190 14
50180-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50181-246 190 14 246 190 14 246 190 14 246 190 14 241 196 14 220 174 15 198 179 130 253 253 253
50182-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50183-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 218 218 218
50184-58 58 58 2 2 6 20 16 6 167 114 7 216 158 10 236 178 12 246 186 14 246 190 14
50185-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50186-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 186 14 242 186 14 185 146 40
50187-54 54 54 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50188-
50189-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 14 14
50190-38 38 38 86 86 86 169 125 40 213 154 11 236 178 12 246 186 14 246 190 14 246 190 14
50191-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50192-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 232 195 16 190 146 13 214 214 214
50193-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50194-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 250 250 250 170 170 170 26 26 26
50195-2 2 6 2 2 6 35 31 12 163 110 8 219 162 10 239 182 13 246 186 14 246 190 14
50196-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50197-246 190 14 246 190 14 246 190 14 246 190 14 246 186 14 236 178 12 224 166 10 149 139 69
50198-46 46 46 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50199-
50200-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18
50201-50 50 50 113 101 86 192 133 9 224 166 10 242 186 14 246 190 14 246 190 14 246 190 14
50202-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50203-246 190 14 246 190 14 246 190 14 246 190 14 242 186 14 230 187 11 204 160 10 133 118 54
50204-226 226 226 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50205-253 253 253 253 253 253 253 253 253 253 253 253 198 198 198 66 66 66 2 2 6 2 2 6
50206-2 2 6 2 2 6 62 42 6 156 107 11 219 162 10 239 182 13 246 186 14 246 190 14
50207-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50208-246 190 14 246 190 14 246 190 14 242 186 14 234 174 13 213 154 11 148 132 55 66 66 66
50209-30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50210-
50211-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22
50212-58 58 58 148 132 55 206 145 10 234 174 13 242 186 14 246 186 14 246 190 14 246 190 14
50213-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50214-246 190 14 246 190 14 246 190 14 246 190 14 246 186 14 236 178 12 204 160 10 163 110 8
50215-62 42 6 124 131 137 218 218 218 250 250 250 253 253 253 253 253 253 253 253 253 250 250 250
50216-242 242 242 210 210 210 151 151 151 66 66 66 6 6 6 2 2 6 2 2 6 2 2 6
50217-2 2 6 2 2 6 62 42 6 163 110 8 216 158 10 236 178 12 246 190 14 246 190 14
50218-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50219-246 190 14 239 182 13 230 174 11 216 158 10 185 146 40 124 112 88 70 70 70 38 38 38
50220-18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50221-
50222-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22
50223-62 62 62 169 125 40 206 145 10 224 166 10 236 178 12 239 182 13 242 186 14 242 186 14
50224-246 186 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50225-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 236 178 12 216 158 10 171 120 8
50226-85 57 6 2 2 6 6 6 6 30 30 30 54 54 54 62 62 62 50 50 50 38 38 38
50227-14 14 14 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50228-2 2 6 6 6 6 85 57 6 167 114 7 213 154 11 236 178 12 246 190 14 246 190 14
50229-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 242 186 14 239 182 13 239 182 13
50230-230 174 11 210 150 10 174 140 55 124 112 88 82 82 82 54 54 54 34 34 34 18 18 18
50231-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50232-
50233-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18
50234-50 50 50 169 125 40 192 133 9 200 144 11 216 158 10 219 162 10 224 166 10 226 170 11
50235-230 174 11 236 178 12 239 182 13 239 182 13 242 186 14 246 186 14 246 190 14 246 190 14
50236-246 190 14 246 190 14 246 190 14 246 190 14 246 186 14 230 174 11 210 150 10 163 110 8
50237-104 69 6 10 10 10 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50238-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50239-2 2 6 6 6 6 85 57 6 167 114 7 206 145 10 230 174 11 242 186 14 246 190 14
50240-246 190 14 246 190 14 246 186 14 242 186 14 239 182 13 230 174 11 224 166 10 213 154 11
50241-169 125 40 124 112 88 86 86 86 58 58 58 38 38 38 22 22 22 10 10 10 6 6 6
50242-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50243-
50244-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 14 14
50245-34 34 34 70 70 70 133 118 54 169 125 40 167 114 7 180 123 7 192 133 9 197 138 11
50246-200 144 11 206 145 10 213 154 11 219 162 10 224 166 10 230 174 11 239 182 13 242 186 14
50247-246 186 14 246 186 14 246 186 14 246 186 14 239 182 13 216 158 10 184 138 11 152 99 6
50248-104 69 6 20 16 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50249-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50250-2 2 6 6 6 6 85 57 6 152 99 6 192 133 9 219 162 10 236 178 12 239 182 13
50251-246 186 14 242 186 14 239 182 13 236 178 12 224 166 10 206 145 10 192 133 9 148 132 55
50252-94 94 94 62 62 62 42 42 42 22 22 22 14 14 14 6 6 6 0 0 0 0 0 0
50253-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50254-
50255-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50256-18 18 18 34 34 34 58 58 58 78 78 78 101 98 89 124 112 88 133 118 54 156 107 11
50257-163 110 8 167 114 7 171 120 8 180 123 7 184 138 11 197 138 11 210 150 10 219 162 10
50258-226 170 11 236 178 12 236 178 12 234 174 13 219 162 10 197 138 11 163 110 8 134 84 6
50259-85 57 6 10 10 10 2 2 6 2 2 6 18 18 18 38 38 38 38 38 38 38 38 38
50260-38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 26 26 26 2 2 6
50261-2 2 6 6 6 6 62 42 6 137 92 6 171 120 8 200 144 11 219 162 10 230 174 11
50262-234 174 13 230 174 11 219 162 10 210 150 10 192 133 9 163 110 8 124 112 88 82 82 82
50263-50 50 50 30 30 30 14 14 14 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
50264-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50265-
50266-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50267-6 6 6 14 14 14 22 22 22 34 34 34 42 42 42 58 58 58 74 74 74 86 86 86
50268-101 98 89 113 101 86 133 118 54 121 92 8 137 92 6 152 99 6 163 110 8 180 123 7
50269-184 138 11 197 138 11 206 145 10 200 144 11 180 123 7 156 107 11 134 84 6 104 69 6
50270-62 42 6 54 54 54 106 106 106 101 98 89 86 86 86 82 82 82 78 78 78 78 78 78
50271-78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 82 82 82 86 86 86 94 94 94
50272-106 106 106 101 101 101 90 61 47 120 80 7 156 107 11 180 123 7 192 133 9 200 144 11
50273-206 145 10 200 144 11 192 133 9 171 120 8 139 102 15 113 101 86 70 70 70 42 42 42
50274-22 22 22 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50275-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50276-
50277-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50278-0 0 0 0 0 0 6 6 6 10 10 10 14 14 14 22 22 22 30 30 30 38 38 38
50279-50 50 50 62 62 62 74 74 74 90 90 90 101 98 89 113 101 86 121 92 8 120 80 7
50280-137 92 6 152 99 6 152 99 6 152 99 6 134 84 6 120 80 7 98 70 6 88 55 22
50281-101 98 89 82 82 82 58 58 58 46 46 46 38 38 38 34 34 34 34 34 34 34 34 34
50282-34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 38 38 38 42 42 42
50283-54 54 54 82 82 82 94 86 71 85 57 6 134 84 6 156 107 11 167 114 7 171 120 8
50284-171 120 8 167 114 7 152 99 6 121 92 8 101 98 89 62 62 62 34 34 34 18 18 18
50285-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50286-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50287-
50288-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50289-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 6 6 6 10 10 10
50290-18 18 18 22 22 22 30 30 30 42 42 42 50 50 50 66 66 66 86 86 86 101 98 89
50291-94 86 71 98 70 6 104 69 6 104 69 6 104 69 6 85 57 6 88 55 22 90 90 90
50292-62 62 62 38 38 38 22 22 22 14 14 14 10 10 10 10 10 10 10 10 10 10 10 10
50293-10 10 10 10 10 10 6 6 6 10 10 10 10 10 10 10 10 10 10 10 10 14 14 14
50294-22 22 22 42 42 42 70 70 70 94 86 71 85 57 6 104 69 6 120 80 7 137 92 6
50295-134 84 6 120 80 7 94 86 71 86 86 86 58 58 58 30 30 30 14 14 14 6 6 6
50296-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50297-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50298-
50299-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50300-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50301-0 0 0 6 6 6 10 10 10 14 14 14 18 18 18 26 26 26 38 38 38 54 54 54
50302-70 70 70 86 86 86 94 86 71 94 86 71 94 86 71 86 86 86 74 74 74 50 50 50
50303-30 30 30 14 14 14 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50304-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50305-6 6 6 18 18 18 34 34 34 58 58 58 82 82 82 94 86 71 94 86 71 94 86 71
50306-94 86 71 94 86 71 74 74 74 50 50 50 26 26 26 14 14 14 6 6 6 0 0 0
50307-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50308-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50309-
50310-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50311-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50312-0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 6 6 6 14 14 14 18 18 18
50313-30 30 30 38 38 38 46 46 46 54 54 54 50 50 50 42 42 42 30 30 30 18 18 18
50314-10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50315-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50316-0 0 0 6 6 6 14 14 14 26 26 26 38 38 38 50 50 50 58 58 58 58 58 58
50317-54 54 54 42 42 42 30 30 30 18 18 18 10 10 10 0 0 0 0 0 0 0 0 0
50318-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50319-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50320-
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-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50324-6 6 6 10 10 10 14 14 14 18 18 18 18 18 18 14 14 14 10 10 10 6 6 6
50325-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50326-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50327-0 0 0 0 0 0 0 0 0 6 6 6 14 14 14 18 18 18 22 22 22 22 22 22
50328-18 18 18 14 14 14 10 10 10 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
50329-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50330-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50331-
50332+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50333+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50334+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50335+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50336+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50337+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50338+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50339+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50340+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50341+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50342+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50343+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50344+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50345+4 4 4 4 4 4
50346+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50347+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50348+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50349+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50350+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50351+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50352+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50353+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50354+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50355+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50356+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50357+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50358+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50359+4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4
50371+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50372+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50373+4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4
50385+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50386+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50387+4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4
50399+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50400+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50401+4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4
50413+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50414+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50415+4 4 4 4 4 4
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 3 3 3 0 0 0 0 0 0
50421+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 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 1 1 1 0 0 0
50426+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
50427+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
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
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 2 2 2 0 0 0 3 4 3 26 28 28
50435+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
50436+5 5 5 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 3 3 3 0 0 0 1 1 1 6 6 6
50440+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
50441+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
50442+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50443+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 4 4 4 4 4 4 4 4 4
50446+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50447+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50448+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
50449+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
50450+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
50451+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50452+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50453+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
50454+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
50455+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
50456+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
50457+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 4 4 4 4 4 4 4 4 4 4 4 4
50460+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50461+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
50462+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
50463+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
50464+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
50465+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50466+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
50467+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
50468+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
50469+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
50470+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
50471+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+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50474+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50475+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
50476+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
50477+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
50478+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
50479+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
50480+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
50481+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
50482+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
50483+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
50484+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
50485+4 4 4 4 4 4
50486+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50487+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50488+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
50489+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
50490+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
50491+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
50492+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
50493+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
50494+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
50495+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
50496+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
50497+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
50498+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
50499+4 4 4 4 4 4
50500+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50501+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50502+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
50503+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
50504+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
50505+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
50506+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
50507+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
50508+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
50509+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
50510+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
50511+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
50512+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
50513+4 4 4 4 4 4
50514+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50515+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50516+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
50517+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
50518+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
50519+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
50520+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
50521+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
50522+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
50523+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
50524+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
50525+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
50526+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
50527+4 4 4 4 4 4
50528+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50529+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50530+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
50531+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
50532+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
50533+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
50534+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
50535+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
50536+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
50537+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
50538+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
50539+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
50540+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
50541+4 4 4 4 4 4
50542+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50543+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50544+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
50545+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
50546+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
50547+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
50548+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
50549+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
50550+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
50551+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
50552+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
50553+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
50554+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
50555+4 4 4 4 4 4
50556+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50557+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
50558+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
50559+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
50560+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
50561+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
50562+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
50563+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
50564+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
50565+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
50566+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
50567+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
50568+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
50569+4 4 4 4 4 4
50570+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50571+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
50572+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
50573+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
50574+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
50575+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
50576+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
50577+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
50578+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
50579+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
50580+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
50581+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
50582+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
50583+0 0 0 4 4 4
50584+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
50585+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
50586+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
50587+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
50588+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
50589+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
50590+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
50591+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
50592+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
50593+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
50594+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
50595+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
50596+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
50597+2 0 0 0 0 0
50598+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
50599+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
50600+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
50601+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
50602+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
50603+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
50604+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
50605+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
50606+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
50607+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
50608+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
50609+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
50610+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
50611+37 38 37 0 0 0
50612+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
50613+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
50614+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
50615+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
50616+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
50617+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
50618+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
50619+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
50620+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
50621+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
50622+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
50623+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
50624+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
50625+85 115 134 4 0 0
50626+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
50627+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
50628+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
50629+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
50630+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
50631+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
50632+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
50633+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
50634+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
50635+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
50636+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
50637+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
50638+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
50639+60 73 81 4 0 0
50640+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
50641+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
50642+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
50643+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
50644+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
50645+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
50646+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
50647+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
50648+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
50649+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
50650+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
50651+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
50652+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
50653+16 19 21 4 0 0
50654+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
50655+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
50656+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
50657+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
50658+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
50659+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
50660+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
50661+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
50662+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
50663+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
50664+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
50665+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
50666+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
50667+4 0 0 4 3 3
50668+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
50669+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
50670+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
50671+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
50672+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
50673+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
50674+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
50675+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
50676+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
50677+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
50678+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
50679+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
50680+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
50681+3 2 2 4 4 4
50682+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
50683+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
50684+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
50685+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
50686+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
50687+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
50688+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50689+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
50690+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
50691+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
50692+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
50693+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
50694+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
50695+4 4 4 4 4 4
50696+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
50697+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
50698+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
50699+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
50700+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
50701+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
50702+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
50703+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
50704+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
50705+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
50706+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
50707+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
50708+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
50709+4 4 4 4 4 4
50710+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
50711+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
50712+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
50713+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
50714+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
50715+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
50716+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
50717+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
50718+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
50719+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
50720+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
50721+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
50722+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
50723+5 5 5 5 5 5
50724+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
50725+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
50726+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
50727+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
50728+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
50729+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
50730+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
50731+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
50732+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
50733+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
50734+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
50735+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
50736+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
50737+5 5 5 4 4 4
50738+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
50739+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
50740+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
50741+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
50742+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
50743+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
50744+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
50745+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
50746+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
50747+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
50748+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
50749+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
50750+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50751+4 4 4 4 4 4
50752+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
50753+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
50754+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
50755+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
50756+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
50757+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
50758+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
50759+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
50760+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
50761+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
50762+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
50763+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
50764+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50765+4 4 4 4 4 4
50766+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
50767+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
50768+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
50769+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
50770+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
50771+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
50772+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
50773+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
50774+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
50775+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
50776+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
50777+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50778+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50779+4 4 4 4 4 4
50780+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
50781+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
50782+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
50783+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
50784+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
50785+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
50786+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
50787+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
50788+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
50789+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
50790+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
50791+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50792+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50793+4 4 4 4 4 4
50794+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
50795+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
50796+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
50797+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
50798+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
50799+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
50800+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
50801+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
50802+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
50803+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
50804+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50805+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50806+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50807+4 4 4 4 4 4
50808+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
50809+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
50810+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
50811+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
50812+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
50813+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
50814+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
50815+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
50816+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
50817+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
50818+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
50819+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50820+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50821+4 4 4 4 4 4
50822+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
50823+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
50824+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
50825+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
50826+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
50827+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
50828+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
50829+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
50830+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
50831+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
50832+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
50833+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50834+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50835+4 4 4 4 4 4
50836+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
50837+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
50838+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
50839+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
50840+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
50841+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
50842+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
50843+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
50844+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
50845+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
50846+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50847+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50848+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50849+4 4 4 4 4 4
50850+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
50851+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
50852+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
50853+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
50854+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
50855+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
50856+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
50857+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
50858+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
50859+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
50860+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50861+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50862+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50863+4 4 4 4 4 4
50864+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
50865+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
50866+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
50867+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
50868+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
50869+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
50870+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
50871+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
50872+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
50873+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
50874+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50875+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50876+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50877+4 4 4 4 4 4
50878+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
50879+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
50880+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
50881+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
50882+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
50883+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
50884+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
50885+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
50886+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
50887+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50888+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50889+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50890+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50891+4 4 4 4 4 4
50892+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
50893+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
50894+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
50895+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
50896+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
50897+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
50898+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
50899+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
50900+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
50901+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50902+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50903+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50904+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50905+4 4 4 4 4 4
50906+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
50907+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
50908+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
50909+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
50910+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
50911+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
50912+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
50913+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
50914+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
50915+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50916+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50917+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50918+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50919+4 4 4 4 4 4
50920+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
50921+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
50922+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
50923+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
50924+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
50925+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
50926+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
50927+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
50928+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
50929+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50930+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50931+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50932+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50933+4 4 4 4 4 4
50934+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
50935+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
50936+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
50937+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
50938+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
50939+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
50940+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
50941+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
50942+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
50943+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50944+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50945+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50946+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50947+4 4 4 4 4 4
50948+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
50949+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
50950+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
50951+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
50952+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
50953+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
50954+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
50955+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
50956+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
50957+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50958+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50959+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50960+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50961+4 4 4 4 4 4
50962+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
50963+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
50964+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
50965+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
50966+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
50967+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
50968+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
50969+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
50970+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
50971+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50972+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50973+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50974+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50975+4 4 4 4 4 4
50976+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
50977+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
50978+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
50979+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
50980+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
50981+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
50982+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
50983+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
50984+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
50985+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50986+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50987+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50988+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50989+4 4 4 4 4 4
50990+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
50991+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
50992+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
50993+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
50994+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
50995+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
50996+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
50997+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
50998+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
50999+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51000+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51001+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51002+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51003+4 4 4 4 4 4
51004+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
51005+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
51006+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
51007+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
51008+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
51009+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
51010+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51011+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
51012+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51013+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51014+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51015+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51016+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51017+4 4 4 4 4 4
51018+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
51019+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
51020+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
51021+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
51022+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
51023+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
51024+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51025+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
51026+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
51027+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51028+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51029+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51030+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51031+4 4 4 4 4 4
51032+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
51033+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
51034+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
51035+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
51036+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
51037+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
51038+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
51039+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
51040+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
51041+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51042+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51043+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51044+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51045+4 4 4 4 4 4
51046+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
51047+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
51048+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
51049+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
51050+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
51051+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
51052+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
51053+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
51054+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
51055+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51056+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51057+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51058+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51059+4 4 4 4 4 4
51060+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
51061+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
51062+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
51063+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
51064+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
51065+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
51066+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
51067+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
51068+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
51069+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51070+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51071+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51072+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51073+4 4 4 4 4 4
51074+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
51075+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
51076+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
51077+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
51078+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
51079+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
51080+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
51081+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
51082+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
51083+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51084+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51085+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51086+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51087+4 4 4 4 4 4
51088+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
51089+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
51090+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
51091+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
51092+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
51093+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
51094+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
51095+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
51096+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
51097+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
51098+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51099+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51100+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51101+4 4 4 4 4 4
51102+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
51103+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
51104+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
51105+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
51106+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
51107+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
51108+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
51109+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
51110+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
51111+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
51112+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51113+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51114+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51115+4 4 4 4 4 4
51116+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
51117+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
51118+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
51119+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
51120+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
51121+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
51122+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51123+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
51124+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
51125+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
51126+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
51127+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51128+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51129+4 4 4 4 4 4
51130+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
51131+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
51132+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
51133+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
51134+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
51135+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
51136+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
51137+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
51138+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
51139+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
51140+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51141+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51142+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51143+4 4 4 4 4 4
51144+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
51145+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
51146+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
51147+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
51148+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
51149+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
51150+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
51151+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
51152+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
51153+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
51154+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51155+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51156+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51157+4 4 4 4 4 4
51158+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
51159+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
51160+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
51161+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
51162+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
51163+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
51164+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
51165+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
51166+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
51167+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
51168+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51169+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51170+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51171+4 4 4 4 4 4
51172+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
51173+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
51174+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
51175+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
51176+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
51177+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
51178+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
51179+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
51180+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
51181+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
51182+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51183+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51184+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51185+4 4 4 4 4 4
51186+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
51187+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
51188+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
51189+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
51190+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
51191+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
51192+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
51193+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
51194+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
51195+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
51196+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51197+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51198+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51199+4 4 4 4 4 4
51200+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
51201+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
51202+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
51203+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
51204+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
51205+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
51206+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
51207+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
51208+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
51209+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51210+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51211+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51212+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51213+4 4 4 4 4 4
51214+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
51215+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
51216+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
51217+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
51218+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
51219+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
51220+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
51221+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
51222+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
51223+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51224+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51225+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51226+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51227+4 4 4 4 4 4
51228+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
51229+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
51230+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
51231+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
51232+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
51233+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
51234+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
51235+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
51236+4 0 0 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 4 4 4 4 4 4 4 4 4 4 4 4
51239+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51240+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51241+4 4 4 4 4 4
51242+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
51243+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
51244+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
51245+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
51246+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
51247+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
51248+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
51249+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
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 4 4 4 4 4 4 4 4 4 4 4 4
51253+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51254+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51255+4 4 4 4 4 4
51256+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
51257+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
51258+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
51259+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
51260+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
51261+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
51262+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
51263+6 6 6 4 0 0 4 0 0 4 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4
51267+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51268+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51269+4 4 4 4 4 4
51270+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
51271+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
51272+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
51273+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
51274+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
51275+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
51276+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
51277+4 0 0 4 3 3 6 6 6 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 4 4 4 4 4 4 4 4 4 4 4 4
51281+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51282+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51283+4 4 4 4 4 4
51284+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51285+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
51286+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
51287+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
51288+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
51289+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
51290+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
51291+6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
51295+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51296+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51297+4 4 4 4 4 4
51298+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51299+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
51300+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
51301+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
51302+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
51303+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
51304+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
51305+5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
51309+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51310+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51311+4 4 4 4 4 4
51312+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51313+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51314+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
51315+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
51316+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
51317+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
51318+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
51319+4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
51323+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51324+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51325+4 4 4 4 4 4
51326+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51327+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51328+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
51329+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
51330+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
51331+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
51332+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
51337+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51338+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51339+4 4 4 4 4 4
51340+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51341+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51342+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51343+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
51344+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
51345+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
51346+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
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 4 4 4 4 4 4 4 4 4 4 4 4
51351+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51352+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51353+4 4 4 4 4 4
51354+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51355+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51356+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51357+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
51358+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
51359+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
51360+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
51365+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51366+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51367+4 4 4 4 4 4
51368+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51369+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51370+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51371+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
51372+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
51373+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
51374+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
51379+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51380+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51381+4 4 4 4 4 4
51382+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51383+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51384+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51385+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
51386+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
51387+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
51388+6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
51393+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51394+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51395+4 4 4 4 4 4
51396+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51397+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51398+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51399+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51400+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
51401+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
51402+4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
51407+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51408+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51409+4 4 4 4 4 4
51410+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51411+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51412+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51413+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51414+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
51415+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
51416+5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
51421+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51422+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51423+4 4 4 4 4 4
51424+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51425+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51426+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51427+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51428+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
51429+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
51435+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51436+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51437+4 4 4 4 4 4
51438+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51439+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51440+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51441+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51442+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
51443+5 5 5 4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
51449+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51450+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51451+4 4 4 4 4 4
51452diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
51453index fe92eed..106e085 100644
51454--- a/drivers/video/mb862xx/mb862xxfb_accel.c
51455+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
51456@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
51457 struct mb862xxfb_par *par = info->par;
51458
51459 if (info->var.bits_per_pixel == 32) {
51460- info->fbops->fb_fillrect = cfb_fillrect;
51461- info->fbops->fb_copyarea = cfb_copyarea;
51462- info->fbops->fb_imageblit = cfb_imageblit;
51463+ pax_open_kernel();
51464+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
51465+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
51466+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
51467+ pax_close_kernel();
51468 } else {
51469 outreg(disp, GC_L0EM, 3);
51470- info->fbops->fb_fillrect = mb86290fb_fillrect;
51471- info->fbops->fb_copyarea = mb86290fb_copyarea;
51472- info->fbops->fb_imageblit = mb86290fb_imageblit;
51473+ pax_open_kernel();
51474+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
51475+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
51476+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
51477+ pax_close_kernel();
51478 }
51479 outreg(draw, GDC_REG_DRAW_BASE, 0);
51480 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
51481diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
51482index ff22871..b129bed 100644
51483--- a/drivers/video/nvidia/nvidia.c
51484+++ b/drivers/video/nvidia/nvidia.c
51485@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
51486 info->fix.line_length = (info->var.xres_virtual *
51487 info->var.bits_per_pixel) >> 3;
51488 if (info->var.accel_flags) {
51489- info->fbops->fb_imageblit = nvidiafb_imageblit;
51490- info->fbops->fb_fillrect = nvidiafb_fillrect;
51491- info->fbops->fb_copyarea = nvidiafb_copyarea;
51492- info->fbops->fb_sync = nvidiafb_sync;
51493+ pax_open_kernel();
51494+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
51495+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
51496+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
51497+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
51498+ pax_close_kernel();
51499 info->pixmap.scan_align = 4;
51500 info->flags &= ~FBINFO_HWACCEL_DISABLED;
51501 info->flags |= FBINFO_READS_FAST;
51502 NVResetGraphics(info);
51503 } else {
51504- info->fbops->fb_imageblit = cfb_imageblit;
51505- info->fbops->fb_fillrect = cfb_fillrect;
51506- info->fbops->fb_copyarea = cfb_copyarea;
51507- info->fbops->fb_sync = NULL;
51508+ pax_open_kernel();
51509+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
51510+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
51511+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
51512+ *(void **)&info->fbops->fb_sync = NULL;
51513+ pax_close_kernel();
51514 info->pixmap.scan_align = 1;
51515 info->flags |= FBINFO_HWACCEL_DISABLED;
51516 info->flags &= ~FBINFO_READS_FAST;
51517@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
51518 info->pixmap.size = 8 * 1024;
51519 info->pixmap.flags = FB_PIXMAP_SYSTEM;
51520
51521- if (!hwcur)
51522- info->fbops->fb_cursor = NULL;
51523+ if (!hwcur) {
51524+ pax_open_kernel();
51525+ *(void **)&info->fbops->fb_cursor = NULL;
51526+ pax_close_kernel();
51527+ }
51528
51529 info->var.accel_flags = (!noaccel);
51530
51531diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
51532index 05c2dc3..ea1f391 100644
51533--- a/drivers/video/s1d13xxxfb.c
51534+++ b/drivers/video/s1d13xxxfb.c
51535@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
51536
51537 switch(prod_id) {
51538 case S1D13506_PROD_ID: /* activate acceleration */
51539- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
51540- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
51541+ pax_open_kernel();
51542+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
51543+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
51544+ pax_close_kernel();
51545 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
51546 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
51547 break;
51548diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
51549index e188ada..aac63c8 100644
51550--- a/drivers/video/smscufx.c
51551+++ b/drivers/video/smscufx.c
51552@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
51553 fb_deferred_io_cleanup(info);
51554 kfree(info->fbdefio);
51555 info->fbdefio = NULL;
51556- info->fbops->fb_mmap = ufx_ops_mmap;
51557+ pax_open_kernel();
51558+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
51559+ pax_close_kernel();
51560 }
51561
51562 pr_debug("released /dev/fb%d user=%d count=%d",
51563diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
51564index d2e5bc3..4cb05d1 100644
51565--- a/drivers/video/udlfb.c
51566+++ b/drivers/video/udlfb.c
51567@@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
51568 dlfb_urb_completion(urb);
51569
51570 error:
51571- atomic_add(bytes_sent, &dev->bytes_sent);
51572- atomic_add(bytes_identical, &dev->bytes_identical);
51573- atomic_add(width*height*2, &dev->bytes_rendered);
51574+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
51575+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
51576+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
51577 end_cycles = get_cycles();
51578- atomic_add(((unsigned int) ((end_cycles - start_cycles)
51579+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
51580 >> 10)), /* Kcycles */
51581 &dev->cpu_kcycles_used);
51582
51583@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
51584 dlfb_urb_completion(urb);
51585
51586 error:
51587- atomic_add(bytes_sent, &dev->bytes_sent);
51588- atomic_add(bytes_identical, &dev->bytes_identical);
51589- atomic_add(bytes_rendered, &dev->bytes_rendered);
51590+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
51591+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
51592+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
51593 end_cycles = get_cycles();
51594- atomic_add(((unsigned int) ((end_cycles - start_cycles)
51595+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
51596 >> 10)), /* Kcycles */
51597 &dev->cpu_kcycles_used);
51598 }
51599@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
51600 fb_deferred_io_cleanup(info);
51601 kfree(info->fbdefio);
51602 info->fbdefio = NULL;
51603- info->fbops->fb_mmap = dlfb_ops_mmap;
51604+ pax_open_kernel();
51605+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
51606+ pax_close_kernel();
51607 }
51608
51609 pr_warn("released /dev/fb%d user=%d count=%d\n",
51610@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
51611 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51612 struct dlfb_data *dev = fb_info->par;
51613 return snprintf(buf, PAGE_SIZE, "%u\n",
51614- atomic_read(&dev->bytes_rendered));
51615+ atomic_read_unchecked(&dev->bytes_rendered));
51616 }
51617
51618 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
51619@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
51620 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51621 struct dlfb_data *dev = fb_info->par;
51622 return snprintf(buf, PAGE_SIZE, "%u\n",
51623- atomic_read(&dev->bytes_identical));
51624+ atomic_read_unchecked(&dev->bytes_identical));
51625 }
51626
51627 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
51628@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
51629 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51630 struct dlfb_data *dev = fb_info->par;
51631 return snprintf(buf, PAGE_SIZE, "%u\n",
51632- atomic_read(&dev->bytes_sent));
51633+ atomic_read_unchecked(&dev->bytes_sent));
51634 }
51635
51636 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
51637@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
51638 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51639 struct dlfb_data *dev = fb_info->par;
51640 return snprintf(buf, PAGE_SIZE, "%u\n",
51641- atomic_read(&dev->cpu_kcycles_used));
51642+ atomic_read_unchecked(&dev->cpu_kcycles_used));
51643 }
51644
51645 static ssize_t edid_show(
51646@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
51647 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51648 struct dlfb_data *dev = fb_info->par;
51649
51650- atomic_set(&dev->bytes_rendered, 0);
51651- atomic_set(&dev->bytes_identical, 0);
51652- atomic_set(&dev->bytes_sent, 0);
51653- atomic_set(&dev->cpu_kcycles_used, 0);
51654+ atomic_set_unchecked(&dev->bytes_rendered, 0);
51655+ atomic_set_unchecked(&dev->bytes_identical, 0);
51656+ atomic_set_unchecked(&dev->bytes_sent, 0);
51657+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
51658
51659 return count;
51660 }
51661diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
51662index 7aec6f3..e3b2d55 100644
51663--- a/drivers/video/uvesafb.c
51664+++ b/drivers/video/uvesafb.c
51665@@ -19,6 +19,7 @@
51666 #include <linux/io.h>
51667 #include <linux/mutex.h>
51668 #include <linux/slab.h>
51669+#include <linux/moduleloader.h>
51670 #include <video/edid.h>
51671 #include <video/uvesafb.h>
51672 #ifdef CONFIG_X86
51673@@ -566,10 +567,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
51674 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
51675 par->pmi_setpal = par->ypan = 0;
51676 } else {
51677+
51678+#ifdef CONFIG_PAX_KERNEXEC
51679+#ifdef CONFIG_MODULES
51680+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
51681+#endif
51682+ if (!par->pmi_code) {
51683+ par->pmi_setpal = par->ypan = 0;
51684+ return 0;
51685+ }
51686+#endif
51687+
51688 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
51689 + task->t.regs.edi);
51690+
51691+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51692+ pax_open_kernel();
51693+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
51694+ pax_close_kernel();
51695+
51696+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
51697+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
51698+#else
51699 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
51700 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
51701+#endif
51702+
51703 printk(KERN_INFO "uvesafb: protected mode interface info at "
51704 "%04x:%04x\n",
51705 (u16)task->t.regs.es, (u16)task->t.regs.edi);
51706@@ -814,13 +837,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
51707 par->ypan = ypan;
51708
51709 if (par->pmi_setpal || par->ypan) {
51710+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
51711 if (__supported_pte_mask & _PAGE_NX) {
51712 par->pmi_setpal = par->ypan = 0;
51713 printk(KERN_WARNING "uvesafb: NX protection is active, "
51714 "better not use the PMI.\n");
51715- } else {
51716+ } else
51717+#endif
51718 uvesafb_vbe_getpmi(task, par);
51719- }
51720 }
51721 #else
51722 /* The protected mode interface is not available on non-x86. */
51723@@ -1454,8 +1478,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
51724 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
51725
51726 /* Disable blanking if the user requested so. */
51727- if (!blank)
51728- info->fbops->fb_blank = NULL;
51729+ if (!blank) {
51730+ pax_open_kernel();
51731+ *(void **)&info->fbops->fb_blank = NULL;
51732+ pax_close_kernel();
51733+ }
51734
51735 /*
51736 * Find out how much IO memory is required for the mode with
51737@@ -1531,8 +1558,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
51738 info->flags = FBINFO_FLAG_DEFAULT |
51739 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
51740
51741- if (!par->ypan)
51742- info->fbops->fb_pan_display = NULL;
51743+ if (!par->ypan) {
51744+ pax_open_kernel();
51745+ *(void **)&info->fbops->fb_pan_display = NULL;
51746+ pax_close_kernel();
51747+ }
51748 }
51749
51750 static void uvesafb_init_mtrr(struct fb_info *info)
51751@@ -1796,6 +1826,11 @@ out:
51752 if (par->vbe_modes)
51753 kfree(par->vbe_modes);
51754
51755+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51756+ if (par->pmi_code)
51757+ module_free_exec(NULL, par->pmi_code);
51758+#endif
51759+
51760 framebuffer_release(info);
51761 return err;
51762 }
51763@@ -1823,6 +1858,12 @@ static int uvesafb_remove(struct platform_device *dev)
51764 kfree(par->vbe_state_orig);
51765 if (par->vbe_state_saved)
51766 kfree(par->vbe_state_saved);
51767+
51768+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51769+ if (par->pmi_code)
51770+ module_free_exec(NULL, par->pmi_code);
51771+#endif
51772+
51773 }
51774
51775 framebuffer_release(info);
51776diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
51777index 501b340..d80aa17 100644
51778--- a/drivers/video/vesafb.c
51779+++ b/drivers/video/vesafb.c
51780@@ -9,6 +9,7 @@
51781 */
51782
51783 #include <linux/module.h>
51784+#include <linux/moduleloader.h>
51785 #include <linux/kernel.h>
51786 #include <linux/errno.h>
51787 #include <linux/string.h>
51788@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
51789 static int vram_total __initdata; /* Set total amount of memory */
51790 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
51791 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
51792-static void (*pmi_start)(void) __read_mostly;
51793-static void (*pmi_pal) (void) __read_mostly;
51794+static void (*pmi_start)(void) __read_only;
51795+static void (*pmi_pal) (void) __read_only;
51796 static int depth __read_mostly;
51797 static int vga_compat __read_mostly;
51798 /* --------------------------------------------------------------------- */
51799@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
51800 unsigned int size_vmode;
51801 unsigned int size_remap;
51802 unsigned int size_total;
51803+ void *pmi_code = NULL;
51804
51805 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
51806 return -ENODEV;
51807@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
51808 size_remap = size_total;
51809 vesafb_fix.smem_len = size_remap;
51810
51811-#ifndef __i386__
51812- screen_info.vesapm_seg = 0;
51813-#endif
51814-
51815 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
51816 printk(KERN_WARNING
51817 "vesafb: cannot reserve video memory at 0x%lx\n",
51818@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
51819 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
51820 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
51821
51822+#ifdef __i386__
51823+
51824+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51825+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
51826+ if (!pmi_code)
51827+#elif !defined(CONFIG_PAX_KERNEXEC)
51828+ if (0)
51829+#endif
51830+
51831+#endif
51832+ screen_info.vesapm_seg = 0;
51833+
51834 if (screen_info.vesapm_seg) {
51835- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
51836- screen_info.vesapm_seg,screen_info.vesapm_off);
51837+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
51838+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
51839 }
51840
51841 if (screen_info.vesapm_seg < 0xc000)
51842@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
51843
51844 if (ypan || pmi_setpal) {
51845 unsigned short *pmi_base;
51846+
51847 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
51848- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
51849- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
51850+
51851+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51852+ pax_open_kernel();
51853+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
51854+#else
51855+ pmi_code = pmi_base;
51856+#endif
51857+
51858+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
51859+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
51860+
51861+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51862+ pmi_start = ktva_ktla(pmi_start);
51863+ pmi_pal = ktva_ktla(pmi_pal);
51864+ pax_close_kernel();
51865+#endif
51866+
51867 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
51868 if (pmi_base[3]) {
51869 printk(KERN_INFO "vesafb: pmi: ports = ");
51870@@ -472,8 +498,11 @@ static int __init vesafb_probe(struct platform_device *dev)
51871 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
51872 (ypan ? FBINFO_HWACCEL_YPAN : 0);
51873
51874- if (!ypan)
51875- info->fbops->fb_pan_display = NULL;
51876+ if (!ypan) {
51877+ pax_open_kernel();
51878+ *(void **)&info->fbops->fb_pan_display = NULL;
51879+ pax_close_kernel();
51880+ }
51881
51882 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
51883 err = -ENOMEM;
51884@@ -488,6 +517,11 @@ static int __init vesafb_probe(struct platform_device *dev)
51885 info->node, info->fix.id);
51886 return 0;
51887 err:
51888+
51889+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51890+ module_free_exec(NULL, pmi_code);
51891+#endif
51892+
51893 if (info->screen_base)
51894 iounmap(info->screen_base);
51895 framebuffer_release(info);
51896diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
51897index 88714ae..16c2e11 100644
51898--- a/drivers/video/via/via_clock.h
51899+++ b/drivers/video/via/via_clock.h
51900@@ -56,7 +56,7 @@ struct via_clock {
51901
51902 void (*set_engine_pll_state)(u8 state);
51903 void (*set_engine_pll)(struct via_pll_config config);
51904-};
51905+} __no_const;
51906
51907
51908 static inline u32 get_pll_internal_frequency(u32 ref_freq,
51909diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
51910index fef20db..d28b1ab 100644
51911--- a/drivers/xen/xenfs/xenstored.c
51912+++ b/drivers/xen/xenfs/xenstored.c
51913@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
51914 static int xsd_kva_open(struct inode *inode, struct file *file)
51915 {
51916 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
51917+#ifdef CONFIG_GRKERNSEC_HIDESYM
51918+ NULL);
51919+#else
51920 xen_store_interface);
51921+#endif
51922+
51923 if (!file->private_data)
51924 return -ENOMEM;
51925 return 0;
51926diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
51927index 9ff073f..05cef23 100644
51928--- a/fs/9p/vfs_addr.c
51929+++ b/fs/9p/vfs_addr.c
51930@@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
51931
51932 retval = v9fs_file_write_internal(inode,
51933 v9inode->writeback_fid,
51934- (__force const char __user *)buffer,
51935+ (const char __force_user *)buffer,
51936 len, &offset, 0);
51937 if (retval > 0)
51938 retval = 0;
51939diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
51940index 25b018e..b941525 100644
51941--- a/fs/9p/vfs_inode.c
51942+++ b/fs/9p/vfs_inode.c
51943@@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
51944 void
51945 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
51946 {
51947- char *s = nd_get_link(nd);
51948+ const char *s = nd_get_link(nd);
51949
51950 p9_debug(P9_DEBUG_VFS, " %s %s\n",
51951 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
51952diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
51953index 370b24c..ff0be7b 100644
51954--- a/fs/Kconfig.binfmt
51955+++ b/fs/Kconfig.binfmt
51956@@ -103,7 +103,7 @@ config HAVE_AOUT
51957
51958 config BINFMT_AOUT
51959 tristate "Kernel support for a.out and ECOFF binaries"
51960- depends on HAVE_AOUT
51961+ depends on HAVE_AOUT && BROKEN
51962 ---help---
51963 A.out (Assembler.OUTput) is a set of formats for libraries and
51964 executables used in the earliest versions of UNIX. Linux used
51965diff --git a/fs/afs/inode.c b/fs/afs/inode.c
51966index 789bc25..fafaeea 100644
51967--- a/fs/afs/inode.c
51968+++ b/fs/afs/inode.c
51969@@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
51970 struct afs_vnode *vnode;
51971 struct super_block *sb;
51972 struct inode *inode;
51973- static atomic_t afs_autocell_ino;
51974+ static atomic_unchecked_t afs_autocell_ino;
51975
51976 _enter("{%x:%u},%*.*s,",
51977 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
51978@@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
51979 data.fid.unique = 0;
51980 data.fid.vnode = 0;
51981
51982- inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
51983+ inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
51984 afs_iget5_autocell_test, afs_iget5_set,
51985 &data);
51986 if (!inode) {
51987diff --git a/fs/aio.c b/fs/aio.c
51988index 9b5ca11..c530886 100644
51989--- a/fs/aio.c
51990+++ b/fs/aio.c
51991@@ -162,7 +162,7 @@ static int aio_setup_ring(struct kioctx *ctx)
51992 size += sizeof(struct io_event) * nr_events;
51993 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
51994
51995- if (nr_pages < 0)
51996+ if (nr_pages <= 0)
51997 return -EINVAL;
51998
51999 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
52000@@ -952,6 +952,7 @@ static ssize_t aio_rw_vect_retry(struct kiocb *iocb, int rw, aio_rw_op *rw_op)
52001 static ssize_t aio_setup_vectored_rw(int rw, struct kiocb *kiocb, bool compat)
52002 {
52003 ssize_t ret;
52004+ struct iovec iovstack;
52005
52006 kiocb->ki_nr_segs = kiocb->ki_nbytes;
52007
52008@@ -959,17 +960,22 @@ static ssize_t aio_setup_vectored_rw(int rw, struct kiocb *kiocb, bool compat)
52009 if (compat)
52010 ret = compat_rw_copy_check_uvector(rw,
52011 (struct compat_iovec __user *)kiocb->ki_buf,
52012- kiocb->ki_nr_segs, 1, &kiocb->ki_inline_vec,
52013+ kiocb->ki_nr_segs, 1, &iovstack,
52014 &kiocb->ki_iovec);
52015 else
52016 #endif
52017 ret = rw_copy_check_uvector(rw,
52018 (struct iovec __user *)kiocb->ki_buf,
52019- kiocb->ki_nr_segs, 1, &kiocb->ki_inline_vec,
52020+ kiocb->ki_nr_segs, 1, &iovstack,
52021 &kiocb->ki_iovec);
52022 if (ret < 0)
52023 return ret;
52024
52025+ if (kiocb->ki_iovec == &iovstack) {
52026+ kiocb->ki_inline_vec = iovstack;
52027+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
52028+ }
52029+
52030 /* ki_nbytes now reflect bytes instead of segs */
52031 kiocb->ki_nbytes = ret;
52032 return 0;
52033diff --git a/fs/attr.c b/fs/attr.c
52034index 1449adb..a2038c2 100644
52035--- a/fs/attr.c
52036+++ b/fs/attr.c
52037@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
52038 unsigned long limit;
52039
52040 limit = rlimit(RLIMIT_FSIZE);
52041+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
52042 if (limit != RLIM_INFINITY && offset > limit)
52043 goto out_sig;
52044 if (offset > inode->i_sb->s_maxbytes)
52045diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
52046index 3db70da..7aeec5b 100644
52047--- a/fs/autofs4/waitq.c
52048+++ b/fs/autofs4/waitq.c
52049@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
52050 {
52051 unsigned long sigpipe, flags;
52052 mm_segment_t fs;
52053- const char *data = (const char *)addr;
52054+ const char __user *data = (const char __force_user *)addr;
52055 ssize_t wr = 0;
52056
52057 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
52058@@ -346,6 +346,10 @@ static int validate_request(struct autofs_wait_queue **wait,
52059 return 1;
52060 }
52061
52062+#ifdef CONFIG_GRKERNSEC_HIDESYM
52063+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
52064+#endif
52065+
52066 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
52067 enum autofs_notify notify)
52068 {
52069@@ -379,7 +383,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
52070
52071 /* If this is a direct mount request create a dummy name */
52072 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
52073+#ifdef CONFIG_GRKERNSEC_HIDESYM
52074+ /* this name does get written to userland via autofs4_write() */
52075+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
52076+#else
52077 qstr.len = sprintf(name, "%p", dentry);
52078+#endif
52079 else {
52080 qstr.len = autofs4_getpath(sbi, dentry, &name);
52081 if (!qstr.len) {
52082diff --git a/fs/befs/endian.h b/fs/befs/endian.h
52083index 2722387..c8dd2a7 100644
52084--- a/fs/befs/endian.h
52085+++ b/fs/befs/endian.h
52086@@ -11,7 +11,7 @@
52087
52088 #include <asm/byteorder.h>
52089
52090-static inline u64
52091+static inline u64 __intentional_overflow(-1)
52092 fs64_to_cpu(const struct super_block *sb, fs64 n)
52093 {
52094 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
52095@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
52096 return (__force fs64)cpu_to_be64(n);
52097 }
52098
52099-static inline u32
52100+static inline u32 __intentional_overflow(-1)
52101 fs32_to_cpu(const struct super_block *sb, fs32 n)
52102 {
52103 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
52104diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
52105index e9c75e2..1baece1 100644
52106--- a/fs/befs/linuxvfs.c
52107+++ b/fs/befs/linuxvfs.c
52108@@ -514,7 +514,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
52109 {
52110 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
52111 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
52112- char *link = nd_get_link(nd);
52113+ const char *link = nd_get_link(nd);
52114 if (!IS_ERR(link))
52115 kfree(link);
52116 }
52117diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
52118index 89dec7f..361b0d75 100644
52119--- a/fs/binfmt_aout.c
52120+++ b/fs/binfmt_aout.c
52121@@ -16,6 +16,7 @@
52122 #include <linux/string.h>
52123 #include <linux/fs.h>
52124 #include <linux/file.h>
52125+#include <linux/security.h>
52126 #include <linux/stat.h>
52127 #include <linux/fcntl.h>
52128 #include <linux/ptrace.h>
52129@@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
52130 #endif
52131 # define START_STACK(u) ((void __user *)u.start_stack)
52132
52133+ memset(&dump, 0, sizeof(dump));
52134+
52135 fs = get_fs();
52136 set_fs(KERNEL_DS);
52137 has_dumped = 1;
52138@@ -69,10 +72,12 @@ static int aout_core_dump(struct coredump_params *cprm)
52139
52140 /* If the size of the dump file exceeds the rlimit, then see what would happen
52141 if we wrote the stack, but not the data area. */
52142+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
52143 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
52144 dump.u_dsize = 0;
52145
52146 /* Make sure we have enough room to write the stack and data areas. */
52147+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
52148 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
52149 dump.u_ssize = 0;
52150
52151@@ -233,6 +238,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
52152 rlim = rlimit(RLIMIT_DATA);
52153 if (rlim >= RLIM_INFINITY)
52154 rlim = ~0;
52155+
52156+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
52157 if (ex.a_data + ex.a_bss > rlim)
52158 return -ENOMEM;
52159
52160@@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
52161
52162 install_exec_creds(bprm);
52163
52164+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52165+ current->mm->pax_flags = 0UL;
52166+#endif
52167+
52168+#ifdef CONFIG_PAX_PAGEEXEC
52169+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
52170+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
52171+
52172+#ifdef CONFIG_PAX_EMUTRAMP
52173+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
52174+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
52175+#endif
52176+
52177+#ifdef CONFIG_PAX_MPROTECT
52178+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
52179+ current->mm->pax_flags |= MF_PAX_MPROTECT;
52180+#endif
52181+
52182+ }
52183+#endif
52184+
52185 if (N_MAGIC(ex) == OMAGIC) {
52186 unsigned long text_addr, map_size;
52187 loff_t pos;
52188@@ -322,7 +350,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
52189 }
52190
52191 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
52192- PROT_READ | PROT_WRITE | PROT_EXEC,
52193+ PROT_READ | PROT_WRITE,
52194 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
52195 fd_offset + ex.a_text);
52196 if (error != N_DATADDR(ex)) {
52197diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
52198index 4c94a79..f428019 100644
52199--- a/fs/binfmt_elf.c
52200+++ b/fs/binfmt_elf.c
52201@@ -34,6 +34,7 @@
52202 #include <linux/utsname.h>
52203 #include <linux/coredump.h>
52204 #include <linux/sched.h>
52205+#include <linux/xattr.h>
52206 #include <asm/uaccess.h>
52207 #include <asm/param.h>
52208 #include <asm/page.h>
52209@@ -60,6 +61,14 @@ static int elf_core_dump(struct coredump_params *cprm);
52210 #define elf_core_dump NULL
52211 #endif
52212
52213+#ifdef CONFIG_PAX_MPROTECT
52214+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
52215+#endif
52216+
52217+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
52218+static void elf_handle_mmap(struct file *file);
52219+#endif
52220+
52221 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
52222 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
52223 #else
52224@@ -79,6 +88,15 @@ static struct linux_binfmt elf_format = {
52225 .load_binary = load_elf_binary,
52226 .load_shlib = load_elf_library,
52227 .core_dump = elf_core_dump,
52228+
52229+#ifdef CONFIG_PAX_MPROTECT
52230+ .handle_mprotect= elf_handle_mprotect,
52231+#endif
52232+
52233+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
52234+ .handle_mmap = elf_handle_mmap,
52235+#endif
52236+
52237 .min_coredump = ELF_EXEC_PAGESIZE,
52238 };
52239
52240@@ -86,6 +104,8 @@ static struct linux_binfmt elf_format = {
52241
52242 static int set_brk(unsigned long start, unsigned long end)
52243 {
52244+ unsigned long e = end;
52245+
52246 start = ELF_PAGEALIGN(start);
52247 end = ELF_PAGEALIGN(end);
52248 if (end > start) {
52249@@ -94,7 +114,7 @@ static int set_brk(unsigned long start, unsigned long end)
52250 if (BAD_ADDR(addr))
52251 return addr;
52252 }
52253- current->mm->start_brk = current->mm->brk = end;
52254+ current->mm->start_brk = current->mm->brk = e;
52255 return 0;
52256 }
52257
52258@@ -155,12 +175,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
52259 elf_addr_t __user *u_rand_bytes;
52260 const char *k_platform = ELF_PLATFORM;
52261 const char *k_base_platform = ELF_BASE_PLATFORM;
52262- unsigned char k_rand_bytes[16];
52263+ u32 k_rand_bytes[4];
52264 int items;
52265 elf_addr_t *elf_info;
52266 int ei_index = 0;
52267 const struct cred *cred = current_cred();
52268 struct vm_area_struct *vma;
52269+ unsigned long saved_auxv[AT_VECTOR_SIZE];
52270
52271 /*
52272 * In some cases (e.g. Hyper-Threading), we want to avoid L1
52273@@ -202,8 +223,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
52274 * Generate 16 random bytes for userspace PRNG seeding.
52275 */
52276 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
52277- u_rand_bytes = (elf_addr_t __user *)
52278- STACK_ALLOC(p, sizeof(k_rand_bytes));
52279+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
52280+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
52281+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
52282+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
52283+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
52284+ u_rand_bytes = (elf_addr_t __user *) p;
52285 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
52286 return -EFAULT;
52287
52288@@ -318,9 +343,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
52289 return -EFAULT;
52290 current->mm->env_end = p;
52291
52292+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
52293+
52294 /* Put the elf_info on the stack in the right place. */
52295 sp = (elf_addr_t __user *)envp + 1;
52296- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
52297+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
52298 return -EFAULT;
52299 return 0;
52300 }
52301@@ -388,15 +415,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
52302 an ELF header */
52303
52304 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52305- struct file *interpreter, unsigned long *interp_map_addr,
52306- unsigned long no_base)
52307+ struct file *interpreter, unsigned long no_base)
52308 {
52309 struct elf_phdr *elf_phdata;
52310 struct elf_phdr *eppnt;
52311- unsigned long load_addr = 0;
52312+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
52313 int load_addr_set = 0;
52314 unsigned long last_bss = 0, elf_bss = 0;
52315- unsigned long error = ~0UL;
52316+ unsigned long error = -EINVAL;
52317 unsigned long total_size;
52318 int retval, i, size;
52319
52320@@ -442,6 +468,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52321 goto out_close;
52322 }
52323
52324+#ifdef CONFIG_PAX_SEGMEXEC
52325+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
52326+ pax_task_size = SEGMEXEC_TASK_SIZE;
52327+#endif
52328+
52329 eppnt = elf_phdata;
52330 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
52331 if (eppnt->p_type == PT_LOAD) {
52332@@ -465,8 +496,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52333 map_addr = elf_map(interpreter, load_addr + vaddr,
52334 eppnt, elf_prot, elf_type, total_size);
52335 total_size = 0;
52336- if (!*interp_map_addr)
52337- *interp_map_addr = map_addr;
52338 error = map_addr;
52339 if (BAD_ADDR(map_addr))
52340 goto out_close;
52341@@ -485,8 +514,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52342 k = load_addr + eppnt->p_vaddr;
52343 if (BAD_ADDR(k) ||
52344 eppnt->p_filesz > eppnt->p_memsz ||
52345- eppnt->p_memsz > TASK_SIZE ||
52346- TASK_SIZE - eppnt->p_memsz < k) {
52347+ eppnt->p_memsz > pax_task_size ||
52348+ pax_task_size - eppnt->p_memsz < k) {
52349 error = -ENOMEM;
52350 goto out_close;
52351 }
52352@@ -525,9 +554,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52353 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
52354
52355 /* Map the last of the bss segment */
52356- error = vm_brk(elf_bss, last_bss - elf_bss);
52357- if (BAD_ADDR(error))
52358- goto out_close;
52359+ if (last_bss > elf_bss) {
52360+ error = vm_brk(elf_bss, last_bss - elf_bss);
52361+ if (BAD_ADDR(error))
52362+ goto out_close;
52363+ }
52364 }
52365
52366 error = load_addr;
52367@@ -538,6 +569,315 @@ out:
52368 return error;
52369 }
52370
52371+#ifdef CONFIG_PAX_PT_PAX_FLAGS
52372+#ifdef CONFIG_PAX_SOFTMODE
52373+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
52374+{
52375+ unsigned long pax_flags = 0UL;
52376+
52377+#ifdef CONFIG_PAX_PAGEEXEC
52378+ if (elf_phdata->p_flags & PF_PAGEEXEC)
52379+ pax_flags |= MF_PAX_PAGEEXEC;
52380+#endif
52381+
52382+#ifdef CONFIG_PAX_SEGMEXEC
52383+ if (elf_phdata->p_flags & PF_SEGMEXEC)
52384+ pax_flags |= MF_PAX_SEGMEXEC;
52385+#endif
52386+
52387+#ifdef CONFIG_PAX_EMUTRAMP
52388+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
52389+ pax_flags |= MF_PAX_EMUTRAMP;
52390+#endif
52391+
52392+#ifdef CONFIG_PAX_MPROTECT
52393+ if (elf_phdata->p_flags & PF_MPROTECT)
52394+ pax_flags |= MF_PAX_MPROTECT;
52395+#endif
52396+
52397+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
52398+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
52399+ pax_flags |= MF_PAX_RANDMMAP;
52400+#endif
52401+
52402+ return pax_flags;
52403+}
52404+#endif
52405+
52406+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
52407+{
52408+ unsigned long pax_flags = 0UL;
52409+
52410+#ifdef CONFIG_PAX_PAGEEXEC
52411+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
52412+ pax_flags |= MF_PAX_PAGEEXEC;
52413+#endif
52414+
52415+#ifdef CONFIG_PAX_SEGMEXEC
52416+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
52417+ pax_flags |= MF_PAX_SEGMEXEC;
52418+#endif
52419+
52420+#ifdef CONFIG_PAX_EMUTRAMP
52421+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
52422+ pax_flags |= MF_PAX_EMUTRAMP;
52423+#endif
52424+
52425+#ifdef CONFIG_PAX_MPROTECT
52426+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
52427+ pax_flags |= MF_PAX_MPROTECT;
52428+#endif
52429+
52430+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
52431+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
52432+ pax_flags |= MF_PAX_RANDMMAP;
52433+#endif
52434+
52435+ return pax_flags;
52436+}
52437+#endif
52438+
52439+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
52440+#ifdef CONFIG_PAX_SOFTMODE
52441+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
52442+{
52443+ unsigned long pax_flags = 0UL;
52444+
52445+#ifdef CONFIG_PAX_PAGEEXEC
52446+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
52447+ pax_flags |= MF_PAX_PAGEEXEC;
52448+#endif
52449+
52450+#ifdef CONFIG_PAX_SEGMEXEC
52451+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
52452+ pax_flags |= MF_PAX_SEGMEXEC;
52453+#endif
52454+
52455+#ifdef CONFIG_PAX_EMUTRAMP
52456+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
52457+ pax_flags |= MF_PAX_EMUTRAMP;
52458+#endif
52459+
52460+#ifdef CONFIG_PAX_MPROTECT
52461+ if (pax_flags_softmode & MF_PAX_MPROTECT)
52462+ pax_flags |= MF_PAX_MPROTECT;
52463+#endif
52464+
52465+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
52466+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
52467+ pax_flags |= MF_PAX_RANDMMAP;
52468+#endif
52469+
52470+ return pax_flags;
52471+}
52472+#endif
52473+
52474+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
52475+{
52476+ unsigned long pax_flags = 0UL;
52477+
52478+#ifdef CONFIG_PAX_PAGEEXEC
52479+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
52480+ pax_flags |= MF_PAX_PAGEEXEC;
52481+#endif
52482+
52483+#ifdef CONFIG_PAX_SEGMEXEC
52484+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
52485+ pax_flags |= MF_PAX_SEGMEXEC;
52486+#endif
52487+
52488+#ifdef CONFIG_PAX_EMUTRAMP
52489+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
52490+ pax_flags |= MF_PAX_EMUTRAMP;
52491+#endif
52492+
52493+#ifdef CONFIG_PAX_MPROTECT
52494+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
52495+ pax_flags |= MF_PAX_MPROTECT;
52496+#endif
52497+
52498+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
52499+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
52500+ pax_flags |= MF_PAX_RANDMMAP;
52501+#endif
52502+
52503+ return pax_flags;
52504+}
52505+#endif
52506+
52507+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52508+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
52509+{
52510+ unsigned long pax_flags = 0UL;
52511+
52512+#ifdef CONFIG_PAX_EI_PAX
52513+
52514+#ifdef CONFIG_PAX_PAGEEXEC
52515+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
52516+ pax_flags |= MF_PAX_PAGEEXEC;
52517+#endif
52518+
52519+#ifdef CONFIG_PAX_SEGMEXEC
52520+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
52521+ pax_flags |= MF_PAX_SEGMEXEC;
52522+#endif
52523+
52524+#ifdef CONFIG_PAX_EMUTRAMP
52525+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
52526+ pax_flags |= MF_PAX_EMUTRAMP;
52527+#endif
52528+
52529+#ifdef CONFIG_PAX_MPROTECT
52530+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
52531+ pax_flags |= MF_PAX_MPROTECT;
52532+#endif
52533+
52534+#ifdef CONFIG_PAX_ASLR
52535+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
52536+ pax_flags |= MF_PAX_RANDMMAP;
52537+#endif
52538+
52539+#else
52540+
52541+#ifdef CONFIG_PAX_PAGEEXEC
52542+ pax_flags |= MF_PAX_PAGEEXEC;
52543+#endif
52544+
52545+#ifdef CONFIG_PAX_SEGMEXEC
52546+ pax_flags |= MF_PAX_SEGMEXEC;
52547+#endif
52548+
52549+#ifdef CONFIG_PAX_MPROTECT
52550+ pax_flags |= MF_PAX_MPROTECT;
52551+#endif
52552+
52553+#ifdef CONFIG_PAX_RANDMMAP
52554+ if (randomize_va_space)
52555+ pax_flags |= MF_PAX_RANDMMAP;
52556+#endif
52557+
52558+#endif
52559+
52560+ return pax_flags;
52561+}
52562+
52563+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
52564+{
52565+
52566+#ifdef CONFIG_PAX_PT_PAX_FLAGS
52567+ unsigned long i;
52568+
52569+ for (i = 0UL; i < elf_ex->e_phnum; i++)
52570+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
52571+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
52572+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
52573+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
52574+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
52575+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
52576+ return ~0UL;
52577+
52578+#ifdef CONFIG_PAX_SOFTMODE
52579+ if (pax_softmode)
52580+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
52581+ else
52582+#endif
52583+
52584+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
52585+ break;
52586+ }
52587+#endif
52588+
52589+ return ~0UL;
52590+}
52591+
52592+static unsigned long pax_parse_xattr_pax(struct file * const file)
52593+{
52594+
52595+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
52596+ ssize_t xattr_size, i;
52597+ unsigned char xattr_value[sizeof("pemrs") - 1];
52598+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
52599+
52600+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
52601+ if (xattr_size <= 0 || xattr_size > sizeof xattr_value)
52602+ return ~0UL;
52603+
52604+ for (i = 0; i < xattr_size; i++)
52605+ switch (xattr_value[i]) {
52606+ default:
52607+ return ~0UL;
52608+
52609+#define parse_flag(option1, option2, flag) \
52610+ case option1: \
52611+ if (pax_flags_hardmode & MF_PAX_##flag) \
52612+ return ~0UL; \
52613+ pax_flags_hardmode |= MF_PAX_##flag; \
52614+ break; \
52615+ case option2: \
52616+ if (pax_flags_softmode & MF_PAX_##flag) \
52617+ return ~0UL; \
52618+ pax_flags_softmode |= MF_PAX_##flag; \
52619+ break;
52620+
52621+ parse_flag('p', 'P', PAGEEXEC);
52622+ parse_flag('e', 'E', EMUTRAMP);
52623+ parse_flag('m', 'M', MPROTECT);
52624+ parse_flag('r', 'R', RANDMMAP);
52625+ parse_flag('s', 'S', SEGMEXEC);
52626+
52627+#undef parse_flag
52628+ }
52629+
52630+ if (pax_flags_hardmode & pax_flags_softmode)
52631+ return ~0UL;
52632+
52633+#ifdef CONFIG_PAX_SOFTMODE
52634+ if (pax_softmode)
52635+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
52636+ else
52637+#endif
52638+
52639+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
52640+#else
52641+ return ~0UL;
52642+#endif
52643+
52644+}
52645+
52646+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
52647+{
52648+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
52649+
52650+ pax_flags = pax_parse_ei_pax(elf_ex);
52651+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
52652+ xattr_pax_flags = pax_parse_xattr_pax(file);
52653+
52654+ if (pt_pax_flags == ~0UL)
52655+ pt_pax_flags = xattr_pax_flags;
52656+ else if (xattr_pax_flags == ~0UL)
52657+ xattr_pax_flags = pt_pax_flags;
52658+ if (pt_pax_flags != xattr_pax_flags)
52659+ return -EINVAL;
52660+ if (pt_pax_flags != ~0UL)
52661+ pax_flags = pt_pax_flags;
52662+
52663+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
52664+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
52665+ if ((__supported_pte_mask & _PAGE_NX))
52666+ pax_flags &= ~MF_PAX_SEGMEXEC;
52667+ else
52668+ pax_flags &= ~MF_PAX_PAGEEXEC;
52669+ }
52670+#endif
52671+
52672+ if (0 > pax_check_flags(&pax_flags))
52673+ return -EINVAL;
52674+
52675+ current->mm->pax_flags = pax_flags;
52676+ return 0;
52677+}
52678+#endif
52679+
52680 /*
52681 * These are the functions used to load ELF style executables and shared
52682 * libraries. There is no binary dependent code anywhere else.
52683@@ -554,6 +894,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
52684 {
52685 unsigned int random_variable = 0;
52686
52687+#ifdef CONFIG_PAX_RANDUSTACK
52688+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
52689+ return stack_top - current->mm->delta_stack;
52690+#endif
52691+
52692 if ((current->flags & PF_RANDOMIZE) &&
52693 !(current->personality & ADDR_NO_RANDOMIZE)) {
52694 random_variable = get_random_int() & STACK_RND_MASK;
52695@@ -572,7 +917,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
52696 unsigned long load_addr = 0, load_bias = 0;
52697 int load_addr_set = 0;
52698 char * elf_interpreter = NULL;
52699- unsigned long error;
52700+ unsigned long error = 0;
52701 struct elf_phdr *elf_ppnt, *elf_phdata;
52702 unsigned long elf_bss, elf_brk;
52703 int retval, i;
52704@@ -582,12 +927,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
52705 unsigned long start_code, end_code, start_data, end_data;
52706 unsigned long reloc_func_desc __maybe_unused = 0;
52707 int executable_stack = EXSTACK_DEFAULT;
52708- unsigned long def_flags = 0;
52709 struct pt_regs *regs = current_pt_regs();
52710 struct {
52711 struct elfhdr elf_ex;
52712 struct elfhdr interp_elf_ex;
52713 } *loc;
52714+ unsigned long pax_task_size = TASK_SIZE;
52715
52716 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
52717 if (!loc) {
52718@@ -723,11 +1068,81 @@ static int load_elf_binary(struct linux_binprm *bprm)
52719 goto out_free_dentry;
52720
52721 /* OK, This is the point of no return */
52722- current->mm->def_flags = def_flags;
52723+
52724+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52725+ current->mm->pax_flags = 0UL;
52726+#endif
52727+
52728+#ifdef CONFIG_PAX_DLRESOLVE
52729+ current->mm->call_dl_resolve = 0UL;
52730+#endif
52731+
52732+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
52733+ current->mm->call_syscall = 0UL;
52734+#endif
52735+
52736+#ifdef CONFIG_PAX_ASLR
52737+ current->mm->delta_mmap = 0UL;
52738+ current->mm->delta_stack = 0UL;
52739+#endif
52740+
52741+ current->mm->def_flags = 0;
52742+
52743+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52744+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
52745+ send_sig(SIGKILL, current, 0);
52746+ goto out_free_dentry;
52747+ }
52748+#endif
52749+
52750+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
52751+ pax_set_initial_flags(bprm);
52752+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
52753+ if (pax_set_initial_flags_func)
52754+ (pax_set_initial_flags_func)(bprm);
52755+#endif
52756+
52757+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
52758+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
52759+ current->mm->context.user_cs_limit = PAGE_SIZE;
52760+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
52761+ }
52762+#endif
52763+
52764+#ifdef CONFIG_PAX_SEGMEXEC
52765+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
52766+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
52767+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
52768+ pax_task_size = SEGMEXEC_TASK_SIZE;
52769+ current->mm->def_flags |= VM_NOHUGEPAGE;
52770+ }
52771+#endif
52772+
52773+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
52774+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
52775+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
52776+ put_cpu();
52777+ }
52778+#endif
52779
52780 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
52781 may depend on the personality. */
52782 SET_PERSONALITY(loc->elf_ex);
52783+
52784+#ifdef CONFIG_PAX_ASLR
52785+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
52786+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
52787+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
52788+ }
52789+#endif
52790+
52791+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
52792+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
52793+ executable_stack = EXSTACK_DISABLE_X;
52794+ current->personality &= ~READ_IMPLIES_EXEC;
52795+ } else
52796+#endif
52797+
52798 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
52799 current->personality |= READ_IMPLIES_EXEC;
52800
52801@@ -817,6 +1232,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
52802 #else
52803 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
52804 #endif
52805+
52806+#ifdef CONFIG_PAX_RANDMMAP
52807+ /* PaX: randomize base address at the default exe base if requested */
52808+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
52809+#ifdef CONFIG_SPARC64
52810+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
52811+#else
52812+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
52813+#endif
52814+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
52815+ elf_flags |= MAP_FIXED;
52816+ }
52817+#endif
52818+
52819 }
52820
52821 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
52822@@ -849,9 +1278,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
52823 * allowed task size. Note that p_filesz must always be
52824 * <= p_memsz so it is only necessary to check p_memsz.
52825 */
52826- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
52827- elf_ppnt->p_memsz > TASK_SIZE ||
52828- TASK_SIZE - elf_ppnt->p_memsz < k) {
52829+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
52830+ elf_ppnt->p_memsz > pax_task_size ||
52831+ pax_task_size - elf_ppnt->p_memsz < k) {
52832 /* set_brk can never work. Avoid overflows. */
52833 send_sig(SIGKILL, current, 0);
52834 retval = -EINVAL;
52835@@ -890,17 +1319,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
52836 goto out_free_dentry;
52837 }
52838 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
52839- send_sig(SIGSEGV, current, 0);
52840- retval = -EFAULT; /* Nobody gets to see this, but.. */
52841- goto out_free_dentry;
52842+ /*
52843+ * This bss-zeroing can fail if the ELF
52844+ * file specifies odd protections. So
52845+ * we don't check the return value
52846+ */
52847 }
52848
52849+#ifdef CONFIG_PAX_RANDMMAP
52850+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
52851+ unsigned long start, size, flags;
52852+ vm_flags_t vm_flags;
52853+
52854+ start = ELF_PAGEALIGN(elf_brk);
52855+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
52856+ flags = MAP_FIXED | MAP_PRIVATE;
52857+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
52858+
52859+ down_write(&current->mm->mmap_sem);
52860+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
52861+ retval = -ENOMEM;
52862+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
52863+// if (current->personality & ADDR_NO_RANDOMIZE)
52864+// vm_flags |= VM_READ | VM_MAYREAD;
52865+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
52866+ retval = IS_ERR_VALUE(start) ? start : 0;
52867+ }
52868+ up_write(&current->mm->mmap_sem);
52869+ if (retval == 0)
52870+ retval = set_brk(start + size, start + size + PAGE_SIZE);
52871+ if (retval < 0) {
52872+ send_sig(SIGKILL, current, 0);
52873+ goto out_free_dentry;
52874+ }
52875+ }
52876+#endif
52877+
52878 if (elf_interpreter) {
52879- unsigned long interp_map_addr = 0;
52880-
52881 elf_entry = load_elf_interp(&loc->interp_elf_ex,
52882 interpreter,
52883- &interp_map_addr,
52884 load_bias);
52885 if (!IS_ERR((void *)elf_entry)) {
52886 /*
52887@@ -1122,7 +1579,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
52888 * Decide what to dump of a segment, part, all or none.
52889 */
52890 static unsigned long vma_dump_size(struct vm_area_struct *vma,
52891- unsigned long mm_flags)
52892+ unsigned long mm_flags, long signr)
52893 {
52894 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
52895
52896@@ -1160,7 +1617,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
52897 if (vma->vm_file == NULL)
52898 return 0;
52899
52900- if (FILTER(MAPPED_PRIVATE))
52901+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
52902 goto whole;
52903
52904 /*
52905@@ -1385,9 +1842,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
52906 {
52907 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
52908 int i = 0;
52909- do
52910+ do {
52911 i += 2;
52912- while (auxv[i - 2] != AT_NULL);
52913+ } while (auxv[i - 2] != AT_NULL);
52914 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
52915 }
52916
52917@@ -1396,7 +1853,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
52918 {
52919 mm_segment_t old_fs = get_fs();
52920 set_fs(KERNEL_DS);
52921- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
52922+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
52923 set_fs(old_fs);
52924 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
52925 }
52926@@ -2023,14 +2480,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
52927 }
52928
52929 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
52930- unsigned long mm_flags)
52931+ struct coredump_params *cprm)
52932 {
52933 struct vm_area_struct *vma;
52934 size_t size = 0;
52935
52936 for (vma = first_vma(current, gate_vma); vma != NULL;
52937 vma = next_vma(vma, gate_vma))
52938- size += vma_dump_size(vma, mm_flags);
52939+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
52940 return size;
52941 }
52942
52943@@ -2123,7 +2580,7 @@ static int elf_core_dump(struct coredump_params *cprm)
52944
52945 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
52946
52947- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
52948+ offset += elf_core_vma_data_size(gate_vma, cprm);
52949 offset += elf_core_extra_data_size();
52950 e_shoff = offset;
52951
52952@@ -2137,10 +2594,12 @@ static int elf_core_dump(struct coredump_params *cprm)
52953 offset = dataoff;
52954
52955 size += sizeof(*elf);
52956+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
52957 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
52958 goto end_coredump;
52959
52960 size += sizeof(*phdr4note);
52961+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
52962 if (size > cprm->limit
52963 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
52964 goto end_coredump;
52965@@ -2154,7 +2613,7 @@ static int elf_core_dump(struct coredump_params *cprm)
52966 phdr.p_offset = offset;
52967 phdr.p_vaddr = vma->vm_start;
52968 phdr.p_paddr = 0;
52969- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
52970+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
52971 phdr.p_memsz = vma->vm_end - vma->vm_start;
52972 offset += phdr.p_filesz;
52973 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
52974@@ -2165,6 +2624,7 @@ static int elf_core_dump(struct coredump_params *cprm)
52975 phdr.p_align = ELF_EXEC_PAGESIZE;
52976
52977 size += sizeof(phdr);
52978+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
52979 if (size > cprm->limit
52980 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
52981 goto end_coredump;
52982@@ -2189,7 +2649,7 @@ static int elf_core_dump(struct coredump_params *cprm)
52983 unsigned long addr;
52984 unsigned long end;
52985
52986- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
52987+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
52988
52989 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
52990 struct page *page;
52991@@ -2198,6 +2658,7 @@ static int elf_core_dump(struct coredump_params *cprm)
52992 page = get_dump_page(addr);
52993 if (page) {
52994 void *kaddr = kmap(page);
52995+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
52996 stop = ((size += PAGE_SIZE) > cprm->limit) ||
52997 !dump_write(cprm->file, kaddr,
52998 PAGE_SIZE);
52999@@ -2215,6 +2676,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53000
53001 if (e_phnum == PN_XNUM) {
53002 size += sizeof(*shdr4extnum);
53003+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
53004 if (size > cprm->limit
53005 || !dump_write(cprm->file, shdr4extnum,
53006 sizeof(*shdr4extnum)))
53007@@ -2235,6 +2697,167 @@ out:
53008
53009 #endif /* CONFIG_ELF_CORE */
53010
53011+#ifdef CONFIG_PAX_MPROTECT
53012+/* PaX: non-PIC ELF libraries need relocations on their executable segments
53013+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
53014+ * we'll remove VM_MAYWRITE for good on RELRO segments.
53015+ *
53016+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
53017+ * basis because we want to allow the common case and not the special ones.
53018+ */
53019+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
53020+{
53021+ struct elfhdr elf_h;
53022+ struct elf_phdr elf_p;
53023+ unsigned long i;
53024+ unsigned long oldflags;
53025+ bool is_textrel_rw, is_textrel_rx, is_relro;
53026+
53027+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
53028+ return;
53029+
53030+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
53031+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
53032+
53033+#ifdef CONFIG_PAX_ELFRELOCS
53034+ /* possible TEXTREL */
53035+ is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
53036+ is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
53037+#else
53038+ is_textrel_rw = false;
53039+ is_textrel_rx = false;
53040+#endif
53041+
53042+ /* possible RELRO */
53043+ is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
53044+
53045+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
53046+ return;
53047+
53048+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
53049+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
53050+
53051+#ifdef CONFIG_PAX_ETEXECRELOCS
53052+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
53053+#else
53054+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
53055+#endif
53056+
53057+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
53058+ !elf_check_arch(&elf_h) ||
53059+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
53060+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
53061+ return;
53062+
53063+ for (i = 0UL; i < elf_h.e_phnum; i++) {
53064+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
53065+ return;
53066+ switch (elf_p.p_type) {
53067+ case PT_DYNAMIC:
53068+ if (!is_textrel_rw && !is_textrel_rx)
53069+ continue;
53070+ i = 0UL;
53071+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
53072+ elf_dyn dyn;
53073+
53074+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
53075+ break;
53076+ if (dyn.d_tag == DT_NULL)
53077+ break;
53078+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
53079+ gr_log_textrel(vma);
53080+ if (is_textrel_rw)
53081+ vma->vm_flags |= VM_MAYWRITE;
53082+ else
53083+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
53084+ vma->vm_flags &= ~VM_MAYWRITE;
53085+ break;
53086+ }
53087+ i++;
53088+ }
53089+ is_textrel_rw = false;
53090+ is_textrel_rx = false;
53091+ continue;
53092+
53093+ case PT_GNU_RELRO:
53094+ if (!is_relro)
53095+ continue;
53096+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
53097+ vma->vm_flags &= ~VM_MAYWRITE;
53098+ is_relro = false;
53099+ continue;
53100+
53101+#ifdef CONFIG_PAX_PT_PAX_FLAGS
53102+ case PT_PAX_FLAGS: {
53103+ const char *msg_mprotect = "", *msg_emutramp = "";
53104+ char *buffer_lib, *buffer_exe;
53105+
53106+ if (elf_p.p_flags & PF_NOMPROTECT)
53107+ msg_mprotect = "MPROTECT disabled";
53108+
53109+#ifdef CONFIG_PAX_EMUTRAMP
53110+ if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
53111+ msg_emutramp = "EMUTRAMP enabled";
53112+#endif
53113+
53114+ if (!msg_mprotect[0] && !msg_emutramp[0])
53115+ continue;
53116+
53117+ if (!printk_ratelimit())
53118+ continue;
53119+
53120+ buffer_lib = (char *)__get_free_page(GFP_KERNEL);
53121+ buffer_exe = (char *)__get_free_page(GFP_KERNEL);
53122+ if (buffer_lib && buffer_exe) {
53123+ char *path_lib, *path_exe;
53124+
53125+ path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
53126+ path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
53127+
53128+ pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
53129+ (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
53130+
53131+ }
53132+ free_page((unsigned long)buffer_exe);
53133+ free_page((unsigned long)buffer_lib);
53134+ continue;
53135+ }
53136+#endif
53137+
53138+ }
53139+ }
53140+}
53141+#endif
53142+
53143+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
53144+
53145+extern int grsec_enable_log_rwxmaps;
53146+
53147+static void elf_handle_mmap(struct file *file)
53148+{
53149+ struct elfhdr elf_h;
53150+ struct elf_phdr elf_p;
53151+ unsigned long i;
53152+
53153+ if (!grsec_enable_log_rwxmaps)
53154+ return;
53155+
53156+ if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
53157+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
53158+ (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
53159+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
53160+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
53161+ return;
53162+
53163+ for (i = 0UL; i < elf_h.e_phnum; i++) {
53164+ if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
53165+ return;
53166+ if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
53167+ gr_log_ptgnustack(file);
53168+ }
53169+}
53170+#endif
53171+
53172 static int __init init_elf_binfmt(void)
53173 {
53174 register_binfmt(&elf_format);
53175diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
53176index d50bbe5..af3b649 100644
53177--- a/fs/binfmt_flat.c
53178+++ b/fs/binfmt_flat.c
53179@@ -566,7 +566,9 @@ static int load_flat_file(struct linux_binprm * bprm,
53180 realdatastart = (unsigned long) -ENOMEM;
53181 printk("Unable to allocate RAM for process data, errno %d\n",
53182 (int)-realdatastart);
53183+ down_write(&current->mm->mmap_sem);
53184 vm_munmap(textpos, text_len);
53185+ up_write(&current->mm->mmap_sem);
53186 ret = realdatastart;
53187 goto err;
53188 }
53189@@ -590,8 +592,10 @@ static int load_flat_file(struct linux_binprm * bprm,
53190 }
53191 if (IS_ERR_VALUE(result)) {
53192 printk("Unable to read data+bss, errno %d\n", (int)-result);
53193+ down_write(&current->mm->mmap_sem);
53194 vm_munmap(textpos, text_len);
53195 vm_munmap(realdatastart, len);
53196+ up_write(&current->mm->mmap_sem);
53197 ret = result;
53198 goto err;
53199 }
53200@@ -653,8 +657,10 @@ static int load_flat_file(struct linux_binprm * bprm,
53201 }
53202 if (IS_ERR_VALUE(result)) {
53203 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
53204+ down_write(&current->mm->mmap_sem);
53205 vm_munmap(textpos, text_len + data_len + extra +
53206 MAX_SHARED_LIBS * sizeof(unsigned long));
53207+ up_write(&current->mm->mmap_sem);
53208 ret = result;
53209 goto err;
53210 }
53211diff --git a/fs/bio.c b/fs/bio.c
53212index 5e7507d..418c639 100644
53213--- a/fs/bio.c
53214+++ b/fs/bio.c
53215@@ -1106,7 +1106,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
53216 /*
53217 * Overflow, abort
53218 */
53219- if (end < start)
53220+ if (end < start || end - start > INT_MAX - nr_pages)
53221 return ERR_PTR(-EINVAL);
53222
53223 nr_pages += end - start;
53224@@ -1240,7 +1240,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
53225 /*
53226 * Overflow, abort
53227 */
53228- if (end < start)
53229+ if (end < start || end - start > INT_MAX - nr_pages)
53230 return ERR_PTR(-EINVAL);
53231
53232 nr_pages += end - start;
53233@@ -1502,7 +1502,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
53234 const int read = bio_data_dir(bio) == READ;
53235 struct bio_map_data *bmd = bio->bi_private;
53236 int i;
53237- char *p = bmd->sgvecs[0].iov_base;
53238+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
53239
53240 bio_for_each_segment_all(bvec, bio, i) {
53241 char *addr = page_address(bvec->bv_page);
53242diff --git a/fs/block_dev.c b/fs/block_dev.c
53243index c7bda5c..2121e94 100644
53244--- a/fs/block_dev.c
53245+++ b/fs/block_dev.c
53246@@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
53247 else if (bdev->bd_contains == bdev)
53248 return true; /* is a whole device which isn't held */
53249
53250- else if (whole->bd_holder == bd_may_claim)
53251+ else if (whole->bd_holder == (void *)bd_may_claim)
53252 return true; /* is a partition of a device that is being partitioned */
53253 else if (whole->bd_holder != NULL)
53254 return false; /* is a partition of a held device */
53255diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
53256index ed50460..fe84385 100644
53257--- a/fs/btrfs/ctree.c
53258+++ b/fs/btrfs/ctree.c
53259@@ -1076,9 +1076,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
53260 free_extent_buffer(buf);
53261 add_root_to_dirty_list(root);
53262 } else {
53263- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
53264- parent_start = parent->start;
53265- else
53266+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
53267+ if (parent)
53268+ parent_start = parent->start;
53269+ else
53270+ parent_start = 0;
53271+ } else
53272 parent_start = 0;
53273
53274 WARN_ON(trans->transid != btrfs_header_generation(parent));
53275diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
53276index 3755109..e3d457f 100644
53277--- a/fs/btrfs/delayed-inode.c
53278+++ b/fs/btrfs/delayed-inode.c
53279@@ -458,7 +458,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
53280
53281 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
53282 {
53283- int seq = atomic_inc_return(&delayed_root->items_seq);
53284+ int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
53285 if ((atomic_dec_return(&delayed_root->items) <
53286 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
53287 waitqueue_active(&delayed_root->wait))
53288@@ -1377,7 +1377,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
53289 static int refs_newer(struct btrfs_delayed_root *delayed_root,
53290 int seq, int count)
53291 {
53292- int val = atomic_read(&delayed_root->items_seq);
53293+ int val = atomic_read_unchecked(&delayed_root->items_seq);
53294
53295 if (val < seq || val >= seq + count)
53296 return 1;
53297@@ -1394,7 +1394,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
53298 if (atomic_read(&delayed_root->items) < BTRFS_DELAYED_BACKGROUND)
53299 return;
53300
53301- seq = atomic_read(&delayed_root->items_seq);
53302+ seq = atomic_read_unchecked(&delayed_root->items_seq);
53303
53304 if (atomic_read(&delayed_root->items) >= BTRFS_DELAYED_WRITEBACK) {
53305 int ret;
53306diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
53307index a4b38f9..f86a509 100644
53308--- a/fs/btrfs/delayed-inode.h
53309+++ b/fs/btrfs/delayed-inode.h
53310@@ -43,7 +43,7 @@ struct btrfs_delayed_root {
53311 */
53312 struct list_head prepare_list;
53313 atomic_t items; /* for delayed items */
53314- atomic_t items_seq; /* for delayed items */
53315+ atomic_unchecked_t items_seq; /* for delayed items */
53316 int nodes; /* for delayed nodes */
53317 wait_queue_head_t wait;
53318 };
53319@@ -87,7 +87,7 @@ static inline void btrfs_init_delayed_root(
53320 struct btrfs_delayed_root *delayed_root)
53321 {
53322 atomic_set(&delayed_root->items, 0);
53323- atomic_set(&delayed_root->items_seq, 0);
53324+ atomic_set_unchecked(&delayed_root->items_seq, 0);
53325 delayed_root->nodes = 0;
53326 spin_lock_init(&delayed_root->lock);
53327 init_waitqueue_head(&delayed_root->wait);
53328diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
53329index 9877a2a..7ebf9ab 100644
53330--- a/fs/btrfs/ioctl.c
53331+++ b/fs/btrfs/ioctl.c
53332@@ -3097,9 +3097,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
53333 for (i = 0; i < num_types; i++) {
53334 struct btrfs_space_info *tmp;
53335
53336+ /* Don't copy in more than we allocated */
53337 if (!slot_count)
53338 break;
53339
53340+ slot_count--;
53341+
53342 info = NULL;
53343 rcu_read_lock();
53344 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
53345@@ -3121,10 +3124,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
53346 memcpy(dest, &space, sizeof(space));
53347 dest++;
53348 space_args.total_spaces++;
53349- slot_count--;
53350 }
53351- if (!slot_count)
53352- break;
53353 }
53354 up_read(&info->groups_sem);
53355 }
53356diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
53357index 8eb6191..eda91e2 100644
53358--- a/fs/btrfs/super.c
53359+++ b/fs/btrfs/super.c
53360@@ -264,7 +264,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
53361 function, line, errstr);
53362 return;
53363 }
53364- ACCESS_ONCE(trans->transaction->aborted) = errno;
53365+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
53366 /* Wake up anybody who may be waiting on this transaction */
53367 wake_up(&root->fs_info->transaction_wait);
53368 wake_up(&root->fs_info->transaction_blocked_wait);
53369diff --git a/fs/buffer.c b/fs/buffer.c
53370index 4d74335..7bd000a 100644
53371--- a/fs/buffer.c
53372+++ b/fs/buffer.c
53373@@ -1005,9 +1005,19 @@ grow_dev_page(struct block_device *bdev, sector_t block,
53374 struct buffer_head *bh;
53375 sector_t end_block;
53376 int ret = 0; /* Will call free_more_memory() */
53377+ gfp_t gfp_mask;
53378
53379- page = find_or_create_page(inode->i_mapping, index,
53380- (mapping_gfp_mask(inode->i_mapping) & ~__GFP_FS)|__GFP_MOVABLE);
53381+ gfp_mask = mapping_gfp_mask(inode->i_mapping) & ~__GFP_FS;
53382+ gfp_mask |= __GFP_MOVABLE;
53383+ /*
53384+ * XXX: __getblk_slow() can not really deal with failure and
53385+ * will endlessly loop on improvised global reclaim. Prefer
53386+ * looping in the allocator rather than here, at least that
53387+ * code knows what it's doing.
53388+ */
53389+ gfp_mask |= __GFP_NOFAIL;
53390+
53391+ page = find_or_create_page(inode->i_mapping, index, gfp_mask);
53392 if (!page)
53393 return ret;
53394
53395@@ -3416,7 +3426,7 @@ void __init buffer_init(void)
53396 bh_cachep = kmem_cache_create("buffer_head",
53397 sizeof(struct buffer_head), 0,
53398 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
53399- SLAB_MEM_SPREAD),
53400+ SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
53401 NULL);
53402
53403 /*
53404diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
53405index 622f469..e8d2d55 100644
53406--- a/fs/cachefiles/bind.c
53407+++ b/fs/cachefiles/bind.c
53408@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
53409 args);
53410
53411 /* start by checking things over */
53412- ASSERT(cache->fstop_percent >= 0 &&
53413- cache->fstop_percent < cache->fcull_percent &&
53414+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
53415 cache->fcull_percent < cache->frun_percent &&
53416 cache->frun_percent < 100);
53417
53418- ASSERT(cache->bstop_percent >= 0 &&
53419- cache->bstop_percent < cache->bcull_percent &&
53420+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
53421 cache->bcull_percent < cache->brun_percent &&
53422 cache->brun_percent < 100);
53423
53424diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
53425index 0a1467b..6a53245 100644
53426--- a/fs/cachefiles/daemon.c
53427+++ b/fs/cachefiles/daemon.c
53428@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
53429 if (n > buflen)
53430 return -EMSGSIZE;
53431
53432- if (copy_to_user(_buffer, buffer, n) != 0)
53433+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
53434 return -EFAULT;
53435
53436 return n;
53437@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
53438 if (test_bit(CACHEFILES_DEAD, &cache->flags))
53439 return -EIO;
53440
53441- if (datalen < 0 || datalen > PAGE_SIZE - 1)
53442+ if (datalen > PAGE_SIZE - 1)
53443 return -EOPNOTSUPP;
53444
53445 /* drag the command string into the kernel so we can parse it */
53446@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
53447 if (args[0] != '%' || args[1] != '\0')
53448 return -EINVAL;
53449
53450- if (fstop < 0 || fstop >= cache->fcull_percent)
53451+ if (fstop >= cache->fcull_percent)
53452 return cachefiles_daemon_range_error(cache, args);
53453
53454 cache->fstop_percent = fstop;
53455@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
53456 if (args[0] != '%' || args[1] != '\0')
53457 return -EINVAL;
53458
53459- if (bstop < 0 || bstop >= cache->bcull_percent)
53460+ if (bstop >= cache->bcull_percent)
53461 return cachefiles_daemon_range_error(cache, args);
53462
53463 cache->bstop_percent = bstop;
53464diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
53465index 4938251..7e01445 100644
53466--- a/fs/cachefiles/internal.h
53467+++ b/fs/cachefiles/internal.h
53468@@ -59,7 +59,7 @@ struct cachefiles_cache {
53469 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
53470 struct rb_root active_nodes; /* active nodes (can't be culled) */
53471 rwlock_t active_lock; /* lock for active_nodes */
53472- atomic_t gravecounter; /* graveyard uniquifier */
53473+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
53474 unsigned frun_percent; /* when to stop culling (% files) */
53475 unsigned fcull_percent; /* when to start culling (% files) */
53476 unsigned fstop_percent; /* when to stop allocating (% files) */
53477@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
53478 * proc.c
53479 */
53480 #ifdef CONFIG_CACHEFILES_HISTOGRAM
53481-extern atomic_t cachefiles_lookup_histogram[HZ];
53482-extern atomic_t cachefiles_mkdir_histogram[HZ];
53483-extern atomic_t cachefiles_create_histogram[HZ];
53484+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
53485+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
53486+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
53487
53488 extern int __init cachefiles_proc_init(void);
53489 extern void cachefiles_proc_cleanup(void);
53490 static inline
53491-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
53492+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
53493 {
53494 unsigned long jif = jiffies - start_jif;
53495 if (jif >= HZ)
53496 jif = HZ - 1;
53497- atomic_inc(&histogram[jif]);
53498+ atomic_inc_unchecked(&histogram[jif]);
53499 }
53500
53501 #else
53502diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
53503index 25badd1..d70d918 100644
53504--- a/fs/cachefiles/namei.c
53505+++ b/fs/cachefiles/namei.c
53506@@ -317,7 +317,7 @@ try_again:
53507 /* first step is to make up a grave dentry in the graveyard */
53508 sprintf(nbuffer, "%08x%08x",
53509 (uint32_t) get_seconds(),
53510- (uint32_t) atomic_inc_return(&cache->gravecounter));
53511+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
53512
53513 /* do the multiway lock magic */
53514 trap = lock_rename(cache->graveyard, dir);
53515diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
53516index eccd339..4c1d995 100644
53517--- a/fs/cachefiles/proc.c
53518+++ b/fs/cachefiles/proc.c
53519@@ -14,9 +14,9 @@
53520 #include <linux/seq_file.h>
53521 #include "internal.h"
53522
53523-atomic_t cachefiles_lookup_histogram[HZ];
53524-atomic_t cachefiles_mkdir_histogram[HZ];
53525-atomic_t cachefiles_create_histogram[HZ];
53526+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
53527+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
53528+atomic_unchecked_t cachefiles_create_histogram[HZ];
53529
53530 /*
53531 * display the latency histogram
53532@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
53533 return 0;
53534 default:
53535 index = (unsigned long) v - 3;
53536- x = atomic_read(&cachefiles_lookup_histogram[index]);
53537- y = atomic_read(&cachefiles_mkdir_histogram[index]);
53538- z = atomic_read(&cachefiles_create_histogram[index]);
53539+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
53540+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
53541+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
53542 if (x == 0 && y == 0 && z == 0)
53543 return 0;
53544
53545diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
53546index ebaff36..7e3ea26 100644
53547--- a/fs/cachefiles/rdwr.c
53548+++ b/fs/cachefiles/rdwr.c
53549@@ -950,7 +950,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
53550 old_fs = get_fs();
53551 set_fs(KERNEL_DS);
53552 ret = file->f_op->write(
53553- file, (const void __user *) data, len, &pos);
53554+ file, (const void __force_user *) data, len, &pos);
53555 set_fs(old_fs);
53556 kunmap(page);
53557 file_end_write(file);
53558diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
53559index a40ceda..f43d17c 100644
53560--- a/fs/ceph/dir.c
53561+++ b/fs/ceph/dir.c
53562@@ -240,7 +240,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
53563 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
53564 struct ceph_mds_client *mdsc = fsc->mdsc;
53565 unsigned frag = fpos_frag(ctx->pos);
53566- int off = fpos_off(ctx->pos);
53567+ unsigned int off = fpos_off(ctx->pos);
53568 int err;
53569 u32 ftype;
53570 struct ceph_mds_reply_info_parsed *rinfo;
53571diff --git a/fs/ceph/super.c b/fs/ceph/super.c
53572index 6627b26..634ec4b 100644
53573--- a/fs/ceph/super.c
53574+++ b/fs/ceph/super.c
53575@@ -839,7 +839,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
53576 /*
53577 * construct our own bdi so we can control readahead, etc.
53578 */
53579-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
53580+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
53581
53582 static int ceph_register_bdi(struct super_block *sb,
53583 struct ceph_fs_client *fsc)
53584@@ -856,7 +856,7 @@ static int ceph_register_bdi(struct super_block *sb,
53585 default_backing_dev_info.ra_pages;
53586
53587 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
53588- atomic_long_inc_return(&bdi_seq));
53589+ atomic_long_inc_return_unchecked(&bdi_seq));
53590 if (!err)
53591 sb->s_bdi = &fsc->backing_dev_info;
53592 return err;
53593diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
53594index f3ac415..3d2420c 100644
53595--- a/fs/cifs/cifs_debug.c
53596+++ b/fs/cifs/cifs_debug.c
53597@@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
53598
53599 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
53600 #ifdef CONFIG_CIFS_STATS2
53601- atomic_set(&totBufAllocCount, 0);
53602- atomic_set(&totSmBufAllocCount, 0);
53603+ atomic_set_unchecked(&totBufAllocCount, 0);
53604+ atomic_set_unchecked(&totSmBufAllocCount, 0);
53605 #endif /* CONFIG_CIFS_STATS2 */
53606 spin_lock(&cifs_tcp_ses_lock);
53607 list_for_each(tmp1, &cifs_tcp_ses_list) {
53608@@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
53609 tcon = list_entry(tmp3,
53610 struct cifs_tcon,
53611 tcon_list);
53612- atomic_set(&tcon->num_smbs_sent, 0);
53613+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
53614 if (server->ops->clear_stats)
53615 server->ops->clear_stats(tcon);
53616 }
53617@@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
53618 smBufAllocCount.counter, cifs_min_small);
53619 #ifdef CONFIG_CIFS_STATS2
53620 seq_printf(m, "Total Large %d Small %d Allocations\n",
53621- atomic_read(&totBufAllocCount),
53622- atomic_read(&totSmBufAllocCount));
53623+ atomic_read_unchecked(&totBufAllocCount),
53624+ atomic_read_unchecked(&totSmBufAllocCount));
53625 #endif /* CONFIG_CIFS_STATS2 */
53626
53627 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
53628@@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
53629 if (tcon->need_reconnect)
53630 seq_puts(m, "\tDISCONNECTED ");
53631 seq_printf(m, "\nSMBs: %d",
53632- atomic_read(&tcon->num_smbs_sent));
53633+ atomic_read_unchecked(&tcon->num_smbs_sent));
53634 if (server->ops->print_stats)
53635 server->ops->print_stats(m, tcon);
53636 }
53637diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
53638index 85ea98d..1eee040 100644
53639--- a/fs/cifs/cifsfs.c
53640+++ b/fs/cifs/cifsfs.c
53641@@ -120,14 +120,16 @@ cifs_read_super(struct super_block *sb)
53642 {
53643 struct inode *inode;
53644 struct cifs_sb_info *cifs_sb;
53645+ struct cifs_tcon *tcon;
53646 int rc = 0;
53647
53648 cifs_sb = CIFS_SB(sb);
53649+ tcon = cifs_sb_master_tcon(cifs_sb);
53650
53651 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIXACL)
53652 sb->s_flags |= MS_POSIXACL;
53653
53654- if (cifs_sb_master_tcon(cifs_sb)->ses->capabilities & CAP_LARGE_FILES)
53655+ if (tcon->ses->capabilities & tcon->ses->server->vals->cap_large_files)
53656 sb->s_maxbytes = MAX_LFS_FILESIZE;
53657 else
53658 sb->s_maxbytes = MAX_NON_LFS;
53659@@ -147,7 +149,7 @@ cifs_read_super(struct super_block *sb)
53660 goto out_no_root;
53661 }
53662
53663- if (cifs_sb_master_tcon(cifs_sb)->nocase)
53664+ if (tcon->nocase)
53665 sb->s_d_op = &cifs_ci_dentry_ops;
53666 else
53667 sb->s_d_op = &cifs_dentry_ops;
53668@@ -1037,7 +1039,7 @@ cifs_init_request_bufs(void)
53669 */
53670 cifs_req_cachep = kmem_cache_create("cifs_request",
53671 CIFSMaxBufSize + max_hdr_size, 0,
53672- SLAB_HWCACHE_ALIGN, NULL);
53673+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
53674 if (cifs_req_cachep == NULL)
53675 return -ENOMEM;
53676
53677@@ -1064,7 +1066,7 @@ cifs_init_request_bufs(void)
53678 efficient to alloc 1 per page off the slab compared to 17K (5page)
53679 alloc of large cifs buffers even when page debugging is on */
53680 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
53681- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
53682+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
53683 NULL);
53684 if (cifs_sm_req_cachep == NULL) {
53685 mempool_destroy(cifs_req_poolp);
53686@@ -1149,8 +1151,8 @@ init_cifs(void)
53687 atomic_set(&bufAllocCount, 0);
53688 atomic_set(&smBufAllocCount, 0);
53689 #ifdef CONFIG_CIFS_STATS2
53690- atomic_set(&totBufAllocCount, 0);
53691- atomic_set(&totSmBufAllocCount, 0);
53692+ atomic_set_unchecked(&totBufAllocCount, 0);
53693+ atomic_set_unchecked(&totSmBufAllocCount, 0);
53694 #endif /* CONFIG_CIFS_STATS2 */
53695
53696 atomic_set(&midCount, 0);
53697diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
53698index 52ca861..47f309c 100644
53699--- a/fs/cifs/cifsglob.h
53700+++ b/fs/cifs/cifsglob.h
53701@@ -756,35 +756,35 @@ struct cifs_tcon {
53702 __u16 Flags; /* optional support bits */
53703 enum statusEnum tidStatus;
53704 #ifdef CONFIG_CIFS_STATS
53705- atomic_t num_smbs_sent;
53706+ atomic_unchecked_t num_smbs_sent;
53707 union {
53708 struct {
53709- atomic_t num_writes;
53710- atomic_t num_reads;
53711- atomic_t num_flushes;
53712- atomic_t num_oplock_brks;
53713- atomic_t num_opens;
53714- atomic_t num_closes;
53715- atomic_t num_deletes;
53716- atomic_t num_mkdirs;
53717- atomic_t num_posixopens;
53718- atomic_t num_posixmkdirs;
53719- atomic_t num_rmdirs;
53720- atomic_t num_renames;
53721- atomic_t num_t2renames;
53722- atomic_t num_ffirst;
53723- atomic_t num_fnext;
53724- atomic_t num_fclose;
53725- atomic_t num_hardlinks;
53726- atomic_t num_symlinks;
53727- atomic_t num_locks;
53728- atomic_t num_acl_get;
53729- atomic_t num_acl_set;
53730+ atomic_unchecked_t num_writes;
53731+ atomic_unchecked_t num_reads;
53732+ atomic_unchecked_t num_flushes;
53733+ atomic_unchecked_t num_oplock_brks;
53734+ atomic_unchecked_t num_opens;
53735+ atomic_unchecked_t num_closes;
53736+ atomic_unchecked_t num_deletes;
53737+ atomic_unchecked_t num_mkdirs;
53738+ atomic_unchecked_t num_posixopens;
53739+ atomic_unchecked_t num_posixmkdirs;
53740+ atomic_unchecked_t num_rmdirs;
53741+ atomic_unchecked_t num_renames;
53742+ atomic_unchecked_t num_t2renames;
53743+ atomic_unchecked_t num_ffirst;
53744+ atomic_unchecked_t num_fnext;
53745+ atomic_unchecked_t num_fclose;
53746+ atomic_unchecked_t num_hardlinks;
53747+ atomic_unchecked_t num_symlinks;
53748+ atomic_unchecked_t num_locks;
53749+ atomic_unchecked_t num_acl_get;
53750+ atomic_unchecked_t num_acl_set;
53751 } cifs_stats;
53752 #ifdef CONFIG_CIFS_SMB2
53753 struct {
53754- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
53755- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
53756+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
53757+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
53758 } smb2_stats;
53759 #endif /* CONFIG_CIFS_SMB2 */
53760 } stats;
53761@@ -1096,7 +1096,7 @@ convert_delimiter(char *path, char delim)
53762 }
53763
53764 #ifdef CONFIG_CIFS_STATS
53765-#define cifs_stats_inc atomic_inc
53766+#define cifs_stats_inc atomic_inc_unchecked
53767
53768 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
53769 unsigned int bytes)
53770@@ -1461,8 +1461,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
53771 /* Various Debug counters */
53772 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
53773 #ifdef CONFIG_CIFS_STATS2
53774-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
53775-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
53776+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
53777+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
53778 #endif
53779 GLOBAL_EXTERN atomic_t smBufAllocCount;
53780 GLOBAL_EXTERN atomic_t midCount;
53781diff --git a/fs/cifs/link.c b/fs/cifs/link.c
53782index 562044f..4af6a17 100644
53783--- a/fs/cifs/link.c
53784+++ b/fs/cifs/link.c
53785@@ -638,7 +638,7 @@ symlink_exit:
53786
53787 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
53788 {
53789- char *p = nd_get_link(nd);
53790+ const char *p = nd_get_link(nd);
53791 if (!IS_ERR(p))
53792 kfree(p);
53793 }
53794diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
53795index f7d4b22..1254377 100644
53796--- a/fs/cifs/misc.c
53797+++ b/fs/cifs/misc.c
53798@@ -169,7 +169,7 @@ cifs_buf_get(void)
53799 memset(ret_buf, 0, buf_size + 3);
53800 atomic_inc(&bufAllocCount);
53801 #ifdef CONFIG_CIFS_STATS2
53802- atomic_inc(&totBufAllocCount);
53803+ atomic_inc_unchecked(&totBufAllocCount);
53804 #endif /* CONFIG_CIFS_STATS2 */
53805 }
53806
53807@@ -204,7 +204,7 @@ cifs_small_buf_get(void)
53808 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
53809 atomic_inc(&smBufAllocCount);
53810 #ifdef CONFIG_CIFS_STATS2
53811- atomic_inc(&totSmBufAllocCount);
53812+ atomic_inc_unchecked(&totSmBufAllocCount);
53813 #endif /* CONFIG_CIFS_STATS2 */
53814
53815 }
53816diff --git a/fs/cifs/netmisc.c b/fs/cifs/netmisc.c
53817index af847e1..651a527 100644
53818--- a/fs/cifs/netmisc.c
53819+++ b/fs/cifs/netmisc.c
53820@@ -780,7 +780,9 @@ static const struct {
53821 ERRDOS, ERRnoaccess, 0xc0000290}, {
53822 ERRDOS, ERRbadfunc, 0xc000029c}, {
53823 ERRDOS, ERRsymlink, NT_STATUS_STOPPED_ON_SYMLINK}, {
53824- ERRDOS, ERRinvlevel, 0x007c0001}, };
53825+ ERRDOS, ERRinvlevel, 0x007c0001}, {
53826+ 0, 0, 0 }
53827+};
53828
53829 /*****************************************************************************
53830 Print an error message from the status code
53831diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
53832index 6094397..51e576f 100644
53833--- a/fs/cifs/smb1ops.c
53834+++ b/fs/cifs/smb1ops.c
53835@@ -590,27 +590,27 @@ static void
53836 cifs_clear_stats(struct cifs_tcon *tcon)
53837 {
53838 #ifdef CONFIG_CIFS_STATS
53839- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
53840- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
53841- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
53842- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
53843- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
53844- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
53845- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
53846- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
53847- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
53848- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
53849- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
53850- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
53851- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
53852- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
53853- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
53854- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
53855- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
53856- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
53857- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
53858- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
53859- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
53860+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
53861+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
53862+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
53863+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
53864+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
53865+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
53866+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
53867+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
53868+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
53869+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
53870+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
53871+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
53872+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
53873+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
53874+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
53875+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
53876+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
53877+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
53878+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
53879+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
53880+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
53881 #endif
53882 }
53883
53884@@ -619,36 +619,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
53885 {
53886 #ifdef CONFIG_CIFS_STATS
53887 seq_printf(m, " Oplocks breaks: %d",
53888- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
53889+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
53890 seq_printf(m, "\nReads: %d Bytes: %llu",
53891- atomic_read(&tcon->stats.cifs_stats.num_reads),
53892+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
53893 (long long)(tcon->bytes_read));
53894 seq_printf(m, "\nWrites: %d Bytes: %llu",
53895- atomic_read(&tcon->stats.cifs_stats.num_writes),
53896+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
53897 (long long)(tcon->bytes_written));
53898 seq_printf(m, "\nFlushes: %d",
53899- atomic_read(&tcon->stats.cifs_stats.num_flushes));
53900+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
53901 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
53902- atomic_read(&tcon->stats.cifs_stats.num_locks),
53903- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
53904- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
53905+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
53906+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
53907+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
53908 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
53909- atomic_read(&tcon->stats.cifs_stats.num_opens),
53910- atomic_read(&tcon->stats.cifs_stats.num_closes),
53911- atomic_read(&tcon->stats.cifs_stats.num_deletes));
53912+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
53913+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
53914+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
53915 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
53916- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
53917- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
53918+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
53919+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
53920 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
53921- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
53922- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
53923+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
53924+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
53925 seq_printf(m, "\nRenames: %d T2 Renames %d",
53926- atomic_read(&tcon->stats.cifs_stats.num_renames),
53927- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
53928+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
53929+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
53930 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
53931- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
53932- atomic_read(&tcon->stats.cifs_stats.num_fnext),
53933- atomic_read(&tcon->stats.cifs_stats.num_fclose));
53934+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
53935+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
53936+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
53937 #endif
53938 }
53939
53940diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
53941index f259e6c..ca948ff 100644
53942--- a/fs/cifs/smb2ops.c
53943+++ b/fs/cifs/smb2ops.c
53944@@ -281,8 +281,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
53945 #ifdef CONFIG_CIFS_STATS
53946 int i;
53947 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
53948- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
53949- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
53950+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
53951+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
53952 }
53953 #endif
53954 }
53955@@ -310,65 +310,65 @@ static void
53956 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
53957 {
53958 #ifdef CONFIG_CIFS_STATS
53959- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
53960- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
53961+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
53962+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
53963 seq_printf(m, "\nNegotiates: %d sent %d failed",
53964- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
53965- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
53966+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
53967+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
53968 seq_printf(m, "\nSessionSetups: %d sent %d failed",
53969- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
53970- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
53971+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
53972+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
53973 seq_printf(m, "\nLogoffs: %d sent %d failed",
53974- atomic_read(&sent[SMB2_LOGOFF_HE]),
53975- atomic_read(&failed[SMB2_LOGOFF_HE]));
53976+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
53977+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
53978 seq_printf(m, "\nTreeConnects: %d sent %d failed",
53979- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
53980- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
53981+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
53982+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
53983 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
53984- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
53985- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
53986+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
53987+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
53988 seq_printf(m, "\nCreates: %d sent %d failed",
53989- atomic_read(&sent[SMB2_CREATE_HE]),
53990- atomic_read(&failed[SMB2_CREATE_HE]));
53991+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
53992+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
53993 seq_printf(m, "\nCloses: %d sent %d failed",
53994- atomic_read(&sent[SMB2_CLOSE_HE]),
53995- atomic_read(&failed[SMB2_CLOSE_HE]));
53996+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
53997+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
53998 seq_printf(m, "\nFlushes: %d sent %d failed",
53999- atomic_read(&sent[SMB2_FLUSH_HE]),
54000- atomic_read(&failed[SMB2_FLUSH_HE]));
54001+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
54002+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
54003 seq_printf(m, "\nReads: %d sent %d failed",
54004- atomic_read(&sent[SMB2_READ_HE]),
54005- atomic_read(&failed[SMB2_READ_HE]));
54006+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
54007+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
54008 seq_printf(m, "\nWrites: %d sent %d failed",
54009- atomic_read(&sent[SMB2_WRITE_HE]),
54010- atomic_read(&failed[SMB2_WRITE_HE]));
54011+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
54012+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
54013 seq_printf(m, "\nLocks: %d sent %d failed",
54014- atomic_read(&sent[SMB2_LOCK_HE]),
54015- atomic_read(&failed[SMB2_LOCK_HE]));
54016+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
54017+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
54018 seq_printf(m, "\nIOCTLs: %d sent %d failed",
54019- atomic_read(&sent[SMB2_IOCTL_HE]),
54020- atomic_read(&failed[SMB2_IOCTL_HE]));
54021+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
54022+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
54023 seq_printf(m, "\nCancels: %d sent %d failed",
54024- atomic_read(&sent[SMB2_CANCEL_HE]),
54025- atomic_read(&failed[SMB2_CANCEL_HE]));
54026+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
54027+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
54028 seq_printf(m, "\nEchos: %d sent %d failed",
54029- atomic_read(&sent[SMB2_ECHO_HE]),
54030- atomic_read(&failed[SMB2_ECHO_HE]));
54031+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
54032+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
54033 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
54034- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
54035- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
54036+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
54037+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
54038 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
54039- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
54040- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
54041+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
54042+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
54043 seq_printf(m, "\nQueryInfos: %d sent %d failed",
54044- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
54045- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
54046+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
54047+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
54048 seq_printf(m, "\nSetInfos: %d sent %d failed",
54049- atomic_read(&sent[SMB2_SET_INFO_HE]),
54050- atomic_read(&failed[SMB2_SET_INFO_HE]));
54051+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
54052+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
54053 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
54054- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
54055- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
54056+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
54057+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
54058 #endif
54059 }
54060
54061diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
54062index abc9c28..3fdae28 100644
54063--- a/fs/cifs/smb2pdu.c
54064+++ b/fs/cifs/smb2pdu.c
54065@@ -1946,8 +1946,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
54066 default:
54067 cifs_dbg(VFS, "info level %u isn't supported\n",
54068 srch_inf->info_level);
54069- rc = -EINVAL;
54070- goto qdir_exit;
54071+ return -EINVAL;
54072 }
54073
54074 req->FileIndex = cpu_to_le32(index);
54075diff --git a/fs/coda/cache.c b/fs/coda/cache.c
54076index 1da168c..8bc7ff6 100644
54077--- a/fs/coda/cache.c
54078+++ b/fs/coda/cache.c
54079@@ -24,7 +24,7 @@
54080 #include "coda_linux.h"
54081 #include "coda_cache.h"
54082
54083-static atomic_t permission_epoch = ATOMIC_INIT(0);
54084+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
54085
54086 /* replace or extend an acl cache hit */
54087 void coda_cache_enter(struct inode *inode, int mask)
54088@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
54089 struct coda_inode_info *cii = ITOC(inode);
54090
54091 spin_lock(&cii->c_lock);
54092- cii->c_cached_epoch = atomic_read(&permission_epoch);
54093+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
54094 if (!uid_eq(cii->c_uid, current_fsuid())) {
54095 cii->c_uid = current_fsuid();
54096 cii->c_cached_perm = mask;
54097@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
54098 {
54099 struct coda_inode_info *cii = ITOC(inode);
54100 spin_lock(&cii->c_lock);
54101- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
54102+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
54103 spin_unlock(&cii->c_lock);
54104 }
54105
54106 /* remove all acl caches */
54107 void coda_cache_clear_all(struct super_block *sb)
54108 {
54109- atomic_inc(&permission_epoch);
54110+ atomic_inc_unchecked(&permission_epoch);
54111 }
54112
54113
54114@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
54115 spin_lock(&cii->c_lock);
54116 hit = (mask & cii->c_cached_perm) == mask &&
54117 uid_eq(cii->c_uid, current_fsuid()) &&
54118- cii->c_cached_epoch == atomic_read(&permission_epoch);
54119+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
54120 spin_unlock(&cii->c_lock);
54121
54122 return hit;
54123diff --git a/fs/compat.c b/fs/compat.c
54124index 6af20de..fec3fbb 100644
54125--- a/fs/compat.c
54126+++ b/fs/compat.c
54127@@ -54,7 +54,7 @@
54128 #include <asm/ioctls.h>
54129 #include "internal.h"
54130
54131-int compat_log = 1;
54132+int compat_log = 0;
54133
54134 int compat_printk(const char *fmt, ...)
54135 {
54136@@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
54137
54138 set_fs(KERNEL_DS);
54139 /* The __user pointer cast is valid because of the set_fs() */
54140- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
54141+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
54142 set_fs(oldfs);
54143 /* truncating is ok because it's a user address */
54144 if (!ret)
54145@@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
54146 goto out;
54147
54148 ret = -EINVAL;
54149- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
54150+ if (nr_segs > UIO_MAXIOV)
54151 goto out;
54152 if (nr_segs > fast_segs) {
54153 ret = -ENOMEM;
54154@@ -834,6 +834,7 @@ struct compat_old_linux_dirent {
54155 struct compat_readdir_callback {
54156 struct dir_context ctx;
54157 struct compat_old_linux_dirent __user *dirent;
54158+ struct file * file;
54159 int result;
54160 };
54161
54162@@ -851,6 +852,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
54163 buf->result = -EOVERFLOW;
54164 return -EOVERFLOW;
54165 }
54166+
54167+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
54168+ return 0;
54169+
54170 buf->result++;
54171 dirent = buf->dirent;
54172 if (!access_ok(VERIFY_WRITE, dirent,
54173@@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
54174 if (!f.file)
54175 return -EBADF;
54176
54177+ buf.file = f.file;
54178 error = iterate_dir(f.file, &buf.ctx);
54179 if (buf.result)
54180 error = buf.result;
54181@@ -901,6 +907,7 @@ struct compat_getdents_callback {
54182 struct dir_context ctx;
54183 struct compat_linux_dirent __user *current_dir;
54184 struct compat_linux_dirent __user *previous;
54185+ struct file * file;
54186 int count;
54187 int error;
54188 };
54189@@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
54190 buf->error = -EOVERFLOW;
54191 return -EOVERFLOW;
54192 }
54193+
54194+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
54195+ return 0;
54196+
54197 dirent = buf->previous;
54198 if (dirent) {
54199 if (__put_user(offset, &dirent->d_off))
54200@@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
54201 if (!f.file)
54202 return -EBADF;
54203
54204+ buf.file = f.file;
54205 error = iterate_dir(f.file, &buf.ctx);
54206 if (error >= 0)
54207 error = buf.error;
54208@@ -987,6 +999,7 @@ struct compat_getdents_callback64 {
54209 struct dir_context ctx;
54210 struct linux_dirent64 __user *current_dir;
54211 struct linux_dirent64 __user *previous;
54212+ struct file * file;
54213 int count;
54214 int error;
54215 };
54216@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
54217 buf->error = -EINVAL; /* only used if we fail.. */
54218 if (reclen > buf->count)
54219 return -EINVAL;
54220+
54221+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
54222+ return 0;
54223+
54224 dirent = buf->previous;
54225
54226 if (dirent) {
54227@@ -1052,6 +1069,7 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
54228 if (!f.file)
54229 return -EBADF;
54230
54231+ buf.file = f.file;
54232 error = iterate_dir(f.file, &buf.ctx);
54233 if (error >= 0)
54234 error = buf.error;
54235diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
54236index a81147e..20bf2b5 100644
54237--- a/fs/compat_binfmt_elf.c
54238+++ b/fs/compat_binfmt_elf.c
54239@@ -30,11 +30,13 @@
54240 #undef elf_phdr
54241 #undef elf_shdr
54242 #undef elf_note
54243+#undef elf_dyn
54244 #undef elf_addr_t
54245 #define elfhdr elf32_hdr
54246 #define elf_phdr elf32_phdr
54247 #define elf_shdr elf32_shdr
54248 #define elf_note elf32_note
54249+#define elf_dyn Elf32_Dyn
54250 #define elf_addr_t Elf32_Addr
54251
54252 /*
54253diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
54254index 5d19acf..9ab093b 100644
54255--- a/fs/compat_ioctl.c
54256+++ b/fs/compat_ioctl.c
54257@@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
54258 return -EFAULT;
54259 if (__get_user(udata, &ss32->iomem_base))
54260 return -EFAULT;
54261- ss.iomem_base = compat_ptr(udata);
54262+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
54263 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
54264 __get_user(ss.port_high, &ss32->port_high))
54265 return -EFAULT;
54266@@ -702,8 +702,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
54267 for (i = 0; i < nmsgs; i++) {
54268 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
54269 return -EFAULT;
54270- if (get_user(datap, &umsgs[i].buf) ||
54271- put_user(compat_ptr(datap), &tmsgs[i].buf))
54272+ if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
54273+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
54274 return -EFAULT;
54275 }
54276 return sys_ioctl(fd, cmd, (unsigned long)tdata);
54277@@ -796,7 +796,7 @@ static int compat_ioctl_preallocate(struct file *file,
54278 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
54279 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
54280 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
54281- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
54282+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
54283 return -EFAULT;
54284
54285 return ioctl_preallocate(file, p);
54286@@ -1616,8 +1616,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
54287 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
54288 {
54289 unsigned int a, b;
54290- a = *(unsigned int *)p;
54291- b = *(unsigned int *)q;
54292+ a = *(const unsigned int *)p;
54293+ b = *(const unsigned int *)q;
54294 if (a > b)
54295 return 1;
54296 if (a < b)
54297diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
54298index 277bd1b..f312c9e 100644
54299--- a/fs/configfs/dir.c
54300+++ b/fs/configfs/dir.c
54301@@ -1546,7 +1546,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
54302 }
54303 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
54304 struct configfs_dirent *next;
54305- const char *name;
54306+ const unsigned char * name;
54307+ char d_name[sizeof(next->s_dentry->d_iname)];
54308 int len;
54309 struct inode *inode = NULL;
54310
54311@@ -1555,7 +1556,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
54312 continue;
54313
54314 name = configfs_get_name(next);
54315- len = strlen(name);
54316+ if (next->s_dentry && name == next->s_dentry->d_iname) {
54317+ len = next->s_dentry->d_name.len;
54318+ memcpy(d_name, name, len);
54319+ name = d_name;
54320+ } else
54321+ len = strlen(name);
54322
54323 /*
54324 * We'll have a dentry and an inode for
54325diff --git a/fs/coredump.c b/fs/coredump.c
54326index 72f816d..1ba8eff 100644
54327--- a/fs/coredump.c
54328+++ b/fs/coredump.c
54329@@ -433,8 +433,8 @@ static void wait_for_dump_helpers(struct file *file)
54330 struct pipe_inode_info *pipe = file->private_data;
54331
54332 pipe_lock(pipe);
54333- pipe->readers++;
54334- pipe->writers--;
54335+ atomic_inc(&pipe->readers);
54336+ atomic_dec(&pipe->writers);
54337 wake_up_interruptible_sync(&pipe->wait);
54338 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
54339 pipe_unlock(pipe);
54340@@ -443,11 +443,11 @@ static void wait_for_dump_helpers(struct file *file)
54341 * We actually want wait_event_freezable() but then we need
54342 * to clear TIF_SIGPENDING and improve dump_interrupted().
54343 */
54344- wait_event_interruptible(pipe->wait, pipe->readers == 1);
54345+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
54346
54347 pipe_lock(pipe);
54348- pipe->readers--;
54349- pipe->writers++;
54350+ atomic_dec(&pipe->readers);
54351+ atomic_inc(&pipe->writers);
54352 pipe_unlock(pipe);
54353 }
54354
54355@@ -494,7 +494,8 @@ void do_coredump(siginfo_t *siginfo)
54356 struct files_struct *displaced;
54357 bool need_nonrelative = false;
54358 bool core_dumped = false;
54359- static atomic_t core_dump_count = ATOMIC_INIT(0);
54360+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
54361+ long signr = siginfo->si_signo;
54362 struct coredump_params cprm = {
54363 .siginfo = siginfo,
54364 .regs = signal_pt_regs(),
54365@@ -507,7 +508,10 @@ void do_coredump(siginfo_t *siginfo)
54366 .mm_flags = mm->flags,
54367 };
54368
54369- audit_core_dumps(siginfo->si_signo);
54370+ audit_core_dumps(signr);
54371+
54372+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
54373+ gr_handle_brute_attach(cprm.mm_flags);
54374
54375 binfmt = mm->binfmt;
54376 if (!binfmt || !binfmt->core_dump)
54377@@ -531,7 +535,7 @@ void do_coredump(siginfo_t *siginfo)
54378 need_nonrelative = true;
54379 }
54380
54381- retval = coredump_wait(siginfo->si_signo, &core_state);
54382+ retval = coredump_wait(signr, &core_state);
54383 if (retval < 0)
54384 goto fail_creds;
54385
54386@@ -574,7 +578,7 @@ void do_coredump(siginfo_t *siginfo)
54387 }
54388 cprm.limit = RLIM_INFINITY;
54389
54390- dump_count = atomic_inc_return(&core_dump_count);
54391+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
54392 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
54393 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
54394 task_tgid_vnr(current), current->comm);
54395@@ -606,6 +610,8 @@ void do_coredump(siginfo_t *siginfo)
54396 } else {
54397 struct inode *inode;
54398
54399+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
54400+
54401 if (cprm.limit < binfmt->min_coredump)
54402 goto fail_unlock;
54403
54404@@ -664,7 +670,7 @@ close_fail:
54405 filp_close(cprm.file, NULL);
54406 fail_dropcount:
54407 if (ispipe)
54408- atomic_dec(&core_dump_count);
54409+ atomic_dec_unchecked(&core_dump_count);
54410 fail_unlock:
54411 kfree(cn.corename);
54412 coredump_finish(mm, core_dumped);
54413@@ -684,7 +690,7 @@ int dump_write(struct file *file, const void *addr, int nr)
54414 {
54415 return !dump_interrupted() &&
54416 access_ok(VERIFY_READ, addr, nr) &&
54417- file->f_op->write(file, addr, nr, &file->f_pos) == nr;
54418+ file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
54419 }
54420 EXPORT_SYMBOL(dump_write);
54421
54422diff --git a/fs/dcache.c b/fs/dcache.c
54423index b949af8..5978926 100644
54424--- a/fs/dcache.c
54425+++ b/fs/dcache.c
54426@@ -3073,7 +3073,8 @@ void __init vfs_caches_init(unsigned long mempages)
54427 mempages -= reserve;
54428
54429 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
54430- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
54431+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
54432+ SLAB_NO_SANITIZE, NULL);
54433
54434 dcache_init();
54435 inode_init();
54436diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
54437index c7c83ff..bda9461 100644
54438--- a/fs/debugfs/inode.c
54439+++ b/fs/debugfs/inode.c
54440@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
54441 */
54442 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
54443 {
54444+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
54445+ return __create_file(name, S_IFDIR | S_IRWXU,
54446+#else
54447 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
54448+#endif
54449 parent, NULL, NULL);
54450 }
54451 EXPORT_SYMBOL_GPL(debugfs_create_dir);
54452diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
54453index 67e9b63..a9adb68 100644
54454--- a/fs/ecryptfs/inode.c
54455+++ b/fs/ecryptfs/inode.c
54456@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
54457 old_fs = get_fs();
54458 set_fs(get_ds());
54459 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
54460- (char __user *)lower_buf,
54461+ (char __force_user *)lower_buf,
54462 PATH_MAX);
54463 set_fs(old_fs);
54464 if (rc < 0)
54465@@ -706,7 +706,7 @@ out:
54466 static void
54467 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
54468 {
54469- char *buf = nd_get_link(nd);
54470+ const char *buf = nd_get_link(nd);
54471 if (!IS_ERR(buf)) {
54472 /* Free the char* */
54473 kfree(buf);
54474diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
54475index e4141f2..d8263e8 100644
54476--- a/fs/ecryptfs/miscdev.c
54477+++ b/fs/ecryptfs/miscdev.c
54478@@ -304,7 +304,7 @@ check_list:
54479 goto out_unlock_msg_ctx;
54480 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
54481 if (msg_ctx->msg) {
54482- if (copy_to_user(&buf[i], packet_length, packet_length_size))
54483+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
54484 goto out_unlock_msg_ctx;
54485 i += packet_length_size;
54486 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
54487diff --git a/fs/exec.c b/fs/exec.c
54488index fd774c7..1c6a7bf 100644
54489--- a/fs/exec.c
54490+++ b/fs/exec.c
54491@@ -55,8 +55,20 @@
54492 #include <linux/pipe_fs_i.h>
54493 #include <linux/oom.h>
54494 #include <linux/compat.h>
54495+#include <linux/random.h>
54496+#include <linux/seq_file.h>
54497+#include <linux/coredump.h>
54498+#include <linux/mman.h>
54499+
54500+#ifdef CONFIG_PAX_REFCOUNT
54501+#include <linux/kallsyms.h>
54502+#include <linux/kdebug.h>
54503+#endif
54504+
54505+#include <trace/events/fs.h>
54506
54507 #include <asm/uaccess.h>
54508+#include <asm/sections.h>
54509 #include <asm/mmu_context.h>
54510 #include <asm/tlb.h>
54511
54512@@ -66,17 +78,32 @@
54513
54514 #include <trace/events/sched.h>
54515
54516+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
54517+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
54518+{
54519+ 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");
54520+}
54521+#endif
54522+
54523+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
54524+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
54525+EXPORT_SYMBOL(pax_set_initial_flags_func);
54526+#endif
54527+
54528 int suid_dumpable = 0;
54529
54530 static LIST_HEAD(formats);
54531 static DEFINE_RWLOCK(binfmt_lock);
54532
54533+extern int gr_process_kernel_exec_ban(void);
54534+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
54535+
54536 void __register_binfmt(struct linux_binfmt * fmt, int insert)
54537 {
54538 BUG_ON(!fmt);
54539 write_lock(&binfmt_lock);
54540- insert ? list_add(&fmt->lh, &formats) :
54541- list_add_tail(&fmt->lh, &formats);
54542+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
54543+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
54544 write_unlock(&binfmt_lock);
54545 }
54546
54547@@ -85,7 +112,7 @@ EXPORT_SYMBOL(__register_binfmt);
54548 void unregister_binfmt(struct linux_binfmt * fmt)
54549 {
54550 write_lock(&binfmt_lock);
54551- list_del(&fmt->lh);
54552+ pax_list_del((struct list_head *)&fmt->lh);
54553 write_unlock(&binfmt_lock);
54554 }
54555
54556@@ -181,18 +208,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
54557 int write)
54558 {
54559 struct page *page;
54560- int ret;
54561
54562-#ifdef CONFIG_STACK_GROWSUP
54563- if (write) {
54564- ret = expand_downwards(bprm->vma, pos);
54565- if (ret < 0)
54566- return NULL;
54567- }
54568-#endif
54569- ret = get_user_pages(current, bprm->mm, pos,
54570- 1, write, 1, &page, NULL);
54571- if (ret <= 0)
54572+ if (0 > expand_downwards(bprm->vma, pos))
54573+ return NULL;
54574+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
54575 return NULL;
54576
54577 if (write) {
54578@@ -208,6 +227,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
54579 if (size <= ARG_MAX)
54580 return page;
54581
54582+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54583+ // only allow 512KB for argv+env on suid/sgid binaries
54584+ // to prevent easy ASLR exhaustion
54585+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
54586+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
54587+ (size > (512 * 1024))) {
54588+ put_page(page);
54589+ return NULL;
54590+ }
54591+#endif
54592+
54593 /*
54594 * Limit to 1/4-th the stack size for the argv+env strings.
54595 * This ensures that:
54596@@ -267,6 +297,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
54597 vma->vm_end = STACK_TOP_MAX;
54598 vma->vm_start = vma->vm_end - PAGE_SIZE;
54599 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
54600+
54601+#ifdef CONFIG_PAX_SEGMEXEC
54602+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
54603+#endif
54604+
54605 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
54606 INIT_LIST_HEAD(&vma->anon_vma_chain);
54607
54608@@ -277,6 +312,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
54609 mm->stack_vm = mm->total_vm = 1;
54610 up_write(&mm->mmap_sem);
54611 bprm->p = vma->vm_end - sizeof(void *);
54612+
54613+#ifdef CONFIG_PAX_RANDUSTACK
54614+ if (randomize_va_space)
54615+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
54616+#endif
54617+
54618 return 0;
54619 err:
54620 up_write(&mm->mmap_sem);
54621@@ -397,7 +438,7 @@ struct user_arg_ptr {
54622 } ptr;
54623 };
54624
54625-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
54626+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
54627 {
54628 const char __user *native;
54629
54630@@ -406,14 +447,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
54631 compat_uptr_t compat;
54632
54633 if (get_user(compat, argv.ptr.compat + nr))
54634- return ERR_PTR(-EFAULT);
54635+ return (const char __force_user *)ERR_PTR(-EFAULT);
54636
54637 return compat_ptr(compat);
54638 }
54639 #endif
54640
54641 if (get_user(native, argv.ptr.native + nr))
54642- return ERR_PTR(-EFAULT);
54643+ return (const char __force_user *)ERR_PTR(-EFAULT);
54644
54645 return native;
54646 }
54647@@ -432,7 +473,7 @@ static int count(struct user_arg_ptr argv, int max)
54648 if (!p)
54649 break;
54650
54651- if (IS_ERR(p))
54652+ if (IS_ERR((const char __force_kernel *)p))
54653 return -EFAULT;
54654
54655 if (i >= max)
54656@@ -467,7 +508,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
54657
54658 ret = -EFAULT;
54659 str = get_user_arg_ptr(argv, argc);
54660- if (IS_ERR(str))
54661+ if (IS_ERR((const char __force_kernel *)str))
54662 goto out;
54663
54664 len = strnlen_user(str, MAX_ARG_STRLEN);
54665@@ -549,7 +590,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
54666 int r;
54667 mm_segment_t oldfs = get_fs();
54668 struct user_arg_ptr argv = {
54669- .ptr.native = (const char __user *const __user *)__argv,
54670+ .ptr.native = (const char __force_user * const __force_user *)__argv,
54671 };
54672
54673 set_fs(KERNEL_DS);
54674@@ -584,7 +625,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
54675 unsigned long new_end = old_end - shift;
54676 struct mmu_gather tlb;
54677
54678- BUG_ON(new_start > new_end);
54679+ if (new_start >= new_end || new_start < mmap_min_addr)
54680+ return -ENOMEM;
54681
54682 /*
54683 * ensure there are no vmas between where we want to go
54684@@ -593,6 +635,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
54685 if (vma != find_vma(mm, new_start))
54686 return -EFAULT;
54687
54688+#ifdef CONFIG_PAX_SEGMEXEC
54689+ BUG_ON(pax_find_mirror_vma(vma));
54690+#endif
54691+
54692 /*
54693 * cover the whole range: [new_start, old_end)
54694 */
54695@@ -673,10 +719,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
54696 stack_top = arch_align_stack(stack_top);
54697 stack_top = PAGE_ALIGN(stack_top);
54698
54699- if (unlikely(stack_top < mmap_min_addr) ||
54700- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
54701- return -ENOMEM;
54702-
54703 stack_shift = vma->vm_end - stack_top;
54704
54705 bprm->p -= stack_shift;
54706@@ -688,8 +730,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
54707 bprm->exec -= stack_shift;
54708
54709 down_write(&mm->mmap_sem);
54710+
54711+ /* Move stack pages down in memory. */
54712+ if (stack_shift) {
54713+ ret = shift_arg_pages(vma, stack_shift);
54714+ if (ret)
54715+ goto out_unlock;
54716+ }
54717+
54718 vm_flags = VM_STACK_FLAGS;
54719
54720+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
54721+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
54722+ vm_flags &= ~VM_EXEC;
54723+
54724+#ifdef CONFIG_PAX_MPROTECT
54725+ if (mm->pax_flags & MF_PAX_MPROTECT)
54726+ vm_flags &= ~VM_MAYEXEC;
54727+#endif
54728+
54729+ }
54730+#endif
54731+
54732 /*
54733 * Adjust stack execute permissions; explicitly enable for
54734 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
54735@@ -708,13 +770,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
54736 goto out_unlock;
54737 BUG_ON(prev != vma);
54738
54739- /* Move stack pages down in memory. */
54740- if (stack_shift) {
54741- ret = shift_arg_pages(vma, stack_shift);
54742- if (ret)
54743- goto out_unlock;
54744- }
54745-
54746 /* mprotect_fixup is overkill to remove the temporary stack flags */
54747 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
54748
54749@@ -738,6 +793,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
54750 #endif
54751 current->mm->start_stack = bprm->p;
54752 ret = expand_stack(vma, stack_base);
54753+
54754+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
54755+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
54756+ unsigned long size;
54757+ vm_flags_t vm_flags;
54758+
54759+ size = STACK_TOP - vma->vm_end;
54760+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
54761+
54762+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
54763+
54764+#ifdef CONFIG_X86
54765+ if (!ret) {
54766+ size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
54767+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
54768+ }
54769+#endif
54770+
54771+ }
54772+#endif
54773+
54774 if (ret)
54775 ret = -EFAULT;
54776
54777@@ -774,6 +850,8 @@ struct file *open_exec(const char *name)
54778
54779 fsnotify_open(file);
54780
54781+ trace_open_exec(name);
54782+
54783 err = deny_write_access(file);
54784 if (err)
54785 goto exit;
54786@@ -797,7 +875,7 @@ int kernel_read(struct file *file, loff_t offset,
54787 old_fs = get_fs();
54788 set_fs(get_ds());
54789 /* The cast to a user pointer is valid due to the set_fs() */
54790- result = vfs_read(file, (void __user *)addr, count, &pos);
54791+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
54792 set_fs(old_fs);
54793 return result;
54794 }
54795@@ -1253,7 +1331,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
54796 }
54797 rcu_read_unlock();
54798
54799- if (p->fs->users > n_fs) {
54800+ if (atomic_read(&p->fs->users) > n_fs) {
54801 bprm->unsafe |= LSM_UNSAFE_SHARE;
54802 } else {
54803 res = -EAGAIN;
54804@@ -1453,6 +1531,31 @@ int search_binary_handler(struct linux_binprm *bprm)
54805
54806 EXPORT_SYMBOL(search_binary_handler);
54807
54808+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54809+static DEFINE_PER_CPU(u64, exec_counter);
54810+static int __init init_exec_counters(void)
54811+{
54812+ unsigned int cpu;
54813+
54814+ for_each_possible_cpu(cpu) {
54815+ per_cpu(exec_counter, cpu) = (u64)cpu;
54816+ }
54817+
54818+ return 0;
54819+}
54820+early_initcall(init_exec_counters);
54821+static inline void increment_exec_counter(void)
54822+{
54823+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
54824+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
54825+}
54826+#else
54827+static inline void increment_exec_counter(void) {}
54828+#endif
54829+
54830+extern void gr_handle_exec_args(struct linux_binprm *bprm,
54831+ struct user_arg_ptr argv);
54832+
54833 /*
54834 * sys_execve() executes a new program.
54835 */
54836@@ -1460,12 +1563,19 @@ static int do_execve_common(const char *filename,
54837 struct user_arg_ptr argv,
54838 struct user_arg_ptr envp)
54839 {
54840+#ifdef CONFIG_GRKERNSEC
54841+ struct file *old_exec_file;
54842+ struct acl_subject_label *old_acl;
54843+ struct rlimit old_rlim[RLIM_NLIMITS];
54844+#endif
54845 struct linux_binprm *bprm;
54846 struct file *file;
54847 struct files_struct *displaced;
54848 bool clear_in_exec;
54849 int retval;
54850
54851+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
54852+
54853 /*
54854 * We move the actual failure in case of RLIMIT_NPROC excess from
54855 * set*uid() to execve() because too many poorly written programs
54856@@ -1506,12 +1616,22 @@ static int do_execve_common(const char *filename,
54857 if (IS_ERR(file))
54858 goto out_unmark;
54859
54860+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
54861+ retval = -EPERM;
54862+ goto out_file;
54863+ }
54864+
54865 sched_exec();
54866
54867 bprm->file = file;
54868 bprm->filename = filename;
54869 bprm->interp = filename;
54870
54871+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
54872+ retval = -EACCES;
54873+ goto out_file;
54874+ }
54875+
54876 retval = bprm_mm_init(bprm);
54877 if (retval)
54878 goto out_file;
54879@@ -1528,24 +1648,70 @@ static int do_execve_common(const char *filename,
54880 if (retval < 0)
54881 goto out;
54882
54883+#ifdef CONFIG_GRKERNSEC
54884+ old_acl = current->acl;
54885+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
54886+ old_exec_file = current->exec_file;
54887+ get_file(file);
54888+ current->exec_file = file;
54889+#endif
54890+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54891+ /* limit suid stack to 8MB
54892+ * we saved the old limits above and will restore them if this exec fails
54893+ */
54894+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
54895+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
54896+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
54897+#endif
54898+
54899+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
54900+ retval = -EPERM;
54901+ goto out_fail;
54902+ }
54903+
54904+ if (!gr_tpe_allow(file)) {
54905+ retval = -EACCES;
54906+ goto out_fail;
54907+ }
54908+
54909+ if (gr_check_crash_exec(file)) {
54910+ retval = -EACCES;
54911+ goto out_fail;
54912+ }
54913+
54914+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
54915+ bprm->unsafe);
54916+ if (retval < 0)
54917+ goto out_fail;
54918+
54919 retval = copy_strings_kernel(1, &bprm->filename, bprm);
54920 if (retval < 0)
54921- goto out;
54922+ goto out_fail;
54923
54924 bprm->exec = bprm->p;
54925 retval = copy_strings(bprm->envc, envp, bprm);
54926 if (retval < 0)
54927- goto out;
54928+ goto out_fail;
54929
54930 retval = copy_strings(bprm->argc, argv, bprm);
54931 if (retval < 0)
54932- goto out;
54933+ goto out_fail;
54934+
54935+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
54936+
54937+ gr_handle_exec_args(bprm, argv);
54938
54939 retval = search_binary_handler(bprm);
54940 if (retval < 0)
54941- goto out;
54942+ goto out_fail;
54943+#ifdef CONFIG_GRKERNSEC
54944+ if (old_exec_file)
54945+ fput(old_exec_file);
54946+#endif
54947
54948 /* execve succeeded */
54949+
54950+ increment_exec_counter();
54951 current->fs->in_exec = 0;
54952 current->in_execve = 0;
54953 acct_update_integrals(current);
54954@@ -1554,6 +1720,14 @@ static int do_execve_common(const char *filename,
54955 put_files_struct(displaced);
54956 return retval;
54957
54958+out_fail:
54959+#ifdef CONFIG_GRKERNSEC
54960+ current->acl = old_acl;
54961+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
54962+ fput(current->exec_file);
54963+ current->exec_file = old_exec_file;
54964+#endif
54965+
54966 out:
54967 if (bprm->mm) {
54968 acct_arg_size(bprm, 0);
54969@@ -1702,3 +1876,287 @@ asmlinkage long compat_sys_execve(const char __user * filename,
54970 return error;
54971 }
54972 #endif
54973+
54974+int pax_check_flags(unsigned long *flags)
54975+{
54976+ int retval = 0;
54977+
54978+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
54979+ if (*flags & MF_PAX_SEGMEXEC)
54980+ {
54981+ *flags &= ~MF_PAX_SEGMEXEC;
54982+ retval = -EINVAL;
54983+ }
54984+#endif
54985+
54986+ if ((*flags & MF_PAX_PAGEEXEC)
54987+
54988+#ifdef CONFIG_PAX_PAGEEXEC
54989+ && (*flags & MF_PAX_SEGMEXEC)
54990+#endif
54991+
54992+ )
54993+ {
54994+ *flags &= ~MF_PAX_PAGEEXEC;
54995+ retval = -EINVAL;
54996+ }
54997+
54998+ if ((*flags & MF_PAX_MPROTECT)
54999+
55000+#ifdef CONFIG_PAX_MPROTECT
55001+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
55002+#endif
55003+
55004+ )
55005+ {
55006+ *flags &= ~MF_PAX_MPROTECT;
55007+ retval = -EINVAL;
55008+ }
55009+
55010+ if ((*flags & MF_PAX_EMUTRAMP)
55011+
55012+#ifdef CONFIG_PAX_EMUTRAMP
55013+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
55014+#endif
55015+
55016+ )
55017+ {
55018+ *flags &= ~MF_PAX_EMUTRAMP;
55019+ retval = -EINVAL;
55020+ }
55021+
55022+ return retval;
55023+}
55024+
55025+EXPORT_SYMBOL(pax_check_flags);
55026+
55027+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
55028+char *pax_get_path(const struct path *path, char *buf, int buflen)
55029+{
55030+ char *pathname = d_path(path, buf, buflen);
55031+
55032+ if (IS_ERR(pathname))
55033+ goto toolong;
55034+
55035+ pathname = mangle_path(buf, pathname, "\t\n\\");
55036+ if (!pathname)
55037+ goto toolong;
55038+
55039+ *pathname = 0;
55040+ return buf;
55041+
55042+toolong:
55043+ return "<path too long>";
55044+}
55045+EXPORT_SYMBOL(pax_get_path);
55046+
55047+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
55048+{
55049+ struct task_struct *tsk = current;
55050+ struct mm_struct *mm = current->mm;
55051+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
55052+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
55053+ char *path_exec = NULL;
55054+ char *path_fault = NULL;
55055+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
55056+ siginfo_t info = { };
55057+
55058+ if (buffer_exec && buffer_fault) {
55059+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
55060+
55061+ down_read(&mm->mmap_sem);
55062+ vma = mm->mmap;
55063+ while (vma && (!vma_exec || !vma_fault)) {
55064+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
55065+ vma_exec = vma;
55066+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
55067+ vma_fault = vma;
55068+ vma = vma->vm_next;
55069+ }
55070+ if (vma_exec)
55071+ path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
55072+ if (vma_fault) {
55073+ start = vma_fault->vm_start;
55074+ end = vma_fault->vm_end;
55075+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
55076+ if (vma_fault->vm_file)
55077+ path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
55078+ else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
55079+ path_fault = "<heap>";
55080+ else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
55081+ path_fault = "<stack>";
55082+ else
55083+ path_fault = "<anonymous mapping>";
55084+ }
55085+ up_read(&mm->mmap_sem);
55086+ }
55087+ if (tsk->signal->curr_ip)
55088+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
55089+ else
55090+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
55091+ 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),
55092+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
55093+ free_page((unsigned long)buffer_exec);
55094+ free_page((unsigned long)buffer_fault);
55095+ pax_report_insns(regs, pc, sp);
55096+ info.si_signo = SIGKILL;
55097+ info.si_errno = 0;
55098+ info.si_code = SI_KERNEL;
55099+ info.si_pid = 0;
55100+ info.si_uid = 0;
55101+ do_coredump(&info);
55102+}
55103+#endif
55104+
55105+#ifdef CONFIG_PAX_REFCOUNT
55106+void pax_report_refcount_overflow(struct pt_regs *regs)
55107+{
55108+ if (current->signal->curr_ip)
55109+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
55110+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
55111+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
55112+ else
55113+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
55114+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
55115+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
55116+ preempt_disable();
55117+ show_regs(regs);
55118+ preempt_enable();
55119+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
55120+}
55121+#endif
55122+
55123+#ifdef CONFIG_PAX_USERCOPY
55124+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
55125+static noinline int check_stack_object(const void *obj, unsigned long len)
55126+{
55127+ const void * const stack = task_stack_page(current);
55128+ const void * const stackend = stack + THREAD_SIZE;
55129+
55130+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
55131+ const void *frame = NULL;
55132+ const void *oldframe;
55133+#endif
55134+
55135+ if (obj + len < obj)
55136+ return -1;
55137+
55138+ if (obj + len <= stack || stackend <= obj)
55139+ return 0;
55140+
55141+ if (obj < stack || stackend < obj + len)
55142+ return -1;
55143+
55144+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
55145+ oldframe = __builtin_frame_address(1);
55146+ if (oldframe)
55147+ frame = __builtin_frame_address(2);
55148+ /*
55149+ low ----------------------------------------------> high
55150+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
55151+ ^----------------^
55152+ allow copies only within here
55153+ */
55154+ while (stack <= frame && frame < stackend) {
55155+ /* if obj + len extends past the last frame, this
55156+ check won't pass and the next frame will be 0,
55157+ causing us to bail out and correctly report
55158+ the copy as invalid
55159+ */
55160+ if (obj + len <= frame)
55161+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
55162+ oldframe = frame;
55163+ frame = *(const void * const *)frame;
55164+ }
55165+ return -1;
55166+#else
55167+ return 1;
55168+#endif
55169+}
55170+
55171+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
55172+{
55173+ if (current->signal->curr_ip)
55174+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
55175+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
55176+ else
55177+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
55178+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
55179+ dump_stack();
55180+ gr_handle_kernel_exploit();
55181+ do_group_exit(SIGKILL);
55182+}
55183+#endif
55184+
55185+#ifdef CONFIG_PAX_USERCOPY
55186+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
55187+{
55188+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
55189+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
55190+#ifdef CONFIG_MODULES
55191+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
55192+#else
55193+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
55194+#endif
55195+
55196+#else
55197+ unsigned long textlow = (unsigned long)_stext;
55198+ unsigned long texthigh = (unsigned long)_etext;
55199+#endif
55200+
55201+ if (high <= textlow || low > texthigh)
55202+ return false;
55203+ else
55204+ return true;
55205+}
55206+#endif
55207+
55208+void __check_object_size(const void *ptr, unsigned long n, bool to_user)
55209+{
55210+
55211+#ifdef CONFIG_PAX_USERCOPY
55212+ const char *type;
55213+
55214+ if (!n)
55215+ return;
55216+
55217+ type = check_heap_object(ptr, n);
55218+ if (!type) {
55219+ int ret = check_stack_object(ptr, n);
55220+ if (ret == 1 || ret == 2)
55221+ return;
55222+ if (ret == 0) {
55223+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
55224+ type = "<kernel text>";
55225+ else
55226+ return;
55227+ } else
55228+ type = "<process stack>";
55229+ }
55230+
55231+ pax_report_usercopy(ptr, n, to_user, type);
55232+#endif
55233+
55234+}
55235+EXPORT_SYMBOL(__check_object_size);
55236+
55237+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
55238+void pax_track_stack(void)
55239+{
55240+ unsigned long sp = (unsigned long)&sp;
55241+ if (sp < current_thread_info()->lowest_stack &&
55242+ sp > (unsigned long)task_stack_page(current))
55243+ current_thread_info()->lowest_stack = sp;
55244+}
55245+EXPORT_SYMBOL(pax_track_stack);
55246+#endif
55247+
55248+#ifdef CONFIG_PAX_SIZE_OVERFLOW
55249+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
55250+{
55251+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
55252+ dump_stack();
55253+ do_group_exit(SIGKILL);
55254+}
55255+EXPORT_SYMBOL(report_size_overflow);
55256+#endif
55257diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
55258index 9f9992b..8b59411 100644
55259--- a/fs/ext2/balloc.c
55260+++ b/fs/ext2/balloc.c
55261@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
55262
55263 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
55264 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
55265- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
55266+ if (free_blocks < root_blocks + 1 &&
55267 !uid_eq(sbi->s_resuid, current_fsuid()) &&
55268 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
55269- !in_group_p (sbi->s_resgid))) {
55270+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
55271 return 0;
55272 }
55273 return 1;
55274diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
55275index 22548f5..41521d8 100644
55276--- a/fs/ext3/balloc.c
55277+++ b/fs/ext3/balloc.c
55278@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
55279
55280 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
55281 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
55282- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
55283+ if (free_blocks < root_blocks + 1 &&
55284 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
55285 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
55286- !in_group_p (sbi->s_resgid))) {
55287+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
55288 return 0;
55289 }
55290 return 1;
55291diff --git a/fs/ext3/namei.c b/fs/ext3/namei.c
55292index 1194b1f..f8cde46 100644
55293--- a/fs/ext3/namei.c
55294+++ b/fs/ext3/namei.c
55295@@ -1783,7 +1783,7 @@ retry:
55296 d_tmpfile(dentry, inode);
55297 err = ext3_orphan_add(handle, inode);
55298 if (err)
55299- goto err_drop_inode;
55300+ goto err_unlock_inode;
55301 mark_inode_dirty(inode);
55302 unlock_new_inode(inode);
55303 }
55304@@ -1791,10 +1791,9 @@ retry:
55305 if (err == -ENOSPC && ext3_should_retry_alloc(dir->i_sb, &retries))
55306 goto retry;
55307 return err;
55308-err_drop_inode:
55309+err_unlock_inode:
55310 ext3_journal_stop(handle);
55311 unlock_new_inode(inode);
55312- iput(inode);
55313 return err;
55314 }
55315
55316diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
55317index ddd715e..c772f88 100644
55318--- a/fs/ext4/balloc.c
55319+++ b/fs/ext4/balloc.c
55320@@ -528,8 +528,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
55321 /* Hm, nope. Are (enough) root reserved clusters available? */
55322 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
55323 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
55324- capable(CAP_SYS_RESOURCE) ||
55325- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
55326+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
55327+ capable_nolog(CAP_SYS_RESOURCE)) {
55328
55329 if (free_clusters >= (nclusters + dirty_clusters +
55330 resv_clusters))
55331diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
55332index 0ab26fb..b6ecb39 100644
55333--- a/fs/ext4/ext4.h
55334+++ b/fs/ext4/ext4.h
55335@@ -1247,19 +1247,19 @@ struct ext4_sb_info {
55336 unsigned long s_mb_last_start;
55337
55338 /* stats for buddy allocator */
55339- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
55340- atomic_t s_bal_success; /* we found long enough chunks */
55341- atomic_t s_bal_allocated; /* in blocks */
55342- atomic_t s_bal_ex_scanned; /* total extents scanned */
55343- atomic_t s_bal_goals; /* goal hits */
55344- atomic_t s_bal_breaks; /* too long searches */
55345- atomic_t s_bal_2orders; /* 2^order hits */
55346+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
55347+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
55348+ atomic_unchecked_t s_bal_allocated; /* in blocks */
55349+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
55350+ atomic_unchecked_t s_bal_goals; /* goal hits */
55351+ atomic_unchecked_t s_bal_breaks; /* too long searches */
55352+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
55353 spinlock_t s_bal_lock;
55354 unsigned long s_mb_buddies_generated;
55355 unsigned long long s_mb_generation_time;
55356- atomic_t s_mb_lost_chunks;
55357- atomic_t s_mb_preallocated;
55358- atomic_t s_mb_discarded;
55359+ atomic_unchecked_t s_mb_lost_chunks;
55360+ atomic_unchecked_t s_mb_preallocated;
55361+ atomic_unchecked_t s_mb_discarded;
55362 atomic_t s_lock_busy;
55363
55364 /* locality groups */
55365diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
55366index 4bbbf13b..dcceaeb 100644
55367--- a/fs/ext4/mballoc.c
55368+++ b/fs/ext4/mballoc.c
55369@@ -1865,7 +1865,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
55370 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
55371
55372 if (EXT4_SB(sb)->s_mb_stats)
55373- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
55374+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
55375
55376 break;
55377 }
55378@@ -2171,7 +2171,7 @@ repeat:
55379 ac->ac_status = AC_STATUS_CONTINUE;
55380 ac->ac_flags |= EXT4_MB_HINT_FIRST;
55381 cr = 3;
55382- atomic_inc(&sbi->s_mb_lost_chunks);
55383+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
55384 goto repeat;
55385 }
55386 }
55387@@ -2679,25 +2679,25 @@ int ext4_mb_release(struct super_block *sb)
55388 if (sbi->s_mb_stats) {
55389 ext4_msg(sb, KERN_INFO,
55390 "mballoc: %u blocks %u reqs (%u success)",
55391- atomic_read(&sbi->s_bal_allocated),
55392- atomic_read(&sbi->s_bal_reqs),
55393- atomic_read(&sbi->s_bal_success));
55394+ atomic_read_unchecked(&sbi->s_bal_allocated),
55395+ atomic_read_unchecked(&sbi->s_bal_reqs),
55396+ atomic_read_unchecked(&sbi->s_bal_success));
55397 ext4_msg(sb, KERN_INFO,
55398 "mballoc: %u extents scanned, %u goal hits, "
55399 "%u 2^N hits, %u breaks, %u lost",
55400- atomic_read(&sbi->s_bal_ex_scanned),
55401- atomic_read(&sbi->s_bal_goals),
55402- atomic_read(&sbi->s_bal_2orders),
55403- atomic_read(&sbi->s_bal_breaks),
55404- atomic_read(&sbi->s_mb_lost_chunks));
55405+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
55406+ atomic_read_unchecked(&sbi->s_bal_goals),
55407+ atomic_read_unchecked(&sbi->s_bal_2orders),
55408+ atomic_read_unchecked(&sbi->s_bal_breaks),
55409+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
55410 ext4_msg(sb, KERN_INFO,
55411 "mballoc: %lu generated and it took %Lu",
55412 sbi->s_mb_buddies_generated,
55413 sbi->s_mb_generation_time);
55414 ext4_msg(sb, KERN_INFO,
55415 "mballoc: %u preallocated, %u discarded",
55416- atomic_read(&sbi->s_mb_preallocated),
55417- atomic_read(&sbi->s_mb_discarded));
55418+ atomic_read_unchecked(&sbi->s_mb_preallocated),
55419+ atomic_read_unchecked(&sbi->s_mb_discarded));
55420 }
55421
55422 free_percpu(sbi->s_locality_groups);
55423@@ -3151,16 +3151,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
55424 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
55425
55426 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
55427- atomic_inc(&sbi->s_bal_reqs);
55428- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
55429+ atomic_inc_unchecked(&sbi->s_bal_reqs);
55430+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
55431 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
55432- atomic_inc(&sbi->s_bal_success);
55433- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
55434+ atomic_inc_unchecked(&sbi->s_bal_success);
55435+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
55436 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
55437 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
55438- atomic_inc(&sbi->s_bal_goals);
55439+ atomic_inc_unchecked(&sbi->s_bal_goals);
55440 if (ac->ac_found > sbi->s_mb_max_to_scan)
55441- atomic_inc(&sbi->s_bal_breaks);
55442+ atomic_inc_unchecked(&sbi->s_bal_breaks);
55443 }
55444
55445 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
55446@@ -3560,7 +3560,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
55447 trace_ext4_mb_new_inode_pa(ac, pa);
55448
55449 ext4_mb_use_inode_pa(ac, pa);
55450- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
55451+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
55452
55453 ei = EXT4_I(ac->ac_inode);
55454 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
55455@@ -3620,7 +3620,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
55456 trace_ext4_mb_new_group_pa(ac, pa);
55457
55458 ext4_mb_use_group_pa(ac, pa);
55459- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
55460+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
55461
55462 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
55463 lg = ac->ac_lg;
55464@@ -3709,7 +3709,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
55465 * from the bitmap and continue.
55466 */
55467 }
55468- atomic_add(free, &sbi->s_mb_discarded);
55469+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
55470
55471 return err;
55472 }
55473@@ -3727,7 +3727,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
55474 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
55475 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
55476 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
55477- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
55478+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
55479 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
55480
55481 return 0;
55482diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
55483index 214461e..3614c89 100644
55484--- a/fs/ext4/mmp.c
55485+++ b/fs/ext4/mmp.c
55486@@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
55487 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
55488 const char *function, unsigned int line, const char *msg)
55489 {
55490- __ext4_warning(sb, function, line, msg);
55491+ __ext4_warning(sb, function, line, "%s", msg);
55492 __ext4_warning(sb, function, line,
55493 "MMP failure info: last update time: %llu, last update "
55494 "node: %s, last update device: %s\n",
55495diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
55496index 35f55a0..b53cbc6 100644
55497--- a/fs/ext4/namei.c
55498+++ b/fs/ext4/namei.c
55499@@ -2319,7 +2319,7 @@ retry:
55500 d_tmpfile(dentry, inode);
55501 err = ext4_orphan_add(handle, inode);
55502 if (err)
55503- goto err_drop_inode;
55504+ goto err_unlock_inode;
55505 mark_inode_dirty(inode);
55506 unlock_new_inode(inode);
55507 }
55508@@ -2328,10 +2328,9 @@ retry:
55509 if (err == -ENOSPC && ext4_should_retry_alloc(dir->i_sb, &retries))
55510 goto retry;
55511 return err;
55512-err_drop_inode:
55513+err_unlock_inode:
55514 ext4_journal_stop(handle);
55515 unlock_new_inode(inode);
55516- iput(inode);
55517 return err;
55518 }
55519
55520diff --git a/fs/ext4/super.c b/fs/ext4/super.c
55521index b59373b..f41c2b5 100644
55522--- a/fs/ext4/super.c
55523+++ b/fs/ext4/super.c
55524@@ -1254,7 +1254,7 @@ static ext4_fsblk_t get_sb_block(void **data)
55525 }
55526
55527 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
55528-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
55529+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
55530 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
55531
55532 #ifdef CONFIG_QUOTA
55533@@ -2394,7 +2394,7 @@ struct ext4_attr {
55534 int offset;
55535 int deprecated_val;
55536 } u;
55537-};
55538+} __do_const;
55539
55540 static int parse_strtoull(const char *buf,
55541 unsigned long long max, unsigned long long *value)
55542diff --git a/fs/fcntl.c b/fs/fcntl.c
55543index 65343c3..9969dcf 100644
55544--- a/fs/fcntl.c
55545+++ b/fs/fcntl.c
55546@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
55547 if (err)
55548 return err;
55549
55550+ if (gr_handle_chroot_fowner(pid, type))
55551+ return -ENOENT;
55552+ if (gr_check_protected_task_fowner(pid, type))
55553+ return -EACCES;
55554+
55555 f_modown(filp, pid, type, force);
55556 return 0;
55557 }
55558diff --git a/fs/fhandle.c b/fs/fhandle.c
55559index 999ff5c..41f4109 100644
55560--- a/fs/fhandle.c
55561+++ b/fs/fhandle.c
55562@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
55563 } else
55564 retval = 0;
55565 /* copy the mount id */
55566- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
55567- sizeof(*mnt_id)) ||
55568+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
55569 copy_to_user(ufh, handle,
55570 sizeof(struct file_handle) + handle_bytes))
55571 retval = -EFAULT;
55572diff --git a/fs/file.c b/fs/file.c
55573index 4a78f98..9447397 100644
55574--- a/fs/file.c
55575+++ b/fs/file.c
55576@@ -16,6 +16,7 @@
55577 #include <linux/slab.h>
55578 #include <linux/vmalloc.h>
55579 #include <linux/file.h>
55580+#include <linux/security.h>
55581 #include <linux/fdtable.h>
55582 #include <linux/bitops.h>
55583 #include <linux/interrupt.h>
55584@@ -828,6 +829,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
55585 if (!file)
55586 return __close_fd(files, fd);
55587
55588+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
55589 if (fd >= rlimit(RLIMIT_NOFILE))
55590 return -EBADF;
55591
55592@@ -854,6 +856,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
55593 if (unlikely(oldfd == newfd))
55594 return -EINVAL;
55595
55596+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
55597 if (newfd >= rlimit(RLIMIT_NOFILE))
55598 return -EBADF;
55599
55600@@ -909,6 +912,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
55601 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
55602 {
55603 int err;
55604+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
55605 if (from >= rlimit(RLIMIT_NOFILE))
55606 return -EINVAL;
55607 err = alloc_fd(from, flags);
55608diff --git a/fs/filesystems.c b/fs/filesystems.c
55609index 92567d9..fcd8cbf 100644
55610--- a/fs/filesystems.c
55611+++ b/fs/filesystems.c
55612@@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
55613 int len = dot ? dot - name : strlen(name);
55614
55615 fs = __get_fs_type(name, len);
55616+#ifdef CONFIG_GRKERNSEC_MODHARDEN
55617+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
55618+#else
55619 if (!fs && (request_module("fs-%.*s", len, name) == 0))
55620+#endif
55621 fs = __get_fs_type(name, len);
55622
55623 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
55624diff --git a/fs/fs_struct.c b/fs/fs_struct.c
55625index d8ac61d..79a36f0 100644
55626--- a/fs/fs_struct.c
55627+++ b/fs/fs_struct.c
55628@@ -4,6 +4,7 @@
55629 #include <linux/path.h>
55630 #include <linux/slab.h>
55631 #include <linux/fs_struct.h>
55632+#include <linux/grsecurity.h>
55633 #include "internal.h"
55634
55635 /*
55636@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
55637 write_seqcount_begin(&fs->seq);
55638 old_root = fs->root;
55639 fs->root = *path;
55640+ gr_set_chroot_entries(current, path);
55641 write_seqcount_end(&fs->seq);
55642 spin_unlock(&fs->lock);
55643 if (old_root.dentry)
55644@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
55645 int hits = 0;
55646 spin_lock(&fs->lock);
55647 write_seqcount_begin(&fs->seq);
55648+ /* this root replacement is only done by pivot_root,
55649+ leave grsec's chroot tagging alone for this task
55650+ so that a pivoted root isn't treated as a chroot
55651+ */
55652 hits += replace_path(&fs->root, old_root, new_root);
55653 hits += replace_path(&fs->pwd, old_root, new_root);
55654 write_seqcount_end(&fs->seq);
55655@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
55656 task_lock(tsk);
55657 spin_lock(&fs->lock);
55658 tsk->fs = NULL;
55659- kill = !--fs->users;
55660+ gr_clear_chroot_entries(tsk);
55661+ kill = !atomic_dec_return(&fs->users);
55662 spin_unlock(&fs->lock);
55663 task_unlock(tsk);
55664 if (kill)
55665@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
55666 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
55667 /* We don't need to lock fs - think why ;-) */
55668 if (fs) {
55669- fs->users = 1;
55670+ atomic_set(&fs->users, 1);
55671 fs->in_exec = 0;
55672 spin_lock_init(&fs->lock);
55673 seqcount_init(&fs->seq);
55674@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
55675 spin_lock(&old->lock);
55676 fs->root = old->root;
55677 path_get(&fs->root);
55678+ /* instead of calling gr_set_chroot_entries here,
55679+ we call it from every caller of this function
55680+ */
55681 fs->pwd = old->pwd;
55682 path_get(&fs->pwd);
55683 spin_unlock(&old->lock);
55684@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
55685
55686 task_lock(current);
55687 spin_lock(&fs->lock);
55688- kill = !--fs->users;
55689+ kill = !atomic_dec_return(&fs->users);
55690 current->fs = new_fs;
55691+ gr_set_chroot_entries(current, &new_fs->root);
55692 spin_unlock(&fs->lock);
55693 task_unlock(current);
55694
55695@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
55696
55697 int current_umask(void)
55698 {
55699- return current->fs->umask;
55700+ return current->fs->umask | gr_acl_umask();
55701 }
55702 EXPORT_SYMBOL(current_umask);
55703
55704 /* to be mentioned only in INIT_TASK */
55705 struct fs_struct init_fs = {
55706- .users = 1,
55707+ .users = ATOMIC_INIT(1),
55708 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
55709 .seq = SEQCNT_ZERO,
55710 .umask = 0022,
55711diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
55712index 0e91a3c..6c6d2e0 100644
55713--- a/fs/fscache/cookie.c
55714+++ b/fs/fscache/cookie.c
55715@@ -19,7 +19,7 @@
55716
55717 struct kmem_cache *fscache_cookie_jar;
55718
55719-static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
55720+static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
55721
55722 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
55723 static int fscache_alloc_object(struct fscache_cache *cache,
55724@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
55725 parent ? (char *) parent->def->name : "<no-parent>",
55726 def->name, netfs_data);
55727
55728- fscache_stat(&fscache_n_acquires);
55729+ fscache_stat_unchecked(&fscache_n_acquires);
55730
55731 /* if there's no parent cookie, then we don't create one here either */
55732 if (!parent) {
55733- fscache_stat(&fscache_n_acquires_null);
55734+ fscache_stat_unchecked(&fscache_n_acquires_null);
55735 _leave(" [no parent]");
55736 return NULL;
55737 }
55738@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
55739 /* allocate and initialise a cookie */
55740 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
55741 if (!cookie) {
55742- fscache_stat(&fscache_n_acquires_oom);
55743+ fscache_stat_unchecked(&fscache_n_acquires_oom);
55744 _leave(" [ENOMEM]");
55745 return NULL;
55746 }
55747@@ -114,13 +114,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
55748
55749 switch (cookie->def->type) {
55750 case FSCACHE_COOKIE_TYPE_INDEX:
55751- fscache_stat(&fscache_n_cookie_index);
55752+ fscache_stat_unchecked(&fscache_n_cookie_index);
55753 break;
55754 case FSCACHE_COOKIE_TYPE_DATAFILE:
55755- fscache_stat(&fscache_n_cookie_data);
55756+ fscache_stat_unchecked(&fscache_n_cookie_data);
55757 break;
55758 default:
55759- fscache_stat(&fscache_n_cookie_special);
55760+ fscache_stat_unchecked(&fscache_n_cookie_special);
55761 break;
55762 }
55763
55764@@ -131,13 +131,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
55765 if (fscache_acquire_non_index_cookie(cookie) < 0) {
55766 atomic_dec(&parent->n_children);
55767 __fscache_cookie_put(cookie);
55768- fscache_stat(&fscache_n_acquires_nobufs);
55769+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
55770 _leave(" = NULL");
55771 return NULL;
55772 }
55773 }
55774
55775- fscache_stat(&fscache_n_acquires_ok);
55776+ fscache_stat_unchecked(&fscache_n_acquires_ok);
55777 _leave(" = %p", cookie);
55778 return cookie;
55779 }
55780@@ -173,7 +173,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
55781 cache = fscache_select_cache_for_object(cookie->parent);
55782 if (!cache) {
55783 up_read(&fscache_addremove_sem);
55784- fscache_stat(&fscache_n_acquires_no_cache);
55785+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
55786 _leave(" = -ENOMEDIUM [no cache]");
55787 return -ENOMEDIUM;
55788 }
55789@@ -259,14 +259,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
55790 object = cache->ops->alloc_object(cache, cookie);
55791 fscache_stat_d(&fscache_n_cop_alloc_object);
55792 if (IS_ERR(object)) {
55793- fscache_stat(&fscache_n_object_no_alloc);
55794+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
55795 ret = PTR_ERR(object);
55796 goto error;
55797 }
55798
55799- fscache_stat(&fscache_n_object_alloc);
55800+ fscache_stat_unchecked(&fscache_n_object_alloc);
55801
55802- object->debug_id = atomic_inc_return(&fscache_object_debug_id);
55803+ object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
55804
55805 _debug("ALLOC OBJ%x: %s {%lx}",
55806 object->debug_id, cookie->def->name, object->events);
55807@@ -380,7 +380,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
55808
55809 _enter("{%s}", cookie->def->name);
55810
55811- fscache_stat(&fscache_n_invalidates);
55812+ fscache_stat_unchecked(&fscache_n_invalidates);
55813
55814 /* Only permit invalidation of data files. Invalidating an index will
55815 * require the caller to release all its attachments to the tree rooted
55816@@ -438,10 +438,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
55817 {
55818 struct fscache_object *object;
55819
55820- fscache_stat(&fscache_n_updates);
55821+ fscache_stat_unchecked(&fscache_n_updates);
55822
55823 if (!cookie) {
55824- fscache_stat(&fscache_n_updates_null);
55825+ fscache_stat_unchecked(&fscache_n_updates_null);
55826 _leave(" [no cookie]");
55827 return;
55828 }
55829@@ -473,12 +473,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
55830 {
55831 struct fscache_object *object;
55832
55833- fscache_stat(&fscache_n_relinquishes);
55834+ fscache_stat_unchecked(&fscache_n_relinquishes);
55835 if (retire)
55836- fscache_stat(&fscache_n_relinquishes_retire);
55837+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
55838
55839 if (!cookie) {
55840- fscache_stat(&fscache_n_relinquishes_null);
55841+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
55842 _leave(" [no cookie]");
55843 return;
55844 }
55845diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
55846index 12d505b..86473a3 100644
55847--- a/fs/fscache/internal.h
55848+++ b/fs/fscache/internal.h
55849@@ -147,101 +147,101 @@ extern void fscache_proc_cleanup(void);
55850 * stats.c
55851 */
55852 #ifdef CONFIG_FSCACHE_STATS
55853-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
55854-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
55855+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
55856+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
55857
55858-extern atomic_t fscache_n_op_pend;
55859-extern atomic_t fscache_n_op_run;
55860-extern atomic_t fscache_n_op_enqueue;
55861-extern atomic_t fscache_n_op_deferred_release;
55862-extern atomic_t fscache_n_op_release;
55863-extern atomic_t fscache_n_op_gc;
55864-extern atomic_t fscache_n_op_cancelled;
55865-extern atomic_t fscache_n_op_rejected;
55866+extern atomic_unchecked_t fscache_n_op_pend;
55867+extern atomic_unchecked_t fscache_n_op_run;
55868+extern atomic_unchecked_t fscache_n_op_enqueue;
55869+extern atomic_unchecked_t fscache_n_op_deferred_release;
55870+extern atomic_unchecked_t fscache_n_op_release;
55871+extern atomic_unchecked_t fscache_n_op_gc;
55872+extern atomic_unchecked_t fscache_n_op_cancelled;
55873+extern atomic_unchecked_t fscache_n_op_rejected;
55874
55875-extern atomic_t fscache_n_attr_changed;
55876-extern atomic_t fscache_n_attr_changed_ok;
55877-extern atomic_t fscache_n_attr_changed_nobufs;
55878-extern atomic_t fscache_n_attr_changed_nomem;
55879-extern atomic_t fscache_n_attr_changed_calls;
55880+extern atomic_unchecked_t fscache_n_attr_changed;
55881+extern atomic_unchecked_t fscache_n_attr_changed_ok;
55882+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
55883+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
55884+extern atomic_unchecked_t fscache_n_attr_changed_calls;
55885
55886-extern atomic_t fscache_n_allocs;
55887-extern atomic_t fscache_n_allocs_ok;
55888-extern atomic_t fscache_n_allocs_wait;
55889-extern atomic_t fscache_n_allocs_nobufs;
55890-extern atomic_t fscache_n_allocs_intr;
55891-extern atomic_t fscache_n_allocs_object_dead;
55892-extern atomic_t fscache_n_alloc_ops;
55893-extern atomic_t fscache_n_alloc_op_waits;
55894+extern atomic_unchecked_t fscache_n_allocs;
55895+extern atomic_unchecked_t fscache_n_allocs_ok;
55896+extern atomic_unchecked_t fscache_n_allocs_wait;
55897+extern atomic_unchecked_t fscache_n_allocs_nobufs;
55898+extern atomic_unchecked_t fscache_n_allocs_intr;
55899+extern atomic_unchecked_t fscache_n_allocs_object_dead;
55900+extern atomic_unchecked_t fscache_n_alloc_ops;
55901+extern atomic_unchecked_t fscache_n_alloc_op_waits;
55902
55903-extern atomic_t fscache_n_retrievals;
55904-extern atomic_t fscache_n_retrievals_ok;
55905-extern atomic_t fscache_n_retrievals_wait;
55906-extern atomic_t fscache_n_retrievals_nodata;
55907-extern atomic_t fscache_n_retrievals_nobufs;
55908-extern atomic_t fscache_n_retrievals_intr;
55909-extern atomic_t fscache_n_retrievals_nomem;
55910-extern atomic_t fscache_n_retrievals_object_dead;
55911-extern atomic_t fscache_n_retrieval_ops;
55912-extern atomic_t fscache_n_retrieval_op_waits;
55913+extern atomic_unchecked_t fscache_n_retrievals;
55914+extern atomic_unchecked_t fscache_n_retrievals_ok;
55915+extern atomic_unchecked_t fscache_n_retrievals_wait;
55916+extern atomic_unchecked_t fscache_n_retrievals_nodata;
55917+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
55918+extern atomic_unchecked_t fscache_n_retrievals_intr;
55919+extern atomic_unchecked_t fscache_n_retrievals_nomem;
55920+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
55921+extern atomic_unchecked_t fscache_n_retrieval_ops;
55922+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
55923
55924-extern atomic_t fscache_n_stores;
55925-extern atomic_t fscache_n_stores_ok;
55926-extern atomic_t fscache_n_stores_again;
55927-extern atomic_t fscache_n_stores_nobufs;
55928-extern atomic_t fscache_n_stores_oom;
55929-extern atomic_t fscache_n_store_ops;
55930-extern atomic_t fscache_n_store_calls;
55931-extern atomic_t fscache_n_store_pages;
55932-extern atomic_t fscache_n_store_radix_deletes;
55933-extern atomic_t fscache_n_store_pages_over_limit;
55934+extern atomic_unchecked_t fscache_n_stores;
55935+extern atomic_unchecked_t fscache_n_stores_ok;
55936+extern atomic_unchecked_t fscache_n_stores_again;
55937+extern atomic_unchecked_t fscache_n_stores_nobufs;
55938+extern atomic_unchecked_t fscache_n_stores_oom;
55939+extern atomic_unchecked_t fscache_n_store_ops;
55940+extern atomic_unchecked_t fscache_n_store_calls;
55941+extern atomic_unchecked_t fscache_n_store_pages;
55942+extern atomic_unchecked_t fscache_n_store_radix_deletes;
55943+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
55944
55945-extern atomic_t fscache_n_store_vmscan_not_storing;
55946-extern atomic_t fscache_n_store_vmscan_gone;
55947-extern atomic_t fscache_n_store_vmscan_busy;
55948-extern atomic_t fscache_n_store_vmscan_cancelled;
55949-extern atomic_t fscache_n_store_vmscan_wait;
55950+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
55951+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
55952+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
55953+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
55954+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
55955
55956-extern atomic_t fscache_n_marks;
55957-extern atomic_t fscache_n_uncaches;
55958+extern atomic_unchecked_t fscache_n_marks;
55959+extern atomic_unchecked_t fscache_n_uncaches;
55960
55961-extern atomic_t fscache_n_acquires;
55962-extern atomic_t fscache_n_acquires_null;
55963-extern atomic_t fscache_n_acquires_no_cache;
55964-extern atomic_t fscache_n_acquires_ok;
55965-extern atomic_t fscache_n_acquires_nobufs;
55966-extern atomic_t fscache_n_acquires_oom;
55967+extern atomic_unchecked_t fscache_n_acquires;
55968+extern atomic_unchecked_t fscache_n_acquires_null;
55969+extern atomic_unchecked_t fscache_n_acquires_no_cache;
55970+extern atomic_unchecked_t fscache_n_acquires_ok;
55971+extern atomic_unchecked_t fscache_n_acquires_nobufs;
55972+extern atomic_unchecked_t fscache_n_acquires_oom;
55973
55974-extern atomic_t fscache_n_invalidates;
55975-extern atomic_t fscache_n_invalidates_run;
55976+extern atomic_unchecked_t fscache_n_invalidates;
55977+extern atomic_unchecked_t fscache_n_invalidates_run;
55978
55979-extern atomic_t fscache_n_updates;
55980-extern atomic_t fscache_n_updates_null;
55981-extern atomic_t fscache_n_updates_run;
55982+extern atomic_unchecked_t fscache_n_updates;
55983+extern atomic_unchecked_t fscache_n_updates_null;
55984+extern atomic_unchecked_t fscache_n_updates_run;
55985
55986-extern atomic_t fscache_n_relinquishes;
55987-extern atomic_t fscache_n_relinquishes_null;
55988-extern atomic_t fscache_n_relinquishes_waitcrt;
55989-extern atomic_t fscache_n_relinquishes_retire;
55990+extern atomic_unchecked_t fscache_n_relinquishes;
55991+extern atomic_unchecked_t fscache_n_relinquishes_null;
55992+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
55993+extern atomic_unchecked_t fscache_n_relinquishes_retire;
55994
55995-extern atomic_t fscache_n_cookie_index;
55996-extern atomic_t fscache_n_cookie_data;
55997-extern atomic_t fscache_n_cookie_special;
55998+extern atomic_unchecked_t fscache_n_cookie_index;
55999+extern atomic_unchecked_t fscache_n_cookie_data;
56000+extern atomic_unchecked_t fscache_n_cookie_special;
56001
56002-extern atomic_t fscache_n_object_alloc;
56003-extern atomic_t fscache_n_object_no_alloc;
56004-extern atomic_t fscache_n_object_lookups;
56005-extern atomic_t fscache_n_object_lookups_negative;
56006-extern atomic_t fscache_n_object_lookups_positive;
56007-extern atomic_t fscache_n_object_lookups_timed_out;
56008-extern atomic_t fscache_n_object_created;
56009-extern atomic_t fscache_n_object_avail;
56010-extern atomic_t fscache_n_object_dead;
56011+extern atomic_unchecked_t fscache_n_object_alloc;
56012+extern atomic_unchecked_t fscache_n_object_no_alloc;
56013+extern atomic_unchecked_t fscache_n_object_lookups;
56014+extern atomic_unchecked_t fscache_n_object_lookups_negative;
56015+extern atomic_unchecked_t fscache_n_object_lookups_positive;
56016+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
56017+extern atomic_unchecked_t fscache_n_object_created;
56018+extern atomic_unchecked_t fscache_n_object_avail;
56019+extern atomic_unchecked_t fscache_n_object_dead;
56020
56021-extern atomic_t fscache_n_checkaux_none;
56022-extern atomic_t fscache_n_checkaux_okay;
56023-extern atomic_t fscache_n_checkaux_update;
56024-extern atomic_t fscache_n_checkaux_obsolete;
56025+extern atomic_unchecked_t fscache_n_checkaux_none;
56026+extern atomic_unchecked_t fscache_n_checkaux_okay;
56027+extern atomic_unchecked_t fscache_n_checkaux_update;
56028+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
56029
56030 extern atomic_t fscache_n_cop_alloc_object;
56031 extern atomic_t fscache_n_cop_lookup_object;
56032@@ -266,6 +266,11 @@ static inline void fscache_stat(atomic_t *stat)
56033 atomic_inc(stat);
56034 }
56035
56036+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
56037+{
56038+ atomic_inc_unchecked(stat);
56039+}
56040+
56041 static inline void fscache_stat_d(atomic_t *stat)
56042 {
56043 atomic_dec(stat);
56044@@ -278,6 +283,7 @@ extern const struct file_operations fscache_stats_fops;
56045
56046 #define __fscache_stat(stat) (NULL)
56047 #define fscache_stat(stat) do {} while (0)
56048+#define fscache_stat_unchecked(stat) do {} while (0)
56049 #define fscache_stat_d(stat) do {} while (0)
56050 #endif
56051
56052diff --git a/fs/fscache/object.c b/fs/fscache/object.c
56053index 86d75a6..5f3d7a0 100644
56054--- a/fs/fscache/object.c
56055+++ b/fs/fscache/object.c
56056@@ -451,7 +451,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
56057 _debug("LOOKUP \"%s\" in \"%s\"",
56058 cookie->def->name, object->cache->tag->name);
56059
56060- fscache_stat(&fscache_n_object_lookups);
56061+ fscache_stat_unchecked(&fscache_n_object_lookups);
56062 fscache_stat(&fscache_n_cop_lookup_object);
56063 ret = object->cache->ops->lookup_object(object);
56064 fscache_stat_d(&fscache_n_cop_lookup_object);
56065@@ -461,7 +461,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
56066 if (ret == -ETIMEDOUT) {
56067 /* probably stuck behind another object, so move this one to
56068 * the back of the queue */
56069- fscache_stat(&fscache_n_object_lookups_timed_out);
56070+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
56071 _leave(" [timeout]");
56072 return NO_TRANSIT;
56073 }
56074@@ -489,7 +489,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
56075 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
56076
56077 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
56078- fscache_stat(&fscache_n_object_lookups_negative);
56079+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
56080
56081 /* Allow write requests to begin stacking up and read requests to begin
56082 * returning ENODATA.
56083@@ -523,7 +523,7 @@ void fscache_obtained_object(struct fscache_object *object)
56084 /* if we were still looking up, then we must have a positive lookup
56085 * result, in which case there may be data available */
56086 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
56087- fscache_stat(&fscache_n_object_lookups_positive);
56088+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
56089
56090 /* We do (presumably) have data */
56091 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
56092@@ -534,7 +534,7 @@ void fscache_obtained_object(struct fscache_object *object)
56093 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
56094 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
56095 } else {
56096- fscache_stat(&fscache_n_object_created);
56097+ fscache_stat_unchecked(&fscache_n_object_created);
56098 }
56099
56100 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
56101@@ -570,7 +570,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
56102 fscache_stat_d(&fscache_n_cop_lookup_complete);
56103
56104 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
56105- fscache_stat(&fscache_n_object_avail);
56106+ fscache_stat_unchecked(&fscache_n_object_avail);
56107
56108 _leave("");
56109 return transit_to(JUMPSTART_DEPS);
56110@@ -716,7 +716,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
56111
56112 /* this just shifts the object release to the work processor */
56113 fscache_put_object(object);
56114- fscache_stat(&fscache_n_object_dead);
56115+ fscache_stat_unchecked(&fscache_n_object_dead);
56116
56117 _leave("");
56118 return transit_to(OBJECT_DEAD);
56119@@ -881,7 +881,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
56120 enum fscache_checkaux result;
56121
56122 if (!object->cookie->def->check_aux) {
56123- fscache_stat(&fscache_n_checkaux_none);
56124+ fscache_stat_unchecked(&fscache_n_checkaux_none);
56125 return FSCACHE_CHECKAUX_OKAY;
56126 }
56127
56128@@ -890,17 +890,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
56129 switch (result) {
56130 /* entry okay as is */
56131 case FSCACHE_CHECKAUX_OKAY:
56132- fscache_stat(&fscache_n_checkaux_okay);
56133+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
56134 break;
56135
56136 /* entry requires update */
56137 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
56138- fscache_stat(&fscache_n_checkaux_update);
56139+ fscache_stat_unchecked(&fscache_n_checkaux_update);
56140 break;
56141
56142 /* entry requires deletion */
56143 case FSCACHE_CHECKAUX_OBSOLETE:
56144- fscache_stat(&fscache_n_checkaux_obsolete);
56145+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
56146 break;
56147
56148 default:
56149@@ -986,7 +986,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
56150 {
56151 const struct fscache_state *s;
56152
56153- fscache_stat(&fscache_n_invalidates_run);
56154+ fscache_stat_unchecked(&fscache_n_invalidates_run);
56155 fscache_stat(&fscache_n_cop_invalidate_object);
56156 s = _fscache_invalidate_object(object, event);
56157 fscache_stat_d(&fscache_n_cop_invalidate_object);
56158@@ -1001,7 +1001,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
56159 {
56160 _enter("{OBJ%x},%d", object->debug_id, event);
56161
56162- fscache_stat(&fscache_n_updates_run);
56163+ fscache_stat_unchecked(&fscache_n_updates_run);
56164 fscache_stat(&fscache_n_cop_update_object);
56165 object->cache->ops->update_object(object);
56166 fscache_stat_d(&fscache_n_cop_update_object);
56167diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
56168index 318071a..379938b 100644
56169--- a/fs/fscache/operation.c
56170+++ b/fs/fscache/operation.c
56171@@ -17,7 +17,7 @@
56172 #include <linux/slab.h>
56173 #include "internal.h"
56174
56175-atomic_t fscache_op_debug_id;
56176+atomic_unchecked_t fscache_op_debug_id;
56177 EXPORT_SYMBOL(fscache_op_debug_id);
56178
56179 /**
56180@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
56181 ASSERTCMP(atomic_read(&op->usage), >, 0);
56182 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
56183
56184- fscache_stat(&fscache_n_op_enqueue);
56185+ fscache_stat_unchecked(&fscache_n_op_enqueue);
56186 switch (op->flags & FSCACHE_OP_TYPE) {
56187 case FSCACHE_OP_ASYNC:
56188 _debug("queue async");
56189@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
56190 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
56191 if (op->processor)
56192 fscache_enqueue_operation(op);
56193- fscache_stat(&fscache_n_op_run);
56194+ fscache_stat_unchecked(&fscache_n_op_run);
56195 }
56196
56197 /*
56198@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
56199 if (object->n_in_progress > 0) {
56200 atomic_inc(&op->usage);
56201 list_add_tail(&op->pend_link, &object->pending_ops);
56202- fscache_stat(&fscache_n_op_pend);
56203+ fscache_stat_unchecked(&fscache_n_op_pend);
56204 } else if (!list_empty(&object->pending_ops)) {
56205 atomic_inc(&op->usage);
56206 list_add_tail(&op->pend_link, &object->pending_ops);
56207- fscache_stat(&fscache_n_op_pend);
56208+ fscache_stat_unchecked(&fscache_n_op_pend);
56209 fscache_start_operations(object);
56210 } else {
56211 ASSERTCMP(object->n_in_progress, ==, 0);
56212@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
56213 object->n_exclusive++; /* reads and writes must wait */
56214 atomic_inc(&op->usage);
56215 list_add_tail(&op->pend_link, &object->pending_ops);
56216- fscache_stat(&fscache_n_op_pend);
56217+ fscache_stat_unchecked(&fscache_n_op_pend);
56218 ret = 0;
56219 } else {
56220 /* If we're in any other state, there must have been an I/O
56221@@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
56222 if (object->n_exclusive > 0) {
56223 atomic_inc(&op->usage);
56224 list_add_tail(&op->pend_link, &object->pending_ops);
56225- fscache_stat(&fscache_n_op_pend);
56226+ fscache_stat_unchecked(&fscache_n_op_pend);
56227 } else if (!list_empty(&object->pending_ops)) {
56228 atomic_inc(&op->usage);
56229 list_add_tail(&op->pend_link, &object->pending_ops);
56230- fscache_stat(&fscache_n_op_pend);
56231+ fscache_stat_unchecked(&fscache_n_op_pend);
56232 fscache_start_operations(object);
56233 } else {
56234 ASSERTCMP(object->n_exclusive, ==, 0);
56235@@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
56236 object->n_ops++;
56237 atomic_inc(&op->usage);
56238 list_add_tail(&op->pend_link, &object->pending_ops);
56239- fscache_stat(&fscache_n_op_pend);
56240+ fscache_stat_unchecked(&fscache_n_op_pend);
56241 ret = 0;
56242 } else if (fscache_object_is_dying(object)) {
56243- fscache_stat(&fscache_n_op_rejected);
56244+ fscache_stat_unchecked(&fscache_n_op_rejected);
56245 op->state = FSCACHE_OP_ST_CANCELLED;
56246 ret = -ENOBUFS;
56247 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
56248@@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
56249 ret = -EBUSY;
56250 if (op->state == FSCACHE_OP_ST_PENDING) {
56251 ASSERT(!list_empty(&op->pend_link));
56252- fscache_stat(&fscache_n_op_cancelled);
56253+ fscache_stat_unchecked(&fscache_n_op_cancelled);
56254 list_del_init(&op->pend_link);
56255 if (do_cancel)
56256 do_cancel(op);
56257@@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
56258 while (!list_empty(&object->pending_ops)) {
56259 op = list_entry(object->pending_ops.next,
56260 struct fscache_operation, pend_link);
56261- fscache_stat(&fscache_n_op_cancelled);
56262+ fscache_stat_unchecked(&fscache_n_op_cancelled);
56263 list_del_init(&op->pend_link);
56264
56265 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
56266@@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
56267 op->state, ==, FSCACHE_OP_ST_CANCELLED);
56268 op->state = FSCACHE_OP_ST_DEAD;
56269
56270- fscache_stat(&fscache_n_op_release);
56271+ fscache_stat_unchecked(&fscache_n_op_release);
56272
56273 if (op->release) {
56274 op->release(op);
56275@@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
56276 * lock, and defer it otherwise */
56277 if (!spin_trylock(&object->lock)) {
56278 _debug("defer put");
56279- fscache_stat(&fscache_n_op_deferred_release);
56280+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
56281
56282 cache = object->cache;
56283 spin_lock(&cache->op_gc_list_lock);
56284@@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
56285
56286 _debug("GC DEFERRED REL OBJ%x OP%x",
56287 object->debug_id, op->debug_id);
56288- fscache_stat(&fscache_n_op_gc);
56289+ fscache_stat_unchecked(&fscache_n_op_gc);
56290
56291 ASSERTCMP(atomic_read(&op->usage), ==, 0);
56292 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
56293diff --git a/fs/fscache/page.c b/fs/fscache/page.c
56294index d479ab3..727a7f2 100644
56295--- a/fs/fscache/page.c
56296+++ b/fs/fscache/page.c
56297@@ -61,7 +61,7 @@ try_again:
56298 val = radix_tree_lookup(&cookie->stores, page->index);
56299 if (!val) {
56300 rcu_read_unlock();
56301- fscache_stat(&fscache_n_store_vmscan_not_storing);
56302+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
56303 __fscache_uncache_page(cookie, page);
56304 return true;
56305 }
56306@@ -91,11 +91,11 @@ try_again:
56307 spin_unlock(&cookie->stores_lock);
56308
56309 if (xpage) {
56310- fscache_stat(&fscache_n_store_vmscan_cancelled);
56311- fscache_stat(&fscache_n_store_radix_deletes);
56312+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
56313+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
56314 ASSERTCMP(xpage, ==, page);
56315 } else {
56316- fscache_stat(&fscache_n_store_vmscan_gone);
56317+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
56318 }
56319
56320 wake_up_bit(&cookie->flags, 0);
56321@@ -110,11 +110,11 @@ page_busy:
56322 * sleeping on memory allocation, so we may need to impose a timeout
56323 * too. */
56324 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
56325- fscache_stat(&fscache_n_store_vmscan_busy);
56326+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
56327 return false;
56328 }
56329
56330- fscache_stat(&fscache_n_store_vmscan_wait);
56331+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
56332 __fscache_wait_on_page_write(cookie, page);
56333 gfp &= ~__GFP_WAIT;
56334 goto try_again;
56335@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
56336 FSCACHE_COOKIE_STORING_TAG);
56337 if (!radix_tree_tag_get(&cookie->stores, page->index,
56338 FSCACHE_COOKIE_PENDING_TAG)) {
56339- fscache_stat(&fscache_n_store_radix_deletes);
56340+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
56341 xpage = radix_tree_delete(&cookie->stores, page->index);
56342 }
56343 spin_unlock(&cookie->stores_lock);
56344@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
56345
56346 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
56347
56348- fscache_stat(&fscache_n_attr_changed_calls);
56349+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
56350
56351 if (fscache_object_is_active(object) &&
56352 fscache_use_cookie(object)) {
56353@@ -189,11 +189,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
56354
56355 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
56356
56357- fscache_stat(&fscache_n_attr_changed);
56358+ fscache_stat_unchecked(&fscache_n_attr_changed);
56359
56360 op = kzalloc(sizeof(*op), GFP_KERNEL);
56361 if (!op) {
56362- fscache_stat(&fscache_n_attr_changed_nomem);
56363+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
56364 _leave(" = -ENOMEM");
56365 return -ENOMEM;
56366 }
56367@@ -211,7 +211,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
56368 if (fscache_submit_exclusive_op(object, op) < 0)
56369 goto nobufs;
56370 spin_unlock(&cookie->lock);
56371- fscache_stat(&fscache_n_attr_changed_ok);
56372+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
56373 fscache_put_operation(op);
56374 _leave(" = 0");
56375 return 0;
56376@@ -219,7 +219,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
56377 nobufs:
56378 spin_unlock(&cookie->lock);
56379 kfree(op);
56380- fscache_stat(&fscache_n_attr_changed_nobufs);
56381+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
56382 _leave(" = %d", -ENOBUFS);
56383 return -ENOBUFS;
56384 }
56385@@ -258,7 +258,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
56386 /* allocate a retrieval operation and attempt to submit it */
56387 op = kzalloc(sizeof(*op), GFP_NOIO);
56388 if (!op) {
56389- fscache_stat(&fscache_n_retrievals_nomem);
56390+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
56391 return NULL;
56392 }
56393
56394@@ -289,13 +289,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
56395 return 0;
56396 }
56397
56398- fscache_stat(&fscache_n_retrievals_wait);
56399+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
56400
56401 jif = jiffies;
56402 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
56403 fscache_wait_bit_interruptible,
56404 TASK_INTERRUPTIBLE) != 0) {
56405- fscache_stat(&fscache_n_retrievals_intr);
56406+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
56407 _leave(" = -ERESTARTSYS");
56408 return -ERESTARTSYS;
56409 }
56410@@ -324,8 +324,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
56411 */
56412 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
56413 struct fscache_retrieval *op,
56414- atomic_t *stat_op_waits,
56415- atomic_t *stat_object_dead)
56416+ atomic_unchecked_t *stat_op_waits,
56417+ atomic_unchecked_t *stat_object_dead)
56418 {
56419 int ret;
56420
56421@@ -333,7 +333,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
56422 goto check_if_dead;
56423
56424 _debug(">>> WT");
56425- fscache_stat(stat_op_waits);
56426+ fscache_stat_unchecked(stat_op_waits);
56427 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
56428 fscache_wait_bit_interruptible,
56429 TASK_INTERRUPTIBLE) != 0) {
56430@@ -350,14 +350,14 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
56431
56432 check_if_dead:
56433 if (op->op.state == FSCACHE_OP_ST_CANCELLED) {
56434- fscache_stat(stat_object_dead);
56435+ fscache_stat_unchecked(stat_object_dead);
56436 _leave(" = -ENOBUFS [cancelled]");
56437 return -ENOBUFS;
56438 }
56439 if (unlikely(fscache_object_is_dead(object))) {
56440 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->op.state);
56441 fscache_cancel_op(&op->op, fscache_do_cancel_retrieval);
56442- fscache_stat(stat_object_dead);
56443+ fscache_stat_unchecked(stat_object_dead);
56444 return -ENOBUFS;
56445 }
56446 return 0;
56447@@ -384,7 +384,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
56448
56449 _enter("%p,%p,,,", cookie, page);
56450
56451- fscache_stat(&fscache_n_retrievals);
56452+ fscache_stat_unchecked(&fscache_n_retrievals);
56453
56454 if (hlist_empty(&cookie->backing_objects))
56455 goto nobufs;
56456@@ -424,7 +424,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
56457 goto nobufs_unlock_dec;
56458 spin_unlock(&cookie->lock);
56459
56460- fscache_stat(&fscache_n_retrieval_ops);
56461+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
56462
56463 /* pin the netfs read context in case we need to do the actual netfs
56464 * read because we've encountered a cache read failure */
56465@@ -454,15 +454,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
56466
56467 error:
56468 if (ret == -ENOMEM)
56469- fscache_stat(&fscache_n_retrievals_nomem);
56470+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
56471 else if (ret == -ERESTARTSYS)
56472- fscache_stat(&fscache_n_retrievals_intr);
56473+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
56474 else if (ret == -ENODATA)
56475- fscache_stat(&fscache_n_retrievals_nodata);
56476+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
56477 else if (ret < 0)
56478- fscache_stat(&fscache_n_retrievals_nobufs);
56479+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
56480 else
56481- fscache_stat(&fscache_n_retrievals_ok);
56482+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
56483
56484 fscache_put_retrieval(op);
56485 _leave(" = %d", ret);
56486@@ -475,7 +475,7 @@ nobufs_unlock:
56487 atomic_dec(&cookie->n_active);
56488 kfree(op);
56489 nobufs:
56490- fscache_stat(&fscache_n_retrievals_nobufs);
56491+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
56492 _leave(" = -ENOBUFS");
56493 return -ENOBUFS;
56494 }
56495@@ -513,7 +513,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
56496
56497 _enter("%p,,%d,,,", cookie, *nr_pages);
56498
56499- fscache_stat(&fscache_n_retrievals);
56500+ fscache_stat_unchecked(&fscache_n_retrievals);
56501
56502 if (hlist_empty(&cookie->backing_objects))
56503 goto nobufs;
56504@@ -549,7 +549,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
56505 goto nobufs_unlock_dec;
56506 spin_unlock(&cookie->lock);
56507
56508- fscache_stat(&fscache_n_retrieval_ops);
56509+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
56510
56511 /* pin the netfs read context in case we need to do the actual netfs
56512 * read because we've encountered a cache read failure */
56513@@ -579,15 +579,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
56514
56515 error:
56516 if (ret == -ENOMEM)
56517- fscache_stat(&fscache_n_retrievals_nomem);
56518+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
56519 else if (ret == -ERESTARTSYS)
56520- fscache_stat(&fscache_n_retrievals_intr);
56521+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
56522 else if (ret == -ENODATA)
56523- fscache_stat(&fscache_n_retrievals_nodata);
56524+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
56525 else if (ret < 0)
56526- fscache_stat(&fscache_n_retrievals_nobufs);
56527+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
56528 else
56529- fscache_stat(&fscache_n_retrievals_ok);
56530+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
56531
56532 fscache_put_retrieval(op);
56533 _leave(" = %d", ret);
56534@@ -600,7 +600,7 @@ nobufs_unlock:
56535 atomic_dec(&cookie->n_active);
56536 kfree(op);
56537 nobufs:
56538- fscache_stat(&fscache_n_retrievals_nobufs);
56539+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
56540 _leave(" = -ENOBUFS");
56541 return -ENOBUFS;
56542 }
56543@@ -624,7 +624,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
56544
56545 _enter("%p,%p,,,", cookie, page);
56546
56547- fscache_stat(&fscache_n_allocs);
56548+ fscache_stat_unchecked(&fscache_n_allocs);
56549
56550 if (hlist_empty(&cookie->backing_objects))
56551 goto nobufs;
56552@@ -656,7 +656,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
56553 goto nobufs_unlock;
56554 spin_unlock(&cookie->lock);
56555
56556- fscache_stat(&fscache_n_alloc_ops);
56557+ fscache_stat_unchecked(&fscache_n_alloc_ops);
56558
56559 ret = fscache_wait_for_retrieval_activation(
56560 object, op,
56561@@ -672,11 +672,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
56562
56563 error:
56564 if (ret == -ERESTARTSYS)
56565- fscache_stat(&fscache_n_allocs_intr);
56566+ fscache_stat_unchecked(&fscache_n_allocs_intr);
56567 else if (ret < 0)
56568- fscache_stat(&fscache_n_allocs_nobufs);
56569+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
56570 else
56571- fscache_stat(&fscache_n_allocs_ok);
56572+ fscache_stat_unchecked(&fscache_n_allocs_ok);
56573
56574 fscache_put_retrieval(op);
56575 _leave(" = %d", ret);
56576@@ -687,7 +687,7 @@ nobufs_unlock:
56577 atomic_dec(&cookie->n_active);
56578 kfree(op);
56579 nobufs:
56580- fscache_stat(&fscache_n_allocs_nobufs);
56581+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
56582 _leave(" = -ENOBUFS");
56583 return -ENOBUFS;
56584 }
56585@@ -747,7 +747,7 @@ static void fscache_write_op(struct fscache_operation *_op)
56586
56587 spin_lock(&cookie->stores_lock);
56588
56589- fscache_stat(&fscache_n_store_calls);
56590+ fscache_stat_unchecked(&fscache_n_store_calls);
56591
56592 /* find a page to store */
56593 page = NULL;
56594@@ -758,7 +758,7 @@ static void fscache_write_op(struct fscache_operation *_op)
56595 page = results[0];
56596 _debug("gang %d [%lx]", n, page->index);
56597 if (page->index > op->store_limit) {
56598- fscache_stat(&fscache_n_store_pages_over_limit);
56599+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
56600 goto superseded;
56601 }
56602
56603@@ -770,7 +770,7 @@ static void fscache_write_op(struct fscache_operation *_op)
56604 spin_unlock(&cookie->stores_lock);
56605 spin_unlock(&object->lock);
56606
56607- fscache_stat(&fscache_n_store_pages);
56608+ fscache_stat_unchecked(&fscache_n_store_pages);
56609 fscache_stat(&fscache_n_cop_write_page);
56610 ret = object->cache->ops->write_page(op, page);
56611 fscache_stat_d(&fscache_n_cop_write_page);
56612@@ -873,7 +873,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
56613 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
56614 ASSERT(PageFsCache(page));
56615
56616- fscache_stat(&fscache_n_stores);
56617+ fscache_stat_unchecked(&fscache_n_stores);
56618
56619 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
56620 _leave(" = -ENOBUFS [invalidating]");
56621@@ -931,7 +931,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
56622 spin_unlock(&cookie->stores_lock);
56623 spin_unlock(&object->lock);
56624
56625- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
56626+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
56627 op->store_limit = object->store_limit;
56628
56629 atomic_inc(&cookie->n_active);
56630@@ -940,8 +940,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
56631
56632 spin_unlock(&cookie->lock);
56633 radix_tree_preload_end();
56634- fscache_stat(&fscache_n_store_ops);
56635- fscache_stat(&fscache_n_stores_ok);
56636+ fscache_stat_unchecked(&fscache_n_store_ops);
56637+ fscache_stat_unchecked(&fscache_n_stores_ok);
56638
56639 /* the work queue now carries its own ref on the object */
56640 fscache_put_operation(&op->op);
56641@@ -949,14 +949,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
56642 return 0;
56643
56644 already_queued:
56645- fscache_stat(&fscache_n_stores_again);
56646+ fscache_stat_unchecked(&fscache_n_stores_again);
56647 already_pending:
56648 spin_unlock(&cookie->stores_lock);
56649 spin_unlock(&object->lock);
56650 spin_unlock(&cookie->lock);
56651 radix_tree_preload_end();
56652 kfree(op);
56653- fscache_stat(&fscache_n_stores_ok);
56654+ fscache_stat_unchecked(&fscache_n_stores_ok);
56655 _leave(" = 0");
56656 return 0;
56657
56658@@ -976,14 +976,14 @@ nobufs:
56659 spin_unlock(&cookie->lock);
56660 radix_tree_preload_end();
56661 kfree(op);
56662- fscache_stat(&fscache_n_stores_nobufs);
56663+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
56664 _leave(" = -ENOBUFS");
56665 return -ENOBUFS;
56666
56667 nomem_free:
56668 kfree(op);
56669 nomem:
56670- fscache_stat(&fscache_n_stores_oom);
56671+ fscache_stat_unchecked(&fscache_n_stores_oom);
56672 _leave(" = -ENOMEM");
56673 return -ENOMEM;
56674 }
56675@@ -1001,7 +1001,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
56676 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
56677 ASSERTCMP(page, !=, NULL);
56678
56679- fscache_stat(&fscache_n_uncaches);
56680+ fscache_stat_unchecked(&fscache_n_uncaches);
56681
56682 /* cache withdrawal may beat us to it */
56683 if (!PageFsCache(page))
56684@@ -1052,7 +1052,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
56685 struct fscache_cookie *cookie = op->op.object->cookie;
56686
56687 #ifdef CONFIG_FSCACHE_STATS
56688- atomic_inc(&fscache_n_marks);
56689+ atomic_inc_unchecked(&fscache_n_marks);
56690 #endif
56691
56692 _debug("- mark %p{%lx}", page, page->index);
56693diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
56694index 40d13c7..ddf52b9 100644
56695--- a/fs/fscache/stats.c
56696+++ b/fs/fscache/stats.c
56697@@ -18,99 +18,99 @@
56698 /*
56699 * operation counters
56700 */
56701-atomic_t fscache_n_op_pend;
56702-atomic_t fscache_n_op_run;
56703-atomic_t fscache_n_op_enqueue;
56704-atomic_t fscache_n_op_requeue;
56705-atomic_t fscache_n_op_deferred_release;
56706-atomic_t fscache_n_op_release;
56707-atomic_t fscache_n_op_gc;
56708-atomic_t fscache_n_op_cancelled;
56709-atomic_t fscache_n_op_rejected;
56710+atomic_unchecked_t fscache_n_op_pend;
56711+atomic_unchecked_t fscache_n_op_run;
56712+atomic_unchecked_t fscache_n_op_enqueue;
56713+atomic_unchecked_t fscache_n_op_requeue;
56714+atomic_unchecked_t fscache_n_op_deferred_release;
56715+atomic_unchecked_t fscache_n_op_release;
56716+atomic_unchecked_t fscache_n_op_gc;
56717+atomic_unchecked_t fscache_n_op_cancelled;
56718+atomic_unchecked_t fscache_n_op_rejected;
56719
56720-atomic_t fscache_n_attr_changed;
56721-atomic_t fscache_n_attr_changed_ok;
56722-atomic_t fscache_n_attr_changed_nobufs;
56723-atomic_t fscache_n_attr_changed_nomem;
56724-atomic_t fscache_n_attr_changed_calls;
56725+atomic_unchecked_t fscache_n_attr_changed;
56726+atomic_unchecked_t fscache_n_attr_changed_ok;
56727+atomic_unchecked_t fscache_n_attr_changed_nobufs;
56728+atomic_unchecked_t fscache_n_attr_changed_nomem;
56729+atomic_unchecked_t fscache_n_attr_changed_calls;
56730
56731-atomic_t fscache_n_allocs;
56732-atomic_t fscache_n_allocs_ok;
56733-atomic_t fscache_n_allocs_wait;
56734-atomic_t fscache_n_allocs_nobufs;
56735-atomic_t fscache_n_allocs_intr;
56736-atomic_t fscache_n_allocs_object_dead;
56737-atomic_t fscache_n_alloc_ops;
56738-atomic_t fscache_n_alloc_op_waits;
56739+atomic_unchecked_t fscache_n_allocs;
56740+atomic_unchecked_t fscache_n_allocs_ok;
56741+atomic_unchecked_t fscache_n_allocs_wait;
56742+atomic_unchecked_t fscache_n_allocs_nobufs;
56743+atomic_unchecked_t fscache_n_allocs_intr;
56744+atomic_unchecked_t fscache_n_allocs_object_dead;
56745+atomic_unchecked_t fscache_n_alloc_ops;
56746+atomic_unchecked_t fscache_n_alloc_op_waits;
56747
56748-atomic_t fscache_n_retrievals;
56749-atomic_t fscache_n_retrievals_ok;
56750-atomic_t fscache_n_retrievals_wait;
56751-atomic_t fscache_n_retrievals_nodata;
56752-atomic_t fscache_n_retrievals_nobufs;
56753-atomic_t fscache_n_retrievals_intr;
56754-atomic_t fscache_n_retrievals_nomem;
56755-atomic_t fscache_n_retrievals_object_dead;
56756-atomic_t fscache_n_retrieval_ops;
56757-atomic_t fscache_n_retrieval_op_waits;
56758+atomic_unchecked_t fscache_n_retrievals;
56759+atomic_unchecked_t fscache_n_retrievals_ok;
56760+atomic_unchecked_t fscache_n_retrievals_wait;
56761+atomic_unchecked_t fscache_n_retrievals_nodata;
56762+atomic_unchecked_t fscache_n_retrievals_nobufs;
56763+atomic_unchecked_t fscache_n_retrievals_intr;
56764+atomic_unchecked_t fscache_n_retrievals_nomem;
56765+atomic_unchecked_t fscache_n_retrievals_object_dead;
56766+atomic_unchecked_t fscache_n_retrieval_ops;
56767+atomic_unchecked_t fscache_n_retrieval_op_waits;
56768
56769-atomic_t fscache_n_stores;
56770-atomic_t fscache_n_stores_ok;
56771-atomic_t fscache_n_stores_again;
56772-atomic_t fscache_n_stores_nobufs;
56773-atomic_t fscache_n_stores_oom;
56774-atomic_t fscache_n_store_ops;
56775-atomic_t fscache_n_store_calls;
56776-atomic_t fscache_n_store_pages;
56777-atomic_t fscache_n_store_radix_deletes;
56778-atomic_t fscache_n_store_pages_over_limit;
56779+atomic_unchecked_t fscache_n_stores;
56780+atomic_unchecked_t fscache_n_stores_ok;
56781+atomic_unchecked_t fscache_n_stores_again;
56782+atomic_unchecked_t fscache_n_stores_nobufs;
56783+atomic_unchecked_t fscache_n_stores_oom;
56784+atomic_unchecked_t fscache_n_store_ops;
56785+atomic_unchecked_t fscache_n_store_calls;
56786+atomic_unchecked_t fscache_n_store_pages;
56787+atomic_unchecked_t fscache_n_store_radix_deletes;
56788+atomic_unchecked_t fscache_n_store_pages_over_limit;
56789
56790-atomic_t fscache_n_store_vmscan_not_storing;
56791-atomic_t fscache_n_store_vmscan_gone;
56792-atomic_t fscache_n_store_vmscan_busy;
56793-atomic_t fscache_n_store_vmscan_cancelled;
56794-atomic_t fscache_n_store_vmscan_wait;
56795+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
56796+atomic_unchecked_t fscache_n_store_vmscan_gone;
56797+atomic_unchecked_t fscache_n_store_vmscan_busy;
56798+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
56799+atomic_unchecked_t fscache_n_store_vmscan_wait;
56800
56801-atomic_t fscache_n_marks;
56802-atomic_t fscache_n_uncaches;
56803+atomic_unchecked_t fscache_n_marks;
56804+atomic_unchecked_t fscache_n_uncaches;
56805
56806-atomic_t fscache_n_acquires;
56807-atomic_t fscache_n_acquires_null;
56808-atomic_t fscache_n_acquires_no_cache;
56809-atomic_t fscache_n_acquires_ok;
56810-atomic_t fscache_n_acquires_nobufs;
56811-atomic_t fscache_n_acquires_oom;
56812+atomic_unchecked_t fscache_n_acquires;
56813+atomic_unchecked_t fscache_n_acquires_null;
56814+atomic_unchecked_t fscache_n_acquires_no_cache;
56815+atomic_unchecked_t fscache_n_acquires_ok;
56816+atomic_unchecked_t fscache_n_acquires_nobufs;
56817+atomic_unchecked_t fscache_n_acquires_oom;
56818
56819-atomic_t fscache_n_invalidates;
56820-atomic_t fscache_n_invalidates_run;
56821+atomic_unchecked_t fscache_n_invalidates;
56822+atomic_unchecked_t fscache_n_invalidates_run;
56823
56824-atomic_t fscache_n_updates;
56825-atomic_t fscache_n_updates_null;
56826-atomic_t fscache_n_updates_run;
56827+atomic_unchecked_t fscache_n_updates;
56828+atomic_unchecked_t fscache_n_updates_null;
56829+atomic_unchecked_t fscache_n_updates_run;
56830
56831-atomic_t fscache_n_relinquishes;
56832-atomic_t fscache_n_relinquishes_null;
56833-atomic_t fscache_n_relinquishes_waitcrt;
56834-atomic_t fscache_n_relinquishes_retire;
56835+atomic_unchecked_t fscache_n_relinquishes;
56836+atomic_unchecked_t fscache_n_relinquishes_null;
56837+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
56838+atomic_unchecked_t fscache_n_relinquishes_retire;
56839
56840-atomic_t fscache_n_cookie_index;
56841-atomic_t fscache_n_cookie_data;
56842-atomic_t fscache_n_cookie_special;
56843+atomic_unchecked_t fscache_n_cookie_index;
56844+atomic_unchecked_t fscache_n_cookie_data;
56845+atomic_unchecked_t fscache_n_cookie_special;
56846
56847-atomic_t fscache_n_object_alloc;
56848-atomic_t fscache_n_object_no_alloc;
56849-atomic_t fscache_n_object_lookups;
56850-atomic_t fscache_n_object_lookups_negative;
56851-atomic_t fscache_n_object_lookups_positive;
56852-atomic_t fscache_n_object_lookups_timed_out;
56853-atomic_t fscache_n_object_created;
56854-atomic_t fscache_n_object_avail;
56855-atomic_t fscache_n_object_dead;
56856+atomic_unchecked_t fscache_n_object_alloc;
56857+atomic_unchecked_t fscache_n_object_no_alloc;
56858+atomic_unchecked_t fscache_n_object_lookups;
56859+atomic_unchecked_t fscache_n_object_lookups_negative;
56860+atomic_unchecked_t fscache_n_object_lookups_positive;
56861+atomic_unchecked_t fscache_n_object_lookups_timed_out;
56862+atomic_unchecked_t fscache_n_object_created;
56863+atomic_unchecked_t fscache_n_object_avail;
56864+atomic_unchecked_t fscache_n_object_dead;
56865
56866-atomic_t fscache_n_checkaux_none;
56867-atomic_t fscache_n_checkaux_okay;
56868-atomic_t fscache_n_checkaux_update;
56869-atomic_t fscache_n_checkaux_obsolete;
56870+atomic_unchecked_t fscache_n_checkaux_none;
56871+atomic_unchecked_t fscache_n_checkaux_okay;
56872+atomic_unchecked_t fscache_n_checkaux_update;
56873+atomic_unchecked_t fscache_n_checkaux_obsolete;
56874
56875 atomic_t fscache_n_cop_alloc_object;
56876 atomic_t fscache_n_cop_lookup_object;
56877@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
56878 seq_puts(m, "FS-Cache statistics\n");
56879
56880 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
56881- atomic_read(&fscache_n_cookie_index),
56882- atomic_read(&fscache_n_cookie_data),
56883- atomic_read(&fscache_n_cookie_special));
56884+ atomic_read_unchecked(&fscache_n_cookie_index),
56885+ atomic_read_unchecked(&fscache_n_cookie_data),
56886+ atomic_read_unchecked(&fscache_n_cookie_special));
56887
56888 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
56889- atomic_read(&fscache_n_object_alloc),
56890- atomic_read(&fscache_n_object_no_alloc),
56891- atomic_read(&fscache_n_object_avail),
56892- atomic_read(&fscache_n_object_dead));
56893+ atomic_read_unchecked(&fscache_n_object_alloc),
56894+ atomic_read_unchecked(&fscache_n_object_no_alloc),
56895+ atomic_read_unchecked(&fscache_n_object_avail),
56896+ atomic_read_unchecked(&fscache_n_object_dead));
56897 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
56898- atomic_read(&fscache_n_checkaux_none),
56899- atomic_read(&fscache_n_checkaux_okay),
56900- atomic_read(&fscache_n_checkaux_update),
56901- atomic_read(&fscache_n_checkaux_obsolete));
56902+ atomic_read_unchecked(&fscache_n_checkaux_none),
56903+ atomic_read_unchecked(&fscache_n_checkaux_okay),
56904+ atomic_read_unchecked(&fscache_n_checkaux_update),
56905+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
56906
56907 seq_printf(m, "Pages : mrk=%u unc=%u\n",
56908- atomic_read(&fscache_n_marks),
56909- atomic_read(&fscache_n_uncaches));
56910+ atomic_read_unchecked(&fscache_n_marks),
56911+ atomic_read_unchecked(&fscache_n_uncaches));
56912
56913 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
56914 " oom=%u\n",
56915- atomic_read(&fscache_n_acquires),
56916- atomic_read(&fscache_n_acquires_null),
56917- atomic_read(&fscache_n_acquires_no_cache),
56918- atomic_read(&fscache_n_acquires_ok),
56919- atomic_read(&fscache_n_acquires_nobufs),
56920- atomic_read(&fscache_n_acquires_oom));
56921+ atomic_read_unchecked(&fscache_n_acquires),
56922+ atomic_read_unchecked(&fscache_n_acquires_null),
56923+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
56924+ atomic_read_unchecked(&fscache_n_acquires_ok),
56925+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
56926+ atomic_read_unchecked(&fscache_n_acquires_oom));
56927
56928 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
56929- atomic_read(&fscache_n_object_lookups),
56930- atomic_read(&fscache_n_object_lookups_negative),
56931- atomic_read(&fscache_n_object_lookups_positive),
56932- atomic_read(&fscache_n_object_created),
56933- atomic_read(&fscache_n_object_lookups_timed_out));
56934+ atomic_read_unchecked(&fscache_n_object_lookups),
56935+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
56936+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
56937+ atomic_read_unchecked(&fscache_n_object_created),
56938+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
56939
56940 seq_printf(m, "Invals : n=%u run=%u\n",
56941- atomic_read(&fscache_n_invalidates),
56942- atomic_read(&fscache_n_invalidates_run));
56943+ atomic_read_unchecked(&fscache_n_invalidates),
56944+ atomic_read_unchecked(&fscache_n_invalidates_run));
56945
56946 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
56947- atomic_read(&fscache_n_updates),
56948- atomic_read(&fscache_n_updates_null),
56949- atomic_read(&fscache_n_updates_run));
56950+ atomic_read_unchecked(&fscache_n_updates),
56951+ atomic_read_unchecked(&fscache_n_updates_null),
56952+ atomic_read_unchecked(&fscache_n_updates_run));
56953
56954 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
56955- atomic_read(&fscache_n_relinquishes),
56956- atomic_read(&fscache_n_relinquishes_null),
56957- atomic_read(&fscache_n_relinquishes_waitcrt),
56958- atomic_read(&fscache_n_relinquishes_retire));
56959+ atomic_read_unchecked(&fscache_n_relinquishes),
56960+ atomic_read_unchecked(&fscache_n_relinquishes_null),
56961+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
56962+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
56963
56964 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
56965- atomic_read(&fscache_n_attr_changed),
56966- atomic_read(&fscache_n_attr_changed_ok),
56967- atomic_read(&fscache_n_attr_changed_nobufs),
56968- atomic_read(&fscache_n_attr_changed_nomem),
56969- atomic_read(&fscache_n_attr_changed_calls));
56970+ atomic_read_unchecked(&fscache_n_attr_changed),
56971+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
56972+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
56973+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
56974+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
56975
56976 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
56977- atomic_read(&fscache_n_allocs),
56978- atomic_read(&fscache_n_allocs_ok),
56979- atomic_read(&fscache_n_allocs_wait),
56980- atomic_read(&fscache_n_allocs_nobufs),
56981- atomic_read(&fscache_n_allocs_intr));
56982+ atomic_read_unchecked(&fscache_n_allocs),
56983+ atomic_read_unchecked(&fscache_n_allocs_ok),
56984+ atomic_read_unchecked(&fscache_n_allocs_wait),
56985+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
56986+ atomic_read_unchecked(&fscache_n_allocs_intr));
56987 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
56988- atomic_read(&fscache_n_alloc_ops),
56989- atomic_read(&fscache_n_alloc_op_waits),
56990- atomic_read(&fscache_n_allocs_object_dead));
56991+ atomic_read_unchecked(&fscache_n_alloc_ops),
56992+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
56993+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
56994
56995 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
56996 " int=%u oom=%u\n",
56997- atomic_read(&fscache_n_retrievals),
56998- atomic_read(&fscache_n_retrievals_ok),
56999- atomic_read(&fscache_n_retrievals_wait),
57000- atomic_read(&fscache_n_retrievals_nodata),
57001- atomic_read(&fscache_n_retrievals_nobufs),
57002- atomic_read(&fscache_n_retrievals_intr),
57003- atomic_read(&fscache_n_retrievals_nomem));
57004+ atomic_read_unchecked(&fscache_n_retrievals),
57005+ atomic_read_unchecked(&fscache_n_retrievals_ok),
57006+ atomic_read_unchecked(&fscache_n_retrievals_wait),
57007+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
57008+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
57009+ atomic_read_unchecked(&fscache_n_retrievals_intr),
57010+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
57011 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
57012- atomic_read(&fscache_n_retrieval_ops),
57013- atomic_read(&fscache_n_retrieval_op_waits),
57014- atomic_read(&fscache_n_retrievals_object_dead));
57015+ atomic_read_unchecked(&fscache_n_retrieval_ops),
57016+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
57017+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
57018
57019 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
57020- atomic_read(&fscache_n_stores),
57021- atomic_read(&fscache_n_stores_ok),
57022- atomic_read(&fscache_n_stores_again),
57023- atomic_read(&fscache_n_stores_nobufs),
57024- atomic_read(&fscache_n_stores_oom));
57025+ atomic_read_unchecked(&fscache_n_stores),
57026+ atomic_read_unchecked(&fscache_n_stores_ok),
57027+ atomic_read_unchecked(&fscache_n_stores_again),
57028+ atomic_read_unchecked(&fscache_n_stores_nobufs),
57029+ atomic_read_unchecked(&fscache_n_stores_oom));
57030 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
57031- atomic_read(&fscache_n_store_ops),
57032- atomic_read(&fscache_n_store_calls),
57033- atomic_read(&fscache_n_store_pages),
57034- atomic_read(&fscache_n_store_radix_deletes),
57035- atomic_read(&fscache_n_store_pages_over_limit));
57036+ atomic_read_unchecked(&fscache_n_store_ops),
57037+ atomic_read_unchecked(&fscache_n_store_calls),
57038+ atomic_read_unchecked(&fscache_n_store_pages),
57039+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
57040+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
57041
57042 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
57043- atomic_read(&fscache_n_store_vmscan_not_storing),
57044- atomic_read(&fscache_n_store_vmscan_gone),
57045- atomic_read(&fscache_n_store_vmscan_busy),
57046- atomic_read(&fscache_n_store_vmscan_cancelled),
57047- atomic_read(&fscache_n_store_vmscan_wait));
57048+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
57049+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
57050+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
57051+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
57052+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
57053
57054 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
57055- atomic_read(&fscache_n_op_pend),
57056- atomic_read(&fscache_n_op_run),
57057- atomic_read(&fscache_n_op_enqueue),
57058- atomic_read(&fscache_n_op_cancelled),
57059- atomic_read(&fscache_n_op_rejected));
57060+ atomic_read_unchecked(&fscache_n_op_pend),
57061+ atomic_read_unchecked(&fscache_n_op_run),
57062+ atomic_read_unchecked(&fscache_n_op_enqueue),
57063+ atomic_read_unchecked(&fscache_n_op_cancelled),
57064+ atomic_read_unchecked(&fscache_n_op_rejected));
57065 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
57066- atomic_read(&fscache_n_op_deferred_release),
57067- atomic_read(&fscache_n_op_release),
57068- atomic_read(&fscache_n_op_gc));
57069+ atomic_read_unchecked(&fscache_n_op_deferred_release),
57070+ atomic_read_unchecked(&fscache_n_op_release),
57071+ atomic_read_unchecked(&fscache_n_op_gc));
57072
57073 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
57074 atomic_read(&fscache_n_cop_alloc_object),
57075diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
57076index aef34b1..59bfd7b 100644
57077--- a/fs/fuse/cuse.c
57078+++ b/fs/fuse/cuse.c
57079@@ -600,10 +600,12 @@ static int __init cuse_init(void)
57080 INIT_LIST_HEAD(&cuse_conntbl[i]);
57081
57082 /* inherit and extend fuse_dev_operations */
57083- cuse_channel_fops = fuse_dev_operations;
57084- cuse_channel_fops.owner = THIS_MODULE;
57085- cuse_channel_fops.open = cuse_channel_open;
57086- cuse_channel_fops.release = cuse_channel_release;
57087+ pax_open_kernel();
57088+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
57089+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
57090+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
57091+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
57092+ pax_close_kernel();
57093
57094 cuse_class = class_create(THIS_MODULE, "cuse");
57095 if (IS_ERR(cuse_class))
57096diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
57097index 1d55f94..088da65 100644
57098--- a/fs/fuse/dev.c
57099+++ b/fs/fuse/dev.c
57100@@ -1339,7 +1339,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
57101 ret = 0;
57102 pipe_lock(pipe);
57103
57104- if (!pipe->readers) {
57105+ if (!atomic_read(&pipe->readers)) {
57106 send_sig(SIGPIPE, current, 0);
57107 if (!ret)
57108 ret = -EPIPE;
57109@@ -1364,7 +1364,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
57110 page_nr++;
57111 ret += buf->len;
57112
57113- if (pipe->files)
57114+ if (atomic_read(&pipe->files))
57115 do_wakeup = 1;
57116 }
57117
57118diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
57119index 8fec28f..cd40dba 100644
57120--- a/fs/fuse/dir.c
57121+++ b/fs/fuse/dir.c
57122@@ -1437,7 +1437,7 @@ static char *read_link(struct dentry *dentry)
57123 return link;
57124 }
57125
57126-static void free_link(char *link)
57127+static void free_link(const char *link)
57128 {
57129 if (!IS_ERR(link))
57130 free_page((unsigned long) link);
57131diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
57132index 64915ee..6bed500 100644
57133--- a/fs/gfs2/inode.c
57134+++ b/fs/gfs2/inode.c
57135@@ -1506,7 +1506,7 @@ out:
57136
57137 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
57138 {
57139- char *s = nd_get_link(nd);
57140+ const char *s = nd_get_link(nd);
57141 if (!IS_ERR(s))
57142 kfree(s);
57143 }
57144diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
57145index d19b30a..ef89c36 100644
57146--- a/fs/hugetlbfs/inode.c
57147+++ b/fs/hugetlbfs/inode.c
57148@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
57149 struct mm_struct *mm = current->mm;
57150 struct vm_area_struct *vma;
57151 struct hstate *h = hstate_file(file);
57152+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
57153 struct vm_unmapped_area_info info;
57154
57155 if (len & ~huge_page_mask(h))
57156@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
57157 return addr;
57158 }
57159
57160+#ifdef CONFIG_PAX_RANDMMAP
57161+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
57162+#endif
57163+
57164 if (addr) {
57165 addr = ALIGN(addr, huge_page_size(h));
57166 vma = find_vma(mm, addr);
57167- if (TASK_SIZE - len >= addr &&
57168- (!vma || addr + len <= vma->vm_start))
57169+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
57170 return addr;
57171 }
57172
57173 info.flags = 0;
57174 info.length = len;
57175 info.low_limit = TASK_UNMAPPED_BASE;
57176+
57177+#ifdef CONFIG_PAX_RANDMMAP
57178+ if (mm->pax_flags & MF_PAX_RANDMMAP)
57179+ info.low_limit += mm->delta_mmap;
57180+#endif
57181+
57182 info.high_limit = TASK_SIZE;
57183 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
57184 info.align_offset = 0;
57185@@ -908,7 +918,7 @@ static struct file_system_type hugetlbfs_fs_type = {
57186 };
57187 MODULE_ALIAS_FS("hugetlbfs");
57188
57189-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
57190+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
57191
57192 static int can_do_hugetlb_shm(void)
57193 {
57194diff --git a/fs/inode.c b/fs/inode.c
57195index d6dfb09..602e77e 100644
57196--- a/fs/inode.c
57197+++ b/fs/inode.c
57198@@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
57199
57200 #ifdef CONFIG_SMP
57201 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
57202- static atomic_t shared_last_ino;
57203- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
57204+ static atomic_unchecked_t shared_last_ino;
57205+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
57206
57207 res = next - LAST_INO_BATCH;
57208 }
57209diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
57210index 4a6cf28..d3a29d3 100644
57211--- a/fs/jffs2/erase.c
57212+++ b/fs/jffs2/erase.c
57213@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
57214 struct jffs2_unknown_node marker = {
57215 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
57216 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
57217- .totlen = cpu_to_je32(c->cleanmarker_size)
57218+ .totlen = cpu_to_je32(c->cleanmarker_size),
57219+ .hdr_crc = cpu_to_je32(0)
57220 };
57221
57222 jffs2_prealloc_raw_node_refs(c, jeb, 1);
57223diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
57224index a6597d6..41b30ec 100644
57225--- a/fs/jffs2/wbuf.c
57226+++ b/fs/jffs2/wbuf.c
57227@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
57228 {
57229 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
57230 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
57231- .totlen = constant_cpu_to_je32(8)
57232+ .totlen = constant_cpu_to_je32(8),
57233+ .hdr_crc = constant_cpu_to_je32(0)
57234 };
57235
57236 /*
57237diff --git a/fs/jfs/super.c b/fs/jfs/super.c
57238index 6669aa2..36b033d 100644
57239--- a/fs/jfs/super.c
57240+++ b/fs/jfs/super.c
57241@@ -882,7 +882,7 @@ static int __init init_jfs_fs(void)
57242
57243 jfs_inode_cachep =
57244 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
57245- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
57246+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
57247 init_once);
57248 if (jfs_inode_cachep == NULL)
57249 return -ENOMEM;
57250diff --git a/fs/libfs.c b/fs/libfs.c
57251index 3a3a9b5..3a9b074 100644
57252--- a/fs/libfs.c
57253+++ b/fs/libfs.c
57254@@ -150,6 +150,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
57255
57256 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
57257 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
57258+ char d_name[sizeof(next->d_iname)];
57259+ const unsigned char *name;
57260+
57261 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
57262 if (!simple_positive(next)) {
57263 spin_unlock(&next->d_lock);
57264@@ -158,7 +161,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
57265
57266 spin_unlock(&next->d_lock);
57267 spin_unlock(&dentry->d_lock);
57268- if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
57269+ name = next->d_name.name;
57270+ if (name == next->d_iname) {
57271+ memcpy(d_name, name, next->d_name.len);
57272+ name = d_name;
57273+ }
57274+ if (!dir_emit(ctx, name, next->d_name.len,
57275 next->d_inode->i_ino, dt_type(next->d_inode)))
57276 return 0;
57277 spin_lock(&dentry->d_lock);
57278diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
57279index acd3947..1f896e2 100644
57280--- a/fs/lockd/clntproc.c
57281+++ b/fs/lockd/clntproc.c
57282@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
57283 /*
57284 * Cookie counter for NLM requests
57285 */
57286-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
57287+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
57288
57289 void nlmclnt_next_cookie(struct nlm_cookie *c)
57290 {
57291- u32 cookie = atomic_inc_return(&nlm_cookie);
57292+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
57293
57294 memcpy(c->data, &cookie, 4);
57295 c->len=4;
57296diff --git a/fs/locks.c b/fs/locks.c
57297index b27a300..4156d0b 100644
57298--- a/fs/locks.c
57299+++ b/fs/locks.c
57300@@ -2183,16 +2183,16 @@ void locks_remove_flock(struct file *filp)
57301 return;
57302
57303 if (filp->f_op && filp->f_op->flock) {
57304- struct file_lock fl = {
57305+ struct file_lock flock = {
57306 .fl_pid = current->tgid,
57307 .fl_file = filp,
57308 .fl_flags = FL_FLOCK,
57309 .fl_type = F_UNLCK,
57310 .fl_end = OFFSET_MAX,
57311 };
57312- filp->f_op->flock(filp, F_SETLKW, &fl);
57313- if (fl.fl_ops && fl.fl_ops->fl_release_private)
57314- fl.fl_ops->fl_release_private(&fl);
57315+ filp->f_op->flock(filp, F_SETLKW, &flock);
57316+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
57317+ flock.fl_ops->fl_release_private(&flock);
57318 }
57319
57320 spin_lock(&inode->i_lock);
57321diff --git a/fs/namei.c b/fs/namei.c
57322index 7720fbd..7934bb2 100644
57323--- a/fs/namei.c
57324+++ b/fs/namei.c
57325@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
57326 if (ret != -EACCES)
57327 return ret;
57328
57329+#ifdef CONFIG_GRKERNSEC
57330+ /* we'll block if we have to log due to a denied capability use */
57331+ if (mask & MAY_NOT_BLOCK)
57332+ return -ECHILD;
57333+#endif
57334+
57335 if (S_ISDIR(inode->i_mode)) {
57336 /* DACs are overridable for directories */
57337- if (inode_capable(inode, CAP_DAC_OVERRIDE))
57338- return 0;
57339 if (!(mask & MAY_WRITE))
57340- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
57341+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
57342+ inode_capable(inode, CAP_DAC_READ_SEARCH))
57343 return 0;
57344+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
57345+ return 0;
57346 return -EACCES;
57347 }
57348 /*
57349+ * Searching includes executable on directories, else just read.
57350+ */
57351+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
57352+ if (mask == MAY_READ)
57353+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
57354+ inode_capable(inode, CAP_DAC_READ_SEARCH))
57355+ return 0;
57356+
57357+ /*
57358 * Read/write DACs are always overridable.
57359 * Executable DACs are overridable when there is
57360 * at least one exec bit set.
57361@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
57362 if (inode_capable(inode, CAP_DAC_OVERRIDE))
57363 return 0;
57364
57365- /*
57366- * Searching includes executable on directories, else just read.
57367- */
57368- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
57369- if (mask == MAY_READ)
57370- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
57371- return 0;
57372-
57373 return -EACCES;
57374 }
57375
57376@@ -820,7 +828,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
57377 {
57378 struct dentry *dentry = link->dentry;
57379 int error;
57380- char *s;
57381+ const char *s;
57382
57383 BUG_ON(nd->flags & LOOKUP_RCU);
57384
57385@@ -841,6 +849,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
57386 if (error)
57387 goto out_put_nd_path;
57388
57389+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
57390+ dentry->d_inode, dentry, nd->path.mnt)) {
57391+ error = -EACCES;
57392+ goto out_put_nd_path;
57393+ }
57394+
57395 nd->last_type = LAST_BIND;
57396 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
57397 error = PTR_ERR(*p);
57398@@ -1588,6 +1602,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
57399 if (res)
57400 break;
57401 res = walk_component(nd, path, LOOKUP_FOLLOW);
57402+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
57403+ res = -EACCES;
57404 put_link(nd, &link, cookie);
57405 } while (res > 0);
57406
57407@@ -1686,7 +1702,7 @@ EXPORT_SYMBOL(full_name_hash);
57408 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
57409 {
57410 unsigned long a, b, adata, bdata, mask, hash, len;
57411- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
57412+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
57413
57414 hash = a = 0;
57415 len = -sizeof(unsigned long);
57416@@ -1967,6 +1983,8 @@ static int path_lookupat(int dfd, const char *name,
57417 if (err)
57418 break;
57419 err = lookup_last(nd, &path);
57420+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
57421+ err = -EACCES;
57422 put_link(nd, &link, cookie);
57423 }
57424 }
57425@@ -1974,6 +1992,13 @@ static int path_lookupat(int dfd, const char *name,
57426 if (!err)
57427 err = complete_walk(nd);
57428
57429+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
57430+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
57431+ path_put(&nd->path);
57432+ err = -ENOENT;
57433+ }
57434+ }
57435+
57436 if (!err && nd->flags & LOOKUP_DIRECTORY) {
57437 if (!can_lookup(nd->inode)) {
57438 path_put(&nd->path);
57439@@ -2001,8 +2026,15 @@ static int filename_lookup(int dfd, struct filename *name,
57440 retval = path_lookupat(dfd, name->name,
57441 flags | LOOKUP_REVAL, nd);
57442
57443- if (likely(!retval))
57444+ if (likely(!retval)) {
57445 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
57446+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
57447+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
57448+ path_put(&nd->path);
57449+ return -ENOENT;
57450+ }
57451+ }
57452+ }
57453 return retval;
57454 }
57455
57456@@ -2380,6 +2412,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
57457 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
57458 return -EPERM;
57459
57460+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
57461+ return -EPERM;
57462+ if (gr_handle_rawio(inode))
57463+ return -EPERM;
57464+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
57465+ return -EACCES;
57466+
57467 return 0;
57468 }
57469
57470@@ -2601,7 +2640,7 @@ looked_up:
57471 * cleared otherwise prior to returning.
57472 */
57473 static int lookup_open(struct nameidata *nd, struct path *path,
57474- struct file *file,
57475+ struct path *link, struct file *file,
57476 const struct open_flags *op,
57477 bool got_write, int *opened)
57478 {
57479@@ -2636,6 +2675,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
57480 /* Negative dentry, just create the file */
57481 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
57482 umode_t mode = op->mode;
57483+
57484+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
57485+ error = -EACCES;
57486+ goto out_dput;
57487+ }
57488+
57489+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
57490+ error = -EACCES;
57491+ goto out_dput;
57492+ }
57493+
57494 if (!IS_POSIXACL(dir->d_inode))
57495 mode &= ~current_umask();
57496 /*
57497@@ -2657,6 +2707,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
57498 nd->flags & LOOKUP_EXCL);
57499 if (error)
57500 goto out_dput;
57501+ else
57502+ gr_handle_create(dentry, nd->path.mnt);
57503 }
57504 out_no_open:
57505 path->dentry = dentry;
57506@@ -2671,7 +2723,7 @@ out_dput:
57507 /*
57508 * Handle the last step of open()
57509 */
57510-static int do_last(struct nameidata *nd, struct path *path,
57511+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
57512 struct file *file, const struct open_flags *op,
57513 int *opened, struct filename *name)
57514 {
57515@@ -2721,6 +2773,15 @@ static int do_last(struct nameidata *nd, struct path *path,
57516 if (error)
57517 return error;
57518
57519+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
57520+ error = -ENOENT;
57521+ goto out;
57522+ }
57523+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
57524+ error = -EACCES;
57525+ goto out;
57526+ }
57527+
57528 audit_inode(name, dir, LOOKUP_PARENT);
57529 error = -EISDIR;
57530 /* trailing slashes? */
57531@@ -2740,7 +2801,7 @@ retry_lookup:
57532 */
57533 }
57534 mutex_lock(&dir->d_inode->i_mutex);
57535- error = lookup_open(nd, path, file, op, got_write, opened);
57536+ error = lookup_open(nd, path, link, file, op, got_write, opened);
57537 mutex_unlock(&dir->d_inode->i_mutex);
57538
57539 if (error <= 0) {
57540@@ -2764,11 +2825,28 @@ retry_lookup:
57541 goto finish_open_created;
57542 }
57543
57544+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
57545+ error = -ENOENT;
57546+ goto exit_dput;
57547+ }
57548+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
57549+ error = -EACCES;
57550+ goto exit_dput;
57551+ }
57552+
57553 /*
57554 * create/update audit record if it already exists.
57555 */
57556- if (path->dentry->d_inode)
57557+ if (path->dentry->d_inode) {
57558+ /* only check if O_CREAT is specified, all other checks need to go
57559+ into may_open */
57560+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
57561+ error = -EACCES;
57562+ goto exit_dput;
57563+ }
57564+
57565 audit_inode(name, path->dentry, 0);
57566+ }
57567
57568 /*
57569 * If atomic_open() acquired write access it is dropped now due to
57570@@ -2809,6 +2887,11 @@ finish_lookup:
57571 }
57572 }
57573 BUG_ON(inode != path->dentry->d_inode);
57574+ /* if we're resolving a symlink to another symlink */
57575+ if (link && gr_handle_symlink_owner(link, inode)) {
57576+ error = -EACCES;
57577+ goto out;
57578+ }
57579 return 1;
57580 }
57581
57582@@ -2818,7 +2901,6 @@ finish_lookup:
57583 save_parent.dentry = nd->path.dentry;
57584 save_parent.mnt = mntget(path->mnt);
57585 nd->path.dentry = path->dentry;
57586-
57587 }
57588 nd->inode = inode;
57589 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
57590@@ -2828,7 +2910,18 @@ finish_open:
57591 path_put(&save_parent);
57592 return error;
57593 }
57594+
57595+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
57596+ error = -ENOENT;
57597+ goto out;
57598+ }
57599+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
57600+ error = -EACCES;
57601+ goto out;
57602+ }
57603+
57604 audit_inode(name, nd->path.dentry, 0);
57605+
57606 error = -EISDIR;
57607 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
57608 goto out;
57609@@ -2991,7 +3084,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
57610 if (unlikely(error))
57611 goto out;
57612
57613- error = do_last(nd, &path, file, op, &opened, pathname);
57614+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
57615 while (unlikely(error > 0)) { /* trailing symlink */
57616 struct path link = path;
57617 void *cookie;
57618@@ -3009,7 +3102,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
57619 error = follow_link(&link, nd, &cookie);
57620 if (unlikely(error))
57621 break;
57622- error = do_last(nd, &path, file, op, &opened, pathname);
57623+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
57624 put_link(nd, &link, cookie);
57625 }
57626 out:
57627@@ -3109,8 +3202,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
57628 goto unlock;
57629
57630 error = -EEXIST;
57631- if (dentry->d_inode)
57632+ if (dentry->d_inode) {
57633+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
57634+ error = -ENOENT;
57635+ }
57636 goto fail;
57637+ }
57638 /*
57639 * Special case - lookup gave negative, but... we had foo/bar/
57640 * From the vfs_mknod() POV we just have a negative dentry -
57641@@ -3162,6 +3259,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
57642 }
57643 EXPORT_SYMBOL(user_path_create);
57644
57645+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
57646+{
57647+ struct filename *tmp = getname(pathname);
57648+ struct dentry *res;
57649+ if (IS_ERR(tmp))
57650+ return ERR_CAST(tmp);
57651+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
57652+ if (IS_ERR(res))
57653+ putname(tmp);
57654+ else
57655+ *to = tmp;
57656+ return res;
57657+}
57658+
57659 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
57660 {
57661 int error = may_create(dir, dentry);
57662@@ -3224,6 +3335,17 @@ retry:
57663
57664 if (!IS_POSIXACL(path.dentry->d_inode))
57665 mode &= ~current_umask();
57666+
57667+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
57668+ error = -EPERM;
57669+ goto out;
57670+ }
57671+
57672+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
57673+ error = -EACCES;
57674+ goto out;
57675+ }
57676+
57677 error = security_path_mknod(&path, dentry, mode, dev);
57678 if (error)
57679 goto out;
57680@@ -3240,6 +3362,8 @@ retry:
57681 break;
57682 }
57683 out:
57684+ if (!error)
57685+ gr_handle_create(dentry, path.mnt);
57686 done_path_create(&path, dentry);
57687 if (retry_estale(error, lookup_flags)) {
57688 lookup_flags |= LOOKUP_REVAL;
57689@@ -3292,9 +3416,16 @@ retry:
57690
57691 if (!IS_POSIXACL(path.dentry->d_inode))
57692 mode &= ~current_umask();
57693+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
57694+ error = -EACCES;
57695+ goto out;
57696+ }
57697 error = security_path_mkdir(&path, dentry, mode);
57698 if (!error)
57699 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
57700+ if (!error)
57701+ gr_handle_create(dentry, path.mnt);
57702+out:
57703 done_path_create(&path, dentry);
57704 if (retry_estale(error, lookup_flags)) {
57705 lookup_flags |= LOOKUP_REVAL;
57706@@ -3375,6 +3506,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
57707 struct filename *name;
57708 struct dentry *dentry;
57709 struct nameidata nd;
57710+ ino_t saved_ino = 0;
57711+ dev_t saved_dev = 0;
57712 unsigned int lookup_flags = 0;
57713 retry:
57714 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
57715@@ -3407,10 +3540,21 @@ retry:
57716 error = -ENOENT;
57717 goto exit3;
57718 }
57719+
57720+ saved_ino = dentry->d_inode->i_ino;
57721+ saved_dev = gr_get_dev_from_dentry(dentry);
57722+
57723+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
57724+ error = -EACCES;
57725+ goto exit3;
57726+ }
57727+
57728 error = security_path_rmdir(&nd.path, dentry);
57729 if (error)
57730 goto exit3;
57731 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
57732+ if (!error && (saved_dev || saved_ino))
57733+ gr_handle_delete(saved_ino, saved_dev);
57734 exit3:
57735 dput(dentry);
57736 exit2:
57737@@ -3476,6 +3620,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
57738 struct dentry *dentry;
57739 struct nameidata nd;
57740 struct inode *inode = NULL;
57741+ ino_t saved_ino = 0;
57742+ dev_t saved_dev = 0;
57743 unsigned int lookup_flags = 0;
57744 retry:
57745 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
57746@@ -3502,10 +3648,22 @@ retry:
57747 if (!inode)
57748 goto slashes;
57749 ihold(inode);
57750+
57751+ if (inode->i_nlink <= 1) {
57752+ saved_ino = inode->i_ino;
57753+ saved_dev = gr_get_dev_from_dentry(dentry);
57754+ }
57755+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
57756+ error = -EACCES;
57757+ goto exit2;
57758+ }
57759+
57760 error = security_path_unlink(&nd.path, dentry);
57761 if (error)
57762 goto exit2;
57763 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
57764+ if (!error && (saved_ino || saved_dev))
57765+ gr_handle_delete(saved_ino, saved_dev);
57766 exit2:
57767 dput(dentry);
57768 }
57769@@ -3583,9 +3741,17 @@ retry:
57770 if (IS_ERR(dentry))
57771 goto out_putname;
57772
57773+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
57774+ error = -EACCES;
57775+ goto out;
57776+ }
57777+
57778 error = security_path_symlink(&path, dentry, from->name);
57779 if (!error)
57780 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
57781+ if (!error)
57782+ gr_handle_create(dentry, path.mnt);
57783+out:
57784 done_path_create(&path, dentry);
57785 if (retry_estale(error, lookup_flags)) {
57786 lookup_flags |= LOOKUP_REVAL;
57787@@ -3665,6 +3831,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
57788 {
57789 struct dentry *new_dentry;
57790 struct path old_path, new_path;
57791+ struct filename *to = NULL;
57792 int how = 0;
57793 int error;
57794
57795@@ -3688,7 +3855,7 @@ retry:
57796 if (error)
57797 return error;
57798
57799- new_dentry = user_path_create(newdfd, newname, &new_path,
57800+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
57801 (how & LOOKUP_REVAL));
57802 error = PTR_ERR(new_dentry);
57803 if (IS_ERR(new_dentry))
57804@@ -3700,11 +3867,28 @@ retry:
57805 error = may_linkat(&old_path);
57806 if (unlikely(error))
57807 goto out_dput;
57808+
57809+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
57810+ old_path.dentry->d_inode,
57811+ old_path.dentry->d_inode->i_mode, to)) {
57812+ error = -EACCES;
57813+ goto out_dput;
57814+ }
57815+
57816+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
57817+ old_path.dentry, old_path.mnt, to)) {
57818+ error = -EACCES;
57819+ goto out_dput;
57820+ }
57821+
57822 error = security_path_link(old_path.dentry, &new_path, new_dentry);
57823 if (error)
57824 goto out_dput;
57825 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
57826+ if (!error)
57827+ gr_handle_create(new_dentry, new_path.mnt);
57828 out_dput:
57829+ putname(to);
57830 done_path_create(&new_path, new_dentry);
57831 if (retry_estale(error, how)) {
57832 how |= LOOKUP_REVAL;
57833@@ -3950,12 +4134,21 @@ retry:
57834 if (new_dentry == trap)
57835 goto exit5;
57836
57837+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
57838+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
57839+ to);
57840+ if (error)
57841+ goto exit5;
57842+
57843 error = security_path_rename(&oldnd.path, old_dentry,
57844 &newnd.path, new_dentry);
57845 if (error)
57846 goto exit5;
57847 error = vfs_rename(old_dir->d_inode, old_dentry,
57848 new_dir->d_inode, new_dentry);
57849+ if (!error)
57850+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
57851+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
57852 exit5:
57853 dput(new_dentry);
57854 exit4:
57855@@ -3987,6 +4180,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
57856
57857 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
57858 {
57859+ char tmpbuf[64];
57860+ const char *newlink;
57861 int len;
57862
57863 len = PTR_ERR(link);
57864@@ -3996,7 +4191,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
57865 len = strlen(link);
57866 if (len > (unsigned) buflen)
57867 len = buflen;
57868- if (copy_to_user(buffer, link, len))
57869+
57870+ if (len < sizeof(tmpbuf)) {
57871+ memcpy(tmpbuf, link, len);
57872+ newlink = tmpbuf;
57873+ } else
57874+ newlink = link;
57875+
57876+ if (copy_to_user(buffer, newlink, len))
57877 len = -EFAULT;
57878 out:
57879 return len;
57880diff --git a/fs/namespace.c b/fs/namespace.c
57881index a45ba4f..b4c7d07 100644
57882--- a/fs/namespace.c
57883+++ b/fs/namespace.c
57884@@ -1265,6 +1265,9 @@ static int do_umount(struct mount *mnt, int flags)
57885 if (!(sb->s_flags & MS_RDONLY))
57886 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
57887 up_write(&sb->s_umount);
57888+
57889+ gr_log_remount(mnt->mnt_devname, retval);
57890+
57891 return retval;
57892 }
57893
57894@@ -1283,6 +1286,9 @@ static int do_umount(struct mount *mnt, int flags)
57895 }
57896 br_write_unlock(&vfsmount_lock);
57897 namespace_unlock();
57898+
57899+ gr_log_unmount(mnt->mnt_devname, retval);
57900+
57901 return retval;
57902 }
57903
57904@@ -1302,7 +1308,7 @@ static inline bool may_mount(void)
57905 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
57906 */
57907
57908-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
57909+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
57910 {
57911 struct path path;
57912 struct mount *mnt;
57913@@ -1342,7 +1348,7 @@ out:
57914 /*
57915 * The 2.0 compatible umount. No flags.
57916 */
57917-SYSCALL_DEFINE1(oldumount, char __user *, name)
57918+SYSCALL_DEFINE1(oldumount, const char __user *, name)
57919 {
57920 return sys_umount(name, 0);
57921 }
57922@@ -2313,6 +2319,16 @@ long do_mount(const char *dev_name, const char *dir_name,
57923 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
57924 MS_STRICTATIME);
57925
57926+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
57927+ retval = -EPERM;
57928+ goto dput_out;
57929+ }
57930+
57931+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
57932+ retval = -EPERM;
57933+ goto dput_out;
57934+ }
57935+
57936 if (flags & MS_REMOUNT)
57937 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
57938 data_page);
57939@@ -2327,6 +2343,9 @@ long do_mount(const char *dev_name, const char *dir_name,
57940 dev_name, data_page);
57941 dput_out:
57942 path_put(&path);
57943+
57944+ gr_log_mount(dev_name, dir_name, retval);
57945+
57946 return retval;
57947 }
57948
57949@@ -2344,7 +2363,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
57950 * number incrementing at 10Ghz will take 12,427 years to wrap which
57951 * is effectively never, so we can ignore the possibility.
57952 */
57953-static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
57954+static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
57955
57956 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
57957 {
57958@@ -2359,7 +2378,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
57959 kfree(new_ns);
57960 return ERR_PTR(ret);
57961 }
57962- new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
57963+ new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
57964 atomic_set(&new_ns->count, 1);
57965 new_ns->root = NULL;
57966 INIT_LIST_HEAD(&new_ns->list);
57967@@ -2373,7 +2392,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
57968 * Allocate a new namespace structure and populate it with contents
57969 * copied from the namespace of the passed in task structure.
57970 */
57971-static struct mnt_namespace *dup_mnt_ns(struct mnt_namespace *mnt_ns,
57972+static __latent_entropy struct mnt_namespace *dup_mnt_ns(struct mnt_namespace *mnt_ns,
57973 struct user_namespace *user_ns, struct fs_struct *fs)
57974 {
57975 struct mnt_namespace *new_ns;
57976@@ -2500,8 +2519,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
57977 }
57978 EXPORT_SYMBOL(mount_subtree);
57979
57980-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
57981- char __user *, type, unsigned long, flags, void __user *, data)
57982+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
57983+ const char __user *, type, unsigned long, flags, void __user *, data)
57984 {
57985 int ret;
57986 char *kernel_type;
57987@@ -2614,6 +2633,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
57988 if (error)
57989 goto out2;
57990
57991+ if (gr_handle_chroot_pivot()) {
57992+ error = -EPERM;
57993+ goto out2;
57994+ }
57995+
57996 get_fs_root(current->fs, &root);
57997 old_mp = lock_mount(&old);
57998 error = PTR_ERR(old_mp);
57999@@ -2864,7 +2888,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
58000 !nsown_capable(CAP_SYS_ADMIN))
58001 return -EPERM;
58002
58003- if (fs->users != 1)
58004+ if (atomic_read(&fs->users) != 1)
58005 return -EINVAL;
58006
58007 get_mnt_ns(mnt_ns);
58008diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
58009index f4ccfe6..a5cf064 100644
58010--- a/fs/nfs/callback_xdr.c
58011+++ b/fs/nfs/callback_xdr.c
58012@@ -51,7 +51,7 @@ struct callback_op {
58013 callback_decode_arg_t decode_args;
58014 callback_encode_res_t encode_res;
58015 long res_maxsize;
58016-};
58017+} __do_const;
58018
58019 static struct callback_op callback_ops[];
58020
58021diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
58022index 941246f..17d8724 100644
58023--- a/fs/nfs/inode.c
58024+++ b/fs/nfs/inode.c
58025@@ -1138,16 +1138,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
58026 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
58027 }
58028
58029-static atomic_long_t nfs_attr_generation_counter;
58030+static atomic_long_unchecked_t nfs_attr_generation_counter;
58031
58032 static unsigned long nfs_read_attr_generation_counter(void)
58033 {
58034- return atomic_long_read(&nfs_attr_generation_counter);
58035+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
58036 }
58037
58038 unsigned long nfs_inc_attr_generation_counter(void)
58039 {
58040- return atomic_long_inc_return(&nfs_attr_generation_counter);
58041+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
58042 }
58043
58044 void nfs_fattr_init(struct nfs_fattr *fattr)
58045diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
58046index 419572f..5414a23 100644
58047--- a/fs/nfsd/nfs4proc.c
58048+++ b/fs/nfsd/nfs4proc.c
58049@@ -1168,7 +1168,7 @@ struct nfsd4_operation {
58050 nfsd4op_rsize op_rsize_bop;
58051 stateid_getter op_get_currentstateid;
58052 stateid_setter op_set_currentstateid;
58053-};
58054+} __do_const;
58055
58056 static struct nfsd4_operation nfsd4_ops[];
58057
58058diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
58059index c2a4701..fd80e29 100644
58060--- a/fs/nfsd/nfs4xdr.c
58061+++ b/fs/nfsd/nfs4xdr.c
58062@@ -1498,7 +1498,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
58063
58064 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
58065
58066-static nfsd4_dec nfsd4_dec_ops[] = {
58067+static const nfsd4_dec nfsd4_dec_ops[] = {
58068 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
58069 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
58070 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
58071@@ -1538,7 +1538,7 @@ static nfsd4_dec nfsd4_dec_ops[] = {
58072 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
58073 };
58074
58075-static nfsd4_dec nfsd41_dec_ops[] = {
58076+static const nfsd4_dec nfsd41_dec_ops[] = {
58077 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
58078 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
58079 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
58080@@ -1600,7 +1600,7 @@ static nfsd4_dec nfsd41_dec_ops[] = {
58081 };
58082
58083 struct nfsd4_minorversion_ops {
58084- nfsd4_dec *decoders;
58085+ const nfsd4_dec *decoders;
58086 int nops;
58087 };
58088
58089diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
58090index e76244e..9fe8f2f1 100644
58091--- a/fs/nfsd/nfscache.c
58092+++ b/fs/nfsd/nfscache.c
58093@@ -526,14 +526,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
58094 {
58095 struct svc_cacherep *rp = rqstp->rq_cacherep;
58096 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
58097- int len;
58098+ long len;
58099 size_t bufsize = 0;
58100
58101 if (!rp)
58102 return;
58103
58104- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
58105- len >>= 2;
58106+ if (statp) {
58107+ len = (char*)statp - (char*)resv->iov_base;
58108+ len = resv->iov_len - len;
58109+ len >>= 2;
58110+ }
58111
58112 /* Don't cache excessive amounts of data and XDR failures */
58113 if (!statp || len > (256 >> 2)) {
58114diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
58115index c827acb..b253b77 100644
58116--- a/fs/nfsd/vfs.c
58117+++ b/fs/nfsd/vfs.c
58118@@ -968,7 +968,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
58119 } else {
58120 oldfs = get_fs();
58121 set_fs(KERNEL_DS);
58122- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
58123+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
58124 set_fs(oldfs);
58125 }
58126
58127@@ -1055,7 +1055,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
58128
58129 /* Write the data. */
58130 oldfs = get_fs(); set_fs(KERNEL_DS);
58131- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
58132+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
58133 set_fs(oldfs);
58134 if (host_err < 0)
58135 goto out_nfserr;
58136@@ -1601,7 +1601,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
58137 */
58138
58139 oldfs = get_fs(); set_fs(KERNEL_DS);
58140- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
58141+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
58142 set_fs(oldfs);
58143
58144 if (host_err < 0)
58145diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
58146index fea6bd5..8ee9d81 100644
58147--- a/fs/nls/nls_base.c
58148+++ b/fs/nls/nls_base.c
58149@@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
58150
58151 int register_nls(struct nls_table * nls)
58152 {
58153- struct nls_table ** tmp = &tables;
58154+ struct nls_table *tmp = tables;
58155
58156 if (nls->next)
58157 return -EBUSY;
58158
58159 spin_lock(&nls_lock);
58160- while (*tmp) {
58161- if (nls == *tmp) {
58162+ while (tmp) {
58163+ if (nls == tmp) {
58164 spin_unlock(&nls_lock);
58165 return -EBUSY;
58166 }
58167- tmp = &(*tmp)->next;
58168+ tmp = tmp->next;
58169 }
58170- nls->next = tables;
58171+ pax_open_kernel();
58172+ *(struct nls_table **)&nls->next = tables;
58173+ pax_close_kernel();
58174 tables = nls;
58175 spin_unlock(&nls_lock);
58176 return 0;
58177@@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
58178
58179 int unregister_nls(struct nls_table * nls)
58180 {
58181- struct nls_table ** tmp = &tables;
58182+ struct nls_table * const * tmp = &tables;
58183
58184 spin_lock(&nls_lock);
58185 while (*tmp) {
58186 if (nls == *tmp) {
58187- *tmp = nls->next;
58188+ pax_open_kernel();
58189+ *(struct nls_table **)tmp = nls->next;
58190+ pax_close_kernel();
58191 spin_unlock(&nls_lock);
58192 return 0;
58193 }
58194diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
58195index 7424929..35f6be5 100644
58196--- a/fs/nls/nls_euc-jp.c
58197+++ b/fs/nls/nls_euc-jp.c
58198@@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
58199 p_nls = load_nls("cp932");
58200
58201 if (p_nls) {
58202- table.charset2upper = p_nls->charset2upper;
58203- table.charset2lower = p_nls->charset2lower;
58204+ pax_open_kernel();
58205+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
58206+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
58207+ pax_close_kernel();
58208 return register_nls(&table);
58209 }
58210
58211diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
58212index e7bc1d7..06bd4bb 100644
58213--- a/fs/nls/nls_koi8-ru.c
58214+++ b/fs/nls/nls_koi8-ru.c
58215@@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
58216 p_nls = load_nls("koi8-u");
58217
58218 if (p_nls) {
58219- table.charset2upper = p_nls->charset2upper;
58220- table.charset2lower = p_nls->charset2lower;
58221+ pax_open_kernel();
58222+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
58223+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
58224+ pax_close_kernel();
58225 return register_nls(&table);
58226 }
58227
58228diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
58229index e44cb64..4807084 100644
58230--- a/fs/notify/fanotify/fanotify_user.c
58231+++ b/fs/notify/fanotify/fanotify_user.c
58232@@ -253,8 +253,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
58233
58234 fd = fanotify_event_metadata.fd;
58235 ret = -EFAULT;
58236- if (copy_to_user(buf, &fanotify_event_metadata,
58237- fanotify_event_metadata.event_len))
58238+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
58239+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
58240 goto out_close_fd;
58241
58242 ret = prepare_for_access_response(group, event, fd);
58243diff --git a/fs/notify/notification.c b/fs/notify/notification.c
58244index 7b51b05..5ea5ef6 100644
58245--- a/fs/notify/notification.c
58246+++ b/fs/notify/notification.c
58247@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
58248 * get set to 0 so it will never get 'freed'
58249 */
58250 static struct fsnotify_event *q_overflow_event;
58251-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
58252+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
58253
58254 /**
58255 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
58256@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
58257 */
58258 u32 fsnotify_get_cookie(void)
58259 {
58260- return atomic_inc_return(&fsnotify_sync_cookie);
58261+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
58262 }
58263 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
58264
58265diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
58266index 9e38daf..5727cae 100644
58267--- a/fs/ntfs/dir.c
58268+++ b/fs/ntfs/dir.c
58269@@ -1310,7 +1310,7 @@ find_next_index_buffer:
58270 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
58271 ~(s64)(ndir->itype.index.block_size - 1)));
58272 /* Bounds checks. */
58273- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
58274+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
58275 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
58276 "inode 0x%lx or driver bug.", vdir->i_ino);
58277 goto err_out;
58278diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
58279index c5670b8..d590213 100644
58280--- a/fs/ntfs/file.c
58281+++ b/fs/ntfs/file.c
58282@@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
58283 char *addr;
58284 size_t total = 0;
58285 unsigned len;
58286- int left;
58287+ unsigned left;
58288
58289 do {
58290 len = PAGE_CACHE_SIZE - ofs;
58291diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
58292index 82650d5..db37dcf 100644
58293--- a/fs/ntfs/super.c
58294+++ b/fs/ntfs/super.c
58295@@ -685,7 +685,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
58296 if (!silent)
58297 ntfs_error(sb, "Primary boot sector is invalid.");
58298 } else if (!silent)
58299- ntfs_error(sb, read_err_str, "primary");
58300+ ntfs_error(sb, read_err_str, "%s", "primary");
58301 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
58302 if (bh_primary)
58303 brelse(bh_primary);
58304@@ -701,7 +701,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
58305 goto hotfix_primary_boot_sector;
58306 brelse(bh_backup);
58307 } else if (!silent)
58308- ntfs_error(sb, read_err_str, "backup");
58309+ ntfs_error(sb, read_err_str, "%s", "backup");
58310 /* Try to read NT3.51- backup boot sector. */
58311 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
58312 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
58313@@ -712,7 +712,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
58314 "sector.");
58315 brelse(bh_backup);
58316 } else if (!silent)
58317- ntfs_error(sb, read_err_str, "backup");
58318+ ntfs_error(sb, read_err_str, "%s", "backup");
58319 /* We failed. Cleanup and return. */
58320 if (bh_primary)
58321 brelse(bh_primary);
58322diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
58323index aebeacd..0dcdd26 100644
58324--- a/fs/ocfs2/localalloc.c
58325+++ b/fs/ocfs2/localalloc.c
58326@@ -1278,7 +1278,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
58327 goto bail;
58328 }
58329
58330- atomic_inc(&osb->alloc_stats.moves);
58331+ atomic_inc_unchecked(&osb->alloc_stats.moves);
58332
58333 bail:
58334 if (handle)
58335diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
58336index 3a90347..c40bef8 100644
58337--- a/fs/ocfs2/ocfs2.h
58338+++ b/fs/ocfs2/ocfs2.h
58339@@ -235,11 +235,11 @@ enum ocfs2_vol_state
58340
58341 struct ocfs2_alloc_stats
58342 {
58343- atomic_t moves;
58344- atomic_t local_data;
58345- atomic_t bitmap_data;
58346- atomic_t bg_allocs;
58347- atomic_t bg_extends;
58348+ atomic_unchecked_t moves;
58349+ atomic_unchecked_t local_data;
58350+ atomic_unchecked_t bitmap_data;
58351+ atomic_unchecked_t bg_allocs;
58352+ atomic_unchecked_t bg_extends;
58353 };
58354
58355 enum ocfs2_local_alloc_state
58356diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
58357index 5397c07..54afc55 100644
58358--- a/fs/ocfs2/suballoc.c
58359+++ b/fs/ocfs2/suballoc.c
58360@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
58361 mlog_errno(status);
58362 goto bail;
58363 }
58364- atomic_inc(&osb->alloc_stats.bg_extends);
58365+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
58366
58367 /* You should never ask for this much metadata */
58368 BUG_ON(bits_wanted >
58369@@ -2000,7 +2000,7 @@ int ocfs2_claim_metadata(handle_t *handle,
58370 mlog_errno(status);
58371 goto bail;
58372 }
58373- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58374+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58375
58376 *suballoc_loc = res.sr_bg_blkno;
58377 *suballoc_bit_start = res.sr_bit_offset;
58378@@ -2164,7 +2164,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
58379 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
58380 res->sr_bits);
58381
58382- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58383+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58384
58385 BUG_ON(res->sr_bits != 1);
58386
58387@@ -2206,7 +2206,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
58388 mlog_errno(status);
58389 goto bail;
58390 }
58391- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58392+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58393
58394 BUG_ON(res.sr_bits != 1);
58395
58396@@ -2310,7 +2310,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
58397 cluster_start,
58398 num_clusters);
58399 if (!status)
58400- atomic_inc(&osb->alloc_stats.local_data);
58401+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
58402 } else {
58403 if (min_clusters > (osb->bitmap_cpg - 1)) {
58404 /* The only paths asking for contiguousness
58405@@ -2336,7 +2336,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
58406 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
58407 res.sr_bg_blkno,
58408 res.sr_bit_offset);
58409- atomic_inc(&osb->alloc_stats.bitmap_data);
58410+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
58411 *num_clusters = res.sr_bits;
58412 }
58413 }
58414diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
58415index 121da2d..a0232bc 100644
58416--- a/fs/ocfs2/super.c
58417+++ b/fs/ocfs2/super.c
58418@@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
58419 "%10s => GlobalAllocs: %d LocalAllocs: %d "
58420 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
58421 "Stats",
58422- atomic_read(&osb->alloc_stats.bitmap_data),
58423- atomic_read(&osb->alloc_stats.local_data),
58424- atomic_read(&osb->alloc_stats.bg_allocs),
58425- atomic_read(&osb->alloc_stats.moves),
58426- atomic_read(&osb->alloc_stats.bg_extends));
58427+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
58428+ atomic_read_unchecked(&osb->alloc_stats.local_data),
58429+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
58430+ atomic_read_unchecked(&osb->alloc_stats.moves),
58431+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
58432
58433 out += snprintf(buf + out, len - out,
58434 "%10s => State: %u Descriptor: %llu Size: %u bits "
58435@@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
58436 spin_lock_init(&osb->osb_xattr_lock);
58437 ocfs2_init_steal_slots(osb);
58438
58439- atomic_set(&osb->alloc_stats.moves, 0);
58440- atomic_set(&osb->alloc_stats.local_data, 0);
58441- atomic_set(&osb->alloc_stats.bitmap_data, 0);
58442- atomic_set(&osb->alloc_stats.bg_allocs, 0);
58443- atomic_set(&osb->alloc_stats.bg_extends, 0);
58444+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
58445+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
58446+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
58447+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
58448+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
58449
58450 /* Copy the blockcheck stats from the superblock probe */
58451 osb->osb_ecc_stats = *stats;
58452diff --git a/fs/open.c b/fs/open.c
58453index 7931f76..7b03f3b 100644
58454--- a/fs/open.c
58455+++ b/fs/open.c
58456@@ -32,6 +32,8 @@
58457 #include <linux/dnotify.h>
58458 #include <linux/compat.h>
58459
58460+#define CREATE_TRACE_POINTS
58461+#include <trace/events/fs.h>
58462 #include "internal.h"
58463
58464 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
58465@@ -102,6 +104,8 @@ long vfs_truncate(struct path *path, loff_t length)
58466 error = locks_verify_truncate(inode, NULL, length);
58467 if (!error)
58468 error = security_path_truncate(path);
58469+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
58470+ error = -EACCES;
58471 if (!error)
58472 error = do_truncate(path->dentry, length, 0, NULL);
58473
58474@@ -186,6 +190,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
58475 error = locks_verify_truncate(inode, f.file, length);
58476 if (!error)
58477 error = security_path_truncate(&f.file->f_path);
58478+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
58479+ error = -EACCES;
58480 if (!error)
58481 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
58482 sb_end_write(inode->i_sb);
58483@@ -360,6 +366,9 @@ retry:
58484 if (__mnt_is_readonly(path.mnt))
58485 res = -EROFS;
58486
58487+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
58488+ res = -EACCES;
58489+
58490 out_path_release:
58491 path_put(&path);
58492 if (retry_estale(res, lookup_flags)) {
58493@@ -391,6 +400,8 @@ retry:
58494 if (error)
58495 goto dput_and_out;
58496
58497+ gr_log_chdir(path.dentry, path.mnt);
58498+
58499 set_fs_pwd(current->fs, &path);
58500
58501 dput_and_out:
58502@@ -420,6 +431,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
58503 goto out_putf;
58504
58505 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
58506+
58507+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
58508+ error = -EPERM;
58509+
58510+ if (!error)
58511+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
58512+
58513 if (!error)
58514 set_fs_pwd(current->fs, &f.file->f_path);
58515 out_putf:
58516@@ -449,7 +467,13 @@ retry:
58517 if (error)
58518 goto dput_and_out;
58519
58520+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
58521+ goto dput_and_out;
58522+
58523 set_fs_root(current->fs, &path);
58524+
58525+ gr_handle_chroot_chdir(&path);
58526+
58527 error = 0;
58528 dput_and_out:
58529 path_put(&path);
58530@@ -471,6 +495,16 @@ static int chmod_common(struct path *path, umode_t mode)
58531 if (error)
58532 return error;
58533 mutex_lock(&inode->i_mutex);
58534+
58535+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
58536+ error = -EACCES;
58537+ goto out_unlock;
58538+ }
58539+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
58540+ error = -EACCES;
58541+ goto out_unlock;
58542+ }
58543+
58544 error = security_path_chmod(path, mode);
58545 if (error)
58546 goto out_unlock;
58547@@ -531,6 +565,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
58548 uid = make_kuid(current_user_ns(), user);
58549 gid = make_kgid(current_user_ns(), group);
58550
58551+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
58552+ return -EACCES;
58553+
58554 newattrs.ia_valid = ATTR_CTIME;
58555 if (user != (uid_t) -1) {
58556 if (!uid_valid(uid))
58557@@ -960,6 +997,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
58558 } else {
58559 fsnotify_open(f);
58560 fd_install(fd, f);
58561+ trace_do_sys_open(tmp->name, flags, mode);
58562 }
58563 }
58564 putname(tmp);
58565diff --git a/fs/pipe.c b/fs/pipe.c
58566index d2c45e1..009fe1c 100644
58567--- a/fs/pipe.c
58568+++ b/fs/pipe.c
58569@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
58570
58571 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
58572 {
58573- if (pipe->files)
58574+ if (atomic_read(&pipe->files))
58575 mutex_lock_nested(&pipe->mutex, subclass);
58576 }
58577
58578@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
58579
58580 void pipe_unlock(struct pipe_inode_info *pipe)
58581 {
58582- if (pipe->files)
58583+ if (atomic_read(&pipe->files))
58584 mutex_unlock(&pipe->mutex);
58585 }
58586 EXPORT_SYMBOL(pipe_unlock);
58587@@ -449,9 +449,9 @@ redo:
58588 }
58589 if (bufs) /* More to do? */
58590 continue;
58591- if (!pipe->writers)
58592+ if (!atomic_read(&pipe->writers))
58593 break;
58594- if (!pipe->waiting_writers) {
58595+ if (!atomic_read(&pipe->waiting_writers)) {
58596 /* syscall merging: Usually we must not sleep
58597 * if O_NONBLOCK is set, or if we got some data.
58598 * But if a writer sleeps in kernel space, then
58599@@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
58600 ret = 0;
58601 __pipe_lock(pipe);
58602
58603- if (!pipe->readers) {
58604+ if (!atomic_read(&pipe->readers)) {
58605 send_sig(SIGPIPE, current, 0);
58606 ret = -EPIPE;
58607 goto out;
58608@@ -562,7 +562,7 @@ redo1:
58609 for (;;) {
58610 int bufs;
58611
58612- if (!pipe->readers) {
58613+ if (!atomic_read(&pipe->readers)) {
58614 send_sig(SIGPIPE, current, 0);
58615 if (!ret)
58616 ret = -EPIPE;
58617@@ -653,9 +653,9 @@ redo2:
58618 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58619 do_wakeup = 0;
58620 }
58621- pipe->waiting_writers++;
58622+ atomic_inc(&pipe->waiting_writers);
58623 pipe_wait(pipe);
58624- pipe->waiting_writers--;
58625+ atomic_dec(&pipe->waiting_writers);
58626 }
58627 out:
58628 __pipe_unlock(pipe);
58629@@ -709,7 +709,7 @@ pipe_poll(struct file *filp, poll_table *wait)
58630 mask = 0;
58631 if (filp->f_mode & FMODE_READ) {
58632 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
58633- if (!pipe->writers && filp->f_version != pipe->w_counter)
58634+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
58635 mask |= POLLHUP;
58636 }
58637
58638@@ -719,7 +719,7 @@ pipe_poll(struct file *filp, poll_table *wait)
58639 * Most Unices do not set POLLERR for FIFOs but on Linux they
58640 * behave exactly like pipes for poll().
58641 */
58642- if (!pipe->readers)
58643+ if (!atomic_read(&pipe->readers))
58644 mask |= POLLERR;
58645 }
58646
58647@@ -734,17 +734,17 @@ pipe_release(struct inode *inode, struct file *file)
58648
58649 __pipe_lock(pipe);
58650 if (file->f_mode & FMODE_READ)
58651- pipe->readers--;
58652+ atomic_dec(&pipe->readers);
58653 if (file->f_mode & FMODE_WRITE)
58654- pipe->writers--;
58655+ atomic_dec(&pipe->writers);
58656
58657- if (pipe->readers || pipe->writers) {
58658+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
58659 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
58660 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58661 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
58662 }
58663 spin_lock(&inode->i_lock);
58664- if (!--pipe->files) {
58665+ if (atomic_dec_and_test(&pipe->files)) {
58666 inode->i_pipe = NULL;
58667 kill = 1;
58668 }
58669@@ -811,7 +811,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
58670 kfree(pipe);
58671 }
58672
58673-static struct vfsmount *pipe_mnt __read_mostly;
58674+struct vfsmount *pipe_mnt __read_mostly;
58675
58676 /*
58677 * pipefs_dname() is called from d_path().
58678@@ -841,8 +841,9 @@ static struct inode * get_pipe_inode(void)
58679 goto fail_iput;
58680
58681 inode->i_pipe = pipe;
58682- pipe->files = 2;
58683- pipe->readers = pipe->writers = 1;
58684+ atomic_set(&pipe->files, 2);
58685+ atomic_set(&pipe->readers, 1);
58686+ atomic_set(&pipe->writers, 1);
58687 inode->i_fop = &pipefifo_fops;
58688
58689 /*
58690@@ -1022,17 +1023,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
58691 spin_lock(&inode->i_lock);
58692 if (inode->i_pipe) {
58693 pipe = inode->i_pipe;
58694- pipe->files++;
58695+ atomic_inc(&pipe->files);
58696 spin_unlock(&inode->i_lock);
58697 } else {
58698 spin_unlock(&inode->i_lock);
58699 pipe = alloc_pipe_info();
58700 if (!pipe)
58701 return -ENOMEM;
58702- pipe->files = 1;
58703+ atomic_set(&pipe->files, 1);
58704 spin_lock(&inode->i_lock);
58705 if (unlikely(inode->i_pipe)) {
58706- inode->i_pipe->files++;
58707+ atomic_inc(&inode->i_pipe->files);
58708 spin_unlock(&inode->i_lock);
58709 free_pipe_info(pipe);
58710 pipe = inode->i_pipe;
58711@@ -1057,10 +1058,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
58712 * opened, even when there is no process writing the FIFO.
58713 */
58714 pipe->r_counter++;
58715- if (pipe->readers++ == 0)
58716+ if (atomic_inc_return(&pipe->readers) == 1)
58717 wake_up_partner(pipe);
58718
58719- if (!is_pipe && !pipe->writers) {
58720+ if (!is_pipe && !atomic_read(&pipe->writers)) {
58721 if ((filp->f_flags & O_NONBLOCK)) {
58722 /* suppress POLLHUP until we have
58723 * seen a writer */
58724@@ -1079,14 +1080,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
58725 * errno=ENXIO when there is no process reading the FIFO.
58726 */
58727 ret = -ENXIO;
58728- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
58729+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
58730 goto err;
58731
58732 pipe->w_counter++;
58733- if (!pipe->writers++)
58734+ if (atomic_inc_return(&pipe->writers) == 1)
58735 wake_up_partner(pipe);
58736
58737- if (!is_pipe && !pipe->readers) {
58738+ if (!is_pipe && !atomic_read(&pipe->readers)) {
58739 if (wait_for_partner(pipe, &pipe->r_counter))
58740 goto err_wr;
58741 }
58742@@ -1100,11 +1101,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
58743 * the process can at least talk to itself.
58744 */
58745
58746- pipe->readers++;
58747- pipe->writers++;
58748+ atomic_inc(&pipe->readers);
58749+ atomic_inc(&pipe->writers);
58750 pipe->r_counter++;
58751 pipe->w_counter++;
58752- if (pipe->readers == 1 || pipe->writers == 1)
58753+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
58754 wake_up_partner(pipe);
58755 break;
58756
58757@@ -1118,20 +1119,20 @@ static int fifo_open(struct inode *inode, struct file *filp)
58758 return 0;
58759
58760 err_rd:
58761- if (!--pipe->readers)
58762+ if (atomic_dec_and_test(&pipe->readers))
58763 wake_up_interruptible(&pipe->wait);
58764 ret = -ERESTARTSYS;
58765 goto err;
58766
58767 err_wr:
58768- if (!--pipe->writers)
58769+ if (atomic_dec_and_test(&pipe->writers))
58770 wake_up_interruptible(&pipe->wait);
58771 ret = -ERESTARTSYS;
58772 goto err;
58773
58774 err:
58775 spin_lock(&inode->i_lock);
58776- if (!--pipe->files) {
58777+ if (atomic_dec_and_test(&pipe->files)) {
58778 inode->i_pipe = NULL;
58779 kill = 1;
58780 }
58781diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
58782index 15af622..0e9f4467 100644
58783--- a/fs/proc/Kconfig
58784+++ b/fs/proc/Kconfig
58785@@ -30,12 +30,12 @@ config PROC_FS
58786
58787 config PROC_KCORE
58788 bool "/proc/kcore support" if !ARM
58789- depends on PROC_FS && MMU
58790+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
58791
58792 config PROC_VMCORE
58793 bool "/proc/vmcore support"
58794- depends on PROC_FS && CRASH_DUMP
58795- default y
58796+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
58797+ default n
58798 help
58799 Exports the dump image of crashed kernel in ELF format.
58800
58801@@ -59,8 +59,8 @@ config PROC_SYSCTL
58802 limited in memory.
58803
58804 config PROC_PAGE_MONITOR
58805- default y
58806- depends on PROC_FS && MMU
58807+ default n
58808+ depends on PROC_FS && MMU && !GRKERNSEC
58809 bool "Enable /proc page monitoring" if EXPERT
58810 help
58811 Various /proc files exist to monitor process memory utilization:
58812diff --git a/fs/proc/array.c b/fs/proc/array.c
58813index cbd0f1b..adec3f0 100644
58814--- a/fs/proc/array.c
58815+++ b/fs/proc/array.c
58816@@ -60,6 +60,7 @@
58817 #include <linux/tty.h>
58818 #include <linux/string.h>
58819 #include <linux/mman.h>
58820+#include <linux/grsecurity.h>
58821 #include <linux/proc_fs.h>
58822 #include <linux/ioport.h>
58823 #include <linux/uaccess.h>
58824@@ -363,6 +364,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
58825 seq_putc(m, '\n');
58826 }
58827
58828+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58829+static inline void task_pax(struct seq_file *m, struct task_struct *p)
58830+{
58831+ if (p->mm)
58832+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
58833+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
58834+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
58835+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
58836+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
58837+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
58838+ else
58839+ seq_printf(m, "PaX:\t-----\n");
58840+}
58841+#endif
58842+
58843 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
58844 struct pid *pid, struct task_struct *task)
58845 {
58846@@ -381,9 +397,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
58847 task_cpus_allowed(m, task);
58848 cpuset_task_status_allowed(m, task);
58849 task_context_switch_counts(m, task);
58850+
58851+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58852+ task_pax(m, task);
58853+#endif
58854+
58855+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
58856+ task_grsec_rbac(m, task);
58857+#endif
58858+
58859 return 0;
58860 }
58861
58862+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58863+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
58864+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
58865+ _mm->pax_flags & MF_PAX_SEGMEXEC))
58866+#endif
58867+
58868 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
58869 struct pid *pid, struct task_struct *task, int whole)
58870 {
58871@@ -405,6 +436,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
58872 char tcomm[sizeof(task->comm)];
58873 unsigned long flags;
58874
58875+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58876+ if (current->exec_id != m->exec_id) {
58877+ gr_log_badprocpid("stat");
58878+ return 0;
58879+ }
58880+#endif
58881+
58882 state = *get_task_state(task);
58883 vsize = eip = esp = 0;
58884 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
58885@@ -476,6 +514,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
58886 gtime = task_gtime(task);
58887 }
58888
58889+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58890+ if (PAX_RAND_FLAGS(mm)) {
58891+ eip = 0;
58892+ esp = 0;
58893+ wchan = 0;
58894+ }
58895+#endif
58896+#ifdef CONFIG_GRKERNSEC_HIDESYM
58897+ wchan = 0;
58898+ eip =0;
58899+ esp =0;
58900+#endif
58901+
58902 /* scale priority and nice values from timeslices to -20..20 */
58903 /* to make it look like a "normal" Unix priority/nice value */
58904 priority = task_prio(task);
58905@@ -512,9 +563,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
58906 seq_put_decimal_ull(m, ' ', vsize);
58907 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
58908 seq_put_decimal_ull(m, ' ', rsslim);
58909+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58910+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
58911+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
58912+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
58913+#else
58914 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
58915 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
58916 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
58917+#endif
58918 seq_put_decimal_ull(m, ' ', esp);
58919 seq_put_decimal_ull(m, ' ', eip);
58920 /* The signal information here is obsolete.
58921@@ -536,7 +593,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
58922 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
58923 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
58924
58925- if (mm && permitted) {
58926+ if (mm && permitted
58927+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58928+ && !PAX_RAND_FLAGS(mm)
58929+#endif
58930+ ) {
58931 seq_put_decimal_ull(m, ' ', mm->start_data);
58932 seq_put_decimal_ull(m, ' ', mm->end_data);
58933 seq_put_decimal_ull(m, ' ', mm->start_brk);
58934@@ -574,8 +635,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
58935 struct pid *pid, struct task_struct *task)
58936 {
58937 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
58938- struct mm_struct *mm = get_task_mm(task);
58939+ struct mm_struct *mm;
58940
58941+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58942+ if (current->exec_id != m->exec_id) {
58943+ gr_log_badprocpid("statm");
58944+ return 0;
58945+ }
58946+#endif
58947+ mm = get_task_mm(task);
58948 if (mm) {
58949 size = task_statm(mm, &shared, &text, &data, &resident);
58950 mmput(mm);
58951@@ -598,6 +666,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
58952 return 0;
58953 }
58954
58955+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
58956+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
58957+{
58958+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
58959+}
58960+#endif
58961+
58962 #ifdef CONFIG_CHECKPOINT_RESTORE
58963 static struct pid *
58964 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
58965diff --git a/fs/proc/base.c b/fs/proc/base.c
58966index 1485e38..8ad4236 100644
58967--- a/fs/proc/base.c
58968+++ b/fs/proc/base.c
58969@@ -113,6 +113,14 @@ struct pid_entry {
58970 union proc_op op;
58971 };
58972
58973+struct getdents_callback {
58974+ struct linux_dirent __user * current_dir;
58975+ struct linux_dirent __user * previous;
58976+ struct file * file;
58977+ int count;
58978+ int error;
58979+};
58980+
58981 #define NOD(NAME, MODE, IOP, FOP, OP) { \
58982 .name = (NAME), \
58983 .len = sizeof(NAME) - 1, \
58984@@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
58985 if (!mm->arg_end)
58986 goto out_mm; /* Shh! No looking before we're done */
58987
58988+ if (gr_acl_handle_procpidmem(task))
58989+ goto out_mm;
58990+
58991 len = mm->arg_end - mm->arg_start;
58992
58993 if (len > PAGE_SIZE)
58994@@ -237,12 +248,28 @@ out:
58995 return res;
58996 }
58997
58998+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58999+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
59000+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
59001+ _mm->pax_flags & MF_PAX_SEGMEXEC))
59002+#endif
59003+
59004 static int proc_pid_auxv(struct task_struct *task, char *buffer)
59005 {
59006 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
59007 int res = PTR_ERR(mm);
59008 if (mm && !IS_ERR(mm)) {
59009 unsigned int nwords = 0;
59010+
59011+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59012+ /* allow if we're currently ptracing this task */
59013+ if (PAX_RAND_FLAGS(mm) &&
59014+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
59015+ mmput(mm);
59016+ return 0;
59017+ }
59018+#endif
59019+
59020 do {
59021 nwords += 2;
59022 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
59023@@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
59024 }
59025
59026
59027-#ifdef CONFIG_KALLSYMS
59028+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59029 /*
59030 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
59031 * Returns the resolved symbol. If that fails, simply return the address.
59032@@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
59033 mutex_unlock(&task->signal->cred_guard_mutex);
59034 }
59035
59036-#ifdef CONFIG_STACKTRACE
59037+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59038
59039 #define MAX_STACK_TRACE_DEPTH 64
59040
59041@@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
59042 return count;
59043 }
59044
59045-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
59046+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
59047 static int proc_pid_syscall(struct task_struct *task, char *buffer)
59048 {
59049 long nr;
59050@@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
59051 /************************************************************************/
59052
59053 /* permission checks */
59054-static int proc_fd_access_allowed(struct inode *inode)
59055+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
59056 {
59057 struct task_struct *task;
59058 int allowed = 0;
59059@@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
59060 */
59061 task = get_proc_task(inode);
59062 if (task) {
59063- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
59064+ if (log)
59065+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
59066+ else
59067+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
59068 put_task_struct(task);
59069 }
59070 return allowed;
59071@@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
59072 struct task_struct *task,
59073 int hide_pid_min)
59074 {
59075+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59076+ return false;
59077+
59078+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59079+ rcu_read_lock();
59080+ {
59081+ const struct cred *tmpcred = current_cred();
59082+ const struct cred *cred = __task_cred(task);
59083+
59084+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
59085+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59086+ || in_group_p(grsec_proc_gid)
59087+#endif
59088+ ) {
59089+ rcu_read_unlock();
59090+ return true;
59091+ }
59092+ }
59093+ rcu_read_unlock();
59094+
59095+ if (!pid->hide_pid)
59096+ return false;
59097+#endif
59098+
59099 if (pid->hide_pid < hide_pid_min)
59100 return true;
59101 if (in_group_p(pid->pid_gid))
59102 return true;
59103+
59104 return ptrace_may_access(task, PTRACE_MODE_READ);
59105 }
59106
59107@@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
59108 put_task_struct(task);
59109
59110 if (!has_perms) {
59111+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59112+ {
59113+#else
59114 if (pid->hide_pid == 2) {
59115+#endif
59116 /*
59117 * Let's make getdents(), stat(), and open()
59118 * consistent with each other. If a process
59119@@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
59120 if (!task)
59121 return -ESRCH;
59122
59123+ if (gr_acl_handle_procpidmem(task)) {
59124+ put_task_struct(task);
59125+ return -EPERM;
59126+ }
59127+
59128 mm = mm_access(task, mode);
59129 put_task_struct(task);
59130
59131@@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
59132
59133 file->private_data = mm;
59134
59135+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59136+ file->f_version = current->exec_id;
59137+#endif
59138+
59139 return 0;
59140 }
59141
59142@@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
59143 ssize_t copied;
59144 char *page;
59145
59146+#ifdef CONFIG_GRKERNSEC
59147+ if (write)
59148+ return -EPERM;
59149+#endif
59150+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59151+ if (file->f_version != current->exec_id) {
59152+ gr_log_badprocpid("mem");
59153+ return 0;
59154+ }
59155+#endif
59156+
59157 if (!mm)
59158 return 0;
59159
59160@@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
59161 goto free;
59162
59163 while (count > 0) {
59164- int this_len = min_t(int, count, PAGE_SIZE);
59165+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
59166
59167 if (write && copy_from_user(page, buf, this_len)) {
59168 copied = -EFAULT;
59169@@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
59170 if (!mm)
59171 return 0;
59172
59173+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59174+ if (file->f_version != current->exec_id) {
59175+ gr_log_badprocpid("environ");
59176+ return 0;
59177+ }
59178+#endif
59179+
59180 page = (char *)__get_free_page(GFP_TEMPORARY);
59181 if (!page)
59182 return -ENOMEM;
59183@@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
59184 goto free;
59185 while (count > 0) {
59186 size_t this_len, max_len;
59187- int retval;
59188+ ssize_t retval;
59189
59190 if (src >= (mm->env_end - mm->env_start))
59191 break;
59192@@ -1461,7 +1547,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
59193 int error = -EACCES;
59194
59195 /* Are we allowed to snoop on the tasks file descriptors? */
59196- if (!proc_fd_access_allowed(inode))
59197+ if (!proc_fd_access_allowed(inode, 0))
59198 goto out;
59199
59200 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
59201@@ -1505,8 +1591,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
59202 struct path path;
59203
59204 /* Are we allowed to snoop on the tasks file descriptors? */
59205- if (!proc_fd_access_allowed(inode))
59206- goto out;
59207+ /* logging this is needed for learning on chromium to work properly,
59208+ but we don't want to flood the logs from 'ps' which does a readlink
59209+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
59210+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
59211+ */
59212+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
59213+ if (!proc_fd_access_allowed(inode,0))
59214+ goto out;
59215+ } else {
59216+ if (!proc_fd_access_allowed(inode,1))
59217+ goto out;
59218+ }
59219
59220 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
59221 if (error)
59222@@ -1556,7 +1652,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
59223 rcu_read_lock();
59224 cred = __task_cred(task);
59225 inode->i_uid = cred->euid;
59226+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59227+ inode->i_gid = grsec_proc_gid;
59228+#else
59229 inode->i_gid = cred->egid;
59230+#endif
59231 rcu_read_unlock();
59232 }
59233 security_task_to_inode(task, inode);
59234@@ -1592,10 +1692,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
59235 return -ENOENT;
59236 }
59237 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
59238+#ifdef CONFIG_GRKERNSEC_PROC_USER
59239+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
59240+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59241+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
59242+#endif
59243 task_dumpable(task)) {
59244 cred = __task_cred(task);
59245 stat->uid = cred->euid;
59246+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59247+ stat->gid = grsec_proc_gid;
59248+#else
59249 stat->gid = cred->egid;
59250+#endif
59251 }
59252 }
59253 rcu_read_unlock();
59254@@ -1633,11 +1742,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
59255
59256 if (task) {
59257 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
59258+#ifdef CONFIG_GRKERNSEC_PROC_USER
59259+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
59260+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59261+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
59262+#endif
59263 task_dumpable(task)) {
59264 rcu_read_lock();
59265 cred = __task_cred(task);
59266 inode->i_uid = cred->euid;
59267+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59268+ inode->i_gid = grsec_proc_gid;
59269+#else
59270 inode->i_gid = cred->egid;
59271+#endif
59272 rcu_read_unlock();
59273 } else {
59274 inode->i_uid = GLOBAL_ROOT_UID;
59275@@ -2166,6 +2284,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
59276 if (!task)
59277 goto out_no_task;
59278
59279+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59280+ goto out;
59281+
59282 /*
59283 * Yes, it does not scale. And it should not. Don't add
59284 * new entries into /proc/<tgid>/ without very good reasons.
59285@@ -2196,6 +2317,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
59286 if (!task)
59287 return -ENOENT;
59288
59289+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59290+ goto out;
59291+
59292 if (!dir_emit_dots(file, ctx))
59293 goto out;
59294
59295@@ -2585,7 +2709,7 @@ static const struct pid_entry tgid_base_stuff[] = {
59296 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
59297 #endif
59298 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
59299-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
59300+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
59301 INF("syscall", S_IRUGO, proc_pid_syscall),
59302 #endif
59303 INF("cmdline", S_IRUGO, proc_pid_cmdline),
59304@@ -2610,10 +2734,10 @@ static const struct pid_entry tgid_base_stuff[] = {
59305 #ifdef CONFIG_SECURITY
59306 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
59307 #endif
59308-#ifdef CONFIG_KALLSYMS
59309+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59310 INF("wchan", S_IRUGO, proc_pid_wchan),
59311 #endif
59312-#ifdef CONFIG_STACKTRACE
59313+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59314 ONE("stack", S_IRUGO, proc_pid_stack),
59315 #endif
59316 #ifdef CONFIG_SCHEDSTATS
59317@@ -2647,6 +2771,9 @@ static const struct pid_entry tgid_base_stuff[] = {
59318 #ifdef CONFIG_HARDWALL
59319 INF("hardwall", S_IRUGO, proc_pid_hardwall),
59320 #endif
59321+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
59322+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
59323+#endif
59324 #ifdef CONFIG_USER_NS
59325 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
59326 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
59327@@ -2777,7 +2904,14 @@ static int proc_pid_instantiate(struct inode *dir,
59328 if (!inode)
59329 goto out;
59330
59331+#ifdef CONFIG_GRKERNSEC_PROC_USER
59332+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
59333+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59334+ inode->i_gid = grsec_proc_gid;
59335+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
59336+#else
59337 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
59338+#endif
59339 inode->i_op = &proc_tgid_base_inode_operations;
59340 inode->i_fop = &proc_tgid_base_operations;
59341 inode->i_flags|=S_IMMUTABLE;
59342@@ -2815,7 +2949,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
59343 if (!task)
59344 goto out;
59345
59346+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59347+ goto out_put_task;
59348+
59349 result = proc_pid_instantiate(dir, dentry, task, NULL);
59350+out_put_task:
59351 put_task_struct(task);
59352 out:
59353 return ERR_PTR(result);
59354@@ -2921,7 +3059,7 @@ static const struct pid_entry tid_base_stuff[] = {
59355 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_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@@ -2948,10 +3086,10 @@ static const struct pid_entry tid_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
59376diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
59377index 82676e3..5f8518a 100644
59378--- a/fs/proc/cmdline.c
59379+++ b/fs/proc/cmdline.c
59380@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
59381
59382 static int __init proc_cmdline_init(void)
59383 {
59384+#ifdef CONFIG_GRKERNSEC_PROC_ADD
59385+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
59386+#else
59387 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
59388+#endif
59389 return 0;
59390 }
59391 module_init(proc_cmdline_init);
59392diff --git a/fs/proc/devices.c b/fs/proc/devices.c
59393index b143471..bb105e5 100644
59394--- a/fs/proc/devices.c
59395+++ b/fs/proc/devices.c
59396@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
59397
59398 static int __init proc_devices_init(void)
59399 {
59400+#ifdef CONFIG_GRKERNSEC_PROC_ADD
59401+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
59402+#else
59403 proc_create("devices", 0, NULL, &proc_devinfo_operations);
59404+#endif
59405 return 0;
59406 }
59407 module_init(proc_devices_init);
59408diff --git a/fs/proc/fd.c b/fs/proc/fd.c
59409index 0ff80f9..a1d7500 100644
59410--- a/fs/proc/fd.c
59411+++ b/fs/proc/fd.c
59412@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
59413 if (!task)
59414 return -ENOENT;
59415
59416- files = get_files_struct(task);
59417+ if (!gr_acl_handle_procpidmem(task))
59418+ files = get_files_struct(task);
59419 put_task_struct(task);
59420
59421 if (files) {
59422@@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
59423 */
59424 int proc_fd_permission(struct inode *inode, int mask)
59425 {
59426+ struct task_struct *task;
59427 int rv = generic_permission(inode, mask);
59428- if (rv == 0)
59429- return 0;
59430+
59431 if (task_pid(current) == proc_pid(inode))
59432 rv = 0;
59433+
59434+ task = get_proc_task(inode);
59435+ if (task == NULL)
59436+ return rv;
59437+
59438+ if (gr_acl_handle_procpidmem(task))
59439+ rv = -EACCES;
59440+
59441+ put_task_struct(task);
59442+
59443 return rv;
59444 }
59445
59446diff --git a/fs/proc/inode.c b/fs/proc/inode.c
59447index 073aea6..0630370 100644
59448--- a/fs/proc/inode.c
59449+++ b/fs/proc/inode.c
59450@@ -23,11 +23,17 @@
59451 #include <linux/slab.h>
59452 #include <linux/mount.h>
59453 #include <linux/magic.h>
59454+#include <linux/grsecurity.h>
59455
59456 #include <asm/uaccess.h>
59457
59458 #include "internal.h"
59459
59460+#ifdef CONFIG_PROC_SYSCTL
59461+extern const struct inode_operations proc_sys_inode_operations;
59462+extern const struct inode_operations proc_sys_dir_operations;
59463+#endif
59464+
59465 static void proc_evict_inode(struct inode *inode)
59466 {
59467 struct proc_dir_entry *de;
59468@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
59469 ns = PROC_I(inode)->ns.ns;
59470 if (ns_ops && ns)
59471 ns_ops->put(ns);
59472+
59473+#ifdef CONFIG_PROC_SYSCTL
59474+ if (inode->i_op == &proc_sys_inode_operations ||
59475+ inode->i_op == &proc_sys_dir_operations)
59476+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
59477+#endif
59478+
59479 }
59480
59481 static struct kmem_cache * proc_inode_cachep;
59482@@ -385,7 +398,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
59483 if (de->mode) {
59484 inode->i_mode = de->mode;
59485 inode->i_uid = de->uid;
59486+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59487+ inode->i_gid = grsec_proc_gid;
59488+#else
59489 inode->i_gid = de->gid;
59490+#endif
59491 }
59492 if (de->size)
59493 inode->i_size = de->size;
59494diff --git a/fs/proc/internal.h b/fs/proc/internal.h
59495index 651d09a..60c73ae 100644
59496--- a/fs/proc/internal.h
59497+++ b/fs/proc/internal.h
59498@@ -155,6 +155,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
59499 struct pid *, struct task_struct *);
59500 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
59501 struct pid *, struct task_struct *);
59502+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
59503+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
59504+#endif
59505
59506 /*
59507 * base.c
59508diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
59509index 06ea155..9a798c7 100644
59510--- a/fs/proc/kcore.c
59511+++ b/fs/proc/kcore.c
59512@@ -484,9 +484,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
59513 * the addresses in the elf_phdr on our list.
59514 */
59515 start = kc_offset_to_vaddr(*fpos - elf_buflen);
59516- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
59517+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
59518+ if (tsz > buflen)
59519 tsz = buflen;
59520-
59521+
59522 while (buflen) {
59523 struct kcore_list *m;
59524
59525@@ -515,20 +516,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
59526 kfree(elf_buf);
59527 } else {
59528 if (kern_addr_valid(start)) {
59529- unsigned long n;
59530+ char *elf_buf;
59531+ mm_segment_t oldfs;
59532
59533- n = copy_to_user(buffer, (char *)start, tsz);
59534- /*
59535- * We cannot distinguish between fault on source
59536- * and fault on destination. When this happens
59537- * we clear too and hope it will trigger the
59538- * EFAULT again.
59539- */
59540- if (n) {
59541- if (clear_user(buffer + tsz - n,
59542- n))
59543+ elf_buf = kmalloc(tsz, GFP_KERNEL);
59544+ if (!elf_buf)
59545+ return -ENOMEM;
59546+ oldfs = get_fs();
59547+ set_fs(KERNEL_DS);
59548+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
59549+ set_fs(oldfs);
59550+ if (copy_to_user(buffer, elf_buf, tsz)) {
59551+ kfree(elf_buf);
59552 return -EFAULT;
59553+ }
59554 }
59555+ set_fs(oldfs);
59556+ kfree(elf_buf);
59557 } else {
59558 if (clear_user(buffer, tsz))
59559 return -EFAULT;
59560@@ -548,6 +552,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
59561
59562 static int open_kcore(struct inode *inode, struct file *filp)
59563 {
59564+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
59565+ return -EPERM;
59566+#endif
59567 if (!capable(CAP_SYS_RAWIO))
59568 return -EPERM;
59569 if (kcore_need_update)
59570diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
59571index 5aa847a..f77c8d4 100644
59572--- a/fs/proc/meminfo.c
59573+++ b/fs/proc/meminfo.c
59574@@ -159,7 +159,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
59575 vmi.used >> 10,
59576 vmi.largest_chunk >> 10
59577 #ifdef CONFIG_MEMORY_FAILURE
59578- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
59579+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
59580 #endif
59581 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
59582 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
59583diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
59584index ccfd99b..1b7e255 100644
59585--- a/fs/proc/nommu.c
59586+++ b/fs/proc/nommu.c
59587@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
59588 if (len < 1)
59589 len = 1;
59590 seq_printf(m, "%*c", len, ' ');
59591- seq_path(m, &file->f_path, "");
59592+ seq_path(m, &file->f_path, "\n\\");
59593 }
59594
59595 seq_putc(m, '\n');
59596diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
59597index 4677bb7..408e936 100644
59598--- a/fs/proc/proc_net.c
59599+++ b/fs/proc/proc_net.c
59600@@ -23,6 +23,7 @@
59601 #include <linux/nsproxy.h>
59602 #include <net/net_namespace.h>
59603 #include <linux/seq_file.h>
59604+#include <linux/grsecurity.h>
59605
59606 #include "internal.h"
59607
59608@@ -109,6 +110,17 @@ static struct net *get_proc_task_net(struct inode *dir)
59609 struct task_struct *task;
59610 struct nsproxy *ns;
59611 struct net *net = NULL;
59612+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59613+ const struct cred *cred = current_cred();
59614+#endif
59615+
59616+#ifdef CONFIG_GRKERNSEC_PROC_USER
59617+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
59618+ return net;
59619+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59620+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
59621+ return net;
59622+#endif
59623
59624 rcu_read_lock();
59625 task = pid_task(proc_pid(dir), PIDTYPE_PID);
59626diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
59627index 7129046..f2779c6 100644
59628--- a/fs/proc/proc_sysctl.c
59629+++ b/fs/proc/proc_sysctl.c
59630@@ -13,11 +13,15 @@
59631 #include <linux/module.h>
59632 #include "internal.h"
59633
59634+extern int gr_handle_chroot_sysctl(const int op);
59635+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
59636+ const int op);
59637+
59638 static const struct dentry_operations proc_sys_dentry_operations;
59639 static const struct file_operations proc_sys_file_operations;
59640-static const struct inode_operations proc_sys_inode_operations;
59641+const struct inode_operations proc_sys_inode_operations;
59642 static const struct file_operations proc_sys_dir_file_operations;
59643-static const struct inode_operations proc_sys_dir_operations;
59644+const struct inode_operations proc_sys_dir_operations;
59645
59646 void proc_sys_poll_notify(struct ctl_table_poll *poll)
59647 {
59648@@ -467,6 +471,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
59649
59650 err = NULL;
59651 d_set_d_op(dentry, &proc_sys_dentry_operations);
59652+
59653+ gr_handle_proc_create(dentry, inode);
59654+
59655 d_add(dentry, inode);
59656
59657 out:
59658@@ -482,6 +489,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
59659 struct inode *inode = file_inode(filp);
59660 struct ctl_table_header *head = grab_header(inode);
59661 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
59662+ int op = write ? MAY_WRITE : MAY_READ;
59663 ssize_t error;
59664 size_t res;
59665
59666@@ -493,7 +501,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
59667 * and won't be until we finish.
59668 */
59669 error = -EPERM;
59670- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
59671+ if (sysctl_perm(head, table, op))
59672 goto out;
59673
59674 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
59675@@ -501,6 +509,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
59676 if (!table->proc_handler)
59677 goto out;
59678
59679+#ifdef CONFIG_GRKERNSEC
59680+ error = -EPERM;
59681+ if (gr_handle_chroot_sysctl(op))
59682+ goto out;
59683+ dget(filp->f_path.dentry);
59684+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
59685+ dput(filp->f_path.dentry);
59686+ goto out;
59687+ }
59688+ dput(filp->f_path.dentry);
59689+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
59690+ goto out;
59691+ if (write && !capable(CAP_SYS_ADMIN))
59692+ goto out;
59693+#endif
59694+
59695 /* careful: calling conventions are nasty here */
59696 res = count;
59697 error = table->proc_handler(table, write, buf, &res, ppos);
59698@@ -598,6 +622,9 @@ static bool proc_sys_fill_cache(struct file *file,
59699 return false;
59700 } else {
59701 d_set_d_op(child, &proc_sys_dentry_operations);
59702+
59703+ gr_handle_proc_create(child, inode);
59704+
59705 d_add(child, inode);
59706 }
59707 } else {
59708@@ -641,6 +668,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
59709 if ((*pos)++ < ctx->pos)
59710 return true;
59711
59712+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
59713+ return 0;
59714+
59715 if (unlikely(S_ISLNK(table->mode)))
59716 res = proc_sys_link_fill_cache(file, ctx, head, table);
59717 else
59718@@ -734,6 +764,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
59719 if (IS_ERR(head))
59720 return PTR_ERR(head);
59721
59722+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
59723+ return -ENOENT;
59724+
59725 generic_fillattr(inode, stat);
59726 if (table)
59727 stat->mode = (stat->mode & S_IFMT) | table->mode;
59728@@ -756,13 +789,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
59729 .llseek = generic_file_llseek,
59730 };
59731
59732-static const struct inode_operations proc_sys_inode_operations = {
59733+const struct inode_operations proc_sys_inode_operations = {
59734 .permission = proc_sys_permission,
59735 .setattr = proc_sys_setattr,
59736 .getattr = proc_sys_getattr,
59737 };
59738
59739-static const struct inode_operations proc_sys_dir_operations = {
59740+const struct inode_operations proc_sys_dir_operations = {
59741 .lookup = proc_sys_lookup,
59742 .permission = proc_sys_permission,
59743 .setattr = proc_sys_setattr,
59744@@ -839,7 +872,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
59745 static struct ctl_dir *new_dir(struct ctl_table_set *set,
59746 const char *name, int namelen)
59747 {
59748- struct ctl_table *table;
59749+ ctl_table_no_const *table;
59750 struct ctl_dir *new;
59751 struct ctl_node *node;
59752 char *new_name;
59753@@ -851,7 +884,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
59754 return NULL;
59755
59756 node = (struct ctl_node *)(new + 1);
59757- table = (struct ctl_table *)(node + 1);
59758+ table = (ctl_table_no_const *)(node + 1);
59759 new_name = (char *)(table + 2);
59760 memcpy(new_name, name, namelen);
59761 new_name[namelen] = '\0';
59762@@ -1020,7 +1053,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
59763 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
59764 struct ctl_table_root *link_root)
59765 {
59766- struct ctl_table *link_table, *entry, *link;
59767+ ctl_table_no_const *link_table, *link;
59768+ struct ctl_table *entry;
59769 struct ctl_table_header *links;
59770 struct ctl_node *node;
59771 char *link_name;
59772@@ -1043,7 +1077,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
59773 return NULL;
59774
59775 node = (struct ctl_node *)(links + 1);
59776- link_table = (struct ctl_table *)(node + nr_entries);
59777+ link_table = (ctl_table_no_const *)(node + nr_entries);
59778 link_name = (char *)&link_table[nr_entries + 1];
59779
59780 for (link = link_table, entry = table; entry->procname; link++, entry++) {
59781@@ -1291,8 +1325,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
59782 struct ctl_table_header ***subheader, struct ctl_table_set *set,
59783 struct ctl_table *table)
59784 {
59785- struct ctl_table *ctl_table_arg = NULL;
59786- struct ctl_table *entry, *files;
59787+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
59788+ struct ctl_table *entry;
59789 int nr_files = 0;
59790 int nr_dirs = 0;
59791 int err = -ENOMEM;
59792@@ -1304,10 +1338,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
59793 nr_files++;
59794 }
59795
59796- files = table;
59797 /* If there are mixed files and directories we need a new table */
59798 if (nr_dirs && nr_files) {
59799- struct ctl_table *new;
59800+ ctl_table_no_const *new;
59801 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
59802 GFP_KERNEL);
59803 if (!files)
59804@@ -1325,7 +1358,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
59805 /* Register everything except a directory full of subdirectories */
59806 if (nr_files || !nr_dirs) {
59807 struct ctl_table_header *header;
59808- header = __register_sysctl_table(set, path, files);
59809+ header = __register_sysctl_table(set, path, files ? files : table);
59810 if (!header) {
59811 kfree(ctl_table_arg);
59812 goto out;
59813diff --git a/fs/proc/root.c b/fs/proc/root.c
59814index 0e0e83c..005ba6a 100644
59815--- a/fs/proc/root.c
59816+++ b/fs/proc/root.c
59817@@ -183,7 +183,15 @@ void __init proc_root_init(void)
59818 #ifdef CONFIG_PROC_DEVICETREE
59819 proc_device_tree_init();
59820 #endif
59821+#ifdef CONFIG_GRKERNSEC_PROC_ADD
59822+#ifdef CONFIG_GRKERNSEC_PROC_USER
59823+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
59824+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59825+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
59826+#endif
59827+#else
59828 proc_mkdir("bus", NULL);
59829+#endif
59830 proc_sys_init();
59831 }
59832
59833diff --git a/fs/proc/self.c b/fs/proc/self.c
59834index 6b6a993..807cccc 100644
59835--- a/fs/proc/self.c
59836+++ b/fs/proc/self.c
59837@@ -39,7 +39,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
59838 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
59839 void *cookie)
59840 {
59841- char *s = nd_get_link(nd);
59842+ const char *s = nd_get_link(nd);
59843 if (!IS_ERR(s))
59844 kfree(s);
59845 }
59846diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
59847index 107d026..c715aeb 100644
59848--- a/fs/proc/task_mmu.c
59849+++ b/fs/proc/task_mmu.c
59850@@ -12,12 +12,19 @@
59851 #include <linux/swap.h>
59852 #include <linux/swapops.h>
59853 #include <linux/mmu_notifier.h>
59854+#include <linux/grsecurity.h>
59855
59856 #include <asm/elf.h>
59857 #include <asm/uaccess.h>
59858 #include <asm/tlbflush.h>
59859 #include "internal.h"
59860
59861+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59862+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
59863+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
59864+ _mm->pax_flags & MF_PAX_SEGMEXEC))
59865+#endif
59866+
59867 void task_mem(struct seq_file *m, struct mm_struct *mm)
59868 {
59869 unsigned long data, text, lib, swap;
59870@@ -53,8 +60,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
59871 "VmExe:\t%8lu kB\n"
59872 "VmLib:\t%8lu kB\n"
59873 "VmPTE:\t%8lu kB\n"
59874- "VmSwap:\t%8lu kB\n",
59875- hiwater_vm << (PAGE_SHIFT-10),
59876+ "VmSwap:\t%8lu kB\n"
59877+
59878+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
59879+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
59880+#endif
59881+
59882+ ,hiwater_vm << (PAGE_SHIFT-10),
59883 total_vm << (PAGE_SHIFT-10),
59884 mm->locked_vm << (PAGE_SHIFT-10),
59885 mm->pinned_vm << (PAGE_SHIFT-10),
59886@@ -63,7 +75,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
59887 data << (PAGE_SHIFT-10),
59888 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
59889 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
59890- swap << (PAGE_SHIFT-10));
59891+ swap << (PAGE_SHIFT-10)
59892+
59893+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
59894+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59895+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
59896+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
59897+#else
59898+ , mm->context.user_cs_base
59899+ , mm->context.user_cs_limit
59900+#endif
59901+#endif
59902+
59903+ );
59904 }
59905
59906 unsigned long task_vsize(struct mm_struct *mm)
59907@@ -278,13 +302,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
59908 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
59909 }
59910
59911- /* We don't show the stack guard page in /proc/maps */
59912+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59913+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
59914+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
59915+#else
59916 start = vma->vm_start;
59917- if (stack_guard_page_start(vma, start))
59918- start += PAGE_SIZE;
59919 end = vma->vm_end;
59920- if (stack_guard_page_end(vma, end))
59921- end -= PAGE_SIZE;
59922+#endif
59923
59924 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
59925 start,
59926@@ -293,7 +317,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
59927 flags & VM_WRITE ? 'w' : '-',
59928 flags & VM_EXEC ? 'x' : '-',
59929 flags & VM_MAYSHARE ? 's' : 'p',
59930+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59931+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
59932+#else
59933 pgoff,
59934+#endif
59935 MAJOR(dev), MINOR(dev), ino, &len);
59936
59937 /*
59938@@ -302,7 +330,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
59939 */
59940 if (file) {
59941 pad_len_spaces(m, len);
59942- seq_path(m, &file->f_path, "\n");
59943+ seq_path(m, &file->f_path, "\n\\");
59944 goto done;
59945 }
59946
59947@@ -328,8 +356,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
59948 * Thread stack in /proc/PID/task/TID/maps or
59949 * the main process stack.
59950 */
59951- if (!is_pid || (vma->vm_start <= mm->start_stack &&
59952- vma->vm_end >= mm->start_stack)) {
59953+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
59954+ (vma->vm_start <= mm->start_stack &&
59955+ vma->vm_end >= mm->start_stack)) {
59956 name = "[stack]";
59957 } else {
59958 /* Thread stack in /proc/PID/maps */
59959@@ -353,6 +382,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
59960 struct proc_maps_private *priv = m->private;
59961 struct task_struct *task = priv->task;
59962
59963+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59964+ if (current->exec_id != m->exec_id) {
59965+ gr_log_badprocpid("maps");
59966+ return 0;
59967+ }
59968+#endif
59969+
59970 show_map_vma(m, vma, is_pid);
59971
59972 if (m->count < m->size) /* vma is copied successfully */
59973@@ -590,12 +626,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
59974 .private = &mss,
59975 };
59976
59977+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59978+ if (current->exec_id != m->exec_id) {
59979+ gr_log_badprocpid("smaps");
59980+ return 0;
59981+ }
59982+#endif
59983 memset(&mss, 0, sizeof mss);
59984- mss.vma = vma;
59985- /* mmap_sem is held in m_start */
59986- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
59987- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
59988-
59989+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59990+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
59991+#endif
59992+ mss.vma = vma;
59993+ /* mmap_sem is held in m_start */
59994+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
59995+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
59996+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59997+ }
59998+#endif
59999 show_map_vma(m, vma, is_pid);
60000
60001 seq_printf(m,
60002@@ -613,7 +660,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
60003 "KernelPageSize: %8lu kB\n"
60004 "MMUPageSize: %8lu kB\n"
60005 "Locked: %8lu kB\n",
60006+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60007+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
60008+#else
60009 (vma->vm_end - vma->vm_start) >> 10,
60010+#endif
60011 mss.resident >> 10,
60012 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
60013 mss.shared_clean >> 10,
60014@@ -1362,6 +1413,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
60015 int n;
60016 char buffer[50];
60017
60018+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60019+ if (current->exec_id != m->exec_id) {
60020+ gr_log_badprocpid("numa_maps");
60021+ return 0;
60022+ }
60023+#endif
60024+
60025 if (!mm)
60026 return 0;
60027
60028@@ -1379,11 +1437,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
60029 mpol_to_str(buffer, sizeof(buffer), pol);
60030 mpol_cond_put(pol);
60031
60032+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60033+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
60034+#else
60035 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
60036+#endif
60037
60038 if (file) {
60039 seq_printf(m, " file=");
60040- seq_path(m, &file->f_path, "\n\t= ");
60041+ seq_path(m, &file->f_path, "\n\t\\= ");
60042 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
60043 seq_printf(m, " heap");
60044 } else {
60045diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
60046index 56123a6..5a2f6ec 100644
60047--- a/fs/proc/task_nommu.c
60048+++ b/fs/proc/task_nommu.c
60049@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
60050 else
60051 bytes += kobjsize(mm);
60052
60053- if (current->fs && current->fs->users > 1)
60054+ if (current->fs && atomic_read(&current->fs->users) > 1)
60055 sbytes += kobjsize(current->fs);
60056 else
60057 bytes += kobjsize(current->fs);
60058@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
60059
60060 if (file) {
60061 pad_len_spaces(m, len);
60062- seq_path(m, &file->f_path, "");
60063+ seq_path(m, &file->f_path, "\n\\");
60064 } else if (mm) {
60065 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
60066
60067diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
60068index a1a16eb..6be46ed 100644
60069--- a/fs/proc/vmcore.c
60070+++ b/fs/proc/vmcore.c
60071@@ -104,9 +104,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
60072 nr_bytes = count;
60073
60074 /* If pfn is not ram, return zeros for sparse dump files */
60075- if (pfn_is_ram(pfn) == 0)
60076- memset(buf, 0, nr_bytes);
60077- else {
60078+ if (pfn_is_ram(pfn) == 0) {
60079+ if (userbuf) {
60080+ if (clear_user((char __force_user *)buf, nr_bytes))
60081+ return -EFAULT;
60082+ } else
60083+ memset(buf, 0, nr_bytes);
60084+ } else {
60085 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
60086 offset, userbuf);
60087 if (tmp < 0)
60088@@ -178,7 +182,7 @@ static ssize_t read_vmcore(struct file *file, char __user *buffer,
60089 if (*fpos < m->offset + m->size) {
60090 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
60091 start = m->paddr + *fpos - m->offset;
60092- tmp = read_from_oldmem(buffer, tsz, &start, 1);
60093+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, 1);
60094 if (tmp < 0)
60095 return tmp;
60096 buflen -= tsz;
60097diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
60098index b00fcc9..e0c6381 100644
60099--- a/fs/qnx6/qnx6.h
60100+++ b/fs/qnx6/qnx6.h
60101@@ -74,7 +74,7 @@ enum {
60102 BYTESEX_BE,
60103 };
60104
60105-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
60106+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
60107 {
60108 if (sbi->s_bytesex == BYTESEX_LE)
60109 return le64_to_cpu((__force __le64)n);
60110@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
60111 return (__force __fs64)cpu_to_be64(n);
60112 }
60113
60114-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
60115+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
60116 {
60117 if (sbi->s_bytesex == BYTESEX_LE)
60118 return le32_to_cpu((__force __le32)n);
60119diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
60120index 16e8abb..2dcf914 100644
60121--- a/fs/quota/netlink.c
60122+++ b/fs/quota/netlink.c
60123@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
60124 void quota_send_warning(struct kqid qid, dev_t dev,
60125 const char warntype)
60126 {
60127- static atomic_t seq;
60128+ static atomic_unchecked_t seq;
60129 struct sk_buff *skb;
60130 void *msg_head;
60131 int ret;
60132@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
60133 "VFS: Not enough memory to send quota warning.\n");
60134 return;
60135 }
60136- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
60137+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
60138 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
60139 if (!msg_head) {
60140 printk(KERN_ERR
60141diff --git a/fs/read_write.c b/fs/read_write.c
60142index 122a384..0b7ecf2 100644
60143--- a/fs/read_write.c
60144+++ b/fs/read_write.c
60145@@ -440,7 +440,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
60146
60147 old_fs = get_fs();
60148 set_fs(get_ds());
60149- p = (__force const char __user *)buf;
60150+ p = (const char __force_user *)buf;
60151 if (count > MAX_RW_COUNT)
60152 count = MAX_RW_COUNT;
60153 if (file->f_op->write)
60154diff --git a/fs/readdir.c b/fs/readdir.c
60155index 93d71e5..6a14be8 100644
60156--- a/fs/readdir.c
60157+++ b/fs/readdir.c
60158@@ -17,6 +17,7 @@
60159 #include <linux/security.h>
60160 #include <linux/syscalls.h>
60161 #include <linux/unistd.h>
60162+#include <linux/namei.h>
60163
60164 #include <asm/uaccess.h>
60165
60166@@ -69,6 +70,7 @@ struct old_linux_dirent {
60167 struct readdir_callback {
60168 struct dir_context ctx;
60169 struct old_linux_dirent __user * dirent;
60170+ struct file * file;
60171 int result;
60172 };
60173
60174@@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
60175 buf->result = -EOVERFLOW;
60176 return -EOVERFLOW;
60177 }
60178+
60179+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60180+ return 0;
60181+
60182 buf->result++;
60183 dirent = buf->dirent;
60184 if (!access_ok(VERIFY_WRITE, dirent,
60185@@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
60186 if (!f.file)
60187 return -EBADF;
60188
60189+ buf.file = f.file;
60190 error = iterate_dir(f.file, &buf.ctx);
60191 if (buf.result)
60192 error = buf.result;
60193@@ -142,6 +149,7 @@ struct getdents_callback {
60194 struct dir_context ctx;
60195 struct linux_dirent __user * current_dir;
60196 struct linux_dirent __user * previous;
60197+ struct file * file;
60198 int count;
60199 int error;
60200 };
60201@@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
60202 buf->error = -EOVERFLOW;
60203 return -EOVERFLOW;
60204 }
60205+
60206+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60207+ return 0;
60208+
60209 dirent = buf->previous;
60210 if (dirent) {
60211 if (__put_user(offset, &dirent->d_off))
60212@@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
60213 if (!f.file)
60214 return -EBADF;
60215
60216+ buf.file = f.file;
60217 error = iterate_dir(f.file, &buf.ctx);
60218 if (error >= 0)
60219 error = buf.error;
60220@@ -226,6 +239,7 @@ struct getdents_callback64 {
60221 struct dir_context ctx;
60222 struct linux_dirent64 __user * current_dir;
60223 struct linux_dirent64 __user * previous;
60224+ struct file *file;
60225 int count;
60226 int error;
60227 };
60228@@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
60229 buf->error = -EINVAL; /* only used if we fail.. */
60230 if (reclen > buf->count)
60231 return -EINVAL;
60232+
60233+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60234+ return 0;
60235+
60236 dirent = buf->previous;
60237 if (dirent) {
60238 if (__put_user(offset, &dirent->d_off))
60239@@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
60240 if (!f.file)
60241 return -EBADF;
60242
60243+ buf.file = f.file;
60244 error = iterate_dir(f.file, &buf.ctx);
60245 if (error >= 0)
60246 error = buf.error;
60247diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
60248index 2b7882b..1c5ef48 100644
60249--- a/fs/reiserfs/do_balan.c
60250+++ b/fs/reiserfs/do_balan.c
60251@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
60252 return;
60253 }
60254
60255- atomic_inc(&(fs_generation(tb->tb_sb)));
60256+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
60257 do_balance_starts(tb);
60258
60259 /* balance leaf returns 0 except if combining L R and S into
60260diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
60261index a958444..42b2323 100644
60262--- a/fs/reiserfs/procfs.c
60263+++ b/fs/reiserfs/procfs.c
60264@@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
60265 "SMALL_TAILS " : "NO_TAILS ",
60266 replay_only(sb) ? "REPLAY_ONLY " : "",
60267 convert_reiserfs(sb) ? "CONV " : "",
60268- atomic_read(&r->s_generation_counter),
60269+ atomic_read_unchecked(&r->s_generation_counter),
60270 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
60271 SF(s_do_balance), SF(s_unneeded_left_neighbor),
60272 SF(s_good_search_by_key_reada), SF(s_bmaps),
60273diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
60274index 3df5ce6..8c0f4b0 100644
60275--- a/fs/reiserfs/reiserfs.h
60276+++ b/fs/reiserfs/reiserfs.h
60277@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
60278 /* Comment? -Hans */
60279 wait_queue_head_t s_wait;
60280 /* To be obsoleted soon by per buffer seals.. -Hans */
60281- atomic_t s_generation_counter; // increased by one every time the
60282+ atomic_unchecked_t s_generation_counter; // increased by one every time the
60283 // tree gets re-balanced
60284 unsigned long s_properties; /* File system properties. Currently holds
60285 on-disk FS format */
60286@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
60287 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
60288
60289 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
60290-#define get_generation(s) atomic_read (&fs_generation(s))
60291+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
60292 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
60293 #define __fs_changed(gen,s) (gen != get_generation (s))
60294 #define fs_changed(gen,s) \
60295diff --git a/fs/select.c b/fs/select.c
60296index 35d4adc7..d6c60db 100644
60297--- a/fs/select.c
60298+++ b/fs/select.c
60299@@ -20,6 +20,7 @@
60300 #include <linux/export.h>
60301 #include <linux/slab.h>
60302 #include <linux/poll.h>
60303+#include <linux/security.h>
60304 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
60305 #include <linux/file.h>
60306 #include <linux/fdtable.h>
60307@@ -881,6 +882,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
60308 struct poll_list *walk = head;
60309 unsigned long todo = nfds;
60310
60311+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
60312 if (nfds > rlimit(RLIMIT_NOFILE))
60313 return -EINVAL;
60314
60315diff --git a/fs/seq_file.c b/fs/seq_file.c
60316index 3135c25..d0395dd 100644
60317--- a/fs/seq_file.c
60318+++ b/fs/seq_file.c
60319@@ -10,6 +10,7 @@
60320 #include <linux/seq_file.h>
60321 #include <linux/slab.h>
60322 #include <linux/cred.h>
60323+#include <linux/sched.h>
60324
60325 #include <asm/uaccess.h>
60326 #include <asm/page.h>
60327@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
60328 #ifdef CONFIG_USER_NS
60329 p->user_ns = file->f_cred->user_ns;
60330 #endif
60331+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60332+ p->exec_id = current->exec_id;
60333+#endif
60334
60335 /*
60336 * Wrappers around seq_open(e.g. swaps_open) need to be
60337@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
60338 return 0;
60339 }
60340 if (!m->buf) {
60341- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
60342+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
60343 if (!m->buf)
60344 return -ENOMEM;
60345 }
60346@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
60347 Eoverflow:
60348 m->op->stop(m, p);
60349 kfree(m->buf);
60350- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
60351+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
60352 return !m->buf ? -ENOMEM : -EAGAIN;
60353 }
60354
60355@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
60356
60357 /* grab buffer if we didn't have one */
60358 if (!m->buf) {
60359- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
60360+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
60361 if (!m->buf)
60362 goto Enomem;
60363 }
60364@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
60365 goto Fill;
60366 m->op->stop(m, p);
60367 kfree(m->buf);
60368- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
60369+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
60370 if (!m->buf)
60371 goto Enomem;
60372 m->count = 0;
60373@@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
60374 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
60375 void *data)
60376 {
60377- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
60378+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
60379 int res = -ENOMEM;
60380
60381 if (op) {
60382diff --git a/fs/splice.c b/fs/splice.c
60383index 3b7ee65..87fc2e4 100644
60384--- a/fs/splice.c
60385+++ b/fs/splice.c
60386@@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
60387 pipe_lock(pipe);
60388
60389 for (;;) {
60390- if (!pipe->readers) {
60391+ if (!atomic_read(&pipe->readers)) {
60392 send_sig(SIGPIPE, current, 0);
60393 if (!ret)
60394 ret = -EPIPE;
60395@@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
60396 page_nr++;
60397 ret += buf->len;
60398
60399- if (pipe->files)
60400+ if (atomic_read(&pipe->files))
60401 do_wakeup = 1;
60402
60403 if (!--spd->nr_pages)
60404@@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
60405 do_wakeup = 0;
60406 }
60407
60408- pipe->waiting_writers++;
60409+ atomic_inc(&pipe->waiting_writers);
60410 pipe_wait(pipe);
60411- pipe->waiting_writers--;
60412+ atomic_dec(&pipe->waiting_writers);
60413 }
60414
60415 pipe_unlock(pipe);
60416@@ -565,7 +565,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
60417 old_fs = get_fs();
60418 set_fs(get_ds());
60419 /* The cast to a user pointer is valid due to the set_fs() */
60420- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
60421+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
60422 set_fs(old_fs);
60423
60424 return res;
60425@@ -580,7 +580,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
60426 old_fs = get_fs();
60427 set_fs(get_ds());
60428 /* The cast to a user pointer is valid due to the set_fs() */
60429- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
60430+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
60431 set_fs(old_fs);
60432
60433 return res;
60434@@ -633,7 +633,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
60435 goto err;
60436
60437 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
60438- vec[i].iov_base = (void __user *) page_address(page);
60439+ vec[i].iov_base = (void __force_user *) page_address(page);
60440 vec[i].iov_len = this_len;
60441 spd.pages[i] = page;
60442 spd.nr_pages++;
60443@@ -829,7 +829,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
60444 ops->release(pipe, buf);
60445 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
60446 pipe->nrbufs--;
60447- if (pipe->files)
60448+ if (atomic_read(&pipe->files))
60449 sd->need_wakeup = true;
60450 }
60451
60452@@ -854,10 +854,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
60453 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
60454 {
60455 while (!pipe->nrbufs) {
60456- if (!pipe->writers)
60457+ if (!atomic_read(&pipe->writers))
60458 return 0;
60459
60460- if (!pipe->waiting_writers && sd->num_spliced)
60461+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
60462 return 0;
60463
60464 if (sd->flags & SPLICE_F_NONBLOCK)
60465@@ -1179,7 +1179,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
60466 * out of the pipe right after the splice_to_pipe(). So set
60467 * PIPE_READERS appropriately.
60468 */
60469- pipe->readers = 1;
60470+ atomic_set(&pipe->readers, 1);
60471
60472 current->splice_pipe = pipe;
60473 }
60474@@ -1475,6 +1475,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
60475
60476 partial[buffers].offset = off;
60477 partial[buffers].len = plen;
60478+ partial[buffers].private = 0;
60479
60480 off = 0;
60481 len -= plen;
60482@@ -1777,9 +1778,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
60483 ret = -ERESTARTSYS;
60484 break;
60485 }
60486- if (!pipe->writers)
60487+ if (!atomic_read(&pipe->writers))
60488 break;
60489- if (!pipe->waiting_writers) {
60490+ if (!atomic_read(&pipe->waiting_writers)) {
60491 if (flags & SPLICE_F_NONBLOCK) {
60492 ret = -EAGAIN;
60493 break;
60494@@ -1811,7 +1812,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
60495 pipe_lock(pipe);
60496
60497 while (pipe->nrbufs >= pipe->buffers) {
60498- if (!pipe->readers) {
60499+ if (!atomic_read(&pipe->readers)) {
60500 send_sig(SIGPIPE, current, 0);
60501 ret = -EPIPE;
60502 break;
60503@@ -1824,9 +1825,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
60504 ret = -ERESTARTSYS;
60505 break;
60506 }
60507- pipe->waiting_writers++;
60508+ atomic_inc(&pipe->waiting_writers);
60509 pipe_wait(pipe);
60510- pipe->waiting_writers--;
60511+ atomic_dec(&pipe->waiting_writers);
60512 }
60513
60514 pipe_unlock(pipe);
60515@@ -1862,14 +1863,14 @@ retry:
60516 pipe_double_lock(ipipe, opipe);
60517
60518 do {
60519- if (!opipe->readers) {
60520+ if (!atomic_read(&opipe->readers)) {
60521 send_sig(SIGPIPE, current, 0);
60522 if (!ret)
60523 ret = -EPIPE;
60524 break;
60525 }
60526
60527- if (!ipipe->nrbufs && !ipipe->writers)
60528+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
60529 break;
60530
60531 /*
60532@@ -1966,7 +1967,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
60533 pipe_double_lock(ipipe, opipe);
60534
60535 do {
60536- if (!opipe->readers) {
60537+ if (!atomic_read(&opipe->readers)) {
60538 send_sig(SIGPIPE, current, 0);
60539 if (!ret)
60540 ret = -EPIPE;
60541@@ -2011,7 +2012,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
60542 * return EAGAIN if we have the potential of some data in the
60543 * future, otherwise just return 0
60544 */
60545- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
60546+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
60547 ret = -EAGAIN;
60548
60549 pipe_unlock(ipipe);
60550diff --git a/fs/stat.c b/fs/stat.c
60551index 04ce1ac..a13dd1e 100644
60552--- a/fs/stat.c
60553+++ b/fs/stat.c
60554@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
60555 stat->gid = inode->i_gid;
60556 stat->rdev = inode->i_rdev;
60557 stat->size = i_size_read(inode);
60558- stat->atime = inode->i_atime;
60559- stat->mtime = inode->i_mtime;
60560+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
60561+ stat->atime = inode->i_ctime;
60562+ stat->mtime = inode->i_ctime;
60563+ } else {
60564+ stat->atime = inode->i_atime;
60565+ stat->mtime = inode->i_mtime;
60566+ }
60567 stat->ctime = inode->i_ctime;
60568 stat->blksize = (1 << inode->i_blkbits);
60569 stat->blocks = inode->i_blocks;
60570@@ -46,8 +51,14 @@ int vfs_getattr(struct path *path, struct kstat *stat)
60571 if (retval)
60572 return retval;
60573
60574- if (inode->i_op->getattr)
60575- return inode->i_op->getattr(path->mnt, path->dentry, stat);
60576+ if (inode->i_op->getattr) {
60577+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
60578+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
60579+ stat->atime = stat->ctime;
60580+ stat->mtime = stat->ctime;
60581+ }
60582+ return retval;
60583+ }
60584
60585 generic_fillattr(inode, stat);
60586 return 0;
60587diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
60588index 15c68f9..36a8b3e 100644
60589--- a/fs/sysfs/bin.c
60590+++ b/fs/sysfs/bin.c
60591@@ -235,13 +235,13 @@ static int bin_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
60592 return ret;
60593 }
60594
60595-static int bin_access(struct vm_area_struct *vma, unsigned long addr,
60596- void *buf, int len, int write)
60597+static ssize_t bin_access(struct vm_area_struct *vma, unsigned long addr,
60598+ void *buf, size_t len, int write)
60599 {
60600 struct file *file = vma->vm_file;
60601 struct bin_buffer *bb = file->private_data;
60602 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
60603- int ret;
60604+ ssize_t ret;
60605
60606 if (!bb->vm_ops)
60607 return -EINVAL;
60608diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
60609index e068e74..92edeb8 100644
60610--- a/fs/sysfs/dir.c
60611+++ b/fs/sysfs/dir.c
60612@@ -40,7 +40,7 @@ static DEFINE_IDA(sysfs_ino_ida);
60613 *
60614 * Returns 31 bit hash of ns + name (so it fits in an off_t )
60615 */
60616-static unsigned int sysfs_name_hash(const void *ns, const char *name)
60617+static unsigned int sysfs_name_hash(const void *ns, const unsigned char *name)
60618 {
60619 unsigned long hash = init_name_hash();
60620 unsigned int len = strlen(name);
60621@@ -679,6 +679,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
60622 struct sysfs_dirent *sd;
60623 int rc;
60624
60625+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
60626+ const char *parent_name = parent_sd->s_name;
60627+
60628+ mode = S_IFDIR | S_IRWXU;
60629+
60630+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
60631+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
60632+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
60633+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
60634+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
60635+#endif
60636+
60637 /* allocate */
60638 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
60639 if (!sd)
60640diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
60641index d2bb7ed..fe8c331 100644
60642--- a/fs/sysfs/file.c
60643+++ b/fs/sysfs/file.c
60644@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
60645
60646 struct sysfs_open_dirent {
60647 atomic_t refcnt;
60648- atomic_t event;
60649+ atomic_unchecked_t event;
60650 wait_queue_head_t poll;
60651 struct list_head buffers; /* goes through sysfs_buffer.list */
60652 };
60653@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
60654 if (!sysfs_get_active(attr_sd))
60655 return -ENODEV;
60656
60657- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
60658+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
60659 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
60660
60661 sysfs_put_active(attr_sd);
60662@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
60663 return -ENOMEM;
60664
60665 atomic_set(&new_od->refcnt, 0);
60666- atomic_set(&new_od->event, 1);
60667+ atomic_set_unchecked(&new_od->event, 1);
60668 init_waitqueue_head(&new_od->poll);
60669 INIT_LIST_HEAD(&new_od->buffers);
60670 goto retry;
60671@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
60672
60673 sysfs_put_active(attr_sd);
60674
60675- if (buffer->event != atomic_read(&od->event))
60676+ if (buffer->event != atomic_read_unchecked(&od->event))
60677 goto trigger;
60678
60679 return DEFAULT_POLLMASK;
60680@@ -452,7 +452,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
60681 if (!WARN_ON(sysfs_type(sd) != SYSFS_KOBJ_ATTR)) {
60682 od = sd->s_attr.open;
60683 if (od) {
60684- atomic_inc(&od->event);
60685+ atomic_inc_unchecked(&od->event);
60686 wake_up_interruptible(&od->poll);
60687 }
60688 }
60689diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
60690index 8c940df..25b733e 100644
60691--- a/fs/sysfs/symlink.c
60692+++ b/fs/sysfs/symlink.c
60693@@ -305,7 +305,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
60694
60695 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
60696 {
60697- char *page = nd_get_link(nd);
60698+ const char *page = nd_get_link(nd);
60699 if (!IS_ERR(page))
60700 free_page((unsigned long)page);
60701 }
60702diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
60703index 69d4889..a810bd4 100644
60704--- a/fs/sysv/sysv.h
60705+++ b/fs/sysv/sysv.h
60706@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
60707 #endif
60708 }
60709
60710-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
60711+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
60712 {
60713 if (sbi->s_bytesex == BYTESEX_PDP)
60714 return PDP_swab((__force __u32)n);
60715diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
60716index e18b988..f1d4ad0f 100644
60717--- a/fs/ubifs/io.c
60718+++ b/fs/ubifs/io.c
60719@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
60720 return err;
60721 }
60722
60723-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
60724+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
60725 {
60726 int err;
60727
60728diff --git a/fs/udf/misc.c b/fs/udf/misc.c
60729index c175b4d..8f36a16 100644
60730--- a/fs/udf/misc.c
60731+++ b/fs/udf/misc.c
60732@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
60733
60734 u8 udf_tag_checksum(const struct tag *t)
60735 {
60736- u8 *data = (u8 *)t;
60737+ const u8 *data = (const u8 *)t;
60738 u8 checksum = 0;
60739 int i;
60740 for (i = 0; i < sizeof(struct tag); ++i)
60741diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
60742index 8d974c4..b82f6ec 100644
60743--- a/fs/ufs/swab.h
60744+++ b/fs/ufs/swab.h
60745@@ -22,7 +22,7 @@ enum {
60746 BYTESEX_BE
60747 };
60748
60749-static inline u64
60750+static inline u64 __intentional_overflow(-1)
60751 fs64_to_cpu(struct super_block *sbp, __fs64 n)
60752 {
60753 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
60754@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
60755 return (__force __fs64)cpu_to_be64(n);
60756 }
60757
60758-static inline u32
60759+static inline u32 __intentional_overflow(-1)
60760 fs32_to_cpu(struct super_block *sbp, __fs32 n)
60761 {
60762 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
60763diff --git a/fs/utimes.c b/fs/utimes.c
60764index f4fb7ec..3fe03c0 100644
60765--- a/fs/utimes.c
60766+++ b/fs/utimes.c
60767@@ -1,6 +1,7 @@
60768 #include <linux/compiler.h>
60769 #include <linux/file.h>
60770 #include <linux/fs.h>
60771+#include <linux/security.h>
60772 #include <linux/linkage.h>
60773 #include <linux/mount.h>
60774 #include <linux/namei.h>
60775@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
60776 goto mnt_drop_write_and_out;
60777 }
60778 }
60779+
60780+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
60781+ error = -EACCES;
60782+ goto mnt_drop_write_and_out;
60783+ }
60784+
60785 mutex_lock(&inode->i_mutex);
60786 error = notify_change(path->dentry, &newattrs);
60787 mutex_unlock(&inode->i_mutex);
60788diff --git a/fs/xattr.c b/fs/xattr.c
60789index 3377dff..4d074d9 100644
60790--- a/fs/xattr.c
60791+++ b/fs/xattr.c
60792@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
60793 return rc;
60794 }
60795
60796+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
60797+ssize_t
60798+pax_getxattr(struct dentry *dentry, void *value, size_t size)
60799+{
60800+ struct inode *inode = dentry->d_inode;
60801+ ssize_t error;
60802+
60803+ error = inode_permission(inode, MAY_EXEC);
60804+ if (error)
60805+ return error;
60806+
60807+ if (inode->i_op->getxattr)
60808+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
60809+ else
60810+ error = -EOPNOTSUPP;
60811+
60812+ return error;
60813+}
60814+EXPORT_SYMBOL(pax_getxattr);
60815+#endif
60816+
60817 ssize_t
60818 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
60819 {
60820@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
60821 * Extended attribute SET operations
60822 */
60823 static long
60824-setxattr(struct dentry *d, const char __user *name, const void __user *value,
60825+setxattr(struct path *path, const char __user *name, const void __user *value,
60826 size_t size, int flags)
60827 {
60828 int error;
60829@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
60830 posix_acl_fix_xattr_from_user(kvalue, size);
60831 }
60832
60833- error = vfs_setxattr(d, kname, kvalue, size, flags);
60834+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
60835+ error = -EACCES;
60836+ goto out;
60837+ }
60838+
60839+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
60840 out:
60841 if (vvalue)
60842 vfree(vvalue);
60843@@ -377,7 +403,7 @@ retry:
60844 return error;
60845 error = mnt_want_write(path.mnt);
60846 if (!error) {
60847- error = setxattr(path.dentry, name, value, size, flags);
60848+ error = setxattr(&path, name, value, size, flags);
60849 mnt_drop_write(path.mnt);
60850 }
60851 path_put(&path);
60852@@ -401,7 +427,7 @@ retry:
60853 return error;
60854 error = mnt_want_write(path.mnt);
60855 if (!error) {
60856- error = setxattr(path.dentry, name, value, size, flags);
60857+ error = setxattr(&path, name, value, size, flags);
60858 mnt_drop_write(path.mnt);
60859 }
60860 path_put(&path);
60861@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
60862 const void __user *,value, size_t, size, int, flags)
60863 {
60864 struct fd f = fdget(fd);
60865- struct dentry *dentry;
60866 int error = -EBADF;
60867
60868 if (!f.file)
60869 return error;
60870- dentry = f.file->f_path.dentry;
60871- audit_inode(NULL, dentry, 0);
60872+ audit_inode(NULL, f.file->f_path.dentry, 0);
60873 error = mnt_want_write_file(f.file);
60874 if (!error) {
60875- error = setxattr(dentry, name, value, size, flags);
60876+ error = setxattr(&f.file->f_path, name, value, size, flags);
60877 mnt_drop_write_file(f.file);
60878 }
60879 fdput(f);
60880diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
60881index 9fbea87..6b19972 100644
60882--- a/fs/xattr_acl.c
60883+++ b/fs/xattr_acl.c
60884@@ -76,8 +76,8 @@ struct posix_acl *
60885 posix_acl_from_xattr(struct user_namespace *user_ns,
60886 const void *value, size_t size)
60887 {
60888- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
60889- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
60890+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
60891+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
60892 int count;
60893 struct posix_acl *acl;
60894 struct posix_acl_entry *acl_e;
60895diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
60896index 05c698c..6b918af 100644
60897--- a/fs/xfs/xfs_bmap.c
60898+++ b/fs/xfs/xfs_bmap.c
60899@@ -765,7 +765,7 @@ xfs_bmap_validate_ret(
60900
60901 #else
60902 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
60903-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
60904+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
60905 #endif /* DEBUG */
60906
60907 /*
60908diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
60909index 97676a3..399a75d 100644
60910--- a/fs/xfs/xfs_dir2_sf.c
60911+++ b/fs/xfs/xfs_dir2_sf.c
60912@@ -848,7 +848,12 @@ xfs_dir2_sf_getdents(
60913
60914 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
60915 ctx->pos = off & 0x7fffffff;
60916- if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen,
60917+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
60918+ char name[sfep->namelen];
60919+ memcpy(name, sfep->name, sfep->namelen);
60920+ if (!dir_emit(ctx, name, sfep->namelen, ino, DT_UNKNOWN))
60921+ return 0;
60922+ } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen,
60923 ino, DT_UNKNOWN))
60924 return 0;
60925 sfep = xfs_dir2_sf_nextentry(sfp, sfep);
60926diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
60927index 6e2bca5..6ce80d3 100644
60928--- a/fs/xfs/xfs_ioctl.c
60929+++ b/fs/xfs/xfs_ioctl.c
60930@@ -127,7 +127,7 @@ xfs_find_handle(
60931 }
60932
60933 error = -EFAULT;
60934- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
60935+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
60936 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
60937 goto out_put;
60938
60939diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
60940index 96dda62..d6c6a52 100644
60941--- a/fs/xfs/xfs_iops.c
60942+++ b/fs/xfs/xfs_iops.c
60943@@ -395,7 +395,7 @@ xfs_vn_put_link(
60944 struct nameidata *nd,
60945 void *p)
60946 {
60947- char *s = nd_get_link(nd);
60948+ const char *s = nd_get_link(nd);
60949
60950 if (!IS_ERR(s))
60951 kfree(s);
60952diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
60953new file mode 100644
60954index 0000000..0fd7c82
60955--- /dev/null
60956+++ b/grsecurity/Kconfig
60957@@ -0,0 +1,1080 @@
60958+#
60959+# grecurity configuration
60960+#
60961+menu "Memory Protections"
60962+depends on GRKERNSEC
60963+
60964+config GRKERNSEC_KMEM
60965+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
60966+ default y if GRKERNSEC_CONFIG_AUTO
60967+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
60968+ help
60969+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
60970+ be written to or read from to modify or leak the contents of the running
60971+ kernel. /dev/port will also not be allowed to be opened and support
60972+ for /dev/cpu/*/msr will be removed. If you have module
60973+ support disabled, enabling this will close up five ways that are
60974+ currently used to insert malicious code into the running kernel.
60975+
60976+ Even with all these features enabled, we still highly recommend that
60977+ you use the RBAC system, as it is still possible for an attacker to
60978+ modify the running kernel through privileged I/O granted by ioperm/iopl.
60979+
60980+ If you are not using XFree86, you may be able to stop this additional
60981+ case by enabling the 'Disable privileged I/O' option. Though nothing
60982+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
60983+ but only to video memory, which is the only writing we allow in this
60984+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
60985+ not be allowed to mprotect it with PROT_WRITE later.
60986+ Enabling this feature will prevent the "cpupower" and "powertop" tools
60987+ from working.
60988+
60989+ It is highly recommended that you say Y here if you meet all the
60990+ conditions above.
60991+
60992+config GRKERNSEC_VM86
60993+ bool "Restrict VM86 mode"
60994+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
60995+ depends on X86_32
60996+
60997+ help
60998+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
60999+ make use of a special execution mode on 32bit x86 processors called
61000+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
61001+ video cards and will still work with this option enabled. The purpose
61002+ of the option is to prevent exploitation of emulation errors in
61003+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
61004+ Nearly all users should be able to enable this option.
61005+
61006+config GRKERNSEC_IO
61007+ bool "Disable privileged I/O"
61008+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
61009+ depends on X86
61010+ select RTC_CLASS
61011+ select RTC_INTF_DEV
61012+ select RTC_DRV_CMOS
61013+
61014+ help
61015+ If you say Y here, all ioperm and iopl calls will return an error.
61016+ Ioperm and iopl can be used to modify the running kernel.
61017+ Unfortunately, some programs need this access to operate properly,
61018+ the most notable of which are XFree86 and hwclock. hwclock can be
61019+ remedied by having RTC support in the kernel, so real-time
61020+ clock support is enabled if this option is enabled, to ensure
61021+ that hwclock operates correctly. XFree86 still will not
61022+ operate correctly with this option enabled, so DO NOT CHOOSE Y
61023+ IF YOU USE XFree86. If you use XFree86 and you still want to
61024+ protect your kernel against modification, use the RBAC system.
61025+
61026+config GRKERNSEC_JIT_HARDEN
61027+ bool "Harden BPF JIT against spray attacks"
61028+ default y if GRKERNSEC_CONFIG_AUTO
61029+ depends on BPF_JIT
61030+ help
61031+ If you say Y here, the native code generated by the kernel's Berkeley
61032+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
61033+ attacks that attempt to fit attacker-beneficial instructions in
61034+ 32bit immediate fields of JIT-generated native instructions. The
61035+ attacker will generally aim to cause an unintended instruction sequence
61036+ of JIT-generated native code to execute by jumping into the middle of
61037+ a generated instruction. This feature effectively randomizes the 32bit
61038+ immediate constants present in the generated code to thwart such attacks.
61039+
61040+ If you're using KERNEXEC, it's recommended that you enable this option
61041+ to supplement the hardening of the kernel.
61042+
61043+config GRKERNSEC_PERF_HARDEN
61044+ bool "Disable unprivileged PERF_EVENTS usage by default"
61045+ default y if GRKERNSEC_CONFIG_AUTO
61046+ depends on PERF_EVENTS
61047+ help
61048+ If you say Y here, the range of acceptable values for the
61049+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
61050+ default to a new value: 3. When the sysctl is set to this value, no
61051+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
61052+
61053+ Though PERF_EVENTS can be used legitimately for performance monitoring
61054+ and low-level application profiling, it is forced on regardless of
61055+ configuration, has been at fault for several vulnerabilities, and
61056+ creates new opportunities for side channels and other information leaks.
61057+
61058+ This feature puts PERF_EVENTS into a secure default state and permits
61059+ the administrator to change out of it temporarily if unprivileged
61060+ application profiling is needed.
61061+
61062+config GRKERNSEC_RAND_THREADSTACK
61063+ bool "Insert random gaps between thread stacks"
61064+ default y if GRKERNSEC_CONFIG_AUTO
61065+ depends on PAX_RANDMMAP && !PPC
61066+ help
61067+ If you say Y here, a random-sized gap will be enforced between allocated
61068+ thread stacks. Glibc's NPTL and other threading libraries that
61069+ pass MAP_STACK to the kernel for thread stack allocation are supported.
61070+ The implementation currently provides 8 bits of entropy for the gap.
61071+
61072+ Many distributions do not compile threaded remote services with the
61073+ -fstack-check argument to GCC, causing the variable-sized stack-based
61074+ allocator, alloca(), to not probe the stack on allocation. This
61075+ permits an unbounded alloca() to skip over any guard page and potentially
61076+ modify another thread's stack reliably. An enforced random gap
61077+ reduces the reliability of such an attack and increases the chance
61078+ that such a read/write to another thread's stack instead lands in
61079+ an unmapped area, causing a crash and triggering grsecurity's
61080+ anti-bruteforcing logic.
61081+
61082+config GRKERNSEC_PROC_MEMMAP
61083+ bool "Harden ASLR against information leaks and entropy reduction"
61084+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
61085+ depends on PAX_NOEXEC || PAX_ASLR
61086+ help
61087+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
61088+ give no information about the addresses of its mappings if
61089+ PaX features that rely on random addresses are enabled on the task.
61090+ In addition to sanitizing this information and disabling other
61091+ dangerous sources of information, this option causes reads of sensitive
61092+ /proc/<pid> entries where the file descriptor was opened in a different
61093+ task than the one performing the read. Such attempts are logged.
61094+ This option also limits argv/env strings for suid/sgid binaries
61095+ to 512KB to prevent a complete exhaustion of the stack entropy provided
61096+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
61097+ binaries to prevent alternative mmap layouts from being abused.
61098+
61099+ If you use PaX it is essential that you say Y here as it closes up
61100+ several holes that make full ASLR useless locally.
61101+
61102+config GRKERNSEC_BRUTE
61103+ bool "Deter exploit bruteforcing"
61104+ default y if GRKERNSEC_CONFIG_AUTO
61105+ help
61106+ If you say Y here, attempts to bruteforce exploits against forking
61107+ daemons such as apache or sshd, as well as against suid/sgid binaries
61108+ will be deterred. When a child of a forking daemon is killed by PaX
61109+ or crashes due to an illegal instruction or other suspicious signal,
61110+ the parent process will be delayed 30 seconds upon every subsequent
61111+ fork until the administrator is able to assess the situation and
61112+ restart the daemon.
61113+ In the suid/sgid case, the attempt is logged, the user has all their
61114+ existing instances of the suid/sgid binary terminated and will
61115+ be unable to execute any suid/sgid binaries for 15 minutes.
61116+
61117+ It is recommended that you also enable signal logging in the auditing
61118+ section so that logs are generated when a process triggers a suspicious
61119+ signal.
61120+ If the sysctl option is enabled, a sysctl option with name
61121+ "deter_bruteforce" is created.
61122+
61123+
61124+config GRKERNSEC_MODHARDEN
61125+ bool "Harden module auto-loading"
61126+ default y if GRKERNSEC_CONFIG_AUTO
61127+ depends on MODULES
61128+ help
61129+ If you say Y here, module auto-loading in response to use of some
61130+ feature implemented by an unloaded module will be restricted to
61131+ root users. Enabling this option helps defend against attacks
61132+ by unprivileged users who abuse the auto-loading behavior to
61133+ cause a vulnerable module to load that is then exploited.
61134+
61135+ If this option prevents a legitimate use of auto-loading for a
61136+ non-root user, the administrator can execute modprobe manually
61137+ with the exact name of the module mentioned in the alert log.
61138+ Alternatively, the administrator can add the module to the list
61139+ of modules loaded at boot by modifying init scripts.
61140+
61141+ Modification of init scripts will most likely be needed on
61142+ Ubuntu servers with encrypted home directory support enabled,
61143+ as the first non-root user logging in will cause the ecb(aes),
61144+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
61145+
61146+config GRKERNSEC_HIDESYM
61147+ bool "Hide kernel symbols"
61148+ default y if GRKERNSEC_CONFIG_AUTO
61149+ select PAX_USERCOPY_SLABS
61150+ help
61151+ If you say Y here, getting information on loaded modules, and
61152+ displaying all kernel symbols through a syscall will be restricted
61153+ to users with CAP_SYS_MODULE. For software compatibility reasons,
61154+ /proc/kallsyms will be restricted to the root user. The RBAC
61155+ system can hide that entry even from root.
61156+
61157+ This option also prevents leaking of kernel addresses through
61158+ several /proc entries.
61159+
61160+ Note that this option is only effective provided the following
61161+ conditions are met:
61162+ 1) The kernel using grsecurity is not precompiled by some distribution
61163+ 2) You have also enabled GRKERNSEC_DMESG
61164+ 3) You are using the RBAC system and hiding other files such as your
61165+ kernel image and System.map. Alternatively, enabling this option
61166+ causes the permissions on /boot, /lib/modules, and the kernel
61167+ source directory to change at compile time to prevent
61168+ reading by non-root users.
61169+ If the above conditions are met, this option will aid in providing a
61170+ useful protection against local kernel exploitation of overflows
61171+ and arbitrary read/write vulnerabilities.
61172+
61173+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
61174+ in addition to this feature.
61175+
61176+config GRKERNSEC_KERN_LOCKOUT
61177+ bool "Active kernel exploit response"
61178+ default y if GRKERNSEC_CONFIG_AUTO
61179+ depends on X86 || ARM || PPC || SPARC
61180+ help
61181+ If you say Y here, when a PaX alert is triggered due to suspicious
61182+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
61183+ or an OOPS occurs due to bad memory accesses, instead of just
61184+ terminating the offending process (and potentially allowing
61185+ a subsequent exploit from the same user), we will take one of two
61186+ actions:
61187+ If the user was root, we will panic the system
61188+ If the user was non-root, we will log the attempt, terminate
61189+ all processes owned by the user, then prevent them from creating
61190+ any new processes until the system is restarted
61191+ This deters repeated kernel exploitation/bruteforcing attempts
61192+ and is useful for later forensics.
61193+
61194+endmenu
61195+menu "Role Based Access Control Options"
61196+depends on GRKERNSEC
61197+
61198+config GRKERNSEC_RBAC_DEBUG
61199+ bool
61200+
61201+config GRKERNSEC_NO_RBAC
61202+ bool "Disable RBAC system"
61203+ help
61204+ If you say Y here, the /dev/grsec device will be removed from the kernel,
61205+ preventing the RBAC system from being enabled. You should only say Y
61206+ here if you have no intention of using the RBAC system, so as to prevent
61207+ an attacker with root access from misusing the RBAC system to hide files
61208+ and processes when loadable module support and /dev/[k]mem have been
61209+ locked down.
61210+
61211+config GRKERNSEC_ACL_HIDEKERN
61212+ bool "Hide kernel processes"
61213+ help
61214+ If you say Y here, all kernel threads will be hidden to all
61215+ processes but those whose subject has the "view hidden processes"
61216+ flag.
61217+
61218+config GRKERNSEC_ACL_MAXTRIES
61219+ int "Maximum tries before password lockout"
61220+ default 3
61221+ help
61222+ This option enforces the maximum number of times a user can attempt
61223+ to authorize themselves with the grsecurity RBAC system before being
61224+ denied the ability to attempt authorization again for a specified time.
61225+ The lower the number, the harder it will be to brute-force a password.
61226+
61227+config GRKERNSEC_ACL_TIMEOUT
61228+ int "Time to wait after max password tries, in seconds"
61229+ default 30
61230+ help
61231+ This option specifies the time the user must wait after attempting to
61232+ authorize to the RBAC system with the maximum number of invalid
61233+ passwords. The higher the number, the harder it will be to brute-force
61234+ a password.
61235+
61236+endmenu
61237+menu "Filesystem Protections"
61238+depends on GRKERNSEC
61239+
61240+config GRKERNSEC_PROC
61241+ bool "Proc restrictions"
61242+ default y if GRKERNSEC_CONFIG_AUTO
61243+ help
61244+ If you say Y here, the permissions of the /proc filesystem
61245+ will be altered to enhance system security and privacy. You MUST
61246+ choose either a user only restriction or a user and group restriction.
61247+ Depending upon the option you choose, you can either restrict users to
61248+ see only the processes they themselves run, or choose a group that can
61249+ view all processes and files normally restricted to root if you choose
61250+ the "restrict to user only" option. NOTE: If you're running identd or
61251+ ntpd as a non-root user, you will have to run it as the group you
61252+ specify here.
61253+
61254+config GRKERNSEC_PROC_USER
61255+ bool "Restrict /proc to user only"
61256+ depends on GRKERNSEC_PROC
61257+ help
61258+ If you say Y here, non-root users will only be able to view their own
61259+ processes, and restricts them from viewing network-related information,
61260+ and viewing kernel symbol and module information.
61261+
61262+config GRKERNSEC_PROC_USERGROUP
61263+ bool "Allow special group"
61264+ default y if GRKERNSEC_CONFIG_AUTO
61265+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
61266+ help
61267+ If you say Y here, you will be able to select a group that will be
61268+ able to view all processes and network-related information. If you've
61269+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
61270+ remain hidden. This option is useful if you want to run identd as
61271+ a non-root user. The group you select may also be chosen at boot time
61272+ via "grsec_proc_gid=" on the kernel commandline.
61273+
61274+config GRKERNSEC_PROC_GID
61275+ int "GID for special group"
61276+ depends on GRKERNSEC_PROC_USERGROUP
61277+ default 1001
61278+
61279+config GRKERNSEC_PROC_ADD
61280+ bool "Additional restrictions"
61281+ default y if GRKERNSEC_CONFIG_AUTO
61282+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
61283+ help
61284+ If you say Y here, additional restrictions will be placed on
61285+ /proc that keep normal users from viewing device information and
61286+ slabinfo information that could be useful for exploits.
61287+
61288+config GRKERNSEC_LINK
61289+ bool "Linking restrictions"
61290+ default y if GRKERNSEC_CONFIG_AUTO
61291+ help
61292+ If you say Y here, /tmp race exploits will be prevented, since users
61293+ will no longer be able to follow symlinks owned by other users in
61294+ world-writable +t directories (e.g. /tmp), unless the owner of the
61295+ symlink is the owner of the directory. users will also not be
61296+ able to hardlink to files they do not own. If the sysctl option is
61297+ enabled, a sysctl option with name "linking_restrictions" is created.
61298+
61299+config GRKERNSEC_SYMLINKOWN
61300+ bool "Kernel-enforced SymlinksIfOwnerMatch"
61301+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
61302+ help
61303+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
61304+ that prevents it from being used as a security feature. As Apache
61305+ verifies the symlink by performing a stat() against the target of
61306+ the symlink before it is followed, an attacker can setup a symlink
61307+ to point to a same-owned file, then replace the symlink with one
61308+ that targets another user's file just after Apache "validates" the
61309+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
61310+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
61311+ will be in place for the group you specify. If the sysctl option
61312+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
61313+ created.
61314+
61315+config GRKERNSEC_SYMLINKOWN_GID
61316+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
61317+ depends on GRKERNSEC_SYMLINKOWN
61318+ default 1006
61319+ help
61320+ Setting this GID determines what group kernel-enforced
61321+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
61322+ is enabled, a sysctl option with name "symlinkown_gid" is created.
61323+
61324+config GRKERNSEC_FIFO
61325+ bool "FIFO restrictions"
61326+ default y if GRKERNSEC_CONFIG_AUTO
61327+ help
61328+ If you say Y here, users will not be able to write to FIFOs they don't
61329+ own in world-writable +t directories (e.g. /tmp), unless the owner of
61330+ the FIFO is the same owner of the directory it's held in. If the sysctl
61331+ option is enabled, a sysctl option with name "fifo_restrictions" is
61332+ created.
61333+
61334+config GRKERNSEC_SYSFS_RESTRICT
61335+ bool "Sysfs/debugfs restriction"
61336+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
61337+ depends on SYSFS
61338+ help
61339+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
61340+ any filesystem normally mounted under it (e.g. debugfs) will be
61341+ mostly accessible only by root. These filesystems generally provide access
61342+ to hardware and debug information that isn't appropriate for unprivileged
61343+ users of the system. Sysfs and debugfs have also become a large source
61344+ of new vulnerabilities, ranging from infoleaks to local compromise.
61345+ There has been very little oversight with an eye toward security involved
61346+ in adding new exporters of information to these filesystems, so their
61347+ use is discouraged.
61348+ For reasons of compatibility, a few directories have been whitelisted
61349+ for access by non-root users:
61350+ /sys/fs/selinux
61351+ /sys/fs/fuse
61352+ /sys/devices/system/cpu
61353+
61354+config GRKERNSEC_ROFS
61355+ bool "Runtime read-only mount protection"
61356+ depends on SYSCTL
61357+ help
61358+ If you say Y here, a sysctl option with name "romount_protect" will
61359+ be created. By setting this option to 1 at runtime, filesystems
61360+ will be protected in the following ways:
61361+ * No new writable mounts will be allowed
61362+ * Existing read-only mounts won't be able to be remounted read/write
61363+ * Write operations will be denied on all block devices
61364+ This option acts independently of grsec_lock: once it is set to 1,
61365+ it cannot be turned off. Therefore, please be mindful of the resulting
61366+ behavior if this option is enabled in an init script on a read-only
61367+ filesystem. This feature is mainly intended for secure embedded systems.
61368+
61369+config GRKERNSEC_DEVICE_SIDECHANNEL
61370+ bool "Eliminate stat/notify-based device sidechannels"
61371+ default y if GRKERNSEC_CONFIG_AUTO
61372+ help
61373+ If you say Y here, timing analyses on block or character
61374+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
61375+ will be thwarted for unprivileged users. If a process without
61376+ CAP_MKNOD stats such a device, the last access and last modify times
61377+ will match the device's create time. No access or modify events
61378+ will be triggered through inotify/dnotify/fanotify for such devices.
61379+ This feature will prevent attacks that may at a minimum
61380+ allow an attacker to determine the administrator's password length.
61381+
61382+config GRKERNSEC_CHROOT
61383+ bool "Chroot jail restrictions"
61384+ default y if GRKERNSEC_CONFIG_AUTO
61385+ help
61386+ If you say Y here, you will be able to choose several options that will
61387+ make breaking out of a chrooted jail much more difficult. If you
61388+ encounter no software incompatibilities with the following options, it
61389+ is recommended that you enable each one.
61390+
61391+config GRKERNSEC_CHROOT_MOUNT
61392+ bool "Deny mounts"
61393+ default y if GRKERNSEC_CONFIG_AUTO
61394+ depends on GRKERNSEC_CHROOT
61395+ help
61396+ If you say Y here, processes inside a chroot will not be able to
61397+ mount or remount filesystems. If the sysctl option is enabled, a
61398+ sysctl option with name "chroot_deny_mount" is created.
61399+
61400+config GRKERNSEC_CHROOT_DOUBLE
61401+ bool "Deny double-chroots"
61402+ default y if GRKERNSEC_CONFIG_AUTO
61403+ depends on GRKERNSEC_CHROOT
61404+ help
61405+ If you say Y here, processes inside a chroot will not be able to chroot
61406+ again outside the chroot. This is a widely used method of breaking
61407+ out of a chroot jail and should not be allowed. If the sysctl
61408+ option is enabled, a sysctl option with name
61409+ "chroot_deny_chroot" is created.
61410+
61411+config GRKERNSEC_CHROOT_PIVOT
61412+ bool "Deny pivot_root in chroot"
61413+ default y if GRKERNSEC_CONFIG_AUTO
61414+ depends on GRKERNSEC_CHROOT
61415+ help
61416+ If you say Y here, processes inside a chroot will not be able to use
61417+ a function called pivot_root() that was introduced in Linux 2.3.41. It
61418+ works similar to chroot in that it changes the root filesystem. This
61419+ function could be misused in a chrooted process to attempt to break out
61420+ of the chroot, and therefore should not be allowed. If the sysctl
61421+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
61422+ created.
61423+
61424+config GRKERNSEC_CHROOT_CHDIR
61425+ bool "Enforce chdir(\"/\") on all chroots"
61426+ default y if GRKERNSEC_CONFIG_AUTO
61427+ depends on GRKERNSEC_CHROOT
61428+ help
61429+ If you say Y here, the current working directory of all newly-chrooted
61430+ applications will be set to the the root directory of the chroot.
61431+ The man page on chroot(2) states:
61432+ Note that this call does not change the current working
61433+ directory, so that `.' can be outside the tree rooted at
61434+ `/'. In particular, the super-user can escape from a
61435+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
61436+
61437+ It is recommended that you say Y here, since it's not known to break
61438+ any software. If the sysctl option is enabled, a sysctl option with
61439+ name "chroot_enforce_chdir" is created.
61440+
61441+config GRKERNSEC_CHROOT_CHMOD
61442+ bool "Deny (f)chmod +s"
61443+ default y if GRKERNSEC_CONFIG_AUTO
61444+ depends on GRKERNSEC_CHROOT
61445+ help
61446+ If you say Y here, processes inside a chroot will not be able to chmod
61447+ or fchmod files to make them have suid or sgid bits. This protects
61448+ against another published method of breaking a chroot. If the sysctl
61449+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
61450+ created.
61451+
61452+config GRKERNSEC_CHROOT_FCHDIR
61453+ bool "Deny fchdir out of chroot"
61454+ default y if GRKERNSEC_CONFIG_AUTO
61455+ depends on GRKERNSEC_CHROOT
61456+ help
61457+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
61458+ to a file descriptor of the chrooting process that points to a directory
61459+ outside the filesystem will be stopped. If the sysctl option
61460+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
61461+
61462+config GRKERNSEC_CHROOT_MKNOD
61463+ bool "Deny mknod"
61464+ default y if GRKERNSEC_CONFIG_AUTO
61465+ depends on GRKERNSEC_CHROOT
61466+ help
61467+ If you say Y here, processes inside a chroot will not be allowed to
61468+ mknod. The problem with using mknod inside a chroot is that it
61469+ would allow an attacker to create a device entry that is the same
61470+ as one on the physical root of your system, which could range from
61471+ anything from the console device to a device for your harddrive (which
61472+ they could then use to wipe the drive or steal data). It is recommended
61473+ that you say Y here, unless you run into software incompatibilities.
61474+ If the sysctl option is enabled, a sysctl option with name
61475+ "chroot_deny_mknod" is created.
61476+
61477+config GRKERNSEC_CHROOT_SHMAT
61478+ bool "Deny shmat() out of chroot"
61479+ default y if GRKERNSEC_CONFIG_AUTO
61480+ depends on GRKERNSEC_CHROOT
61481+ help
61482+ If you say Y here, processes inside a chroot will not be able to attach
61483+ to shared memory segments that were created outside of the chroot jail.
61484+ It is recommended that you say Y here. If the sysctl option is enabled,
61485+ a sysctl option with name "chroot_deny_shmat" is created.
61486+
61487+config GRKERNSEC_CHROOT_UNIX
61488+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
61489+ default y if GRKERNSEC_CONFIG_AUTO
61490+ depends on GRKERNSEC_CHROOT
61491+ help
61492+ If you say Y here, processes inside a chroot will not be able to
61493+ connect to abstract (meaning not belonging to a filesystem) Unix
61494+ domain sockets that were bound outside of a chroot. It is recommended
61495+ that you say Y here. If the sysctl option is enabled, a sysctl option
61496+ with name "chroot_deny_unix" is created.
61497+
61498+config GRKERNSEC_CHROOT_FINDTASK
61499+ bool "Protect outside processes"
61500+ default y if GRKERNSEC_CONFIG_AUTO
61501+ depends on GRKERNSEC_CHROOT
61502+ help
61503+ If you say Y here, processes inside a chroot will not be able to
61504+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
61505+ getsid, or view any process outside of the chroot. If the sysctl
61506+ option is enabled, a sysctl option with name "chroot_findtask" is
61507+ created.
61508+
61509+config GRKERNSEC_CHROOT_NICE
61510+ bool "Restrict priority changes"
61511+ default y if GRKERNSEC_CONFIG_AUTO
61512+ depends on GRKERNSEC_CHROOT
61513+ help
61514+ If you say Y here, processes inside a chroot will not be able to raise
61515+ the priority of processes in the chroot, or alter the priority of
61516+ processes outside the chroot. This provides more security than simply
61517+ removing CAP_SYS_NICE from the process' capability set. If the
61518+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
61519+ is created.
61520+
61521+config GRKERNSEC_CHROOT_SYSCTL
61522+ bool "Deny sysctl writes"
61523+ default y if GRKERNSEC_CONFIG_AUTO
61524+ depends on GRKERNSEC_CHROOT
61525+ help
61526+ If you say Y here, an attacker in a chroot will not be able to
61527+ write to sysctl entries, either by sysctl(2) or through a /proc
61528+ interface. It is strongly recommended that you say Y here. If the
61529+ sysctl option is enabled, a sysctl option with name
61530+ "chroot_deny_sysctl" is created.
61531+
61532+config GRKERNSEC_CHROOT_CAPS
61533+ bool "Capability restrictions"
61534+ default y if GRKERNSEC_CONFIG_AUTO
61535+ depends on GRKERNSEC_CHROOT
61536+ help
61537+ If you say Y here, the capabilities on all processes within a
61538+ chroot jail will be lowered to stop module insertion, raw i/o,
61539+ system and net admin tasks, rebooting the system, modifying immutable
61540+ files, modifying IPC owned by another, and changing the system time.
61541+ This is left an option because it can break some apps. Disable this
61542+ if your chrooted apps are having problems performing those kinds of
61543+ tasks. If the sysctl option is enabled, a sysctl option with
61544+ name "chroot_caps" is created.
61545+
61546+config GRKERNSEC_CHROOT_INITRD
61547+ bool "Exempt initrd tasks from restrictions"
61548+ default y if GRKERNSEC_CONFIG_AUTO
61549+ depends on GRKERNSEC_CHROOT && BLK_DEV_RAM
61550+ help
61551+ If you say Y here, tasks started prior to init will be exempted from
61552+ grsecurity's chroot restrictions. This option is mainly meant to
61553+ resolve Plymouth's performing privileged operations unnecessarily
61554+ in a chroot.
61555+
61556+endmenu
61557+menu "Kernel Auditing"
61558+depends on GRKERNSEC
61559+
61560+config GRKERNSEC_AUDIT_GROUP
61561+ bool "Single group for auditing"
61562+ help
61563+ If you say Y here, the exec and chdir logging features will only operate
61564+ on a group you specify. This option is recommended if you only want to
61565+ watch certain users instead of having a large amount of logs from the
61566+ entire system. If the sysctl option is enabled, a sysctl option with
61567+ name "audit_group" is created.
61568+
61569+config GRKERNSEC_AUDIT_GID
61570+ int "GID for auditing"
61571+ depends on GRKERNSEC_AUDIT_GROUP
61572+ default 1007
61573+
61574+config GRKERNSEC_EXECLOG
61575+ bool "Exec logging"
61576+ help
61577+ If you say Y here, all execve() calls will be logged (since the
61578+ other exec*() calls are frontends to execve(), all execution
61579+ will be logged). Useful for shell-servers that like to keep track
61580+ of their users. If the sysctl option is enabled, a sysctl option with
61581+ name "exec_logging" is created.
61582+ WARNING: This option when enabled will produce a LOT of logs, especially
61583+ on an active system.
61584+
61585+config GRKERNSEC_RESLOG
61586+ bool "Resource logging"
61587+ default y if GRKERNSEC_CONFIG_AUTO
61588+ help
61589+ If you say Y here, all attempts to overstep resource limits will
61590+ be logged with the resource name, the requested size, and the current
61591+ limit. It is highly recommended that you say Y here. If the sysctl
61592+ option is enabled, a sysctl option with name "resource_logging" is
61593+ created. If the RBAC system is enabled, the sysctl value is ignored.
61594+
61595+config GRKERNSEC_CHROOT_EXECLOG
61596+ bool "Log execs within chroot"
61597+ help
61598+ If you say Y here, all executions inside a chroot jail will be logged
61599+ to syslog. This can cause a large amount of logs if certain
61600+ applications (eg. djb's daemontools) are installed on the system, and
61601+ is therefore left as an option. If the sysctl option is enabled, a
61602+ sysctl option with name "chroot_execlog" is created.
61603+
61604+config GRKERNSEC_AUDIT_PTRACE
61605+ bool "Ptrace logging"
61606+ help
61607+ If you say Y here, all attempts to attach to a process via ptrace
61608+ will be logged. If the sysctl option is enabled, a sysctl option
61609+ with name "audit_ptrace" is created.
61610+
61611+config GRKERNSEC_AUDIT_CHDIR
61612+ bool "Chdir logging"
61613+ help
61614+ If you say Y here, all chdir() calls will be logged. If the sysctl
61615+ option is enabled, a sysctl option with name "audit_chdir" is created.
61616+
61617+config GRKERNSEC_AUDIT_MOUNT
61618+ bool "(Un)Mount logging"
61619+ help
61620+ If you say Y here, all mounts and unmounts will be logged. If the
61621+ sysctl option is enabled, a sysctl option with name "audit_mount" is
61622+ created.
61623+
61624+config GRKERNSEC_SIGNAL
61625+ bool "Signal logging"
61626+ default y if GRKERNSEC_CONFIG_AUTO
61627+ help
61628+ If you say Y here, certain important signals will be logged, such as
61629+ SIGSEGV, which will as a result inform you of when a error in a program
61630+ occurred, which in some cases could mean a possible exploit attempt.
61631+ If the sysctl option is enabled, a sysctl option with name
61632+ "signal_logging" is created.
61633+
61634+config GRKERNSEC_FORKFAIL
61635+ bool "Fork failure logging"
61636+ help
61637+ If you say Y here, all failed fork() attempts will be logged.
61638+ This could suggest a fork bomb, or someone attempting to overstep
61639+ their process limit. If the sysctl option is enabled, a sysctl option
61640+ with name "forkfail_logging" is created.
61641+
61642+config GRKERNSEC_TIME
61643+ bool "Time change logging"
61644+ default y if GRKERNSEC_CONFIG_AUTO
61645+ help
61646+ If you say Y here, any changes of the system clock will be logged.
61647+ If the sysctl option is enabled, a sysctl option with name
61648+ "timechange_logging" is created.
61649+
61650+config GRKERNSEC_PROC_IPADDR
61651+ bool "/proc/<pid>/ipaddr support"
61652+ default y if GRKERNSEC_CONFIG_AUTO
61653+ help
61654+ If you say Y here, a new entry will be added to each /proc/<pid>
61655+ directory that contains the IP address of the person using the task.
61656+ The IP is carried across local TCP and AF_UNIX stream sockets.
61657+ This information can be useful for IDS/IPSes to perform remote response
61658+ to a local attack. The entry is readable by only the owner of the
61659+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
61660+ the RBAC system), and thus does not create privacy concerns.
61661+
61662+config GRKERNSEC_RWXMAP_LOG
61663+ bool 'Denied RWX mmap/mprotect logging'
61664+ default y if GRKERNSEC_CONFIG_AUTO
61665+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
61666+ help
61667+ If you say Y here, calls to mmap() and mprotect() with explicit
61668+ usage of PROT_WRITE and PROT_EXEC together will be logged when
61669+ denied by the PAX_MPROTECT feature. This feature will also
61670+ log other problematic scenarios that can occur when PAX_MPROTECT
61671+ is enabled on a binary, like textrels and PT_GNU_STACK. If the
61672+ sysctl option is enabled, a sysctl option with name "rwxmap_logging"
61673+ is created.
61674+
61675+endmenu
61676+
61677+menu "Executable Protections"
61678+depends on GRKERNSEC
61679+
61680+config GRKERNSEC_DMESG
61681+ bool "Dmesg(8) restriction"
61682+ default y if GRKERNSEC_CONFIG_AUTO
61683+ help
61684+ If you say Y here, non-root users will not be able to use dmesg(8)
61685+ to view the contents of the kernel's circular log buffer.
61686+ The kernel's log buffer often contains kernel addresses and other
61687+ identifying information useful to an attacker in fingerprinting a
61688+ system for a targeted exploit.
61689+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
61690+ created.
61691+
61692+config GRKERNSEC_HARDEN_PTRACE
61693+ bool "Deter ptrace-based process snooping"
61694+ default y if GRKERNSEC_CONFIG_AUTO
61695+ help
61696+ If you say Y here, TTY sniffers and other malicious monitoring
61697+ programs implemented through ptrace will be defeated. If you
61698+ have been using the RBAC system, this option has already been
61699+ enabled for several years for all users, with the ability to make
61700+ fine-grained exceptions.
61701+
61702+ This option only affects the ability of non-root users to ptrace
61703+ processes that are not a descendent of the ptracing process.
61704+ This means that strace ./binary and gdb ./binary will still work,
61705+ but attaching to arbitrary processes will not. If the sysctl
61706+ option is enabled, a sysctl option with name "harden_ptrace" is
61707+ created.
61708+
61709+config GRKERNSEC_PTRACE_READEXEC
61710+ bool "Require read access to ptrace sensitive binaries"
61711+ default y if GRKERNSEC_CONFIG_AUTO
61712+ help
61713+ If you say Y here, unprivileged users will not be able to ptrace unreadable
61714+ binaries. This option is useful in environments that
61715+ remove the read bits (e.g. file mode 4711) from suid binaries to
61716+ prevent infoleaking of their contents. This option adds
61717+ consistency to the use of that file mode, as the binary could normally
61718+ be read out when run without privileges while ptracing.
61719+
61720+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
61721+ is created.
61722+
61723+config GRKERNSEC_SETXID
61724+ bool "Enforce consistent multithreaded privileges"
61725+ default y if GRKERNSEC_CONFIG_AUTO
61726+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
61727+ help
61728+ If you say Y here, a change from a root uid to a non-root uid
61729+ in a multithreaded application will cause the resulting uids,
61730+ gids, supplementary groups, and capabilities in that thread
61731+ to be propagated to the other threads of the process. In most
61732+ cases this is unnecessary, as glibc will emulate this behavior
61733+ on behalf of the application. Other libcs do not act in the
61734+ same way, allowing the other threads of the process to continue
61735+ running with root privileges. If the sysctl option is enabled,
61736+ a sysctl option with name "consistent_setxid" is created.
61737+
61738+config GRKERNSEC_TPE
61739+ bool "Trusted Path Execution (TPE)"
61740+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
61741+ help
61742+ If you say Y here, you will be able to choose a gid to add to the
61743+ supplementary groups of users you want to mark as "untrusted."
61744+ These users will not be able to execute any files that are not in
61745+ root-owned directories writable only by root. If the sysctl option
61746+ is enabled, a sysctl option with name "tpe" is created.
61747+
61748+config GRKERNSEC_TPE_ALL
61749+ bool "Partially restrict all non-root users"
61750+ depends on GRKERNSEC_TPE
61751+ help
61752+ If you say Y here, all non-root users will be covered under
61753+ a weaker TPE restriction. This is separate from, and in addition to,
61754+ the main TPE options that you have selected elsewhere. Thus, if a
61755+ "trusted" GID is chosen, this restriction applies to even that GID.
61756+ Under this restriction, all non-root users will only be allowed to
61757+ execute files in directories they own that are not group or
61758+ world-writable, or in directories owned by root and writable only by
61759+ root. If the sysctl option is enabled, a sysctl option with name
61760+ "tpe_restrict_all" is created.
61761+
61762+config GRKERNSEC_TPE_INVERT
61763+ bool "Invert GID option"
61764+ depends on GRKERNSEC_TPE
61765+ help
61766+ If you say Y here, the group you specify in the TPE configuration will
61767+ decide what group TPE restrictions will be *disabled* for. This
61768+ option is useful if you want TPE restrictions to be applied to most
61769+ users on the system. If the sysctl option is enabled, a sysctl option
61770+ with name "tpe_invert" is created. Unlike other sysctl options, this
61771+ entry will default to on for backward-compatibility.
61772+
61773+config GRKERNSEC_TPE_GID
61774+ int
61775+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
61776+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
61777+
61778+config GRKERNSEC_TPE_UNTRUSTED_GID
61779+ int "GID for TPE-untrusted users"
61780+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
61781+ default 1005
61782+ help
61783+ Setting this GID determines what group TPE restrictions will be
61784+ *enabled* for. If the sysctl option is enabled, a sysctl option
61785+ with name "tpe_gid" is created.
61786+
61787+config GRKERNSEC_TPE_TRUSTED_GID
61788+ int "GID for TPE-trusted users"
61789+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
61790+ default 1005
61791+ help
61792+ Setting this GID determines what group TPE restrictions will be
61793+ *disabled* for. If the sysctl option is enabled, a sysctl option
61794+ with name "tpe_gid" is created.
61795+
61796+endmenu
61797+menu "Network Protections"
61798+depends on GRKERNSEC
61799+
61800+config GRKERNSEC_RANDNET
61801+ bool "Larger entropy pools"
61802+ default y if GRKERNSEC_CONFIG_AUTO
61803+ help
61804+ If you say Y here, the entropy pools used for many features of Linux
61805+ and grsecurity will be doubled in size. Since several grsecurity
61806+ features use additional randomness, it is recommended that you say Y
61807+ here. Saying Y here has a similar effect as modifying
61808+ /proc/sys/kernel/random/poolsize.
61809+
61810+config GRKERNSEC_BLACKHOLE
61811+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
61812+ default y if GRKERNSEC_CONFIG_AUTO
61813+ depends on NET
61814+ help
61815+ If you say Y here, neither TCP resets nor ICMP
61816+ destination-unreachable packets will be sent in response to packets
61817+ sent to ports for which no associated listening process exists.
61818+ This feature supports both IPV4 and IPV6 and exempts the
61819+ loopback interface from blackholing. Enabling this feature
61820+ makes a host more resilient to DoS attacks and reduces network
61821+ visibility against scanners.
61822+
61823+ The blackhole feature as-implemented is equivalent to the FreeBSD
61824+ blackhole feature, as it prevents RST responses to all packets, not
61825+ just SYNs. Under most application behavior this causes no
61826+ problems, but applications (like haproxy) may not close certain
61827+ connections in a way that cleanly terminates them on the remote
61828+ end, leaving the remote host in LAST_ACK state. Because of this
61829+ side-effect and to prevent intentional LAST_ACK DoSes, this
61830+ feature also adds automatic mitigation against such attacks.
61831+ The mitigation drastically reduces the amount of time a socket
61832+ can spend in LAST_ACK state. If you're using haproxy and not
61833+ all servers it connects to have this option enabled, consider
61834+ disabling this feature on the haproxy host.
61835+
61836+ If the sysctl option is enabled, two sysctl options with names
61837+ "ip_blackhole" and "lastack_retries" will be created.
61838+ While "ip_blackhole" takes the standard zero/non-zero on/off
61839+ toggle, "lastack_retries" uses the same kinds of values as
61840+ "tcp_retries1" and "tcp_retries2". The default value of 4
61841+ prevents a socket from lasting more than 45 seconds in LAST_ACK
61842+ state.
61843+
61844+config GRKERNSEC_NO_SIMULT_CONNECT
61845+ bool "Disable TCP Simultaneous Connect"
61846+ default y if GRKERNSEC_CONFIG_AUTO
61847+ depends on NET
61848+ help
61849+ If you say Y here, a feature by Willy Tarreau will be enabled that
61850+ removes a weakness in Linux's strict implementation of TCP that
61851+ allows two clients to connect to each other without either entering
61852+ a listening state. The weakness allows an attacker to easily prevent
61853+ a client from connecting to a known server provided the source port
61854+ for the connection is guessed correctly.
61855+
61856+ As the weakness could be used to prevent an antivirus or IPS from
61857+ fetching updates, or prevent an SSL gateway from fetching a CRL,
61858+ it should be eliminated by enabling this option. Though Linux is
61859+ one of few operating systems supporting simultaneous connect, it
61860+ has no legitimate use in practice and is rarely supported by firewalls.
61861+
61862+config GRKERNSEC_SOCKET
61863+ bool "Socket restrictions"
61864+ depends on NET
61865+ help
61866+ If you say Y here, you will be able to choose from several options.
61867+ If you assign a GID on your system and add it to the supplementary
61868+ groups of users you want to restrict socket access to, this patch
61869+ will perform up to three things, based on the option(s) you choose.
61870+
61871+config GRKERNSEC_SOCKET_ALL
61872+ bool "Deny any sockets to group"
61873+ depends on GRKERNSEC_SOCKET
61874+ help
61875+ If you say Y here, you will be able to choose a GID of whose users will
61876+ be unable to connect to other hosts from your machine or run server
61877+ applications from your machine. If the sysctl option is enabled, a
61878+ sysctl option with name "socket_all" is created.
61879+
61880+config GRKERNSEC_SOCKET_ALL_GID
61881+ int "GID to deny all sockets for"
61882+ depends on GRKERNSEC_SOCKET_ALL
61883+ default 1004
61884+ help
61885+ Here you can choose the GID to disable socket access for. Remember to
61886+ add the users you want socket access disabled for to the GID
61887+ specified here. If the sysctl option is enabled, a sysctl option
61888+ with name "socket_all_gid" is created.
61889+
61890+config GRKERNSEC_SOCKET_CLIENT
61891+ bool "Deny client sockets to group"
61892+ depends on GRKERNSEC_SOCKET
61893+ help
61894+ If you say Y here, you will be able to choose a GID of whose users will
61895+ be unable to connect to other hosts from your machine, but will be
61896+ able to run servers. If this option is enabled, all users in the group
61897+ you specify will have to use passive mode when initiating ftp transfers
61898+ from the shell on your machine. If the sysctl option is enabled, a
61899+ sysctl option with name "socket_client" is created.
61900+
61901+config GRKERNSEC_SOCKET_CLIENT_GID
61902+ int "GID to deny client sockets for"
61903+ depends on GRKERNSEC_SOCKET_CLIENT
61904+ default 1003
61905+ help
61906+ Here you can choose the GID to disable client socket access for.
61907+ Remember to add the users you want client socket access disabled for to
61908+ the GID specified here. If the sysctl option is enabled, a sysctl
61909+ option with name "socket_client_gid" is created.
61910+
61911+config GRKERNSEC_SOCKET_SERVER
61912+ bool "Deny server sockets to group"
61913+ depends on GRKERNSEC_SOCKET
61914+ help
61915+ If you say Y here, you will be able to choose a GID of whose users will
61916+ be unable to run server applications from your machine. If the sysctl
61917+ option is enabled, a sysctl option with name "socket_server" is created.
61918+
61919+config GRKERNSEC_SOCKET_SERVER_GID
61920+ int "GID to deny server sockets for"
61921+ depends on GRKERNSEC_SOCKET_SERVER
61922+ default 1002
61923+ help
61924+ Here you can choose the GID to disable server socket access for.
61925+ Remember to add the users you want server socket access disabled for to
61926+ the GID specified here. If the sysctl option is enabled, a sysctl
61927+ option with name "socket_server_gid" is created.
61928+
61929+endmenu
61930+
61931+menu "Physical Protections"
61932+depends on GRKERNSEC
61933+
61934+config GRKERNSEC_DENYUSB
61935+ bool "Deny new USB connections after toggle"
61936+ default y if GRKERNSEC_CONFIG_AUTO
61937+ depends on SYSCTL && USB_SUPPORT
61938+ help
61939+ If you say Y here, a new sysctl option with name "deny_new_usb"
61940+ will be created. Setting its value to 1 will prevent any new
61941+ USB devices from being recognized by the OS. Any attempted USB
61942+ device insertion will be logged. This option is intended to be
61943+ used against custom USB devices designed to exploit vulnerabilities
61944+ in various USB device drivers.
61945+
61946+ For greatest effectiveness, this sysctl should be set after any
61947+ relevant init scripts. This option is safe to enable in distros
61948+ as each user can choose whether or not to toggle the sysctl.
61949+
61950+config GRKERNSEC_DENYUSB_FORCE
61951+ bool "Reject all USB devices not connected at boot"
61952+ select USB
61953+ depends on GRKERNSEC_DENYUSB
61954+ help
61955+ If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
61956+ that doesn't involve a sysctl entry. This option should only be
61957+ enabled if you're sure you want to deny all new USB connections
61958+ at runtime and don't want to modify init scripts. This should not
61959+ be enabled by distros. It forces the core USB code to be built
61960+ into the kernel image so that all devices connected at boot time
61961+ can be recognized and new USB device connections can be prevented
61962+ prior to init running.
61963+
61964+endmenu
61965+
61966+menu "Sysctl Support"
61967+depends on GRKERNSEC && SYSCTL
61968+
61969+config GRKERNSEC_SYSCTL
61970+ bool "Sysctl support"
61971+ default y if GRKERNSEC_CONFIG_AUTO
61972+ help
61973+ If you say Y here, you will be able to change the options that
61974+ grsecurity runs with at bootup, without having to recompile your
61975+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
61976+ to enable (1) or disable (0) various features. All the sysctl entries
61977+ are mutable until the "grsec_lock" entry is set to a non-zero value.
61978+ All features enabled in the kernel configuration are disabled at boot
61979+ if you do not say Y to the "Turn on features by default" option.
61980+ All options should be set at startup, and the grsec_lock entry should
61981+ be set to a non-zero value after all the options are set.
61982+ *THIS IS EXTREMELY IMPORTANT*
61983+
61984+config GRKERNSEC_SYSCTL_DISTRO
61985+ bool "Extra sysctl support for distro makers (READ HELP)"
61986+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
61987+ help
61988+ If you say Y here, additional sysctl options will be created
61989+ for features that affect processes running as root. Therefore,
61990+ it is critical when using this option that the grsec_lock entry be
61991+ enabled after boot. Only distros with prebuilt kernel packages
61992+ with this option enabled that can ensure grsec_lock is enabled
61993+ after boot should use this option.
61994+ *Failure to set grsec_lock after boot makes all grsec features
61995+ this option covers useless*
61996+
61997+ Currently this option creates the following sysctl entries:
61998+ "Disable Privileged I/O": "disable_priv_io"
61999+
62000+config GRKERNSEC_SYSCTL_ON
62001+ bool "Turn on features by default"
62002+ default y if GRKERNSEC_CONFIG_AUTO
62003+ depends on GRKERNSEC_SYSCTL
62004+ help
62005+ If you say Y here, instead of having all features enabled in the
62006+ kernel configuration disabled at boot time, the features will be
62007+ enabled at boot time. It is recommended you say Y here unless
62008+ there is some reason you would want all sysctl-tunable features to
62009+ be disabled by default. As mentioned elsewhere, it is important
62010+ to enable the grsec_lock entry once you have finished modifying
62011+ the sysctl entries.
62012+
62013+endmenu
62014+menu "Logging Options"
62015+depends on GRKERNSEC
62016+
62017+config GRKERNSEC_FLOODTIME
62018+ int "Seconds in between log messages (minimum)"
62019+ default 10
62020+ help
62021+ This option allows you to enforce the number of seconds between
62022+ grsecurity log messages. The default should be suitable for most
62023+ people, however, if you choose to change it, choose a value small enough
62024+ to allow informative logs to be produced, but large enough to
62025+ prevent flooding.
62026+
62027+config GRKERNSEC_FLOODBURST
62028+ int "Number of messages in a burst (maximum)"
62029+ default 6
62030+ help
62031+ This option allows you to choose the maximum number of messages allowed
62032+ within the flood time interval you chose in a separate option. The
62033+ default should be suitable for most people, however if you find that
62034+ many of your logs are being interpreted as flooding, you may want to
62035+ raise this value.
62036+
62037+endmenu
62038diff --git a/grsecurity/Makefile b/grsecurity/Makefile
62039new file mode 100644
62040index 0000000..b0b77d5
62041--- /dev/null
62042+++ b/grsecurity/Makefile
62043@@ -0,0 +1,43 @@
62044+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
62045+# during 2001-2009 it has been completely redesigned by Brad Spengler
62046+# into an RBAC system
62047+#
62048+# All code in this directory and various hooks inserted throughout the kernel
62049+# are copyright Brad Spengler - Open Source Security, Inc., and released
62050+# under the GPL v2 or higher
62051+
62052+KBUILD_CFLAGS += -Werror
62053+
62054+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
62055+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
62056+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
62057+ grsec_usb.o
62058+
62059+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
62060+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
62061+ gracl_learn.o grsec_log.o
62062+ifdef CONFIG_COMPAT
62063+obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
62064+endif
62065+
62066+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
62067+
62068+ifdef CONFIG_NET
62069+obj-y += grsec_sock.o
62070+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
62071+endif
62072+
62073+ifndef CONFIG_GRKERNSEC
62074+obj-y += grsec_disabled.o
62075+endif
62076+
62077+ifdef CONFIG_GRKERNSEC_HIDESYM
62078+extra-y := grsec_hidesym.o
62079+$(obj)/grsec_hidesym.o:
62080+ @-chmod -f 500 /boot
62081+ @-chmod -f 500 /lib/modules
62082+ @-chmod -f 500 /lib64/modules
62083+ @-chmod -f 500 /lib32/modules
62084+ @-chmod -f 700 .
62085+ @echo ' grsec: protected kernel image paths'
62086+endif
62087diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
62088new file mode 100644
62089index 0000000..c0793fd
62090--- /dev/null
62091+++ b/grsecurity/gracl.c
62092@@ -0,0 +1,4178 @@
62093+#include <linux/kernel.h>
62094+#include <linux/module.h>
62095+#include <linux/sched.h>
62096+#include <linux/mm.h>
62097+#include <linux/file.h>
62098+#include <linux/fs.h>
62099+#include <linux/namei.h>
62100+#include <linux/mount.h>
62101+#include <linux/tty.h>
62102+#include <linux/proc_fs.h>
62103+#include <linux/lglock.h>
62104+#include <linux/slab.h>
62105+#include <linux/vmalloc.h>
62106+#include <linux/types.h>
62107+#include <linux/sysctl.h>
62108+#include <linux/netdevice.h>
62109+#include <linux/ptrace.h>
62110+#include <linux/gracl.h>
62111+#include <linux/gralloc.h>
62112+#include <linux/security.h>
62113+#include <linux/grinternal.h>
62114+#include <linux/pid_namespace.h>
62115+#include <linux/stop_machine.h>
62116+#include <linux/fdtable.h>
62117+#include <linux/percpu.h>
62118+#include <linux/lglock.h>
62119+#include <linux/hugetlb.h>
62120+#include <linux/posix-timers.h>
62121+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
62122+#include <linux/magic.h>
62123+#include <linux/pagemap.h>
62124+#include "../fs/btrfs/async-thread.h"
62125+#include "../fs/btrfs/ctree.h"
62126+#include "../fs/btrfs/btrfs_inode.h"
62127+#endif
62128+#include "../fs/mount.h"
62129+
62130+#include <asm/uaccess.h>
62131+#include <asm/errno.h>
62132+#include <asm/mman.h>
62133+
62134+extern struct lglock vfsmount_lock;
62135+
62136+static struct acl_role_db acl_role_set;
62137+static struct name_db name_set;
62138+static struct inodev_db inodev_set;
62139+
62140+/* for keeping track of userspace pointers used for subjects, so we
62141+ can share references in the kernel as well
62142+*/
62143+
62144+static struct path real_root;
62145+
62146+static struct acl_subj_map_db subj_map_set;
62147+
62148+static struct acl_role_label *default_role;
62149+
62150+static struct acl_role_label *role_list;
62151+
62152+static u16 acl_sp_role_value;
62153+
62154+extern char *gr_shared_page[4];
62155+static DEFINE_MUTEX(gr_dev_mutex);
62156+DEFINE_RWLOCK(gr_inode_lock);
62157+
62158+struct gr_arg *gr_usermode;
62159+
62160+static unsigned int gr_status __read_only = GR_STATUS_INIT;
62161+
62162+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
62163+extern void gr_clear_learn_entries(void);
62164+
62165+unsigned char *gr_system_salt;
62166+unsigned char *gr_system_sum;
62167+
62168+static struct sprole_pw **acl_special_roles = NULL;
62169+static __u16 num_sprole_pws = 0;
62170+
62171+static struct acl_role_label *kernel_role = NULL;
62172+
62173+static unsigned int gr_auth_attempts = 0;
62174+static unsigned long gr_auth_expires = 0UL;
62175+
62176+#ifdef CONFIG_NET
62177+extern struct vfsmount *sock_mnt;
62178+#endif
62179+
62180+extern struct vfsmount *pipe_mnt;
62181+extern struct vfsmount *shm_mnt;
62182+
62183+#ifdef CONFIG_HUGETLBFS
62184+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
62185+#endif
62186+
62187+static struct acl_object_label *fakefs_obj_rw;
62188+static struct acl_object_label *fakefs_obj_rwx;
62189+
62190+extern int gr_init_uidset(void);
62191+extern void gr_free_uidset(void);
62192+extern void gr_remove_uid(uid_t uid);
62193+extern int gr_find_uid(uid_t uid);
62194+
62195+static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
62196+{
62197+ if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
62198+ return -EFAULT;
62199+
62200+ return 0;
62201+}
62202+
62203+static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
62204+{
62205+ if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
62206+ return -EFAULT;
62207+
62208+ return 0;
62209+}
62210+
62211+static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
62212+{
62213+ if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
62214+ return -EFAULT;
62215+
62216+ return 0;
62217+}
62218+
62219+static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
62220+{
62221+ if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
62222+ return -EFAULT;
62223+
62224+ return 0;
62225+}
62226+
62227+static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
62228+{
62229+ if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
62230+ return -EFAULT;
62231+
62232+ return 0;
62233+}
62234+
62235+static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
62236+{
62237+ if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
62238+ return -EFAULT;
62239+
62240+ return 0;
62241+}
62242+
62243+static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
62244+{
62245+ if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
62246+ return -EFAULT;
62247+
62248+ return 0;
62249+}
62250+
62251+static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
62252+{
62253+ if (copy_from_user(trans, userp, sizeof(struct role_transition)))
62254+ return -EFAULT;
62255+
62256+ return 0;
62257+}
62258+
62259+int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
62260+{
62261+ if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
62262+ return -EFAULT;
62263+
62264+ return 0;
62265+}
62266+
62267+static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
62268+{
62269+ if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
62270+ return -EFAULT;
62271+
62272+ if ((uwrap->version != GRSECURITY_VERSION) || (uwrap->size != sizeof(struct gr_arg)))
62273+ return -EINVAL;
62274+
62275+ return 0;
62276+}
62277+
62278+static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
62279+{
62280+ if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
62281+ return -EFAULT;
62282+
62283+ return 0;
62284+}
62285+
62286+static size_t get_gr_arg_wrapper_size_normal(void)
62287+{
62288+ return sizeof(struct gr_arg_wrapper);
62289+}
62290+
62291+#ifdef CONFIG_COMPAT
62292+extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
62293+extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
62294+extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
62295+extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
62296+extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
62297+extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
62298+extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
62299+extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
62300+extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
62301+extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
62302+extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
62303+extern size_t get_gr_arg_wrapper_size_compat(void);
62304+
62305+int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
62306+int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
62307+int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
62308+int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
62309+int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
62310+int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
62311+int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
62312+int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
62313+int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
62314+int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
62315+int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
62316+size_t (* get_gr_arg_wrapper_size)(void) __read_only;
62317+
62318+#else
62319+#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
62320+#define copy_gr_arg copy_gr_arg_normal
62321+#define copy_gr_hash_struct copy_gr_hash_struct_normal
62322+#define copy_acl_object_label copy_acl_object_label_normal
62323+#define copy_acl_subject_label copy_acl_subject_label_normal
62324+#define copy_acl_role_label copy_acl_role_label_normal
62325+#define copy_acl_ip_label copy_acl_ip_label_normal
62326+#define copy_pointer_from_array copy_pointer_from_array_normal
62327+#define copy_sprole_pw copy_sprole_pw_normal
62328+#define copy_role_transition copy_role_transition_normal
62329+#define copy_role_allowed_ip copy_role_allowed_ip_normal
62330+#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
62331+#endif
62332+
62333+__inline__ int
62334+gr_acl_is_enabled(void)
62335+{
62336+ return (gr_status & GR_READY);
62337+}
62338+
62339+static inline dev_t __get_dev(const struct dentry *dentry)
62340+{
62341+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
62342+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
62343+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
62344+ else
62345+#endif
62346+ return dentry->d_sb->s_dev;
62347+}
62348+
62349+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
62350+{
62351+ return __get_dev(dentry);
62352+}
62353+
62354+static char gr_task_roletype_to_char(struct task_struct *task)
62355+{
62356+ switch (task->role->roletype &
62357+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
62358+ GR_ROLE_SPECIAL)) {
62359+ case GR_ROLE_DEFAULT:
62360+ return 'D';
62361+ case GR_ROLE_USER:
62362+ return 'U';
62363+ case GR_ROLE_GROUP:
62364+ return 'G';
62365+ case GR_ROLE_SPECIAL:
62366+ return 'S';
62367+ }
62368+
62369+ return 'X';
62370+}
62371+
62372+char gr_roletype_to_char(void)
62373+{
62374+ return gr_task_roletype_to_char(current);
62375+}
62376+
62377+__inline__ int
62378+gr_acl_tpe_check(void)
62379+{
62380+ if (unlikely(!(gr_status & GR_READY)))
62381+ return 0;
62382+ if (current->role->roletype & GR_ROLE_TPE)
62383+ return 1;
62384+ else
62385+ return 0;
62386+}
62387+
62388+int
62389+gr_handle_rawio(const struct inode *inode)
62390+{
62391+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62392+ if (inode && S_ISBLK(inode->i_mode) &&
62393+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
62394+ !capable(CAP_SYS_RAWIO))
62395+ return 1;
62396+#endif
62397+ return 0;
62398+}
62399+
62400+static int
62401+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
62402+{
62403+ if (likely(lena != lenb))
62404+ return 0;
62405+
62406+ return !memcmp(a, b, lena);
62407+}
62408+
62409+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
62410+{
62411+ *buflen -= namelen;
62412+ if (*buflen < 0)
62413+ return -ENAMETOOLONG;
62414+ *buffer -= namelen;
62415+ memcpy(*buffer, str, namelen);
62416+ return 0;
62417+}
62418+
62419+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
62420+{
62421+ return prepend(buffer, buflen, name->name, name->len);
62422+}
62423+
62424+static int prepend_path(const struct path *path, struct path *root,
62425+ char **buffer, int *buflen)
62426+{
62427+ struct dentry *dentry = path->dentry;
62428+ struct vfsmount *vfsmnt = path->mnt;
62429+ struct mount *mnt = real_mount(vfsmnt);
62430+ bool slash = false;
62431+ int error = 0;
62432+
62433+ while (dentry != root->dentry || vfsmnt != root->mnt) {
62434+ struct dentry * parent;
62435+
62436+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
62437+ /* Global root? */
62438+ if (!mnt_has_parent(mnt)) {
62439+ goto out;
62440+ }
62441+ dentry = mnt->mnt_mountpoint;
62442+ mnt = mnt->mnt_parent;
62443+ vfsmnt = &mnt->mnt;
62444+ continue;
62445+ }
62446+ parent = dentry->d_parent;
62447+ prefetch(parent);
62448+ spin_lock(&dentry->d_lock);
62449+ error = prepend_name(buffer, buflen, &dentry->d_name);
62450+ spin_unlock(&dentry->d_lock);
62451+ if (!error)
62452+ error = prepend(buffer, buflen, "/", 1);
62453+ if (error)
62454+ break;
62455+
62456+ slash = true;
62457+ dentry = parent;
62458+ }
62459+
62460+out:
62461+ if (!error && !slash)
62462+ error = prepend(buffer, buflen, "/", 1);
62463+
62464+ return error;
62465+}
62466+
62467+/* this must be called with vfsmount_lock and rename_lock held */
62468+
62469+static char *__our_d_path(const struct path *path, struct path *root,
62470+ char *buf, int buflen)
62471+{
62472+ char *res = buf + buflen;
62473+ int error;
62474+
62475+ prepend(&res, &buflen, "\0", 1);
62476+ error = prepend_path(path, root, &res, &buflen);
62477+ if (error)
62478+ return ERR_PTR(error);
62479+
62480+ return res;
62481+}
62482+
62483+static char *
62484+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
62485+{
62486+ char *retval;
62487+
62488+ retval = __our_d_path(path, root, buf, buflen);
62489+ if (unlikely(IS_ERR(retval)))
62490+ retval = strcpy(buf, "<path too long>");
62491+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
62492+ retval[1] = '\0';
62493+
62494+ return retval;
62495+}
62496+
62497+static char *
62498+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
62499+ char *buf, int buflen)
62500+{
62501+ struct path path;
62502+ char *res;
62503+
62504+ path.dentry = (struct dentry *)dentry;
62505+ path.mnt = (struct vfsmount *)vfsmnt;
62506+
62507+ /* we can use real_root.dentry, real_root.mnt, because this is only called
62508+ by the RBAC system */
62509+ res = gen_full_path(&path, &real_root, buf, buflen);
62510+
62511+ return res;
62512+}
62513+
62514+static char *
62515+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
62516+ char *buf, int buflen)
62517+{
62518+ char *res;
62519+ struct path path;
62520+ struct path root;
62521+ struct task_struct *reaper = init_pid_ns.child_reaper;
62522+
62523+ path.dentry = (struct dentry *)dentry;
62524+ path.mnt = (struct vfsmount *)vfsmnt;
62525+
62526+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
62527+ get_fs_root(reaper->fs, &root);
62528+
62529+ br_read_lock(&vfsmount_lock);
62530+ write_seqlock(&rename_lock);
62531+ res = gen_full_path(&path, &root, buf, buflen);
62532+ write_sequnlock(&rename_lock);
62533+ br_read_unlock(&vfsmount_lock);
62534+
62535+ path_put(&root);
62536+ return res;
62537+}
62538+
62539+static char *
62540+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
62541+{
62542+ char *ret;
62543+ br_read_lock(&vfsmount_lock);
62544+ write_seqlock(&rename_lock);
62545+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
62546+ PAGE_SIZE);
62547+ write_sequnlock(&rename_lock);
62548+ br_read_unlock(&vfsmount_lock);
62549+ return ret;
62550+}
62551+
62552+static char *
62553+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
62554+{
62555+ char *ret;
62556+ char *buf;
62557+ int buflen;
62558+
62559+ br_read_lock(&vfsmount_lock);
62560+ write_seqlock(&rename_lock);
62561+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
62562+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
62563+ buflen = (int)(ret - buf);
62564+ if (buflen >= 5)
62565+ prepend(&ret, &buflen, "/proc", 5);
62566+ else
62567+ ret = strcpy(buf, "<path too long>");
62568+ write_sequnlock(&rename_lock);
62569+ br_read_unlock(&vfsmount_lock);
62570+ return ret;
62571+}
62572+
62573+char *
62574+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
62575+{
62576+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
62577+ PAGE_SIZE);
62578+}
62579+
62580+char *
62581+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
62582+{
62583+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
62584+ PAGE_SIZE);
62585+}
62586+
62587+char *
62588+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
62589+{
62590+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
62591+ PAGE_SIZE);
62592+}
62593+
62594+char *
62595+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
62596+{
62597+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
62598+ PAGE_SIZE);
62599+}
62600+
62601+char *
62602+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
62603+{
62604+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
62605+ PAGE_SIZE);
62606+}
62607+
62608+__inline__ __u32
62609+to_gr_audit(const __u32 reqmode)
62610+{
62611+ /* masks off auditable permission flags, then shifts them to create
62612+ auditing flags, and adds the special case of append auditing if
62613+ we're requesting write */
62614+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
62615+}
62616+
62617+struct acl_subject_label *
62618+lookup_subject_map(const struct acl_subject_label *userp)
62619+{
62620+ unsigned int index = gr_shash(userp, subj_map_set.s_size);
62621+ struct subject_map *match;
62622+
62623+ match = subj_map_set.s_hash[index];
62624+
62625+ while (match && match->user != userp)
62626+ match = match->next;
62627+
62628+ if (match != NULL)
62629+ return match->kernel;
62630+ else
62631+ return NULL;
62632+}
62633+
62634+static void
62635+insert_subj_map_entry(struct subject_map *subjmap)
62636+{
62637+ unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
62638+ struct subject_map **curr;
62639+
62640+ subjmap->prev = NULL;
62641+
62642+ curr = &subj_map_set.s_hash[index];
62643+ if (*curr != NULL)
62644+ (*curr)->prev = subjmap;
62645+
62646+ subjmap->next = *curr;
62647+ *curr = subjmap;
62648+
62649+ return;
62650+}
62651+
62652+static struct acl_role_label *
62653+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
62654+ const gid_t gid)
62655+{
62656+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
62657+ struct acl_role_label *match;
62658+ struct role_allowed_ip *ipp;
62659+ unsigned int x;
62660+ u32 curr_ip = task->signal->curr_ip;
62661+
62662+ task->signal->saved_ip = curr_ip;
62663+
62664+ match = acl_role_set.r_hash[index];
62665+
62666+ while (match) {
62667+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
62668+ for (x = 0; x < match->domain_child_num; x++) {
62669+ if (match->domain_children[x] == uid)
62670+ goto found;
62671+ }
62672+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
62673+ break;
62674+ match = match->next;
62675+ }
62676+found:
62677+ if (match == NULL) {
62678+ try_group:
62679+ index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
62680+ match = acl_role_set.r_hash[index];
62681+
62682+ while (match) {
62683+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
62684+ for (x = 0; x < match->domain_child_num; x++) {
62685+ if (match->domain_children[x] == gid)
62686+ goto found2;
62687+ }
62688+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
62689+ break;
62690+ match = match->next;
62691+ }
62692+found2:
62693+ if (match == NULL)
62694+ match = default_role;
62695+ if (match->allowed_ips == NULL)
62696+ return match;
62697+ else {
62698+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
62699+ if (likely
62700+ ((ntohl(curr_ip) & ipp->netmask) ==
62701+ (ntohl(ipp->addr) & ipp->netmask)))
62702+ return match;
62703+ }
62704+ match = default_role;
62705+ }
62706+ } else if (match->allowed_ips == NULL) {
62707+ return match;
62708+ } else {
62709+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
62710+ if (likely
62711+ ((ntohl(curr_ip) & ipp->netmask) ==
62712+ (ntohl(ipp->addr) & ipp->netmask)))
62713+ return match;
62714+ }
62715+ goto try_group;
62716+ }
62717+
62718+ return match;
62719+}
62720+
62721+struct acl_subject_label *
62722+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
62723+ const struct acl_role_label *role)
62724+{
62725+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
62726+ struct acl_subject_label *match;
62727+
62728+ match = role->subj_hash[index];
62729+
62730+ while (match && (match->inode != ino || match->device != dev ||
62731+ (match->mode & GR_DELETED))) {
62732+ match = match->next;
62733+ }
62734+
62735+ if (match && !(match->mode & GR_DELETED))
62736+ return match;
62737+ else
62738+ return NULL;
62739+}
62740+
62741+struct acl_subject_label *
62742+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
62743+ const struct acl_role_label *role)
62744+{
62745+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
62746+ struct acl_subject_label *match;
62747+
62748+ match = role->subj_hash[index];
62749+
62750+ while (match && (match->inode != ino || match->device != dev ||
62751+ !(match->mode & GR_DELETED))) {
62752+ match = match->next;
62753+ }
62754+
62755+ if (match && (match->mode & GR_DELETED))
62756+ return match;
62757+ else
62758+ return NULL;
62759+}
62760+
62761+static struct acl_object_label *
62762+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
62763+ const struct acl_subject_label *subj)
62764+{
62765+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
62766+ struct acl_object_label *match;
62767+
62768+ match = subj->obj_hash[index];
62769+
62770+ while (match && (match->inode != ino || match->device != dev ||
62771+ (match->mode & GR_DELETED))) {
62772+ match = match->next;
62773+ }
62774+
62775+ if (match && !(match->mode & GR_DELETED))
62776+ return match;
62777+ else
62778+ return NULL;
62779+}
62780+
62781+static struct acl_object_label *
62782+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
62783+ const struct acl_subject_label *subj)
62784+{
62785+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
62786+ struct acl_object_label *match;
62787+
62788+ match = subj->obj_hash[index];
62789+
62790+ while (match && (match->inode != ino || match->device != dev ||
62791+ !(match->mode & GR_DELETED))) {
62792+ match = match->next;
62793+ }
62794+
62795+ if (match && (match->mode & GR_DELETED))
62796+ return match;
62797+
62798+ match = subj->obj_hash[index];
62799+
62800+ while (match && (match->inode != ino || match->device != dev ||
62801+ (match->mode & GR_DELETED))) {
62802+ match = match->next;
62803+ }
62804+
62805+ if (match && !(match->mode & GR_DELETED))
62806+ return match;
62807+ else
62808+ return NULL;
62809+}
62810+
62811+static struct name_entry *
62812+lookup_name_entry(const char *name)
62813+{
62814+ unsigned int len = strlen(name);
62815+ unsigned int key = full_name_hash(name, len);
62816+ unsigned int index = key % name_set.n_size;
62817+ struct name_entry *match;
62818+
62819+ match = name_set.n_hash[index];
62820+
62821+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
62822+ match = match->next;
62823+
62824+ return match;
62825+}
62826+
62827+static struct name_entry *
62828+lookup_name_entry_create(const char *name)
62829+{
62830+ unsigned int len = strlen(name);
62831+ unsigned int key = full_name_hash(name, len);
62832+ unsigned int index = key % name_set.n_size;
62833+ struct name_entry *match;
62834+
62835+ match = name_set.n_hash[index];
62836+
62837+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
62838+ !match->deleted))
62839+ match = match->next;
62840+
62841+ if (match && match->deleted)
62842+ return match;
62843+
62844+ match = name_set.n_hash[index];
62845+
62846+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
62847+ match->deleted))
62848+ match = match->next;
62849+
62850+ if (match && !match->deleted)
62851+ return match;
62852+ else
62853+ return NULL;
62854+}
62855+
62856+static struct inodev_entry *
62857+lookup_inodev_entry(const ino_t ino, const dev_t dev)
62858+{
62859+ unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
62860+ struct inodev_entry *match;
62861+
62862+ match = inodev_set.i_hash[index];
62863+
62864+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
62865+ match = match->next;
62866+
62867+ return match;
62868+}
62869+
62870+static void
62871+insert_inodev_entry(struct inodev_entry *entry)
62872+{
62873+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
62874+ inodev_set.i_size);
62875+ struct inodev_entry **curr;
62876+
62877+ entry->prev = NULL;
62878+
62879+ curr = &inodev_set.i_hash[index];
62880+ if (*curr != NULL)
62881+ (*curr)->prev = entry;
62882+
62883+ entry->next = *curr;
62884+ *curr = entry;
62885+
62886+ return;
62887+}
62888+
62889+static void
62890+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
62891+{
62892+ unsigned int index =
62893+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
62894+ struct acl_role_label **curr;
62895+ struct acl_role_label *tmp, *tmp2;
62896+
62897+ curr = &acl_role_set.r_hash[index];
62898+
62899+ /* simple case, slot is empty, just set it to our role */
62900+ if (*curr == NULL) {
62901+ *curr = role;
62902+ } else {
62903+ /* example:
62904+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
62905+ 2 -> 3
62906+ */
62907+ /* first check to see if we can already be reached via this slot */
62908+ tmp = *curr;
62909+ while (tmp && tmp != role)
62910+ tmp = tmp->next;
62911+ if (tmp == role) {
62912+ /* we don't need to add ourselves to this slot's chain */
62913+ return;
62914+ }
62915+ /* we need to add ourselves to this chain, two cases */
62916+ if (role->next == NULL) {
62917+ /* simple case, append the current chain to our role */
62918+ role->next = *curr;
62919+ *curr = role;
62920+ } else {
62921+ /* 1 -> 2 -> 3 -> 4
62922+ 2 -> 3 -> 4
62923+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
62924+ */
62925+ /* trickier case: walk our role's chain until we find
62926+ the role for the start of the current slot's chain */
62927+ tmp = role;
62928+ tmp2 = *curr;
62929+ while (tmp->next && tmp->next != tmp2)
62930+ tmp = tmp->next;
62931+ if (tmp->next == tmp2) {
62932+ /* from example above, we found 3, so just
62933+ replace this slot's chain with ours */
62934+ *curr = role;
62935+ } else {
62936+ /* we didn't find a subset of our role's chain
62937+ in the current slot's chain, so append their
62938+ chain to ours, and set us as the first role in
62939+ the slot's chain
62940+
62941+ we could fold this case with the case above,
62942+ but making it explicit for clarity
62943+ */
62944+ tmp->next = tmp2;
62945+ *curr = role;
62946+ }
62947+ }
62948+ }
62949+
62950+ return;
62951+}
62952+
62953+static void
62954+insert_acl_role_label(struct acl_role_label *role)
62955+{
62956+ int i;
62957+
62958+ if (role_list == NULL) {
62959+ role_list = role;
62960+ role->prev = NULL;
62961+ } else {
62962+ role->prev = role_list;
62963+ role_list = role;
62964+ }
62965+
62966+ /* used for hash chains */
62967+ role->next = NULL;
62968+
62969+ if (role->roletype & GR_ROLE_DOMAIN) {
62970+ for (i = 0; i < role->domain_child_num; i++)
62971+ __insert_acl_role_label(role, role->domain_children[i]);
62972+ } else
62973+ __insert_acl_role_label(role, role->uidgid);
62974+}
62975+
62976+static int
62977+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
62978+{
62979+ struct name_entry **curr, *nentry;
62980+ struct inodev_entry *ientry;
62981+ unsigned int len = strlen(name);
62982+ unsigned int key = full_name_hash(name, len);
62983+ unsigned int index = key % name_set.n_size;
62984+
62985+ curr = &name_set.n_hash[index];
62986+
62987+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
62988+ curr = &((*curr)->next);
62989+
62990+ if (*curr != NULL)
62991+ return 1;
62992+
62993+ nentry = acl_alloc(sizeof (struct name_entry));
62994+ if (nentry == NULL)
62995+ return 0;
62996+ ientry = acl_alloc(sizeof (struct inodev_entry));
62997+ if (ientry == NULL)
62998+ return 0;
62999+ ientry->nentry = nentry;
63000+
63001+ nentry->key = key;
63002+ nentry->name = name;
63003+ nentry->inode = inode;
63004+ nentry->device = device;
63005+ nentry->len = len;
63006+ nentry->deleted = deleted;
63007+
63008+ nentry->prev = NULL;
63009+ curr = &name_set.n_hash[index];
63010+ if (*curr != NULL)
63011+ (*curr)->prev = nentry;
63012+ nentry->next = *curr;
63013+ *curr = nentry;
63014+
63015+ /* insert us into the table searchable by inode/dev */
63016+ insert_inodev_entry(ientry);
63017+
63018+ return 1;
63019+}
63020+
63021+static void
63022+insert_acl_obj_label(struct acl_object_label *obj,
63023+ struct acl_subject_label *subj)
63024+{
63025+ unsigned int index =
63026+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
63027+ struct acl_object_label **curr;
63028+
63029+
63030+ obj->prev = NULL;
63031+
63032+ curr = &subj->obj_hash[index];
63033+ if (*curr != NULL)
63034+ (*curr)->prev = obj;
63035+
63036+ obj->next = *curr;
63037+ *curr = obj;
63038+
63039+ return;
63040+}
63041+
63042+static void
63043+insert_acl_subj_label(struct acl_subject_label *obj,
63044+ struct acl_role_label *role)
63045+{
63046+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
63047+ struct acl_subject_label **curr;
63048+
63049+ obj->prev = NULL;
63050+
63051+ curr = &role->subj_hash[index];
63052+ if (*curr != NULL)
63053+ (*curr)->prev = obj;
63054+
63055+ obj->next = *curr;
63056+ *curr = obj;
63057+
63058+ return;
63059+}
63060+
63061+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
63062+
63063+static void *
63064+create_table(__u32 * len, int elementsize)
63065+{
63066+ unsigned int table_sizes[] = {
63067+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
63068+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
63069+ 4194301, 8388593, 16777213, 33554393, 67108859
63070+ };
63071+ void *newtable = NULL;
63072+ unsigned int pwr = 0;
63073+
63074+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
63075+ table_sizes[pwr] <= *len)
63076+ pwr++;
63077+
63078+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
63079+ return newtable;
63080+
63081+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
63082+ newtable =
63083+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
63084+ else
63085+ newtable = vmalloc(table_sizes[pwr] * elementsize);
63086+
63087+ *len = table_sizes[pwr];
63088+
63089+ return newtable;
63090+}
63091+
63092+static int
63093+init_variables(const struct gr_arg *arg)
63094+{
63095+ struct task_struct *reaper = init_pid_ns.child_reaper;
63096+ unsigned int stacksize;
63097+
63098+ subj_map_set.s_size = arg->role_db.num_subjects;
63099+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
63100+ name_set.n_size = arg->role_db.num_objects;
63101+ inodev_set.i_size = arg->role_db.num_objects;
63102+
63103+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
63104+ !name_set.n_size || !inodev_set.i_size)
63105+ return 1;
63106+
63107+ if (!gr_init_uidset())
63108+ return 1;
63109+
63110+ /* set up the stack that holds allocation info */
63111+
63112+ stacksize = arg->role_db.num_pointers + 5;
63113+
63114+ if (!acl_alloc_stack_init(stacksize))
63115+ return 1;
63116+
63117+ /* grab reference for the real root dentry and vfsmount */
63118+ get_fs_root(reaper->fs, &real_root);
63119+
63120+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
63121+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
63122+#endif
63123+
63124+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
63125+ if (fakefs_obj_rw == NULL)
63126+ return 1;
63127+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
63128+
63129+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
63130+ if (fakefs_obj_rwx == NULL)
63131+ return 1;
63132+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
63133+
63134+ subj_map_set.s_hash =
63135+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
63136+ acl_role_set.r_hash =
63137+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
63138+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
63139+ inodev_set.i_hash =
63140+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
63141+
63142+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
63143+ !name_set.n_hash || !inodev_set.i_hash)
63144+ return 1;
63145+
63146+ memset(subj_map_set.s_hash, 0,
63147+ sizeof(struct subject_map *) * subj_map_set.s_size);
63148+ memset(acl_role_set.r_hash, 0,
63149+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
63150+ memset(name_set.n_hash, 0,
63151+ sizeof (struct name_entry *) * name_set.n_size);
63152+ memset(inodev_set.i_hash, 0,
63153+ sizeof (struct inodev_entry *) * inodev_set.i_size);
63154+
63155+ return 0;
63156+}
63157+
63158+/* free information not needed after startup
63159+ currently contains user->kernel pointer mappings for subjects
63160+*/
63161+
63162+static void
63163+free_init_variables(void)
63164+{
63165+ __u32 i;
63166+
63167+ if (subj_map_set.s_hash) {
63168+ for (i = 0; i < subj_map_set.s_size; i++) {
63169+ if (subj_map_set.s_hash[i]) {
63170+ kfree(subj_map_set.s_hash[i]);
63171+ subj_map_set.s_hash[i] = NULL;
63172+ }
63173+ }
63174+
63175+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
63176+ PAGE_SIZE)
63177+ kfree(subj_map_set.s_hash);
63178+ else
63179+ vfree(subj_map_set.s_hash);
63180+ }
63181+
63182+ return;
63183+}
63184+
63185+static void
63186+free_variables(void)
63187+{
63188+ struct acl_subject_label *s;
63189+ struct acl_role_label *r;
63190+ struct task_struct *task, *task2;
63191+ unsigned int x;
63192+
63193+ gr_clear_learn_entries();
63194+
63195+ read_lock(&tasklist_lock);
63196+ do_each_thread(task2, task) {
63197+ task->acl_sp_role = 0;
63198+ task->acl_role_id = 0;
63199+ task->acl = NULL;
63200+ task->role = NULL;
63201+ } while_each_thread(task2, task);
63202+ read_unlock(&tasklist_lock);
63203+
63204+ /* release the reference to the real root dentry and vfsmount */
63205+ path_put(&real_root);
63206+ memset(&real_root, 0, sizeof(real_root));
63207+
63208+ /* free all object hash tables */
63209+
63210+ FOR_EACH_ROLE_START(r)
63211+ if (r->subj_hash == NULL)
63212+ goto next_role;
63213+ FOR_EACH_SUBJECT_START(r, s, x)
63214+ if (s->obj_hash == NULL)
63215+ break;
63216+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
63217+ kfree(s->obj_hash);
63218+ else
63219+ vfree(s->obj_hash);
63220+ FOR_EACH_SUBJECT_END(s, x)
63221+ FOR_EACH_NESTED_SUBJECT_START(r, s)
63222+ if (s->obj_hash == NULL)
63223+ break;
63224+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
63225+ kfree(s->obj_hash);
63226+ else
63227+ vfree(s->obj_hash);
63228+ FOR_EACH_NESTED_SUBJECT_END(s)
63229+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
63230+ kfree(r->subj_hash);
63231+ else
63232+ vfree(r->subj_hash);
63233+ r->subj_hash = NULL;
63234+next_role:
63235+ FOR_EACH_ROLE_END(r)
63236+
63237+ acl_free_all();
63238+
63239+ if (acl_role_set.r_hash) {
63240+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
63241+ PAGE_SIZE)
63242+ kfree(acl_role_set.r_hash);
63243+ else
63244+ vfree(acl_role_set.r_hash);
63245+ }
63246+ if (name_set.n_hash) {
63247+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
63248+ PAGE_SIZE)
63249+ kfree(name_set.n_hash);
63250+ else
63251+ vfree(name_set.n_hash);
63252+ }
63253+
63254+ if (inodev_set.i_hash) {
63255+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
63256+ PAGE_SIZE)
63257+ kfree(inodev_set.i_hash);
63258+ else
63259+ vfree(inodev_set.i_hash);
63260+ }
63261+
63262+ gr_free_uidset();
63263+
63264+ memset(&name_set, 0, sizeof (struct name_db));
63265+ memset(&inodev_set, 0, sizeof (struct inodev_db));
63266+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
63267+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
63268+
63269+ default_role = NULL;
63270+ kernel_role = NULL;
63271+ role_list = NULL;
63272+
63273+ return;
63274+}
63275+
63276+static struct acl_subject_label *
63277+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
63278+
63279+static int alloc_and_copy_string(char **name, unsigned int maxlen)
63280+{
63281+ unsigned int len = strnlen_user(*name, maxlen);
63282+ char *tmp;
63283+
63284+ if (!len || len >= maxlen)
63285+ return -EINVAL;
63286+
63287+ if ((tmp = (char *) acl_alloc(len)) == NULL)
63288+ return -ENOMEM;
63289+
63290+ if (copy_from_user(tmp, *name, len))
63291+ return -EFAULT;
63292+
63293+ tmp[len-1] = '\0';
63294+ *name = tmp;
63295+
63296+ return 0;
63297+}
63298+
63299+static int
63300+copy_user_glob(struct acl_object_label *obj)
63301+{
63302+ struct acl_object_label *g_tmp, **guser;
63303+ int error;
63304+
63305+ if (obj->globbed == NULL)
63306+ return 0;
63307+
63308+ guser = &obj->globbed;
63309+ while (*guser) {
63310+ g_tmp = (struct acl_object_label *)
63311+ acl_alloc(sizeof (struct acl_object_label));
63312+ if (g_tmp == NULL)
63313+ return -ENOMEM;
63314+
63315+ if (copy_acl_object_label(g_tmp, *guser))
63316+ return -EFAULT;
63317+
63318+ error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
63319+ if (error)
63320+ return error;
63321+
63322+ *guser = g_tmp;
63323+ guser = &(g_tmp->next);
63324+ }
63325+
63326+ return 0;
63327+}
63328+
63329+static int
63330+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
63331+ struct acl_role_label *role)
63332+{
63333+ struct acl_object_label *o_tmp;
63334+ int ret;
63335+
63336+ while (userp) {
63337+ if ((o_tmp = (struct acl_object_label *)
63338+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
63339+ return -ENOMEM;
63340+
63341+ if (copy_acl_object_label(o_tmp, userp))
63342+ return -EFAULT;
63343+
63344+ userp = o_tmp->prev;
63345+
63346+ ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
63347+ if (ret)
63348+ return ret;
63349+
63350+ insert_acl_obj_label(o_tmp, subj);
63351+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
63352+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
63353+ return -ENOMEM;
63354+
63355+ ret = copy_user_glob(o_tmp);
63356+ if (ret)
63357+ return ret;
63358+
63359+ if (o_tmp->nested) {
63360+ int already_copied;
63361+
63362+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
63363+ if (IS_ERR(o_tmp->nested))
63364+ return PTR_ERR(o_tmp->nested);
63365+
63366+ /* insert into nested subject list if we haven't copied this one yet
63367+ to prevent duplicate entries */
63368+ if (!already_copied) {
63369+ o_tmp->nested->next = role->hash->first;
63370+ role->hash->first = o_tmp->nested;
63371+ }
63372+ }
63373+ }
63374+
63375+ return 0;
63376+}
63377+
63378+static __u32
63379+count_user_subjs(struct acl_subject_label *userp)
63380+{
63381+ struct acl_subject_label s_tmp;
63382+ __u32 num = 0;
63383+
63384+ while (userp) {
63385+ if (copy_acl_subject_label(&s_tmp, userp))
63386+ break;
63387+
63388+ userp = s_tmp.prev;
63389+ }
63390+
63391+ return num;
63392+}
63393+
63394+static int
63395+copy_user_allowedips(struct acl_role_label *rolep)
63396+{
63397+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
63398+
63399+ ruserip = rolep->allowed_ips;
63400+
63401+ while (ruserip) {
63402+ rlast = rtmp;
63403+
63404+ if ((rtmp = (struct role_allowed_ip *)
63405+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
63406+ return -ENOMEM;
63407+
63408+ if (copy_role_allowed_ip(rtmp, ruserip))
63409+ return -EFAULT;
63410+
63411+ ruserip = rtmp->prev;
63412+
63413+ if (!rlast) {
63414+ rtmp->prev = NULL;
63415+ rolep->allowed_ips = rtmp;
63416+ } else {
63417+ rlast->next = rtmp;
63418+ rtmp->prev = rlast;
63419+ }
63420+
63421+ if (!ruserip)
63422+ rtmp->next = NULL;
63423+ }
63424+
63425+ return 0;
63426+}
63427+
63428+static int
63429+copy_user_transitions(struct acl_role_label *rolep)
63430+{
63431+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
63432+ int error;
63433+
63434+ rusertp = rolep->transitions;
63435+
63436+ while (rusertp) {
63437+ rlast = rtmp;
63438+
63439+ if ((rtmp = (struct role_transition *)
63440+ acl_alloc(sizeof (struct role_transition))) == NULL)
63441+ return -ENOMEM;
63442+
63443+ if (copy_role_transition(rtmp, rusertp))
63444+ return -EFAULT;
63445+
63446+ rusertp = rtmp->prev;
63447+
63448+ error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
63449+ if (error)
63450+ return error;
63451+
63452+ if (!rlast) {
63453+ rtmp->prev = NULL;
63454+ rolep->transitions = rtmp;
63455+ } else {
63456+ rlast->next = rtmp;
63457+ rtmp->prev = rlast;
63458+ }
63459+
63460+ if (!rusertp)
63461+ rtmp->next = NULL;
63462+ }
63463+
63464+ return 0;
63465+}
63466+
63467+static __u32 count_user_objs(const struct acl_object_label __user *userp)
63468+{
63469+ struct acl_object_label o_tmp;
63470+ __u32 num = 0;
63471+
63472+ while (userp) {
63473+ if (copy_acl_object_label(&o_tmp, userp))
63474+ break;
63475+
63476+ userp = o_tmp.prev;
63477+ num++;
63478+ }
63479+
63480+ return num;
63481+}
63482+
63483+static struct acl_subject_label *
63484+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
63485+{
63486+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
63487+ __u32 num_objs;
63488+ struct acl_ip_label **i_tmp, *i_utmp2;
63489+ struct gr_hash_struct ghash;
63490+ struct subject_map *subjmap;
63491+ unsigned int i_num;
63492+ int err;
63493+
63494+ if (already_copied != NULL)
63495+ *already_copied = 0;
63496+
63497+ s_tmp = lookup_subject_map(userp);
63498+
63499+ /* we've already copied this subject into the kernel, just return
63500+ the reference to it, and don't copy it over again
63501+ */
63502+ if (s_tmp) {
63503+ if (already_copied != NULL)
63504+ *already_copied = 1;
63505+ return(s_tmp);
63506+ }
63507+
63508+ if ((s_tmp = (struct acl_subject_label *)
63509+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
63510+ return ERR_PTR(-ENOMEM);
63511+
63512+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
63513+ if (subjmap == NULL)
63514+ return ERR_PTR(-ENOMEM);
63515+
63516+ subjmap->user = userp;
63517+ subjmap->kernel = s_tmp;
63518+ insert_subj_map_entry(subjmap);
63519+
63520+ if (copy_acl_subject_label(s_tmp, userp))
63521+ return ERR_PTR(-EFAULT);
63522+
63523+ err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
63524+ if (err)
63525+ return ERR_PTR(err);
63526+
63527+ if (!strcmp(s_tmp->filename, "/"))
63528+ role->root_label = s_tmp;
63529+
63530+ if (copy_gr_hash_struct(&ghash, s_tmp->hash))
63531+ return ERR_PTR(-EFAULT);
63532+
63533+ /* copy user and group transition tables */
63534+
63535+ if (s_tmp->user_trans_num) {
63536+ uid_t *uidlist;
63537+
63538+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
63539+ if (uidlist == NULL)
63540+ return ERR_PTR(-ENOMEM);
63541+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
63542+ return ERR_PTR(-EFAULT);
63543+
63544+ s_tmp->user_transitions = uidlist;
63545+ }
63546+
63547+ if (s_tmp->group_trans_num) {
63548+ gid_t *gidlist;
63549+
63550+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
63551+ if (gidlist == NULL)
63552+ return ERR_PTR(-ENOMEM);
63553+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
63554+ return ERR_PTR(-EFAULT);
63555+
63556+ s_tmp->group_transitions = gidlist;
63557+ }
63558+
63559+ /* set up object hash table */
63560+ num_objs = count_user_objs(ghash.first);
63561+
63562+ s_tmp->obj_hash_size = num_objs;
63563+ s_tmp->obj_hash =
63564+ (struct acl_object_label **)
63565+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
63566+
63567+ if (!s_tmp->obj_hash)
63568+ return ERR_PTR(-ENOMEM);
63569+
63570+ memset(s_tmp->obj_hash, 0,
63571+ s_tmp->obj_hash_size *
63572+ sizeof (struct acl_object_label *));
63573+
63574+ /* add in objects */
63575+ err = copy_user_objs(ghash.first, s_tmp, role);
63576+
63577+ if (err)
63578+ return ERR_PTR(err);
63579+
63580+ /* set pointer for parent subject */
63581+ if (s_tmp->parent_subject) {
63582+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
63583+
63584+ if (IS_ERR(s_tmp2))
63585+ return s_tmp2;
63586+
63587+ s_tmp->parent_subject = s_tmp2;
63588+ }
63589+
63590+ /* add in ip acls */
63591+
63592+ if (!s_tmp->ip_num) {
63593+ s_tmp->ips = NULL;
63594+ goto insert;
63595+ }
63596+
63597+ i_tmp =
63598+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
63599+ sizeof (struct acl_ip_label *));
63600+
63601+ if (!i_tmp)
63602+ return ERR_PTR(-ENOMEM);
63603+
63604+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
63605+ *(i_tmp + i_num) =
63606+ (struct acl_ip_label *)
63607+ acl_alloc(sizeof (struct acl_ip_label));
63608+ if (!*(i_tmp + i_num))
63609+ return ERR_PTR(-ENOMEM);
63610+
63611+ if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
63612+ return ERR_PTR(-EFAULT);
63613+
63614+ if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
63615+ return ERR_PTR(-EFAULT);
63616+
63617+ if ((*(i_tmp + i_num))->iface == NULL)
63618+ continue;
63619+
63620+ err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
63621+ if (err)
63622+ return ERR_PTR(err);
63623+ }
63624+
63625+ s_tmp->ips = i_tmp;
63626+
63627+insert:
63628+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
63629+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
63630+ return ERR_PTR(-ENOMEM);
63631+
63632+ return s_tmp;
63633+}
63634+
63635+static int
63636+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
63637+{
63638+ struct acl_subject_label s_pre;
63639+ struct acl_subject_label * ret;
63640+ int err;
63641+
63642+ while (userp) {
63643+ if (copy_acl_subject_label(&s_pre, userp))
63644+ return -EFAULT;
63645+
63646+ ret = do_copy_user_subj(userp, role, NULL);
63647+
63648+ err = PTR_ERR(ret);
63649+ if (IS_ERR(ret))
63650+ return err;
63651+
63652+ insert_acl_subj_label(ret, role);
63653+
63654+ userp = s_pre.prev;
63655+ }
63656+
63657+ return 0;
63658+}
63659+
63660+static int
63661+copy_user_acl(struct gr_arg *arg)
63662+{
63663+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
63664+ struct acl_subject_label *subj_list;
63665+ struct sprole_pw *sptmp;
63666+ struct gr_hash_struct *ghash;
63667+ uid_t *domainlist;
63668+ unsigned int r_num;
63669+ int err = 0;
63670+ __u16 i;
63671+ __u32 num_subjs;
63672+
63673+ /* we need a default and kernel role */
63674+ if (arg->role_db.num_roles < 2)
63675+ return -EINVAL;
63676+
63677+ /* copy special role authentication info from userspace */
63678+
63679+ num_sprole_pws = arg->num_sprole_pws;
63680+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
63681+
63682+ if (!acl_special_roles && num_sprole_pws)
63683+ return -ENOMEM;
63684+
63685+ for (i = 0; i < num_sprole_pws; i++) {
63686+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
63687+ if (!sptmp)
63688+ return -ENOMEM;
63689+ if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
63690+ return -EFAULT;
63691+
63692+ err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
63693+ if (err)
63694+ return err;
63695+
63696+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
63697+ printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
63698+#endif
63699+
63700+ acl_special_roles[i] = sptmp;
63701+ }
63702+
63703+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
63704+
63705+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
63706+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
63707+
63708+ if (!r_tmp)
63709+ return -ENOMEM;
63710+
63711+ if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
63712+ return -EFAULT;
63713+
63714+ if (copy_acl_role_label(r_tmp, r_utmp2))
63715+ return -EFAULT;
63716+
63717+ err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
63718+ if (err)
63719+ return err;
63720+
63721+ if (!strcmp(r_tmp->rolename, "default")
63722+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
63723+ default_role = r_tmp;
63724+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
63725+ kernel_role = r_tmp;
63726+ }
63727+
63728+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
63729+ return -ENOMEM;
63730+
63731+ if (copy_gr_hash_struct(ghash, r_tmp->hash))
63732+ return -EFAULT;
63733+
63734+ r_tmp->hash = ghash;
63735+
63736+ num_subjs = count_user_subjs(r_tmp->hash->first);
63737+
63738+ r_tmp->subj_hash_size = num_subjs;
63739+ r_tmp->subj_hash =
63740+ (struct acl_subject_label **)
63741+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
63742+
63743+ if (!r_tmp->subj_hash)
63744+ return -ENOMEM;
63745+
63746+ err = copy_user_allowedips(r_tmp);
63747+ if (err)
63748+ return err;
63749+
63750+ /* copy domain info */
63751+ if (r_tmp->domain_children != NULL) {
63752+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
63753+ if (domainlist == NULL)
63754+ return -ENOMEM;
63755+
63756+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
63757+ return -EFAULT;
63758+
63759+ r_tmp->domain_children = domainlist;
63760+ }
63761+
63762+ err = copy_user_transitions(r_tmp);
63763+ if (err)
63764+ return err;
63765+
63766+ memset(r_tmp->subj_hash, 0,
63767+ r_tmp->subj_hash_size *
63768+ sizeof (struct acl_subject_label *));
63769+
63770+ /* acquire the list of subjects, then NULL out
63771+ the list prior to parsing the subjects for this role,
63772+ as during this parsing the list is replaced with a list
63773+ of *nested* subjects for the role
63774+ */
63775+ subj_list = r_tmp->hash->first;
63776+
63777+ /* set nested subject list to null */
63778+ r_tmp->hash->first = NULL;
63779+
63780+ err = copy_user_subjs(subj_list, r_tmp);
63781+
63782+ if (err)
63783+ return err;
63784+
63785+ insert_acl_role_label(r_tmp);
63786+ }
63787+
63788+ if (default_role == NULL || kernel_role == NULL)
63789+ return -EINVAL;
63790+
63791+ return err;
63792+}
63793+
63794+static int
63795+gracl_init(struct gr_arg *args)
63796+{
63797+ int error = 0;
63798+
63799+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
63800+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
63801+
63802+ if (init_variables(args)) {
63803+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
63804+ error = -ENOMEM;
63805+ free_variables();
63806+ goto out;
63807+ }
63808+
63809+ error = copy_user_acl(args);
63810+ free_init_variables();
63811+ if (error) {
63812+ free_variables();
63813+ goto out;
63814+ }
63815+
63816+ if ((error = gr_set_acls(0))) {
63817+ free_variables();
63818+ goto out;
63819+ }
63820+
63821+ pax_open_kernel();
63822+ gr_status |= GR_READY;
63823+ pax_close_kernel();
63824+
63825+ out:
63826+ return error;
63827+}
63828+
63829+/* derived from glibc fnmatch() 0: match, 1: no match*/
63830+
63831+static int
63832+glob_match(const char *p, const char *n)
63833+{
63834+ char c;
63835+
63836+ while ((c = *p++) != '\0') {
63837+ switch (c) {
63838+ case '?':
63839+ if (*n == '\0')
63840+ return 1;
63841+ else if (*n == '/')
63842+ return 1;
63843+ break;
63844+ case '\\':
63845+ if (*n != c)
63846+ return 1;
63847+ break;
63848+ case '*':
63849+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
63850+ if (*n == '/')
63851+ return 1;
63852+ else if (c == '?') {
63853+ if (*n == '\0')
63854+ return 1;
63855+ else
63856+ ++n;
63857+ }
63858+ }
63859+ if (c == '\0') {
63860+ return 0;
63861+ } else {
63862+ const char *endp;
63863+
63864+ if ((endp = strchr(n, '/')) == NULL)
63865+ endp = n + strlen(n);
63866+
63867+ if (c == '[') {
63868+ for (--p; n < endp; ++n)
63869+ if (!glob_match(p, n))
63870+ return 0;
63871+ } else if (c == '/') {
63872+ while (*n != '\0' && *n != '/')
63873+ ++n;
63874+ if (*n == '/' && !glob_match(p, n + 1))
63875+ return 0;
63876+ } else {
63877+ for (--p; n < endp; ++n)
63878+ if (*n == c && !glob_match(p, n))
63879+ return 0;
63880+ }
63881+
63882+ return 1;
63883+ }
63884+ case '[':
63885+ {
63886+ int not;
63887+ char cold;
63888+
63889+ if (*n == '\0' || *n == '/')
63890+ return 1;
63891+
63892+ not = (*p == '!' || *p == '^');
63893+ if (not)
63894+ ++p;
63895+
63896+ c = *p++;
63897+ for (;;) {
63898+ unsigned char fn = (unsigned char)*n;
63899+
63900+ if (c == '\0')
63901+ return 1;
63902+ else {
63903+ if (c == fn)
63904+ goto matched;
63905+ cold = c;
63906+ c = *p++;
63907+
63908+ if (c == '-' && *p != ']') {
63909+ unsigned char cend = *p++;
63910+
63911+ if (cend == '\0')
63912+ return 1;
63913+
63914+ if (cold <= fn && fn <= cend)
63915+ goto matched;
63916+
63917+ c = *p++;
63918+ }
63919+ }
63920+
63921+ if (c == ']')
63922+ break;
63923+ }
63924+ if (!not)
63925+ return 1;
63926+ break;
63927+ matched:
63928+ while (c != ']') {
63929+ if (c == '\0')
63930+ return 1;
63931+
63932+ c = *p++;
63933+ }
63934+ if (not)
63935+ return 1;
63936+ }
63937+ break;
63938+ default:
63939+ if (c != *n)
63940+ return 1;
63941+ }
63942+
63943+ ++n;
63944+ }
63945+
63946+ if (*n == '\0')
63947+ return 0;
63948+
63949+ if (*n == '/')
63950+ return 0;
63951+
63952+ return 1;
63953+}
63954+
63955+static struct acl_object_label *
63956+chk_glob_label(struct acl_object_label *globbed,
63957+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
63958+{
63959+ struct acl_object_label *tmp;
63960+
63961+ if (*path == NULL)
63962+ *path = gr_to_filename_nolock(dentry, mnt);
63963+
63964+ tmp = globbed;
63965+
63966+ while (tmp) {
63967+ if (!glob_match(tmp->filename, *path))
63968+ return tmp;
63969+ tmp = tmp->next;
63970+ }
63971+
63972+ return NULL;
63973+}
63974+
63975+static struct acl_object_label *
63976+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
63977+ const ino_t curr_ino, const dev_t curr_dev,
63978+ const struct acl_subject_label *subj, char **path, const int checkglob)
63979+{
63980+ struct acl_subject_label *tmpsubj;
63981+ struct acl_object_label *retval;
63982+ struct acl_object_label *retval2;
63983+
63984+ tmpsubj = (struct acl_subject_label *) subj;
63985+ read_lock(&gr_inode_lock);
63986+ do {
63987+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
63988+ if (retval) {
63989+ if (checkglob && retval->globbed) {
63990+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
63991+ if (retval2)
63992+ retval = retval2;
63993+ }
63994+ break;
63995+ }
63996+ } while ((tmpsubj = tmpsubj->parent_subject));
63997+ read_unlock(&gr_inode_lock);
63998+
63999+ return retval;
64000+}
64001+
64002+static __inline__ struct acl_object_label *
64003+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
64004+ struct dentry *curr_dentry,
64005+ const struct acl_subject_label *subj, char **path, const int checkglob)
64006+{
64007+ int newglob = checkglob;
64008+ ino_t inode;
64009+ dev_t device;
64010+
64011+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
64012+ as we don't want a / * rule to match instead of the / object
64013+ don't do this for create lookups that call this function though, since they're looking up
64014+ on the parent and thus need globbing checks on all paths
64015+ */
64016+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
64017+ newglob = GR_NO_GLOB;
64018+
64019+ spin_lock(&curr_dentry->d_lock);
64020+ inode = curr_dentry->d_inode->i_ino;
64021+ device = __get_dev(curr_dentry);
64022+ spin_unlock(&curr_dentry->d_lock);
64023+
64024+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
64025+}
64026+
64027+#ifdef CONFIG_HUGETLBFS
64028+static inline bool
64029+is_hugetlbfs_mnt(const struct vfsmount *mnt)
64030+{
64031+ int i;
64032+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
64033+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
64034+ return true;
64035+ }
64036+
64037+ return false;
64038+}
64039+#endif
64040+
64041+static struct acl_object_label *
64042+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64043+ const struct acl_subject_label *subj, char *path, const int checkglob)
64044+{
64045+ struct dentry *dentry = (struct dentry *) l_dentry;
64046+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
64047+ struct mount *real_mnt = real_mount(mnt);
64048+ struct acl_object_label *retval;
64049+ struct dentry *parent;
64050+
64051+ br_read_lock(&vfsmount_lock);
64052+ write_seqlock(&rename_lock);
64053+
64054+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
64055+#ifdef CONFIG_NET
64056+ mnt == sock_mnt ||
64057+#endif
64058+#ifdef CONFIG_HUGETLBFS
64059+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
64060+#endif
64061+ /* ignore Eric Biederman */
64062+ IS_PRIVATE(l_dentry->d_inode))) {
64063+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
64064+ goto out;
64065+ }
64066+
64067+ for (;;) {
64068+ if (dentry == real_root.dentry && mnt == real_root.mnt)
64069+ break;
64070+
64071+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
64072+ if (!mnt_has_parent(real_mnt))
64073+ break;
64074+
64075+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
64076+ if (retval != NULL)
64077+ goto out;
64078+
64079+ dentry = real_mnt->mnt_mountpoint;
64080+ real_mnt = real_mnt->mnt_parent;
64081+ mnt = &real_mnt->mnt;
64082+ continue;
64083+ }
64084+
64085+ parent = dentry->d_parent;
64086+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
64087+ if (retval != NULL)
64088+ goto out;
64089+
64090+ dentry = parent;
64091+ }
64092+
64093+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
64094+
64095+ /* real_root is pinned so we don't have to hold a reference */
64096+ if (retval == NULL)
64097+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
64098+out:
64099+ write_sequnlock(&rename_lock);
64100+ br_read_unlock(&vfsmount_lock);
64101+
64102+ BUG_ON(retval == NULL);
64103+
64104+ return retval;
64105+}
64106+
64107+static __inline__ struct acl_object_label *
64108+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64109+ const struct acl_subject_label *subj)
64110+{
64111+ char *path = NULL;
64112+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
64113+}
64114+
64115+static __inline__ struct acl_object_label *
64116+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64117+ const struct acl_subject_label *subj)
64118+{
64119+ char *path = NULL;
64120+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
64121+}
64122+
64123+static __inline__ struct acl_object_label *
64124+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64125+ const struct acl_subject_label *subj, char *path)
64126+{
64127+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
64128+}
64129+
64130+static struct acl_subject_label *
64131+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64132+ const struct acl_role_label *role)
64133+{
64134+ struct dentry *dentry = (struct dentry *) l_dentry;
64135+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
64136+ struct mount *real_mnt = real_mount(mnt);
64137+ struct acl_subject_label *retval;
64138+ struct dentry *parent;
64139+
64140+ br_read_lock(&vfsmount_lock);
64141+ write_seqlock(&rename_lock);
64142+
64143+ for (;;) {
64144+ if (dentry == real_root.dentry && mnt == real_root.mnt)
64145+ break;
64146+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
64147+ if (!mnt_has_parent(real_mnt))
64148+ break;
64149+
64150+ spin_lock(&dentry->d_lock);
64151+ read_lock(&gr_inode_lock);
64152+ retval =
64153+ lookup_acl_subj_label(dentry->d_inode->i_ino,
64154+ __get_dev(dentry), role);
64155+ read_unlock(&gr_inode_lock);
64156+ spin_unlock(&dentry->d_lock);
64157+ if (retval != NULL)
64158+ goto out;
64159+
64160+ dentry = real_mnt->mnt_mountpoint;
64161+ real_mnt = real_mnt->mnt_parent;
64162+ mnt = &real_mnt->mnt;
64163+ continue;
64164+ }
64165+
64166+ spin_lock(&dentry->d_lock);
64167+ read_lock(&gr_inode_lock);
64168+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
64169+ __get_dev(dentry), role);
64170+ read_unlock(&gr_inode_lock);
64171+ parent = dentry->d_parent;
64172+ spin_unlock(&dentry->d_lock);
64173+
64174+ if (retval != NULL)
64175+ goto out;
64176+
64177+ dentry = parent;
64178+ }
64179+
64180+ spin_lock(&dentry->d_lock);
64181+ read_lock(&gr_inode_lock);
64182+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
64183+ __get_dev(dentry), role);
64184+ read_unlock(&gr_inode_lock);
64185+ spin_unlock(&dentry->d_lock);
64186+
64187+ if (unlikely(retval == NULL)) {
64188+ /* real_root is pinned, we don't need to hold a reference */
64189+ read_lock(&gr_inode_lock);
64190+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
64191+ __get_dev(real_root.dentry), role);
64192+ read_unlock(&gr_inode_lock);
64193+ }
64194+out:
64195+ write_sequnlock(&rename_lock);
64196+ br_read_unlock(&vfsmount_lock);
64197+
64198+ BUG_ON(retval == NULL);
64199+
64200+ return retval;
64201+}
64202+
64203+static void
64204+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
64205+{
64206+ struct task_struct *task = current;
64207+ const struct cred *cred = current_cred();
64208+
64209+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
64210+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
64211+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
64212+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
64213+
64214+ return;
64215+}
64216+
64217+static void
64218+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
64219+{
64220+ struct task_struct *task = current;
64221+ const struct cred *cred = current_cred();
64222+
64223+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
64224+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
64225+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
64226+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
64227+
64228+ return;
64229+}
64230+
64231+static void
64232+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
64233+{
64234+ struct task_struct *task = current;
64235+ const struct cred *cred = current_cred();
64236+
64237+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
64238+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
64239+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
64240+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
64241+
64242+ return;
64243+}
64244+
64245+__u32
64246+gr_search_file(const struct dentry * dentry, const __u32 mode,
64247+ const struct vfsmount * mnt)
64248+{
64249+ __u32 retval = mode;
64250+ struct acl_subject_label *curracl;
64251+ struct acl_object_label *currobj;
64252+
64253+ if (unlikely(!(gr_status & GR_READY)))
64254+ return (mode & ~GR_AUDITS);
64255+
64256+ curracl = current->acl;
64257+
64258+ currobj = chk_obj_label(dentry, mnt, curracl);
64259+ retval = currobj->mode & mode;
64260+
64261+ /* if we're opening a specified transfer file for writing
64262+ (e.g. /dev/initctl), then transfer our role to init
64263+ */
64264+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
64265+ current->role->roletype & GR_ROLE_PERSIST)) {
64266+ struct task_struct *task = init_pid_ns.child_reaper;
64267+
64268+ if (task->role != current->role) {
64269+ task->acl_sp_role = 0;
64270+ task->acl_role_id = current->acl_role_id;
64271+ task->role = current->role;
64272+ rcu_read_lock();
64273+ read_lock(&grsec_exec_file_lock);
64274+ gr_apply_subject_to_task(task);
64275+ read_unlock(&grsec_exec_file_lock);
64276+ rcu_read_unlock();
64277+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
64278+ }
64279+ }
64280+
64281+ if (unlikely
64282+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
64283+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
64284+ __u32 new_mode = mode;
64285+
64286+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
64287+
64288+ retval = new_mode;
64289+
64290+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
64291+ new_mode |= GR_INHERIT;
64292+
64293+ if (!(mode & GR_NOLEARN))
64294+ gr_log_learn(dentry, mnt, new_mode);
64295+ }
64296+
64297+ return retval;
64298+}
64299+
64300+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
64301+ const struct dentry *parent,
64302+ const struct vfsmount *mnt)
64303+{
64304+ struct name_entry *match;
64305+ struct acl_object_label *matchpo;
64306+ struct acl_subject_label *curracl;
64307+ char *path;
64308+
64309+ if (unlikely(!(gr_status & GR_READY)))
64310+ return NULL;
64311+
64312+ preempt_disable();
64313+ path = gr_to_filename_rbac(new_dentry, mnt);
64314+ match = lookup_name_entry_create(path);
64315+
64316+ curracl = current->acl;
64317+
64318+ if (match) {
64319+ read_lock(&gr_inode_lock);
64320+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
64321+ read_unlock(&gr_inode_lock);
64322+
64323+ if (matchpo) {
64324+ preempt_enable();
64325+ return matchpo;
64326+ }
64327+ }
64328+
64329+ // lookup parent
64330+
64331+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
64332+
64333+ preempt_enable();
64334+ return matchpo;
64335+}
64336+
64337+__u32
64338+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
64339+ const struct vfsmount * mnt, const __u32 mode)
64340+{
64341+ struct acl_object_label *matchpo;
64342+ __u32 retval;
64343+
64344+ if (unlikely(!(gr_status & GR_READY)))
64345+ return (mode & ~GR_AUDITS);
64346+
64347+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
64348+
64349+ retval = matchpo->mode & mode;
64350+
64351+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
64352+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
64353+ __u32 new_mode = mode;
64354+
64355+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
64356+
64357+ gr_log_learn(new_dentry, mnt, new_mode);
64358+ return new_mode;
64359+ }
64360+
64361+ return retval;
64362+}
64363+
64364+__u32
64365+gr_check_link(const struct dentry * new_dentry,
64366+ const struct dentry * parent_dentry,
64367+ const struct vfsmount * parent_mnt,
64368+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
64369+{
64370+ struct acl_object_label *obj;
64371+ __u32 oldmode, newmode;
64372+ __u32 needmode;
64373+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
64374+ GR_DELETE | GR_INHERIT;
64375+
64376+ if (unlikely(!(gr_status & GR_READY)))
64377+ return (GR_CREATE | GR_LINK);
64378+
64379+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
64380+ oldmode = obj->mode;
64381+
64382+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
64383+ newmode = obj->mode;
64384+
64385+ needmode = newmode & checkmodes;
64386+
64387+ // old name for hardlink must have at least the permissions of the new name
64388+ if ((oldmode & needmode) != needmode)
64389+ goto bad;
64390+
64391+ // if old name had restrictions/auditing, make sure the new name does as well
64392+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
64393+
64394+ // don't allow hardlinking of suid/sgid/fcapped files without permission
64395+ if (is_privileged_binary(old_dentry))
64396+ needmode |= GR_SETID;
64397+
64398+ if ((newmode & needmode) != needmode)
64399+ goto bad;
64400+
64401+ // enforce minimum permissions
64402+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
64403+ return newmode;
64404+bad:
64405+ needmode = oldmode;
64406+ if (is_privileged_binary(old_dentry))
64407+ needmode |= GR_SETID;
64408+
64409+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
64410+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
64411+ return (GR_CREATE | GR_LINK);
64412+ } else if (newmode & GR_SUPPRESS)
64413+ return GR_SUPPRESS;
64414+ else
64415+ return 0;
64416+}
64417+
64418+int
64419+gr_check_hidden_task(const struct task_struct *task)
64420+{
64421+ if (unlikely(!(gr_status & GR_READY)))
64422+ return 0;
64423+
64424+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
64425+ return 1;
64426+
64427+ return 0;
64428+}
64429+
64430+int
64431+gr_check_protected_task(const struct task_struct *task)
64432+{
64433+ if (unlikely(!(gr_status & GR_READY) || !task))
64434+ return 0;
64435+
64436+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
64437+ task->acl != current->acl)
64438+ return 1;
64439+
64440+ return 0;
64441+}
64442+
64443+int
64444+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
64445+{
64446+ struct task_struct *p;
64447+ int ret = 0;
64448+
64449+ if (unlikely(!(gr_status & GR_READY) || !pid))
64450+ return ret;
64451+
64452+ read_lock(&tasklist_lock);
64453+ do_each_pid_task(pid, type, p) {
64454+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
64455+ p->acl != current->acl) {
64456+ ret = 1;
64457+ goto out;
64458+ }
64459+ } while_each_pid_task(pid, type, p);
64460+out:
64461+ read_unlock(&tasklist_lock);
64462+
64463+ return ret;
64464+}
64465+
64466+void
64467+gr_copy_label(struct task_struct *tsk)
64468+{
64469+ tsk->signal->used_accept = 0;
64470+ tsk->acl_sp_role = 0;
64471+ tsk->acl_role_id = current->acl_role_id;
64472+ tsk->acl = current->acl;
64473+ tsk->role = current->role;
64474+ tsk->signal->curr_ip = current->signal->curr_ip;
64475+ tsk->signal->saved_ip = current->signal->saved_ip;
64476+ if (current->exec_file)
64477+ get_file(current->exec_file);
64478+ tsk->exec_file = current->exec_file;
64479+ tsk->is_writable = current->is_writable;
64480+ if (unlikely(current->signal->used_accept)) {
64481+ current->signal->curr_ip = 0;
64482+ current->signal->saved_ip = 0;
64483+ }
64484+
64485+ return;
64486+}
64487+
64488+static void
64489+gr_set_proc_res(struct task_struct *task)
64490+{
64491+ struct acl_subject_label *proc;
64492+ unsigned short i;
64493+
64494+ proc = task->acl;
64495+
64496+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
64497+ return;
64498+
64499+ for (i = 0; i < RLIM_NLIMITS; i++) {
64500+ if (!(proc->resmask & (1U << i)))
64501+ continue;
64502+
64503+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
64504+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
64505+
64506+ if (i == RLIMIT_CPU)
64507+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
64508+ }
64509+
64510+ return;
64511+}
64512+
64513+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
64514+
64515+int
64516+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
64517+{
64518+ unsigned int i;
64519+ __u16 num;
64520+ uid_t *uidlist;
64521+ uid_t curuid;
64522+ int realok = 0;
64523+ int effectiveok = 0;
64524+ int fsok = 0;
64525+ uid_t globalreal, globaleffective, globalfs;
64526+
64527+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
64528+ struct user_struct *user;
64529+
64530+ if (!uid_valid(real))
64531+ goto skipit;
64532+
64533+ /* find user based on global namespace */
64534+
64535+ globalreal = GR_GLOBAL_UID(real);
64536+
64537+ user = find_user(make_kuid(&init_user_ns, globalreal));
64538+ if (user == NULL)
64539+ goto skipit;
64540+
64541+ if (gr_process_kernel_setuid_ban(user)) {
64542+ /* for find_user */
64543+ free_uid(user);
64544+ return 1;
64545+ }
64546+
64547+ /* for find_user */
64548+ free_uid(user);
64549+
64550+skipit:
64551+#endif
64552+
64553+ if (unlikely(!(gr_status & GR_READY)))
64554+ return 0;
64555+
64556+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
64557+ gr_log_learn_uid_change(real, effective, fs);
64558+
64559+ num = current->acl->user_trans_num;
64560+ uidlist = current->acl->user_transitions;
64561+
64562+ if (uidlist == NULL)
64563+ return 0;
64564+
64565+ if (!uid_valid(real)) {
64566+ realok = 1;
64567+ globalreal = (uid_t)-1;
64568+ } else {
64569+ globalreal = GR_GLOBAL_UID(real);
64570+ }
64571+ if (!uid_valid(effective)) {
64572+ effectiveok = 1;
64573+ globaleffective = (uid_t)-1;
64574+ } else {
64575+ globaleffective = GR_GLOBAL_UID(effective);
64576+ }
64577+ if (!uid_valid(fs)) {
64578+ fsok = 1;
64579+ globalfs = (uid_t)-1;
64580+ } else {
64581+ globalfs = GR_GLOBAL_UID(fs);
64582+ }
64583+
64584+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
64585+ for (i = 0; i < num; i++) {
64586+ curuid = uidlist[i];
64587+ if (globalreal == curuid)
64588+ realok = 1;
64589+ if (globaleffective == curuid)
64590+ effectiveok = 1;
64591+ if (globalfs == curuid)
64592+ fsok = 1;
64593+ }
64594+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
64595+ for (i = 0; i < num; i++) {
64596+ curuid = uidlist[i];
64597+ if (globalreal == curuid)
64598+ break;
64599+ if (globaleffective == curuid)
64600+ break;
64601+ if (globalfs == curuid)
64602+ break;
64603+ }
64604+ /* not in deny list */
64605+ if (i == num) {
64606+ realok = 1;
64607+ effectiveok = 1;
64608+ fsok = 1;
64609+ }
64610+ }
64611+
64612+ if (realok && effectiveok && fsok)
64613+ return 0;
64614+ else {
64615+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
64616+ return 1;
64617+ }
64618+}
64619+
64620+int
64621+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
64622+{
64623+ unsigned int i;
64624+ __u16 num;
64625+ gid_t *gidlist;
64626+ gid_t curgid;
64627+ int realok = 0;
64628+ int effectiveok = 0;
64629+ int fsok = 0;
64630+ gid_t globalreal, globaleffective, globalfs;
64631+
64632+ if (unlikely(!(gr_status & GR_READY)))
64633+ return 0;
64634+
64635+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
64636+ gr_log_learn_gid_change(real, effective, fs);
64637+
64638+ num = current->acl->group_trans_num;
64639+ gidlist = current->acl->group_transitions;
64640+
64641+ if (gidlist == NULL)
64642+ return 0;
64643+
64644+ if (!gid_valid(real)) {
64645+ realok = 1;
64646+ globalreal = (gid_t)-1;
64647+ } else {
64648+ globalreal = GR_GLOBAL_GID(real);
64649+ }
64650+ if (!gid_valid(effective)) {
64651+ effectiveok = 1;
64652+ globaleffective = (gid_t)-1;
64653+ } else {
64654+ globaleffective = GR_GLOBAL_GID(effective);
64655+ }
64656+ if (!gid_valid(fs)) {
64657+ fsok = 1;
64658+ globalfs = (gid_t)-1;
64659+ } else {
64660+ globalfs = GR_GLOBAL_GID(fs);
64661+ }
64662+
64663+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
64664+ for (i = 0; i < num; i++) {
64665+ curgid = gidlist[i];
64666+ if (globalreal == curgid)
64667+ realok = 1;
64668+ if (globaleffective == curgid)
64669+ effectiveok = 1;
64670+ if (globalfs == curgid)
64671+ fsok = 1;
64672+ }
64673+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
64674+ for (i = 0; i < num; i++) {
64675+ curgid = gidlist[i];
64676+ if (globalreal == curgid)
64677+ break;
64678+ if (globaleffective == curgid)
64679+ break;
64680+ if (globalfs == curgid)
64681+ break;
64682+ }
64683+ /* not in deny list */
64684+ if (i == num) {
64685+ realok = 1;
64686+ effectiveok = 1;
64687+ fsok = 1;
64688+ }
64689+ }
64690+
64691+ if (realok && effectiveok && fsok)
64692+ return 0;
64693+ else {
64694+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
64695+ return 1;
64696+ }
64697+}
64698+
64699+extern int gr_acl_is_capable(const int cap);
64700+
64701+void
64702+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
64703+{
64704+ struct acl_role_label *role = task->role;
64705+ struct acl_subject_label *subj = NULL;
64706+ struct acl_object_label *obj;
64707+ struct file *filp;
64708+ uid_t uid;
64709+ gid_t gid;
64710+
64711+ if (unlikely(!(gr_status & GR_READY)))
64712+ return;
64713+
64714+ uid = GR_GLOBAL_UID(kuid);
64715+ gid = GR_GLOBAL_GID(kgid);
64716+
64717+ filp = task->exec_file;
64718+
64719+ /* kernel process, we'll give them the kernel role */
64720+ if (unlikely(!filp)) {
64721+ task->role = kernel_role;
64722+ task->acl = kernel_role->root_label;
64723+ return;
64724+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
64725+ role = lookup_acl_role_label(task, uid, gid);
64726+
64727+ /* don't change the role if we're not a privileged process */
64728+ if (role && task->role != role &&
64729+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
64730+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
64731+ return;
64732+
64733+ /* perform subject lookup in possibly new role
64734+ we can use this result below in the case where role == task->role
64735+ */
64736+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
64737+
64738+ /* if we changed uid/gid, but result in the same role
64739+ and are using inheritance, don't lose the inherited subject
64740+ if current subject is other than what normal lookup
64741+ would result in, we arrived via inheritance, don't
64742+ lose subject
64743+ */
64744+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
64745+ (subj == task->acl)))
64746+ task->acl = subj;
64747+
64748+ task->role = role;
64749+
64750+ task->is_writable = 0;
64751+
64752+ /* ignore additional mmap checks for processes that are writable
64753+ by the default ACL */
64754+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
64755+ if (unlikely(obj->mode & GR_WRITE))
64756+ task->is_writable = 1;
64757+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
64758+ if (unlikely(obj->mode & GR_WRITE))
64759+ task->is_writable = 1;
64760+
64761+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
64762+ 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);
64763+#endif
64764+
64765+ gr_set_proc_res(task);
64766+
64767+ return;
64768+}
64769+
64770+int
64771+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
64772+ const int unsafe_flags)
64773+{
64774+ struct task_struct *task = current;
64775+ struct acl_subject_label *newacl;
64776+ struct acl_object_label *obj;
64777+ __u32 retmode;
64778+
64779+ if (unlikely(!(gr_status & GR_READY)))
64780+ return 0;
64781+
64782+ newacl = chk_subj_label(dentry, mnt, task->role);
64783+
64784+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
64785+ did an exec
64786+ */
64787+ rcu_read_lock();
64788+ read_lock(&tasklist_lock);
64789+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
64790+ (task->parent->acl->mode & GR_POVERRIDE))) {
64791+ read_unlock(&tasklist_lock);
64792+ rcu_read_unlock();
64793+ goto skip_check;
64794+ }
64795+ read_unlock(&tasklist_lock);
64796+ rcu_read_unlock();
64797+
64798+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
64799+ !(task->role->roletype & GR_ROLE_GOD) &&
64800+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
64801+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
64802+ if (unsafe_flags & LSM_UNSAFE_SHARE)
64803+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
64804+ else
64805+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
64806+ return -EACCES;
64807+ }
64808+
64809+skip_check:
64810+
64811+ obj = chk_obj_label(dentry, mnt, task->acl);
64812+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
64813+
64814+ if (!(task->acl->mode & GR_INHERITLEARN) &&
64815+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
64816+ if (obj->nested)
64817+ task->acl = obj->nested;
64818+ else
64819+ task->acl = newacl;
64820+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
64821+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
64822+
64823+ task->is_writable = 0;
64824+
64825+ /* ignore additional mmap checks for processes that are writable
64826+ by the default ACL */
64827+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
64828+ if (unlikely(obj->mode & GR_WRITE))
64829+ task->is_writable = 1;
64830+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
64831+ if (unlikely(obj->mode & GR_WRITE))
64832+ task->is_writable = 1;
64833+
64834+ gr_set_proc_res(task);
64835+
64836+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
64837+ 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);
64838+#endif
64839+ return 0;
64840+}
64841+
64842+/* always called with valid inodev ptr */
64843+static void
64844+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
64845+{
64846+ struct acl_object_label *matchpo;
64847+ struct acl_subject_label *matchps;
64848+ struct acl_subject_label *subj;
64849+ struct acl_role_label *role;
64850+ unsigned int x;
64851+
64852+ FOR_EACH_ROLE_START(role)
64853+ FOR_EACH_SUBJECT_START(role, subj, x)
64854+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
64855+ matchpo->mode |= GR_DELETED;
64856+ FOR_EACH_SUBJECT_END(subj,x)
64857+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
64858+ /* nested subjects aren't in the role's subj_hash table */
64859+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
64860+ matchpo->mode |= GR_DELETED;
64861+ FOR_EACH_NESTED_SUBJECT_END(subj)
64862+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
64863+ matchps->mode |= GR_DELETED;
64864+ FOR_EACH_ROLE_END(role)
64865+
64866+ inodev->nentry->deleted = 1;
64867+
64868+ return;
64869+}
64870+
64871+void
64872+gr_handle_delete(const ino_t ino, const dev_t dev)
64873+{
64874+ struct inodev_entry *inodev;
64875+
64876+ if (unlikely(!(gr_status & GR_READY)))
64877+ return;
64878+
64879+ write_lock(&gr_inode_lock);
64880+ inodev = lookup_inodev_entry(ino, dev);
64881+ if (inodev != NULL)
64882+ do_handle_delete(inodev, ino, dev);
64883+ write_unlock(&gr_inode_lock);
64884+
64885+ return;
64886+}
64887+
64888+static void
64889+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
64890+ const ino_t newinode, const dev_t newdevice,
64891+ struct acl_subject_label *subj)
64892+{
64893+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
64894+ struct acl_object_label *match;
64895+
64896+ match = subj->obj_hash[index];
64897+
64898+ while (match && (match->inode != oldinode ||
64899+ match->device != olddevice ||
64900+ !(match->mode & GR_DELETED)))
64901+ match = match->next;
64902+
64903+ if (match && (match->inode == oldinode)
64904+ && (match->device == olddevice)
64905+ && (match->mode & GR_DELETED)) {
64906+ if (match->prev == NULL) {
64907+ subj->obj_hash[index] = match->next;
64908+ if (match->next != NULL)
64909+ match->next->prev = NULL;
64910+ } else {
64911+ match->prev->next = match->next;
64912+ if (match->next != NULL)
64913+ match->next->prev = match->prev;
64914+ }
64915+ match->prev = NULL;
64916+ match->next = NULL;
64917+ match->inode = newinode;
64918+ match->device = newdevice;
64919+ match->mode &= ~GR_DELETED;
64920+
64921+ insert_acl_obj_label(match, subj);
64922+ }
64923+
64924+ return;
64925+}
64926+
64927+static void
64928+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
64929+ const ino_t newinode, const dev_t newdevice,
64930+ struct acl_role_label *role)
64931+{
64932+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
64933+ struct acl_subject_label *match;
64934+
64935+ match = role->subj_hash[index];
64936+
64937+ while (match && (match->inode != oldinode ||
64938+ match->device != olddevice ||
64939+ !(match->mode & GR_DELETED)))
64940+ match = match->next;
64941+
64942+ if (match && (match->inode == oldinode)
64943+ && (match->device == olddevice)
64944+ && (match->mode & GR_DELETED)) {
64945+ if (match->prev == NULL) {
64946+ role->subj_hash[index] = match->next;
64947+ if (match->next != NULL)
64948+ match->next->prev = NULL;
64949+ } else {
64950+ match->prev->next = match->next;
64951+ if (match->next != NULL)
64952+ match->next->prev = match->prev;
64953+ }
64954+ match->prev = NULL;
64955+ match->next = NULL;
64956+ match->inode = newinode;
64957+ match->device = newdevice;
64958+ match->mode &= ~GR_DELETED;
64959+
64960+ insert_acl_subj_label(match, role);
64961+ }
64962+
64963+ return;
64964+}
64965+
64966+static void
64967+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
64968+ const ino_t newinode, const dev_t newdevice)
64969+{
64970+ unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
64971+ struct inodev_entry *match;
64972+
64973+ match = inodev_set.i_hash[index];
64974+
64975+ while (match && (match->nentry->inode != oldinode ||
64976+ match->nentry->device != olddevice || !match->nentry->deleted))
64977+ match = match->next;
64978+
64979+ if (match && (match->nentry->inode == oldinode)
64980+ && (match->nentry->device == olddevice) &&
64981+ match->nentry->deleted) {
64982+ if (match->prev == NULL) {
64983+ inodev_set.i_hash[index] = match->next;
64984+ if (match->next != NULL)
64985+ match->next->prev = NULL;
64986+ } else {
64987+ match->prev->next = match->next;
64988+ if (match->next != NULL)
64989+ match->next->prev = match->prev;
64990+ }
64991+ match->prev = NULL;
64992+ match->next = NULL;
64993+ match->nentry->inode = newinode;
64994+ match->nentry->device = newdevice;
64995+ match->nentry->deleted = 0;
64996+
64997+ insert_inodev_entry(match);
64998+ }
64999+
65000+ return;
65001+}
65002+
65003+static void
65004+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
65005+{
65006+ struct acl_subject_label *subj;
65007+ struct acl_role_label *role;
65008+ unsigned int x;
65009+
65010+ FOR_EACH_ROLE_START(role)
65011+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
65012+
65013+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
65014+ if ((subj->inode == ino) && (subj->device == dev)) {
65015+ subj->inode = ino;
65016+ subj->device = dev;
65017+ }
65018+ /* nested subjects aren't in the role's subj_hash table */
65019+ update_acl_obj_label(matchn->inode, matchn->device,
65020+ ino, dev, subj);
65021+ FOR_EACH_NESTED_SUBJECT_END(subj)
65022+ FOR_EACH_SUBJECT_START(role, subj, x)
65023+ update_acl_obj_label(matchn->inode, matchn->device,
65024+ ino, dev, subj);
65025+ FOR_EACH_SUBJECT_END(subj,x)
65026+ FOR_EACH_ROLE_END(role)
65027+
65028+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
65029+
65030+ return;
65031+}
65032+
65033+static void
65034+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
65035+ const struct vfsmount *mnt)
65036+{
65037+ ino_t ino = dentry->d_inode->i_ino;
65038+ dev_t dev = __get_dev(dentry);
65039+
65040+ __do_handle_create(matchn, ino, dev);
65041+
65042+ return;
65043+}
65044+
65045+void
65046+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
65047+{
65048+ struct name_entry *matchn;
65049+
65050+ if (unlikely(!(gr_status & GR_READY)))
65051+ return;
65052+
65053+ preempt_disable();
65054+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
65055+
65056+ if (unlikely((unsigned long)matchn)) {
65057+ write_lock(&gr_inode_lock);
65058+ do_handle_create(matchn, dentry, mnt);
65059+ write_unlock(&gr_inode_lock);
65060+ }
65061+ preempt_enable();
65062+
65063+ return;
65064+}
65065+
65066+void
65067+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
65068+{
65069+ struct name_entry *matchn;
65070+
65071+ if (unlikely(!(gr_status & GR_READY)))
65072+ return;
65073+
65074+ preempt_disable();
65075+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
65076+
65077+ if (unlikely((unsigned long)matchn)) {
65078+ write_lock(&gr_inode_lock);
65079+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
65080+ write_unlock(&gr_inode_lock);
65081+ }
65082+ preempt_enable();
65083+
65084+ return;
65085+}
65086+
65087+void
65088+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
65089+ struct dentry *old_dentry,
65090+ struct dentry *new_dentry,
65091+ struct vfsmount *mnt, const __u8 replace)
65092+{
65093+ struct name_entry *matchn;
65094+ struct inodev_entry *inodev;
65095+ struct inode *inode = new_dentry->d_inode;
65096+ ino_t old_ino = old_dentry->d_inode->i_ino;
65097+ dev_t old_dev = __get_dev(old_dentry);
65098+
65099+ /* vfs_rename swaps the name and parent link for old_dentry and
65100+ new_dentry
65101+ at this point, old_dentry has the new name, parent link, and inode
65102+ for the renamed file
65103+ if a file is being replaced by a rename, new_dentry has the inode
65104+ and name for the replaced file
65105+ */
65106+
65107+ if (unlikely(!(gr_status & GR_READY)))
65108+ return;
65109+
65110+ preempt_disable();
65111+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
65112+
65113+ /* we wouldn't have to check d_inode if it weren't for
65114+ NFS silly-renaming
65115+ */
65116+
65117+ write_lock(&gr_inode_lock);
65118+ if (unlikely(replace && inode)) {
65119+ ino_t new_ino = inode->i_ino;
65120+ dev_t new_dev = __get_dev(new_dentry);
65121+
65122+ inodev = lookup_inodev_entry(new_ino, new_dev);
65123+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
65124+ do_handle_delete(inodev, new_ino, new_dev);
65125+ }
65126+
65127+ inodev = lookup_inodev_entry(old_ino, old_dev);
65128+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
65129+ do_handle_delete(inodev, old_ino, old_dev);
65130+
65131+ if (unlikely((unsigned long)matchn))
65132+ do_handle_create(matchn, old_dentry, mnt);
65133+
65134+ write_unlock(&gr_inode_lock);
65135+ preempt_enable();
65136+
65137+ return;
65138+}
65139+
65140+static int
65141+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
65142+ unsigned char **sum)
65143+{
65144+ struct acl_role_label *r;
65145+ struct role_allowed_ip *ipp;
65146+ struct role_transition *trans;
65147+ unsigned int i;
65148+ int found = 0;
65149+ u32 curr_ip = current->signal->curr_ip;
65150+
65151+ current->signal->saved_ip = curr_ip;
65152+
65153+ /* check transition table */
65154+
65155+ for (trans = current->role->transitions; trans; trans = trans->next) {
65156+ if (!strcmp(rolename, trans->rolename)) {
65157+ found = 1;
65158+ break;
65159+ }
65160+ }
65161+
65162+ if (!found)
65163+ return 0;
65164+
65165+ /* handle special roles that do not require authentication
65166+ and check ip */
65167+
65168+ FOR_EACH_ROLE_START(r)
65169+ if (!strcmp(rolename, r->rolename) &&
65170+ (r->roletype & GR_ROLE_SPECIAL)) {
65171+ found = 0;
65172+ if (r->allowed_ips != NULL) {
65173+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
65174+ if ((ntohl(curr_ip) & ipp->netmask) ==
65175+ (ntohl(ipp->addr) & ipp->netmask))
65176+ found = 1;
65177+ }
65178+ } else
65179+ found = 2;
65180+ if (!found)
65181+ return 0;
65182+
65183+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
65184+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
65185+ *salt = NULL;
65186+ *sum = NULL;
65187+ return 1;
65188+ }
65189+ }
65190+ FOR_EACH_ROLE_END(r)
65191+
65192+ for (i = 0; i < num_sprole_pws; i++) {
65193+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
65194+ *salt = acl_special_roles[i]->salt;
65195+ *sum = acl_special_roles[i]->sum;
65196+ return 1;
65197+ }
65198+ }
65199+
65200+ return 0;
65201+}
65202+
65203+static void
65204+assign_special_role(char *rolename)
65205+{
65206+ struct acl_object_label *obj;
65207+ struct acl_role_label *r;
65208+ struct acl_role_label *assigned = NULL;
65209+ struct task_struct *tsk;
65210+ struct file *filp;
65211+
65212+ FOR_EACH_ROLE_START(r)
65213+ if (!strcmp(rolename, r->rolename) &&
65214+ (r->roletype & GR_ROLE_SPECIAL)) {
65215+ assigned = r;
65216+ break;
65217+ }
65218+ FOR_EACH_ROLE_END(r)
65219+
65220+ if (!assigned)
65221+ return;
65222+
65223+ read_lock(&tasklist_lock);
65224+ read_lock(&grsec_exec_file_lock);
65225+
65226+ tsk = current->real_parent;
65227+ if (tsk == NULL)
65228+ goto out_unlock;
65229+
65230+ filp = tsk->exec_file;
65231+ if (filp == NULL)
65232+ goto out_unlock;
65233+
65234+ tsk->is_writable = 0;
65235+
65236+ tsk->acl_sp_role = 1;
65237+ tsk->acl_role_id = ++acl_sp_role_value;
65238+ tsk->role = assigned;
65239+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
65240+
65241+ /* ignore additional mmap checks for processes that are writable
65242+ by the default ACL */
65243+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
65244+ if (unlikely(obj->mode & GR_WRITE))
65245+ tsk->is_writable = 1;
65246+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
65247+ if (unlikely(obj->mode & GR_WRITE))
65248+ tsk->is_writable = 1;
65249+
65250+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
65251+ 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));
65252+#endif
65253+
65254+out_unlock:
65255+ read_unlock(&grsec_exec_file_lock);
65256+ read_unlock(&tasklist_lock);
65257+ return;
65258+}
65259+
65260+int gr_check_secure_terminal(struct task_struct *task)
65261+{
65262+ struct task_struct *p, *p2, *p3;
65263+ struct files_struct *files;
65264+ struct fdtable *fdt;
65265+ struct file *our_file = NULL, *file;
65266+ int i;
65267+
65268+ if (task->signal->tty == NULL)
65269+ return 1;
65270+
65271+ files = get_files_struct(task);
65272+ if (files != NULL) {
65273+ rcu_read_lock();
65274+ fdt = files_fdtable(files);
65275+ for (i=0; i < fdt->max_fds; i++) {
65276+ file = fcheck_files(files, i);
65277+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
65278+ get_file(file);
65279+ our_file = file;
65280+ }
65281+ }
65282+ rcu_read_unlock();
65283+ put_files_struct(files);
65284+ }
65285+
65286+ if (our_file == NULL)
65287+ return 1;
65288+
65289+ read_lock(&tasklist_lock);
65290+ do_each_thread(p2, p) {
65291+ files = get_files_struct(p);
65292+ if (files == NULL ||
65293+ (p->signal && p->signal->tty == task->signal->tty)) {
65294+ if (files != NULL)
65295+ put_files_struct(files);
65296+ continue;
65297+ }
65298+ rcu_read_lock();
65299+ fdt = files_fdtable(files);
65300+ for (i=0; i < fdt->max_fds; i++) {
65301+ file = fcheck_files(files, i);
65302+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
65303+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
65304+ p3 = task;
65305+ while (task_pid_nr(p3) > 0) {
65306+ if (p3 == p)
65307+ break;
65308+ p3 = p3->real_parent;
65309+ }
65310+ if (p3 == p)
65311+ break;
65312+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
65313+ gr_handle_alertkill(p);
65314+ rcu_read_unlock();
65315+ put_files_struct(files);
65316+ read_unlock(&tasklist_lock);
65317+ fput(our_file);
65318+ return 0;
65319+ }
65320+ }
65321+ rcu_read_unlock();
65322+ put_files_struct(files);
65323+ } while_each_thread(p2, p);
65324+ read_unlock(&tasklist_lock);
65325+
65326+ fput(our_file);
65327+ return 1;
65328+}
65329+
65330+static int gr_rbac_disable(void *unused)
65331+{
65332+ pax_open_kernel();
65333+ gr_status &= ~GR_READY;
65334+ pax_close_kernel();
65335+
65336+ return 0;
65337+}
65338+
65339+ssize_t
65340+write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
65341+{
65342+ struct gr_arg_wrapper uwrap;
65343+ unsigned char *sprole_salt = NULL;
65344+ unsigned char *sprole_sum = NULL;
65345+ int error = 0;
65346+ int error2 = 0;
65347+ size_t req_count = 0;
65348+
65349+ mutex_lock(&gr_dev_mutex);
65350+
65351+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
65352+ error = -EPERM;
65353+ goto out;
65354+ }
65355+
65356+#ifdef CONFIG_COMPAT
65357+ pax_open_kernel();
65358+ if (is_compat_task()) {
65359+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
65360+ copy_gr_arg = &copy_gr_arg_compat;
65361+ copy_acl_object_label = &copy_acl_object_label_compat;
65362+ copy_acl_subject_label = &copy_acl_subject_label_compat;
65363+ copy_acl_role_label = &copy_acl_role_label_compat;
65364+ copy_acl_ip_label = &copy_acl_ip_label_compat;
65365+ copy_role_allowed_ip = &copy_role_allowed_ip_compat;
65366+ copy_role_transition = &copy_role_transition_compat;
65367+ copy_sprole_pw = &copy_sprole_pw_compat;
65368+ copy_gr_hash_struct = &copy_gr_hash_struct_compat;
65369+ copy_pointer_from_array = &copy_pointer_from_array_compat;
65370+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
65371+ } else {
65372+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
65373+ copy_gr_arg = &copy_gr_arg_normal;
65374+ copy_acl_object_label = &copy_acl_object_label_normal;
65375+ copy_acl_subject_label = &copy_acl_subject_label_normal;
65376+ copy_acl_role_label = &copy_acl_role_label_normal;
65377+ copy_acl_ip_label = &copy_acl_ip_label_normal;
65378+ copy_role_allowed_ip = &copy_role_allowed_ip_normal;
65379+ copy_role_transition = &copy_role_transition_normal;
65380+ copy_sprole_pw = &copy_sprole_pw_normal;
65381+ copy_gr_hash_struct = &copy_gr_hash_struct_normal;
65382+ copy_pointer_from_array = &copy_pointer_from_array_normal;
65383+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
65384+ }
65385+ pax_close_kernel();
65386+#endif
65387+
65388+ req_count = get_gr_arg_wrapper_size();
65389+
65390+ if (count != req_count) {
65391+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
65392+ error = -EINVAL;
65393+ goto out;
65394+ }
65395+
65396+
65397+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
65398+ gr_auth_expires = 0;
65399+ gr_auth_attempts = 0;
65400+ }
65401+
65402+ error = copy_gr_arg_wrapper(buf, &uwrap);
65403+ if (error)
65404+ goto out;
65405+
65406+ error = copy_gr_arg(uwrap.arg, gr_usermode);
65407+ if (error)
65408+ goto out;
65409+
65410+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
65411+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
65412+ time_after(gr_auth_expires, get_seconds())) {
65413+ error = -EBUSY;
65414+ goto out;
65415+ }
65416+
65417+ /* if non-root trying to do anything other than use a special role,
65418+ do not attempt authentication, do not count towards authentication
65419+ locking
65420+ */
65421+
65422+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
65423+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
65424+ gr_is_global_nonroot(current_uid())) {
65425+ error = -EPERM;
65426+ goto out;
65427+ }
65428+
65429+ /* ensure pw and special role name are null terminated */
65430+
65431+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
65432+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
65433+
65434+ /* Okay.
65435+ * We have our enough of the argument structure..(we have yet
65436+ * to copy_from_user the tables themselves) . Copy the tables
65437+ * only if we need them, i.e. for loading operations. */
65438+
65439+ switch (gr_usermode->mode) {
65440+ case GR_STATUS:
65441+ if (gr_status & GR_READY) {
65442+ error = 1;
65443+ if (!gr_check_secure_terminal(current))
65444+ error = 3;
65445+ } else
65446+ error = 2;
65447+ goto out;
65448+ case GR_SHUTDOWN:
65449+ if ((gr_status & GR_READY)
65450+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
65451+ stop_machine(gr_rbac_disable, NULL, NULL);
65452+ free_variables();
65453+ memset(gr_usermode, 0, sizeof (struct gr_arg));
65454+ memset(gr_system_salt, 0, GR_SALT_LEN);
65455+ memset(gr_system_sum, 0, GR_SHA_LEN);
65456+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
65457+ } else if (gr_status & GR_READY) {
65458+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
65459+ error = -EPERM;
65460+ } else {
65461+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
65462+ error = -EAGAIN;
65463+ }
65464+ break;
65465+ case GR_ENABLE:
65466+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
65467+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
65468+ else {
65469+ if (gr_status & GR_READY)
65470+ error = -EAGAIN;
65471+ else
65472+ error = error2;
65473+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
65474+ }
65475+ break;
65476+ case GR_RELOAD:
65477+ if (!(gr_status & GR_READY)) {
65478+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
65479+ error = -EAGAIN;
65480+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
65481+ stop_machine(gr_rbac_disable, NULL, NULL);
65482+ free_variables();
65483+ error2 = gracl_init(gr_usermode);
65484+ if (!error2)
65485+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
65486+ else {
65487+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
65488+ error = error2;
65489+ }
65490+ } else {
65491+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
65492+ error = -EPERM;
65493+ }
65494+ break;
65495+ case GR_SEGVMOD:
65496+ if (unlikely(!(gr_status & GR_READY))) {
65497+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
65498+ error = -EAGAIN;
65499+ break;
65500+ }
65501+
65502+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
65503+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
65504+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
65505+ struct acl_subject_label *segvacl;
65506+ segvacl =
65507+ lookup_acl_subj_label(gr_usermode->segv_inode,
65508+ gr_usermode->segv_device,
65509+ current->role);
65510+ if (segvacl) {
65511+ segvacl->crashes = 0;
65512+ segvacl->expires = 0;
65513+ }
65514+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
65515+ gr_remove_uid(gr_usermode->segv_uid);
65516+ }
65517+ } else {
65518+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
65519+ error = -EPERM;
65520+ }
65521+ break;
65522+ case GR_SPROLE:
65523+ case GR_SPROLEPAM:
65524+ if (unlikely(!(gr_status & GR_READY))) {
65525+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
65526+ error = -EAGAIN;
65527+ break;
65528+ }
65529+
65530+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
65531+ current->role->expires = 0;
65532+ current->role->auth_attempts = 0;
65533+ }
65534+
65535+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
65536+ time_after(current->role->expires, get_seconds())) {
65537+ error = -EBUSY;
65538+ goto out;
65539+ }
65540+
65541+ if (lookup_special_role_auth
65542+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
65543+ && ((!sprole_salt && !sprole_sum)
65544+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
65545+ char *p = "";
65546+ assign_special_role(gr_usermode->sp_role);
65547+ read_lock(&tasklist_lock);
65548+ if (current->real_parent)
65549+ p = current->real_parent->role->rolename;
65550+ read_unlock(&tasklist_lock);
65551+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
65552+ p, acl_sp_role_value);
65553+ } else {
65554+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
65555+ error = -EPERM;
65556+ if(!(current->role->auth_attempts++))
65557+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
65558+
65559+ goto out;
65560+ }
65561+ break;
65562+ case GR_UNSPROLE:
65563+ if (unlikely(!(gr_status & GR_READY))) {
65564+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
65565+ error = -EAGAIN;
65566+ break;
65567+ }
65568+
65569+ if (current->role->roletype & GR_ROLE_SPECIAL) {
65570+ char *p = "";
65571+ int i = 0;
65572+
65573+ read_lock(&tasklist_lock);
65574+ if (current->real_parent) {
65575+ p = current->real_parent->role->rolename;
65576+ i = current->real_parent->acl_role_id;
65577+ }
65578+ read_unlock(&tasklist_lock);
65579+
65580+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
65581+ gr_set_acls(1);
65582+ } else {
65583+ error = -EPERM;
65584+ goto out;
65585+ }
65586+ break;
65587+ default:
65588+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
65589+ error = -EINVAL;
65590+ break;
65591+ }
65592+
65593+ if (error != -EPERM)
65594+ goto out;
65595+
65596+ if(!(gr_auth_attempts++))
65597+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
65598+
65599+ out:
65600+ mutex_unlock(&gr_dev_mutex);
65601+
65602+ if (!error)
65603+ error = req_count;
65604+
65605+ return error;
65606+}
65607+
65608+/* must be called with
65609+ rcu_read_lock();
65610+ read_lock(&tasklist_lock);
65611+ read_lock(&grsec_exec_file_lock);
65612+*/
65613+int gr_apply_subject_to_task(struct task_struct *task)
65614+{
65615+ struct acl_object_label *obj;
65616+ char *tmpname;
65617+ struct acl_subject_label *tmpsubj;
65618+ struct file *filp;
65619+ struct name_entry *nmatch;
65620+
65621+ filp = task->exec_file;
65622+ if (filp == NULL)
65623+ return 0;
65624+
65625+ /* the following is to apply the correct subject
65626+ on binaries running when the RBAC system
65627+ is enabled, when the binaries have been
65628+ replaced or deleted since their execution
65629+ -----
65630+ when the RBAC system starts, the inode/dev
65631+ from exec_file will be one the RBAC system
65632+ is unaware of. It only knows the inode/dev
65633+ of the present file on disk, or the absence
65634+ of it.
65635+ */
65636+ preempt_disable();
65637+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
65638+
65639+ nmatch = lookup_name_entry(tmpname);
65640+ preempt_enable();
65641+ tmpsubj = NULL;
65642+ if (nmatch) {
65643+ if (nmatch->deleted)
65644+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
65645+ else
65646+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
65647+ if (tmpsubj != NULL)
65648+ task->acl = tmpsubj;
65649+ }
65650+ if (tmpsubj == NULL)
65651+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
65652+ task->role);
65653+ if (task->acl) {
65654+ task->is_writable = 0;
65655+ /* ignore additional mmap checks for processes that are writable
65656+ by the default ACL */
65657+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
65658+ if (unlikely(obj->mode & GR_WRITE))
65659+ task->is_writable = 1;
65660+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
65661+ if (unlikely(obj->mode & GR_WRITE))
65662+ task->is_writable = 1;
65663+
65664+ gr_set_proc_res(task);
65665+
65666+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
65667+ 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);
65668+#endif
65669+ } else {
65670+ return 1;
65671+ }
65672+
65673+ return 0;
65674+}
65675+
65676+int
65677+gr_set_acls(const int type)
65678+{
65679+ struct task_struct *task, *task2;
65680+ struct acl_role_label *role = current->role;
65681+ __u16 acl_role_id = current->acl_role_id;
65682+ const struct cred *cred;
65683+ int ret;
65684+
65685+ rcu_read_lock();
65686+ read_lock(&tasklist_lock);
65687+ read_lock(&grsec_exec_file_lock);
65688+ do_each_thread(task2, task) {
65689+ /* check to see if we're called from the exit handler,
65690+ if so, only replace ACLs that have inherited the admin
65691+ ACL */
65692+
65693+ if (type && (task->role != role ||
65694+ task->acl_role_id != acl_role_id))
65695+ continue;
65696+
65697+ task->acl_role_id = 0;
65698+ task->acl_sp_role = 0;
65699+
65700+ if (task->exec_file) {
65701+ cred = __task_cred(task);
65702+ task->role = lookup_acl_role_label(task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
65703+ ret = gr_apply_subject_to_task(task);
65704+ if (ret) {
65705+ read_unlock(&grsec_exec_file_lock);
65706+ read_unlock(&tasklist_lock);
65707+ rcu_read_unlock();
65708+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
65709+ return ret;
65710+ }
65711+ } else {
65712+ // it's a kernel process
65713+ task->role = kernel_role;
65714+ task->acl = kernel_role->root_label;
65715+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
65716+ task->acl->mode &= ~GR_PROCFIND;
65717+#endif
65718+ }
65719+ } while_each_thread(task2, task);
65720+ read_unlock(&grsec_exec_file_lock);
65721+ read_unlock(&tasklist_lock);
65722+ rcu_read_unlock();
65723+
65724+ return 0;
65725+}
65726+
65727+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
65728+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
65729+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
65730+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
65731+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
65732+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
65733+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
65734+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
65735+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
65736+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
65737+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
65738+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
65739+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
65740+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
65741+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
65742+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
65743+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
65744+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
65745+};
65746+
65747+void
65748+gr_learn_resource(const struct task_struct *task,
65749+ const int res, const unsigned long wanted, const int gt)
65750+{
65751+ struct acl_subject_label *acl;
65752+ const struct cred *cred;
65753+
65754+ if (unlikely((gr_status & GR_READY) &&
65755+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
65756+ goto skip_reslog;
65757+
65758+ gr_log_resource(task, res, wanted, gt);
65759+skip_reslog:
65760+
65761+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
65762+ return;
65763+
65764+ acl = task->acl;
65765+
65766+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
65767+ !(acl->resmask & (1U << (unsigned short) res))))
65768+ return;
65769+
65770+ if (wanted >= acl->res[res].rlim_cur) {
65771+ unsigned long res_add;
65772+
65773+ res_add = wanted + res_learn_bumps[res];
65774+
65775+ acl->res[res].rlim_cur = res_add;
65776+
65777+ if (wanted > acl->res[res].rlim_max)
65778+ acl->res[res].rlim_max = res_add;
65779+
65780+ /* only log the subject filename, since resource logging is supported for
65781+ single-subject learning only */
65782+ rcu_read_lock();
65783+ cred = __task_cred(task);
65784+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
65785+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
65786+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
65787+ "", (unsigned long) res, &task->signal->saved_ip);
65788+ rcu_read_unlock();
65789+ }
65790+
65791+ return;
65792+}
65793+EXPORT_SYMBOL(gr_learn_resource);
65794+#endif
65795+
65796+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
65797+void
65798+pax_set_initial_flags(struct linux_binprm *bprm)
65799+{
65800+ struct task_struct *task = current;
65801+ struct acl_subject_label *proc;
65802+ unsigned long flags;
65803+
65804+ if (unlikely(!(gr_status & GR_READY)))
65805+ return;
65806+
65807+ flags = pax_get_flags(task);
65808+
65809+ proc = task->acl;
65810+
65811+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
65812+ flags &= ~MF_PAX_PAGEEXEC;
65813+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
65814+ flags &= ~MF_PAX_SEGMEXEC;
65815+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
65816+ flags &= ~MF_PAX_RANDMMAP;
65817+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
65818+ flags &= ~MF_PAX_EMUTRAMP;
65819+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
65820+ flags &= ~MF_PAX_MPROTECT;
65821+
65822+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
65823+ flags |= MF_PAX_PAGEEXEC;
65824+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
65825+ flags |= MF_PAX_SEGMEXEC;
65826+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
65827+ flags |= MF_PAX_RANDMMAP;
65828+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
65829+ flags |= MF_PAX_EMUTRAMP;
65830+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
65831+ flags |= MF_PAX_MPROTECT;
65832+
65833+ pax_set_flags(task, flags);
65834+
65835+ return;
65836+}
65837+#endif
65838+
65839+int
65840+gr_handle_proc_ptrace(struct task_struct *task)
65841+{
65842+ struct file *filp;
65843+ struct task_struct *tmp = task;
65844+ struct task_struct *curtemp = current;
65845+ __u32 retmode;
65846+
65847+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
65848+ if (unlikely(!(gr_status & GR_READY)))
65849+ return 0;
65850+#endif
65851+
65852+ read_lock(&tasklist_lock);
65853+ read_lock(&grsec_exec_file_lock);
65854+ filp = task->exec_file;
65855+
65856+ while (task_pid_nr(tmp) > 0) {
65857+ if (tmp == curtemp)
65858+ break;
65859+ tmp = tmp->real_parent;
65860+ }
65861+
65862+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
65863+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
65864+ read_unlock(&grsec_exec_file_lock);
65865+ read_unlock(&tasklist_lock);
65866+ return 1;
65867+ }
65868+
65869+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
65870+ if (!(gr_status & GR_READY)) {
65871+ read_unlock(&grsec_exec_file_lock);
65872+ read_unlock(&tasklist_lock);
65873+ return 0;
65874+ }
65875+#endif
65876+
65877+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
65878+ read_unlock(&grsec_exec_file_lock);
65879+ read_unlock(&tasklist_lock);
65880+
65881+ if (retmode & GR_NOPTRACE)
65882+ return 1;
65883+
65884+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
65885+ && (current->acl != task->acl || (current->acl != current->role->root_label
65886+ && task_pid_nr(current) != task_pid_nr(task))))
65887+ return 1;
65888+
65889+ return 0;
65890+}
65891+
65892+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
65893+{
65894+ if (unlikely(!(gr_status & GR_READY)))
65895+ return;
65896+
65897+ if (!(current->role->roletype & GR_ROLE_GOD))
65898+ return;
65899+
65900+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
65901+ p->role->rolename, gr_task_roletype_to_char(p),
65902+ p->acl->filename);
65903+}
65904+
65905+int
65906+gr_handle_ptrace(struct task_struct *task, const long request)
65907+{
65908+ struct task_struct *tmp = task;
65909+ struct task_struct *curtemp = current;
65910+ __u32 retmode;
65911+
65912+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
65913+ if (unlikely(!(gr_status & GR_READY)))
65914+ return 0;
65915+#endif
65916+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
65917+ read_lock(&tasklist_lock);
65918+ while (task_pid_nr(tmp) > 0) {
65919+ if (tmp == curtemp)
65920+ break;
65921+ tmp = tmp->real_parent;
65922+ }
65923+
65924+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
65925+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
65926+ read_unlock(&tasklist_lock);
65927+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
65928+ return 1;
65929+ }
65930+ read_unlock(&tasklist_lock);
65931+ }
65932+
65933+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
65934+ if (!(gr_status & GR_READY))
65935+ return 0;
65936+#endif
65937+
65938+ read_lock(&grsec_exec_file_lock);
65939+ if (unlikely(!task->exec_file)) {
65940+ read_unlock(&grsec_exec_file_lock);
65941+ return 0;
65942+ }
65943+
65944+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
65945+ read_unlock(&grsec_exec_file_lock);
65946+
65947+ if (retmode & GR_NOPTRACE) {
65948+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
65949+ return 1;
65950+ }
65951+
65952+ if (retmode & GR_PTRACERD) {
65953+ switch (request) {
65954+ case PTRACE_SEIZE:
65955+ case PTRACE_POKETEXT:
65956+ case PTRACE_POKEDATA:
65957+ case PTRACE_POKEUSR:
65958+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
65959+ case PTRACE_SETREGS:
65960+ case PTRACE_SETFPREGS:
65961+#endif
65962+#ifdef CONFIG_X86
65963+ case PTRACE_SETFPXREGS:
65964+#endif
65965+#ifdef CONFIG_ALTIVEC
65966+ case PTRACE_SETVRREGS:
65967+#endif
65968+ return 1;
65969+ default:
65970+ return 0;
65971+ }
65972+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
65973+ !(current->role->roletype & GR_ROLE_GOD) &&
65974+ (current->acl != task->acl)) {
65975+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
65976+ return 1;
65977+ }
65978+
65979+ return 0;
65980+}
65981+
65982+static int is_writable_mmap(const struct file *filp)
65983+{
65984+ struct task_struct *task = current;
65985+ struct acl_object_label *obj, *obj2;
65986+
65987+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
65988+ !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))) {
65989+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
65990+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
65991+ task->role->root_label);
65992+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
65993+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
65994+ return 1;
65995+ }
65996+ }
65997+ return 0;
65998+}
65999+
66000+int
66001+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
66002+{
66003+ __u32 mode;
66004+
66005+ if (unlikely(!file || !(prot & PROT_EXEC)))
66006+ return 1;
66007+
66008+ if (is_writable_mmap(file))
66009+ return 0;
66010+
66011+ mode =
66012+ gr_search_file(file->f_path.dentry,
66013+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
66014+ file->f_path.mnt);
66015+
66016+ if (!gr_tpe_allow(file))
66017+ return 0;
66018+
66019+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
66020+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66021+ return 0;
66022+ } else if (unlikely(!(mode & GR_EXEC))) {
66023+ return 0;
66024+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
66025+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66026+ return 1;
66027+ }
66028+
66029+ return 1;
66030+}
66031+
66032+int
66033+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
66034+{
66035+ __u32 mode;
66036+
66037+ if (unlikely(!file || !(prot & PROT_EXEC)))
66038+ return 1;
66039+
66040+ if (is_writable_mmap(file))
66041+ return 0;
66042+
66043+ mode =
66044+ gr_search_file(file->f_path.dentry,
66045+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
66046+ file->f_path.mnt);
66047+
66048+ if (!gr_tpe_allow(file))
66049+ return 0;
66050+
66051+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
66052+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66053+ return 0;
66054+ } else if (unlikely(!(mode & GR_EXEC))) {
66055+ return 0;
66056+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
66057+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66058+ return 1;
66059+ }
66060+
66061+ return 1;
66062+}
66063+
66064+void
66065+gr_acl_handle_psacct(struct task_struct *task, const long code)
66066+{
66067+ unsigned long runtime;
66068+ unsigned long cputime;
66069+ unsigned int wday, cday;
66070+ __u8 whr, chr;
66071+ __u8 wmin, cmin;
66072+ __u8 wsec, csec;
66073+ struct timespec timeval;
66074+
66075+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
66076+ !(task->acl->mode & GR_PROCACCT)))
66077+ return;
66078+
66079+ do_posix_clock_monotonic_gettime(&timeval);
66080+ runtime = timeval.tv_sec - task->start_time.tv_sec;
66081+ wday = runtime / (3600 * 24);
66082+ runtime -= wday * (3600 * 24);
66083+ whr = runtime / 3600;
66084+ runtime -= whr * 3600;
66085+ wmin = runtime / 60;
66086+ runtime -= wmin * 60;
66087+ wsec = runtime;
66088+
66089+ cputime = (task->utime + task->stime) / HZ;
66090+ cday = cputime / (3600 * 24);
66091+ cputime -= cday * (3600 * 24);
66092+ chr = cputime / 3600;
66093+ cputime -= chr * 3600;
66094+ cmin = cputime / 60;
66095+ cputime -= cmin * 60;
66096+ csec = cputime;
66097+
66098+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
66099+
66100+ return;
66101+}
66102+
66103+void gr_set_kernel_label(struct task_struct *task)
66104+{
66105+ if (gr_status & GR_READY) {
66106+ task->role = kernel_role;
66107+ task->acl = kernel_role->root_label;
66108+ }
66109+ return;
66110+}
66111+
66112+#ifdef CONFIG_TASKSTATS
66113+int gr_is_taskstats_denied(int pid)
66114+{
66115+ struct task_struct *task;
66116+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66117+ const struct cred *cred;
66118+#endif
66119+ int ret = 0;
66120+
66121+ /* restrict taskstats viewing to un-chrooted root users
66122+ who have the 'view' subject flag if the RBAC system is enabled
66123+ */
66124+
66125+ rcu_read_lock();
66126+ read_lock(&tasklist_lock);
66127+ task = find_task_by_vpid(pid);
66128+ if (task) {
66129+#ifdef CONFIG_GRKERNSEC_CHROOT
66130+ if (proc_is_chrooted(task))
66131+ ret = -EACCES;
66132+#endif
66133+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66134+ cred = __task_cred(task);
66135+#ifdef CONFIG_GRKERNSEC_PROC_USER
66136+ if (gr_is_global_nonroot(cred->uid))
66137+ ret = -EACCES;
66138+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66139+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
66140+ ret = -EACCES;
66141+#endif
66142+#endif
66143+ if (gr_status & GR_READY) {
66144+ if (!(task->acl->mode & GR_VIEW))
66145+ ret = -EACCES;
66146+ }
66147+ } else
66148+ ret = -ENOENT;
66149+
66150+ read_unlock(&tasklist_lock);
66151+ rcu_read_unlock();
66152+
66153+ return ret;
66154+}
66155+#endif
66156+
66157+/* AUXV entries are filled via a descendant of search_binary_handler
66158+ after we've already applied the subject for the target
66159+*/
66160+int gr_acl_enable_at_secure(void)
66161+{
66162+ if (unlikely(!(gr_status & GR_READY)))
66163+ return 0;
66164+
66165+ if (current->acl->mode & GR_ATSECURE)
66166+ return 1;
66167+
66168+ return 0;
66169+}
66170+
66171+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
66172+{
66173+ struct task_struct *task = current;
66174+ struct dentry *dentry = file->f_path.dentry;
66175+ struct vfsmount *mnt = file->f_path.mnt;
66176+ struct acl_object_label *obj, *tmp;
66177+ struct acl_subject_label *subj;
66178+ unsigned int bufsize;
66179+ int is_not_root;
66180+ char *path;
66181+ dev_t dev = __get_dev(dentry);
66182+
66183+ if (unlikely(!(gr_status & GR_READY)))
66184+ return 1;
66185+
66186+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
66187+ return 1;
66188+
66189+ /* ignore Eric Biederman */
66190+ if (IS_PRIVATE(dentry->d_inode))
66191+ return 1;
66192+
66193+ subj = task->acl;
66194+ read_lock(&gr_inode_lock);
66195+ do {
66196+ obj = lookup_acl_obj_label(ino, dev, subj);
66197+ if (obj != NULL) {
66198+ read_unlock(&gr_inode_lock);
66199+ return (obj->mode & GR_FIND) ? 1 : 0;
66200+ }
66201+ } while ((subj = subj->parent_subject));
66202+ read_unlock(&gr_inode_lock);
66203+
66204+ /* this is purely an optimization since we're looking for an object
66205+ for the directory we're doing a readdir on
66206+ if it's possible for any globbed object to match the entry we're
66207+ filling into the directory, then the object we find here will be
66208+ an anchor point with attached globbed objects
66209+ */
66210+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
66211+ if (obj->globbed == NULL)
66212+ return (obj->mode & GR_FIND) ? 1 : 0;
66213+
66214+ is_not_root = ((obj->filename[0] == '/') &&
66215+ (obj->filename[1] == '\0')) ? 0 : 1;
66216+ bufsize = PAGE_SIZE - namelen - is_not_root;
66217+
66218+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
66219+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
66220+ return 1;
66221+
66222+ preempt_disable();
66223+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
66224+ bufsize);
66225+
66226+ bufsize = strlen(path);
66227+
66228+ /* if base is "/", don't append an additional slash */
66229+ if (is_not_root)
66230+ *(path + bufsize) = '/';
66231+ memcpy(path + bufsize + is_not_root, name, namelen);
66232+ *(path + bufsize + namelen + is_not_root) = '\0';
66233+
66234+ tmp = obj->globbed;
66235+ while (tmp) {
66236+ if (!glob_match(tmp->filename, path)) {
66237+ preempt_enable();
66238+ return (tmp->mode & GR_FIND) ? 1 : 0;
66239+ }
66240+ tmp = tmp->next;
66241+ }
66242+ preempt_enable();
66243+ return (obj->mode & GR_FIND) ? 1 : 0;
66244+}
66245+
66246+void gr_put_exec_file(struct task_struct *task)
66247+{
66248+ struct file *filp;
66249+
66250+ write_lock(&grsec_exec_file_lock);
66251+ filp = task->exec_file;
66252+ task->exec_file = NULL;
66253+ write_unlock(&grsec_exec_file_lock);
66254+
66255+ if (filp)
66256+ fput(filp);
66257+
66258+ return;
66259+}
66260+
66261+
66262+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
66263+EXPORT_SYMBOL(gr_acl_is_enabled);
66264+#endif
66265+EXPORT_SYMBOL(gr_set_kernel_label);
66266+#ifdef CONFIG_SECURITY
66267+EXPORT_SYMBOL(gr_check_user_change);
66268+EXPORT_SYMBOL(gr_check_group_change);
66269+#endif
66270+
66271diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
66272new file mode 100644
66273index 0000000..34fefda
66274--- /dev/null
66275+++ b/grsecurity/gracl_alloc.c
66276@@ -0,0 +1,105 @@
66277+#include <linux/kernel.h>
66278+#include <linux/mm.h>
66279+#include <linux/slab.h>
66280+#include <linux/vmalloc.h>
66281+#include <linux/gracl.h>
66282+#include <linux/grsecurity.h>
66283+
66284+static unsigned long alloc_stack_next = 1;
66285+static unsigned long alloc_stack_size = 1;
66286+static void **alloc_stack;
66287+
66288+static __inline__ int
66289+alloc_pop(void)
66290+{
66291+ if (alloc_stack_next == 1)
66292+ return 0;
66293+
66294+ kfree(alloc_stack[alloc_stack_next - 2]);
66295+
66296+ alloc_stack_next--;
66297+
66298+ return 1;
66299+}
66300+
66301+static __inline__ int
66302+alloc_push(void *buf)
66303+{
66304+ if (alloc_stack_next >= alloc_stack_size)
66305+ return 1;
66306+
66307+ alloc_stack[alloc_stack_next - 1] = buf;
66308+
66309+ alloc_stack_next++;
66310+
66311+ return 0;
66312+}
66313+
66314+void *
66315+acl_alloc(unsigned long len)
66316+{
66317+ void *ret = NULL;
66318+
66319+ if (!len || len > PAGE_SIZE)
66320+ goto out;
66321+
66322+ ret = kmalloc(len, GFP_KERNEL);
66323+
66324+ if (ret) {
66325+ if (alloc_push(ret)) {
66326+ kfree(ret);
66327+ ret = NULL;
66328+ }
66329+ }
66330+
66331+out:
66332+ return ret;
66333+}
66334+
66335+void *
66336+acl_alloc_num(unsigned long num, unsigned long len)
66337+{
66338+ if (!len || (num > (PAGE_SIZE / len)))
66339+ return NULL;
66340+
66341+ return acl_alloc(num * len);
66342+}
66343+
66344+void
66345+acl_free_all(void)
66346+{
66347+ if (gr_acl_is_enabled() || !alloc_stack)
66348+ return;
66349+
66350+ while (alloc_pop()) ;
66351+
66352+ if (alloc_stack) {
66353+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
66354+ kfree(alloc_stack);
66355+ else
66356+ vfree(alloc_stack);
66357+ }
66358+
66359+ alloc_stack = NULL;
66360+ alloc_stack_size = 1;
66361+ alloc_stack_next = 1;
66362+
66363+ return;
66364+}
66365+
66366+int
66367+acl_alloc_stack_init(unsigned long size)
66368+{
66369+ if ((size * sizeof (void *)) <= PAGE_SIZE)
66370+ alloc_stack =
66371+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
66372+ else
66373+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
66374+
66375+ alloc_stack_size = size;
66376+
66377+ if (!alloc_stack)
66378+ return 0;
66379+ else
66380+ return 1;
66381+}
66382diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
66383new file mode 100644
66384index 0000000..bdd51ea
66385--- /dev/null
66386+++ b/grsecurity/gracl_cap.c
66387@@ -0,0 +1,110 @@
66388+#include <linux/kernel.h>
66389+#include <linux/module.h>
66390+#include <linux/sched.h>
66391+#include <linux/gracl.h>
66392+#include <linux/grsecurity.h>
66393+#include <linux/grinternal.h>
66394+
66395+extern const char *captab_log[];
66396+extern int captab_log_entries;
66397+
66398+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
66399+{
66400+ struct acl_subject_label *curracl;
66401+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
66402+ kernel_cap_t cap_audit = __cap_empty_set;
66403+
66404+ if (!gr_acl_is_enabled())
66405+ return 1;
66406+
66407+ curracl = task->acl;
66408+
66409+ cap_drop = curracl->cap_lower;
66410+ cap_mask = curracl->cap_mask;
66411+ cap_audit = curracl->cap_invert_audit;
66412+
66413+ while ((curracl = curracl->parent_subject)) {
66414+ /* if the cap isn't specified in the current computed mask but is specified in the
66415+ current level subject, and is lowered in the current level subject, then add
66416+ it to the set of dropped capabilities
66417+ otherwise, add the current level subject's mask to the current computed mask
66418+ */
66419+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
66420+ cap_raise(cap_mask, cap);
66421+ if (cap_raised(curracl->cap_lower, cap))
66422+ cap_raise(cap_drop, cap);
66423+ if (cap_raised(curracl->cap_invert_audit, cap))
66424+ cap_raise(cap_audit, cap);
66425+ }
66426+ }
66427+
66428+ if (!cap_raised(cap_drop, cap)) {
66429+ if (cap_raised(cap_audit, cap))
66430+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
66431+ return 1;
66432+ }
66433+
66434+ curracl = task->acl;
66435+
66436+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
66437+ && cap_raised(cred->cap_effective, cap)) {
66438+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
66439+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
66440+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
66441+ gr_to_filename(task->exec_file->f_path.dentry,
66442+ task->exec_file->f_path.mnt) : curracl->filename,
66443+ curracl->filename, 0UL,
66444+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
66445+ return 1;
66446+ }
66447+
66448+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
66449+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
66450+
66451+ return 0;
66452+}
66453+
66454+int
66455+gr_acl_is_capable(const int cap)
66456+{
66457+ return gr_task_acl_is_capable(current, current_cred(), cap);
66458+}
66459+
66460+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
66461+{
66462+ struct acl_subject_label *curracl;
66463+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
66464+
66465+ if (!gr_acl_is_enabled())
66466+ return 1;
66467+
66468+ curracl = task->acl;
66469+
66470+ cap_drop = curracl->cap_lower;
66471+ cap_mask = curracl->cap_mask;
66472+
66473+ while ((curracl = curracl->parent_subject)) {
66474+ /* if the cap isn't specified in the current computed mask but is specified in the
66475+ current level subject, and is lowered in the current level subject, then add
66476+ it to the set of dropped capabilities
66477+ otherwise, add the current level subject's mask to the current computed mask
66478+ */
66479+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
66480+ cap_raise(cap_mask, cap);
66481+ if (cap_raised(curracl->cap_lower, cap))
66482+ cap_raise(cap_drop, cap);
66483+ }
66484+ }
66485+
66486+ if (!cap_raised(cap_drop, cap))
66487+ return 1;
66488+
66489+ return 0;
66490+}
66491+
66492+int
66493+gr_acl_is_capable_nolog(const int cap)
66494+{
66495+ return gr_task_acl_is_capable_nolog(current, cap);
66496+}
66497+
66498diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
66499new file mode 100644
66500index 0000000..a43dd06
66501--- /dev/null
66502+++ b/grsecurity/gracl_compat.c
66503@@ -0,0 +1,269 @@
66504+#include <linux/kernel.h>
66505+#include <linux/gracl.h>
66506+#include <linux/compat.h>
66507+#include <linux/gracl_compat.h>
66508+
66509+#include <asm/uaccess.h>
66510+
66511+int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
66512+{
66513+ struct gr_arg_wrapper_compat uwrapcompat;
66514+
66515+ if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
66516+ return -EFAULT;
66517+
66518+ if ((uwrapcompat.version != GRSECURITY_VERSION) ||
66519+ (uwrapcompat.size != sizeof(struct gr_arg_compat)))
66520+ return -EINVAL;
66521+
66522+ uwrap->arg = compat_ptr(uwrapcompat.arg);
66523+ uwrap->version = uwrapcompat.version;
66524+ uwrap->size = sizeof(struct gr_arg);
66525+
66526+ return 0;
66527+}
66528+
66529+int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
66530+{
66531+ struct gr_arg_compat argcompat;
66532+
66533+ if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
66534+ return -EFAULT;
66535+
66536+ arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
66537+ arg->role_db.num_pointers = argcompat.role_db.num_pointers;
66538+ arg->role_db.num_roles = argcompat.role_db.num_roles;
66539+ arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
66540+ arg->role_db.num_subjects = argcompat.role_db.num_subjects;
66541+ arg->role_db.num_objects = argcompat.role_db.num_objects;
66542+
66543+ memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
66544+ memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
66545+ memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
66546+ memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
66547+ arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
66548+ arg->segv_device = argcompat.segv_device;
66549+ arg->segv_inode = argcompat.segv_inode;
66550+ arg->segv_uid = argcompat.segv_uid;
66551+ arg->num_sprole_pws = argcompat.num_sprole_pws;
66552+ arg->mode = argcompat.mode;
66553+
66554+ return 0;
66555+}
66556+
66557+int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
66558+{
66559+ struct acl_object_label_compat objcompat;
66560+
66561+ if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
66562+ return -EFAULT;
66563+
66564+ obj->filename = compat_ptr(objcompat.filename);
66565+ obj->inode = objcompat.inode;
66566+ obj->device = objcompat.device;
66567+ obj->mode = objcompat.mode;
66568+
66569+ obj->nested = compat_ptr(objcompat.nested);
66570+ obj->globbed = compat_ptr(objcompat.globbed);
66571+
66572+ obj->prev = compat_ptr(objcompat.prev);
66573+ obj->next = compat_ptr(objcompat.next);
66574+
66575+ return 0;
66576+}
66577+
66578+int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
66579+{
66580+ unsigned int i;
66581+ struct acl_subject_label_compat subjcompat;
66582+
66583+ if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
66584+ return -EFAULT;
66585+
66586+ subj->filename = compat_ptr(subjcompat.filename);
66587+ subj->inode = subjcompat.inode;
66588+ subj->device = subjcompat.device;
66589+ subj->mode = subjcompat.mode;
66590+ subj->cap_mask = subjcompat.cap_mask;
66591+ subj->cap_lower = subjcompat.cap_lower;
66592+ subj->cap_invert_audit = subjcompat.cap_invert_audit;
66593+
66594+ for (i = 0; i < GR_NLIMITS; i++) {
66595+ if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
66596+ subj->res[i].rlim_cur = RLIM_INFINITY;
66597+ else
66598+ subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
66599+ if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
66600+ subj->res[i].rlim_max = RLIM_INFINITY;
66601+ else
66602+ subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
66603+ }
66604+ subj->resmask = subjcompat.resmask;
66605+
66606+ subj->user_trans_type = subjcompat.user_trans_type;
66607+ subj->group_trans_type = subjcompat.group_trans_type;
66608+ subj->user_transitions = compat_ptr(subjcompat.user_transitions);
66609+ subj->group_transitions = compat_ptr(subjcompat.group_transitions);
66610+ subj->user_trans_num = subjcompat.user_trans_num;
66611+ subj->group_trans_num = subjcompat.group_trans_num;
66612+
66613+ memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
66614+ memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
66615+ subj->ip_type = subjcompat.ip_type;
66616+ subj->ips = compat_ptr(subjcompat.ips);
66617+ subj->ip_num = subjcompat.ip_num;
66618+ subj->inaddr_any_override = subjcompat.inaddr_any_override;
66619+
66620+ subj->crashes = subjcompat.crashes;
66621+ subj->expires = subjcompat.expires;
66622+
66623+ subj->parent_subject = compat_ptr(subjcompat.parent_subject);
66624+ subj->hash = compat_ptr(subjcompat.hash);
66625+ subj->prev = compat_ptr(subjcompat.prev);
66626+ subj->next = compat_ptr(subjcompat.next);
66627+
66628+ subj->obj_hash = compat_ptr(subjcompat.obj_hash);
66629+ subj->obj_hash_size = subjcompat.obj_hash_size;
66630+ subj->pax_flags = subjcompat.pax_flags;
66631+
66632+ return 0;
66633+}
66634+
66635+int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
66636+{
66637+ struct acl_role_label_compat rolecompat;
66638+
66639+ if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
66640+ return -EFAULT;
66641+
66642+ role->rolename = compat_ptr(rolecompat.rolename);
66643+ role->uidgid = rolecompat.uidgid;
66644+ role->roletype = rolecompat.roletype;
66645+
66646+ role->auth_attempts = rolecompat.auth_attempts;
66647+ role->expires = rolecompat.expires;
66648+
66649+ role->root_label = compat_ptr(rolecompat.root_label);
66650+ role->hash = compat_ptr(rolecompat.hash);
66651+
66652+ role->prev = compat_ptr(rolecompat.prev);
66653+ role->next = compat_ptr(rolecompat.next);
66654+
66655+ role->transitions = compat_ptr(rolecompat.transitions);
66656+ role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
66657+ role->domain_children = compat_ptr(rolecompat.domain_children);
66658+ role->domain_child_num = rolecompat.domain_child_num;
66659+
66660+ role->umask = rolecompat.umask;
66661+
66662+ role->subj_hash = compat_ptr(rolecompat.subj_hash);
66663+ role->subj_hash_size = rolecompat.subj_hash_size;
66664+
66665+ return 0;
66666+}
66667+
66668+int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
66669+{
66670+ struct role_allowed_ip_compat roleip_compat;
66671+
66672+ if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
66673+ return -EFAULT;
66674+
66675+ roleip->addr = roleip_compat.addr;
66676+ roleip->netmask = roleip_compat.netmask;
66677+
66678+ roleip->prev = compat_ptr(roleip_compat.prev);
66679+ roleip->next = compat_ptr(roleip_compat.next);
66680+
66681+ return 0;
66682+}
66683+
66684+int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
66685+{
66686+ struct role_transition_compat trans_compat;
66687+
66688+ if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
66689+ return -EFAULT;
66690+
66691+ trans->rolename = compat_ptr(trans_compat.rolename);
66692+
66693+ trans->prev = compat_ptr(trans_compat.prev);
66694+ trans->next = compat_ptr(trans_compat.next);
66695+
66696+ return 0;
66697+
66698+}
66699+
66700+int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
66701+{
66702+ struct gr_hash_struct_compat hash_compat;
66703+
66704+ if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
66705+ return -EFAULT;
66706+
66707+ hash->table = compat_ptr(hash_compat.table);
66708+ hash->nametable = compat_ptr(hash_compat.nametable);
66709+ hash->first = compat_ptr(hash_compat.first);
66710+
66711+ hash->table_size = hash_compat.table_size;
66712+ hash->used_size = hash_compat.used_size;
66713+
66714+ hash->type = hash_compat.type;
66715+
66716+ return 0;
66717+}
66718+
66719+int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
66720+{
66721+ compat_uptr_t ptrcompat;
66722+
66723+ if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
66724+ return -EFAULT;
66725+
66726+ *(void **)ptr = compat_ptr(ptrcompat);
66727+
66728+ return 0;
66729+}
66730+
66731+int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
66732+{
66733+ struct acl_ip_label_compat ip_compat;
66734+
66735+ if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
66736+ return -EFAULT;
66737+
66738+ ip->iface = compat_ptr(ip_compat.iface);
66739+ ip->addr = ip_compat.addr;
66740+ ip->netmask = ip_compat.netmask;
66741+ ip->low = ip_compat.low;
66742+ ip->high = ip_compat.high;
66743+ ip->mode = ip_compat.mode;
66744+ ip->type = ip_compat.type;
66745+
66746+ memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
66747+
66748+ ip->prev = compat_ptr(ip_compat.prev);
66749+ ip->next = compat_ptr(ip_compat.next);
66750+
66751+ return 0;
66752+}
66753+
66754+int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
66755+{
66756+ struct sprole_pw_compat pw_compat;
66757+
66758+ if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
66759+ return -EFAULT;
66760+
66761+ pw->rolename = compat_ptr(pw_compat.rolename);
66762+ memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
66763+ memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
66764+
66765+ return 0;
66766+}
66767+
66768+size_t get_gr_arg_wrapper_size_compat(void)
66769+{
66770+ return sizeof(struct gr_arg_wrapper_compat);
66771+}
66772+
66773diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
66774new file mode 100644
66775index 0000000..a340c17
66776--- /dev/null
66777+++ b/grsecurity/gracl_fs.c
66778@@ -0,0 +1,431 @@
66779+#include <linux/kernel.h>
66780+#include <linux/sched.h>
66781+#include <linux/types.h>
66782+#include <linux/fs.h>
66783+#include <linux/file.h>
66784+#include <linux/stat.h>
66785+#include <linux/grsecurity.h>
66786+#include <linux/grinternal.h>
66787+#include <linux/gracl.h>
66788+
66789+umode_t
66790+gr_acl_umask(void)
66791+{
66792+ if (unlikely(!gr_acl_is_enabled()))
66793+ return 0;
66794+
66795+ return current->role->umask;
66796+}
66797+
66798+__u32
66799+gr_acl_handle_hidden_file(const struct dentry * dentry,
66800+ const struct vfsmount * mnt)
66801+{
66802+ __u32 mode;
66803+
66804+ if (unlikely(!dentry->d_inode))
66805+ return GR_FIND;
66806+
66807+ mode =
66808+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
66809+
66810+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
66811+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
66812+ return mode;
66813+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
66814+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
66815+ return 0;
66816+ } else if (unlikely(!(mode & GR_FIND)))
66817+ return 0;
66818+
66819+ return GR_FIND;
66820+}
66821+
66822+__u32
66823+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
66824+ int acc_mode)
66825+{
66826+ __u32 reqmode = GR_FIND;
66827+ __u32 mode;
66828+
66829+ if (unlikely(!dentry->d_inode))
66830+ return reqmode;
66831+
66832+ if (acc_mode & MAY_APPEND)
66833+ reqmode |= GR_APPEND;
66834+ else if (acc_mode & MAY_WRITE)
66835+ reqmode |= GR_WRITE;
66836+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
66837+ reqmode |= GR_READ;
66838+
66839+ mode =
66840+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
66841+ mnt);
66842+
66843+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
66844+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
66845+ reqmode & GR_READ ? " reading" : "",
66846+ reqmode & GR_WRITE ? " writing" : reqmode &
66847+ GR_APPEND ? " appending" : "");
66848+ return reqmode;
66849+ } else
66850+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
66851+ {
66852+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
66853+ reqmode & GR_READ ? " reading" : "",
66854+ reqmode & GR_WRITE ? " writing" : reqmode &
66855+ GR_APPEND ? " appending" : "");
66856+ return 0;
66857+ } else if (unlikely((mode & reqmode) != reqmode))
66858+ return 0;
66859+
66860+ return reqmode;
66861+}
66862+
66863+__u32
66864+gr_acl_handle_creat(const struct dentry * dentry,
66865+ const struct dentry * p_dentry,
66866+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
66867+ const int imode)
66868+{
66869+ __u32 reqmode = GR_WRITE | GR_CREATE;
66870+ __u32 mode;
66871+
66872+ if (acc_mode & MAY_APPEND)
66873+ reqmode |= GR_APPEND;
66874+ // if a directory was required or the directory already exists, then
66875+ // don't count this open as a read
66876+ if ((acc_mode & MAY_READ) &&
66877+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
66878+ reqmode |= GR_READ;
66879+ if ((open_flags & O_CREAT) &&
66880+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
66881+ reqmode |= GR_SETID;
66882+
66883+ mode =
66884+ gr_check_create(dentry, p_dentry, p_mnt,
66885+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
66886+
66887+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
66888+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
66889+ reqmode & GR_READ ? " reading" : "",
66890+ reqmode & GR_WRITE ? " writing" : reqmode &
66891+ GR_APPEND ? " appending" : "");
66892+ return reqmode;
66893+ } else
66894+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
66895+ {
66896+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
66897+ reqmode & GR_READ ? " reading" : "",
66898+ reqmode & GR_WRITE ? " writing" : reqmode &
66899+ GR_APPEND ? " appending" : "");
66900+ return 0;
66901+ } else if (unlikely((mode & reqmode) != reqmode))
66902+ return 0;
66903+
66904+ return reqmode;
66905+}
66906+
66907+__u32
66908+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
66909+ const int fmode)
66910+{
66911+ __u32 mode, reqmode = GR_FIND;
66912+
66913+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
66914+ reqmode |= GR_EXEC;
66915+ if (fmode & S_IWOTH)
66916+ reqmode |= GR_WRITE;
66917+ if (fmode & S_IROTH)
66918+ reqmode |= GR_READ;
66919+
66920+ mode =
66921+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
66922+ mnt);
66923+
66924+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
66925+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
66926+ reqmode & GR_READ ? " reading" : "",
66927+ reqmode & GR_WRITE ? " writing" : "",
66928+ reqmode & GR_EXEC ? " executing" : "");
66929+ return reqmode;
66930+ } else
66931+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
66932+ {
66933+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
66934+ reqmode & GR_READ ? " reading" : "",
66935+ reqmode & GR_WRITE ? " writing" : "",
66936+ reqmode & GR_EXEC ? " executing" : "");
66937+ return 0;
66938+ } else if (unlikely((mode & reqmode) != reqmode))
66939+ return 0;
66940+
66941+ return reqmode;
66942+}
66943+
66944+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
66945+{
66946+ __u32 mode;
66947+
66948+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
66949+
66950+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
66951+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
66952+ return mode;
66953+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
66954+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
66955+ return 0;
66956+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
66957+ return 0;
66958+
66959+ return (reqmode);
66960+}
66961+
66962+__u32
66963+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
66964+{
66965+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
66966+}
66967+
66968+__u32
66969+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
66970+{
66971+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
66972+}
66973+
66974+__u32
66975+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
66976+{
66977+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
66978+}
66979+
66980+__u32
66981+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
66982+{
66983+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
66984+}
66985+
66986+__u32
66987+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
66988+ umode_t *modeptr)
66989+{
66990+ umode_t mode;
66991+
66992+ *modeptr &= ~gr_acl_umask();
66993+ mode = *modeptr;
66994+
66995+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
66996+ return 1;
66997+
66998+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
66999+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
67000+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
67001+ GR_CHMOD_ACL_MSG);
67002+ } else {
67003+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
67004+ }
67005+}
67006+
67007+__u32
67008+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
67009+{
67010+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
67011+}
67012+
67013+__u32
67014+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
67015+{
67016+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
67017+}
67018+
67019+__u32
67020+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
67021+{
67022+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
67023+}
67024+
67025+__u32
67026+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
67027+{
67028+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
67029+ GR_UNIXCONNECT_ACL_MSG);
67030+}
67031+
67032+/* hardlinks require at minimum create and link permission,
67033+ any additional privilege required is based on the
67034+ privilege of the file being linked to
67035+*/
67036+__u32
67037+gr_acl_handle_link(const struct dentry * new_dentry,
67038+ const struct dentry * parent_dentry,
67039+ const struct vfsmount * parent_mnt,
67040+ const struct dentry * old_dentry,
67041+ const struct vfsmount * old_mnt, const struct filename *to)
67042+{
67043+ __u32 mode;
67044+ __u32 needmode = GR_CREATE | GR_LINK;
67045+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
67046+
67047+ mode =
67048+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
67049+ old_mnt);
67050+
67051+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
67052+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
67053+ return mode;
67054+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
67055+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
67056+ return 0;
67057+ } else if (unlikely((mode & needmode) != needmode))
67058+ return 0;
67059+
67060+ return 1;
67061+}
67062+
67063+__u32
67064+gr_acl_handle_symlink(const struct dentry * new_dentry,
67065+ const struct dentry * parent_dentry,
67066+ const struct vfsmount * parent_mnt, const struct filename *from)
67067+{
67068+ __u32 needmode = GR_WRITE | GR_CREATE;
67069+ __u32 mode;
67070+
67071+ mode =
67072+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
67073+ GR_CREATE | GR_AUDIT_CREATE |
67074+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
67075+
67076+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
67077+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
67078+ return mode;
67079+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
67080+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
67081+ return 0;
67082+ } else if (unlikely((mode & needmode) != needmode))
67083+ return 0;
67084+
67085+ return (GR_WRITE | GR_CREATE);
67086+}
67087+
67088+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)
67089+{
67090+ __u32 mode;
67091+
67092+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
67093+
67094+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
67095+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
67096+ return mode;
67097+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
67098+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
67099+ return 0;
67100+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
67101+ return 0;
67102+
67103+ return (reqmode);
67104+}
67105+
67106+__u32
67107+gr_acl_handle_mknod(const struct dentry * new_dentry,
67108+ const struct dentry * parent_dentry,
67109+ const struct vfsmount * parent_mnt,
67110+ const int mode)
67111+{
67112+ __u32 reqmode = GR_WRITE | GR_CREATE;
67113+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
67114+ reqmode |= GR_SETID;
67115+
67116+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
67117+ reqmode, GR_MKNOD_ACL_MSG);
67118+}
67119+
67120+__u32
67121+gr_acl_handle_mkdir(const struct dentry *new_dentry,
67122+ const struct dentry *parent_dentry,
67123+ const struct vfsmount *parent_mnt)
67124+{
67125+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
67126+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
67127+}
67128+
67129+#define RENAME_CHECK_SUCCESS(old, new) \
67130+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
67131+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
67132+
67133+int
67134+gr_acl_handle_rename(struct dentry *new_dentry,
67135+ struct dentry *parent_dentry,
67136+ const struct vfsmount *parent_mnt,
67137+ struct dentry *old_dentry,
67138+ struct inode *old_parent_inode,
67139+ struct vfsmount *old_mnt, const struct filename *newname)
67140+{
67141+ __u32 comp1, comp2;
67142+ int error = 0;
67143+
67144+ if (unlikely(!gr_acl_is_enabled()))
67145+ return 0;
67146+
67147+ if (!new_dentry->d_inode) {
67148+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
67149+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
67150+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
67151+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
67152+ GR_DELETE | GR_AUDIT_DELETE |
67153+ GR_AUDIT_READ | GR_AUDIT_WRITE |
67154+ GR_SUPPRESS, old_mnt);
67155+ } else {
67156+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
67157+ GR_CREATE | GR_DELETE |
67158+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
67159+ GR_AUDIT_READ | GR_AUDIT_WRITE |
67160+ GR_SUPPRESS, parent_mnt);
67161+ comp2 =
67162+ gr_search_file(old_dentry,
67163+ GR_READ | GR_WRITE | GR_AUDIT_READ |
67164+ GR_DELETE | GR_AUDIT_DELETE |
67165+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
67166+ }
67167+
67168+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
67169+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
67170+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
67171+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
67172+ && !(comp2 & GR_SUPPRESS)) {
67173+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
67174+ error = -EACCES;
67175+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
67176+ error = -EACCES;
67177+
67178+ return error;
67179+}
67180+
67181+void
67182+gr_acl_handle_exit(void)
67183+{
67184+ u16 id;
67185+ char *rolename;
67186+
67187+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
67188+ !(current->role->roletype & GR_ROLE_PERSIST))) {
67189+ id = current->acl_role_id;
67190+ rolename = current->role->rolename;
67191+ gr_set_acls(1);
67192+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
67193+ }
67194+
67195+ gr_put_exec_file(current);
67196+ return;
67197+}
67198+
67199+int
67200+gr_acl_handle_procpidmem(const struct task_struct *task)
67201+{
67202+ if (unlikely(!gr_acl_is_enabled()))
67203+ return 0;
67204+
67205+ if (task != current && task->acl->mode & GR_PROTPROCFD)
67206+ return -EACCES;
67207+
67208+ return 0;
67209+}
67210diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
67211new file mode 100644
67212index 0000000..f056b81
67213--- /dev/null
67214+++ b/grsecurity/gracl_ip.c
67215@@ -0,0 +1,386 @@
67216+#include <linux/kernel.h>
67217+#include <asm/uaccess.h>
67218+#include <asm/errno.h>
67219+#include <net/sock.h>
67220+#include <linux/file.h>
67221+#include <linux/fs.h>
67222+#include <linux/net.h>
67223+#include <linux/in.h>
67224+#include <linux/skbuff.h>
67225+#include <linux/ip.h>
67226+#include <linux/udp.h>
67227+#include <linux/types.h>
67228+#include <linux/sched.h>
67229+#include <linux/netdevice.h>
67230+#include <linux/inetdevice.h>
67231+#include <linux/gracl.h>
67232+#include <linux/grsecurity.h>
67233+#include <linux/grinternal.h>
67234+
67235+#define GR_BIND 0x01
67236+#define GR_CONNECT 0x02
67237+#define GR_INVERT 0x04
67238+#define GR_BINDOVERRIDE 0x08
67239+#define GR_CONNECTOVERRIDE 0x10
67240+#define GR_SOCK_FAMILY 0x20
67241+
67242+static const char * gr_protocols[IPPROTO_MAX] = {
67243+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
67244+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
67245+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
67246+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
67247+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
67248+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
67249+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
67250+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
67251+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
67252+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
67253+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
67254+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
67255+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
67256+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
67257+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
67258+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
67259+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
67260+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
67261+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
67262+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
67263+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
67264+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
67265+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
67266+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
67267+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
67268+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
67269+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
67270+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
67271+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
67272+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
67273+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
67274+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
67275+ };
67276+
67277+static const char * gr_socktypes[SOCK_MAX] = {
67278+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
67279+ "unknown:7", "unknown:8", "unknown:9", "packet"
67280+ };
67281+
67282+static const char * gr_sockfamilies[AF_MAX+1] = {
67283+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
67284+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
67285+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
67286+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
67287+ };
67288+
67289+const char *
67290+gr_proto_to_name(unsigned char proto)
67291+{
67292+ return gr_protocols[proto];
67293+}
67294+
67295+const char *
67296+gr_socktype_to_name(unsigned char type)
67297+{
67298+ return gr_socktypes[type];
67299+}
67300+
67301+const char *
67302+gr_sockfamily_to_name(unsigned char family)
67303+{
67304+ return gr_sockfamilies[family];
67305+}
67306+
67307+extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
67308+
67309+int
67310+gr_search_socket(const int domain, const int type, const int protocol)
67311+{
67312+ struct acl_subject_label *curr;
67313+ const struct cred *cred = current_cred();
67314+
67315+ if (unlikely(!gr_acl_is_enabled()))
67316+ goto exit;
67317+
67318+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
67319+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
67320+ goto exit; // let the kernel handle it
67321+
67322+ curr = current->acl;
67323+
67324+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
67325+ /* the family is allowed, if this is PF_INET allow it only if
67326+ the extra sock type/protocol checks pass */
67327+ if (domain == PF_INET)
67328+ goto inet_check;
67329+ goto exit;
67330+ } else {
67331+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
67332+ __u32 fakeip = 0;
67333+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67334+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67335+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67336+ gr_to_filename(current->exec_file->f_path.dentry,
67337+ current->exec_file->f_path.mnt) :
67338+ curr->filename, curr->filename,
67339+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
67340+ &current->signal->saved_ip);
67341+ goto exit;
67342+ }
67343+ goto exit_fail;
67344+ }
67345+
67346+inet_check:
67347+ /* the rest of this checking is for IPv4 only */
67348+ if (!curr->ips)
67349+ goto exit;
67350+
67351+ if ((curr->ip_type & (1U << type)) &&
67352+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
67353+ goto exit;
67354+
67355+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
67356+ /* we don't place acls on raw sockets , and sometimes
67357+ dgram/ip sockets are opened for ioctl and not
67358+ bind/connect, so we'll fake a bind learn log */
67359+ if (type == SOCK_RAW || type == SOCK_PACKET) {
67360+ __u32 fakeip = 0;
67361+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67362+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67363+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67364+ gr_to_filename(current->exec_file->f_path.dentry,
67365+ current->exec_file->f_path.mnt) :
67366+ curr->filename, curr->filename,
67367+ &fakeip, 0, type,
67368+ protocol, GR_CONNECT, &current->signal->saved_ip);
67369+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
67370+ __u32 fakeip = 0;
67371+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67372+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67373+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67374+ gr_to_filename(current->exec_file->f_path.dentry,
67375+ current->exec_file->f_path.mnt) :
67376+ curr->filename, curr->filename,
67377+ &fakeip, 0, type,
67378+ protocol, GR_BIND, &current->signal->saved_ip);
67379+ }
67380+ /* we'll log when they use connect or bind */
67381+ goto exit;
67382+ }
67383+
67384+exit_fail:
67385+ if (domain == PF_INET)
67386+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
67387+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
67388+ else if (rcu_access_pointer(net_families[domain]) != NULL)
67389+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
67390+ gr_socktype_to_name(type), protocol);
67391+
67392+ return 0;
67393+exit:
67394+ return 1;
67395+}
67396+
67397+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)
67398+{
67399+ if ((ip->mode & mode) &&
67400+ (ip_port >= ip->low) &&
67401+ (ip_port <= ip->high) &&
67402+ ((ntohl(ip_addr) & our_netmask) ==
67403+ (ntohl(our_addr) & our_netmask))
67404+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
67405+ && (ip->type & (1U << type))) {
67406+ if (ip->mode & GR_INVERT)
67407+ return 2; // specifically denied
67408+ else
67409+ return 1; // allowed
67410+ }
67411+
67412+ return 0; // not specifically allowed, may continue parsing
67413+}
67414+
67415+static int
67416+gr_search_connectbind(const int full_mode, struct sock *sk,
67417+ struct sockaddr_in *addr, const int type)
67418+{
67419+ char iface[IFNAMSIZ] = {0};
67420+ struct acl_subject_label *curr;
67421+ struct acl_ip_label *ip;
67422+ struct inet_sock *isk;
67423+ struct net_device *dev;
67424+ struct in_device *idev;
67425+ unsigned long i;
67426+ int ret;
67427+ int mode = full_mode & (GR_BIND | GR_CONNECT);
67428+ __u32 ip_addr = 0;
67429+ __u32 our_addr;
67430+ __u32 our_netmask;
67431+ char *p;
67432+ __u16 ip_port = 0;
67433+ const struct cred *cred = current_cred();
67434+
67435+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
67436+ return 0;
67437+
67438+ curr = current->acl;
67439+ isk = inet_sk(sk);
67440+
67441+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
67442+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
67443+ addr->sin_addr.s_addr = curr->inaddr_any_override;
67444+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
67445+ struct sockaddr_in saddr;
67446+ int err;
67447+
67448+ saddr.sin_family = AF_INET;
67449+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
67450+ saddr.sin_port = isk->inet_sport;
67451+
67452+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
67453+ if (err)
67454+ return err;
67455+
67456+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
67457+ if (err)
67458+ return err;
67459+ }
67460+
67461+ if (!curr->ips)
67462+ return 0;
67463+
67464+ ip_addr = addr->sin_addr.s_addr;
67465+ ip_port = ntohs(addr->sin_port);
67466+
67467+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
67468+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67469+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67470+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67471+ gr_to_filename(current->exec_file->f_path.dentry,
67472+ current->exec_file->f_path.mnt) :
67473+ curr->filename, curr->filename,
67474+ &ip_addr, ip_port, type,
67475+ sk->sk_protocol, mode, &current->signal->saved_ip);
67476+ return 0;
67477+ }
67478+
67479+ for (i = 0; i < curr->ip_num; i++) {
67480+ ip = *(curr->ips + i);
67481+ if (ip->iface != NULL) {
67482+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
67483+ p = strchr(iface, ':');
67484+ if (p != NULL)
67485+ *p = '\0';
67486+ dev = dev_get_by_name(sock_net(sk), iface);
67487+ if (dev == NULL)
67488+ continue;
67489+ idev = in_dev_get(dev);
67490+ if (idev == NULL) {
67491+ dev_put(dev);
67492+ continue;
67493+ }
67494+ rcu_read_lock();
67495+ for_ifa(idev) {
67496+ if (!strcmp(ip->iface, ifa->ifa_label)) {
67497+ our_addr = ifa->ifa_address;
67498+ our_netmask = 0xffffffff;
67499+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
67500+ if (ret == 1) {
67501+ rcu_read_unlock();
67502+ in_dev_put(idev);
67503+ dev_put(dev);
67504+ return 0;
67505+ } else if (ret == 2) {
67506+ rcu_read_unlock();
67507+ in_dev_put(idev);
67508+ dev_put(dev);
67509+ goto denied;
67510+ }
67511+ }
67512+ } endfor_ifa(idev);
67513+ rcu_read_unlock();
67514+ in_dev_put(idev);
67515+ dev_put(dev);
67516+ } else {
67517+ our_addr = ip->addr;
67518+ our_netmask = ip->netmask;
67519+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
67520+ if (ret == 1)
67521+ return 0;
67522+ else if (ret == 2)
67523+ goto denied;
67524+ }
67525+ }
67526+
67527+denied:
67528+ if (mode == GR_BIND)
67529+ 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));
67530+ else if (mode == GR_CONNECT)
67531+ 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));
67532+
67533+ return -EACCES;
67534+}
67535+
67536+int
67537+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
67538+{
67539+ /* always allow disconnection of dgram sockets with connect */
67540+ if (addr->sin_family == AF_UNSPEC)
67541+ return 0;
67542+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
67543+}
67544+
67545+int
67546+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
67547+{
67548+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
67549+}
67550+
67551+int gr_search_listen(struct socket *sock)
67552+{
67553+ struct sock *sk = sock->sk;
67554+ struct sockaddr_in addr;
67555+
67556+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
67557+ addr.sin_port = inet_sk(sk)->inet_sport;
67558+
67559+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
67560+}
67561+
67562+int gr_search_accept(struct socket *sock)
67563+{
67564+ struct sock *sk = sock->sk;
67565+ struct sockaddr_in addr;
67566+
67567+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
67568+ addr.sin_port = inet_sk(sk)->inet_sport;
67569+
67570+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
67571+}
67572+
67573+int
67574+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
67575+{
67576+ if (addr)
67577+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
67578+ else {
67579+ struct sockaddr_in sin;
67580+ const struct inet_sock *inet = inet_sk(sk);
67581+
67582+ sin.sin_addr.s_addr = inet->inet_daddr;
67583+ sin.sin_port = inet->inet_dport;
67584+
67585+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
67586+ }
67587+}
67588+
67589+int
67590+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
67591+{
67592+ struct sockaddr_in sin;
67593+
67594+ if (unlikely(skb->len < sizeof (struct udphdr)))
67595+ return 0; // skip this packet
67596+
67597+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
67598+ sin.sin_port = udp_hdr(skb)->source;
67599+
67600+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
67601+}
67602diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
67603new file mode 100644
67604index 0000000..25f54ef
67605--- /dev/null
67606+++ b/grsecurity/gracl_learn.c
67607@@ -0,0 +1,207 @@
67608+#include <linux/kernel.h>
67609+#include <linux/mm.h>
67610+#include <linux/sched.h>
67611+#include <linux/poll.h>
67612+#include <linux/string.h>
67613+#include <linux/file.h>
67614+#include <linux/types.h>
67615+#include <linux/vmalloc.h>
67616+#include <linux/grinternal.h>
67617+
67618+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
67619+ size_t count, loff_t *ppos);
67620+extern int gr_acl_is_enabled(void);
67621+
67622+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
67623+static int gr_learn_attached;
67624+
67625+/* use a 512k buffer */
67626+#define LEARN_BUFFER_SIZE (512 * 1024)
67627+
67628+static DEFINE_SPINLOCK(gr_learn_lock);
67629+static DEFINE_MUTEX(gr_learn_user_mutex);
67630+
67631+/* we need to maintain two buffers, so that the kernel context of grlearn
67632+ uses a semaphore around the userspace copying, and the other kernel contexts
67633+ use a spinlock when copying into the buffer, since they cannot sleep
67634+*/
67635+static char *learn_buffer;
67636+static char *learn_buffer_user;
67637+static int learn_buffer_len;
67638+static int learn_buffer_user_len;
67639+
67640+static ssize_t
67641+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
67642+{
67643+ DECLARE_WAITQUEUE(wait, current);
67644+ ssize_t retval = 0;
67645+
67646+ add_wait_queue(&learn_wait, &wait);
67647+ set_current_state(TASK_INTERRUPTIBLE);
67648+ do {
67649+ mutex_lock(&gr_learn_user_mutex);
67650+ spin_lock(&gr_learn_lock);
67651+ if (learn_buffer_len)
67652+ break;
67653+ spin_unlock(&gr_learn_lock);
67654+ mutex_unlock(&gr_learn_user_mutex);
67655+ if (file->f_flags & O_NONBLOCK) {
67656+ retval = -EAGAIN;
67657+ goto out;
67658+ }
67659+ if (signal_pending(current)) {
67660+ retval = -ERESTARTSYS;
67661+ goto out;
67662+ }
67663+
67664+ schedule();
67665+ } while (1);
67666+
67667+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
67668+ learn_buffer_user_len = learn_buffer_len;
67669+ retval = learn_buffer_len;
67670+ learn_buffer_len = 0;
67671+
67672+ spin_unlock(&gr_learn_lock);
67673+
67674+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
67675+ retval = -EFAULT;
67676+
67677+ mutex_unlock(&gr_learn_user_mutex);
67678+out:
67679+ set_current_state(TASK_RUNNING);
67680+ remove_wait_queue(&learn_wait, &wait);
67681+ return retval;
67682+}
67683+
67684+static unsigned int
67685+poll_learn(struct file * file, poll_table * wait)
67686+{
67687+ poll_wait(file, &learn_wait, wait);
67688+
67689+ if (learn_buffer_len)
67690+ return (POLLIN | POLLRDNORM);
67691+
67692+ return 0;
67693+}
67694+
67695+void
67696+gr_clear_learn_entries(void)
67697+{
67698+ char *tmp;
67699+
67700+ mutex_lock(&gr_learn_user_mutex);
67701+ spin_lock(&gr_learn_lock);
67702+ tmp = learn_buffer;
67703+ learn_buffer = NULL;
67704+ spin_unlock(&gr_learn_lock);
67705+ if (tmp)
67706+ vfree(tmp);
67707+ if (learn_buffer_user != NULL) {
67708+ vfree(learn_buffer_user);
67709+ learn_buffer_user = NULL;
67710+ }
67711+ learn_buffer_len = 0;
67712+ mutex_unlock(&gr_learn_user_mutex);
67713+
67714+ return;
67715+}
67716+
67717+void
67718+gr_add_learn_entry(const char *fmt, ...)
67719+{
67720+ va_list args;
67721+ unsigned int len;
67722+
67723+ if (!gr_learn_attached)
67724+ return;
67725+
67726+ spin_lock(&gr_learn_lock);
67727+
67728+ /* leave a gap at the end so we know when it's "full" but don't have to
67729+ compute the exact length of the string we're trying to append
67730+ */
67731+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
67732+ spin_unlock(&gr_learn_lock);
67733+ wake_up_interruptible(&learn_wait);
67734+ return;
67735+ }
67736+ if (learn_buffer == NULL) {
67737+ spin_unlock(&gr_learn_lock);
67738+ return;
67739+ }
67740+
67741+ va_start(args, fmt);
67742+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
67743+ va_end(args);
67744+
67745+ learn_buffer_len += len + 1;
67746+
67747+ spin_unlock(&gr_learn_lock);
67748+ wake_up_interruptible(&learn_wait);
67749+
67750+ return;
67751+}
67752+
67753+static int
67754+open_learn(struct inode *inode, struct file *file)
67755+{
67756+ if (file->f_mode & FMODE_READ && gr_learn_attached)
67757+ return -EBUSY;
67758+ if (file->f_mode & FMODE_READ) {
67759+ int retval = 0;
67760+ mutex_lock(&gr_learn_user_mutex);
67761+ if (learn_buffer == NULL)
67762+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
67763+ if (learn_buffer_user == NULL)
67764+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
67765+ if (learn_buffer == NULL) {
67766+ retval = -ENOMEM;
67767+ goto out_error;
67768+ }
67769+ if (learn_buffer_user == NULL) {
67770+ retval = -ENOMEM;
67771+ goto out_error;
67772+ }
67773+ learn_buffer_len = 0;
67774+ learn_buffer_user_len = 0;
67775+ gr_learn_attached = 1;
67776+out_error:
67777+ mutex_unlock(&gr_learn_user_mutex);
67778+ return retval;
67779+ }
67780+ return 0;
67781+}
67782+
67783+static int
67784+close_learn(struct inode *inode, struct file *file)
67785+{
67786+ if (file->f_mode & FMODE_READ) {
67787+ char *tmp = NULL;
67788+ mutex_lock(&gr_learn_user_mutex);
67789+ spin_lock(&gr_learn_lock);
67790+ tmp = learn_buffer;
67791+ learn_buffer = NULL;
67792+ spin_unlock(&gr_learn_lock);
67793+ if (tmp)
67794+ vfree(tmp);
67795+ if (learn_buffer_user != NULL) {
67796+ vfree(learn_buffer_user);
67797+ learn_buffer_user = NULL;
67798+ }
67799+ learn_buffer_len = 0;
67800+ learn_buffer_user_len = 0;
67801+ gr_learn_attached = 0;
67802+ mutex_unlock(&gr_learn_user_mutex);
67803+ }
67804+
67805+ return 0;
67806+}
67807+
67808+const struct file_operations grsec_fops = {
67809+ .read = read_learn,
67810+ .write = write_grsec_handler,
67811+ .open = open_learn,
67812+ .release = close_learn,
67813+ .poll = poll_learn,
67814+};
67815diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
67816new file mode 100644
67817index 0000000..39645c9
67818--- /dev/null
67819+++ b/grsecurity/gracl_res.c
67820@@ -0,0 +1,68 @@
67821+#include <linux/kernel.h>
67822+#include <linux/sched.h>
67823+#include <linux/gracl.h>
67824+#include <linux/grinternal.h>
67825+
67826+static const char *restab_log[] = {
67827+ [RLIMIT_CPU] = "RLIMIT_CPU",
67828+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
67829+ [RLIMIT_DATA] = "RLIMIT_DATA",
67830+ [RLIMIT_STACK] = "RLIMIT_STACK",
67831+ [RLIMIT_CORE] = "RLIMIT_CORE",
67832+ [RLIMIT_RSS] = "RLIMIT_RSS",
67833+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
67834+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
67835+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
67836+ [RLIMIT_AS] = "RLIMIT_AS",
67837+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
67838+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
67839+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
67840+ [RLIMIT_NICE] = "RLIMIT_NICE",
67841+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
67842+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
67843+ [GR_CRASH_RES] = "RLIMIT_CRASH"
67844+};
67845+
67846+void
67847+gr_log_resource(const struct task_struct *task,
67848+ const int res, const unsigned long wanted, const int gt)
67849+{
67850+ const struct cred *cred;
67851+ unsigned long rlim;
67852+
67853+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
67854+ return;
67855+
67856+ // not yet supported resource
67857+ if (unlikely(!restab_log[res]))
67858+ return;
67859+
67860+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
67861+ rlim = task_rlimit_max(task, res);
67862+ else
67863+ rlim = task_rlimit(task, res);
67864+
67865+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
67866+ return;
67867+
67868+ rcu_read_lock();
67869+ cred = __task_cred(task);
67870+
67871+ if (res == RLIMIT_NPROC &&
67872+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
67873+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
67874+ goto out_rcu_unlock;
67875+ else if (res == RLIMIT_MEMLOCK &&
67876+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
67877+ goto out_rcu_unlock;
67878+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
67879+ goto out_rcu_unlock;
67880+ rcu_read_unlock();
67881+
67882+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
67883+
67884+ return;
67885+out_rcu_unlock:
67886+ rcu_read_unlock();
67887+ return;
67888+}
67889diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
67890new file mode 100644
67891index 0000000..3c38bfe
67892--- /dev/null
67893+++ b/grsecurity/gracl_segv.c
67894@@ -0,0 +1,305 @@
67895+#include <linux/kernel.h>
67896+#include <linux/mm.h>
67897+#include <asm/uaccess.h>
67898+#include <asm/errno.h>
67899+#include <asm/mman.h>
67900+#include <net/sock.h>
67901+#include <linux/file.h>
67902+#include <linux/fs.h>
67903+#include <linux/net.h>
67904+#include <linux/in.h>
67905+#include <linux/slab.h>
67906+#include <linux/types.h>
67907+#include <linux/sched.h>
67908+#include <linux/timer.h>
67909+#include <linux/gracl.h>
67910+#include <linux/grsecurity.h>
67911+#include <linux/grinternal.h>
67912+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
67913+#include <linux/magic.h>
67914+#include <linux/pagemap.h>
67915+#include "../fs/btrfs/async-thread.h"
67916+#include "../fs/btrfs/ctree.h"
67917+#include "../fs/btrfs/btrfs_inode.h"
67918+#endif
67919+
67920+static struct crash_uid *uid_set;
67921+static unsigned short uid_used;
67922+static DEFINE_SPINLOCK(gr_uid_lock);
67923+extern rwlock_t gr_inode_lock;
67924+extern struct acl_subject_label *
67925+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
67926+ struct acl_role_label *role);
67927+
67928+static inline dev_t __get_dev(const struct dentry *dentry)
67929+{
67930+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
67931+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
67932+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
67933+ else
67934+#endif
67935+ return dentry->d_sb->s_dev;
67936+}
67937+
67938+int
67939+gr_init_uidset(void)
67940+{
67941+ uid_set =
67942+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
67943+ uid_used = 0;
67944+
67945+ return uid_set ? 1 : 0;
67946+}
67947+
67948+void
67949+gr_free_uidset(void)
67950+{
67951+ if (uid_set)
67952+ kfree(uid_set);
67953+
67954+ return;
67955+}
67956+
67957+int
67958+gr_find_uid(const uid_t uid)
67959+{
67960+ struct crash_uid *tmp = uid_set;
67961+ uid_t buid;
67962+ int low = 0, high = uid_used - 1, mid;
67963+
67964+ while (high >= low) {
67965+ mid = (low + high) >> 1;
67966+ buid = tmp[mid].uid;
67967+ if (buid == uid)
67968+ return mid;
67969+ if (buid > uid)
67970+ high = mid - 1;
67971+ if (buid < uid)
67972+ low = mid + 1;
67973+ }
67974+
67975+ return -1;
67976+}
67977+
67978+static __inline__ void
67979+gr_insertsort(void)
67980+{
67981+ unsigned short i, j;
67982+ struct crash_uid index;
67983+
67984+ for (i = 1; i < uid_used; i++) {
67985+ index = uid_set[i];
67986+ j = i;
67987+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
67988+ uid_set[j] = uid_set[j - 1];
67989+ j--;
67990+ }
67991+ uid_set[j] = index;
67992+ }
67993+
67994+ return;
67995+}
67996+
67997+static __inline__ void
67998+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
67999+{
68000+ int loc;
68001+ uid_t uid = GR_GLOBAL_UID(kuid);
68002+
68003+ if (uid_used == GR_UIDTABLE_MAX)
68004+ return;
68005+
68006+ loc = gr_find_uid(uid);
68007+
68008+ if (loc >= 0) {
68009+ uid_set[loc].expires = expires;
68010+ return;
68011+ }
68012+
68013+ uid_set[uid_used].uid = uid;
68014+ uid_set[uid_used].expires = expires;
68015+ uid_used++;
68016+
68017+ gr_insertsort();
68018+
68019+ return;
68020+}
68021+
68022+void
68023+gr_remove_uid(const unsigned short loc)
68024+{
68025+ unsigned short i;
68026+
68027+ for (i = loc + 1; i < uid_used; i++)
68028+ uid_set[i - 1] = uid_set[i];
68029+
68030+ uid_used--;
68031+
68032+ return;
68033+}
68034+
68035+int
68036+gr_check_crash_uid(const kuid_t kuid)
68037+{
68038+ int loc;
68039+ int ret = 0;
68040+ uid_t uid;
68041+
68042+ if (unlikely(!gr_acl_is_enabled()))
68043+ return 0;
68044+
68045+ uid = GR_GLOBAL_UID(kuid);
68046+
68047+ spin_lock(&gr_uid_lock);
68048+ loc = gr_find_uid(uid);
68049+
68050+ if (loc < 0)
68051+ goto out_unlock;
68052+
68053+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
68054+ gr_remove_uid(loc);
68055+ else
68056+ ret = 1;
68057+
68058+out_unlock:
68059+ spin_unlock(&gr_uid_lock);
68060+ return ret;
68061+}
68062+
68063+static __inline__ int
68064+proc_is_setxid(const struct cred *cred)
68065+{
68066+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
68067+ !uid_eq(cred->uid, cred->fsuid))
68068+ return 1;
68069+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
68070+ !gid_eq(cred->gid, cred->fsgid))
68071+ return 1;
68072+
68073+ return 0;
68074+}
68075+
68076+extern int gr_fake_force_sig(int sig, struct task_struct *t);
68077+
68078+void
68079+gr_handle_crash(struct task_struct *task, const int sig)
68080+{
68081+ struct acl_subject_label *curr;
68082+ struct task_struct *tsk, *tsk2;
68083+ const struct cred *cred;
68084+ const struct cred *cred2;
68085+
68086+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
68087+ return;
68088+
68089+ if (unlikely(!gr_acl_is_enabled()))
68090+ return;
68091+
68092+ curr = task->acl;
68093+
68094+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
68095+ return;
68096+
68097+ if (time_before_eq(curr->expires, get_seconds())) {
68098+ curr->expires = 0;
68099+ curr->crashes = 0;
68100+ }
68101+
68102+ curr->crashes++;
68103+
68104+ if (!curr->expires)
68105+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
68106+
68107+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
68108+ time_after(curr->expires, get_seconds())) {
68109+ rcu_read_lock();
68110+ cred = __task_cred(task);
68111+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
68112+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
68113+ spin_lock(&gr_uid_lock);
68114+ gr_insert_uid(cred->uid, curr->expires);
68115+ spin_unlock(&gr_uid_lock);
68116+ curr->expires = 0;
68117+ curr->crashes = 0;
68118+ read_lock(&tasklist_lock);
68119+ do_each_thread(tsk2, tsk) {
68120+ cred2 = __task_cred(tsk);
68121+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
68122+ gr_fake_force_sig(SIGKILL, tsk);
68123+ } while_each_thread(tsk2, tsk);
68124+ read_unlock(&tasklist_lock);
68125+ } else {
68126+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
68127+ read_lock(&tasklist_lock);
68128+ read_lock(&grsec_exec_file_lock);
68129+ do_each_thread(tsk2, tsk) {
68130+ if (likely(tsk != task)) {
68131+ // if this thread has the same subject as the one that triggered
68132+ // RES_CRASH and it's the same binary, kill it
68133+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
68134+ gr_fake_force_sig(SIGKILL, tsk);
68135+ }
68136+ } while_each_thread(tsk2, tsk);
68137+ read_unlock(&grsec_exec_file_lock);
68138+ read_unlock(&tasklist_lock);
68139+ }
68140+ rcu_read_unlock();
68141+ }
68142+
68143+ return;
68144+}
68145+
68146+int
68147+gr_check_crash_exec(const struct file *filp)
68148+{
68149+ struct acl_subject_label *curr;
68150+
68151+ if (unlikely(!gr_acl_is_enabled()))
68152+ return 0;
68153+
68154+ read_lock(&gr_inode_lock);
68155+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
68156+ __get_dev(filp->f_path.dentry),
68157+ current->role);
68158+ read_unlock(&gr_inode_lock);
68159+
68160+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
68161+ (!curr->crashes && !curr->expires))
68162+ return 0;
68163+
68164+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
68165+ time_after(curr->expires, get_seconds()))
68166+ return 1;
68167+ else if (time_before_eq(curr->expires, get_seconds())) {
68168+ curr->crashes = 0;
68169+ curr->expires = 0;
68170+ }
68171+
68172+ return 0;
68173+}
68174+
68175+void
68176+gr_handle_alertkill(struct task_struct *task)
68177+{
68178+ struct acl_subject_label *curracl;
68179+ __u32 curr_ip;
68180+ struct task_struct *p, *p2;
68181+
68182+ if (unlikely(!gr_acl_is_enabled()))
68183+ return;
68184+
68185+ curracl = task->acl;
68186+ curr_ip = task->signal->curr_ip;
68187+
68188+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
68189+ read_lock(&tasklist_lock);
68190+ do_each_thread(p2, p) {
68191+ if (p->signal->curr_ip == curr_ip)
68192+ gr_fake_force_sig(SIGKILL, p);
68193+ } while_each_thread(p2, p);
68194+ read_unlock(&tasklist_lock);
68195+ } else if (curracl->mode & GR_KILLPROC)
68196+ gr_fake_force_sig(SIGKILL, task);
68197+
68198+ return;
68199+}
68200diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
68201new file mode 100644
68202index 0000000..98011b0
68203--- /dev/null
68204+++ b/grsecurity/gracl_shm.c
68205@@ -0,0 +1,40 @@
68206+#include <linux/kernel.h>
68207+#include <linux/mm.h>
68208+#include <linux/sched.h>
68209+#include <linux/file.h>
68210+#include <linux/ipc.h>
68211+#include <linux/gracl.h>
68212+#include <linux/grsecurity.h>
68213+#include <linux/grinternal.h>
68214+
68215+int
68216+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68217+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
68218+{
68219+ struct task_struct *task;
68220+
68221+ if (!gr_acl_is_enabled())
68222+ return 1;
68223+
68224+ rcu_read_lock();
68225+ read_lock(&tasklist_lock);
68226+
68227+ task = find_task_by_vpid(shm_cprid);
68228+
68229+ if (unlikely(!task))
68230+ task = find_task_by_vpid(shm_lapid);
68231+
68232+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
68233+ (task_pid_nr(task) == shm_lapid)) &&
68234+ (task->acl->mode & GR_PROTSHM) &&
68235+ (task->acl != current->acl))) {
68236+ read_unlock(&tasklist_lock);
68237+ rcu_read_unlock();
68238+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
68239+ return 0;
68240+ }
68241+ read_unlock(&tasklist_lock);
68242+ rcu_read_unlock();
68243+
68244+ return 1;
68245+}
68246diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
68247new file mode 100644
68248index 0000000..bc0be01
68249--- /dev/null
68250+++ b/grsecurity/grsec_chdir.c
68251@@ -0,0 +1,19 @@
68252+#include <linux/kernel.h>
68253+#include <linux/sched.h>
68254+#include <linux/fs.h>
68255+#include <linux/file.h>
68256+#include <linux/grsecurity.h>
68257+#include <linux/grinternal.h>
68258+
68259+void
68260+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
68261+{
68262+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
68263+ if ((grsec_enable_chdir && grsec_enable_group &&
68264+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
68265+ !grsec_enable_group)) {
68266+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
68267+ }
68268+#endif
68269+ return;
68270+}
68271diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
68272new file mode 100644
68273index 0000000..bd6e105
68274--- /dev/null
68275+++ b/grsecurity/grsec_chroot.c
68276@@ -0,0 +1,370 @@
68277+#include <linux/kernel.h>
68278+#include <linux/module.h>
68279+#include <linux/sched.h>
68280+#include <linux/file.h>
68281+#include <linux/fs.h>
68282+#include <linux/mount.h>
68283+#include <linux/types.h>
68284+#include "../fs/mount.h"
68285+#include <linux/grsecurity.h>
68286+#include <linux/grinternal.h>
68287+
68288+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
68289+static int gr_init_ran;
68290+#endif
68291+
68292+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
68293+{
68294+#ifdef CONFIG_GRKERNSEC
68295+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
68296+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
68297+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
68298+ && gr_init_ran
68299+#endif
68300+ )
68301+ task->gr_is_chrooted = 1;
68302+ else {
68303+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
68304+ if (task_pid_nr(task) == 1 && !gr_init_ran)
68305+ gr_init_ran = 1;
68306+#endif
68307+ task->gr_is_chrooted = 0;
68308+ }
68309+
68310+ task->gr_chroot_dentry = path->dentry;
68311+#endif
68312+ return;
68313+}
68314+
68315+void gr_clear_chroot_entries(struct task_struct *task)
68316+{
68317+#ifdef CONFIG_GRKERNSEC
68318+ task->gr_is_chrooted = 0;
68319+ task->gr_chroot_dentry = NULL;
68320+#endif
68321+ return;
68322+}
68323+
68324+int
68325+gr_handle_chroot_unix(const pid_t pid)
68326+{
68327+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
68328+ struct task_struct *p;
68329+
68330+ if (unlikely(!grsec_enable_chroot_unix))
68331+ return 1;
68332+
68333+ if (likely(!proc_is_chrooted(current)))
68334+ return 1;
68335+
68336+ rcu_read_lock();
68337+ read_lock(&tasklist_lock);
68338+ p = find_task_by_vpid_unrestricted(pid);
68339+ if (unlikely(p && !have_same_root(current, p))) {
68340+ read_unlock(&tasklist_lock);
68341+ rcu_read_unlock();
68342+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
68343+ return 0;
68344+ }
68345+ read_unlock(&tasklist_lock);
68346+ rcu_read_unlock();
68347+#endif
68348+ return 1;
68349+}
68350+
68351+int
68352+gr_handle_chroot_nice(void)
68353+{
68354+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
68355+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
68356+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
68357+ return -EPERM;
68358+ }
68359+#endif
68360+ return 0;
68361+}
68362+
68363+int
68364+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
68365+{
68366+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
68367+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
68368+ && proc_is_chrooted(current)) {
68369+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
68370+ return -EACCES;
68371+ }
68372+#endif
68373+ return 0;
68374+}
68375+
68376+int
68377+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
68378+{
68379+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68380+ struct task_struct *p;
68381+ int ret = 0;
68382+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
68383+ return ret;
68384+
68385+ read_lock(&tasklist_lock);
68386+ do_each_pid_task(pid, type, p) {
68387+ if (!have_same_root(current, p)) {
68388+ ret = 1;
68389+ goto out;
68390+ }
68391+ } while_each_pid_task(pid, type, p);
68392+out:
68393+ read_unlock(&tasklist_lock);
68394+ return ret;
68395+#endif
68396+ return 0;
68397+}
68398+
68399+int
68400+gr_pid_is_chrooted(struct task_struct *p)
68401+{
68402+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68403+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
68404+ return 0;
68405+
68406+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
68407+ !have_same_root(current, p)) {
68408+ return 1;
68409+ }
68410+#endif
68411+ return 0;
68412+}
68413+
68414+EXPORT_SYMBOL(gr_pid_is_chrooted);
68415+
68416+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
68417+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
68418+{
68419+ struct path path, currentroot;
68420+ int ret = 0;
68421+
68422+ path.dentry = (struct dentry *)u_dentry;
68423+ path.mnt = (struct vfsmount *)u_mnt;
68424+ get_fs_root(current->fs, &currentroot);
68425+ if (path_is_under(&path, &currentroot))
68426+ ret = 1;
68427+ path_put(&currentroot);
68428+
68429+ return ret;
68430+}
68431+#endif
68432+
68433+int
68434+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
68435+{
68436+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
68437+ if (!grsec_enable_chroot_fchdir)
68438+ return 1;
68439+
68440+ if (!proc_is_chrooted(current))
68441+ return 1;
68442+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
68443+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
68444+ return 0;
68445+ }
68446+#endif
68447+ return 1;
68448+}
68449+
68450+int
68451+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68452+ const time_t shm_createtime)
68453+{
68454+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
68455+ struct task_struct *p;
68456+ time_t starttime;
68457+
68458+ if (unlikely(!grsec_enable_chroot_shmat))
68459+ return 1;
68460+
68461+ if (likely(!proc_is_chrooted(current)))
68462+ return 1;
68463+
68464+ rcu_read_lock();
68465+ read_lock(&tasklist_lock);
68466+
68467+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
68468+ starttime = p->start_time.tv_sec;
68469+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
68470+ if (have_same_root(current, p)) {
68471+ goto allow;
68472+ } else {
68473+ read_unlock(&tasklist_lock);
68474+ rcu_read_unlock();
68475+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
68476+ return 0;
68477+ }
68478+ }
68479+ /* creator exited, pid reuse, fall through to next check */
68480+ }
68481+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
68482+ if (unlikely(!have_same_root(current, p))) {
68483+ read_unlock(&tasklist_lock);
68484+ rcu_read_unlock();
68485+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
68486+ return 0;
68487+ }
68488+ }
68489+
68490+allow:
68491+ read_unlock(&tasklist_lock);
68492+ rcu_read_unlock();
68493+#endif
68494+ return 1;
68495+}
68496+
68497+void
68498+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
68499+{
68500+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
68501+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
68502+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
68503+#endif
68504+ return;
68505+}
68506+
68507+int
68508+gr_handle_chroot_mknod(const struct dentry *dentry,
68509+ const struct vfsmount *mnt, const int mode)
68510+{
68511+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
68512+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
68513+ proc_is_chrooted(current)) {
68514+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
68515+ return -EPERM;
68516+ }
68517+#endif
68518+ return 0;
68519+}
68520+
68521+int
68522+gr_handle_chroot_mount(const struct dentry *dentry,
68523+ const struct vfsmount *mnt, const char *dev_name)
68524+{
68525+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
68526+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
68527+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
68528+ return -EPERM;
68529+ }
68530+#endif
68531+ return 0;
68532+}
68533+
68534+int
68535+gr_handle_chroot_pivot(void)
68536+{
68537+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
68538+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
68539+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
68540+ return -EPERM;
68541+ }
68542+#endif
68543+ return 0;
68544+}
68545+
68546+int
68547+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
68548+{
68549+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
68550+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
68551+ !gr_is_outside_chroot(dentry, mnt)) {
68552+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
68553+ return -EPERM;
68554+ }
68555+#endif
68556+ return 0;
68557+}
68558+
68559+extern const char *captab_log[];
68560+extern int captab_log_entries;
68561+
68562+int
68563+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
68564+{
68565+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68566+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
68567+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
68568+ if (cap_raised(chroot_caps, cap)) {
68569+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
68570+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
68571+ }
68572+ return 0;
68573+ }
68574+ }
68575+#endif
68576+ return 1;
68577+}
68578+
68579+int
68580+gr_chroot_is_capable(const int cap)
68581+{
68582+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68583+ return gr_task_chroot_is_capable(current, current_cred(), cap);
68584+#endif
68585+ return 1;
68586+}
68587+
68588+int
68589+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
68590+{
68591+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68592+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
68593+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
68594+ if (cap_raised(chroot_caps, cap)) {
68595+ return 0;
68596+ }
68597+ }
68598+#endif
68599+ return 1;
68600+}
68601+
68602+int
68603+gr_chroot_is_capable_nolog(const int cap)
68604+{
68605+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68606+ return gr_task_chroot_is_capable_nolog(current, cap);
68607+#endif
68608+ return 1;
68609+}
68610+
68611+int
68612+gr_handle_chroot_sysctl(const int op)
68613+{
68614+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
68615+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
68616+ proc_is_chrooted(current))
68617+ return -EACCES;
68618+#endif
68619+ return 0;
68620+}
68621+
68622+void
68623+gr_handle_chroot_chdir(const struct path *path)
68624+{
68625+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
68626+ if (grsec_enable_chroot_chdir)
68627+ set_fs_pwd(current->fs, path);
68628+#endif
68629+ return;
68630+}
68631+
68632+int
68633+gr_handle_chroot_chmod(const struct dentry *dentry,
68634+ const struct vfsmount *mnt, const int mode)
68635+{
68636+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
68637+ /* allow chmod +s on directories, but not files */
68638+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
68639+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
68640+ proc_is_chrooted(current)) {
68641+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
68642+ return -EPERM;
68643+ }
68644+#endif
68645+ return 0;
68646+}
68647diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
68648new file mode 100644
68649index 0000000..ce65ceb
68650--- /dev/null
68651+++ b/grsecurity/grsec_disabled.c
68652@@ -0,0 +1,434 @@
68653+#include <linux/kernel.h>
68654+#include <linux/module.h>
68655+#include <linux/sched.h>
68656+#include <linux/file.h>
68657+#include <linux/fs.h>
68658+#include <linux/kdev_t.h>
68659+#include <linux/net.h>
68660+#include <linux/in.h>
68661+#include <linux/ip.h>
68662+#include <linux/skbuff.h>
68663+#include <linux/sysctl.h>
68664+
68665+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
68666+void
68667+pax_set_initial_flags(struct linux_binprm *bprm)
68668+{
68669+ return;
68670+}
68671+#endif
68672+
68673+#ifdef CONFIG_SYSCTL
68674+__u32
68675+gr_handle_sysctl(const struct ctl_table * table, const int op)
68676+{
68677+ return 0;
68678+}
68679+#endif
68680+
68681+#ifdef CONFIG_TASKSTATS
68682+int gr_is_taskstats_denied(int pid)
68683+{
68684+ return 0;
68685+}
68686+#endif
68687+
68688+int
68689+gr_acl_is_enabled(void)
68690+{
68691+ return 0;
68692+}
68693+
68694+void
68695+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
68696+{
68697+ return;
68698+}
68699+
68700+int
68701+gr_handle_rawio(const struct inode *inode)
68702+{
68703+ return 0;
68704+}
68705+
68706+void
68707+gr_acl_handle_psacct(struct task_struct *task, const long code)
68708+{
68709+ return;
68710+}
68711+
68712+int
68713+gr_handle_ptrace(struct task_struct *task, const long request)
68714+{
68715+ return 0;
68716+}
68717+
68718+int
68719+gr_handle_proc_ptrace(struct task_struct *task)
68720+{
68721+ return 0;
68722+}
68723+
68724+int
68725+gr_set_acls(const int type)
68726+{
68727+ return 0;
68728+}
68729+
68730+int
68731+gr_check_hidden_task(const struct task_struct *tsk)
68732+{
68733+ return 0;
68734+}
68735+
68736+int
68737+gr_check_protected_task(const struct task_struct *task)
68738+{
68739+ return 0;
68740+}
68741+
68742+int
68743+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
68744+{
68745+ return 0;
68746+}
68747+
68748+void
68749+gr_copy_label(struct task_struct *tsk)
68750+{
68751+ return;
68752+}
68753+
68754+void
68755+gr_set_pax_flags(struct task_struct *task)
68756+{
68757+ return;
68758+}
68759+
68760+int
68761+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
68762+ const int unsafe_share)
68763+{
68764+ return 0;
68765+}
68766+
68767+void
68768+gr_handle_delete(const ino_t ino, const dev_t dev)
68769+{
68770+ return;
68771+}
68772+
68773+void
68774+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
68775+{
68776+ return;
68777+}
68778+
68779+void
68780+gr_handle_crash(struct task_struct *task, const int sig)
68781+{
68782+ return;
68783+}
68784+
68785+int
68786+gr_check_crash_exec(const struct file *filp)
68787+{
68788+ return 0;
68789+}
68790+
68791+int
68792+gr_check_crash_uid(const kuid_t uid)
68793+{
68794+ return 0;
68795+}
68796+
68797+void
68798+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
68799+ struct dentry *old_dentry,
68800+ struct dentry *new_dentry,
68801+ struct vfsmount *mnt, const __u8 replace)
68802+{
68803+ return;
68804+}
68805+
68806+int
68807+gr_search_socket(const int family, const int type, const int protocol)
68808+{
68809+ return 1;
68810+}
68811+
68812+int
68813+gr_search_connectbind(const int mode, const struct socket *sock,
68814+ const struct sockaddr_in *addr)
68815+{
68816+ return 0;
68817+}
68818+
68819+void
68820+gr_handle_alertkill(struct task_struct *task)
68821+{
68822+ return;
68823+}
68824+
68825+__u32
68826+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
68827+{
68828+ return 1;
68829+}
68830+
68831+__u32
68832+gr_acl_handle_hidden_file(const struct dentry * dentry,
68833+ const struct vfsmount * mnt)
68834+{
68835+ return 1;
68836+}
68837+
68838+__u32
68839+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
68840+ int acc_mode)
68841+{
68842+ return 1;
68843+}
68844+
68845+__u32
68846+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
68847+{
68848+ return 1;
68849+}
68850+
68851+__u32
68852+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
68853+{
68854+ return 1;
68855+}
68856+
68857+int
68858+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
68859+ unsigned int *vm_flags)
68860+{
68861+ return 1;
68862+}
68863+
68864+__u32
68865+gr_acl_handle_truncate(const struct dentry * dentry,
68866+ const struct vfsmount * mnt)
68867+{
68868+ return 1;
68869+}
68870+
68871+__u32
68872+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
68873+{
68874+ return 1;
68875+}
68876+
68877+__u32
68878+gr_acl_handle_access(const struct dentry * dentry,
68879+ const struct vfsmount * mnt, const int fmode)
68880+{
68881+ return 1;
68882+}
68883+
68884+__u32
68885+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
68886+ umode_t *mode)
68887+{
68888+ return 1;
68889+}
68890+
68891+__u32
68892+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
68893+{
68894+ return 1;
68895+}
68896+
68897+__u32
68898+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
68899+{
68900+ return 1;
68901+}
68902+
68903+void
68904+grsecurity_init(void)
68905+{
68906+ return;
68907+}
68908+
68909+umode_t gr_acl_umask(void)
68910+{
68911+ return 0;
68912+}
68913+
68914+__u32
68915+gr_acl_handle_mknod(const struct dentry * new_dentry,
68916+ const struct dentry * parent_dentry,
68917+ const struct vfsmount * parent_mnt,
68918+ const int mode)
68919+{
68920+ return 1;
68921+}
68922+
68923+__u32
68924+gr_acl_handle_mkdir(const struct dentry * new_dentry,
68925+ const struct dentry * parent_dentry,
68926+ const struct vfsmount * parent_mnt)
68927+{
68928+ return 1;
68929+}
68930+
68931+__u32
68932+gr_acl_handle_symlink(const struct dentry * new_dentry,
68933+ const struct dentry * parent_dentry,
68934+ const struct vfsmount * parent_mnt, const struct filename *from)
68935+{
68936+ return 1;
68937+}
68938+
68939+__u32
68940+gr_acl_handle_link(const struct dentry * new_dentry,
68941+ const struct dentry * parent_dentry,
68942+ const struct vfsmount * parent_mnt,
68943+ const struct dentry * old_dentry,
68944+ const struct vfsmount * old_mnt, const struct filename *to)
68945+{
68946+ return 1;
68947+}
68948+
68949+int
68950+gr_acl_handle_rename(const struct dentry *new_dentry,
68951+ const struct dentry *parent_dentry,
68952+ const struct vfsmount *parent_mnt,
68953+ const struct dentry *old_dentry,
68954+ const struct inode *old_parent_inode,
68955+ const struct vfsmount *old_mnt, const struct filename *newname)
68956+{
68957+ return 0;
68958+}
68959+
68960+int
68961+gr_acl_handle_filldir(const struct file *file, const char *name,
68962+ const int namelen, const ino_t ino)
68963+{
68964+ return 1;
68965+}
68966+
68967+int
68968+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68969+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
68970+{
68971+ return 1;
68972+}
68973+
68974+int
68975+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
68976+{
68977+ return 0;
68978+}
68979+
68980+int
68981+gr_search_accept(const struct socket *sock)
68982+{
68983+ return 0;
68984+}
68985+
68986+int
68987+gr_search_listen(const struct socket *sock)
68988+{
68989+ return 0;
68990+}
68991+
68992+int
68993+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
68994+{
68995+ return 0;
68996+}
68997+
68998+__u32
68999+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
69000+{
69001+ return 1;
69002+}
69003+
69004+__u32
69005+gr_acl_handle_creat(const struct dentry * dentry,
69006+ const struct dentry * p_dentry,
69007+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
69008+ const int imode)
69009+{
69010+ return 1;
69011+}
69012+
69013+void
69014+gr_acl_handle_exit(void)
69015+{
69016+ return;
69017+}
69018+
69019+int
69020+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
69021+{
69022+ return 1;
69023+}
69024+
69025+void
69026+gr_set_role_label(const kuid_t uid, const kgid_t gid)
69027+{
69028+ return;
69029+}
69030+
69031+int
69032+gr_acl_handle_procpidmem(const struct task_struct *task)
69033+{
69034+ return 0;
69035+}
69036+
69037+int
69038+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
69039+{
69040+ return 0;
69041+}
69042+
69043+int
69044+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
69045+{
69046+ return 0;
69047+}
69048+
69049+void
69050+gr_set_kernel_label(struct task_struct *task)
69051+{
69052+ return;
69053+}
69054+
69055+int
69056+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
69057+{
69058+ return 0;
69059+}
69060+
69061+int
69062+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
69063+{
69064+ return 0;
69065+}
69066+
69067+int gr_acl_enable_at_secure(void)
69068+{
69069+ return 0;
69070+}
69071+
69072+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
69073+{
69074+ return dentry->d_sb->s_dev;
69075+}
69076+
69077+void gr_put_exec_file(struct task_struct *task)
69078+{
69079+ return;
69080+}
69081+
69082+EXPORT_SYMBOL(gr_set_kernel_label);
69083+#ifdef CONFIG_SECURITY
69084+EXPORT_SYMBOL(gr_check_user_change);
69085+EXPORT_SYMBOL(gr_check_group_change);
69086+#endif
69087diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
69088new file mode 100644
69089index 0000000..387032b
69090--- /dev/null
69091+++ b/grsecurity/grsec_exec.c
69092@@ -0,0 +1,187 @@
69093+#include <linux/kernel.h>
69094+#include <linux/sched.h>
69095+#include <linux/file.h>
69096+#include <linux/binfmts.h>
69097+#include <linux/fs.h>
69098+#include <linux/types.h>
69099+#include <linux/grdefs.h>
69100+#include <linux/grsecurity.h>
69101+#include <linux/grinternal.h>
69102+#include <linux/capability.h>
69103+#include <linux/module.h>
69104+#include <linux/compat.h>
69105+
69106+#include <asm/uaccess.h>
69107+
69108+#ifdef CONFIG_GRKERNSEC_EXECLOG
69109+static char gr_exec_arg_buf[132];
69110+static DEFINE_MUTEX(gr_exec_arg_mutex);
69111+#endif
69112+
69113+struct user_arg_ptr {
69114+#ifdef CONFIG_COMPAT
69115+ bool is_compat;
69116+#endif
69117+ union {
69118+ const char __user *const __user *native;
69119+#ifdef CONFIG_COMPAT
69120+ const compat_uptr_t __user *compat;
69121+#endif
69122+ } ptr;
69123+};
69124+
69125+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
69126+
69127+void
69128+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
69129+{
69130+#ifdef CONFIG_GRKERNSEC_EXECLOG
69131+ char *grarg = gr_exec_arg_buf;
69132+ unsigned int i, x, execlen = 0;
69133+ char c;
69134+
69135+ if (!((grsec_enable_execlog && grsec_enable_group &&
69136+ in_group_p(grsec_audit_gid))
69137+ || (grsec_enable_execlog && !grsec_enable_group)))
69138+ return;
69139+
69140+ mutex_lock(&gr_exec_arg_mutex);
69141+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
69142+
69143+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
69144+ const char __user *p;
69145+ unsigned int len;
69146+
69147+ p = get_user_arg_ptr(argv, i);
69148+ if (IS_ERR(p))
69149+ goto log;
69150+
69151+ len = strnlen_user(p, 128 - execlen);
69152+ if (len > 128 - execlen)
69153+ len = 128 - execlen;
69154+ else if (len > 0)
69155+ len--;
69156+ if (copy_from_user(grarg + execlen, p, len))
69157+ goto log;
69158+
69159+ /* rewrite unprintable characters */
69160+ for (x = 0; x < len; x++) {
69161+ c = *(grarg + execlen + x);
69162+ if (c < 32 || c > 126)
69163+ *(grarg + execlen + x) = ' ';
69164+ }
69165+
69166+ execlen += len;
69167+ *(grarg + execlen) = ' ';
69168+ *(grarg + execlen + 1) = '\0';
69169+ execlen++;
69170+ }
69171+
69172+ log:
69173+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
69174+ bprm->file->f_path.mnt, grarg);
69175+ mutex_unlock(&gr_exec_arg_mutex);
69176+#endif
69177+ return;
69178+}
69179+
69180+#ifdef CONFIG_GRKERNSEC
69181+extern int gr_acl_is_capable(const int cap);
69182+extern int gr_acl_is_capable_nolog(const int cap);
69183+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
69184+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
69185+extern int gr_chroot_is_capable(const int cap);
69186+extern int gr_chroot_is_capable_nolog(const int cap);
69187+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
69188+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
69189+#endif
69190+
69191+const char *captab_log[] = {
69192+ "CAP_CHOWN",
69193+ "CAP_DAC_OVERRIDE",
69194+ "CAP_DAC_READ_SEARCH",
69195+ "CAP_FOWNER",
69196+ "CAP_FSETID",
69197+ "CAP_KILL",
69198+ "CAP_SETGID",
69199+ "CAP_SETUID",
69200+ "CAP_SETPCAP",
69201+ "CAP_LINUX_IMMUTABLE",
69202+ "CAP_NET_BIND_SERVICE",
69203+ "CAP_NET_BROADCAST",
69204+ "CAP_NET_ADMIN",
69205+ "CAP_NET_RAW",
69206+ "CAP_IPC_LOCK",
69207+ "CAP_IPC_OWNER",
69208+ "CAP_SYS_MODULE",
69209+ "CAP_SYS_RAWIO",
69210+ "CAP_SYS_CHROOT",
69211+ "CAP_SYS_PTRACE",
69212+ "CAP_SYS_PACCT",
69213+ "CAP_SYS_ADMIN",
69214+ "CAP_SYS_BOOT",
69215+ "CAP_SYS_NICE",
69216+ "CAP_SYS_RESOURCE",
69217+ "CAP_SYS_TIME",
69218+ "CAP_SYS_TTY_CONFIG",
69219+ "CAP_MKNOD",
69220+ "CAP_LEASE",
69221+ "CAP_AUDIT_WRITE",
69222+ "CAP_AUDIT_CONTROL",
69223+ "CAP_SETFCAP",
69224+ "CAP_MAC_OVERRIDE",
69225+ "CAP_MAC_ADMIN",
69226+ "CAP_SYSLOG",
69227+ "CAP_WAKE_ALARM"
69228+};
69229+
69230+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
69231+
69232+int gr_is_capable(const int cap)
69233+{
69234+#ifdef CONFIG_GRKERNSEC
69235+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
69236+ return 1;
69237+ return 0;
69238+#else
69239+ return 1;
69240+#endif
69241+}
69242+
69243+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
69244+{
69245+#ifdef CONFIG_GRKERNSEC
69246+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
69247+ return 1;
69248+ return 0;
69249+#else
69250+ return 1;
69251+#endif
69252+}
69253+
69254+int gr_is_capable_nolog(const int cap)
69255+{
69256+#ifdef CONFIG_GRKERNSEC
69257+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
69258+ return 1;
69259+ return 0;
69260+#else
69261+ return 1;
69262+#endif
69263+}
69264+
69265+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
69266+{
69267+#ifdef CONFIG_GRKERNSEC
69268+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
69269+ return 1;
69270+ return 0;
69271+#else
69272+ return 1;
69273+#endif
69274+}
69275+
69276+EXPORT_SYMBOL(gr_is_capable);
69277+EXPORT_SYMBOL(gr_is_capable_nolog);
69278+EXPORT_SYMBOL(gr_task_is_capable);
69279+EXPORT_SYMBOL(gr_task_is_capable_nolog);
69280diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
69281new file mode 100644
69282index 0000000..06cc6ea
69283--- /dev/null
69284+++ b/grsecurity/grsec_fifo.c
69285@@ -0,0 +1,24 @@
69286+#include <linux/kernel.h>
69287+#include <linux/sched.h>
69288+#include <linux/fs.h>
69289+#include <linux/file.h>
69290+#include <linux/grinternal.h>
69291+
69292+int
69293+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
69294+ const struct dentry *dir, const int flag, const int acc_mode)
69295+{
69296+#ifdef CONFIG_GRKERNSEC_FIFO
69297+ const struct cred *cred = current_cred();
69298+
69299+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
69300+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
69301+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
69302+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
69303+ if (!inode_permission(dentry->d_inode, acc_mode))
69304+ 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));
69305+ return -EACCES;
69306+ }
69307+#endif
69308+ return 0;
69309+}
69310diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
69311new file mode 100644
69312index 0000000..8ca18bf
69313--- /dev/null
69314+++ b/grsecurity/grsec_fork.c
69315@@ -0,0 +1,23 @@
69316+#include <linux/kernel.h>
69317+#include <linux/sched.h>
69318+#include <linux/grsecurity.h>
69319+#include <linux/grinternal.h>
69320+#include <linux/errno.h>
69321+
69322+void
69323+gr_log_forkfail(const int retval)
69324+{
69325+#ifdef CONFIG_GRKERNSEC_FORKFAIL
69326+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
69327+ switch (retval) {
69328+ case -EAGAIN:
69329+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
69330+ break;
69331+ case -ENOMEM:
69332+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
69333+ break;
69334+ }
69335+ }
69336+#endif
69337+ return;
69338+}
69339diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
69340new file mode 100644
69341index 0000000..99a0cb9
69342--- /dev/null
69343+++ b/grsecurity/grsec_init.c
69344@@ -0,0 +1,283 @@
69345+#include <linux/kernel.h>
69346+#include <linux/sched.h>
69347+#include <linux/mm.h>
69348+#include <linux/gracl.h>
69349+#include <linux/slab.h>
69350+#include <linux/vmalloc.h>
69351+#include <linux/percpu.h>
69352+#include <linux/module.h>
69353+
69354+int grsec_enable_ptrace_readexec;
69355+int grsec_enable_setxid;
69356+int grsec_enable_symlinkown;
69357+kgid_t grsec_symlinkown_gid;
69358+int grsec_enable_brute;
69359+int grsec_enable_link;
69360+int grsec_enable_dmesg;
69361+int grsec_enable_harden_ptrace;
69362+int grsec_enable_fifo;
69363+int grsec_enable_execlog;
69364+int grsec_enable_signal;
69365+int grsec_enable_forkfail;
69366+int grsec_enable_audit_ptrace;
69367+int grsec_enable_time;
69368+int grsec_enable_group;
69369+kgid_t grsec_audit_gid;
69370+int grsec_enable_chdir;
69371+int grsec_enable_mount;
69372+int grsec_enable_rofs;
69373+int grsec_deny_new_usb;
69374+int grsec_enable_chroot_findtask;
69375+int grsec_enable_chroot_mount;
69376+int grsec_enable_chroot_shmat;
69377+int grsec_enable_chroot_fchdir;
69378+int grsec_enable_chroot_double;
69379+int grsec_enable_chroot_pivot;
69380+int grsec_enable_chroot_chdir;
69381+int grsec_enable_chroot_chmod;
69382+int grsec_enable_chroot_mknod;
69383+int grsec_enable_chroot_nice;
69384+int grsec_enable_chroot_execlog;
69385+int grsec_enable_chroot_caps;
69386+int grsec_enable_chroot_sysctl;
69387+int grsec_enable_chroot_unix;
69388+int grsec_enable_tpe;
69389+kgid_t grsec_tpe_gid;
69390+int grsec_enable_blackhole;
69391+#ifdef CONFIG_IPV6_MODULE
69392+EXPORT_SYMBOL(grsec_enable_blackhole);
69393+#endif
69394+int grsec_lastack_retries;
69395+int grsec_enable_tpe_all;
69396+int grsec_enable_tpe_invert;
69397+int grsec_enable_socket_all;
69398+kgid_t grsec_socket_all_gid;
69399+int grsec_enable_socket_client;
69400+kgid_t grsec_socket_client_gid;
69401+int grsec_enable_socket_server;
69402+kgid_t grsec_socket_server_gid;
69403+int grsec_resource_logging;
69404+int grsec_disable_privio;
69405+int grsec_enable_log_rwxmaps;
69406+int grsec_lock;
69407+
69408+DEFINE_SPINLOCK(grsec_alert_lock);
69409+unsigned long grsec_alert_wtime = 0;
69410+unsigned long grsec_alert_fyet = 0;
69411+
69412+DEFINE_SPINLOCK(grsec_audit_lock);
69413+
69414+DEFINE_RWLOCK(grsec_exec_file_lock);
69415+
69416+char *gr_shared_page[4];
69417+
69418+char *gr_alert_log_fmt;
69419+char *gr_audit_log_fmt;
69420+char *gr_alert_log_buf;
69421+char *gr_audit_log_buf;
69422+
69423+extern struct gr_arg *gr_usermode;
69424+extern unsigned char *gr_system_salt;
69425+extern unsigned char *gr_system_sum;
69426+
69427+void __init
69428+grsecurity_init(void)
69429+{
69430+ int j;
69431+ /* create the per-cpu shared pages */
69432+
69433+#ifdef CONFIG_X86
69434+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
69435+#endif
69436+
69437+ for (j = 0; j < 4; j++) {
69438+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
69439+ if (gr_shared_page[j] == NULL) {
69440+ panic("Unable to allocate grsecurity shared page");
69441+ return;
69442+ }
69443+ }
69444+
69445+ /* allocate log buffers */
69446+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
69447+ if (!gr_alert_log_fmt) {
69448+ panic("Unable to allocate grsecurity alert log format buffer");
69449+ return;
69450+ }
69451+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
69452+ if (!gr_audit_log_fmt) {
69453+ panic("Unable to allocate grsecurity audit log format buffer");
69454+ return;
69455+ }
69456+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
69457+ if (!gr_alert_log_buf) {
69458+ panic("Unable to allocate grsecurity alert log buffer");
69459+ return;
69460+ }
69461+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
69462+ if (!gr_audit_log_buf) {
69463+ panic("Unable to allocate grsecurity audit log buffer");
69464+ return;
69465+ }
69466+
69467+ /* allocate memory for authentication structure */
69468+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
69469+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
69470+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
69471+
69472+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
69473+ panic("Unable to allocate grsecurity authentication structure");
69474+ return;
69475+ }
69476+
69477+
69478+#ifdef CONFIG_GRKERNSEC_IO
69479+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
69480+ grsec_disable_privio = 1;
69481+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
69482+ grsec_disable_privio = 1;
69483+#else
69484+ grsec_disable_privio = 0;
69485+#endif
69486+#endif
69487+
69488+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
69489+ /* for backward compatibility, tpe_invert always defaults to on if
69490+ enabled in the kernel
69491+ */
69492+ grsec_enable_tpe_invert = 1;
69493+#endif
69494+
69495+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
69496+#ifndef CONFIG_GRKERNSEC_SYSCTL
69497+ grsec_lock = 1;
69498+#endif
69499+
69500+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
69501+ grsec_enable_log_rwxmaps = 1;
69502+#endif
69503+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
69504+ grsec_enable_group = 1;
69505+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
69506+#endif
69507+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
69508+ grsec_enable_ptrace_readexec = 1;
69509+#endif
69510+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
69511+ grsec_enable_chdir = 1;
69512+#endif
69513+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69514+ grsec_enable_harden_ptrace = 1;
69515+#endif
69516+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
69517+ grsec_enable_mount = 1;
69518+#endif
69519+#ifdef CONFIG_GRKERNSEC_LINK
69520+ grsec_enable_link = 1;
69521+#endif
69522+#ifdef CONFIG_GRKERNSEC_BRUTE
69523+ grsec_enable_brute = 1;
69524+#endif
69525+#ifdef CONFIG_GRKERNSEC_DMESG
69526+ grsec_enable_dmesg = 1;
69527+#endif
69528+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
69529+ grsec_enable_blackhole = 1;
69530+ grsec_lastack_retries = 4;
69531+#endif
69532+#ifdef CONFIG_GRKERNSEC_FIFO
69533+ grsec_enable_fifo = 1;
69534+#endif
69535+#ifdef CONFIG_GRKERNSEC_EXECLOG
69536+ grsec_enable_execlog = 1;
69537+#endif
69538+#ifdef CONFIG_GRKERNSEC_SETXID
69539+ grsec_enable_setxid = 1;
69540+#endif
69541+#ifdef CONFIG_GRKERNSEC_SIGNAL
69542+ grsec_enable_signal = 1;
69543+#endif
69544+#ifdef CONFIG_GRKERNSEC_FORKFAIL
69545+ grsec_enable_forkfail = 1;
69546+#endif
69547+#ifdef CONFIG_GRKERNSEC_TIME
69548+ grsec_enable_time = 1;
69549+#endif
69550+#ifdef CONFIG_GRKERNSEC_RESLOG
69551+ grsec_resource_logging = 1;
69552+#endif
69553+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69554+ grsec_enable_chroot_findtask = 1;
69555+#endif
69556+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
69557+ grsec_enable_chroot_unix = 1;
69558+#endif
69559+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
69560+ grsec_enable_chroot_mount = 1;
69561+#endif
69562+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
69563+ grsec_enable_chroot_fchdir = 1;
69564+#endif
69565+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
69566+ grsec_enable_chroot_shmat = 1;
69567+#endif
69568+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
69569+ grsec_enable_audit_ptrace = 1;
69570+#endif
69571+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
69572+ grsec_enable_chroot_double = 1;
69573+#endif
69574+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
69575+ grsec_enable_chroot_pivot = 1;
69576+#endif
69577+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
69578+ grsec_enable_chroot_chdir = 1;
69579+#endif
69580+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
69581+ grsec_enable_chroot_chmod = 1;
69582+#endif
69583+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
69584+ grsec_enable_chroot_mknod = 1;
69585+#endif
69586+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
69587+ grsec_enable_chroot_nice = 1;
69588+#endif
69589+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
69590+ grsec_enable_chroot_execlog = 1;
69591+#endif
69592+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
69593+ grsec_enable_chroot_caps = 1;
69594+#endif
69595+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
69596+ grsec_enable_chroot_sysctl = 1;
69597+#endif
69598+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
69599+ grsec_enable_symlinkown = 1;
69600+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
69601+#endif
69602+#ifdef CONFIG_GRKERNSEC_TPE
69603+ grsec_enable_tpe = 1;
69604+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
69605+#ifdef CONFIG_GRKERNSEC_TPE_ALL
69606+ grsec_enable_tpe_all = 1;
69607+#endif
69608+#endif
69609+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
69610+ grsec_enable_socket_all = 1;
69611+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
69612+#endif
69613+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
69614+ grsec_enable_socket_client = 1;
69615+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
69616+#endif
69617+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
69618+ grsec_enable_socket_server = 1;
69619+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
69620+#endif
69621+#endif
69622+#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
69623+ grsec_deny_new_usb = 1;
69624+#endif
69625+
69626+ return;
69627+}
69628diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
69629new file mode 100644
69630index 0000000..5e05e20
69631--- /dev/null
69632+++ b/grsecurity/grsec_link.c
69633@@ -0,0 +1,58 @@
69634+#include <linux/kernel.h>
69635+#include <linux/sched.h>
69636+#include <linux/fs.h>
69637+#include <linux/file.h>
69638+#include <linux/grinternal.h>
69639+
69640+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
69641+{
69642+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
69643+ const struct inode *link_inode = link->dentry->d_inode;
69644+
69645+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
69646+ /* ignore root-owned links, e.g. /proc/self */
69647+ gr_is_global_nonroot(link_inode->i_uid) && target &&
69648+ !uid_eq(link_inode->i_uid, target->i_uid)) {
69649+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
69650+ return 1;
69651+ }
69652+#endif
69653+ return 0;
69654+}
69655+
69656+int
69657+gr_handle_follow_link(const struct inode *parent,
69658+ const struct inode *inode,
69659+ const struct dentry *dentry, const struct vfsmount *mnt)
69660+{
69661+#ifdef CONFIG_GRKERNSEC_LINK
69662+ const struct cred *cred = current_cred();
69663+
69664+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
69665+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
69666+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
69667+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
69668+ return -EACCES;
69669+ }
69670+#endif
69671+ return 0;
69672+}
69673+
69674+int
69675+gr_handle_hardlink(const struct dentry *dentry,
69676+ const struct vfsmount *mnt,
69677+ struct inode *inode, const int mode, const struct filename *to)
69678+{
69679+#ifdef CONFIG_GRKERNSEC_LINK
69680+ const struct cred *cred = current_cred();
69681+
69682+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
69683+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
69684+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
69685+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
69686+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
69687+ return -EPERM;
69688+ }
69689+#endif
69690+ return 0;
69691+}
69692diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
69693new file mode 100644
69694index 0000000..dbe0a6b
69695--- /dev/null
69696+++ b/grsecurity/grsec_log.c
69697@@ -0,0 +1,341 @@
69698+#include <linux/kernel.h>
69699+#include <linux/sched.h>
69700+#include <linux/file.h>
69701+#include <linux/tty.h>
69702+#include <linux/fs.h>
69703+#include <linux/mm.h>
69704+#include <linux/grinternal.h>
69705+
69706+#ifdef CONFIG_TREE_PREEMPT_RCU
69707+#define DISABLE_PREEMPT() preempt_disable()
69708+#define ENABLE_PREEMPT() preempt_enable()
69709+#else
69710+#define DISABLE_PREEMPT()
69711+#define ENABLE_PREEMPT()
69712+#endif
69713+
69714+#define BEGIN_LOCKS(x) \
69715+ DISABLE_PREEMPT(); \
69716+ rcu_read_lock(); \
69717+ read_lock(&tasklist_lock); \
69718+ read_lock(&grsec_exec_file_lock); \
69719+ if (x != GR_DO_AUDIT) \
69720+ spin_lock(&grsec_alert_lock); \
69721+ else \
69722+ spin_lock(&grsec_audit_lock)
69723+
69724+#define END_LOCKS(x) \
69725+ if (x != GR_DO_AUDIT) \
69726+ spin_unlock(&grsec_alert_lock); \
69727+ else \
69728+ spin_unlock(&grsec_audit_lock); \
69729+ read_unlock(&grsec_exec_file_lock); \
69730+ read_unlock(&tasklist_lock); \
69731+ rcu_read_unlock(); \
69732+ ENABLE_PREEMPT(); \
69733+ if (x == GR_DONT_AUDIT) \
69734+ gr_handle_alertkill(current)
69735+
69736+enum {
69737+ FLOODING,
69738+ NO_FLOODING
69739+};
69740+
69741+extern char *gr_alert_log_fmt;
69742+extern char *gr_audit_log_fmt;
69743+extern char *gr_alert_log_buf;
69744+extern char *gr_audit_log_buf;
69745+
69746+static int gr_log_start(int audit)
69747+{
69748+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
69749+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
69750+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
69751+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
69752+ unsigned long curr_secs = get_seconds();
69753+
69754+ if (audit == GR_DO_AUDIT)
69755+ goto set_fmt;
69756+
69757+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
69758+ grsec_alert_wtime = curr_secs;
69759+ grsec_alert_fyet = 0;
69760+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
69761+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
69762+ grsec_alert_fyet++;
69763+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
69764+ grsec_alert_wtime = curr_secs;
69765+ grsec_alert_fyet++;
69766+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
69767+ return FLOODING;
69768+ }
69769+ else return FLOODING;
69770+
69771+set_fmt:
69772+#endif
69773+ memset(buf, 0, PAGE_SIZE);
69774+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
69775+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
69776+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
69777+ } else if (current->signal->curr_ip) {
69778+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
69779+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
69780+ } else if (gr_acl_is_enabled()) {
69781+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
69782+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
69783+ } else {
69784+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
69785+ strcpy(buf, fmt);
69786+ }
69787+
69788+ return NO_FLOODING;
69789+}
69790+
69791+static void gr_log_middle(int audit, const char *msg, va_list ap)
69792+ __attribute__ ((format (printf, 2, 0)));
69793+
69794+static void gr_log_middle(int audit, const char *msg, va_list ap)
69795+{
69796+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
69797+ unsigned int len = strlen(buf);
69798+
69799+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
69800+
69801+ return;
69802+}
69803+
69804+static void gr_log_middle_varargs(int audit, const char *msg, ...)
69805+ __attribute__ ((format (printf, 2, 3)));
69806+
69807+static void gr_log_middle_varargs(int audit, const char *msg, ...)
69808+{
69809+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
69810+ unsigned int len = strlen(buf);
69811+ va_list ap;
69812+
69813+ va_start(ap, msg);
69814+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
69815+ va_end(ap);
69816+
69817+ return;
69818+}
69819+
69820+static void gr_log_end(int audit, int append_default)
69821+{
69822+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
69823+ if (append_default) {
69824+ struct task_struct *task = current;
69825+ struct task_struct *parent = task->real_parent;
69826+ const struct cred *cred = __task_cred(task);
69827+ const struct cred *pcred = __task_cred(parent);
69828+ unsigned int len = strlen(buf);
69829+
69830+ 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));
69831+ }
69832+
69833+ printk("%s\n", buf);
69834+
69835+ return;
69836+}
69837+
69838+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
69839+{
69840+ int logtype;
69841+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
69842+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
69843+ void *voidptr = NULL;
69844+ int num1 = 0, num2 = 0;
69845+ unsigned long ulong1 = 0, ulong2 = 0;
69846+ struct dentry *dentry = NULL;
69847+ struct vfsmount *mnt = NULL;
69848+ struct file *file = NULL;
69849+ struct task_struct *task = NULL;
69850+ struct vm_area_struct *vma = NULL;
69851+ const struct cred *cred, *pcred;
69852+ va_list ap;
69853+
69854+ BEGIN_LOCKS(audit);
69855+ logtype = gr_log_start(audit);
69856+ if (logtype == FLOODING) {
69857+ END_LOCKS(audit);
69858+ return;
69859+ }
69860+ va_start(ap, argtypes);
69861+ switch (argtypes) {
69862+ case GR_TTYSNIFF:
69863+ task = va_arg(ap, struct task_struct *);
69864+ 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));
69865+ break;
69866+ case GR_SYSCTL_HIDDEN:
69867+ str1 = va_arg(ap, char *);
69868+ gr_log_middle_varargs(audit, msg, result, str1);
69869+ break;
69870+ case GR_RBAC:
69871+ dentry = va_arg(ap, struct dentry *);
69872+ mnt = va_arg(ap, struct vfsmount *);
69873+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
69874+ break;
69875+ case GR_RBAC_STR:
69876+ dentry = va_arg(ap, struct dentry *);
69877+ mnt = va_arg(ap, struct vfsmount *);
69878+ str1 = va_arg(ap, char *);
69879+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
69880+ break;
69881+ case GR_STR_RBAC:
69882+ str1 = va_arg(ap, char *);
69883+ dentry = va_arg(ap, struct dentry *);
69884+ mnt = va_arg(ap, struct vfsmount *);
69885+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
69886+ break;
69887+ case GR_RBAC_MODE2:
69888+ dentry = va_arg(ap, struct dentry *);
69889+ mnt = va_arg(ap, struct vfsmount *);
69890+ str1 = va_arg(ap, char *);
69891+ str2 = va_arg(ap, char *);
69892+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
69893+ break;
69894+ case GR_RBAC_MODE3:
69895+ dentry = va_arg(ap, struct dentry *);
69896+ mnt = va_arg(ap, struct vfsmount *);
69897+ str1 = va_arg(ap, char *);
69898+ str2 = va_arg(ap, char *);
69899+ str3 = va_arg(ap, char *);
69900+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
69901+ break;
69902+ case GR_FILENAME:
69903+ dentry = va_arg(ap, struct dentry *);
69904+ mnt = va_arg(ap, struct vfsmount *);
69905+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
69906+ break;
69907+ case GR_STR_FILENAME:
69908+ str1 = va_arg(ap, char *);
69909+ dentry = va_arg(ap, struct dentry *);
69910+ mnt = va_arg(ap, struct vfsmount *);
69911+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
69912+ break;
69913+ case GR_FILENAME_STR:
69914+ dentry = va_arg(ap, struct dentry *);
69915+ mnt = va_arg(ap, struct vfsmount *);
69916+ str1 = va_arg(ap, char *);
69917+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
69918+ break;
69919+ case GR_FILENAME_TWO_INT:
69920+ dentry = va_arg(ap, struct dentry *);
69921+ mnt = va_arg(ap, struct vfsmount *);
69922+ num1 = va_arg(ap, int);
69923+ num2 = va_arg(ap, int);
69924+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
69925+ break;
69926+ case GR_FILENAME_TWO_INT_STR:
69927+ dentry = va_arg(ap, struct dentry *);
69928+ mnt = va_arg(ap, struct vfsmount *);
69929+ num1 = va_arg(ap, int);
69930+ num2 = va_arg(ap, int);
69931+ str1 = va_arg(ap, char *);
69932+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
69933+ break;
69934+ case GR_TEXTREL:
69935+ file = va_arg(ap, struct file *);
69936+ ulong1 = va_arg(ap, unsigned long);
69937+ ulong2 = va_arg(ap, unsigned long);
69938+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
69939+ break;
69940+ case GR_PTRACE:
69941+ task = va_arg(ap, struct task_struct *);
69942+ 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));
69943+ break;
69944+ case GR_RESOURCE:
69945+ task = va_arg(ap, struct task_struct *);
69946+ cred = __task_cred(task);
69947+ pcred = __task_cred(task->real_parent);
69948+ ulong1 = va_arg(ap, unsigned long);
69949+ str1 = va_arg(ap, char *);
69950+ ulong2 = va_arg(ap, unsigned long);
69951+ 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));
69952+ break;
69953+ case GR_CAP:
69954+ task = va_arg(ap, struct task_struct *);
69955+ cred = __task_cred(task);
69956+ pcred = __task_cred(task->real_parent);
69957+ str1 = va_arg(ap, char *);
69958+ 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));
69959+ break;
69960+ case GR_SIG:
69961+ str1 = va_arg(ap, char *);
69962+ voidptr = va_arg(ap, void *);
69963+ gr_log_middle_varargs(audit, msg, str1, voidptr);
69964+ break;
69965+ case GR_SIG2:
69966+ task = va_arg(ap, struct task_struct *);
69967+ cred = __task_cred(task);
69968+ pcred = __task_cred(task->real_parent);
69969+ num1 = va_arg(ap, int);
69970+ 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));
69971+ break;
69972+ case GR_CRASH1:
69973+ task = va_arg(ap, struct task_struct *);
69974+ cred = __task_cred(task);
69975+ pcred = __task_cred(task->real_parent);
69976+ ulong1 = va_arg(ap, unsigned long);
69977+ 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);
69978+ break;
69979+ case GR_CRASH2:
69980+ task = va_arg(ap, struct task_struct *);
69981+ cred = __task_cred(task);
69982+ pcred = __task_cred(task->real_parent);
69983+ ulong1 = va_arg(ap, unsigned long);
69984+ 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);
69985+ break;
69986+ case GR_RWXMAP:
69987+ file = va_arg(ap, struct file *);
69988+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
69989+ break;
69990+ case GR_RWXMAPVMA:
69991+ vma = va_arg(ap, struct vm_area_struct *);
69992+ if (vma->vm_file)
69993+ str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
69994+ else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
69995+ str1 = "<stack>";
69996+ else if (vma->vm_start <= current->mm->brk &&
69997+ vma->vm_end >= current->mm->start_brk)
69998+ str1 = "<heap>";
69999+ else
70000+ str1 = "<anonymous mapping>";
70001+ gr_log_middle_varargs(audit, msg, str1);
70002+ break;
70003+ case GR_PSACCT:
70004+ {
70005+ unsigned int wday, cday;
70006+ __u8 whr, chr;
70007+ __u8 wmin, cmin;
70008+ __u8 wsec, csec;
70009+ char cur_tty[64] = { 0 };
70010+ char parent_tty[64] = { 0 };
70011+
70012+ task = va_arg(ap, struct task_struct *);
70013+ wday = va_arg(ap, unsigned int);
70014+ cday = va_arg(ap, unsigned int);
70015+ whr = va_arg(ap, int);
70016+ chr = va_arg(ap, int);
70017+ wmin = va_arg(ap, int);
70018+ cmin = va_arg(ap, int);
70019+ wsec = va_arg(ap, int);
70020+ csec = va_arg(ap, int);
70021+ ulong1 = va_arg(ap, unsigned long);
70022+ cred = __task_cred(task);
70023+ pcred = __task_cred(task->real_parent);
70024+
70025+ 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));
70026+ }
70027+ break;
70028+ default:
70029+ gr_log_middle(audit, msg, ap);
70030+ }
70031+ va_end(ap);
70032+ // these don't need DEFAULTSECARGS printed on the end
70033+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
70034+ gr_log_end(audit, 0);
70035+ else
70036+ gr_log_end(audit, 1);
70037+ END_LOCKS(audit);
70038+}
70039diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
70040new file mode 100644
70041index 0000000..f536303
70042--- /dev/null
70043+++ b/grsecurity/grsec_mem.c
70044@@ -0,0 +1,40 @@
70045+#include <linux/kernel.h>
70046+#include <linux/sched.h>
70047+#include <linux/mm.h>
70048+#include <linux/mman.h>
70049+#include <linux/grinternal.h>
70050+
70051+void
70052+gr_handle_ioperm(void)
70053+{
70054+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
70055+ return;
70056+}
70057+
70058+void
70059+gr_handle_iopl(void)
70060+{
70061+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
70062+ return;
70063+}
70064+
70065+void
70066+gr_handle_mem_readwrite(u64 from, u64 to)
70067+{
70068+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
70069+ return;
70070+}
70071+
70072+void
70073+gr_handle_vm86(void)
70074+{
70075+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
70076+ return;
70077+}
70078+
70079+void
70080+gr_log_badprocpid(const char *entry)
70081+{
70082+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
70083+ return;
70084+}
70085diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
70086new file mode 100644
70087index 0000000..2131422
70088--- /dev/null
70089+++ b/grsecurity/grsec_mount.c
70090@@ -0,0 +1,62 @@
70091+#include <linux/kernel.h>
70092+#include <linux/sched.h>
70093+#include <linux/mount.h>
70094+#include <linux/grsecurity.h>
70095+#include <linux/grinternal.h>
70096+
70097+void
70098+gr_log_remount(const char *devname, const int retval)
70099+{
70100+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
70101+ if (grsec_enable_mount && (retval >= 0))
70102+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
70103+#endif
70104+ return;
70105+}
70106+
70107+void
70108+gr_log_unmount(const char *devname, const int retval)
70109+{
70110+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
70111+ if (grsec_enable_mount && (retval >= 0))
70112+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
70113+#endif
70114+ return;
70115+}
70116+
70117+void
70118+gr_log_mount(const char *from, const char *to, const int retval)
70119+{
70120+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
70121+ if (grsec_enable_mount && (retval >= 0))
70122+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
70123+#endif
70124+ return;
70125+}
70126+
70127+int
70128+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
70129+{
70130+#ifdef CONFIG_GRKERNSEC_ROFS
70131+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
70132+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
70133+ return -EPERM;
70134+ } else
70135+ return 0;
70136+#endif
70137+ return 0;
70138+}
70139+
70140+int
70141+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
70142+{
70143+#ifdef CONFIG_GRKERNSEC_ROFS
70144+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
70145+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
70146+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
70147+ return -EPERM;
70148+ } else
70149+ return 0;
70150+#endif
70151+ return 0;
70152+}
70153diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
70154new file mode 100644
70155index 0000000..6ee9d50
70156--- /dev/null
70157+++ b/grsecurity/grsec_pax.c
70158@@ -0,0 +1,45 @@
70159+#include <linux/kernel.h>
70160+#include <linux/sched.h>
70161+#include <linux/mm.h>
70162+#include <linux/file.h>
70163+#include <linux/grinternal.h>
70164+#include <linux/grsecurity.h>
70165+
70166+void
70167+gr_log_textrel(struct vm_area_struct * vma)
70168+{
70169+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70170+ if (grsec_enable_log_rwxmaps)
70171+ gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
70172+#endif
70173+ return;
70174+}
70175+
70176+void gr_log_ptgnustack(struct file *file)
70177+{
70178+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70179+ if (grsec_enable_log_rwxmaps)
70180+ gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
70181+#endif
70182+ return;
70183+}
70184+
70185+void
70186+gr_log_rwxmmap(struct file *file)
70187+{
70188+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70189+ if (grsec_enable_log_rwxmaps)
70190+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
70191+#endif
70192+ return;
70193+}
70194+
70195+void
70196+gr_log_rwxmprotect(struct vm_area_struct *vma)
70197+{
70198+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70199+ if (grsec_enable_log_rwxmaps)
70200+ gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
70201+#endif
70202+ return;
70203+}
70204diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
70205new file mode 100644
70206index 0000000..f7f29aa
70207--- /dev/null
70208+++ b/grsecurity/grsec_ptrace.c
70209@@ -0,0 +1,30 @@
70210+#include <linux/kernel.h>
70211+#include <linux/sched.h>
70212+#include <linux/grinternal.h>
70213+#include <linux/security.h>
70214+
70215+void
70216+gr_audit_ptrace(struct task_struct *task)
70217+{
70218+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
70219+ if (grsec_enable_audit_ptrace)
70220+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
70221+#endif
70222+ return;
70223+}
70224+
70225+int
70226+gr_ptrace_readexec(struct file *file, int unsafe_flags)
70227+{
70228+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
70229+ const struct dentry *dentry = file->f_path.dentry;
70230+ const struct vfsmount *mnt = file->f_path.mnt;
70231+
70232+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
70233+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
70234+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
70235+ return -EACCES;
70236+ }
70237+#endif
70238+ return 0;
70239+}
70240diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
70241new file mode 100644
70242index 0000000..4e29cc7
70243--- /dev/null
70244+++ b/grsecurity/grsec_sig.c
70245@@ -0,0 +1,246 @@
70246+#include <linux/kernel.h>
70247+#include <linux/sched.h>
70248+#include <linux/fs.h>
70249+#include <linux/delay.h>
70250+#include <linux/grsecurity.h>
70251+#include <linux/grinternal.h>
70252+#include <linux/hardirq.h>
70253+
70254+char *signames[] = {
70255+ [SIGSEGV] = "Segmentation fault",
70256+ [SIGILL] = "Illegal instruction",
70257+ [SIGABRT] = "Abort",
70258+ [SIGBUS] = "Invalid alignment/Bus error"
70259+};
70260+
70261+void
70262+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
70263+{
70264+#ifdef CONFIG_GRKERNSEC_SIGNAL
70265+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
70266+ (sig == SIGABRT) || (sig == SIGBUS))) {
70267+ if (task_pid_nr(t) == task_pid_nr(current)) {
70268+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
70269+ } else {
70270+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
70271+ }
70272+ }
70273+#endif
70274+ return;
70275+}
70276+
70277+int
70278+gr_handle_signal(const struct task_struct *p, const int sig)
70279+{
70280+#ifdef CONFIG_GRKERNSEC
70281+ /* ignore the 0 signal for protected task checks */
70282+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
70283+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
70284+ return -EPERM;
70285+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
70286+ return -EPERM;
70287+ }
70288+#endif
70289+ return 0;
70290+}
70291+
70292+#ifdef CONFIG_GRKERNSEC
70293+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
70294+
70295+int gr_fake_force_sig(int sig, struct task_struct *t)
70296+{
70297+ unsigned long int flags;
70298+ int ret, blocked, ignored;
70299+ struct k_sigaction *action;
70300+
70301+ spin_lock_irqsave(&t->sighand->siglock, flags);
70302+ action = &t->sighand->action[sig-1];
70303+ ignored = action->sa.sa_handler == SIG_IGN;
70304+ blocked = sigismember(&t->blocked, sig);
70305+ if (blocked || ignored) {
70306+ action->sa.sa_handler = SIG_DFL;
70307+ if (blocked) {
70308+ sigdelset(&t->blocked, sig);
70309+ recalc_sigpending_and_wake(t);
70310+ }
70311+ }
70312+ if (action->sa.sa_handler == SIG_DFL)
70313+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
70314+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
70315+
70316+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
70317+
70318+ return ret;
70319+}
70320+#endif
70321+
70322+#ifdef CONFIG_GRKERNSEC_BRUTE
70323+#define GR_USER_BAN_TIME (15 * 60)
70324+#define GR_DAEMON_BRUTE_TIME (30 * 60)
70325+
70326+static int __get_dumpable(unsigned long mm_flags)
70327+{
70328+ int ret;
70329+
70330+ ret = mm_flags & MMF_DUMPABLE_MASK;
70331+ return (ret >= 2) ? 2 : ret;
70332+}
70333+#endif
70334+
70335+void gr_handle_brute_attach(unsigned long mm_flags)
70336+{
70337+#ifdef CONFIG_GRKERNSEC_BRUTE
70338+ struct task_struct *p = current;
70339+ kuid_t uid = GLOBAL_ROOT_UID;
70340+ int daemon = 0;
70341+
70342+ if (!grsec_enable_brute)
70343+ return;
70344+
70345+ rcu_read_lock();
70346+ read_lock(&tasklist_lock);
70347+ read_lock(&grsec_exec_file_lock);
70348+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
70349+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
70350+ p->real_parent->brute = 1;
70351+ daemon = 1;
70352+ } else {
70353+ const struct cred *cred = __task_cred(p), *cred2;
70354+ struct task_struct *tsk, *tsk2;
70355+
70356+ if (!__get_dumpable(mm_flags) && gr_is_global_nonroot(cred->uid)) {
70357+ struct user_struct *user;
70358+
70359+ uid = cred->uid;
70360+
70361+ /* this is put upon execution past expiration */
70362+ user = find_user(uid);
70363+ if (user == NULL)
70364+ goto unlock;
70365+ user->suid_banned = 1;
70366+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
70367+ if (user->suid_ban_expires == ~0UL)
70368+ user->suid_ban_expires--;
70369+
70370+ /* only kill other threads of the same binary, from the same user */
70371+ do_each_thread(tsk2, tsk) {
70372+ cred2 = __task_cred(tsk);
70373+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
70374+ gr_fake_force_sig(SIGKILL, tsk);
70375+ } while_each_thread(tsk2, tsk);
70376+ }
70377+ }
70378+unlock:
70379+ read_unlock(&grsec_exec_file_lock);
70380+ read_unlock(&tasklist_lock);
70381+ rcu_read_unlock();
70382+
70383+ if (gr_is_global_nonroot(uid))
70384+ 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);
70385+ else if (daemon)
70386+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
70387+
70388+#endif
70389+ return;
70390+}
70391+
70392+void gr_handle_brute_check(void)
70393+{
70394+#ifdef CONFIG_GRKERNSEC_BRUTE
70395+ struct task_struct *p = current;
70396+
70397+ if (unlikely(p->brute)) {
70398+ if (!grsec_enable_brute)
70399+ p->brute = 0;
70400+ else if (time_before(get_seconds(), p->brute_expires))
70401+ msleep(30 * 1000);
70402+ }
70403+#endif
70404+ return;
70405+}
70406+
70407+void gr_handle_kernel_exploit(void)
70408+{
70409+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
70410+ const struct cred *cred;
70411+ struct task_struct *tsk, *tsk2;
70412+ struct user_struct *user;
70413+ kuid_t uid;
70414+
70415+ if (in_irq() || in_serving_softirq() || in_nmi())
70416+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
70417+
70418+ uid = current_uid();
70419+
70420+ if (gr_is_global_root(uid))
70421+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
70422+ else {
70423+ /* kill all the processes of this user, hold a reference
70424+ to their creds struct, and prevent them from creating
70425+ another process until system reset
70426+ */
70427+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
70428+ GR_GLOBAL_UID(uid));
70429+ /* we intentionally leak this ref */
70430+ user = get_uid(current->cred->user);
70431+ if (user)
70432+ user->kernel_banned = 1;
70433+
70434+ /* kill all processes of this user */
70435+ read_lock(&tasklist_lock);
70436+ do_each_thread(tsk2, tsk) {
70437+ cred = __task_cred(tsk);
70438+ if (uid_eq(cred->uid, uid))
70439+ gr_fake_force_sig(SIGKILL, tsk);
70440+ } while_each_thread(tsk2, tsk);
70441+ read_unlock(&tasklist_lock);
70442+ }
70443+#endif
70444+}
70445+
70446+#ifdef CONFIG_GRKERNSEC_BRUTE
70447+static bool suid_ban_expired(struct user_struct *user)
70448+{
70449+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
70450+ user->suid_banned = 0;
70451+ user->suid_ban_expires = 0;
70452+ free_uid(user);
70453+ return true;
70454+ }
70455+
70456+ return false;
70457+}
70458+#endif
70459+
70460+int gr_process_kernel_exec_ban(void)
70461+{
70462+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
70463+ if (unlikely(current->cred->user->kernel_banned))
70464+ return -EPERM;
70465+#endif
70466+ return 0;
70467+}
70468+
70469+int gr_process_kernel_setuid_ban(struct user_struct *user)
70470+{
70471+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
70472+ if (unlikely(user->kernel_banned))
70473+ gr_fake_force_sig(SIGKILL, current);
70474+#endif
70475+ return 0;
70476+}
70477+
70478+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
70479+{
70480+#ifdef CONFIG_GRKERNSEC_BRUTE
70481+ struct user_struct *user = current->cred->user;
70482+ if (unlikely(user->suid_banned)) {
70483+ if (suid_ban_expired(user))
70484+ return 0;
70485+ /* disallow execution of suid binaries only */
70486+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
70487+ return -EPERM;
70488+ }
70489+#endif
70490+ return 0;
70491+}
70492diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
70493new file mode 100644
70494index 0000000..4030d57
70495--- /dev/null
70496+++ b/grsecurity/grsec_sock.c
70497@@ -0,0 +1,244 @@
70498+#include <linux/kernel.h>
70499+#include <linux/module.h>
70500+#include <linux/sched.h>
70501+#include <linux/file.h>
70502+#include <linux/net.h>
70503+#include <linux/in.h>
70504+#include <linux/ip.h>
70505+#include <net/sock.h>
70506+#include <net/inet_sock.h>
70507+#include <linux/grsecurity.h>
70508+#include <linux/grinternal.h>
70509+#include <linux/gracl.h>
70510+
70511+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
70512+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
70513+
70514+EXPORT_SYMBOL(gr_search_udp_recvmsg);
70515+EXPORT_SYMBOL(gr_search_udp_sendmsg);
70516+
70517+#ifdef CONFIG_UNIX_MODULE
70518+EXPORT_SYMBOL(gr_acl_handle_unix);
70519+EXPORT_SYMBOL(gr_acl_handle_mknod);
70520+EXPORT_SYMBOL(gr_handle_chroot_unix);
70521+EXPORT_SYMBOL(gr_handle_create);
70522+#endif
70523+
70524+#ifdef CONFIG_GRKERNSEC
70525+#define gr_conn_table_size 32749
70526+struct conn_table_entry {
70527+ struct conn_table_entry *next;
70528+ struct signal_struct *sig;
70529+};
70530+
70531+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
70532+DEFINE_SPINLOCK(gr_conn_table_lock);
70533+
70534+extern const char * gr_socktype_to_name(unsigned char type);
70535+extern const char * gr_proto_to_name(unsigned char proto);
70536+extern const char * gr_sockfamily_to_name(unsigned char family);
70537+
70538+static __inline__ int
70539+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
70540+{
70541+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
70542+}
70543+
70544+static __inline__ int
70545+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
70546+ __u16 sport, __u16 dport)
70547+{
70548+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
70549+ sig->gr_sport == sport && sig->gr_dport == dport))
70550+ return 1;
70551+ else
70552+ return 0;
70553+}
70554+
70555+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
70556+{
70557+ struct conn_table_entry **match;
70558+ unsigned int index;
70559+
70560+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
70561+ sig->gr_sport, sig->gr_dport,
70562+ gr_conn_table_size);
70563+
70564+ newent->sig = sig;
70565+
70566+ match = &gr_conn_table[index];
70567+ newent->next = *match;
70568+ *match = newent;
70569+
70570+ return;
70571+}
70572+
70573+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
70574+{
70575+ struct conn_table_entry *match, *last = NULL;
70576+ unsigned int index;
70577+
70578+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
70579+ sig->gr_sport, sig->gr_dport,
70580+ gr_conn_table_size);
70581+
70582+ match = gr_conn_table[index];
70583+ while (match && !conn_match(match->sig,
70584+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
70585+ sig->gr_dport)) {
70586+ last = match;
70587+ match = match->next;
70588+ }
70589+
70590+ if (match) {
70591+ if (last)
70592+ last->next = match->next;
70593+ else
70594+ gr_conn_table[index] = NULL;
70595+ kfree(match);
70596+ }
70597+
70598+ return;
70599+}
70600+
70601+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
70602+ __u16 sport, __u16 dport)
70603+{
70604+ struct conn_table_entry *match;
70605+ unsigned int index;
70606+
70607+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
70608+
70609+ match = gr_conn_table[index];
70610+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
70611+ match = match->next;
70612+
70613+ if (match)
70614+ return match->sig;
70615+ else
70616+ return NULL;
70617+}
70618+
70619+#endif
70620+
70621+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
70622+{
70623+#ifdef CONFIG_GRKERNSEC
70624+ struct signal_struct *sig = task->signal;
70625+ struct conn_table_entry *newent;
70626+
70627+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
70628+ if (newent == NULL)
70629+ return;
70630+ /* no bh lock needed since we are called with bh disabled */
70631+ spin_lock(&gr_conn_table_lock);
70632+ gr_del_task_from_ip_table_nolock(sig);
70633+ sig->gr_saddr = inet->inet_rcv_saddr;
70634+ sig->gr_daddr = inet->inet_daddr;
70635+ sig->gr_sport = inet->inet_sport;
70636+ sig->gr_dport = inet->inet_dport;
70637+ gr_add_to_task_ip_table_nolock(sig, newent);
70638+ spin_unlock(&gr_conn_table_lock);
70639+#endif
70640+ return;
70641+}
70642+
70643+void gr_del_task_from_ip_table(struct task_struct *task)
70644+{
70645+#ifdef CONFIG_GRKERNSEC
70646+ spin_lock_bh(&gr_conn_table_lock);
70647+ gr_del_task_from_ip_table_nolock(task->signal);
70648+ spin_unlock_bh(&gr_conn_table_lock);
70649+#endif
70650+ return;
70651+}
70652+
70653+void
70654+gr_attach_curr_ip(const struct sock *sk)
70655+{
70656+#ifdef CONFIG_GRKERNSEC
70657+ struct signal_struct *p, *set;
70658+ const struct inet_sock *inet = inet_sk(sk);
70659+
70660+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
70661+ return;
70662+
70663+ set = current->signal;
70664+
70665+ spin_lock_bh(&gr_conn_table_lock);
70666+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
70667+ inet->inet_dport, inet->inet_sport);
70668+ if (unlikely(p != NULL)) {
70669+ set->curr_ip = p->curr_ip;
70670+ set->used_accept = 1;
70671+ gr_del_task_from_ip_table_nolock(p);
70672+ spin_unlock_bh(&gr_conn_table_lock);
70673+ return;
70674+ }
70675+ spin_unlock_bh(&gr_conn_table_lock);
70676+
70677+ set->curr_ip = inet->inet_daddr;
70678+ set->used_accept = 1;
70679+#endif
70680+ return;
70681+}
70682+
70683+int
70684+gr_handle_sock_all(const int family, const int type, const int protocol)
70685+{
70686+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
70687+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
70688+ (family != AF_UNIX)) {
70689+ if (family == AF_INET)
70690+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
70691+ else
70692+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
70693+ return -EACCES;
70694+ }
70695+#endif
70696+ return 0;
70697+}
70698+
70699+int
70700+gr_handle_sock_server(const struct sockaddr *sck)
70701+{
70702+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
70703+ if (grsec_enable_socket_server &&
70704+ in_group_p(grsec_socket_server_gid) &&
70705+ sck && (sck->sa_family != AF_UNIX) &&
70706+ (sck->sa_family != AF_LOCAL)) {
70707+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
70708+ return -EACCES;
70709+ }
70710+#endif
70711+ return 0;
70712+}
70713+
70714+int
70715+gr_handle_sock_server_other(const struct sock *sck)
70716+{
70717+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
70718+ if (grsec_enable_socket_server &&
70719+ in_group_p(grsec_socket_server_gid) &&
70720+ sck && (sck->sk_family != AF_UNIX) &&
70721+ (sck->sk_family != AF_LOCAL)) {
70722+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
70723+ return -EACCES;
70724+ }
70725+#endif
70726+ return 0;
70727+}
70728+
70729+int
70730+gr_handle_sock_client(const struct sockaddr *sck)
70731+{
70732+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
70733+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
70734+ sck && (sck->sa_family != AF_UNIX) &&
70735+ (sck->sa_family != AF_LOCAL)) {
70736+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
70737+ return -EACCES;
70738+ }
70739+#endif
70740+ return 0;
70741+}
70742diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
70743new file mode 100644
70744index 0000000..a147ae7
70745--- /dev/null
70746+++ b/grsecurity/grsec_sysctl.c
70747@@ -0,0 +1,470 @@
70748+#include <linux/kernel.h>
70749+#include <linux/sched.h>
70750+#include <linux/sysctl.h>
70751+#include <linux/grsecurity.h>
70752+#include <linux/grinternal.h>
70753+
70754+int
70755+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
70756+{
70757+#ifdef CONFIG_GRKERNSEC_SYSCTL
70758+ if (dirname == NULL || name == NULL)
70759+ return 0;
70760+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
70761+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
70762+ return -EACCES;
70763+ }
70764+#endif
70765+ return 0;
70766+}
70767+
70768+#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
70769+static int __maybe_unused __read_only one = 1;
70770+#endif
70771+
70772+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
70773+ defined(CONFIG_GRKERNSEC_DENYUSB)
70774+struct ctl_table grsecurity_table[] = {
70775+#ifdef CONFIG_GRKERNSEC_SYSCTL
70776+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
70777+#ifdef CONFIG_GRKERNSEC_IO
70778+ {
70779+ .procname = "disable_priv_io",
70780+ .data = &grsec_disable_privio,
70781+ .maxlen = sizeof(int),
70782+ .mode = 0600,
70783+ .proc_handler = &proc_dointvec,
70784+ },
70785+#endif
70786+#endif
70787+#ifdef CONFIG_GRKERNSEC_LINK
70788+ {
70789+ .procname = "linking_restrictions",
70790+ .data = &grsec_enable_link,
70791+ .maxlen = sizeof(int),
70792+ .mode = 0600,
70793+ .proc_handler = &proc_dointvec,
70794+ },
70795+#endif
70796+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
70797+ {
70798+ .procname = "enforce_symlinksifowner",
70799+ .data = &grsec_enable_symlinkown,
70800+ .maxlen = sizeof(int),
70801+ .mode = 0600,
70802+ .proc_handler = &proc_dointvec,
70803+ },
70804+ {
70805+ .procname = "symlinkown_gid",
70806+ .data = &grsec_symlinkown_gid,
70807+ .maxlen = sizeof(int),
70808+ .mode = 0600,
70809+ .proc_handler = &proc_dointvec,
70810+ },
70811+#endif
70812+#ifdef CONFIG_GRKERNSEC_BRUTE
70813+ {
70814+ .procname = "deter_bruteforce",
70815+ .data = &grsec_enable_brute,
70816+ .maxlen = sizeof(int),
70817+ .mode = 0600,
70818+ .proc_handler = &proc_dointvec,
70819+ },
70820+#endif
70821+#ifdef CONFIG_GRKERNSEC_FIFO
70822+ {
70823+ .procname = "fifo_restrictions",
70824+ .data = &grsec_enable_fifo,
70825+ .maxlen = sizeof(int),
70826+ .mode = 0600,
70827+ .proc_handler = &proc_dointvec,
70828+ },
70829+#endif
70830+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
70831+ {
70832+ .procname = "ptrace_readexec",
70833+ .data = &grsec_enable_ptrace_readexec,
70834+ .maxlen = sizeof(int),
70835+ .mode = 0600,
70836+ .proc_handler = &proc_dointvec,
70837+ },
70838+#endif
70839+#ifdef CONFIG_GRKERNSEC_SETXID
70840+ {
70841+ .procname = "consistent_setxid",
70842+ .data = &grsec_enable_setxid,
70843+ .maxlen = sizeof(int),
70844+ .mode = 0600,
70845+ .proc_handler = &proc_dointvec,
70846+ },
70847+#endif
70848+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
70849+ {
70850+ .procname = "ip_blackhole",
70851+ .data = &grsec_enable_blackhole,
70852+ .maxlen = sizeof(int),
70853+ .mode = 0600,
70854+ .proc_handler = &proc_dointvec,
70855+ },
70856+ {
70857+ .procname = "lastack_retries",
70858+ .data = &grsec_lastack_retries,
70859+ .maxlen = sizeof(int),
70860+ .mode = 0600,
70861+ .proc_handler = &proc_dointvec,
70862+ },
70863+#endif
70864+#ifdef CONFIG_GRKERNSEC_EXECLOG
70865+ {
70866+ .procname = "exec_logging",
70867+ .data = &grsec_enable_execlog,
70868+ .maxlen = sizeof(int),
70869+ .mode = 0600,
70870+ .proc_handler = &proc_dointvec,
70871+ },
70872+#endif
70873+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70874+ {
70875+ .procname = "rwxmap_logging",
70876+ .data = &grsec_enable_log_rwxmaps,
70877+ .maxlen = sizeof(int),
70878+ .mode = 0600,
70879+ .proc_handler = &proc_dointvec,
70880+ },
70881+#endif
70882+#ifdef CONFIG_GRKERNSEC_SIGNAL
70883+ {
70884+ .procname = "signal_logging",
70885+ .data = &grsec_enable_signal,
70886+ .maxlen = sizeof(int),
70887+ .mode = 0600,
70888+ .proc_handler = &proc_dointvec,
70889+ },
70890+#endif
70891+#ifdef CONFIG_GRKERNSEC_FORKFAIL
70892+ {
70893+ .procname = "forkfail_logging",
70894+ .data = &grsec_enable_forkfail,
70895+ .maxlen = sizeof(int),
70896+ .mode = 0600,
70897+ .proc_handler = &proc_dointvec,
70898+ },
70899+#endif
70900+#ifdef CONFIG_GRKERNSEC_TIME
70901+ {
70902+ .procname = "timechange_logging",
70903+ .data = &grsec_enable_time,
70904+ .maxlen = sizeof(int),
70905+ .mode = 0600,
70906+ .proc_handler = &proc_dointvec,
70907+ },
70908+#endif
70909+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
70910+ {
70911+ .procname = "chroot_deny_shmat",
70912+ .data = &grsec_enable_chroot_shmat,
70913+ .maxlen = sizeof(int),
70914+ .mode = 0600,
70915+ .proc_handler = &proc_dointvec,
70916+ },
70917+#endif
70918+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
70919+ {
70920+ .procname = "chroot_deny_unix",
70921+ .data = &grsec_enable_chroot_unix,
70922+ .maxlen = sizeof(int),
70923+ .mode = 0600,
70924+ .proc_handler = &proc_dointvec,
70925+ },
70926+#endif
70927+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
70928+ {
70929+ .procname = "chroot_deny_mount",
70930+ .data = &grsec_enable_chroot_mount,
70931+ .maxlen = sizeof(int),
70932+ .mode = 0600,
70933+ .proc_handler = &proc_dointvec,
70934+ },
70935+#endif
70936+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
70937+ {
70938+ .procname = "chroot_deny_fchdir",
70939+ .data = &grsec_enable_chroot_fchdir,
70940+ .maxlen = sizeof(int),
70941+ .mode = 0600,
70942+ .proc_handler = &proc_dointvec,
70943+ },
70944+#endif
70945+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
70946+ {
70947+ .procname = "chroot_deny_chroot",
70948+ .data = &grsec_enable_chroot_double,
70949+ .maxlen = sizeof(int),
70950+ .mode = 0600,
70951+ .proc_handler = &proc_dointvec,
70952+ },
70953+#endif
70954+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
70955+ {
70956+ .procname = "chroot_deny_pivot",
70957+ .data = &grsec_enable_chroot_pivot,
70958+ .maxlen = sizeof(int),
70959+ .mode = 0600,
70960+ .proc_handler = &proc_dointvec,
70961+ },
70962+#endif
70963+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
70964+ {
70965+ .procname = "chroot_enforce_chdir",
70966+ .data = &grsec_enable_chroot_chdir,
70967+ .maxlen = sizeof(int),
70968+ .mode = 0600,
70969+ .proc_handler = &proc_dointvec,
70970+ },
70971+#endif
70972+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
70973+ {
70974+ .procname = "chroot_deny_chmod",
70975+ .data = &grsec_enable_chroot_chmod,
70976+ .maxlen = sizeof(int),
70977+ .mode = 0600,
70978+ .proc_handler = &proc_dointvec,
70979+ },
70980+#endif
70981+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
70982+ {
70983+ .procname = "chroot_deny_mknod",
70984+ .data = &grsec_enable_chroot_mknod,
70985+ .maxlen = sizeof(int),
70986+ .mode = 0600,
70987+ .proc_handler = &proc_dointvec,
70988+ },
70989+#endif
70990+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
70991+ {
70992+ .procname = "chroot_restrict_nice",
70993+ .data = &grsec_enable_chroot_nice,
70994+ .maxlen = sizeof(int),
70995+ .mode = 0600,
70996+ .proc_handler = &proc_dointvec,
70997+ },
70998+#endif
70999+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
71000+ {
71001+ .procname = "chroot_execlog",
71002+ .data = &grsec_enable_chroot_execlog,
71003+ .maxlen = sizeof(int),
71004+ .mode = 0600,
71005+ .proc_handler = &proc_dointvec,
71006+ },
71007+#endif
71008+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
71009+ {
71010+ .procname = "chroot_caps",
71011+ .data = &grsec_enable_chroot_caps,
71012+ .maxlen = sizeof(int),
71013+ .mode = 0600,
71014+ .proc_handler = &proc_dointvec,
71015+ },
71016+#endif
71017+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
71018+ {
71019+ .procname = "chroot_deny_sysctl",
71020+ .data = &grsec_enable_chroot_sysctl,
71021+ .maxlen = sizeof(int),
71022+ .mode = 0600,
71023+ .proc_handler = &proc_dointvec,
71024+ },
71025+#endif
71026+#ifdef CONFIG_GRKERNSEC_TPE
71027+ {
71028+ .procname = "tpe",
71029+ .data = &grsec_enable_tpe,
71030+ .maxlen = sizeof(int),
71031+ .mode = 0600,
71032+ .proc_handler = &proc_dointvec,
71033+ },
71034+ {
71035+ .procname = "tpe_gid",
71036+ .data = &grsec_tpe_gid,
71037+ .maxlen = sizeof(int),
71038+ .mode = 0600,
71039+ .proc_handler = &proc_dointvec,
71040+ },
71041+#endif
71042+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
71043+ {
71044+ .procname = "tpe_invert",
71045+ .data = &grsec_enable_tpe_invert,
71046+ .maxlen = sizeof(int),
71047+ .mode = 0600,
71048+ .proc_handler = &proc_dointvec,
71049+ },
71050+#endif
71051+#ifdef CONFIG_GRKERNSEC_TPE_ALL
71052+ {
71053+ .procname = "tpe_restrict_all",
71054+ .data = &grsec_enable_tpe_all,
71055+ .maxlen = sizeof(int),
71056+ .mode = 0600,
71057+ .proc_handler = &proc_dointvec,
71058+ },
71059+#endif
71060+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
71061+ {
71062+ .procname = "socket_all",
71063+ .data = &grsec_enable_socket_all,
71064+ .maxlen = sizeof(int),
71065+ .mode = 0600,
71066+ .proc_handler = &proc_dointvec,
71067+ },
71068+ {
71069+ .procname = "socket_all_gid",
71070+ .data = &grsec_socket_all_gid,
71071+ .maxlen = sizeof(int),
71072+ .mode = 0600,
71073+ .proc_handler = &proc_dointvec,
71074+ },
71075+#endif
71076+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
71077+ {
71078+ .procname = "socket_client",
71079+ .data = &grsec_enable_socket_client,
71080+ .maxlen = sizeof(int),
71081+ .mode = 0600,
71082+ .proc_handler = &proc_dointvec,
71083+ },
71084+ {
71085+ .procname = "socket_client_gid",
71086+ .data = &grsec_socket_client_gid,
71087+ .maxlen = sizeof(int),
71088+ .mode = 0600,
71089+ .proc_handler = &proc_dointvec,
71090+ },
71091+#endif
71092+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
71093+ {
71094+ .procname = "socket_server",
71095+ .data = &grsec_enable_socket_server,
71096+ .maxlen = sizeof(int),
71097+ .mode = 0600,
71098+ .proc_handler = &proc_dointvec,
71099+ },
71100+ {
71101+ .procname = "socket_server_gid",
71102+ .data = &grsec_socket_server_gid,
71103+ .maxlen = sizeof(int),
71104+ .mode = 0600,
71105+ .proc_handler = &proc_dointvec,
71106+ },
71107+#endif
71108+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
71109+ {
71110+ .procname = "audit_group",
71111+ .data = &grsec_enable_group,
71112+ .maxlen = sizeof(int),
71113+ .mode = 0600,
71114+ .proc_handler = &proc_dointvec,
71115+ },
71116+ {
71117+ .procname = "audit_gid",
71118+ .data = &grsec_audit_gid,
71119+ .maxlen = sizeof(int),
71120+ .mode = 0600,
71121+ .proc_handler = &proc_dointvec,
71122+ },
71123+#endif
71124+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
71125+ {
71126+ .procname = "audit_chdir",
71127+ .data = &grsec_enable_chdir,
71128+ .maxlen = sizeof(int),
71129+ .mode = 0600,
71130+ .proc_handler = &proc_dointvec,
71131+ },
71132+#endif
71133+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
71134+ {
71135+ .procname = "audit_mount",
71136+ .data = &grsec_enable_mount,
71137+ .maxlen = sizeof(int),
71138+ .mode = 0600,
71139+ .proc_handler = &proc_dointvec,
71140+ },
71141+#endif
71142+#ifdef CONFIG_GRKERNSEC_DMESG
71143+ {
71144+ .procname = "dmesg",
71145+ .data = &grsec_enable_dmesg,
71146+ .maxlen = sizeof(int),
71147+ .mode = 0600,
71148+ .proc_handler = &proc_dointvec,
71149+ },
71150+#endif
71151+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
71152+ {
71153+ .procname = "chroot_findtask",
71154+ .data = &grsec_enable_chroot_findtask,
71155+ .maxlen = sizeof(int),
71156+ .mode = 0600,
71157+ .proc_handler = &proc_dointvec,
71158+ },
71159+#endif
71160+#ifdef CONFIG_GRKERNSEC_RESLOG
71161+ {
71162+ .procname = "resource_logging",
71163+ .data = &grsec_resource_logging,
71164+ .maxlen = sizeof(int),
71165+ .mode = 0600,
71166+ .proc_handler = &proc_dointvec,
71167+ },
71168+#endif
71169+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
71170+ {
71171+ .procname = "audit_ptrace",
71172+ .data = &grsec_enable_audit_ptrace,
71173+ .maxlen = sizeof(int),
71174+ .mode = 0600,
71175+ .proc_handler = &proc_dointvec,
71176+ },
71177+#endif
71178+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
71179+ {
71180+ .procname = "harden_ptrace",
71181+ .data = &grsec_enable_harden_ptrace,
71182+ .maxlen = sizeof(int),
71183+ .mode = 0600,
71184+ .proc_handler = &proc_dointvec,
71185+ },
71186+#endif
71187+ {
71188+ .procname = "grsec_lock",
71189+ .data = &grsec_lock,
71190+ .maxlen = sizeof(int),
71191+ .mode = 0600,
71192+ .proc_handler = &proc_dointvec,
71193+ },
71194+#endif
71195+#ifdef CONFIG_GRKERNSEC_ROFS
71196+ {
71197+ .procname = "romount_protect",
71198+ .data = &grsec_enable_rofs,
71199+ .maxlen = sizeof(int),
71200+ .mode = 0600,
71201+ .proc_handler = &proc_dointvec_minmax,
71202+ .extra1 = &one,
71203+ .extra2 = &one,
71204+ },
71205+#endif
71206+#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
71207+ {
71208+ .procname = "deny_new_usb",
71209+ .data = &grsec_deny_new_usb,
71210+ .maxlen = sizeof(int),
71211+ .mode = 0600,
71212+ .proc_handler = &proc_dointvec,
71213+ },
71214+#endif
71215+ { }
71216+};
71217+#endif
71218diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
71219new file mode 100644
71220index 0000000..0dc13c3
71221--- /dev/null
71222+++ b/grsecurity/grsec_time.c
71223@@ -0,0 +1,16 @@
71224+#include <linux/kernel.h>
71225+#include <linux/sched.h>
71226+#include <linux/grinternal.h>
71227+#include <linux/module.h>
71228+
71229+void
71230+gr_log_timechange(void)
71231+{
71232+#ifdef CONFIG_GRKERNSEC_TIME
71233+ if (grsec_enable_time)
71234+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
71235+#endif
71236+ return;
71237+}
71238+
71239+EXPORT_SYMBOL(gr_log_timechange);
71240diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
71241new file mode 100644
71242index 0000000..ee57dcf
71243--- /dev/null
71244+++ b/grsecurity/grsec_tpe.c
71245@@ -0,0 +1,73 @@
71246+#include <linux/kernel.h>
71247+#include <linux/sched.h>
71248+#include <linux/file.h>
71249+#include <linux/fs.h>
71250+#include <linux/grinternal.h>
71251+
71252+extern int gr_acl_tpe_check(void);
71253+
71254+int
71255+gr_tpe_allow(const struct file *file)
71256+{
71257+#ifdef CONFIG_GRKERNSEC
71258+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
71259+ const struct cred *cred = current_cred();
71260+ char *msg = NULL;
71261+ char *msg2 = NULL;
71262+
71263+ // never restrict root
71264+ if (gr_is_global_root(cred->uid))
71265+ return 1;
71266+
71267+ if (grsec_enable_tpe) {
71268+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
71269+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
71270+ msg = "not being in trusted group";
71271+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
71272+ msg = "being in untrusted group";
71273+#else
71274+ if (in_group_p(grsec_tpe_gid))
71275+ msg = "being in untrusted group";
71276+#endif
71277+ }
71278+ if (!msg && gr_acl_tpe_check())
71279+ msg = "being in untrusted role";
71280+
71281+ // not in any affected group/role
71282+ if (!msg)
71283+ goto next_check;
71284+
71285+ if (gr_is_global_nonroot(inode->i_uid))
71286+ msg2 = "file in non-root-owned directory";
71287+ else if (inode->i_mode & S_IWOTH)
71288+ msg2 = "file in world-writable directory";
71289+ else if (inode->i_mode & S_IWGRP)
71290+ msg2 = "file in group-writable directory";
71291+
71292+ if (msg && msg2) {
71293+ char fullmsg[70] = {0};
71294+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
71295+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
71296+ return 0;
71297+ }
71298+ msg = NULL;
71299+next_check:
71300+#ifdef CONFIG_GRKERNSEC_TPE_ALL
71301+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
71302+ return 1;
71303+
71304+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
71305+ msg = "directory not owned by user";
71306+ else if (inode->i_mode & S_IWOTH)
71307+ msg = "file in world-writable directory";
71308+ else if (inode->i_mode & S_IWGRP)
71309+ msg = "file in group-writable directory";
71310+
71311+ if (msg) {
71312+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
71313+ return 0;
71314+ }
71315+#endif
71316+#endif
71317+ return 1;
71318+}
71319diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
71320new file mode 100644
71321index 0000000..ae02d8e
71322--- /dev/null
71323+++ b/grsecurity/grsec_usb.c
71324@@ -0,0 +1,15 @@
71325+#include <linux/kernel.h>
71326+#include <linux/grinternal.h>
71327+#include <linux/module.h>
71328+
71329+int gr_handle_new_usb(void)
71330+{
71331+#ifdef CONFIG_GRKERNSEC_DENYUSB
71332+ if (grsec_deny_new_usb) {
71333+ printk(KERN_ALERT "grsec: denied insert of new USB device\n");
71334+ return 1;
71335+ }
71336+#endif
71337+ return 0;
71338+}
71339+EXPORT_SYMBOL_GPL(gr_handle_new_usb);
71340diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
71341new file mode 100644
71342index 0000000..9f7b1ac
71343--- /dev/null
71344+++ b/grsecurity/grsum.c
71345@@ -0,0 +1,61 @@
71346+#include <linux/err.h>
71347+#include <linux/kernel.h>
71348+#include <linux/sched.h>
71349+#include <linux/mm.h>
71350+#include <linux/scatterlist.h>
71351+#include <linux/crypto.h>
71352+#include <linux/gracl.h>
71353+
71354+
71355+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
71356+#error "crypto and sha256 must be built into the kernel"
71357+#endif
71358+
71359+int
71360+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
71361+{
71362+ char *p;
71363+ struct crypto_hash *tfm;
71364+ struct hash_desc desc;
71365+ struct scatterlist sg;
71366+ unsigned char temp_sum[GR_SHA_LEN];
71367+ volatile int retval = 0;
71368+ volatile int dummy = 0;
71369+ unsigned int i;
71370+
71371+ sg_init_table(&sg, 1);
71372+
71373+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
71374+ if (IS_ERR(tfm)) {
71375+ /* should never happen, since sha256 should be built in */
71376+ return 1;
71377+ }
71378+
71379+ desc.tfm = tfm;
71380+ desc.flags = 0;
71381+
71382+ crypto_hash_init(&desc);
71383+
71384+ p = salt;
71385+ sg_set_buf(&sg, p, GR_SALT_LEN);
71386+ crypto_hash_update(&desc, &sg, sg.length);
71387+
71388+ p = entry->pw;
71389+ sg_set_buf(&sg, p, strlen(p));
71390+
71391+ crypto_hash_update(&desc, &sg, sg.length);
71392+
71393+ crypto_hash_final(&desc, temp_sum);
71394+
71395+ memset(entry->pw, 0, GR_PW_LEN);
71396+
71397+ for (i = 0; i < GR_SHA_LEN; i++)
71398+ if (sum[i] != temp_sum[i])
71399+ retval = 1;
71400+ else
71401+ dummy = 1; // waste a cycle
71402+
71403+ crypto_free_hash(tfm);
71404+
71405+ return retval;
71406+}
71407diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
71408index 77ff547..181834f 100644
71409--- a/include/asm-generic/4level-fixup.h
71410+++ b/include/asm-generic/4level-fixup.h
71411@@ -13,8 +13,10 @@
71412 #define pmd_alloc(mm, pud, address) \
71413 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
71414 NULL: pmd_offset(pud, address))
71415+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
71416
71417 #define pud_alloc(mm, pgd, address) (pgd)
71418+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
71419 #define pud_offset(pgd, start) (pgd)
71420 #define pud_none(pud) 0
71421 #define pud_bad(pud) 0
71422diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
71423index b7babf0..04ad282 100644
71424--- a/include/asm-generic/atomic-long.h
71425+++ b/include/asm-generic/atomic-long.h
71426@@ -22,6 +22,12 @@
71427
71428 typedef atomic64_t atomic_long_t;
71429
71430+#ifdef CONFIG_PAX_REFCOUNT
71431+typedef atomic64_unchecked_t atomic_long_unchecked_t;
71432+#else
71433+typedef atomic64_t atomic_long_unchecked_t;
71434+#endif
71435+
71436 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
71437
71438 static inline long atomic_long_read(atomic_long_t *l)
71439@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
71440 return (long)atomic64_read(v);
71441 }
71442
71443+#ifdef CONFIG_PAX_REFCOUNT
71444+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
71445+{
71446+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71447+
71448+ return (long)atomic64_read_unchecked(v);
71449+}
71450+#endif
71451+
71452 static inline void atomic_long_set(atomic_long_t *l, long i)
71453 {
71454 atomic64_t *v = (atomic64_t *)l;
71455@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
71456 atomic64_set(v, i);
71457 }
71458
71459+#ifdef CONFIG_PAX_REFCOUNT
71460+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
71461+{
71462+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71463+
71464+ atomic64_set_unchecked(v, i);
71465+}
71466+#endif
71467+
71468 static inline void atomic_long_inc(atomic_long_t *l)
71469 {
71470 atomic64_t *v = (atomic64_t *)l;
71471@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
71472 atomic64_inc(v);
71473 }
71474
71475+#ifdef CONFIG_PAX_REFCOUNT
71476+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
71477+{
71478+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71479+
71480+ atomic64_inc_unchecked(v);
71481+}
71482+#endif
71483+
71484 static inline void atomic_long_dec(atomic_long_t *l)
71485 {
71486 atomic64_t *v = (atomic64_t *)l;
71487@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
71488 atomic64_dec(v);
71489 }
71490
71491+#ifdef CONFIG_PAX_REFCOUNT
71492+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
71493+{
71494+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71495+
71496+ atomic64_dec_unchecked(v);
71497+}
71498+#endif
71499+
71500 static inline void atomic_long_add(long i, atomic_long_t *l)
71501 {
71502 atomic64_t *v = (atomic64_t *)l;
71503@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
71504 atomic64_add(i, v);
71505 }
71506
71507+#ifdef CONFIG_PAX_REFCOUNT
71508+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
71509+{
71510+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71511+
71512+ atomic64_add_unchecked(i, v);
71513+}
71514+#endif
71515+
71516 static inline void atomic_long_sub(long i, atomic_long_t *l)
71517 {
71518 atomic64_t *v = (atomic64_t *)l;
71519@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
71520 atomic64_sub(i, v);
71521 }
71522
71523+#ifdef CONFIG_PAX_REFCOUNT
71524+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
71525+{
71526+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71527+
71528+ atomic64_sub_unchecked(i, v);
71529+}
71530+#endif
71531+
71532 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
71533 {
71534 atomic64_t *v = (atomic64_t *)l;
71535@@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
71536 return (long)atomic64_add_return(i, v);
71537 }
71538
71539+#ifdef CONFIG_PAX_REFCOUNT
71540+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
71541+{
71542+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71543+
71544+ return (long)atomic64_add_return_unchecked(i, v);
71545+}
71546+#endif
71547+
71548 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
71549 {
71550 atomic64_t *v = (atomic64_t *)l;
71551@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
71552 return (long)atomic64_inc_return(v);
71553 }
71554
71555+#ifdef CONFIG_PAX_REFCOUNT
71556+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
71557+{
71558+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71559+
71560+ return (long)atomic64_inc_return_unchecked(v);
71561+}
71562+#endif
71563+
71564 static inline long atomic_long_dec_return(atomic_long_t *l)
71565 {
71566 atomic64_t *v = (atomic64_t *)l;
71567@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
71568
71569 typedef atomic_t atomic_long_t;
71570
71571+#ifdef CONFIG_PAX_REFCOUNT
71572+typedef atomic_unchecked_t atomic_long_unchecked_t;
71573+#else
71574+typedef atomic_t atomic_long_unchecked_t;
71575+#endif
71576+
71577 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
71578 static inline long atomic_long_read(atomic_long_t *l)
71579 {
71580@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
71581 return (long)atomic_read(v);
71582 }
71583
71584+#ifdef CONFIG_PAX_REFCOUNT
71585+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
71586+{
71587+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71588+
71589+ return (long)atomic_read_unchecked(v);
71590+}
71591+#endif
71592+
71593 static inline void atomic_long_set(atomic_long_t *l, long i)
71594 {
71595 atomic_t *v = (atomic_t *)l;
71596@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
71597 atomic_set(v, i);
71598 }
71599
71600+#ifdef CONFIG_PAX_REFCOUNT
71601+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
71602+{
71603+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71604+
71605+ atomic_set_unchecked(v, i);
71606+}
71607+#endif
71608+
71609 static inline void atomic_long_inc(atomic_long_t *l)
71610 {
71611 atomic_t *v = (atomic_t *)l;
71612@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
71613 atomic_inc(v);
71614 }
71615
71616+#ifdef CONFIG_PAX_REFCOUNT
71617+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
71618+{
71619+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71620+
71621+ atomic_inc_unchecked(v);
71622+}
71623+#endif
71624+
71625 static inline void atomic_long_dec(atomic_long_t *l)
71626 {
71627 atomic_t *v = (atomic_t *)l;
71628@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
71629 atomic_dec(v);
71630 }
71631
71632+#ifdef CONFIG_PAX_REFCOUNT
71633+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
71634+{
71635+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71636+
71637+ atomic_dec_unchecked(v);
71638+}
71639+#endif
71640+
71641 static inline void atomic_long_add(long i, atomic_long_t *l)
71642 {
71643 atomic_t *v = (atomic_t *)l;
71644@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
71645 atomic_add(i, v);
71646 }
71647
71648+#ifdef CONFIG_PAX_REFCOUNT
71649+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
71650+{
71651+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71652+
71653+ atomic_add_unchecked(i, v);
71654+}
71655+#endif
71656+
71657 static inline void atomic_long_sub(long i, atomic_long_t *l)
71658 {
71659 atomic_t *v = (atomic_t *)l;
71660@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
71661 atomic_sub(i, v);
71662 }
71663
71664+#ifdef CONFIG_PAX_REFCOUNT
71665+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
71666+{
71667+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71668+
71669+ atomic_sub_unchecked(i, v);
71670+}
71671+#endif
71672+
71673 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
71674 {
71675 atomic_t *v = (atomic_t *)l;
71676@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
71677 return (long)atomic_add_return(i, v);
71678 }
71679
71680+#ifdef CONFIG_PAX_REFCOUNT
71681+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
71682+{
71683+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71684+
71685+ return (long)atomic_add_return_unchecked(i, v);
71686+}
71687+
71688+#endif
71689+
71690 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
71691 {
71692 atomic_t *v = (atomic_t *)l;
71693@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
71694 return (long)atomic_inc_return(v);
71695 }
71696
71697+#ifdef CONFIG_PAX_REFCOUNT
71698+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
71699+{
71700+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71701+
71702+ return (long)atomic_inc_return_unchecked(v);
71703+}
71704+#endif
71705+
71706 static inline long atomic_long_dec_return(atomic_long_t *l)
71707 {
71708 atomic_t *v = (atomic_t *)l;
71709@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
71710
71711 #endif /* BITS_PER_LONG == 64 */
71712
71713+#ifdef CONFIG_PAX_REFCOUNT
71714+static inline void pax_refcount_needs_these_functions(void)
71715+{
71716+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
71717+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
71718+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
71719+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
71720+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
71721+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
71722+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
71723+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
71724+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
71725+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
71726+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
71727+#ifdef CONFIG_X86
71728+ atomic_clear_mask_unchecked(0, NULL);
71729+ atomic_set_mask_unchecked(0, NULL);
71730+#endif
71731+
71732+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
71733+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
71734+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
71735+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
71736+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
71737+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
71738+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
71739+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
71740+}
71741+#else
71742+#define atomic_read_unchecked(v) atomic_read(v)
71743+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
71744+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
71745+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
71746+#define atomic_inc_unchecked(v) atomic_inc(v)
71747+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
71748+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
71749+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
71750+#define atomic_dec_unchecked(v) atomic_dec(v)
71751+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
71752+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
71753+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
71754+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
71755+
71756+#define atomic_long_read_unchecked(v) atomic_long_read(v)
71757+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
71758+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
71759+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
71760+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
71761+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
71762+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
71763+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
71764+#endif
71765+
71766 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
71767diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
71768index 33bd2de..f31bff97 100644
71769--- a/include/asm-generic/atomic.h
71770+++ b/include/asm-generic/atomic.h
71771@@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
71772 * Atomically clears the bits set in @mask from @v
71773 */
71774 #ifndef atomic_clear_mask
71775-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
71776+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
71777 {
71778 unsigned long flags;
71779
71780diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
71781index b18ce4f..2ee2843 100644
71782--- a/include/asm-generic/atomic64.h
71783+++ b/include/asm-generic/atomic64.h
71784@@ -16,6 +16,8 @@ typedef struct {
71785 long long counter;
71786 } atomic64_t;
71787
71788+typedef atomic64_t atomic64_unchecked_t;
71789+
71790 #define ATOMIC64_INIT(i) { (i) }
71791
71792 extern long long atomic64_read(const atomic64_t *v);
71793@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
71794 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
71795 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
71796
71797+#define atomic64_read_unchecked(v) atomic64_read(v)
71798+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
71799+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
71800+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
71801+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
71802+#define atomic64_inc_unchecked(v) atomic64_inc(v)
71803+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
71804+#define atomic64_dec_unchecked(v) atomic64_dec(v)
71805+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
71806+
71807 #endif /* _ASM_GENERIC_ATOMIC64_H */
71808diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
71809index 1bfcfe5..e04c5c9 100644
71810--- a/include/asm-generic/cache.h
71811+++ b/include/asm-generic/cache.h
71812@@ -6,7 +6,7 @@
71813 * cache lines need to provide their own cache.h.
71814 */
71815
71816-#define L1_CACHE_SHIFT 5
71817-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
71818+#define L1_CACHE_SHIFT 5UL
71819+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
71820
71821 #endif /* __ASM_GENERIC_CACHE_H */
71822diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
71823index 0d68a1e..b74a761 100644
71824--- a/include/asm-generic/emergency-restart.h
71825+++ b/include/asm-generic/emergency-restart.h
71826@@ -1,7 +1,7 @@
71827 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
71828 #define _ASM_GENERIC_EMERGENCY_RESTART_H
71829
71830-static inline void machine_emergency_restart(void)
71831+static inline __noreturn void machine_emergency_restart(void)
71832 {
71833 machine_restart(NULL);
71834 }
71835diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
71836index 90f99c7..00ce236 100644
71837--- a/include/asm-generic/kmap_types.h
71838+++ b/include/asm-generic/kmap_types.h
71839@@ -2,9 +2,9 @@
71840 #define _ASM_GENERIC_KMAP_TYPES_H
71841
71842 #ifdef __WITH_KM_FENCE
71843-# define KM_TYPE_NR 41
71844+# define KM_TYPE_NR 42
71845 #else
71846-# define KM_TYPE_NR 20
71847+# define KM_TYPE_NR 21
71848 #endif
71849
71850 #endif
71851diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
71852index 9ceb03b..62b0b8f 100644
71853--- a/include/asm-generic/local.h
71854+++ b/include/asm-generic/local.h
71855@@ -23,24 +23,37 @@ typedef struct
71856 atomic_long_t a;
71857 } local_t;
71858
71859+typedef struct {
71860+ atomic_long_unchecked_t a;
71861+} local_unchecked_t;
71862+
71863 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
71864
71865 #define local_read(l) atomic_long_read(&(l)->a)
71866+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
71867 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
71868+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
71869 #define local_inc(l) atomic_long_inc(&(l)->a)
71870+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
71871 #define local_dec(l) atomic_long_dec(&(l)->a)
71872+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
71873 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
71874+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
71875 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
71876+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
71877
71878 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
71879 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
71880 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
71881 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
71882 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
71883+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
71884 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
71885 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
71886+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
71887
71888 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
71889+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
71890 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
71891 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
71892 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
71893diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
71894index 725612b..9cc513a 100644
71895--- a/include/asm-generic/pgtable-nopmd.h
71896+++ b/include/asm-generic/pgtable-nopmd.h
71897@@ -1,14 +1,19 @@
71898 #ifndef _PGTABLE_NOPMD_H
71899 #define _PGTABLE_NOPMD_H
71900
71901-#ifndef __ASSEMBLY__
71902-
71903 #include <asm-generic/pgtable-nopud.h>
71904
71905-struct mm_struct;
71906-
71907 #define __PAGETABLE_PMD_FOLDED
71908
71909+#define PMD_SHIFT PUD_SHIFT
71910+#define PTRS_PER_PMD 1
71911+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
71912+#define PMD_MASK (~(PMD_SIZE-1))
71913+
71914+#ifndef __ASSEMBLY__
71915+
71916+struct mm_struct;
71917+
71918 /*
71919 * Having the pmd type consist of a pud gets the size right, and allows
71920 * us to conceptually access the pud entry that this pmd is folded into
71921@@ -16,11 +21,6 @@ struct mm_struct;
71922 */
71923 typedef struct { pud_t pud; } pmd_t;
71924
71925-#define PMD_SHIFT PUD_SHIFT
71926-#define PTRS_PER_PMD 1
71927-#define PMD_SIZE (1UL << PMD_SHIFT)
71928-#define PMD_MASK (~(PMD_SIZE-1))
71929-
71930 /*
71931 * The "pud_xxx()" functions here are trivial for a folded two-level
71932 * setup: the pmd is never bad, and a pmd always exists (as it's folded
71933diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
71934index 810431d..0ec4804f 100644
71935--- a/include/asm-generic/pgtable-nopud.h
71936+++ b/include/asm-generic/pgtable-nopud.h
71937@@ -1,10 +1,15 @@
71938 #ifndef _PGTABLE_NOPUD_H
71939 #define _PGTABLE_NOPUD_H
71940
71941-#ifndef __ASSEMBLY__
71942-
71943 #define __PAGETABLE_PUD_FOLDED
71944
71945+#define PUD_SHIFT PGDIR_SHIFT
71946+#define PTRS_PER_PUD 1
71947+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
71948+#define PUD_MASK (~(PUD_SIZE-1))
71949+
71950+#ifndef __ASSEMBLY__
71951+
71952 /*
71953 * Having the pud type consist of a pgd gets the size right, and allows
71954 * us to conceptually access the pgd entry that this pud is folded into
71955@@ -12,11 +17,6 @@
71956 */
71957 typedef struct { pgd_t pgd; } pud_t;
71958
71959-#define PUD_SHIFT PGDIR_SHIFT
71960-#define PTRS_PER_PUD 1
71961-#define PUD_SIZE (1UL << PUD_SHIFT)
71962-#define PUD_MASK (~(PUD_SIZE-1))
71963-
71964 /*
71965 * The "pgd_xxx()" functions here are trivial for a folded two-level
71966 * setup: the pud is never bad, and a pud always exists (as it's folded
71967@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
71968 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
71969
71970 #define pgd_populate(mm, pgd, pud) do { } while (0)
71971+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
71972 /*
71973 * (puds are folded into pgds so this doesn't get actually called,
71974 * but the define is needed for a generic inline function.)
71975diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
71976index 0807ddf..cd67747 100644
71977--- a/include/asm-generic/pgtable.h
71978+++ b/include/asm-generic/pgtable.h
71979@@ -741,6 +741,22 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
71980 }
71981 #endif /* CONFIG_NUMA_BALANCING */
71982
71983+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
71984+#ifdef CONFIG_PAX_KERNEXEC
71985+#error KERNEXEC requires pax_open_kernel
71986+#else
71987+static inline unsigned long pax_open_kernel(void) { return 0; }
71988+#endif
71989+#endif
71990+
71991+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
71992+#ifdef CONFIG_PAX_KERNEXEC
71993+#error KERNEXEC requires pax_close_kernel
71994+#else
71995+static inline unsigned long pax_close_kernel(void) { return 0; }
71996+#endif
71997+#endif
71998+
71999 #endif /* CONFIG_MMU */
72000
72001 #endif /* !__ASSEMBLY__ */
72002diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
72003index dc1269c..48a4f51 100644
72004--- a/include/asm-generic/uaccess.h
72005+++ b/include/asm-generic/uaccess.h
72006@@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
72007 return __clear_user(to, n);
72008 }
72009
72010+#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
72011+#ifdef CONFIG_PAX_MEMORY_UDEREF
72012+#error UDEREF requires pax_open_userland
72013+#else
72014+static inline unsigned long pax_open_userland(void) { return 0; }
72015+#endif
72016+#endif
72017+
72018+#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
72019+#ifdef CONFIG_PAX_MEMORY_UDEREF
72020+#error UDEREF requires pax_close_userland
72021+#else
72022+static inline unsigned long pax_close_userland(void) { return 0; }
72023+#endif
72024+#endif
72025+
72026 #endif /* __ASM_GENERIC_UACCESS_H */
72027diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
72028index 69732d2..cbe16d9 100644
72029--- a/include/asm-generic/vmlinux.lds.h
72030+++ b/include/asm-generic/vmlinux.lds.h
72031@@ -227,6 +227,7 @@
72032 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
72033 VMLINUX_SYMBOL(__start_rodata) = .; \
72034 *(.rodata) *(.rodata.*) \
72035+ *(.data..read_only) \
72036 *(__vermagic) /* Kernel version magic */ \
72037 . = ALIGN(8); \
72038 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
72039@@ -710,17 +711,18 @@
72040 * section in the linker script will go there too. @phdr should have
72041 * a leading colon.
72042 *
72043- * Note that this macros defines __per_cpu_load as an absolute symbol.
72044+ * Note that this macros defines per_cpu_load as an absolute symbol.
72045 * If there is no need to put the percpu section at a predetermined
72046 * address, use PERCPU_SECTION.
72047 */
72048 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
72049- VMLINUX_SYMBOL(__per_cpu_load) = .; \
72050- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
72051+ per_cpu_load = .; \
72052+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
72053 - LOAD_OFFSET) { \
72054+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
72055 PERCPU_INPUT(cacheline) \
72056 } phdr \
72057- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
72058+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
72059
72060 /**
72061 * PERCPU_SECTION - define output section for percpu area, simple version
72062diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
72063index 418d270..bfd2794 100644
72064--- a/include/crypto/algapi.h
72065+++ b/include/crypto/algapi.h
72066@@ -34,7 +34,7 @@ struct crypto_type {
72067 unsigned int maskclear;
72068 unsigned int maskset;
72069 unsigned int tfmsize;
72070-};
72071+} __do_const;
72072
72073 struct crypto_instance {
72074 struct crypto_alg alg;
72075diff --git a/include/drm/drmP.h b/include/drm/drmP.h
72076index 12083dc..39740ec 100644
72077--- a/include/drm/drmP.h
72078+++ b/include/drm/drmP.h
72079@@ -69,6 +69,7 @@
72080 #include <linux/workqueue.h>
72081 #include <linux/poll.h>
72082 #include <asm/pgalloc.h>
72083+#include <asm/local.h>
72084 #include <drm/drm.h>
72085 #include <drm/drm_sarea.h>
72086
72087@@ -293,10 +294,12 @@ do { \
72088 * \param cmd command.
72089 * \param arg argument.
72090 */
72091-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
72092+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
72093+ struct drm_file *file_priv);
72094+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
72095 struct drm_file *file_priv);
72096
72097-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
72098+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
72099 unsigned long arg);
72100
72101 #define DRM_IOCTL_NR(n) _IOC_NR(n)
72102@@ -311,10 +314,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
72103 struct drm_ioctl_desc {
72104 unsigned int cmd;
72105 int flags;
72106- drm_ioctl_t *func;
72107+ drm_ioctl_t func;
72108 unsigned int cmd_drv;
72109 const char *name;
72110-};
72111+} __do_const;
72112
72113 /**
72114 * Creates a driver or general drm_ioctl_desc array entry for the given
72115@@ -1015,7 +1018,7 @@ struct drm_info_list {
72116 int (*show)(struct seq_file*, void*); /** show callback */
72117 u32 driver_features; /**< Required driver features for this entry */
72118 void *data;
72119-};
72120+} __do_const;
72121
72122 /**
72123 * debugfs node structure. This structure represents a debugfs file.
72124@@ -1088,7 +1091,7 @@ struct drm_device {
72125
72126 /** \name Usage Counters */
72127 /*@{ */
72128- int open_count; /**< Outstanding files open */
72129+ local_t open_count; /**< Outstanding files open */
72130 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
72131 atomic_t vma_count; /**< Outstanding vma areas open */
72132 int buf_use; /**< Buffers in use -- cannot alloc */
72133@@ -1099,7 +1102,7 @@ struct drm_device {
72134 /*@{ */
72135 unsigned long counters;
72136 enum drm_stat_type types[15];
72137- atomic_t counts[15];
72138+ atomic_unchecked_t counts[15];
72139 /*@} */
72140
72141 struct list_head filelist;
72142diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
72143index f43d556..94d9343 100644
72144--- a/include/drm/drm_crtc_helper.h
72145+++ b/include/drm/drm_crtc_helper.h
72146@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
72147 struct drm_connector *connector);
72148 /* disable encoder when not in use - more explicit than dpms off */
72149 void (*disable)(struct drm_encoder *encoder);
72150-};
72151+} __no_const;
72152
72153 /**
72154 * drm_connector_helper_funcs - helper operations for connectors
72155diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
72156index 72dcbe8..8db58d7 100644
72157--- a/include/drm/ttm/ttm_memory.h
72158+++ b/include/drm/ttm/ttm_memory.h
72159@@ -48,7 +48,7 @@
72160
72161 struct ttm_mem_shrink {
72162 int (*do_shrink) (struct ttm_mem_shrink *);
72163-};
72164+} __no_const;
72165
72166 /**
72167 * struct ttm_mem_global - Global memory accounting structure.
72168diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
72169index 4b840e8..155d235 100644
72170--- a/include/keys/asymmetric-subtype.h
72171+++ b/include/keys/asymmetric-subtype.h
72172@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
72173 /* Verify the signature on a key of this subtype (optional) */
72174 int (*verify_signature)(const struct key *key,
72175 const struct public_key_signature *sig);
72176-};
72177+} __do_const;
72178
72179 /**
72180 * asymmetric_key_subtype - Get the subtype from an asymmetric key
72181diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
72182index c1da539..1dcec55 100644
72183--- a/include/linux/atmdev.h
72184+++ b/include/linux/atmdev.h
72185@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
72186 #endif
72187
72188 struct k_atm_aal_stats {
72189-#define __HANDLE_ITEM(i) atomic_t i
72190+#define __HANDLE_ITEM(i) atomic_unchecked_t i
72191 __AAL_STAT_ITEMS
72192 #undef __HANDLE_ITEM
72193 };
72194@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
72195 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
72196 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
72197 struct module *owner;
72198-};
72199+} __do_const ;
72200
72201 struct atmphy_ops {
72202 int (*start)(struct atm_dev *dev);
72203diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
72204index 70cf138..0418ee2 100644
72205--- a/include/linux/binfmts.h
72206+++ b/include/linux/binfmts.h
72207@@ -73,8 +73,10 @@ struct linux_binfmt {
72208 int (*load_binary)(struct linux_binprm *);
72209 int (*load_shlib)(struct file *);
72210 int (*core_dump)(struct coredump_params *cprm);
72211+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
72212+ void (*handle_mmap)(struct file *);
72213 unsigned long min_coredump; /* minimal dump size */
72214-};
72215+} __do_const;
72216
72217 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
72218
72219diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
72220index 2fdb4a4..54aad7e 100644
72221--- a/include/linux/blkdev.h
72222+++ b/include/linux/blkdev.h
72223@@ -1526,7 +1526,7 @@ struct block_device_operations {
72224 /* this callback is with swap_lock and sometimes page table lock held */
72225 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
72226 struct module *owner;
72227-};
72228+} __do_const;
72229
72230 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
72231 unsigned long);
72232diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
72233index 7c2e030..b72475d 100644
72234--- a/include/linux/blktrace_api.h
72235+++ b/include/linux/blktrace_api.h
72236@@ -23,7 +23,7 @@ struct blk_trace {
72237 struct dentry *dir;
72238 struct dentry *dropped_file;
72239 struct dentry *msg_file;
72240- atomic_t dropped;
72241+ atomic_unchecked_t dropped;
72242 };
72243
72244 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
72245diff --git a/include/linux/cache.h b/include/linux/cache.h
72246index 4c57065..40346da 100644
72247--- a/include/linux/cache.h
72248+++ b/include/linux/cache.h
72249@@ -16,6 +16,14 @@
72250 #define __read_mostly
72251 #endif
72252
72253+#ifndef __read_only
72254+#ifdef CONFIG_PAX_KERNEXEC
72255+#error KERNEXEC requires __read_only
72256+#else
72257+#define __read_only __read_mostly
72258+#endif
72259+#endif
72260+
72261 #ifndef ____cacheline_aligned
72262 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
72263 #endif
72264diff --git a/include/linux/capability.h b/include/linux/capability.h
72265index d9a4f7f4..19f77d6 100644
72266--- a/include/linux/capability.h
72267+++ b/include/linux/capability.h
72268@@ -213,8 +213,13 @@ extern bool ns_capable(struct user_namespace *ns, int cap);
72269 extern bool nsown_capable(int cap);
72270 extern bool inode_capable(const struct inode *inode, int cap);
72271 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
72272+extern bool capable_nolog(int cap);
72273+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
72274+extern bool inode_capable_nolog(const struct inode *inode, int cap);
72275
72276 /* audit system wants to get cap info from files as well */
72277 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
72278
72279+extern int is_privileged_binary(const struct dentry *dentry);
72280+
72281 #endif /* !_LINUX_CAPABILITY_H */
72282diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
72283index 8609d57..86e4d79 100644
72284--- a/include/linux/cdrom.h
72285+++ b/include/linux/cdrom.h
72286@@ -87,7 +87,6 @@ struct cdrom_device_ops {
72287
72288 /* driver specifications */
72289 const int capability; /* capability flags */
72290- int n_minors; /* number of active minor devices */
72291 /* handle uniform packets for scsi type devices (scsi,atapi) */
72292 int (*generic_packet) (struct cdrom_device_info *,
72293 struct packet_command *);
72294diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
72295index 4ce9056..86caac6 100644
72296--- a/include/linux/cleancache.h
72297+++ b/include/linux/cleancache.h
72298@@ -31,7 +31,7 @@ struct cleancache_ops {
72299 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
72300 void (*invalidate_inode)(int, struct cleancache_filekey);
72301 void (*invalidate_fs)(int);
72302-};
72303+} __no_const;
72304
72305 extern struct cleancache_ops *
72306 cleancache_register_ops(struct cleancache_ops *ops);
72307diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
72308index 1ec14a7..d0654a2 100644
72309--- a/include/linux/clk-provider.h
72310+++ b/include/linux/clk-provider.h
72311@@ -132,6 +132,7 @@ struct clk_ops {
72312 unsigned long);
72313 void (*init)(struct clk_hw *hw);
72314 };
72315+typedef struct clk_ops __no_const clk_ops_no_const;
72316
72317 /**
72318 * struct clk_init_data - holds init data that's common to all clocks and is
72319diff --git a/include/linux/compat.h b/include/linux/compat.h
72320index ec1aee4..1077986 100644
72321--- a/include/linux/compat.h
72322+++ b/include/linux/compat.h
72323@@ -312,7 +312,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
72324 compat_size_t __user *len_ptr);
72325
72326 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
72327-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
72328+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
72329 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
72330 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
72331 compat_ssize_t msgsz, int msgflg);
72332@@ -419,7 +419,7 @@ extern int compat_ptrace_request(struct task_struct *child,
72333 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
72334 compat_ulong_t addr, compat_ulong_t data);
72335 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
72336- compat_long_t addr, compat_long_t data);
72337+ compat_ulong_t addr, compat_ulong_t data);
72338
72339 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, size_t);
72340 /*
72341diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
72342index ded4299..da50e3b 100644
72343--- a/include/linux/compiler-gcc4.h
72344+++ b/include/linux/compiler-gcc4.h
72345@@ -39,9 +39,29 @@
72346 # define __compiletime_warning(message) __attribute__((warning(message)))
72347 # define __compiletime_error(message) __attribute__((error(message)))
72348 #endif /* __CHECKER__ */
72349+
72350+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
72351+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
72352+#define __bos0(ptr) __bos((ptr), 0)
72353+#define __bos1(ptr) __bos((ptr), 1)
72354 #endif /* GCC_VERSION >= 40300 */
72355
72356 #if GCC_VERSION >= 40500
72357+
72358+#ifdef CONSTIFY_PLUGIN
72359+#define __no_const __attribute__((no_const))
72360+#define __do_const __attribute__((do_const))
72361+#endif
72362+
72363+#ifdef SIZE_OVERFLOW_PLUGIN
72364+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
72365+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
72366+#endif
72367+
72368+#ifdef LATENT_ENTROPY_PLUGIN
72369+#define __latent_entropy __attribute__((latent_entropy))
72370+#endif
72371+
72372 /*
72373 * Mark a position in code as unreachable. This can be used to
72374 * suppress control flow warnings after asm blocks that transfer
72375diff --git a/include/linux/compiler.h b/include/linux/compiler.h
72376index 92669cd..1771a15 100644
72377--- a/include/linux/compiler.h
72378+++ b/include/linux/compiler.h
72379@@ -5,11 +5,14 @@
72380
72381 #ifdef __CHECKER__
72382 # define __user __attribute__((noderef, address_space(1)))
72383+# define __force_user __force __user
72384 # define __kernel __attribute__((address_space(0)))
72385+# define __force_kernel __force __kernel
72386 # define __safe __attribute__((safe))
72387 # define __force __attribute__((force))
72388 # define __nocast __attribute__((nocast))
72389 # define __iomem __attribute__((noderef, address_space(2)))
72390+# define __force_iomem __force __iomem
72391 # define __must_hold(x) __attribute__((context(x,1,1)))
72392 # define __acquires(x) __attribute__((context(x,0,1)))
72393 # define __releases(x) __attribute__((context(x,1,0)))
72394@@ -17,20 +20,37 @@
72395 # define __release(x) __context__(x,-1)
72396 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
72397 # define __percpu __attribute__((noderef, address_space(3)))
72398+# define __force_percpu __force __percpu
72399 #ifdef CONFIG_SPARSE_RCU_POINTER
72400 # define __rcu __attribute__((noderef, address_space(4)))
72401+# define __force_rcu __force __rcu
72402 #else
72403 # define __rcu
72404+# define __force_rcu
72405 #endif
72406 extern void __chk_user_ptr(const volatile void __user *);
72407 extern void __chk_io_ptr(const volatile void __iomem *);
72408 #else
72409-# define __user
72410-# define __kernel
72411+# ifdef CHECKER_PLUGIN
72412+//# define __user
72413+//# define __force_user
72414+//# define __kernel
72415+//# define __force_kernel
72416+# else
72417+# ifdef STRUCTLEAK_PLUGIN
72418+# define __user __attribute__((user))
72419+# else
72420+# define __user
72421+# endif
72422+# define __force_user
72423+# define __kernel
72424+# define __force_kernel
72425+# endif
72426 # define __safe
72427 # define __force
72428 # define __nocast
72429 # define __iomem
72430+# define __force_iomem
72431 # define __chk_user_ptr(x) (void)0
72432 # define __chk_io_ptr(x) (void)0
72433 # define __builtin_warning(x, y...) (1)
72434@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
72435 # define __release(x) (void)0
72436 # define __cond_lock(x,c) (c)
72437 # define __percpu
72438+# define __force_percpu
72439 # define __rcu
72440+# define __force_rcu
72441 #endif
72442
72443 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
72444@@ -275,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
72445 # define __attribute_const__ /* unimplemented */
72446 #endif
72447
72448+#ifndef __no_const
72449+# define __no_const
72450+#endif
72451+
72452+#ifndef __do_const
72453+# define __do_const
72454+#endif
72455+
72456+#ifndef __size_overflow
72457+# define __size_overflow(...)
72458+#endif
72459+
72460+#ifndef __intentional_overflow
72461+# define __intentional_overflow(...)
72462+#endif
72463+
72464+#ifndef __latent_entropy
72465+# define __latent_entropy
72466+#endif
72467+
72468 /*
72469 * Tell gcc if a function is cold. The compiler will assume any path
72470 * directly leading to the call is unlikely.
72471@@ -284,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
72472 #define __cold
72473 #endif
72474
72475+#ifndef __alloc_size
72476+#define __alloc_size(...)
72477+#endif
72478+
72479+#ifndef __bos
72480+#define __bos(ptr, arg)
72481+#endif
72482+
72483+#ifndef __bos0
72484+#define __bos0(ptr)
72485+#endif
72486+
72487+#ifndef __bos1
72488+#define __bos1(ptr)
72489+#endif
72490+
72491 /* Simple shorthand for a section definition */
72492 #ifndef __section
72493 # define __section(S) __attribute__ ((__section__(#S)))
72494@@ -349,7 +407,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
72495 * use is to mediate communication between process-level code and irq/NMI
72496 * handlers, all running on the same CPU.
72497 */
72498-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
72499+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
72500+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
72501
72502 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
72503 #ifdef CONFIG_KPROBES
72504diff --git a/include/linux/completion.h b/include/linux/completion.h
72505index 3cd574d..adce5fa 100644
72506--- a/include/linux/completion.h
72507+++ b/include/linux/completion.h
72508@@ -79,15 +79,15 @@ static inline void init_completion(struct completion *x)
72509 extern void wait_for_completion(struct completion *);
72510 extern void wait_for_completion_io(struct completion *);
72511 extern int wait_for_completion_interruptible(struct completion *x);
72512-extern int wait_for_completion_killable(struct completion *x);
72513+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
72514 extern unsigned long wait_for_completion_timeout(struct completion *x,
72515 unsigned long timeout);
72516 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
72517 unsigned long timeout);
72518 extern long wait_for_completion_interruptible_timeout(
72519- struct completion *x, unsigned long timeout);
72520+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
72521 extern long wait_for_completion_killable_timeout(
72522- struct completion *x, unsigned long timeout);
72523+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
72524 extern bool try_wait_for_completion(struct completion *x);
72525 extern bool completion_done(struct completion *x);
72526
72527diff --git a/include/linux/configfs.h b/include/linux/configfs.h
72528index 34025df..d94bbbc 100644
72529--- a/include/linux/configfs.h
72530+++ b/include/linux/configfs.h
72531@@ -125,7 +125,7 @@ struct configfs_attribute {
72532 const char *ca_name;
72533 struct module *ca_owner;
72534 umode_t ca_mode;
72535-};
72536+} __do_const;
72537
72538 /*
72539 * Users often need to create attribute structures for their configurable
72540diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
72541index 90d5a15..950cb80 100644
72542--- a/include/linux/cpufreq.h
72543+++ b/include/linux/cpufreq.h
72544@@ -266,7 +266,7 @@ struct cpufreq_driver {
72545 int (*suspend) (struct cpufreq_policy *policy);
72546 int (*resume) (struct cpufreq_policy *policy);
72547 struct freq_attr **attr;
72548-};
72549+} __do_const;
72550
72551 /* flags */
72552
72553@@ -325,6 +325,7 @@ struct global_attr {
72554 ssize_t (*store)(struct kobject *a, struct attribute *b,
72555 const char *c, size_t count);
72556 };
72557+typedef struct global_attr __no_const global_attr_no_const;
72558
72559 #define define_one_global_ro(_name) \
72560 static struct global_attr _name = \
72561diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
72562index 0bc4b74..973b368 100644
72563--- a/include/linux/cpuidle.h
72564+++ b/include/linux/cpuidle.h
72565@@ -52,7 +52,8 @@ struct cpuidle_state {
72566 int index);
72567
72568 int (*enter_dead) (struct cpuidle_device *dev, int index);
72569-};
72570+} __do_const;
72571+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
72572
72573 /* Idle State Flags */
72574 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
72575@@ -191,7 +192,7 @@ struct cpuidle_governor {
72576 void (*reflect) (struct cpuidle_device *dev, int index);
72577
72578 struct module *owner;
72579-};
72580+} __do_const;
72581
72582 #ifdef CONFIG_CPU_IDLE
72583
72584diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
72585index d08e4d2..95fad61 100644
72586--- a/include/linux/cpumask.h
72587+++ b/include/linux/cpumask.h
72588@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
72589 }
72590
72591 /* Valid inputs for n are -1 and 0. */
72592-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
72593+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
72594 {
72595 return n+1;
72596 }
72597
72598-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
72599+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
72600 {
72601 return n+1;
72602 }
72603
72604-static inline unsigned int cpumask_next_and(int n,
72605+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
72606 const struct cpumask *srcp,
72607 const struct cpumask *andp)
72608 {
72609@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
72610 *
72611 * Returns >= nr_cpu_ids if no further cpus set.
72612 */
72613-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
72614+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
72615 {
72616 /* -1 is a legal arg here. */
72617 if (n != -1)
72618@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
72619 *
72620 * Returns >= nr_cpu_ids if no further cpus unset.
72621 */
72622-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
72623+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
72624 {
72625 /* -1 is a legal arg here. */
72626 if (n != -1)
72627@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
72628 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
72629 }
72630
72631-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
72632+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
72633 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
72634
72635 /**
72636diff --git a/include/linux/cred.h b/include/linux/cred.h
72637index 04421e8..6bce4ef 100644
72638--- a/include/linux/cred.h
72639+++ b/include/linux/cred.h
72640@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
72641 static inline void validate_process_creds(void)
72642 {
72643 }
72644+static inline void validate_task_creds(struct task_struct *task)
72645+{
72646+}
72647 #endif
72648
72649 /**
72650diff --git a/include/linux/crypto.h b/include/linux/crypto.h
72651index b92eadf..b4ecdc1 100644
72652--- a/include/linux/crypto.h
72653+++ b/include/linux/crypto.h
72654@@ -373,7 +373,7 @@ struct cipher_tfm {
72655 const u8 *key, unsigned int keylen);
72656 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
72657 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
72658-};
72659+} __no_const;
72660
72661 struct hash_tfm {
72662 int (*init)(struct hash_desc *desc);
72663@@ -394,13 +394,13 @@ struct compress_tfm {
72664 int (*cot_decompress)(struct crypto_tfm *tfm,
72665 const u8 *src, unsigned int slen,
72666 u8 *dst, unsigned int *dlen);
72667-};
72668+} __no_const;
72669
72670 struct rng_tfm {
72671 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
72672 unsigned int dlen);
72673 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
72674-};
72675+} __no_const;
72676
72677 #define crt_ablkcipher crt_u.ablkcipher
72678 #define crt_aead crt_u.aead
72679diff --git a/include/linux/ctype.h b/include/linux/ctype.h
72680index 653589e..4ef254a 100644
72681--- a/include/linux/ctype.h
72682+++ b/include/linux/ctype.h
72683@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
72684 * Fast implementation of tolower() for internal usage. Do not use in your
72685 * code.
72686 */
72687-static inline char _tolower(const char c)
72688+static inline unsigned char _tolower(const unsigned char c)
72689 {
72690 return c | 0x20;
72691 }
72692diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
72693index 7925bf0..d5143d2 100644
72694--- a/include/linux/decompress/mm.h
72695+++ b/include/linux/decompress/mm.h
72696@@ -77,7 +77,7 @@ static void free(void *where)
72697 * warnings when not needed (indeed large_malloc / large_free are not
72698 * needed by inflate */
72699
72700-#define malloc(a) kmalloc(a, GFP_KERNEL)
72701+#define malloc(a) kmalloc((a), GFP_KERNEL)
72702 #define free(a) kfree(a)
72703
72704 #define large_malloc(a) vmalloc(a)
72705diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
72706index 5f1ab92..39c35ae 100644
72707--- a/include/linux/devfreq.h
72708+++ b/include/linux/devfreq.h
72709@@ -114,7 +114,7 @@ struct devfreq_governor {
72710 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
72711 int (*event_handler)(struct devfreq *devfreq,
72712 unsigned int event, void *data);
72713-};
72714+} __do_const;
72715
72716 /**
72717 * struct devfreq - Device devfreq structure
72718diff --git a/include/linux/device.h b/include/linux/device.h
72719index 22b546a..a573dc9 100644
72720--- a/include/linux/device.h
72721+++ b/include/linux/device.h
72722@@ -305,7 +305,7 @@ struct subsys_interface {
72723 struct list_head node;
72724 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
72725 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
72726-};
72727+} __do_const;
72728
72729 int subsys_interface_register(struct subsys_interface *sif);
72730 void subsys_interface_unregister(struct subsys_interface *sif);
72731@@ -493,7 +493,7 @@ struct device_type {
72732 void (*release)(struct device *dev);
72733
72734 const struct dev_pm_ops *pm;
72735-};
72736+} __do_const;
72737
72738 /* interface for exporting device attributes */
72739 struct device_attribute {
72740@@ -503,11 +503,12 @@ struct device_attribute {
72741 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
72742 const char *buf, size_t count);
72743 };
72744+typedef struct device_attribute __no_const device_attribute_no_const;
72745
72746 struct dev_ext_attribute {
72747 struct device_attribute attr;
72748 void *var;
72749-};
72750+} __do_const;
72751
72752 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
72753 char *buf);
72754diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
72755index 94af418..b1ca7a2 100644
72756--- a/include/linux/dma-mapping.h
72757+++ b/include/linux/dma-mapping.h
72758@@ -54,7 +54,7 @@ struct dma_map_ops {
72759 u64 (*get_required_mask)(struct device *dev);
72760 #endif
72761 int is_phys;
72762-};
72763+} __do_const;
72764
72765 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
72766
72767diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
72768index cb286b1..923d066 100644
72769--- a/include/linux/dmaengine.h
72770+++ b/include/linux/dmaengine.h
72771@@ -1030,9 +1030,9 @@ struct dma_pinned_list {
72772 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
72773 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
72774
72775-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
72776+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
72777 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
72778-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
72779+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
72780 struct dma_pinned_list *pinned_list, struct page *page,
72781 unsigned int offset, size_t len);
72782
72783diff --git a/include/linux/efi.h b/include/linux/efi.h
72784index 5f8f176..62a0556 100644
72785--- a/include/linux/efi.h
72786+++ b/include/linux/efi.h
72787@@ -745,6 +745,7 @@ struct efivar_operations {
72788 efi_set_variable_t *set_variable;
72789 efi_query_variable_store_t *query_variable_store;
72790 };
72791+typedef struct efivar_operations __no_const efivar_operations_no_const;
72792
72793 struct efivars {
72794 /*
72795diff --git a/include/linux/elf.h b/include/linux/elf.h
72796index 40a3c0e..4c45a38 100644
72797--- a/include/linux/elf.h
72798+++ b/include/linux/elf.h
72799@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
72800 #define elf_note elf32_note
72801 #define elf_addr_t Elf32_Off
72802 #define Elf_Half Elf32_Half
72803+#define elf_dyn Elf32_Dyn
72804
72805 #else
72806
72807@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
72808 #define elf_note elf64_note
72809 #define elf_addr_t Elf64_Off
72810 #define Elf_Half Elf64_Half
72811+#define elf_dyn Elf64_Dyn
72812
72813 #endif
72814
72815diff --git a/include/linux/err.h b/include/linux/err.h
72816index 221fcfb..f29e5e2 100644
72817--- a/include/linux/err.h
72818+++ b/include/linux/err.h
72819@@ -19,12 +19,12 @@
72820
72821 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
72822
72823-static inline void * __must_check ERR_PTR(long error)
72824+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
72825 {
72826 return (void *) error;
72827 }
72828
72829-static inline long __must_check PTR_ERR(__force const void *ptr)
72830+static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
72831 {
72832 return (long) ptr;
72833 }
72834diff --git a/include/linux/extcon.h b/include/linux/extcon.h
72835index fcb51c8..bdafcf6 100644
72836--- a/include/linux/extcon.h
72837+++ b/include/linux/extcon.h
72838@@ -134,7 +134,7 @@ struct extcon_dev {
72839 /* /sys/class/extcon/.../mutually_exclusive/... */
72840 struct attribute_group attr_g_muex;
72841 struct attribute **attrs_muex;
72842- struct device_attribute *d_attrs_muex;
72843+ device_attribute_no_const *d_attrs_muex;
72844 };
72845
72846 /**
72847diff --git a/include/linux/fb.h b/include/linux/fb.h
72848index ffac70a..ca3e711 100644
72849--- a/include/linux/fb.h
72850+++ b/include/linux/fb.h
72851@@ -304,7 +304,7 @@ struct fb_ops {
72852 /* called at KDB enter and leave time to prepare the console */
72853 int (*fb_debug_enter)(struct fb_info *info);
72854 int (*fb_debug_leave)(struct fb_info *info);
72855-};
72856+} __do_const;
72857
72858 #ifdef CONFIG_FB_TILEBLITTING
72859 #define FB_TILE_CURSOR_NONE 0
72860diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
72861index 085197b..0fa6f0b 100644
72862--- a/include/linux/fdtable.h
72863+++ b/include/linux/fdtable.h
72864@@ -95,7 +95,7 @@ struct files_struct *get_files_struct(struct task_struct *);
72865 void put_files_struct(struct files_struct *fs);
72866 void reset_files_struct(struct files_struct *);
72867 int unshare_files(struct files_struct **);
72868-struct files_struct *dup_fd(struct files_struct *, int *);
72869+struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
72870 void do_close_on_exec(struct files_struct *);
72871 int iterate_fd(struct files_struct *, unsigned,
72872 int (*)(const void *, struct file *, unsigned),
72873diff --git a/include/linux/filter.h b/include/linux/filter.h
72874index a6ac848..a104a76 100644
72875--- a/include/linux/filter.h
72876+++ b/include/linux/filter.h
72877@@ -20,6 +20,7 @@ struct compat_sock_fprog {
72878
72879 struct sk_buff;
72880 struct sock;
72881+struct bpf_jit_work;
72882
72883 struct sk_filter
72884 {
72885@@ -27,6 +28,9 @@ struct sk_filter
72886 unsigned int len; /* Number of filter blocks */
72887 unsigned int (*bpf_func)(const struct sk_buff *skb,
72888 const struct sock_filter *filter);
72889+#ifdef CONFIG_BPF_JIT
72890+ struct bpf_jit_work *work;
72891+#endif
72892 struct rcu_head rcu;
72893 struct sock_filter insns[0];
72894 };
72895diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
72896index 8293262..2b3b8bd 100644
72897--- a/include/linux/frontswap.h
72898+++ b/include/linux/frontswap.h
72899@@ -11,7 +11,7 @@ struct frontswap_ops {
72900 int (*load)(unsigned, pgoff_t, struct page *);
72901 void (*invalidate_page)(unsigned, pgoff_t);
72902 void (*invalidate_area)(unsigned);
72903-};
72904+} __no_const;
72905
72906 extern bool frontswap_enabled;
72907 extern struct frontswap_ops *
72908diff --git a/include/linux/fs.h b/include/linux/fs.h
72909index 9818747..788bfbd 100644
72910--- a/include/linux/fs.h
72911+++ b/include/linux/fs.h
72912@@ -1554,7 +1554,8 @@ struct file_operations {
72913 long (*fallocate)(struct file *file, int mode, loff_t offset,
72914 loff_t len);
72915 int (*show_fdinfo)(struct seq_file *m, struct file *f);
72916-};
72917+} __do_const;
72918+typedef struct file_operations __no_const file_operations_no_const;
72919
72920 struct inode_operations {
72921 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
72922@@ -2740,4 +2741,14 @@ static inline bool dir_relax(struct inode *inode)
72923 return !IS_DEADDIR(inode);
72924 }
72925
72926+static inline bool is_sidechannel_device(const struct inode *inode)
72927+{
72928+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
72929+ umode_t mode = inode->i_mode;
72930+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
72931+#else
72932+ return false;
72933+#endif
72934+}
72935+
72936 #endif /* _LINUX_FS_H */
72937diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
72938index 2b93a9a..855d94a 100644
72939--- a/include/linux/fs_struct.h
72940+++ b/include/linux/fs_struct.h
72941@@ -6,7 +6,7 @@
72942 #include <linux/seqlock.h>
72943
72944 struct fs_struct {
72945- int users;
72946+ atomic_t users;
72947 spinlock_t lock;
72948 seqcount_t seq;
72949 int umask;
72950diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
72951index a9ff9a3..1ba1788 100644
72952--- a/include/linux/fscache-cache.h
72953+++ b/include/linux/fscache-cache.h
72954@@ -113,7 +113,7 @@ struct fscache_operation {
72955 fscache_operation_release_t release;
72956 };
72957
72958-extern atomic_t fscache_op_debug_id;
72959+extern atomic_unchecked_t fscache_op_debug_id;
72960 extern void fscache_op_work_func(struct work_struct *work);
72961
72962 extern void fscache_enqueue_operation(struct fscache_operation *);
72963@@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
72964 INIT_WORK(&op->work, fscache_op_work_func);
72965 atomic_set(&op->usage, 1);
72966 op->state = FSCACHE_OP_ST_INITIALISED;
72967- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
72968+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
72969 op->processor = processor;
72970 op->release = release;
72971 INIT_LIST_HEAD(&op->pend_link);
72972diff --git a/include/linux/fscache.h b/include/linux/fscache.h
72973index 7a08623..4c07b0f 100644
72974--- a/include/linux/fscache.h
72975+++ b/include/linux/fscache.h
72976@@ -152,7 +152,7 @@ struct fscache_cookie_def {
72977 * - this is mandatory for any object that may have data
72978 */
72979 void (*now_uncached)(void *cookie_netfs_data);
72980-};
72981+} __do_const;
72982
72983 /*
72984 * fscache cached network filesystem type
72985diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
72986index 1c804b0..1432c2b 100644
72987--- a/include/linux/fsnotify.h
72988+++ b/include/linux/fsnotify.h
72989@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
72990 struct inode *inode = file_inode(file);
72991 __u32 mask = FS_ACCESS;
72992
72993+ if (is_sidechannel_device(inode))
72994+ return;
72995+
72996 if (S_ISDIR(inode->i_mode))
72997 mask |= FS_ISDIR;
72998
72999@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
73000 struct inode *inode = file_inode(file);
73001 __u32 mask = FS_MODIFY;
73002
73003+ if (is_sidechannel_device(inode))
73004+ return;
73005+
73006 if (S_ISDIR(inode->i_mode))
73007 mask |= FS_ISDIR;
73008
73009@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
73010 */
73011 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
73012 {
73013- return kstrdup(name, GFP_KERNEL);
73014+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
73015 }
73016
73017 /*
73018diff --git a/include/linux/genhd.h b/include/linux/genhd.h
73019index 9f3c275..8bdff5d 100644
73020--- a/include/linux/genhd.h
73021+++ b/include/linux/genhd.h
73022@@ -194,7 +194,7 @@ struct gendisk {
73023 struct kobject *slave_dir;
73024
73025 struct timer_rand_state *random;
73026- atomic_t sync_io; /* RAID */
73027+ atomic_unchecked_t sync_io; /* RAID */
73028 struct disk_events *ev;
73029 #ifdef CONFIG_BLK_DEV_INTEGRITY
73030 struct blk_integrity *integrity;
73031@@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
73032 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
73033
73034 /* drivers/char/random.c */
73035-extern void add_disk_randomness(struct gendisk *disk);
73036+extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
73037 extern void rand_initialize_disk(struct gendisk *disk);
73038
73039 static inline sector_t get_start_sect(struct block_device *bdev)
73040diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
73041index 023bc34..b02b46a 100644
73042--- a/include/linux/genl_magic_func.h
73043+++ b/include/linux/genl_magic_func.h
73044@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
73045 },
73046
73047 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
73048-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
73049+static struct genl_ops ZZZ_genl_ops[] = {
73050 #include GENL_MAGIC_INCLUDE_FILE
73051 };
73052
73053diff --git a/include/linux/gfp.h b/include/linux/gfp.h
73054index 9b4dd49..61fd41d 100644
73055--- a/include/linux/gfp.h
73056+++ b/include/linux/gfp.h
73057@@ -35,6 +35,13 @@ struct vm_area_struct;
73058 #define ___GFP_NO_KSWAPD 0x400000u
73059 #define ___GFP_OTHER_NODE 0x800000u
73060 #define ___GFP_WRITE 0x1000000u
73061+
73062+#ifdef CONFIG_PAX_USERCOPY_SLABS
73063+#define ___GFP_USERCOPY 0x2000000u
73064+#else
73065+#define ___GFP_USERCOPY 0
73066+#endif
73067+
73068 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
73069
73070 /*
73071@@ -92,6 +99,7 @@ struct vm_area_struct;
73072 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
73073 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
73074 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
73075+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
73076
73077 /*
73078 * This may seem redundant, but it's a way of annotating false positives vs.
73079@@ -99,7 +107,7 @@ struct vm_area_struct;
73080 */
73081 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
73082
73083-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
73084+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
73085 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
73086
73087 /* This equals 0, but use constants in case they ever change */
73088@@ -153,6 +161,8 @@ struct vm_area_struct;
73089 /* 4GB DMA on some platforms */
73090 #define GFP_DMA32 __GFP_DMA32
73091
73092+#define GFP_USERCOPY __GFP_USERCOPY
73093+
73094 /* Convert GFP flags to their corresponding migrate type */
73095 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
73096 {
73097diff --git a/include/linux/gracl.h b/include/linux/gracl.h
73098new file mode 100644
73099index 0000000..ebe6d72
73100--- /dev/null
73101+++ b/include/linux/gracl.h
73102@@ -0,0 +1,319 @@
73103+#ifndef GR_ACL_H
73104+#define GR_ACL_H
73105+
73106+#include <linux/grdefs.h>
73107+#include <linux/resource.h>
73108+#include <linux/capability.h>
73109+#include <linux/dcache.h>
73110+#include <asm/resource.h>
73111+
73112+/* Major status information */
73113+
73114+#define GR_VERSION "grsecurity 2.9.1"
73115+#define GRSECURITY_VERSION 0x2901
73116+
73117+enum {
73118+ GR_SHUTDOWN = 0,
73119+ GR_ENABLE = 1,
73120+ GR_SPROLE = 2,
73121+ GR_RELOAD = 3,
73122+ GR_SEGVMOD = 4,
73123+ GR_STATUS = 5,
73124+ GR_UNSPROLE = 6,
73125+ GR_PASSSET = 7,
73126+ GR_SPROLEPAM = 8,
73127+};
73128+
73129+/* Password setup definitions
73130+ * kernel/grhash.c */
73131+enum {
73132+ GR_PW_LEN = 128,
73133+ GR_SALT_LEN = 16,
73134+ GR_SHA_LEN = 32,
73135+};
73136+
73137+enum {
73138+ GR_SPROLE_LEN = 64,
73139+};
73140+
73141+enum {
73142+ GR_NO_GLOB = 0,
73143+ GR_REG_GLOB,
73144+ GR_CREATE_GLOB
73145+};
73146+
73147+#define GR_NLIMITS 32
73148+
73149+/* Begin Data Structures */
73150+
73151+struct sprole_pw {
73152+ unsigned char *rolename;
73153+ unsigned char salt[GR_SALT_LEN];
73154+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
73155+};
73156+
73157+struct name_entry {
73158+ __u32 key;
73159+ ino_t inode;
73160+ dev_t device;
73161+ char *name;
73162+ __u16 len;
73163+ __u8 deleted;
73164+ struct name_entry *prev;
73165+ struct name_entry *next;
73166+};
73167+
73168+struct inodev_entry {
73169+ struct name_entry *nentry;
73170+ struct inodev_entry *prev;
73171+ struct inodev_entry *next;
73172+};
73173+
73174+struct acl_role_db {
73175+ struct acl_role_label **r_hash;
73176+ __u32 r_size;
73177+};
73178+
73179+struct inodev_db {
73180+ struct inodev_entry **i_hash;
73181+ __u32 i_size;
73182+};
73183+
73184+struct name_db {
73185+ struct name_entry **n_hash;
73186+ __u32 n_size;
73187+};
73188+
73189+struct crash_uid {
73190+ uid_t uid;
73191+ unsigned long expires;
73192+};
73193+
73194+struct gr_hash_struct {
73195+ void **table;
73196+ void **nametable;
73197+ void *first;
73198+ __u32 table_size;
73199+ __u32 used_size;
73200+ int type;
73201+};
73202+
73203+/* Userspace Grsecurity ACL data structures */
73204+
73205+struct acl_subject_label {
73206+ char *filename;
73207+ ino_t inode;
73208+ dev_t device;
73209+ __u32 mode;
73210+ kernel_cap_t cap_mask;
73211+ kernel_cap_t cap_lower;
73212+ kernel_cap_t cap_invert_audit;
73213+
73214+ struct rlimit res[GR_NLIMITS];
73215+ __u32 resmask;
73216+
73217+ __u8 user_trans_type;
73218+ __u8 group_trans_type;
73219+ uid_t *user_transitions;
73220+ gid_t *group_transitions;
73221+ __u16 user_trans_num;
73222+ __u16 group_trans_num;
73223+
73224+ __u32 sock_families[2];
73225+ __u32 ip_proto[8];
73226+ __u32 ip_type;
73227+ struct acl_ip_label **ips;
73228+ __u32 ip_num;
73229+ __u32 inaddr_any_override;
73230+
73231+ __u32 crashes;
73232+ unsigned long expires;
73233+
73234+ struct acl_subject_label *parent_subject;
73235+ struct gr_hash_struct *hash;
73236+ struct acl_subject_label *prev;
73237+ struct acl_subject_label *next;
73238+
73239+ struct acl_object_label **obj_hash;
73240+ __u32 obj_hash_size;
73241+ __u16 pax_flags;
73242+};
73243+
73244+struct role_allowed_ip {
73245+ __u32 addr;
73246+ __u32 netmask;
73247+
73248+ struct role_allowed_ip *prev;
73249+ struct role_allowed_ip *next;
73250+};
73251+
73252+struct role_transition {
73253+ char *rolename;
73254+
73255+ struct role_transition *prev;
73256+ struct role_transition *next;
73257+};
73258+
73259+struct acl_role_label {
73260+ char *rolename;
73261+ uid_t uidgid;
73262+ __u16 roletype;
73263+
73264+ __u16 auth_attempts;
73265+ unsigned long expires;
73266+
73267+ struct acl_subject_label *root_label;
73268+ struct gr_hash_struct *hash;
73269+
73270+ struct acl_role_label *prev;
73271+ struct acl_role_label *next;
73272+
73273+ struct role_transition *transitions;
73274+ struct role_allowed_ip *allowed_ips;
73275+ uid_t *domain_children;
73276+ __u16 domain_child_num;
73277+
73278+ umode_t umask;
73279+
73280+ struct acl_subject_label **subj_hash;
73281+ __u32 subj_hash_size;
73282+};
73283+
73284+struct user_acl_role_db {
73285+ struct acl_role_label **r_table;
73286+ __u32 num_pointers; /* Number of allocations to track */
73287+ __u32 num_roles; /* Number of roles */
73288+ __u32 num_domain_children; /* Number of domain children */
73289+ __u32 num_subjects; /* Number of subjects */
73290+ __u32 num_objects; /* Number of objects */
73291+};
73292+
73293+struct acl_object_label {
73294+ char *filename;
73295+ ino_t inode;
73296+ dev_t device;
73297+ __u32 mode;
73298+
73299+ struct acl_subject_label *nested;
73300+ struct acl_object_label *globbed;
73301+
73302+ /* next two structures not used */
73303+
73304+ struct acl_object_label *prev;
73305+ struct acl_object_label *next;
73306+};
73307+
73308+struct acl_ip_label {
73309+ char *iface;
73310+ __u32 addr;
73311+ __u32 netmask;
73312+ __u16 low, high;
73313+ __u8 mode;
73314+ __u32 type;
73315+ __u32 proto[8];
73316+
73317+ /* next two structures not used */
73318+
73319+ struct acl_ip_label *prev;
73320+ struct acl_ip_label *next;
73321+};
73322+
73323+struct gr_arg {
73324+ struct user_acl_role_db role_db;
73325+ unsigned char pw[GR_PW_LEN];
73326+ unsigned char salt[GR_SALT_LEN];
73327+ unsigned char sum[GR_SHA_LEN];
73328+ unsigned char sp_role[GR_SPROLE_LEN];
73329+ struct sprole_pw *sprole_pws;
73330+ dev_t segv_device;
73331+ ino_t segv_inode;
73332+ uid_t segv_uid;
73333+ __u16 num_sprole_pws;
73334+ __u16 mode;
73335+};
73336+
73337+struct gr_arg_wrapper {
73338+ struct gr_arg *arg;
73339+ __u32 version;
73340+ __u32 size;
73341+};
73342+
73343+struct subject_map {
73344+ struct acl_subject_label *user;
73345+ struct acl_subject_label *kernel;
73346+ struct subject_map *prev;
73347+ struct subject_map *next;
73348+};
73349+
73350+struct acl_subj_map_db {
73351+ struct subject_map **s_hash;
73352+ __u32 s_size;
73353+};
73354+
73355+/* End Data Structures Section */
73356+
73357+/* Hash functions generated by empirical testing by Brad Spengler
73358+ Makes good use of the low bits of the inode. Generally 0-1 times
73359+ in loop for successful match. 0-3 for unsuccessful match.
73360+ Shift/add algorithm with modulus of table size and an XOR*/
73361+
73362+static __inline__ unsigned int
73363+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
73364+{
73365+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
73366+}
73367+
73368+ static __inline__ unsigned int
73369+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
73370+{
73371+ return ((const unsigned long)userp % sz);
73372+}
73373+
73374+static __inline__ unsigned int
73375+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
73376+{
73377+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
73378+}
73379+
73380+static __inline__ unsigned int
73381+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
73382+{
73383+ return full_name_hash((const unsigned char *)name, len) % sz;
73384+}
73385+
73386+#define FOR_EACH_ROLE_START(role) \
73387+ role = role_list; \
73388+ while (role) {
73389+
73390+#define FOR_EACH_ROLE_END(role) \
73391+ role = role->prev; \
73392+ }
73393+
73394+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
73395+ subj = NULL; \
73396+ iter = 0; \
73397+ while (iter < role->subj_hash_size) { \
73398+ if (subj == NULL) \
73399+ subj = role->subj_hash[iter]; \
73400+ if (subj == NULL) { \
73401+ iter++; \
73402+ continue; \
73403+ }
73404+
73405+#define FOR_EACH_SUBJECT_END(subj,iter) \
73406+ subj = subj->next; \
73407+ if (subj == NULL) \
73408+ iter++; \
73409+ }
73410+
73411+
73412+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
73413+ subj = role->hash->first; \
73414+ while (subj != NULL) {
73415+
73416+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
73417+ subj = subj->next; \
73418+ }
73419+
73420+#endif
73421+
73422diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
73423new file mode 100644
73424index 0000000..33ebd1f
73425--- /dev/null
73426+++ b/include/linux/gracl_compat.h
73427@@ -0,0 +1,156 @@
73428+#ifndef GR_ACL_COMPAT_H
73429+#define GR_ACL_COMPAT_H
73430+
73431+#include <linux/resource.h>
73432+#include <asm/resource.h>
73433+
73434+struct sprole_pw_compat {
73435+ compat_uptr_t rolename;
73436+ unsigned char salt[GR_SALT_LEN];
73437+ unsigned char sum[GR_SHA_LEN];
73438+};
73439+
73440+struct gr_hash_struct_compat {
73441+ compat_uptr_t table;
73442+ compat_uptr_t nametable;
73443+ compat_uptr_t first;
73444+ __u32 table_size;
73445+ __u32 used_size;
73446+ int type;
73447+};
73448+
73449+struct acl_subject_label_compat {
73450+ compat_uptr_t filename;
73451+ compat_ino_t inode;
73452+ __u32 device;
73453+ __u32 mode;
73454+ kernel_cap_t cap_mask;
73455+ kernel_cap_t cap_lower;
73456+ kernel_cap_t cap_invert_audit;
73457+
73458+ struct compat_rlimit res[GR_NLIMITS];
73459+ __u32 resmask;
73460+
73461+ __u8 user_trans_type;
73462+ __u8 group_trans_type;
73463+ compat_uptr_t user_transitions;
73464+ compat_uptr_t group_transitions;
73465+ __u16 user_trans_num;
73466+ __u16 group_trans_num;
73467+
73468+ __u32 sock_families[2];
73469+ __u32 ip_proto[8];
73470+ __u32 ip_type;
73471+ compat_uptr_t ips;
73472+ __u32 ip_num;
73473+ __u32 inaddr_any_override;
73474+
73475+ __u32 crashes;
73476+ compat_ulong_t expires;
73477+
73478+ compat_uptr_t parent_subject;
73479+ compat_uptr_t hash;
73480+ compat_uptr_t prev;
73481+ compat_uptr_t next;
73482+
73483+ compat_uptr_t obj_hash;
73484+ __u32 obj_hash_size;
73485+ __u16 pax_flags;
73486+};
73487+
73488+struct role_allowed_ip_compat {
73489+ __u32 addr;
73490+ __u32 netmask;
73491+
73492+ compat_uptr_t prev;
73493+ compat_uptr_t next;
73494+};
73495+
73496+struct role_transition_compat {
73497+ compat_uptr_t rolename;
73498+
73499+ compat_uptr_t prev;
73500+ compat_uptr_t next;
73501+};
73502+
73503+struct acl_role_label_compat {
73504+ compat_uptr_t rolename;
73505+ uid_t uidgid;
73506+ __u16 roletype;
73507+
73508+ __u16 auth_attempts;
73509+ compat_ulong_t expires;
73510+
73511+ compat_uptr_t root_label;
73512+ compat_uptr_t hash;
73513+
73514+ compat_uptr_t prev;
73515+ compat_uptr_t next;
73516+
73517+ compat_uptr_t transitions;
73518+ compat_uptr_t allowed_ips;
73519+ compat_uptr_t domain_children;
73520+ __u16 domain_child_num;
73521+
73522+ umode_t umask;
73523+
73524+ compat_uptr_t subj_hash;
73525+ __u32 subj_hash_size;
73526+};
73527+
73528+struct user_acl_role_db_compat {
73529+ compat_uptr_t r_table;
73530+ __u32 num_pointers;
73531+ __u32 num_roles;
73532+ __u32 num_domain_children;
73533+ __u32 num_subjects;
73534+ __u32 num_objects;
73535+};
73536+
73537+struct acl_object_label_compat {
73538+ compat_uptr_t filename;
73539+ compat_ino_t inode;
73540+ __u32 device;
73541+ __u32 mode;
73542+
73543+ compat_uptr_t nested;
73544+ compat_uptr_t globbed;
73545+
73546+ compat_uptr_t prev;
73547+ compat_uptr_t next;
73548+};
73549+
73550+struct acl_ip_label_compat {
73551+ compat_uptr_t iface;
73552+ __u32 addr;
73553+ __u32 netmask;
73554+ __u16 low, high;
73555+ __u8 mode;
73556+ __u32 type;
73557+ __u32 proto[8];
73558+
73559+ compat_uptr_t prev;
73560+ compat_uptr_t next;
73561+};
73562+
73563+struct gr_arg_compat {
73564+ struct user_acl_role_db_compat role_db;
73565+ unsigned char pw[GR_PW_LEN];
73566+ unsigned char salt[GR_SALT_LEN];
73567+ unsigned char sum[GR_SHA_LEN];
73568+ unsigned char sp_role[GR_SPROLE_LEN];
73569+ compat_uptr_t sprole_pws;
73570+ __u32 segv_device;
73571+ compat_ino_t segv_inode;
73572+ uid_t segv_uid;
73573+ __u16 num_sprole_pws;
73574+ __u16 mode;
73575+};
73576+
73577+struct gr_arg_wrapper_compat {
73578+ compat_uptr_t arg;
73579+ __u32 version;
73580+ __u32 size;
73581+};
73582+
73583+#endif
73584diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
73585new file mode 100644
73586index 0000000..323ecf2
73587--- /dev/null
73588+++ b/include/linux/gralloc.h
73589@@ -0,0 +1,9 @@
73590+#ifndef __GRALLOC_H
73591+#define __GRALLOC_H
73592+
73593+void acl_free_all(void);
73594+int acl_alloc_stack_init(unsigned long size);
73595+void *acl_alloc(unsigned long len);
73596+void *acl_alloc_num(unsigned long num, unsigned long len);
73597+
73598+#endif
73599diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
73600new file mode 100644
73601index 0000000..be66033
73602--- /dev/null
73603+++ b/include/linux/grdefs.h
73604@@ -0,0 +1,140 @@
73605+#ifndef GRDEFS_H
73606+#define GRDEFS_H
73607+
73608+/* Begin grsecurity status declarations */
73609+
73610+enum {
73611+ GR_READY = 0x01,
73612+ GR_STATUS_INIT = 0x00 // disabled state
73613+};
73614+
73615+/* Begin ACL declarations */
73616+
73617+/* Role flags */
73618+
73619+enum {
73620+ GR_ROLE_USER = 0x0001,
73621+ GR_ROLE_GROUP = 0x0002,
73622+ GR_ROLE_DEFAULT = 0x0004,
73623+ GR_ROLE_SPECIAL = 0x0008,
73624+ GR_ROLE_AUTH = 0x0010,
73625+ GR_ROLE_NOPW = 0x0020,
73626+ GR_ROLE_GOD = 0x0040,
73627+ GR_ROLE_LEARN = 0x0080,
73628+ GR_ROLE_TPE = 0x0100,
73629+ GR_ROLE_DOMAIN = 0x0200,
73630+ GR_ROLE_PAM = 0x0400,
73631+ GR_ROLE_PERSIST = 0x0800
73632+};
73633+
73634+/* ACL Subject and Object mode flags */
73635+enum {
73636+ GR_DELETED = 0x80000000
73637+};
73638+
73639+/* ACL Object-only mode flags */
73640+enum {
73641+ GR_READ = 0x00000001,
73642+ GR_APPEND = 0x00000002,
73643+ GR_WRITE = 0x00000004,
73644+ GR_EXEC = 0x00000008,
73645+ GR_FIND = 0x00000010,
73646+ GR_INHERIT = 0x00000020,
73647+ GR_SETID = 0x00000040,
73648+ GR_CREATE = 0x00000080,
73649+ GR_DELETE = 0x00000100,
73650+ GR_LINK = 0x00000200,
73651+ GR_AUDIT_READ = 0x00000400,
73652+ GR_AUDIT_APPEND = 0x00000800,
73653+ GR_AUDIT_WRITE = 0x00001000,
73654+ GR_AUDIT_EXEC = 0x00002000,
73655+ GR_AUDIT_FIND = 0x00004000,
73656+ GR_AUDIT_INHERIT= 0x00008000,
73657+ GR_AUDIT_SETID = 0x00010000,
73658+ GR_AUDIT_CREATE = 0x00020000,
73659+ GR_AUDIT_DELETE = 0x00040000,
73660+ GR_AUDIT_LINK = 0x00080000,
73661+ GR_PTRACERD = 0x00100000,
73662+ GR_NOPTRACE = 0x00200000,
73663+ GR_SUPPRESS = 0x00400000,
73664+ GR_NOLEARN = 0x00800000,
73665+ GR_INIT_TRANSFER= 0x01000000
73666+};
73667+
73668+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
73669+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
73670+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
73671+
73672+/* ACL subject-only mode flags */
73673+enum {
73674+ GR_KILL = 0x00000001,
73675+ GR_VIEW = 0x00000002,
73676+ GR_PROTECTED = 0x00000004,
73677+ GR_LEARN = 0x00000008,
73678+ GR_OVERRIDE = 0x00000010,
73679+ /* just a placeholder, this mode is only used in userspace */
73680+ GR_DUMMY = 0x00000020,
73681+ GR_PROTSHM = 0x00000040,
73682+ GR_KILLPROC = 0x00000080,
73683+ GR_KILLIPPROC = 0x00000100,
73684+ /* just a placeholder, this mode is only used in userspace */
73685+ GR_NOTROJAN = 0x00000200,
73686+ GR_PROTPROCFD = 0x00000400,
73687+ GR_PROCACCT = 0x00000800,
73688+ GR_RELAXPTRACE = 0x00001000,
73689+ //GR_NESTED = 0x00002000,
73690+ GR_INHERITLEARN = 0x00004000,
73691+ GR_PROCFIND = 0x00008000,
73692+ GR_POVERRIDE = 0x00010000,
73693+ GR_KERNELAUTH = 0x00020000,
73694+ GR_ATSECURE = 0x00040000,
73695+ GR_SHMEXEC = 0x00080000
73696+};
73697+
73698+enum {
73699+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
73700+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
73701+ GR_PAX_ENABLE_MPROTECT = 0x0004,
73702+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
73703+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
73704+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
73705+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
73706+ GR_PAX_DISABLE_MPROTECT = 0x0400,
73707+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
73708+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
73709+};
73710+
73711+enum {
73712+ GR_ID_USER = 0x01,
73713+ GR_ID_GROUP = 0x02,
73714+};
73715+
73716+enum {
73717+ GR_ID_ALLOW = 0x01,
73718+ GR_ID_DENY = 0x02,
73719+};
73720+
73721+#define GR_CRASH_RES 31
73722+#define GR_UIDTABLE_MAX 500
73723+
73724+/* begin resource learning section */
73725+enum {
73726+ GR_RLIM_CPU_BUMP = 60,
73727+ GR_RLIM_FSIZE_BUMP = 50000,
73728+ GR_RLIM_DATA_BUMP = 10000,
73729+ GR_RLIM_STACK_BUMP = 1000,
73730+ GR_RLIM_CORE_BUMP = 10000,
73731+ GR_RLIM_RSS_BUMP = 500000,
73732+ GR_RLIM_NPROC_BUMP = 1,
73733+ GR_RLIM_NOFILE_BUMP = 5,
73734+ GR_RLIM_MEMLOCK_BUMP = 50000,
73735+ GR_RLIM_AS_BUMP = 500000,
73736+ GR_RLIM_LOCKS_BUMP = 2,
73737+ GR_RLIM_SIGPENDING_BUMP = 5,
73738+ GR_RLIM_MSGQUEUE_BUMP = 10000,
73739+ GR_RLIM_NICE_BUMP = 1,
73740+ GR_RLIM_RTPRIO_BUMP = 1,
73741+ GR_RLIM_RTTIME_BUMP = 1000000
73742+};
73743+
73744+#endif
73745diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
73746new file mode 100644
73747index 0000000..e337683
73748--- /dev/null
73749+++ b/include/linux/grinternal.h
73750@@ -0,0 +1,229 @@
73751+#ifndef __GRINTERNAL_H
73752+#define __GRINTERNAL_H
73753+
73754+#ifdef CONFIG_GRKERNSEC
73755+
73756+#include <linux/fs.h>
73757+#include <linux/mnt_namespace.h>
73758+#include <linux/nsproxy.h>
73759+#include <linux/gracl.h>
73760+#include <linux/grdefs.h>
73761+#include <linux/grmsg.h>
73762+
73763+void gr_add_learn_entry(const char *fmt, ...)
73764+ __attribute__ ((format (printf, 1, 2)));
73765+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
73766+ const struct vfsmount *mnt);
73767+__u32 gr_check_create(const struct dentry *new_dentry,
73768+ const struct dentry *parent,
73769+ const struct vfsmount *mnt, const __u32 mode);
73770+int gr_check_protected_task(const struct task_struct *task);
73771+__u32 to_gr_audit(const __u32 reqmode);
73772+int gr_set_acls(const int type);
73773+int gr_apply_subject_to_task(struct task_struct *task);
73774+int gr_acl_is_enabled(void);
73775+char gr_roletype_to_char(void);
73776+
73777+void gr_handle_alertkill(struct task_struct *task);
73778+char *gr_to_filename(const struct dentry *dentry,
73779+ const struct vfsmount *mnt);
73780+char *gr_to_filename1(const struct dentry *dentry,
73781+ const struct vfsmount *mnt);
73782+char *gr_to_filename2(const struct dentry *dentry,
73783+ const struct vfsmount *mnt);
73784+char *gr_to_filename3(const struct dentry *dentry,
73785+ const struct vfsmount *mnt);
73786+
73787+extern int grsec_enable_ptrace_readexec;
73788+extern int grsec_enable_harden_ptrace;
73789+extern int grsec_enable_link;
73790+extern int grsec_enable_fifo;
73791+extern int grsec_enable_execve;
73792+extern int grsec_enable_shm;
73793+extern int grsec_enable_execlog;
73794+extern int grsec_enable_signal;
73795+extern int grsec_enable_audit_ptrace;
73796+extern int grsec_enable_forkfail;
73797+extern int grsec_enable_time;
73798+extern int grsec_enable_rofs;
73799+extern int grsec_deny_new_usb;
73800+extern int grsec_enable_chroot_shmat;
73801+extern int grsec_enable_chroot_mount;
73802+extern int grsec_enable_chroot_double;
73803+extern int grsec_enable_chroot_pivot;
73804+extern int grsec_enable_chroot_chdir;
73805+extern int grsec_enable_chroot_chmod;
73806+extern int grsec_enable_chroot_mknod;
73807+extern int grsec_enable_chroot_fchdir;
73808+extern int grsec_enable_chroot_nice;
73809+extern int grsec_enable_chroot_execlog;
73810+extern int grsec_enable_chroot_caps;
73811+extern int grsec_enable_chroot_sysctl;
73812+extern int grsec_enable_chroot_unix;
73813+extern int grsec_enable_symlinkown;
73814+extern kgid_t grsec_symlinkown_gid;
73815+extern int grsec_enable_tpe;
73816+extern kgid_t grsec_tpe_gid;
73817+extern int grsec_enable_tpe_all;
73818+extern int grsec_enable_tpe_invert;
73819+extern int grsec_enable_socket_all;
73820+extern kgid_t grsec_socket_all_gid;
73821+extern int grsec_enable_socket_client;
73822+extern kgid_t grsec_socket_client_gid;
73823+extern int grsec_enable_socket_server;
73824+extern kgid_t grsec_socket_server_gid;
73825+extern kgid_t grsec_audit_gid;
73826+extern int grsec_enable_group;
73827+extern int grsec_enable_log_rwxmaps;
73828+extern int grsec_enable_mount;
73829+extern int grsec_enable_chdir;
73830+extern int grsec_resource_logging;
73831+extern int grsec_enable_blackhole;
73832+extern int grsec_lastack_retries;
73833+extern int grsec_enable_brute;
73834+extern int grsec_lock;
73835+
73836+extern spinlock_t grsec_alert_lock;
73837+extern unsigned long grsec_alert_wtime;
73838+extern unsigned long grsec_alert_fyet;
73839+
73840+extern spinlock_t grsec_audit_lock;
73841+
73842+extern rwlock_t grsec_exec_file_lock;
73843+
73844+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
73845+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
73846+ (tsk)->exec_file->f_path.mnt) : "/")
73847+
73848+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
73849+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
73850+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
73851+
73852+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
73853+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
73854+ (tsk)->exec_file->f_path.mnt) : "/")
73855+
73856+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
73857+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
73858+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
73859+
73860+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
73861+
73862+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
73863+
73864+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
73865+{
73866+ if (file1 && file2) {
73867+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
73868+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
73869+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
73870+ return true;
73871+ }
73872+
73873+ return false;
73874+}
73875+
73876+#define GR_CHROOT_CAPS {{ \
73877+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
73878+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
73879+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
73880+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
73881+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
73882+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
73883+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
73884+
73885+#define security_learn(normal_msg,args...) \
73886+({ \
73887+ read_lock(&grsec_exec_file_lock); \
73888+ gr_add_learn_entry(normal_msg "\n", ## args); \
73889+ read_unlock(&grsec_exec_file_lock); \
73890+})
73891+
73892+enum {
73893+ GR_DO_AUDIT,
73894+ GR_DONT_AUDIT,
73895+ /* used for non-audit messages that we shouldn't kill the task on */
73896+ GR_DONT_AUDIT_GOOD
73897+};
73898+
73899+enum {
73900+ GR_TTYSNIFF,
73901+ GR_RBAC,
73902+ GR_RBAC_STR,
73903+ GR_STR_RBAC,
73904+ GR_RBAC_MODE2,
73905+ GR_RBAC_MODE3,
73906+ GR_FILENAME,
73907+ GR_SYSCTL_HIDDEN,
73908+ GR_NOARGS,
73909+ GR_ONE_INT,
73910+ GR_ONE_INT_TWO_STR,
73911+ GR_ONE_STR,
73912+ GR_STR_INT,
73913+ GR_TWO_STR_INT,
73914+ GR_TWO_INT,
73915+ GR_TWO_U64,
73916+ GR_THREE_INT,
73917+ GR_FIVE_INT_TWO_STR,
73918+ GR_TWO_STR,
73919+ GR_THREE_STR,
73920+ GR_FOUR_STR,
73921+ GR_STR_FILENAME,
73922+ GR_FILENAME_STR,
73923+ GR_FILENAME_TWO_INT,
73924+ GR_FILENAME_TWO_INT_STR,
73925+ GR_TEXTREL,
73926+ GR_PTRACE,
73927+ GR_RESOURCE,
73928+ GR_CAP,
73929+ GR_SIG,
73930+ GR_SIG2,
73931+ GR_CRASH1,
73932+ GR_CRASH2,
73933+ GR_PSACCT,
73934+ GR_RWXMAP,
73935+ GR_RWXMAPVMA
73936+};
73937+
73938+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
73939+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
73940+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
73941+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
73942+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
73943+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
73944+#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)
73945+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
73946+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
73947+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
73948+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
73949+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
73950+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
73951+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
73952+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
73953+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
73954+#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)
73955+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
73956+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
73957+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
73958+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
73959+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
73960+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
73961+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
73962+#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)
73963+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
73964+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
73965+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
73966+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
73967+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
73968+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
73969+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
73970+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
73971+#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)
73972+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
73973+#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
73974+
73975+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
73976+
73977+#endif
73978+
73979+#endif
73980diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
73981new file mode 100644
73982index 0000000..a4396b5
73983--- /dev/null
73984+++ b/include/linux/grmsg.h
73985@@ -0,0 +1,113 @@
73986+#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"
73987+#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"
73988+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
73989+#define GR_STOPMOD_MSG "denied modification of module state by "
73990+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
73991+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
73992+#define GR_IOPERM_MSG "denied use of ioperm() by "
73993+#define GR_IOPL_MSG "denied use of iopl() by "
73994+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
73995+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
73996+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
73997+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
73998+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
73999+#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"
74000+#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"
74001+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
74002+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
74003+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
74004+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
74005+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
74006+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
74007+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
74008+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
74009+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
74010+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
74011+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
74012+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
74013+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
74014+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
74015+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
74016+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
74017+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
74018+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
74019+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
74020+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
74021+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
74022+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
74023+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
74024+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
74025+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
74026+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
74027+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
74028+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
74029+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
74030+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
74031+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
74032+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
74033+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
74034+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
74035+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
74036+#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"
74037+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
74038+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
74039+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
74040+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
74041+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
74042+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
74043+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
74044+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
74045+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
74046+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
74047+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
74048+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
74049+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
74050+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
74051+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
74052+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
74053+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
74054+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
74055+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
74056+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
74057+#define GR_FAILFORK_MSG "failed fork with errno %s by "
74058+#define GR_NICE_CHROOT_MSG "denied priority change by "
74059+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
74060+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
74061+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
74062+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
74063+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
74064+#define GR_TIME_MSG "time set by "
74065+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
74066+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
74067+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
74068+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
74069+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
74070+#define GR_BIND_MSG "denied bind() by "
74071+#define GR_CONNECT_MSG "denied connect() by "
74072+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
74073+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
74074+#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"
74075+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
74076+#define GR_CAP_ACL_MSG "use of %s denied for "
74077+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
74078+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
74079+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
74080+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
74081+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
74082+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
74083+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
74084+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
74085+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
74086+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
74087+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
74088+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
74089+#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
74090+#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
74091+#define GR_VM86_MSG "denied use of vm86 by "
74092+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
74093+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
74094+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
74095+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
74096+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
74097+#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 "
74098+#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 "
74099diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
74100new file mode 100644
74101index 0000000..d6f5a21
74102--- /dev/null
74103+++ b/include/linux/grsecurity.h
74104@@ -0,0 +1,244 @@
74105+#ifndef GR_SECURITY_H
74106+#define GR_SECURITY_H
74107+#include <linux/fs.h>
74108+#include <linux/fs_struct.h>
74109+#include <linux/binfmts.h>
74110+#include <linux/gracl.h>
74111+
74112+/* notify of brain-dead configs */
74113+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
74114+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
74115+#endif
74116+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
74117+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
74118+#endif
74119+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
74120+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
74121+#endif
74122+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
74123+#error "CONFIG_PAX enabled, but no PaX options are enabled."
74124+#endif
74125+
74126+int gr_handle_new_usb(void);
74127+
74128+void gr_handle_brute_attach(unsigned long mm_flags);
74129+void gr_handle_brute_check(void);
74130+void gr_handle_kernel_exploit(void);
74131+
74132+char gr_roletype_to_char(void);
74133+
74134+int gr_acl_enable_at_secure(void);
74135+
74136+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
74137+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
74138+
74139+void gr_del_task_from_ip_table(struct task_struct *p);
74140+
74141+int gr_pid_is_chrooted(struct task_struct *p);
74142+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
74143+int gr_handle_chroot_nice(void);
74144+int gr_handle_chroot_sysctl(const int op);
74145+int gr_handle_chroot_setpriority(struct task_struct *p,
74146+ const int niceval);
74147+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
74148+int gr_handle_chroot_chroot(const struct dentry *dentry,
74149+ const struct vfsmount *mnt);
74150+void gr_handle_chroot_chdir(const struct path *path);
74151+int gr_handle_chroot_chmod(const struct dentry *dentry,
74152+ const struct vfsmount *mnt, const int mode);
74153+int gr_handle_chroot_mknod(const struct dentry *dentry,
74154+ const struct vfsmount *mnt, const int mode);
74155+int gr_handle_chroot_mount(const struct dentry *dentry,
74156+ const struct vfsmount *mnt,
74157+ const char *dev_name);
74158+int gr_handle_chroot_pivot(void);
74159+int gr_handle_chroot_unix(const pid_t pid);
74160+
74161+int gr_handle_rawio(const struct inode *inode);
74162+
74163+void gr_handle_ioperm(void);
74164+void gr_handle_iopl(void);
74165+
74166+umode_t gr_acl_umask(void);
74167+
74168+int gr_tpe_allow(const struct file *file);
74169+
74170+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
74171+void gr_clear_chroot_entries(struct task_struct *task);
74172+
74173+void gr_log_forkfail(const int retval);
74174+void gr_log_timechange(void);
74175+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
74176+void gr_log_chdir(const struct dentry *dentry,
74177+ const struct vfsmount *mnt);
74178+void gr_log_chroot_exec(const struct dentry *dentry,
74179+ const struct vfsmount *mnt);
74180+void gr_log_remount(const char *devname, const int retval);
74181+void gr_log_unmount(const char *devname, const int retval);
74182+void gr_log_mount(const char *from, const char *to, const int retval);
74183+void gr_log_textrel(struct vm_area_struct *vma);
74184+void gr_log_ptgnustack(struct file *file);
74185+void gr_log_rwxmmap(struct file *file);
74186+void gr_log_rwxmprotect(struct vm_area_struct *vma);
74187+
74188+int gr_handle_follow_link(const struct inode *parent,
74189+ const struct inode *inode,
74190+ const struct dentry *dentry,
74191+ const struct vfsmount *mnt);
74192+int gr_handle_fifo(const struct dentry *dentry,
74193+ const struct vfsmount *mnt,
74194+ const struct dentry *dir, const int flag,
74195+ const int acc_mode);
74196+int gr_handle_hardlink(const struct dentry *dentry,
74197+ const struct vfsmount *mnt,
74198+ struct inode *inode,
74199+ const int mode, const struct filename *to);
74200+
74201+int gr_is_capable(const int cap);
74202+int gr_is_capable_nolog(const int cap);
74203+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74204+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
74205+
74206+void gr_copy_label(struct task_struct *tsk);
74207+void gr_handle_crash(struct task_struct *task, const int sig);
74208+int gr_handle_signal(const struct task_struct *p, const int sig);
74209+int gr_check_crash_uid(const kuid_t uid);
74210+int gr_check_protected_task(const struct task_struct *task);
74211+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
74212+int gr_acl_handle_mmap(const struct file *file,
74213+ const unsigned long prot);
74214+int gr_acl_handle_mprotect(const struct file *file,
74215+ const unsigned long prot);
74216+int gr_check_hidden_task(const struct task_struct *tsk);
74217+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
74218+ const struct vfsmount *mnt);
74219+__u32 gr_acl_handle_utime(const struct dentry *dentry,
74220+ const struct vfsmount *mnt);
74221+__u32 gr_acl_handle_access(const struct dentry *dentry,
74222+ const struct vfsmount *mnt, const int fmode);
74223+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
74224+ const struct vfsmount *mnt, umode_t *mode);
74225+__u32 gr_acl_handle_chown(const struct dentry *dentry,
74226+ const struct vfsmount *mnt);
74227+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
74228+ const struct vfsmount *mnt);
74229+int gr_handle_ptrace(struct task_struct *task, const long request);
74230+int gr_handle_proc_ptrace(struct task_struct *task);
74231+__u32 gr_acl_handle_execve(const struct dentry *dentry,
74232+ const struct vfsmount *mnt);
74233+int gr_check_crash_exec(const struct file *filp);
74234+int gr_acl_is_enabled(void);
74235+void gr_set_kernel_label(struct task_struct *task);
74236+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
74237+ const kgid_t gid);
74238+int gr_set_proc_label(const struct dentry *dentry,
74239+ const struct vfsmount *mnt,
74240+ const int unsafe_flags);
74241+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
74242+ const struct vfsmount *mnt);
74243+__u32 gr_acl_handle_open(const struct dentry *dentry,
74244+ const struct vfsmount *mnt, int acc_mode);
74245+__u32 gr_acl_handle_creat(const struct dentry *dentry,
74246+ const struct dentry *p_dentry,
74247+ const struct vfsmount *p_mnt,
74248+ int open_flags, int acc_mode, const int imode);
74249+void gr_handle_create(const struct dentry *dentry,
74250+ const struct vfsmount *mnt);
74251+void gr_handle_proc_create(const struct dentry *dentry,
74252+ const struct inode *inode);
74253+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
74254+ const struct dentry *parent_dentry,
74255+ const struct vfsmount *parent_mnt,
74256+ const int mode);
74257+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
74258+ const struct dentry *parent_dentry,
74259+ const struct vfsmount *parent_mnt);
74260+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
74261+ const struct vfsmount *mnt);
74262+void gr_handle_delete(const ino_t ino, const dev_t dev);
74263+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
74264+ const struct vfsmount *mnt);
74265+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
74266+ const struct dentry *parent_dentry,
74267+ const struct vfsmount *parent_mnt,
74268+ const struct filename *from);
74269+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
74270+ const struct dentry *parent_dentry,
74271+ const struct vfsmount *parent_mnt,
74272+ const struct dentry *old_dentry,
74273+ const struct vfsmount *old_mnt, const struct filename *to);
74274+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
74275+int gr_acl_handle_rename(struct dentry *new_dentry,
74276+ struct dentry *parent_dentry,
74277+ const struct vfsmount *parent_mnt,
74278+ struct dentry *old_dentry,
74279+ struct inode *old_parent_inode,
74280+ struct vfsmount *old_mnt, const struct filename *newname);
74281+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
74282+ struct dentry *old_dentry,
74283+ struct dentry *new_dentry,
74284+ struct vfsmount *mnt, const __u8 replace);
74285+__u32 gr_check_link(const struct dentry *new_dentry,
74286+ const struct dentry *parent_dentry,
74287+ const struct vfsmount *parent_mnt,
74288+ const struct dentry *old_dentry,
74289+ const struct vfsmount *old_mnt);
74290+int gr_acl_handle_filldir(const struct file *file, const char *name,
74291+ const unsigned int namelen, const ino_t ino);
74292+
74293+__u32 gr_acl_handle_unix(const struct dentry *dentry,
74294+ const struct vfsmount *mnt);
74295+void gr_acl_handle_exit(void);
74296+void gr_acl_handle_psacct(struct task_struct *task, const long code);
74297+int gr_acl_handle_procpidmem(const struct task_struct *task);
74298+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
74299+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
74300+void gr_audit_ptrace(struct task_struct *task);
74301+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
74302+void gr_put_exec_file(struct task_struct *task);
74303+
74304+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
74305+
74306+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
74307+extern void gr_learn_resource(const struct task_struct *task, const int res,
74308+ const unsigned long wanted, const int gt);
74309+#else
74310+static inline void gr_learn_resource(const struct task_struct *task, const int res,
74311+ const unsigned long wanted, const int gt)
74312+{
74313+}
74314+#endif
74315+
74316+#ifdef CONFIG_GRKERNSEC_RESLOG
74317+extern void gr_log_resource(const struct task_struct *task, const int res,
74318+ const unsigned long wanted, const int gt);
74319+#else
74320+static inline void gr_log_resource(const struct task_struct *task, const int res,
74321+ const unsigned long wanted, const int gt)
74322+{
74323+}
74324+#endif
74325+
74326+#ifdef CONFIG_GRKERNSEC
74327+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
74328+void gr_handle_vm86(void);
74329+void gr_handle_mem_readwrite(u64 from, u64 to);
74330+
74331+void gr_log_badprocpid(const char *entry);
74332+
74333+extern int grsec_enable_dmesg;
74334+extern int grsec_disable_privio;
74335+
74336+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
74337+extern kgid_t grsec_proc_gid;
74338+#endif
74339+
74340+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74341+extern int grsec_enable_chroot_findtask;
74342+#endif
74343+#ifdef CONFIG_GRKERNSEC_SETXID
74344+extern int grsec_enable_setxid;
74345+#endif
74346+#endif
74347+
74348+#endif
74349diff --git a/include/linux/grsock.h b/include/linux/grsock.h
74350new file mode 100644
74351index 0000000..e7ffaaf
74352--- /dev/null
74353+++ b/include/linux/grsock.h
74354@@ -0,0 +1,19 @@
74355+#ifndef __GRSOCK_H
74356+#define __GRSOCK_H
74357+
74358+extern void gr_attach_curr_ip(const struct sock *sk);
74359+extern int gr_handle_sock_all(const int family, const int type,
74360+ const int protocol);
74361+extern int gr_handle_sock_server(const struct sockaddr *sck);
74362+extern int gr_handle_sock_server_other(const struct sock *sck);
74363+extern int gr_handle_sock_client(const struct sockaddr *sck);
74364+extern int gr_search_connect(struct socket * sock,
74365+ struct sockaddr_in * addr);
74366+extern int gr_search_bind(struct socket * sock,
74367+ struct sockaddr_in * addr);
74368+extern int gr_search_listen(struct socket * sock);
74369+extern int gr_search_accept(struct socket * sock);
74370+extern int gr_search_socket(const int domain, const int type,
74371+ const int protocol);
74372+
74373+#endif
74374diff --git a/include/linux/highmem.h b/include/linux/highmem.h
74375index 7fb31da..08b5114 100644
74376--- a/include/linux/highmem.h
74377+++ b/include/linux/highmem.h
74378@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
74379 kunmap_atomic(kaddr);
74380 }
74381
74382+static inline void sanitize_highpage(struct page *page)
74383+{
74384+ void *kaddr;
74385+ unsigned long flags;
74386+
74387+ local_irq_save(flags);
74388+ kaddr = kmap_atomic(page);
74389+ clear_page(kaddr);
74390+ kunmap_atomic(kaddr);
74391+ local_irq_restore(flags);
74392+}
74393+
74394 static inline void zero_user_segments(struct page *page,
74395 unsigned start1, unsigned end1,
74396 unsigned start2, unsigned end2)
74397diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
74398index 1c7b89a..7f52502 100644
74399--- a/include/linux/hwmon-sysfs.h
74400+++ b/include/linux/hwmon-sysfs.h
74401@@ -25,7 +25,8 @@
74402 struct sensor_device_attribute{
74403 struct device_attribute dev_attr;
74404 int index;
74405-};
74406+} __do_const;
74407+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
74408 #define to_sensor_dev_attr(_dev_attr) \
74409 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
74410
74411@@ -41,7 +42,7 @@ struct sensor_device_attribute_2 {
74412 struct device_attribute dev_attr;
74413 u8 index;
74414 u8 nr;
74415-};
74416+} __do_const;
74417 #define to_sensor_dev_attr_2(_dev_attr) \
74418 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
74419
74420diff --git a/include/linux/i2c.h b/include/linux/i2c.h
74421index e988fa9..ff9f17e 100644
74422--- a/include/linux/i2c.h
74423+++ b/include/linux/i2c.h
74424@@ -366,6 +366,7 @@ struct i2c_algorithm {
74425 /* To determine what the adapter supports */
74426 u32 (*functionality) (struct i2c_adapter *);
74427 };
74428+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
74429
74430 /**
74431 * struct i2c_bus_recovery_info - I2C bus recovery information
74432diff --git a/include/linux/i2o.h b/include/linux/i2o.h
74433index d23c3c2..eb63c81 100644
74434--- a/include/linux/i2o.h
74435+++ b/include/linux/i2o.h
74436@@ -565,7 +565,7 @@ struct i2o_controller {
74437 struct i2o_device *exec; /* Executive */
74438 #if BITS_PER_LONG == 64
74439 spinlock_t context_list_lock; /* lock for context_list */
74440- atomic_t context_list_counter; /* needed for unique contexts */
74441+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
74442 struct list_head context_list; /* list of context id's
74443 and pointers */
74444 #endif
74445diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
74446index aff7ad8..3942bbd 100644
74447--- a/include/linux/if_pppox.h
74448+++ b/include/linux/if_pppox.h
74449@@ -76,7 +76,7 @@ struct pppox_proto {
74450 int (*ioctl)(struct socket *sock, unsigned int cmd,
74451 unsigned long arg);
74452 struct module *owner;
74453-};
74454+} __do_const;
74455
74456 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
74457 extern void unregister_pppox_proto(int proto_num);
74458diff --git a/include/linux/init.h b/include/linux/init.h
74459index e73f2b7..cc996e0 100644
74460--- a/include/linux/init.h
74461+++ b/include/linux/init.h
74462@@ -39,9 +39,17 @@
74463 * Also note, that this data cannot be "const".
74464 */
74465
74466+#define add_init_latent_entropy __latent_entropy
74467+
74468+#ifdef CONFIG_MEMORY_HOTPLUG
74469+#define add_meminit_latent_entropy
74470+#else
74471+#define add_meminit_latent_entropy __latent_entropy
74472+#endif
74473+
74474 /* These are for everybody (although not all archs will actually
74475 discard it in modules) */
74476-#define __init __section(.init.text) __cold notrace
74477+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
74478 #define __initdata __section(.init.data)
74479 #define __initconst __constsection(.init.rodata)
74480 #define __exitdata __section(.exit.data)
74481@@ -102,7 +110,7 @@
74482 #define __cpuexitconst
74483
74484 /* Used for MEMORY_HOTPLUG */
74485-#define __meminit __section(.meminit.text) __cold notrace
74486+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
74487 #define __meminitdata __section(.meminit.data)
74488 #define __meminitconst __constsection(.meminit.rodata)
74489 #define __memexit __section(.memexit.text) __exitused __cold notrace
74490diff --git a/include/linux/init_task.h b/include/linux/init_task.h
74491index 5cd0f09..c9f67cc 100644
74492--- a/include/linux/init_task.h
74493+++ b/include/linux/init_task.h
74494@@ -154,6 +154,12 @@ extern struct task_group root_task_group;
74495
74496 #define INIT_TASK_COMM "swapper"
74497
74498+#ifdef CONFIG_X86
74499+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
74500+#else
74501+#define INIT_TASK_THREAD_INFO
74502+#endif
74503+
74504 /*
74505 * INIT_TASK is used to set up the first task table, touch at
74506 * your own risk!. Base=0, limit=0x1fffff (=2MB)
74507@@ -193,6 +199,7 @@ extern struct task_group root_task_group;
74508 RCU_POINTER_INITIALIZER(cred, &init_cred), \
74509 .comm = INIT_TASK_COMM, \
74510 .thread = INIT_THREAD, \
74511+ INIT_TASK_THREAD_INFO \
74512 .fs = &init_fs, \
74513 .files = &init_files, \
74514 .signal = &init_signals, \
74515diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
74516index 5fa5afe..ac55b25 100644
74517--- a/include/linux/interrupt.h
74518+++ b/include/linux/interrupt.h
74519@@ -430,7 +430,7 @@ enum
74520 /* map softirq index to softirq name. update 'softirq_to_name' in
74521 * kernel/softirq.c when adding a new softirq.
74522 */
74523-extern char *softirq_to_name[NR_SOFTIRQS];
74524+extern const char * const softirq_to_name[NR_SOFTIRQS];
74525
74526 /* softirq mask and active fields moved to irq_cpustat_t in
74527 * asm/hardirq.h to get better cache usage. KAO
74528@@ -438,12 +438,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
74529
74530 struct softirq_action
74531 {
74532- void (*action)(struct softirq_action *);
74533-};
74534+ void (*action)(void);
74535+} __no_const;
74536
74537 asmlinkage void do_softirq(void);
74538 asmlinkage void __do_softirq(void);
74539-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
74540+extern void open_softirq(int nr, void (*action)(void));
74541 extern void softirq_init(void);
74542 extern void __raise_softirq_irqoff(unsigned int nr);
74543
74544diff --git a/include/linux/iommu.h b/include/linux/iommu.h
74545index 3aeb730..2177f39 100644
74546--- a/include/linux/iommu.h
74547+++ b/include/linux/iommu.h
74548@@ -113,7 +113,7 @@ struct iommu_ops {
74549 u32 (*domain_get_windows)(struct iommu_domain *domain);
74550
74551 unsigned long pgsize_bitmap;
74552-};
74553+} __do_const;
74554
74555 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
74556 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
74557diff --git a/include/linux/ioport.h b/include/linux/ioport.h
74558index 89b7c24..382af74 100644
74559--- a/include/linux/ioport.h
74560+++ b/include/linux/ioport.h
74561@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
74562 int adjust_resource(struct resource *res, resource_size_t start,
74563 resource_size_t size);
74564 resource_size_t resource_alignment(struct resource *res);
74565-static inline resource_size_t resource_size(const struct resource *res)
74566+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
74567 {
74568 return res->end - res->start + 1;
74569 }
74570diff --git a/include/linux/irq.h b/include/linux/irq.h
74571index f04d3ba..bcf2cfb 100644
74572--- a/include/linux/irq.h
74573+++ b/include/linux/irq.h
74574@@ -333,7 +333,8 @@ struct irq_chip {
74575 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
74576
74577 unsigned long flags;
74578-};
74579+} __do_const;
74580+typedef struct irq_chip __no_const irq_chip_no_const;
74581
74582 /*
74583 * irq_chip specific flags
74584diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
74585index 3e203eb..3fe68d0 100644
74586--- a/include/linux/irqchip/arm-gic.h
74587+++ b/include/linux/irqchip/arm-gic.h
74588@@ -59,9 +59,11 @@
74589
74590 #ifndef __ASSEMBLY__
74591
74592+#include <linux/irq.h>
74593+
74594 struct device_node;
74595
74596-extern struct irq_chip gic_arch_extn;
74597+extern irq_chip_no_const gic_arch_extn;
74598
74599 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
74600 u32 offset, struct device_node *);
74601diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
74602index 6883e19..e854fcb 100644
74603--- a/include/linux/kallsyms.h
74604+++ b/include/linux/kallsyms.h
74605@@ -15,7 +15,8 @@
74606
74607 struct module;
74608
74609-#ifdef CONFIG_KALLSYMS
74610+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
74611+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
74612 /* Lookup the address for a symbol. Returns 0 if not found. */
74613 unsigned long kallsyms_lookup_name(const char *name);
74614
74615@@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
74616 /* Stupid that this does nothing, but I didn't create this mess. */
74617 #define __print_symbol(fmt, addr)
74618 #endif /*CONFIG_KALLSYMS*/
74619+#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
74620+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
74621+extern unsigned long kallsyms_lookup_name(const char *name);
74622+extern void __print_symbol(const char *fmt, unsigned long address);
74623+extern int sprint_backtrace(char *buffer, unsigned long address);
74624+extern int sprint_symbol(char *buffer, unsigned long address);
74625+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
74626+const char *kallsyms_lookup(unsigned long addr,
74627+ unsigned long *symbolsize,
74628+ unsigned long *offset,
74629+ char **modname, char *namebuf);
74630+extern int kallsyms_lookup_size_offset(unsigned long addr,
74631+ unsigned long *symbolsize,
74632+ unsigned long *offset);
74633+#endif
74634
74635 /* This macro allows us to keep printk typechecking */
74636 static __printf(1, 2)
74637diff --git a/include/linux/key-type.h b/include/linux/key-type.h
74638index 518a53a..5e28358 100644
74639--- a/include/linux/key-type.h
74640+++ b/include/linux/key-type.h
74641@@ -125,7 +125,7 @@ struct key_type {
74642 /* internal fields */
74643 struct list_head link; /* link in types list */
74644 struct lock_class_key lock_class; /* key->sem lock class */
74645-};
74646+} __do_const;
74647
74648 extern struct key_type key_type_keyring;
74649
74650diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
74651index c6e091b..a940adf 100644
74652--- a/include/linux/kgdb.h
74653+++ b/include/linux/kgdb.h
74654@@ -52,7 +52,7 @@ extern int kgdb_connected;
74655 extern int kgdb_io_module_registered;
74656
74657 extern atomic_t kgdb_setting_breakpoint;
74658-extern atomic_t kgdb_cpu_doing_single_step;
74659+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
74660
74661 extern struct task_struct *kgdb_usethread;
74662 extern struct task_struct *kgdb_contthread;
74663@@ -254,7 +254,7 @@ struct kgdb_arch {
74664 void (*correct_hw_break)(void);
74665
74666 void (*enable_nmi)(bool on);
74667-};
74668+} __do_const;
74669
74670 /**
74671 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
74672@@ -279,7 +279,7 @@ struct kgdb_io {
74673 void (*pre_exception) (void);
74674 void (*post_exception) (void);
74675 int is_console;
74676-};
74677+} __do_const;
74678
74679 extern struct kgdb_arch arch_kgdb_ops;
74680
74681diff --git a/include/linux/kmod.h b/include/linux/kmod.h
74682index 0555cc6..b16a7a4 100644
74683--- a/include/linux/kmod.h
74684+++ b/include/linux/kmod.h
74685@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
74686 * usually useless though. */
74687 extern __printf(2, 3)
74688 int __request_module(bool wait, const char *name, ...);
74689+extern __printf(3, 4)
74690+int ___request_module(bool wait, char *param_name, const char *name, ...);
74691 #define request_module(mod...) __request_module(true, mod)
74692 #define request_module_nowait(mod...) __request_module(false, mod)
74693 #define try_then_request_module(x, mod...) \
74694diff --git a/include/linux/kobject.h b/include/linux/kobject.h
74695index 939b112..ed6ed51 100644
74696--- a/include/linux/kobject.h
74697+++ b/include/linux/kobject.h
74698@@ -111,7 +111,7 @@ struct kobj_type {
74699 struct attribute **default_attrs;
74700 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
74701 const void *(*namespace)(struct kobject *kobj);
74702-};
74703+} __do_const;
74704
74705 struct kobj_uevent_env {
74706 char *envp[UEVENT_NUM_ENVP];
74707@@ -134,6 +134,7 @@ struct kobj_attribute {
74708 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
74709 const char *buf, size_t count);
74710 };
74711+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
74712
74713 extern const struct sysfs_ops kobj_sysfs_ops;
74714
74715diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
74716index f66b065..c2c29b4 100644
74717--- a/include/linux/kobject_ns.h
74718+++ b/include/linux/kobject_ns.h
74719@@ -43,7 +43,7 @@ struct kobj_ns_type_operations {
74720 const void *(*netlink_ns)(struct sock *sk);
74721 const void *(*initial_ns)(void);
74722 void (*drop_ns)(void *);
74723-};
74724+} __do_const;
74725
74726 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
74727 int kobj_ns_type_registered(enum kobj_ns_type type);
74728diff --git a/include/linux/kref.h b/include/linux/kref.h
74729index 484604d..0f6c5b6 100644
74730--- a/include/linux/kref.h
74731+++ b/include/linux/kref.h
74732@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
74733 static inline int kref_sub(struct kref *kref, unsigned int count,
74734 void (*release)(struct kref *kref))
74735 {
74736- WARN_ON(release == NULL);
74737+ BUG_ON(release == NULL);
74738
74739 if (atomic_sub_and_test((int) count, &kref->refcount)) {
74740 release(kref);
74741diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
74742index a63d83e..77fd685 100644
74743--- a/include/linux/kvm_host.h
74744+++ b/include/linux/kvm_host.h
74745@@ -446,7 +446,7 @@ static inline void kvm_irqfd_exit(void)
74746 {
74747 }
74748 #endif
74749-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
74750+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
74751 struct module *module);
74752 void kvm_exit(void);
74753
74754@@ -618,7 +618,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
74755 struct kvm_guest_debug *dbg);
74756 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
74757
74758-int kvm_arch_init(void *opaque);
74759+int kvm_arch_init(const void *opaque);
74760 void kvm_arch_exit(void);
74761
74762 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
74763diff --git a/include/linux/libata.h b/include/linux/libata.h
74764index 4ea55bb..dcd2601 100644
74765--- a/include/linux/libata.h
74766+++ b/include/linux/libata.h
74767@@ -924,7 +924,7 @@ struct ata_port_operations {
74768 * fields must be pointers.
74769 */
74770 const struct ata_port_operations *inherits;
74771-};
74772+} __do_const;
74773
74774 struct ata_port_info {
74775 unsigned long flags;
74776diff --git a/include/linux/linkage.h b/include/linux/linkage.h
74777index d3e8ad2..a949f68 100644
74778--- a/include/linux/linkage.h
74779+++ b/include/linux/linkage.h
74780@@ -31,6 +31,7 @@
74781 #endif
74782
74783 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
74784+#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
74785 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
74786
74787 /*
74788diff --git a/include/linux/list.h b/include/linux/list.h
74789index f4d8a2f..38e6e46 100644
74790--- a/include/linux/list.h
74791+++ b/include/linux/list.h
74792@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
74793 extern void list_del(struct list_head *entry);
74794 #endif
74795
74796+extern void __pax_list_add(struct list_head *new,
74797+ struct list_head *prev,
74798+ struct list_head *next);
74799+static inline void pax_list_add(struct list_head *new, struct list_head *head)
74800+{
74801+ __pax_list_add(new, head, head->next);
74802+}
74803+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
74804+{
74805+ __pax_list_add(new, head->prev, head);
74806+}
74807+extern void pax_list_del(struct list_head *entry);
74808+
74809 /**
74810 * list_replace - replace old entry by new one
74811 * @old : the element to be replaced
74812@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
74813 INIT_LIST_HEAD(entry);
74814 }
74815
74816+extern void pax_list_del_init(struct list_head *entry);
74817+
74818 /**
74819 * list_move - delete from one list and add as another's head
74820 * @list: the entry to move
74821diff --git a/include/linux/math64.h b/include/linux/math64.h
74822index 2913b86..8dcbb1e 100644
74823--- a/include/linux/math64.h
74824+++ b/include/linux/math64.h
74825@@ -15,7 +15,7 @@
74826 * This is commonly provided by 32bit archs to provide an optimized 64bit
74827 * divide.
74828 */
74829-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
74830+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
74831 {
74832 *remainder = dividend % divisor;
74833 return dividend / divisor;
74834@@ -33,7 +33,7 @@ static inline s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
74835 /**
74836 * div64_u64 - unsigned 64bit divide with 64bit divisor
74837 */
74838-static inline u64 div64_u64(u64 dividend, u64 divisor)
74839+static inline u64 __intentional_overflow(0) div64_u64(u64 dividend, u64 divisor)
74840 {
74841 return dividend / divisor;
74842 }
74843@@ -52,7 +52,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
74844 #define div64_ul(x, y) div_u64((x), (y))
74845
74846 #ifndef div_u64_rem
74847-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
74848+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
74849 {
74850 *remainder = do_div(dividend, divisor);
74851 return dividend;
74852@@ -81,7 +81,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
74853 * divide.
74854 */
74855 #ifndef div_u64
74856-static inline u64 div_u64(u64 dividend, u32 divisor)
74857+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
74858 {
74859 u32 remainder;
74860 return div_u64_rem(dividend, divisor, &remainder);
74861diff --git a/include/linux/mm.h b/include/linux/mm.h
74862index f022460..6ecf4f9 100644
74863--- a/include/linux/mm.h
74864+++ b/include/linux/mm.h
74865@@ -113,6 +113,11 @@ extern unsigned int kobjsize(const void *objp);
74866 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
74867 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
74868 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
74869+
74870+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
74871+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
74872+#endif
74873+
74874 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
74875
74876 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
74877@@ -208,8 +213,8 @@ struct vm_operations_struct {
74878 /* called by access_process_vm when get_user_pages() fails, typically
74879 * for use by special VMAs that can switch between memory and hardware
74880 */
74881- int (*access)(struct vm_area_struct *vma, unsigned long addr,
74882- void *buf, int len, int write);
74883+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
74884+ void *buf, size_t len, int write);
74885 #ifdef CONFIG_NUMA
74886 /*
74887 * set_policy() op must add a reference to any non-NULL @new mempolicy
74888@@ -239,6 +244,7 @@ struct vm_operations_struct {
74889 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
74890 unsigned long size, pgoff_t pgoff);
74891 };
74892+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
74893
74894 struct mmu_gather;
74895 struct inode;
74896@@ -983,8 +989,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
74897 unsigned long *pfn);
74898 int follow_phys(struct vm_area_struct *vma, unsigned long address,
74899 unsigned int flags, unsigned long *prot, resource_size_t *phys);
74900-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
74901- void *buf, int len, int write);
74902+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
74903+ void *buf, size_t len, int write);
74904
74905 static inline void unmap_shared_mapping_range(struct address_space *mapping,
74906 loff_t const holebegin, loff_t const holelen)
74907@@ -1023,9 +1029,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
74908 }
74909 #endif
74910
74911-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
74912-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
74913- void *buf, int len, int write);
74914+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
74915+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
74916+ void *buf, size_t len, int write);
74917
74918 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
74919 unsigned long start, unsigned long nr_pages,
74920@@ -1057,34 +1063,6 @@ int set_page_dirty(struct page *page);
74921 int set_page_dirty_lock(struct page *page);
74922 int clear_page_dirty_for_io(struct page *page);
74923
74924-/* Is the vma a continuation of the stack vma above it? */
74925-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
74926-{
74927- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
74928-}
74929-
74930-static inline int stack_guard_page_start(struct vm_area_struct *vma,
74931- unsigned long addr)
74932-{
74933- return (vma->vm_flags & VM_GROWSDOWN) &&
74934- (vma->vm_start == addr) &&
74935- !vma_growsdown(vma->vm_prev, addr);
74936-}
74937-
74938-/* Is the vma a continuation of the stack vma below it? */
74939-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
74940-{
74941- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
74942-}
74943-
74944-static inline int stack_guard_page_end(struct vm_area_struct *vma,
74945- unsigned long addr)
74946-{
74947- return (vma->vm_flags & VM_GROWSUP) &&
74948- (vma->vm_end == addr) &&
74949- !vma_growsup(vma->vm_next, addr);
74950-}
74951-
74952 extern pid_t
74953 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
74954
74955@@ -1184,6 +1162,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
74956 }
74957 #endif
74958
74959+#ifdef CONFIG_MMU
74960+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
74961+#else
74962+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
74963+{
74964+ return __pgprot(0);
74965+}
74966+#endif
74967+
74968 int vma_wants_writenotify(struct vm_area_struct *vma);
74969
74970 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
74971@@ -1202,8 +1189,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
74972 {
74973 return 0;
74974 }
74975+
74976+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
74977+ unsigned long address)
74978+{
74979+ return 0;
74980+}
74981 #else
74982 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
74983+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
74984 #endif
74985
74986 #ifdef __PAGETABLE_PMD_FOLDED
74987@@ -1212,8 +1206,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
74988 {
74989 return 0;
74990 }
74991+
74992+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
74993+ unsigned long address)
74994+{
74995+ return 0;
74996+}
74997 #else
74998 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
74999+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
75000 #endif
75001
75002 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
75003@@ -1231,11 +1232,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
75004 NULL: pud_offset(pgd, address);
75005 }
75006
75007+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
75008+{
75009+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
75010+ NULL: pud_offset(pgd, address);
75011+}
75012+
75013 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
75014 {
75015 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
75016 NULL: pmd_offset(pud, address);
75017 }
75018+
75019+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
75020+{
75021+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
75022+ NULL: pmd_offset(pud, address);
75023+}
75024 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
75025
75026 #if USE_SPLIT_PTLOCKS
75027@@ -1531,6 +1544,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75028 unsigned long len, unsigned long prot, unsigned long flags,
75029 unsigned long pgoff, unsigned long *populate);
75030 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
75031+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
75032
75033 #ifdef CONFIG_MMU
75034 extern int __mm_populate(unsigned long addr, unsigned long len,
75035@@ -1559,10 +1573,11 @@ struct vm_unmapped_area_info {
75036 unsigned long high_limit;
75037 unsigned long align_mask;
75038 unsigned long align_offset;
75039+ unsigned long threadstack_offset;
75040 };
75041
75042-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
75043-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
75044+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
75045+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
75046
75047 /*
75048 * Search for an unmapped address range.
75049@@ -1574,7 +1589,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
75050 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
75051 */
75052 static inline unsigned long
75053-vm_unmapped_area(struct vm_unmapped_area_info *info)
75054+vm_unmapped_area(const struct vm_unmapped_area_info *info)
75055 {
75056 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
75057 return unmapped_area(info);
75058@@ -1637,6 +1652,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
75059 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
75060 struct vm_area_struct **pprev);
75061
75062+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
75063+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
75064+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
75065+
75066 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
75067 NULL if none. Assume start_addr < end_addr. */
75068 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
75069@@ -1665,15 +1684,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
75070 return vma;
75071 }
75072
75073-#ifdef CONFIG_MMU
75074-pgprot_t vm_get_page_prot(unsigned long vm_flags);
75075-#else
75076-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
75077-{
75078- return __pgprot(0);
75079-}
75080-#endif
75081-
75082 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
75083 unsigned long change_prot_numa(struct vm_area_struct *vma,
75084 unsigned long start, unsigned long end);
75085@@ -1725,6 +1735,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
75086 static inline void vm_stat_account(struct mm_struct *mm,
75087 unsigned long flags, struct file *file, long pages)
75088 {
75089+
75090+#ifdef CONFIG_PAX_RANDMMAP
75091+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
75092+#endif
75093+
75094 mm->total_vm += pages;
75095 }
75096 #endif /* CONFIG_PROC_FS */
75097@@ -1805,7 +1820,7 @@ extern int unpoison_memory(unsigned long pfn);
75098 extern int sysctl_memory_failure_early_kill;
75099 extern int sysctl_memory_failure_recovery;
75100 extern void shake_page(struct page *p, int access);
75101-extern atomic_long_t num_poisoned_pages;
75102+extern atomic_long_unchecked_t num_poisoned_pages;
75103 extern int soft_offline_page(struct page *page, int flags);
75104
75105 extern void dump_page(struct page *page);
75106@@ -1842,5 +1857,11 @@ void __init setup_nr_node_ids(void);
75107 static inline void setup_nr_node_ids(void) {}
75108 #endif
75109
75110+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
75111+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
75112+#else
75113+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
75114+#endif
75115+
75116 #endif /* __KERNEL__ */
75117 #endif /* _LINUX_MM_H */
75118diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
75119index faf4b7c..1e70c6e 100644
75120--- a/include/linux/mm_types.h
75121+++ b/include/linux/mm_types.h
75122@@ -289,6 +289,8 @@ struct vm_area_struct {
75123 #ifdef CONFIG_NUMA
75124 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
75125 #endif
75126+
75127+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
75128 };
75129
75130 struct core_thread {
75131@@ -435,6 +437,24 @@ struct mm_struct {
75132 int first_nid;
75133 #endif
75134 struct uprobes_state uprobes_state;
75135+
75136+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
75137+ unsigned long pax_flags;
75138+#endif
75139+
75140+#ifdef CONFIG_PAX_DLRESOLVE
75141+ unsigned long call_dl_resolve;
75142+#endif
75143+
75144+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
75145+ unsigned long call_syscall;
75146+#endif
75147+
75148+#ifdef CONFIG_PAX_ASLR
75149+ unsigned long delta_mmap; /* randomized offset */
75150+ unsigned long delta_stack; /* randomized offset */
75151+#endif
75152+
75153 };
75154
75155 /* first nid will either be a valid NID or one of these values */
75156diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
75157index c5d5278..f0b68c8 100644
75158--- a/include/linux/mmiotrace.h
75159+++ b/include/linux/mmiotrace.h
75160@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
75161 /* Called from ioremap.c */
75162 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
75163 void __iomem *addr);
75164-extern void mmiotrace_iounmap(volatile void __iomem *addr);
75165+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
75166
75167 /* For anyone to insert markers. Remember trailing newline. */
75168 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
75169@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
75170 {
75171 }
75172
75173-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
75174+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
75175 {
75176 }
75177
75178diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
75179index af4a3b7..9ad8889 100644
75180--- a/include/linux/mmzone.h
75181+++ b/include/linux/mmzone.h
75182@@ -396,7 +396,7 @@ struct zone {
75183 unsigned long flags; /* zone flags, see below */
75184
75185 /* Zone statistics */
75186- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
75187+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
75188
75189 /*
75190 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
75191diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
75192index 45e9214..a7227d6 100644
75193--- a/include/linux/mod_devicetable.h
75194+++ b/include/linux/mod_devicetable.h
75195@@ -13,7 +13,7 @@
75196 typedef unsigned long kernel_ulong_t;
75197 #endif
75198
75199-#define PCI_ANY_ID (~0)
75200+#define PCI_ANY_ID ((__u16)~0)
75201
75202 struct pci_device_id {
75203 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
75204@@ -139,7 +139,7 @@ struct usb_device_id {
75205 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
75206 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
75207
75208-#define HID_ANY_ID (~0)
75209+#define HID_ANY_ID (~0U)
75210 #define HID_BUS_ANY 0xffff
75211 #define HID_GROUP_ANY 0x0000
75212
75213@@ -467,7 +467,7 @@ struct dmi_system_id {
75214 const char *ident;
75215 struct dmi_strmatch matches[4];
75216 void *driver_data;
75217-};
75218+} __do_const;
75219 /*
75220 * struct dmi_device_id appears during expansion of
75221 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
75222diff --git a/include/linux/module.h b/include/linux/module.h
75223index 46f1ea0..a34ca37 100644
75224--- a/include/linux/module.h
75225+++ b/include/linux/module.h
75226@@ -17,9 +17,11 @@
75227 #include <linux/moduleparam.h>
75228 #include <linux/tracepoint.h>
75229 #include <linux/export.h>
75230+#include <linux/fs.h>
75231
75232 #include <linux/percpu.h>
75233 #include <asm/module.h>
75234+#include <asm/pgtable.h>
75235
75236 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
75237 #define MODULE_SIG_STRING "~Module signature appended~\n"
75238@@ -54,12 +56,13 @@ struct module_attribute {
75239 int (*test)(struct module *);
75240 void (*free)(struct module *);
75241 };
75242+typedef struct module_attribute __no_const module_attribute_no_const;
75243
75244 struct module_version_attribute {
75245 struct module_attribute mattr;
75246 const char *module_name;
75247 const char *version;
75248-} __attribute__ ((__aligned__(sizeof(void *))));
75249+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
75250
75251 extern ssize_t __modver_version_show(struct module_attribute *,
75252 struct module_kobject *, char *);
75253@@ -232,7 +235,7 @@ struct module
75254
75255 /* Sysfs stuff. */
75256 struct module_kobject mkobj;
75257- struct module_attribute *modinfo_attrs;
75258+ module_attribute_no_const *modinfo_attrs;
75259 const char *version;
75260 const char *srcversion;
75261 struct kobject *holders_dir;
75262@@ -281,19 +284,16 @@ struct module
75263 int (*init)(void);
75264
75265 /* If this is non-NULL, vfree after init() returns */
75266- void *module_init;
75267+ void *module_init_rx, *module_init_rw;
75268
75269 /* Here is the actual code + data, vfree'd on unload. */
75270- void *module_core;
75271+ void *module_core_rx, *module_core_rw;
75272
75273 /* Here are the sizes of the init and core sections */
75274- unsigned int init_size, core_size;
75275+ unsigned int init_size_rw, core_size_rw;
75276
75277 /* The size of the executable code in each section. */
75278- unsigned int init_text_size, core_text_size;
75279-
75280- /* Size of RO sections of the module (text+rodata) */
75281- unsigned int init_ro_size, core_ro_size;
75282+ unsigned int init_size_rx, core_size_rx;
75283
75284 /* Arch-specific module values */
75285 struct mod_arch_specific arch;
75286@@ -349,6 +349,10 @@ struct module
75287 #ifdef CONFIG_EVENT_TRACING
75288 struct ftrace_event_call **trace_events;
75289 unsigned int num_trace_events;
75290+ struct file_operations trace_id;
75291+ struct file_operations trace_enable;
75292+ struct file_operations trace_format;
75293+ struct file_operations trace_filter;
75294 #endif
75295 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
75296 unsigned int num_ftrace_callsites;
75297@@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
75298 bool is_module_percpu_address(unsigned long addr);
75299 bool is_module_text_address(unsigned long addr);
75300
75301+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
75302+{
75303+
75304+#ifdef CONFIG_PAX_KERNEXEC
75305+ if (ktla_ktva(addr) >= (unsigned long)start &&
75306+ ktla_ktva(addr) < (unsigned long)start + size)
75307+ return 1;
75308+#endif
75309+
75310+ return ((void *)addr >= start && (void *)addr < start + size);
75311+}
75312+
75313+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
75314+{
75315+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
75316+}
75317+
75318+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
75319+{
75320+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
75321+}
75322+
75323+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
75324+{
75325+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
75326+}
75327+
75328+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
75329+{
75330+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
75331+}
75332+
75333 static inline int within_module_core(unsigned long addr, const struct module *mod)
75334 {
75335- return (unsigned long)mod->module_core <= addr &&
75336- addr < (unsigned long)mod->module_core + mod->core_size;
75337+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
75338 }
75339
75340 static inline int within_module_init(unsigned long addr, const struct module *mod)
75341 {
75342- return (unsigned long)mod->module_init <= addr &&
75343- addr < (unsigned long)mod->module_init + mod->init_size;
75344+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
75345 }
75346
75347 /* Search for module by name: must hold module_mutex. */
75348diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
75349index 560ca53..ef621ef 100644
75350--- a/include/linux/moduleloader.h
75351+++ b/include/linux/moduleloader.h
75352@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
75353 sections. Returns NULL on failure. */
75354 void *module_alloc(unsigned long size);
75355
75356+#ifdef CONFIG_PAX_KERNEXEC
75357+void *module_alloc_exec(unsigned long size);
75358+#else
75359+#define module_alloc_exec(x) module_alloc(x)
75360+#endif
75361+
75362 /* Free memory returned from module_alloc. */
75363 void module_free(struct module *mod, void *module_region);
75364
75365+#ifdef CONFIG_PAX_KERNEXEC
75366+void module_free_exec(struct module *mod, void *module_region);
75367+#else
75368+#define module_free_exec(x, y) module_free((x), (y))
75369+#endif
75370+
75371 /*
75372 * Apply the given relocation to the (simplified) ELF. Return -error
75373 * or 0.
75374@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
75375 unsigned int relsec,
75376 struct module *me)
75377 {
75378+#ifdef CONFIG_MODULES
75379 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
75380+#endif
75381 return -ENOEXEC;
75382 }
75383 #endif
75384@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
75385 unsigned int relsec,
75386 struct module *me)
75387 {
75388+#ifdef CONFIG_MODULES
75389 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
75390+#endif
75391 return -ENOEXEC;
75392 }
75393 #endif
75394diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
75395index 27d9da3..5d94aa3 100644
75396--- a/include/linux/moduleparam.h
75397+++ b/include/linux/moduleparam.h
75398@@ -284,7 +284,7 @@ static inline void __kernel_param_unlock(void)
75399 * @len is usually just sizeof(string).
75400 */
75401 #define module_param_string(name, string, len, perm) \
75402- static const struct kparam_string __param_string_##name \
75403+ static const struct kparam_string __param_string_##name __used \
75404 = { len, string }; \
75405 __module_param_call(MODULE_PARAM_PREFIX, name, \
75406 &param_ops_string, \
75407@@ -423,7 +423,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
75408 */
75409 #define module_param_array_named(name, array, type, nump, perm) \
75410 param_check_##type(name, &(array)[0]); \
75411- static const struct kparam_array __param_arr_##name \
75412+ static const struct kparam_array __param_arr_##name __used \
75413 = { .max = ARRAY_SIZE(array), .num = nump, \
75414 .ops = &param_ops_##type, \
75415 .elemsize = sizeof(array[0]), .elem = array }; \
75416diff --git a/include/linux/namei.h b/include/linux/namei.h
75417index 5a5ff57..5ae5070 100644
75418--- a/include/linux/namei.h
75419+++ b/include/linux/namei.h
75420@@ -19,7 +19,7 @@ struct nameidata {
75421 unsigned seq;
75422 int last_type;
75423 unsigned depth;
75424- char *saved_names[MAX_NESTED_LINKS + 1];
75425+ const char *saved_names[MAX_NESTED_LINKS + 1];
75426 };
75427
75428 /*
75429@@ -84,12 +84,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
75430
75431 extern void nd_jump_link(struct nameidata *nd, struct path *path);
75432
75433-static inline void nd_set_link(struct nameidata *nd, char *path)
75434+static inline void nd_set_link(struct nameidata *nd, const char *path)
75435 {
75436 nd->saved_names[nd->depth] = path;
75437 }
75438
75439-static inline char *nd_get_link(struct nameidata *nd)
75440+static inline const char *nd_get_link(const struct nameidata *nd)
75441 {
75442 return nd->saved_names[nd->depth];
75443 }
75444diff --git a/include/linux/net.h b/include/linux/net.h
75445index 4f27575..fc8a65f 100644
75446--- a/include/linux/net.h
75447+++ b/include/linux/net.h
75448@@ -183,7 +183,7 @@ struct net_proto_family {
75449 int (*create)(struct net *net, struct socket *sock,
75450 int protocol, int kern);
75451 struct module *owner;
75452-};
75453+} __do_const;
75454
75455 struct iovec;
75456 struct kvec;
75457diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
75458index 9a41568..203d903 100644
75459--- a/include/linux/netdevice.h
75460+++ b/include/linux/netdevice.h
75461@@ -1061,6 +1061,7 @@ struct net_device_ops {
75462 int (*ndo_change_carrier)(struct net_device *dev,
75463 bool new_carrier);
75464 };
75465+typedef struct net_device_ops __no_const net_device_ops_no_const;
75466
75467 /*
75468 * The DEVICE structure.
75469@@ -1131,7 +1132,7 @@ struct net_device {
75470 int iflink;
75471
75472 struct net_device_stats stats;
75473- atomic_long_t rx_dropped; /* dropped packets by core network
75474+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
75475 * Do not use this in drivers.
75476 */
75477
75478diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
75479index de70f7b..2675e91 100644
75480--- a/include/linux/netfilter.h
75481+++ b/include/linux/netfilter.h
75482@@ -82,7 +82,7 @@ struct nf_sockopt_ops {
75483 #endif
75484 /* Use the module struct to lock set/get code in place */
75485 struct module *owner;
75486-};
75487+} __do_const;
75488
75489 /* Function to register/unregister hook points. */
75490 int nf_register_hook(struct nf_hook_ops *reg);
75491diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
75492index d80e275..c3510b8 100644
75493--- a/include/linux/netfilter/ipset/ip_set.h
75494+++ b/include/linux/netfilter/ipset/ip_set.h
75495@@ -124,7 +124,7 @@ struct ip_set_type_variant {
75496 /* Return true if "b" set is the same as "a"
75497 * according to the create set parameters */
75498 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
75499-};
75500+} __do_const;
75501
75502 /* The core set type structure */
75503 struct ip_set_type {
75504diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
75505index cadb740..d7c37c0 100644
75506--- a/include/linux/netfilter/nfnetlink.h
75507+++ b/include/linux/netfilter/nfnetlink.h
75508@@ -16,7 +16,7 @@ struct nfnl_callback {
75509 const struct nlattr * const cda[]);
75510 const struct nla_policy *policy; /* netlink attribute policy */
75511 const u_int16_t attr_count; /* number of nlattr's */
75512-};
75513+} __do_const;
75514
75515 struct nfnetlink_subsystem {
75516 const char *name;
75517diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
75518new file mode 100644
75519index 0000000..33f4af8
75520--- /dev/null
75521+++ b/include/linux/netfilter/xt_gradm.h
75522@@ -0,0 +1,9 @@
75523+#ifndef _LINUX_NETFILTER_XT_GRADM_H
75524+#define _LINUX_NETFILTER_XT_GRADM_H 1
75525+
75526+struct xt_gradm_mtinfo {
75527+ __u16 flags;
75528+ __u16 invflags;
75529+};
75530+
75531+#endif
75532diff --git a/include/linux/nls.h b/include/linux/nls.h
75533index 5dc635f..35f5e11 100644
75534--- a/include/linux/nls.h
75535+++ b/include/linux/nls.h
75536@@ -31,7 +31,7 @@ struct nls_table {
75537 const unsigned char *charset2upper;
75538 struct module *owner;
75539 struct nls_table *next;
75540-};
75541+} __do_const;
75542
75543 /* this value hold the maximum octet of charset */
75544 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
75545diff --git a/include/linux/notifier.h b/include/linux/notifier.h
75546index d14a4c3..a078786 100644
75547--- a/include/linux/notifier.h
75548+++ b/include/linux/notifier.h
75549@@ -54,7 +54,8 @@ struct notifier_block {
75550 notifier_fn_t notifier_call;
75551 struct notifier_block __rcu *next;
75552 int priority;
75553-};
75554+} __do_const;
75555+typedef struct notifier_block __no_const notifier_block_no_const;
75556
75557 struct atomic_notifier_head {
75558 spinlock_t lock;
75559diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
75560index a4c5624..79d6d88 100644
75561--- a/include/linux/oprofile.h
75562+++ b/include/linux/oprofile.h
75563@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
75564 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
75565 char const * name, ulong * val);
75566
75567-/** Create a file for read-only access to an atomic_t. */
75568+/** Create a file for read-only access to an atomic_unchecked_t. */
75569 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
75570- char const * name, atomic_t * val);
75571+ char const * name, atomic_unchecked_t * val);
75572
75573 /** create a directory */
75574 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
75575diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
75576index 8db71dc..a76bf2c 100644
75577--- a/include/linux/pci_hotplug.h
75578+++ b/include/linux/pci_hotplug.h
75579@@ -80,7 +80,8 @@ struct hotplug_slot_ops {
75580 int (*get_attention_status) (struct hotplug_slot *slot, u8 *value);
75581 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
75582 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
75583-};
75584+} __do_const;
75585+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
75586
75587 /**
75588 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
75589diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
75590index c43f6ea..2d4416f 100644
75591--- a/include/linux/perf_event.h
75592+++ b/include/linux/perf_event.h
75593@@ -328,8 +328,8 @@ struct perf_event {
75594
75595 enum perf_event_active_state state;
75596 unsigned int attach_state;
75597- local64_t count;
75598- atomic64_t child_count;
75599+ local64_t count; /* PaX: fix it one day */
75600+ atomic64_unchecked_t child_count;
75601
75602 /*
75603 * These are the total time in nanoseconds that the event
75604@@ -380,8 +380,8 @@ struct perf_event {
75605 * These accumulate total time (in nanoseconds) that children
75606 * events have been enabled and running, respectively.
75607 */
75608- atomic64_t child_total_time_enabled;
75609- atomic64_t child_total_time_running;
75610+ atomic64_unchecked_t child_total_time_enabled;
75611+ atomic64_unchecked_t child_total_time_running;
75612
75613 /*
75614 * Protect attach/detach and child_list:
75615@@ -703,7 +703,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
75616 entry->ip[entry->nr++] = ip;
75617 }
75618
75619-extern int sysctl_perf_event_paranoid;
75620+extern int sysctl_perf_event_legitimately_concerned;
75621 extern int sysctl_perf_event_mlock;
75622 extern int sysctl_perf_event_sample_rate;
75623 extern int sysctl_perf_cpu_time_max_percent;
75624@@ -718,19 +718,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
75625 loff_t *ppos);
75626
75627
75628+static inline bool perf_paranoid_any(void)
75629+{
75630+ return sysctl_perf_event_legitimately_concerned > 2;
75631+}
75632+
75633 static inline bool perf_paranoid_tracepoint_raw(void)
75634 {
75635- return sysctl_perf_event_paranoid > -1;
75636+ return sysctl_perf_event_legitimately_concerned > -1;
75637 }
75638
75639 static inline bool perf_paranoid_cpu(void)
75640 {
75641- return sysctl_perf_event_paranoid > 0;
75642+ return sysctl_perf_event_legitimately_concerned > 0;
75643 }
75644
75645 static inline bool perf_paranoid_kernel(void)
75646 {
75647- return sysctl_perf_event_paranoid > 1;
75648+ return sysctl_perf_event_legitimately_concerned > 1;
75649 }
75650
75651 extern void perf_event_init(void);
75652@@ -846,7 +851,7 @@ struct perf_pmu_events_attr {
75653 struct device_attribute attr;
75654 u64 id;
75655 const char *event_str;
75656-};
75657+} __do_const;
75658
75659 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
75660 static struct perf_pmu_events_attr _var = { \
75661diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
75662index b8809fe..ae4ccd0 100644
75663--- a/include/linux/pipe_fs_i.h
75664+++ b/include/linux/pipe_fs_i.h
75665@@ -47,10 +47,10 @@ struct pipe_inode_info {
75666 struct mutex mutex;
75667 wait_queue_head_t wait;
75668 unsigned int nrbufs, curbuf, buffers;
75669- unsigned int readers;
75670- unsigned int writers;
75671- unsigned int files;
75672- unsigned int waiting_writers;
75673+ atomic_t readers;
75674+ atomic_t writers;
75675+ atomic_t files;
75676+ atomic_t waiting_writers;
75677 unsigned int r_counter;
75678 unsigned int w_counter;
75679 struct page *tmp_page;
75680diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
75681index 5f28cae..3d23723 100644
75682--- a/include/linux/platform_data/usb-ehci-s5p.h
75683+++ b/include/linux/platform_data/usb-ehci-s5p.h
75684@@ -14,7 +14,7 @@
75685 struct s5p_ehci_platdata {
75686 int (*phy_init)(struct platform_device *pdev, int type);
75687 int (*phy_exit)(struct platform_device *pdev, int type);
75688-};
75689+} __no_const;
75690
75691 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
75692
75693diff --git a/include/linux/platform_data/usb-ohci-exynos.h b/include/linux/platform_data/usb-ohci-exynos.h
75694index c256c59..8ea94c7 100644
75695--- a/include/linux/platform_data/usb-ohci-exynos.h
75696+++ b/include/linux/platform_data/usb-ohci-exynos.h
75697@@ -14,7 +14,7 @@
75698 struct exynos4_ohci_platdata {
75699 int (*phy_init)(struct platform_device *pdev, int type);
75700 int (*phy_exit)(struct platform_device *pdev, int type);
75701-};
75702+} __no_const;
75703
75704 extern void exynos4_ohci_set_platdata(struct exynos4_ohci_platdata *pd);
75705
75706diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
75707index 7c1d252..c5c773e 100644
75708--- a/include/linux/pm_domain.h
75709+++ b/include/linux/pm_domain.h
75710@@ -48,7 +48,7 @@ struct gpd_dev_ops {
75711
75712 struct gpd_cpu_data {
75713 unsigned int saved_exit_latency;
75714- struct cpuidle_state *idle_state;
75715+ cpuidle_state_no_const *idle_state;
75716 };
75717
75718 struct generic_pm_domain {
75719diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
75720index 6fa7cea..7bf6415 100644
75721--- a/include/linux/pm_runtime.h
75722+++ b/include/linux/pm_runtime.h
75723@@ -103,7 +103,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
75724
75725 static inline void pm_runtime_mark_last_busy(struct device *dev)
75726 {
75727- ACCESS_ONCE(dev->power.last_busy) = jiffies;
75728+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
75729 }
75730
75731 #else /* !CONFIG_PM_RUNTIME */
75732diff --git a/include/linux/pnp.h b/include/linux/pnp.h
75733index 195aafc..49a7bc2 100644
75734--- a/include/linux/pnp.h
75735+++ b/include/linux/pnp.h
75736@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
75737 struct pnp_fixup {
75738 char id[7];
75739 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
75740-};
75741+} __do_const;
75742
75743 /* config parameters */
75744 #define PNP_CONFIG_NORMAL 0x0001
75745diff --git a/include/linux/poison.h b/include/linux/poison.h
75746index 2110a81..13a11bb 100644
75747--- a/include/linux/poison.h
75748+++ b/include/linux/poison.h
75749@@ -19,8 +19,8 @@
75750 * under normal circumstances, used to verify that nobody uses
75751 * non-initialized list entries.
75752 */
75753-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
75754-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
75755+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
75756+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
75757
75758 /********** include/linux/timer.h **********/
75759 /*
75760diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
75761index d8b187c3..9a9257a 100644
75762--- a/include/linux/power/smartreflex.h
75763+++ b/include/linux/power/smartreflex.h
75764@@ -238,7 +238,7 @@ struct omap_sr_class_data {
75765 int (*notify)(struct omap_sr *sr, u32 status);
75766 u8 notify_flags;
75767 u8 class_type;
75768-};
75769+} __do_const;
75770
75771 /**
75772 * struct omap_sr_nvalue_table - Smartreflex n-target value info
75773diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
75774index 4ea1d37..80f4b33 100644
75775--- a/include/linux/ppp-comp.h
75776+++ b/include/linux/ppp-comp.h
75777@@ -84,7 +84,7 @@ struct compressor {
75778 struct module *owner;
75779 /* Extra skb space needed by the compressor algorithm */
75780 unsigned int comp_extra;
75781-};
75782+} __do_const;
75783
75784 /*
75785 * The return value from decompress routine is the length of the
75786diff --git a/include/linux/preempt.h b/include/linux/preempt.h
75787index f5d4723..a6ea2fa 100644
75788--- a/include/linux/preempt.h
75789+++ b/include/linux/preempt.h
75790@@ -18,8 +18,13 @@
75791 # define sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
75792 #endif
75793
75794+#define raw_add_preempt_count(val) do { preempt_count() += (val); } while (0)
75795+#define raw_sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
75796+
75797 #define inc_preempt_count() add_preempt_count(1)
75798+#define raw_inc_preempt_count() raw_add_preempt_count(1)
75799 #define dec_preempt_count() sub_preempt_count(1)
75800+#define raw_dec_preempt_count() raw_sub_preempt_count(1)
75801
75802 #define preempt_count() (current_thread_info()->preempt_count)
75803
75804@@ -64,6 +69,12 @@ do { \
75805 barrier(); \
75806 } while (0)
75807
75808+#define raw_preempt_disable() \
75809+do { \
75810+ raw_inc_preempt_count(); \
75811+ barrier(); \
75812+} while (0)
75813+
75814 #define sched_preempt_enable_no_resched() \
75815 do { \
75816 barrier(); \
75817@@ -72,6 +83,12 @@ do { \
75818
75819 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
75820
75821+#define raw_preempt_enable_no_resched() \
75822+do { \
75823+ barrier(); \
75824+ raw_dec_preempt_count(); \
75825+} while (0)
75826+
75827 #define preempt_enable() \
75828 do { \
75829 preempt_enable_no_resched(); \
75830@@ -116,8 +133,10 @@ do { \
75831 * region.
75832 */
75833 #define preempt_disable() barrier()
75834+#define raw_preempt_disable() barrier()
75835 #define sched_preempt_enable_no_resched() barrier()
75836 #define preempt_enable_no_resched() barrier()
75837+#define raw_preempt_enable_no_resched() barrier()
75838 #define preempt_enable() barrier()
75839
75840 #define preempt_disable_notrace() barrier()
75841diff --git a/include/linux/printk.h b/include/linux/printk.h
75842index 22c7052..ad3fa0a 100644
75843--- a/include/linux/printk.h
75844+++ b/include/linux/printk.h
75845@@ -106,6 +106,8 @@ static inline __printf(1, 2) __cold
75846 void early_printk(const char *s, ...) { }
75847 #endif
75848
75849+extern int kptr_restrict;
75850+
75851 #ifdef CONFIG_PRINTK
75852 asmlinkage __printf(5, 0)
75853 int vprintk_emit(int facility, int level,
75854@@ -140,7 +142,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
75855
75856 extern int printk_delay_msec;
75857 extern int dmesg_restrict;
75858-extern int kptr_restrict;
75859
75860 extern void wake_up_klogd(void);
75861
75862diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
75863index 608e60a..c26f864 100644
75864--- a/include/linux/proc_fs.h
75865+++ b/include/linux/proc_fs.h
75866@@ -34,6 +34,19 @@ static inline struct proc_dir_entry *proc_create(
75867 return proc_create_data(name, mode, parent, proc_fops, NULL);
75868 }
75869
75870+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
75871+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
75872+{
75873+#ifdef CONFIG_GRKERNSEC_PROC_USER
75874+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
75875+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75876+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
75877+#else
75878+ return proc_create_data(name, mode, parent, proc_fops, NULL);
75879+#endif
75880+}
75881+
75882+
75883 extern void proc_set_size(struct proc_dir_entry *, loff_t);
75884 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
75885 extern void *PDE_DATA(const struct inode *);
75886diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
75887index 34a1e10..03a6d03 100644
75888--- a/include/linux/proc_ns.h
75889+++ b/include/linux/proc_ns.h
75890@@ -14,7 +14,7 @@ struct proc_ns_operations {
75891 void (*put)(void *ns);
75892 int (*install)(struct nsproxy *nsproxy, void *ns);
75893 unsigned int (*inum)(void *ns);
75894-};
75895+} __do_const;
75896
75897 struct proc_ns {
75898 void *ns;
75899diff --git a/include/linux/random.h b/include/linux/random.h
75900index 6312dd9..2561947 100644
75901--- a/include/linux/random.h
75902+++ b/include/linux/random.h
75903@@ -10,9 +10,19 @@
75904
75905
75906 extern void add_device_randomness(const void *, unsigned int);
75907+
75908+static inline void add_latent_entropy(void)
75909+{
75910+
75911+#ifdef LATENT_ENTROPY_PLUGIN
75912+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
75913+#endif
75914+
75915+}
75916+
75917 extern void add_input_randomness(unsigned int type, unsigned int code,
75918- unsigned int value);
75919-extern void add_interrupt_randomness(int irq, int irq_flags);
75920+ unsigned int value) __latent_entropy;
75921+extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
75922
75923 extern void get_random_bytes(void *buf, int nbytes);
75924 extern void get_random_bytes_arch(void *buf, int nbytes);
75925@@ -33,6 +43,11 @@ void prandom_seed(u32 seed);
75926 u32 prandom_u32_state(struct rnd_state *);
75927 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
75928
75929+static inline unsigned long pax_get_random_long(void)
75930+{
75931+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
75932+}
75933+
75934 /*
75935 * Handle minimum values for seeds
75936 */
75937diff --git a/include/linux/rculist.h b/include/linux/rculist.h
75938index 4106721..132d42c 100644
75939--- a/include/linux/rculist.h
75940+++ b/include/linux/rculist.h
75941@@ -44,6 +44,9 @@ extern void __list_add_rcu(struct list_head *new,
75942 struct list_head *prev, struct list_head *next);
75943 #endif
75944
75945+extern void __pax_list_add_rcu(struct list_head *new,
75946+ struct list_head *prev, struct list_head *next);
75947+
75948 /**
75949 * list_add_rcu - add a new entry to rcu-protected list
75950 * @new: new entry to be added
75951@@ -65,6 +68,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
75952 __list_add_rcu(new, head, head->next);
75953 }
75954
75955+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
75956+{
75957+ __pax_list_add_rcu(new, head, head->next);
75958+}
75959+
75960 /**
75961 * list_add_tail_rcu - add a new entry to rcu-protected list
75962 * @new: new entry to be added
75963@@ -87,6 +95,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
75964 __list_add_rcu(new, head->prev, head);
75965 }
75966
75967+static inline void pax_list_add_tail_rcu(struct list_head *new,
75968+ struct list_head *head)
75969+{
75970+ __pax_list_add_rcu(new, head->prev, head);
75971+}
75972+
75973 /**
75974 * list_del_rcu - deletes entry from list without re-initialization
75975 * @entry: the element to delete from the list.
75976@@ -117,6 +131,8 @@ static inline void list_del_rcu(struct list_head *entry)
75977 entry->prev = LIST_POISON2;
75978 }
75979
75980+extern void pax_list_del_rcu(struct list_head *entry);
75981+
75982 /**
75983 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
75984 * @n: the element to delete from the hash list.
75985diff --git a/include/linux/reboot.h b/include/linux/reboot.h
75986index 8e00f9f..9449b55 100644
75987--- a/include/linux/reboot.h
75988+++ b/include/linux/reboot.h
75989@@ -43,9 +43,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
75990 * Architecture-specific implementations of sys_reboot commands.
75991 */
75992
75993-extern void machine_restart(char *cmd);
75994-extern void machine_halt(void);
75995-extern void machine_power_off(void);
75996+extern void machine_restart(char *cmd) __noreturn;
75997+extern void machine_halt(void) __noreturn;
75998+extern void machine_power_off(void) __noreturn;
75999
76000 extern void machine_shutdown(void);
76001 struct pt_regs;
76002@@ -56,9 +56,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
76003 */
76004
76005 extern void kernel_restart_prepare(char *cmd);
76006-extern void kernel_restart(char *cmd);
76007-extern void kernel_halt(void);
76008-extern void kernel_power_off(void);
76009+extern void kernel_restart(char *cmd) __noreturn;
76010+extern void kernel_halt(void) __noreturn;
76011+extern void kernel_power_off(void) __noreturn;
76012
76013 extern int C_A_D; /* for sysctl */
76014 void ctrl_alt_del(void);
76015@@ -72,7 +72,7 @@ extern int orderly_poweroff(bool force);
76016 * Emergency restart, callable from an interrupt handler.
76017 */
76018
76019-extern void emergency_restart(void);
76020+extern void emergency_restart(void) __noreturn;
76021 #include <asm/emergency-restart.h>
76022
76023 #endif /* _LINUX_REBOOT_H */
76024diff --git a/include/linux/regset.h b/include/linux/regset.h
76025index 8e0c9fe..ac4d221 100644
76026--- a/include/linux/regset.h
76027+++ b/include/linux/regset.h
76028@@ -161,7 +161,8 @@ struct user_regset {
76029 unsigned int align;
76030 unsigned int bias;
76031 unsigned int core_note_type;
76032-};
76033+} __do_const;
76034+typedef struct user_regset __no_const user_regset_no_const;
76035
76036 /**
76037 * struct user_regset_view - available regsets
76038diff --git a/include/linux/relay.h b/include/linux/relay.h
76039index d7c8359..818daf5 100644
76040--- a/include/linux/relay.h
76041+++ b/include/linux/relay.h
76042@@ -157,7 +157,7 @@ struct rchan_callbacks
76043 * The callback should return 0 if successful, negative if not.
76044 */
76045 int (*remove_buf_file)(struct dentry *dentry);
76046-};
76047+} __no_const;
76048
76049 /*
76050 * CONFIG_RELAY kernel API, kernel/relay.c
76051diff --git a/include/linux/rio.h b/include/linux/rio.h
76052index b71d573..2f940bd 100644
76053--- a/include/linux/rio.h
76054+++ b/include/linux/rio.h
76055@@ -355,7 +355,7 @@ struct rio_ops {
76056 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
76057 u64 rstart, u32 size, u32 flags);
76058 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
76059-};
76060+} __no_const;
76061
76062 #define RIO_RESOURCE_MEM 0x00000100
76063 #define RIO_RESOURCE_DOORBELL 0x00000200
76064diff --git a/include/linux/rmap.h b/include/linux/rmap.h
76065index 6dacb93..6174423 100644
76066--- a/include/linux/rmap.h
76067+++ b/include/linux/rmap.h
76068@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
76069 void anon_vma_init(void); /* create anon_vma_cachep */
76070 int anon_vma_prepare(struct vm_area_struct *);
76071 void unlink_anon_vmas(struct vm_area_struct *);
76072-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
76073-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
76074+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
76075+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
76076
76077 static inline void anon_vma_merge(struct vm_area_struct *vma,
76078 struct vm_area_struct *next)
76079diff --git a/include/linux/sched.h b/include/linux/sched.h
76080index 078066d..4090b3b 100644
76081--- a/include/linux/sched.h
76082+++ b/include/linux/sched.h
76083@@ -62,6 +62,7 @@ struct bio_list;
76084 struct fs_struct;
76085 struct perf_event_context;
76086 struct blk_plug;
76087+struct linux_binprm;
76088
76089 /*
76090 * List of flags we want to share for kernel threads,
76091@@ -303,7 +304,7 @@ extern char __sched_text_start[], __sched_text_end[];
76092 extern int in_sched_functions(unsigned long addr);
76093
76094 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
76095-extern signed long schedule_timeout(signed long timeout);
76096+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
76097 extern signed long schedule_timeout_interruptible(signed long timeout);
76098 extern signed long schedule_timeout_killable(signed long timeout);
76099 extern signed long schedule_timeout_uninterruptible(signed long timeout);
76100@@ -314,6 +315,19 @@ struct nsproxy;
76101 struct user_namespace;
76102
76103 #ifdef CONFIG_MMU
76104+
76105+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
76106+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
76107+#else
76108+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
76109+{
76110+ return 0;
76111+}
76112+#endif
76113+
76114+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
76115+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
76116+
76117 extern void arch_pick_mmap_layout(struct mm_struct *mm);
76118 extern unsigned long
76119 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
76120@@ -589,6 +603,17 @@ struct signal_struct {
76121 #ifdef CONFIG_TASKSTATS
76122 struct taskstats *stats;
76123 #endif
76124+
76125+#ifdef CONFIG_GRKERNSEC
76126+ u32 curr_ip;
76127+ u32 saved_ip;
76128+ u32 gr_saddr;
76129+ u32 gr_daddr;
76130+ u16 gr_sport;
76131+ u16 gr_dport;
76132+ u8 used_accept:1;
76133+#endif
76134+
76135 #ifdef CONFIG_AUDIT
76136 unsigned audit_tty;
76137 unsigned audit_tty_log_passwd;
76138@@ -669,6 +694,14 @@ struct user_struct {
76139 struct key *session_keyring; /* UID's default session keyring */
76140 #endif
76141
76142+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
76143+ unsigned char kernel_banned;
76144+#endif
76145+#ifdef CONFIG_GRKERNSEC_BRUTE
76146+ unsigned char suid_banned;
76147+ unsigned long suid_ban_expires;
76148+#endif
76149+
76150 /* Hash table maintenance information */
76151 struct hlist_node uidhash_node;
76152 kuid_t uid;
76153@@ -1151,8 +1184,8 @@ struct task_struct {
76154 struct list_head thread_group;
76155
76156 struct completion *vfork_done; /* for vfork() */
76157- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
76158- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
76159+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
76160+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
76161
76162 cputime_t utime, stime, utimescaled, stimescaled;
76163 cputime_t gtime;
76164@@ -1177,11 +1210,6 @@ struct task_struct {
76165 struct task_cputime cputime_expires;
76166 struct list_head cpu_timers[3];
76167
76168-/* process credentials */
76169- const struct cred __rcu *real_cred; /* objective and real subjective task
76170- * credentials (COW) */
76171- const struct cred __rcu *cred; /* effective (overridable) subjective task
76172- * credentials (COW) */
76173 char comm[TASK_COMM_LEN]; /* executable name excluding path
76174 - access with [gs]et_task_comm (which lock
76175 it with task_lock())
76176@@ -1198,6 +1226,10 @@ struct task_struct {
76177 #endif
76178 /* CPU-specific state of this task */
76179 struct thread_struct thread;
76180+/* thread_info moved to task_struct */
76181+#ifdef CONFIG_X86
76182+ struct thread_info tinfo;
76183+#endif
76184 /* filesystem information */
76185 struct fs_struct *fs;
76186 /* open file information */
76187@@ -1271,6 +1303,10 @@ struct task_struct {
76188 gfp_t lockdep_reclaim_gfp;
76189 #endif
76190
76191+/* process credentials */
76192+ const struct cred __rcu *real_cred; /* objective and real subjective task
76193+ * credentials (COW) */
76194+
76195 /* journalling filesystem info */
76196 void *journal_info;
76197
76198@@ -1309,6 +1345,10 @@ struct task_struct {
76199 /* cg_list protected by css_set_lock and tsk->alloc_lock */
76200 struct list_head cg_list;
76201 #endif
76202+
76203+ const struct cred __rcu *cred; /* effective (overridable) subjective task
76204+ * credentials (COW) */
76205+
76206 #ifdef CONFIG_FUTEX
76207 struct robust_list_head __user *robust_list;
76208 #ifdef CONFIG_COMPAT
76209@@ -1406,8 +1446,76 @@ struct task_struct {
76210 unsigned int sequential_io;
76211 unsigned int sequential_io_avg;
76212 #endif
76213+
76214+#ifdef CONFIG_GRKERNSEC
76215+ /* grsecurity */
76216+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
76217+ u64 exec_id;
76218+#endif
76219+#ifdef CONFIG_GRKERNSEC_SETXID
76220+ const struct cred *delayed_cred;
76221+#endif
76222+ struct dentry *gr_chroot_dentry;
76223+ struct acl_subject_label *acl;
76224+ struct acl_role_label *role;
76225+ struct file *exec_file;
76226+ unsigned long brute_expires;
76227+ u16 acl_role_id;
76228+ /* is this the task that authenticated to the special role */
76229+ u8 acl_sp_role;
76230+ u8 is_writable;
76231+ u8 brute;
76232+ u8 gr_is_chrooted;
76233+#endif
76234+
76235 };
76236
76237+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
76238+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
76239+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
76240+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
76241+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
76242+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
76243+
76244+#ifdef CONFIG_PAX_SOFTMODE
76245+extern int pax_softmode;
76246+#endif
76247+
76248+extern int pax_check_flags(unsigned long *);
76249+
76250+/* if tsk != current then task_lock must be held on it */
76251+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
76252+static inline unsigned long pax_get_flags(struct task_struct *tsk)
76253+{
76254+ if (likely(tsk->mm))
76255+ return tsk->mm->pax_flags;
76256+ else
76257+ return 0UL;
76258+}
76259+
76260+/* if tsk != current then task_lock must be held on it */
76261+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
76262+{
76263+ if (likely(tsk->mm)) {
76264+ tsk->mm->pax_flags = flags;
76265+ return 0;
76266+ }
76267+ return -EINVAL;
76268+}
76269+#endif
76270+
76271+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
76272+extern void pax_set_initial_flags(struct linux_binprm *bprm);
76273+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
76274+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
76275+#endif
76276+
76277+struct path;
76278+extern char *pax_get_path(const struct path *path, char *buf, int buflen);
76279+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
76280+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
76281+extern void pax_report_refcount_overflow(struct pt_regs *regs);
76282+
76283 /* Future-safe accessor for struct task_struct's cpus_allowed. */
76284 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
76285
76286@@ -1466,7 +1574,7 @@ struct pid_namespace;
76287 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
76288 struct pid_namespace *ns);
76289
76290-static inline pid_t task_pid_nr(struct task_struct *tsk)
76291+static inline pid_t task_pid_nr(const struct task_struct *tsk)
76292 {
76293 return tsk->pid;
76294 }
76295@@ -1916,7 +2024,9 @@ void yield(void);
76296 extern struct exec_domain default_exec_domain;
76297
76298 union thread_union {
76299+#ifndef CONFIG_X86
76300 struct thread_info thread_info;
76301+#endif
76302 unsigned long stack[THREAD_SIZE/sizeof(long)];
76303 };
76304
76305@@ -1949,6 +2059,7 @@ extern struct pid_namespace init_pid_ns;
76306 */
76307
76308 extern struct task_struct *find_task_by_vpid(pid_t nr);
76309+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
76310 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
76311 struct pid_namespace *ns);
76312
76313@@ -2113,7 +2224,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
76314 extern void exit_itimers(struct signal_struct *);
76315 extern void flush_itimer_signals(void);
76316
76317-extern void do_group_exit(int);
76318+extern __noreturn void do_group_exit(int);
76319
76320 extern int allow_signal(int);
76321 extern int disallow_signal(int);
76322@@ -2304,9 +2415,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
76323
76324 #endif
76325
76326-static inline int object_is_on_stack(void *obj)
76327+static inline int object_starts_on_stack(void *obj)
76328 {
76329- void *stack = task_stack_page(current);
76330+ const void *stack = task_stack_page(current);
76331
76332 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
76333 }
76334diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
76335index bf8086b..962b035 100644
76336--- a/include/linux/sched/sysctl.h
76337+++ b/include/linux/sched/sysctl.h
76338@@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
76339 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
76340
76341 extern int sysctl_max_map_count;
76342+extern unsigned long sysctl_heap_stack_gap;
76343
76344 extern unsigned int sysctl_sched_latency;
76345 extern unsigned int sysctl_sched_min_granularity;
76346diff --git a/include/linux/security.h b/include/linux/security.h
76347index 7ce53ae..8ee24a5 100644
76348--- a/include/linux/security.h
76349+++ b/include/linux/security.h
76350@@ -27,6 +27,7 @@
76351 #include <linux/slab.h>
76352 #include <linux/err.h>
76353 #include <linux/string.h>
76354+#include <linux/grsecurity.h>
76355
76356 struct linux_binprm;
76357 struct cred;
76358@@ -116,8 +117,6 @@ struct seq_file;
76359
76360 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
76361
76362-void reset_security_ops(void);
76363-
76364 #ifdef CONFIG_MMU
76365 extern unsigned long mmap_min_addr;
76366 extern unsigned long dac_mmap_min_addr;
76367diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
76368index 4e32edc..f8f2d18 100644
76369--- a/include/linux/seq_file.h
76370+++ b/include/linux/seq_file.h
76371@@ -26,6 +26,9 @@ struct seq_file {
76372 struct mutex lock;
76373 const struct seq_operations *op;
76374 int poll_event;
76375+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
76376+ u64 exec_id;
76377+#endif
76378 #ifdef CONFIG_USER_NS
76379 struct user_namespace *user_ns;
76380 #endif
76381@@ -38,6 +41,7 @@ struct seq_operations {
76382 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
76383 int (*show) (struct seq_file *m, void *v);
76384 };
76385+typedef struct seq_operations __no_const seq_operations_no_const;
76386
76387 #define SEQ_SKIP 1
76388
76389diff --git a/include/linux/shm.h b/include/linux/shm.h
76390index 429c199..4d42e38 100644
76391--- a/include/linux/shm.h
76392+++ b/include/linux/shm.h
76393@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
76394
76395 /* The task created the shm object. NULL if the task is dead. */
76396 struct task_struct *shm_creator;
76397+#ifdef CONFIG_GRKERNSEC
76398+ time_t shm_createtime;
76399+ pid_t shm_lapid;
76400+#endif
76401 };
76402
76403 /* shm_mode upper byte flags */
76404diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
76405index 3b71a4e..5c9f309 100644
76406--- a/include/linux/skbuff.h
76407+++ b/include/linux/skbuff.h
76408@@ -648,7 +648,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
76409 extern struct sk_buff *__alloc_skb(unsigned int size,
76410 gfp_t priority, int flags, int node);
76411 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
76412-static inline struct sk_buff *alloc_skb(unsigned int size,
76413+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
76414 gfp_t priority)
76415 {
76416 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
76417@@ -764,7 +764,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
76418 */
76419 static inline int skb_queue_empty(const struct sk_buff_head *list)
76420 {
76421- return list->next == (struct sk_buff *)list;
76422+ return list->next == (const struct sk_buff *)list;
76423 }
76424
76425 /**
76426@@ -777,7 +777,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
76427 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
76428 const struct sk_buff *skb)
76429 {
76430- return skb->next == (struct sk_buff *)list;
76431+ return skb->next == (const struct sk_buff *)list;
76432 }
76433
76434 /**
76435@@ -790,7 +790,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
76436 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
76437 const struct sk_buff *skb)
76438 {
76439- return skb->prev == (struct sk_buff *)list;
76440+ return skb->prev == (const struct sk_buff *)list;
76441 }
76442
76443 /**
76444@@ -1750,7 +1750,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
76445 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
76446 */
76447 #ifndef NET_SKB_PAD
76448-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
76449+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
76450 #endif
76451
76452 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
76453@@ -2345,7 +2345,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
76454 int noblock, int *err);
76455 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
76456 struct poll_table_struct *wait);
76457-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
76458+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
76459 int offset, struct iovec *to,
76460 int size);
76461 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
76462@@ -2636,6 +2636,9 @@ static inline void nf_reset(struct sk_buff *skb)
76463 nf_bridge_put(skb->nf_bridge);
76464 skb->nf_bridge = NULL;
76465 #endif
76466+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
76467+ skb->nf_trace = 0;
76468+#endif
76469 }
76470
76471 static inline void nf_reset_trace(struct sk_buff *skb)
76472diff --git a/include/linux/slab.h b/include/linux/slab.h
76473index 6c5cc0e..9ca0fd6 100644
76474--- a/include/linux/slab.h
76475+++ b/include/linux/slab.h
76476@@ -12,15 +12,29 @@
76477 #include <linux/gfp.h>
76478 #include <linux/types.h>
76479 #include <linux/workqueue.h>
76480-
76481+#include <linux/err.h>
76482
76483 /*
76484 * Flags to pass to kmem_cache_create().
76485 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
76486 */
76487 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
76488+
76489+#ifdef CONFIG_PAX_USERCOPY_SLABS
76490+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
76491+#else
76492+#define SLAB_USERCOPY 0x00000000UL
76493+#endif
76494+
76495 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
76496 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
76497+
76498+#ifdef CONFIG_PAX_MEMORY_SANITIZE
76499+#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
76500+#else
76501+#define SLAB_NO_SANITIZE 0x00000000UL
76502+#endif
76503+
76504 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
76505 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
76506 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
76507@@ -89,10 +103,13 @@
76508 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
76509 * Both make kfree a no-op.
76510 */
76511-#define ZERO_SIZE_PTR ((void *)16)
76512+#define ZERO_SIZE_PTR \
76513+({ \
76514+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
76515+ (void *)(-MAX_ERRNO-1L); \
76516+})
76517
76518-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
76519- (unsigned long)ZERO_SIZE_PTR)
76520+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
76521
76522
76523 struct mem_cgroup;
76524@@ -132,6 +149,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
76525 void kfree(const void *);
76526 void kzfree(const void *);
76527 size_t ksize(const void *);
76528+const char *check_heap_object(const void *ptr, unsigned long n);
76529+bool is_usercopy_object(const void *ptr);
76530
76531 /*
76532 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
76533@@ -164,7 +183,7 @@ struct kmem_cache {
76534 unsigned int align; /* Alignment as calculated */
76535 unsigned long flags; /* Active flags on the slab */
76536 const char *name; /* Slab name for sysfs */
76537- int refcount; /* Use counter */
76538+ atomic_t refcount; /* Use counter */
76539 void (*ctor)(void *); /* Called on object slot creation */
76540 struct list_head list; /* List of all slab caches on the system */
76541 };
76542@@ -238,6 +257,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
76543 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
76544 #endif
76545
76546+#ifdef CONFIG_PAX_USERCOPY_SLABS
76547+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
76548+#endif
76549+
76550 /*
76551 * Figure out which kmalloc slab an allocation of a certain size
76552 * belongs to.
76553@@ -246,7 +269,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
76554 * 2 = 120 .. 192 bytes
76555 * n = 2^(n-1) .. 2^n -1
76556 */
76557-static __always_inline int kmalloc_index(size_t size)
76558+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
76559 {
76560 if (!size)
76561 return 0;
76562@@ -492,7 +515,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
76563 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
76564 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
76565 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
76566-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
76567+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
76568 #define kmalloc_track_caller(size, flags) \
76569 __kmalloc_track_caller(size, flags, _RET_IP_)
76570 #else
76571@@ -512,7 +535,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
76572 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
76573 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
76574 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
76575-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
76576+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
76577 #define kmalloc_node_track_caller(size, flags, node) \
76578 __kmalloc_node_track_caller(size, flags, node, \
76579 _RET_IP_)
76580diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
76581index cd40158..4e2f7af 100644
76582--- a/include/linux/slab_def.h
76583+++ b/include/linux/slab_def.h
76584@@ -50,7 +50,7 @@ struct kmem_cache {
76585 /* 4) cache creation/removal */
76586 const char *name;
76587 struct list_head list;
76588- int refcount;
76589+ atomic_t refcount;
76590 int object_size;
76591 int align;
76592
76593@@ -66,10 +66,14 @@ struct kmem_cache {
76594 unsigned long node_allocs;
76595 unsigned long node_frees;
76596 unsigned long node_overflow;
76597- atomic_t allochit;
76598- atomic_t allocmiss;
76599- atomic_t freehit;
76600- atomic_t freemiss;
76601+ atomic_unchecked_t allochit;
76602+ atomic_unchecked_t allocmiss;
76603+ atomic_unchecked_t freehit;
76604+ atomic_unchecked_t freemiss;
76605+#ifdef CONFIG_PAX_MEMORY_SANITIZE
76606+ atomic_unchecked_t sanitized;
76607+ atomic_unchecked_t not_sanitized;
76608+#endif
76609
76610 /*
76611 * If debugging is enabled, then the allocator can add additional
76612@@ -103,7 +107,7 @@ struct kmem_cache {
76613 };
76614
76615 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
76616-void *__kmalloc(size_t size, gfp_t flags);
76617+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
76618
76619 #ifdef CONFIG_TRACING
76620 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
76621@@ -136,6 +140,13 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76622 cachep = kmalloc_dma_caches[i];
76623 else
76624 #endif
76625+
76626+#ifdef CONFIG_PAX_USERCOPY_SLABS
76627+ if (flags & GFP_USERCOPY)
76628+ cachep = kmalloc_usercopy_caches[i];
76629+ else
76630+#endif
76631+
76632 cachep = kmalloc_caches[i];
76633
76634 ret = kmem_cache_alloc_trace(cachep, flags, size);
76635@@ -146,7 +157,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76636 }
76637
76638 #ifdef CONFIG_NUMA
76639-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
76640+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
76641 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
76642
76643 #ifdef CONFIG_TRACING
76644@@ -185,6 +196,13 @@ static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
76645 cachep = kmalloc_dma_caches[i];
76646 else
76647 #endif
76648+
76649+#ifdef CONFIG_PAX_USERCOPY_SLABS
76650+ if (flags & GFP_USERCOPY)
76651+ cachep = kmalloc_usercopy_caches[i];
76652+ else
76653+#endif
76654+
76655 cachep = kmalloc_caches[i];
76656
76657 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
76658diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
76659index 095a5a4..4b82027 100644
76660--- a/include/linux/slob_def.h
76661+++ b/include/linux/slob_def.h
76662@@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
76663 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
76664 }
76665
76666-void *__kmalloc_node(size_t size, gfp_t flags, int node);
76667+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
76668
76669 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
76670 {
76671@@ -23,7 +23,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76672 return __kmalloc_node(size, flags, NUMA_NO_NODE);
76673 }
76674
76675-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
76676+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
76677 {
76678 return kmalloc(size, flags);
76679 }
76680diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
76681index 027276f..092bfe8 100644
76682--- a/include/linux/slub_def.h
76683+++ b/include/linux/slub_def.h
76684@@ -80,7 +80,7 @@ struct kmem_cache {
76685 struct kmem_cache_order_objects max;
76686 struct kmem_cache_order_objects min;
76687 gfp_t allocflags; /* gfp flags to use on each alloc */
76688- int refcount; /* Refcount for slab cache destroy */
76689+ atomic_t refcount; /* Refcount for slab cache destroy */
76690 void (*ctor)(void *);
76691 int inuse; /* Offset to metadata */
76692 int align; /* Alignment */
76693@@ -105,7 +105,7 @@ struct kmem_cache {
76694 };
76695
76696 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
76697-void *__kmalloc(size_t size, gfp_t flags);
76698+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
76699
76700 static __always_inline void *
76701 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
76702@@ -149,7 +149,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
76703 }
76704 #endif
76705
76706-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
76707+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
76708 {
76709 unsigned int order = get_order(size);
76710 return kmalloc_order_trace(size, flags, order);
76711@@ -175,7 +175,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76712 }
76713
76714 #ifdef CONFIG_NUMA
76715-void *__kmalloc_node(size_t size, gfp_t flags, int node);
76716+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
76717 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
76718
76719 #ifdef CONFIG_TRACING
76720diff --git a/include/linux/smp.h b/include/linux/smp.h
76721index c181399..09d7b92 100644
76722--- a/include/linux/smp.h
76723+++ b/include/linux/smp.h
76724@@ -217,7 +217,9 @@ static inline void kick_all_cpus_sync(void) { }
76725 #endif
76726
76727 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
76728+#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
76729 #define put_cpu() preempt_enable()
76730+#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
76731
76732 /*
76733 * Callback to arch code if there's nosmp or maxcpus=0 on the
76734diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
76735index 54f91d3..be2c379 100644
76736--- a/include/linux/sock_diag.h
76737+++ b/include/linux/sock_diag.h
76738@@ -11,7 +11,7 @@ struct sock;
76739 struct sock_diag_handler {
76740 __u8 family;
76741 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
76742-};
76743+} __do_const;
76744
76745 int sock_diag_register(const struct sock_diag_handler *h);
76746 void sock_diag_unregister(const struct sock_diag_handler *h);
76747diff --git a/include/linux/sonet.h b/include/linux/sonet.h
76748index 680f9a3..f13aeb0 100644
76749--- a/include/linux/sonet.h
76750+++ b/include/linux/sonet.h
76751@@ -7,7 +7,7 @@
76752 #include <uapi/linux/sonet.h>
76753
76754 struct k_sonet_stats {
76755-#define __HANDLE_ITEM(i) atomic_t i
76756+#define __HANDLE_ITEM(i) atomic_unchecked_t i
76757 __SONET_ITEMS
76758 #undef __HANDLE_ITEM
76759 };
76760diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
76761index 07d8e53..dc934c9 100644
76762--- a/include/linux/sunrpc/addr.h
76763+++ b/include/linux/sunrpc/addr.h
76764@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
76765 {
76766 switch (sap->sa_family) {
76767 case AF_INET:
76768- return ntohs(((struct sockaddr_in *)sap)->sin_port);
76769+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
76770 case AF_INET6:
76771- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
76772+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
76773 }
76774 return 0;
76775 }
76776@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
76777 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
76778 const struct sockaddr *src)
76779 {
76780- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
76781+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
76782 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
76783
76784 dsin->sin_family = ssin->sin_family;
76785@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
76786 if (sa->sa_family != AF_INET6)
76787 return 0;
76788
76789- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
76790+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
76791 }
76792
76793 #endif /* _LINUX_SUNRPC_ADDR_H */
76794diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
76795index bfe11be..12bc8c4 100644
76796--- a/include/linux/sunrpc/clnt.h
76797+++ b/include/linux/sunrpc/clnt.h
76798@@ -96,7 +96,7 @@ struct rpc_procinfo {
76799 unsigned int p_timer; /* Which RTT timer to use */
76800 u32 p_statidx; /* Which procedure to account */
76801 const char * p_name; /* name of procedure */
76802-};
76803+} __do_const;
76804
76805 #ifdef __KERNEL__
76806
76807diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
76808index 1f0216b..6a4fa50 100644
76809--- a/include/linux/sunrpc/svc.h
76810+++ b/include/linux/sunrpc/svc.h
76811@@ -411,7 +411,7 @@ struct svc_procedure {
76812 unsigned int pc_count; /* call count */
76813 unsigned int pc_cachetype; /* cache info (NFS) */
76814 unsigned int pc_xdrressize; /* maximum size of XDR reply */
76815-};
76816+} __do_const;
76817
76818 /*
76819 * Function prototypes.
76820diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
76821index 0b8e3e6..33e0a01 100644
76822--- a/include/linux/sunrpc/svc_rdma.h
76823+++ b/include/linux/sunrpc/svc_rdma.h
76824@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
76825 extern unsigned int svcrdma_max_requests;
76826 extern unsigned int svcrdma_max_req_size;
76827
76828-extern atomic_t rdma_stat_recv;
76829-extern atomic_t rdma_stat_read;
76830-extern atomic_t rdma_stat_write;
76831-extern atomic_t rdma_stat_sq_starve;
76832-extern atomic_t rdma_stat_rq_starve;
76833-extern atomic_t rdma_stat_rq_poll;
76834-extern atomic_t rdma_stat_rq_prod;
76835-extern atomic_t rdma_stat_sq_poll;
76836-extern atomic_t rdma_stat_sq_prod;
76837+extern atomic_unchecked_t rdma_stat_recv;
76838+extern atomic_unchecked_t rdma_stat_read;
76839+extern atomic_unchecked_t rdma_stat_write;
76840+extern atomic_unchecked_t rdma_stat_sq_starve;
76841+extern atomic_unchecked_t rdma_stat_rq_starve;
76842+extern atomic_unchecked_t rdma_stat_rq_poll;
76843+extern atomic_unchecked_t rdma_stat_rq_prod;
76844+extern atomic_unchecked_t rdma_stat_sq_poll;
76845+extern atomic_unchecked_t rdma_stat_sq_prod;
76846
76847 #define RPCRDMA_VERSION 1
76848
76849diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
76850index 8d71d65..f79586e 100644
76851--- a/include/linux/sunrpc/svcauth.h
76852+++ b/include/linux/sunrpc/svcauth.h
76853@@ -120,7 +120,7 @@ struct auth_ops {
76854 int (*release)(struct svc_rqst *rq);
76855 void (*domain_release)(struct auth_domain *);
76856 int (*set_client)(struct svc_rqst *rq);
76857-};
76858+} __do_const;
76859
76860 #define SVC_GARBAGE 1
76861 #define SVC_SYSERR 2
76862diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
76863index a5ffd32..0935dea 100644
76864--- a/include/linux/swiotlb.h
76865+++ b/include/linux/swiotlb.h
76866@@ -60,7 +60,8 @@ extern void
76867
76868 extern void
76869 swiotlb_free_coherent(struct device *hwdev, size_t size,
76870- void *vaddr, dma_addr_t dma_handle);
76871+ void *vaddr, dma_addr_t dma_handle,
76872+ struct dma_attrs *attrs);
76873
76874 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
76875 unsigned long offset, size_t size,
76876diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
76877index 84662ec..5271947 100644
76878--- a/include/linux/syscalls.h
76879+++ b/include/linux/syscalls.h
76880@@ -97,8 +97,14 @@ struct sigaltstack;
76881 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
76882
76883 #define __SC_DECL(t, a) t a
76884+#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))
76885 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
76886-#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
76887+#define __SC_LONG(t, a) __typeof( \
76888+ __builtin_choose_expr( \
76889+ sizeof(t) > sizeof(int), \
76890+ (t) 0, \
76891+ __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
76892+ )) a
76893 #define __SC_CAST(t, a) (t) a
76894 #define __SC_ARGS(t, a) a
76895 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
76896@@ -362,11 +368,11 @@ asmlinkage long sys_sync(void);
76897 asmlinkage long sys_fsync(unsigned int fd);
76898 asmlinkage long sys_fdatasync(unsigned int fd);
76899 asmlinkage long sys_bdflush(int func, long data);
76900-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
76901- char __user *type, unsigned long flags,
76902+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
76903+ const char __user *type, unsigned long flags,
76904 void __user *data);
76905-asmlinkage long sys_umount(char __user *name, int flags);
76906-asmlinkage long sys_oldumount(char __user *name);
76907+asmlinkage long sys_umount(const char __user *name, int flags);
76908+asmlinkage long sys_oldumount(const char __user *name);
76909 asmlinkage long sys_truncate(const char __user *path, long length);
76910 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
76911 asmlinkage long sys_stat(const char __user *filename,
76912@@ -578,7 +584,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
76913 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
76914 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
76915 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
76916- struct sockaddr __user *, int);
76917+ struct sockaddr __user *, int) __intentional_overflow(0);
76918 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
76919 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
76920 unsigned int vlen, unsigned flags);
76921diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
76922index 27b3b0b..e093dd9 100644
76923--- a/include/linux/syscore_ops.h
76924+++ b/include/linux/syscore_ops.h
76925@@ -16,7 +16,7 @@ struct syscore_ops {
76926 int (*suspend)(void);
76927 void (*resume)(void);
76928 void (*shutdown)(void);
76929-};
76930+} __do_const;
76931
76932 extern void register_syscore_ops(struct syscore_ops *ops);
76933 extern void unregister_syscore_ops(struct syscore_ops *ops);
76934diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
76935index 14a8ff2..af52bad 100644
76936--- a/include/linux/sysctl.h
76937+++ b/include/linux/sysctl.h
76938@@ -34,13 +34,13 @@ struct ctl_table_root;
76939 struct ctl_table_header;
76940 struct ctl_dir;
76941
76942-typedef struct ctl_table ctl_table;
76943-
76944 typedef int proc_handler (struct ctl_table *ctl, int write,
76945 void __user *buffer, size_t *lenp, loff_t *ppos);
76946
76947 extern int proc_dostring(struct ctl_table *, int,
76948 void __user *, size_t *, loff_t *);
76949+extern int proc_dostring_modpriv(struct ctl_table *, int,
76950+ void __user *, size_t *, loff_t *);
76951 extern int proc_dointvec(struct ctl_table *, int,
76952 void __user *, size_t *, loff_t *);
76953 extern int proc_dointvec_minmax(struct ctl_table *, int,
76954@@ -115,7 +115,9 @@ struct ctl_table
76955 struct ctl_table_poll *poll;
76956 void *extra1;
76957 void *extra2;
76958-};
76959+} __do_const;
76960+typedef struct ctl_table __no_const ctl_table_no_const;
76961+typedef struct ctl_table ctl_table;
76962
76963 struct ctl_node {
76964 struct rb_node node;
76965diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
76966index 9e8a9b5..753de68 100644
76967--- a/include/linux/sysfs.h
76968+++ b/include/linux/sysfs.h
76969@@ -33,7 +33,8 @@ struct attribute {
76970 struct lock_class_key *key;
76971 struct lock_class_key skey;
76972 #endif
76973-};
76974+} __do_const;
76975+typedef struct attribute __no_const attribute_no_const;
76976
76977 /**
76978 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
76979@@ -62,7 +63,8 @@ struct attribute_group {
76980 struct attribute *, int);
76981 struct attribute **attrs;
76982 struct bin_attribute **bin_attrs;
76983-};
76984+} __do_const;
76985+typedef struct attribute_group __no_const attribute_group_no_const;
76986
76987 /**
76988 * Use these macros to make defining attributes easier. See include/linux/device.h
76989@@ -123,7 +125,8 @@ struct bin_attribute {
76990 char *, loff_t, size_t);
76991 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
76992 struct vm_area_struct *vma);
76993-};
76994+} __do_const;
76995+typedef struct bin_attribute __no_const bin_attribute_no_const;
76996
76997 /**
76998 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
76999diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
77000index 7faf933..9b85a0c 100644
77001--- a/include/linux/sysrq.h
77002+++ b/include/linux/sysrq.h
77003@@ -16,6 +16,7 @@
77004
77005 #include <linux/errno.h>
77006 #include <linux/types.h>
77007+#include <linux/compiler.h>
77008
77009 /* Enable/disable SYSRQ support by default (0==no, 1==yes). */
77010 #define SYSRQ_DEFAULT_ENABLE 1
77011@@ -36,7 +37,7 @@ struct sysrq_key_op {
77012 char *help_msg;
77013 char *action_msg;
77014 int enable_mask;
77015-};
77016+} __do_const;
77017
77018 #ifdef CONFIG_MAGIC_SYSRQ
77019
77020diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
77021index e7e0473..7989295 100644
77022--- a/include/linux/thread_info.h
77023+++ b/include/linux/thread_info.h
77024@@ -148,6 +148,15 @@ static inline bool test_and_clear_restore_sigmask(void)
77025 #error "no set_restore_sigmask() provided and default one won't work"
77026 #endif
77027
77028+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
77029+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
77030+{
77031+#ifndef CONFIG_PAX_USERCOPY_DEBUG
77032+ if (!__builtin_constant_p(n))
77033+#endif
77034+ __check_object_size(ptr, n, to_user);
77035+}
77036+
77037 #endif /* __KERNEL__ */
77038
77039 #endif /* _LINUX_THREAD_INFO_H */
77040diff --git a/include/linux/tty.h b/include/linux/tty.h
77041index 01ac30e..bf18a71 100644
77042--- a/include/linux/tty.h
77043+++ b/include/linux/tty.h
77044@@ -194,7 +194,7 @@ struct tty_port {
77045 const struct tty_port_operations *ops; /* Port operations */
77046 spinlock_t lock; /* Lock protecting tty field */
77047 int blocked_open; /* Waiting to open */
77048- int count; /* Usage count */
77049+ atomic_t count; /* Usage count */
77050 wait_queue_head_t open_wait; /* Open waiters */
77051 wait_queue_head_t close_wait; /* Close waiters */
77052 wait_queue_head_t delta_msr_wait; /* Modem status change */
77053@@ -547,7 +547,7 @@ extern int tty_port_open(struct tty_port *port,
77054 struct tty_struct *tty, struct file *filp);
77055 static inline int tty_port_users(struct tty_port *port)
77056 {
77057- return port->count + port->blocked_open;
77058+ return atomic_read(&port->count) + port->blocked_open;
77059 }
77060
77061 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
77062diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
77063index 756a609..b302dd6 100644
77064--- a/include/linux/tty_driver.h
77065+++ b/include/linux/tty_driver.h
77066@@ -285,7 +285,7 @@ struct tty_operations {
77067 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
77068 #endif
77069 const struct file_operations *proc_fops;
77070-};
77071+} __do_const;
77072
77073 struct tty_driver {
77074 int magic; /* magic number for this structure */
77075diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
77076index a1b0489..f02e17c 100644
77077--- a/include/linux/tty_ldisc.h
77078+++ b/include/linux/tty_ldisc.h
77079@@ -198,7 +198,7 @@ struct tty_ldisc_ops {
77080
77081 struct module *owner;
77082
77083- int refcount;
77084+ atomic_t refcount;
77085 };
77086
77087 struct tty_ldisc {
77088diff --git a/include/linux/types.h b/include/linux/types.h
77089index 4d118ba..c3ee9bf 100644
77090--- a/include/linux/types.h
77091+++ b/include/linux/types.h
77092@@ -176,10 +176,26 @@ typedef struct {
77093 int counter;
77094 } atomic_t;
77095
77096+#ifdef CONFIG_PAX_REFCOUNT
77097+typedef struct {
77098+ int counter;
77099+} atomic_unchecked_t;
77100+#else
77101+typedef atomic_t atomic_unchecked_t;
77102+#endif
77103+
77104 #ifdef CONFIG_64BIT
77105 typedef struct {
77106 long counter;
77107 } atomic64_t;
77108+
77109+#ifdef CONFIG_PAX_REFCOUNT
77110+typedef struct {
77111+ long counter;
77112+} atomic64_unchecked_t;
77113+#else
77114+typedef atomic64_t atomic64_unchecked_t;
77115+#endif
77116 #endif
77117
77118 struct list_head {
77119diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
77120index 5ca0951..ab496a5 100644
77121--- a/include/linux/uaccess.h
77122+++ b/include/linux/uaccess.h
77123@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
77124 long ret; \
77125 mm_segment_t old_fs = get_fs(); \
77126 \
77127- set_fs(KERNEL_DS); \
77128 pagefault_disable(); \
77129- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
77130- pagefault_enable(); \
77131+ set_fs(KERNEL_DS); \
77132+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
77133 set_fs(old_fs); \
77134+ pagefault_enable(); \
77135 ret; \
77136 })
77137
77138diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
77139index 8e522cbc..aa8572d 100644
77140--- a/include/linux/uidgid.h
77141+++ b/include/linux/uidgid.h
77142@@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
77143
77144 #endif /* CONFIG_USER_NS */
77145
77146+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
77147+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
77148+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
77149+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
77150+
77151 #endif /* _LINUX_UIDGID_H */
77152diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
77153index 99c1b4d..562e6f3 100644
77154--- a/include/linux/unaligned/access_ok.h
77155+++ b/include/linux/unaligned/access_ok.h
77156@@ -4,34 +4,34 @@
77157 #include <linux/kernel.h>
77158 #include <asm/byteorder.h>
77159
77160-static inline u16 get_unaligned_le16(const void *p)
77161+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
77162 {
77163- return le16_to_cpup((__le16 *)p);
77164+ return le16_to_cpup((const __le16 *)p);
77165 }
77166
77167-static inline u32 get_unaligned_le32(const void *p)
77168+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
77169 {
77170- return le32_to_cpup((__le32 *)p);
77171+ return le32_to_cpup((const __le32 *)p);
77172 }
77173
77174-static inline u64 get_unaligned_le64(const void *p)
77175+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
77176 {
77177- return le64_to_cpup((__le64 *)p);
77178+ return le64_to_cpup((const __le64 *)p);
77179 }
77180
77181-static inline u16 get_unaligned_be16(const void *p)
77182+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
77183 {
77184- return be16_to_cpup((__be16 *)p);
77185+ return be16_to_cpup((const __be16 *)p);
77186 }
77187
77188-static inline u32 get_unaligned_be32(const void *p)
77189+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
77190 {
77191- return be32_to_cpup((__be32 *)p);
77192+ return be32_to_cpup((const __be32 *)p);
77193 }
77194
77195-static inline u64 get_unaligned_be64(const void *p)
77196+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
77197 {
77198- return be64_to_cpup((__be64 *)p);
77199+ return be64_to_cpup((const __be64 *)p);
77200 }
77201
77202 static inline void put_unaligned_le16(u16 val, void *p)
77203diff --git a/include/linux/usb.h b/include/linux/usb.h
77204index 0eec268..4496526 100644
77205--- a/include/linux/usb.h
77206+++ b/include/linux/usb.h
77207@@ -560,7 +560,7 @@ struct usb_device {
77208 int maxchild;
77209
77210 u32 quirks;
77211- atomic_t urbnum;
77212+ atomic_unchecked_t urbnum;
77213
77214 unsigned long active_duration;
77215
77216@@ -1617,7 +1617,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
77217
77218 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
77219 __u8 request, __u8 requesttype, __u16 value, __u16 index,
77220- void *data, __u16 size, int timeout);
77221+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
77222 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
77223 void *data, int len, int *actual_length, int timeout);
77224 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
77225diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
77226index e452ba6..78f8e80 100644
77227--- a/include/linux/usb/renesas_usbhs.h
77228+++ b/include/linux/usb/renesas_usbhs.h
77229@@ -39,7 +39,7 @@ enum {
77230 */
77231 struct renesas_usbhs_driver_callback {
77232 int (*notify_hotplug)(struct platform_device *pdev);
77233-};
77234+} __no_const;
77235
77236 /*
77237 * callback functions for platform
77238diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
77239index 6f8fbcf..8259001 100644
77240--- a/include/linux/vermagic.h
77241+++ b/include/linux/vermagic.h
77242@@ -25,9 +25,35 @@
77243 #define MODULE_ARCH_VERMAGIC ""
77244 #endif
77245
77246+#ifdef CONFIG_PAX_REFCOUNT
77247+#define MODULE_PAX_REFCOUNT "REFCOUNT "
77248+#else
77249+#define MODULE_PAX_REFCOUNT ""
77250+#endif
77251+
77252+#ifdef CONSTIFY_PLUGIN
77253+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
77254+#else
77255+#define MODULE_CONSTIFY_PLUGIN ""
77256+#endif
77257+
77258+#ifdef STACKLEAK_PLUGIN
77259+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
77260+#else
77261+#define MODULE_STACKLEAK_PLUGIN ""
77262+#endif
77263+
77264+#ifdef CONFIG_GRKERNSEC
77265+#define MODULE_GRSEC "GRSEC "
77266+#else
77267+#define MODULE_GRSEC ""
77268+#endif
77269+
77270 #define VERMAGIC_STRING \
77271 UTS_RELEASE " " \
77272 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
77273 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
77274- MODULE_ARCH_VERMAGIC
77275+ MODULE_ARCH_VERMAGIC \
77276+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
77277+ MODULE_GRSEC
77278
77279diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
77280index 4b8a891..c20e936 100644
77281--- a/include/linux/vmalloc.h
77282+++ b/include/linux/vmalloc.h
77283@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
77284 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
77285 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
77286 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
77287+
77288+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
77289+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
77290+#endif
77291+
77292 /* bits [20..32] reserved for arch specific ioremap internals */
77293
77294 /*
77295@@ -75,7 +80,7 @@ extern void *vmalloc_32_user(unsigned long size);
77296 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
77297 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
77298 unsigned long start, unsigned long end, gfp_t gfp_mask,
77299- pgprot_t prot, int node, const void *caller);
77300+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
77301 extern void vfree(const void *addr);
77302
77303 extern void *vmap(struct page **pages, unsigned int count,
77304@@ -141,8 +146,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
77305 extern void free_vm_area(struct vm_struct *area);
77306
77307 /* for /dev/kmem */
77308-extern long vread(char *buf, char *addr, unsigned long count);
77309-extern long vwrite(char *buf, char *addr, unsigned long count);
77310+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
77311+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
77312
77313 /*
77314 * Internals. Dont't use..
77315diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
77316index c586679..f06b389 100644
77317--- a/include/linux/vmstat.h
77318+++ b/include/linux/vmstat.h
77319@@ -90,18 +90,18 @@ static inline void vm_events_fold_cpu(int cpu)
77320 /*
77321 * Zone based page accounting with per cpu differentials.
77322 */
77323-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
77324+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
77325
77326 static inline void zone_page_state_add(long x, struct zone *zone,
77327 enum zone_stat_item item)
77328 {
77329- atomic_long_add(x, &zone->vm_stat[item]);
77330- atomic_long_add(x, &vm_stat[item]);
77331+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
77332+ atomic_long_add_unchecked(x, &vm_stat[item]);
77333 }
77334
77335 static inline unsigned long global_page_state(enum zone_stat_item item)
77336 {
77337- long x = atomic_long_read(&vm_stat[item]);
77338+ long x = atomic_long_read_unchecked(&vm_stat[item]);
77339 #ifdef CONFIG_SMP
77340 if (x < 0)
77341 x = 0;
77342@@ -112,7 +112,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
77343 static inline unsigned long zone_page_state(struct zone *zone,
77344 enum zone_stat_item item)
77345 {
77346- long x = atomic_long_read(&zone->vm_stat[item]);
77347+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
77348 #ifdef CONFIG_SMP
77349 if (x < 0)
77350 x = 0;
77351@@ -129,7 +129,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
77352 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
77353 enum zone_stat_item item)
77354 {
77355- long x = atomic_long_read(&zone->vm_stat[item]);
77356+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
77357
77358 #ifdef CONFIG_SMP
77359 int cpu;
77360@@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
77361
77362 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
77363 {
77364- atomic_long_inc(&zone->vm_stat[item]);
77365- atomic_long_inc(&vm_stat[item]);
77366+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
77367+ atomic_long_inc_unchecked(&vm_stat[item]);
77368 }
77369
77370 static inline void __inc_zone_page_state(struct page *page,
77371@@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
77372
77373 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
77374 {
77375- atomic_long_dec(&zone->vm_stat[item]);
77376- atomic_long_dec(&vm_stat[item]);
77377+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
77378+ atomic_long_dec_unchecked(&vm_stat[item]);
77379 }
77380
77381 static inline void __dec_zone_page_state(struct page *page,
77382diff --git a/include/linux/xattr.h b/include/linux/xattr.h
77383index fdbafc6..49dfe4f 100644
77384--- a/include/linux/xattr.h
77385+++ b/include/linux/xattr.h
77386@@ -28,7 +28,7 @@ struct xattr_handler {
77387 size_t size, int handler_flags);
77388 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
77389 size_t size, int flags, int handler_flags);
77390-};
77391+} __do_const;
77392
77393 struct xattr {
77394 char *name;
77395@@ -37,6 +37,9 @@ struct xattr {
77396 };
77397
77398 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
77399+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
77400+ssize_t pax_getxattr(struct dentry *, void *, size_t);
77401+#endif
77402 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
77403 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
77404 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
77405diff --git a/include/linux/yam.h b/include/linux/yam.h
77406index 7fe2822..512cdc2 100644
77407--- a/include/linux/yam.h
77408+++ b/include/linux/yam.h
77409@@ -77,6 +77,6 @@ struct yamdrv_ioctl_cfg {
77410
77411 struct yamdrv_ioctl_mcs {
77412 int cmd;
77413- int bitrate;
77414+ unsigned int bitrate;
77415 unsigned char bits[YAM_FPGA_SIZE];
77416 };
77417diff --git a/include/linux/zlib.h b/include/linux/zlib.h
77418index 9c5a6b4..09c9438 100644
77419--- a/include/linux/zlib.h
77420+++ b/include/linux/zlib.h
77421@@ -31,6 +31,7 @@
77422 #define _ZLIB_H
77423
77424 #include <linux/zconf.h>
77425+#include <linux/compiler.h>
77426
77427 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
77428 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
77429@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
77430
77431 /* basic functions */
77432
77433-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
77434+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
77435 /*
77436 Returns the number of bytes that needs to be allocated for a per-
77437 stream workspace with the specified parameters. A pointer to this
77438diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
77439index c768c9f..bdcaa5a 100644
77440--- a/include/media/v4l2-dev.h
77441+++ b/include/media/v4l2-dev.h
77442@@ -76,7 +76,7 @@ struct v4l2_file_operations {
77443 int (*mmap) (struct file *, struct vm_area_struct *);
77444 int (*open) (struct file *);
77445 int (*release) (struct file *);
77446-};
77447+} __do_const;
77448
77449 /*
77450 * Newer version of video_device, handled by videodev2.c
77451diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
77452index c9b1593..a572459 100644
77453--- a/include/media/v4l2-device.h
77454+++ b/include/media/v4l2-device.h
77455@@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
77456 this function returns 0. If the name ends with a digit (e.g. cx18),
77457 then the name will be set to cx18-0 since cx180 looks really odd. */
77458 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
77459- atomic_t *instance);
77460+ atomic_unchecked_t *instance);
77461
77462 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
77463 Since the parent disappears this ensures that v4l2_dev doesn't have an
77464diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
77465index d9fa68f..45c88d1 100644
77466--- a/include/net/9p/transport.h
77467+++ b/include/net/9p/transport.h
77468@@ -63,7 +63,7 @@ struct p9_trans_module {
77469 int (*cancelled)(struct p9_client *, struct p9_req_t *req);
77470 int (*zc_request)(struct p9_client *, struct p9_req_t *,
77471 char *, char *, int , int, int, int);
77472-};
77473+} __do_const;
77474
77475 void v9fs_register_trans(struct p9_trans_module *m);
77476 void v9fs_unregister_trans(struct p9_trans_module *m);
77477diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
77478index 1a966af..2767cf6 100644
77479--- a/include/net/bluetooth/l2cap.h
77480+++ b/include/net/bluetooth/l2cap.h
77481@@ -551,7 +551,7 @@ struct l2cap_ops {
77482 void (*defer) (struct l2cap_chan *chan);
77483 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
77484 unsigned long len, int nb);
77485-};
77486+} __do_const;
77487
77488 struct l2cap_conn {
77489 struct hci_conn *hcon;
77490diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
77491index f2ae33d..c457cf0 100644
77492--- a/include/net/caif/cfctrl.h
77493+++ b/include/net/caif/cfctrl.h
77494@@ -52,7 +52,7 @@ struct cfctrl_rsp {
77495 void (*radioset_rsp)(void);
77496 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
77497 struct cflayer *client_layer);
77498-};
77499+} __no_const;
77500
77501 /* Link Setup Parameters for CAIF-Links. */
77502 struct cfctrl_link_param {
77503@@ -101,8 +101,8 @@ struct cfctrl_request_info {
77504 struct cfctrl {
77505 struct cfsrvl serv;
77506 struct cfctrl_rsp res;
77507- atomic_t req_seq_no;
77508- atomic_t rsp_seq_no;
77509+ atomic_unchecked_t req_seq_no;
77510+ atomic_unchecked_t rsp_seq_no;
77511 struct list_head list;
77512 /* Protects from simultaneous access to first_req list */
77513 spinlock_t info_list_lock;
77514diff --git a/include/net/flow.h b/include/net/flow.h
77515index 628e11b..4c475df 100644
77516--- a/include/net/flow.h
77517+++ b/include/net/flow.h
77518@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
77519
77520 extern void flow_cache_flush(void);
77521 extern void flow_cache_flush_deferred(void);
77522-extern atomic_t flow_cache_genid;
77523+extern atomic_unchecked_t flow_cache_genid;
77524
77525 #endif
77526diff --git a/include/net/genetlink.h b/include/net/genetlink.h
77527index 8e0b6c8..73cf605 100644
77528--- a/include/net/genetlink.h
77529+++ b/include/net/genetlink.h
77530@@ -120,7 +120,7 @@ struct genl_ops {
77531 struct netlink_callback *cb);
77532 int (*done)(struct netlink_callback *cb);
77533 struct list_head ops_list;
77534-};
77535+} __do_const;
77536
77537 extern int __genl_register_family(struct genl_family *family);
77538
77539diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
77540index 734d9b5..48a9a4b 100644
77541--- a/include/net/gro_cells.h
77542+++ b/include/net/gro_cells.h
77543@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
77544 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
77545
77546 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
77547- atomic_long_inc(&dev->rx_dropped);
77548+ atomic_long_inc_unchecked(&dev->rx_dropped);
77549 kfree_skb(skb);
77550 return;
77551 }
77552diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
77553index de2c785..0588a6b 100644
77554--- a/include/net/inet_connection_sock.h
77555+++ b/include/net/inet_connection_sock.h
77556@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
77557 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
77558 int (*bind_conflict)(const struct sock *sk,
77559 const struct inet_bind_bucket *tb, bool relax);
77560-};
77561+} __do_const;
77562
77563 /** inet_connection_sock - INET connection oriented sock
77564 *
77565diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
77566index 53f464d..0bd0b49 100644
77567--- a/include/net/inetpeer.h
77568+++ b/include/net/inetpeer.h
77569@@ -47,8 +47,8 @@ struct inet_peer {
77570 */
77571 union {
77572 struct {
77573- atomic_t rid; /* Frag reception counter */
77574- atomic_t ip_id_count; /* IP ID for the next packet */
77575+ atomic_unchecked_t rid; /* Frag reception counter */
77576+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
77577 };
77578 struct rcu_head rcu;
77579 struct inet_peer *gc_next;
77580@@ -178,16 +178,13 @@ static inline void inet_peer_refcheck(const struct inet_peer *p)
77581 /* can be called with or without local BH being disabled */
77582 static inline int inet_getid(struct inet_peer *p, int more)
77583 {
77584- int old, new;
77585+ int id;
77586 more++;
77587 inet_peer_refcheck(p);
77588- do {
77589- old = atomic_read(&p->ip_id_count);
77590- new = old + more;
77591- if (!new)
77592- new = 1;
77593- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
77594- return new;
77595+ id = atomic_add_return_unchecked(more, &p->ip_id_count);
77596+ if (!id)
77597+ id = atomic_inc_return_unchecked(&p->ip_id_count);
77598+ return id;
77599 }
77600
77601 #endif /* _NET_INETPEER_H */
77602diff --git a/include/net/ip.h b/include/net/ip.h
77603index edfa591..a643b82 100644
77604--- a/include/net/ip.h
77605+++ b/include/net/ip.h
77606@@ -202,7 +202,7 @@ extern struct local_ports {
77607 } sysctl_local_ports;
77608 extern void inet_get_local_port_range(int *low, int *high);
77609
77610-extern unsigned long *sysctl_local_reserved_ports;
77611+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
77612 static inline int inet_is_reserved_local_port(int port)
77613 {
77614 return test_bit(port, sysctl_local_reserved_ports);
77615diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
77616index cbf2be3..3683f6d 100644
77617--- a/include/net/ip_fib.h
77618+++ b/include/net/ip_fib.h
77619@@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
77620
77621 #define FIB_RES_SADDR(net, res) \
77622 ((FIB_RES_NH(res).nh_saddr_genid == \
77623- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
77624+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
77625 FIB_RES_NH(res).nh_saddr : \
77626 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
77627 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
77628diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
77629index f0d70f0..185f15b 100644
77630--- a/include/net/ip_vs.h
77631+++ b/include/net/ip_vs.h
77632@@ -588,7 +588,7 @@ struct ip_vs_conn {
77633 struct ip_vs_conn *control; /* Master control connection */
77634 atomic_t n_control; /* Number of controlled ones */
77635 struct ip_vs_dest *dest; /* real server */
77636- atomic_t in_pkts; /* incoming packet counter */
77637+ atomic_unchecked_t in_pkts; /* incoming packet counter */
77638
77639 /* packet transmitter for different forwarding methods. If it
77640 mangles the packet, it must return NF_DROP or better NF_STOLEN,
77641@@ -737,7 +737,7 @@ struct ip_vs_dest {
77642 __be16 port; /* port number of the server */
77643 union nf_inet_addr addr; /* IP address of the server */
77644 volatile unsigned int flags; /* dest status flags */
77645- atomic_t conn_flags; /* flags to copy to conn */
77646+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
77647 atomic_t weight; /* server weight */
77648
77649 atomic_t refcnt; /* reference counter */
77650@@ -993,11 +993,11 @@ struct netns_ipvs {
77651 /* ip_vs_lblc */
77652 int sysctl_lblc_expiration;
77653 struct ctl_table_header *lblc_ctl_header;
77654- struct ctl_table *lblc_ctl_table;
77655+ ctl_table_no_const *lblc_ctl_table;
77656 /* ip_vs_lblcr */
77657 int sysctl_lblcr_expiration;
77658 struct ctl_table_header *lblcr_ctl_header;
77659- struct ctl_table *lblcr_ctl_table;
77660+ ctl_table_no_const *lblcr_ctl_table;
77661 /* ip_vs_est */
77662 struct list_head est_list; /* estimator list */
77663 spinlock_t est_lock;
77664diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
77665index 80ffde3..968b0f4 100644
77666--- a/include/net/irda/ircomm_tty.h
77667+++ b/include/net/irda/ircomm_tty.h
77668@@ -35,6 +35,7 @@
77669 #include <linux/termios.h>
77670 #include <linux/timer.h>
77671 #include <linux/tty.h> /* struct tty_struct */
77672+#include <asm/local.h>
77673
77674 #include <net/irda/irias_object.h>
77675 #include <net/irda/ircomm_core.h>
77676diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
77677index 714cc9a..ea05f3e 100644
77678--- a/include/net/iucv/af_iucv.h
77679+++ b/include/net/iucv/af_iucv.h
77680@@ -149,7 +149,7 @@ struct iucv_skb_cb {
77681 struct iucv_sock_list {
77682 struct hlist_head head;
77683 rwlock_t lock;
77684- atomic_t autobind_name;
77685+ atomic_unchecked_t autobind_name;
77686 };
77687
77688 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
77689diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
77690index df83f69..9b640b8 100644
77691--- a/include/net/llc_c_ac.h
77692+++ b/include/net/llc_c_ac.h
77693@@ -87,7 +87,7 @@
77694 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
77695 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
77696
77697-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
77698+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
77699
77700 extern int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
77701 extern int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
77702diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
77703index 6ca3113..f8026dd 100644
77704--- a/include/net/llc_c_ev.h
77705+++ b/include/net/llc_c_ev.h
77706@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
77707 return (struct llc_conn_state_ev *)skb->cb;
77708 }
77709
77710-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
77711-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
77712+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
77713+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
77714
77715 extern int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
77716 extern int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
77717diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
77718index 0e79cfb..f46db31 100644
77719--- a/include/net/llc_c_st.h
77720+++ b/include/net/llc_c_st.h
77721@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
77722 u8 next_state;
77723 llc_conn_ev_qfyr_t *ev_qualifiers;
77724 llc_conn_action_t *ev_actions;
77725-};
77726+} __do_const;
77727
77728 struct llc_conn_state {
77729 u8 current_state;
77730diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
77731index 37a3bbd..55a4241 100644
77732--- a/include/net/llc_s_ac.h
77733+++ b/include/net/llc_s_ac.h
77734@@ -23,7 +23,7 @@
77735 #define SAP_ACT_TEST_IND 9
77736
77737 /* All action functions must look like this */
77738-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
77739+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
77740
77741 extern int llc_sap_action_unitdata_ind(struct llc_sap *sap,
77742 struct sk_buff *skb);
77743diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
77744index 567c681..cd73ac0 100644
77745--- a/include/net/llc_s_st.h
77746+++ b/include/net/llc_s_st.h
77747@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
77748 llc_sap_ev_t ev;
77749 u8 next_state;
77750 llc_sap_action_t *ev_actions;
77751-};
77752+} __do_const;
77753
77754 struct llc_sap_state {
77755 u8 curr_state;
77756diff --git a/include/net/mac80211.h b/include/net/mac80211.h
77757index 551ba6a..11c99c1 100644
77758--- a/include/net/mac80211.h
77759+++ b/include/net/mac80211.h
77760@@ -4221,7 +4221,7 @@ struct rate_control_ops {
77761 void (*add_sta_debugfs)(void *priv, void *priv_sta,
77762 struct dentry *dir);
77763 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
77764-};
77765+} __do_const;
77766
77767 static inline int rate_supported(struct ieee80211_sta *sta,
77768 enum ieee80211_band band,
77769diff --git a/include/net/neighbour.h b/include/net/neighbour.h
77770index 7e748ad..5c6229b 100644
77771--- a/include/net/neighbour.h
77772+++ b/include/net/neighbour.h
77773@@ -123,7 +123,7 @@ struct neigh_ops {
77774 void (*error_report)(struct neighbour *, struct sk_buff *);
77775 int (*output)(struct neighbour *, struct sk_buff *);
77776 int (*connected_output)(struct neighbour *, struct sk_buff *);
77777-};
77778+} __do_const;
77779
77780 struct pneigh_entry {
77781 struct pneigh_entry *next;
77782diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
77783index 84e37b1..8eba19a 100644
77784--- a/include/net/net_namespace.h
77785+++ b/include/net/net_namespace.h
77786@@ -119,8 +119,8 @@ struct net {
77787 struct netns_ipvs *ipvs;
77788 #endif
77789 struct sock *diag_nlsk;
77790- atomic_t rt_genid;
77791- atomic_t fnhe_genid;
77792+ atomic_unchecked_t rt_genid;
77793+ atomic_unchecked_t fnhe_genid;
77794 };
77795
77796 /*
77797@@ -277,7 +277,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
77798 #define __net_init __init
77799 #define __net_exit __exit_refok
77800 #define __net_initdata __initdata
77801+#ifdef CONSTIFY_PLUGIN
77802 #define __net_initconst __initconst
77803+#else
77804+#define __net_initconst __initdata
77805+#endif
77806 #endif
77807
77808 struct pernet_operations {
77809@@ -287,7 +291,7 @@ struct pernet_operations {
77810 void (*exit_batch)(struct list_head *net_exit_list);
77811 int *id;
77812 size_t size;
77813-};
77814+} __do_const;
77815
77816 /*
77817 * Use these carefully. If you implement a network device and it
77818@@ -335,22 +339,22 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
77819
77820 static inline int rt_genid(struct net *net)
77821 {
77822- return atomic_read(&net->rt_genid);
77823+ return atomic_read_unchecked(&net->rt_genid);
77824 }
77825
77826 static inline void rt_genid_bump(struct net *net)
77827 {
77828- atomic_inc(&net->rt_genid);
77829+ atomic_inc_unchecked(&net->rt_genid);
77830 }
77831
77832 static inline int fnhe_genid(struct net *net)
77833 {
77834- return atomic_read(&net->fnhe_genid);
77835+ return atomic_read_unchecked(&net->fnhe_genid);
77836 }
77837
77838 static inline void fnhe_genid_bump(struct net *net)
77839 {
77840- atomic_inc(&net->fnhe_genid);
77841+ atomic_inc_unchecked(&net->fnhe_genid);
77842 }
77843
77844 #endif /* __NET_NET_NAMESPACE_H */
77845diff --git a/include/net/netdma.h b/include/net/netdma.h
77846index 8ba8ce2..99b7fff 100644
77847--- a/include/net/netdma.h
77848+++ b/include/net/netdma.h
77849@@ -24,7 +24,7 @@
77850 #include <linux/dmaengine.h>
77851 #include <linux/skbuff.h>
77852
77853-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
77854+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
77855 struct sk_buff *skb, int offset, struct iovec *to,
77856 size_t len, struct dma_pinned_list *pinned_list);
77857
77858diff --git a/include/net/netlink.h b/include/net/netlink.h
77859index 9690b0f..87aded7 100644
77860--- a/include/net/netlink.h
77861+++ b/include/net/netlink.h
77862@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
77863 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
77864 {
77865 if (mark)
77866- skb_trim(skb, (unsigned char *) mark - skb->data);
77867+ skb_trim(skb, (const unsigned char *) mark - skb->data);
77868 }
77869
77870 /**
77871diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
77872index c9c0c53..53f24c3 100644
77873--- a/include/net/netns/conntrack.h
77874+++ b/include/net/netns/conntrack.h
77875@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
77876 struct nf_proto_net {
77877 #ifdef CONFIG_SYSCTL
77878 struct ctl_table_header *ctl_table_header;
77879- struct ctl_table *ctl_table;
77880+ ctl_table_no_const *ctl_table;
77881 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
77882 struct ctl_table_header *ctl_compat_header;
77883- struct ctl_table *ctl_compat_table;
77884+ ctl_table_no_const *ctl_compat_table;
77885 #endif
77886 #endif
77887 unsigned int users;
77888@@ -58,7 +58,7 @@ struct nf_ip_net {
77889 struct nf_icmp_net icmpv6;
77890 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
77891 struct ctl_table_header *ctl_table_header;
77892- struct ctl_table *ctl_table;
77893+ ctl_table_no_const *ctl_table;
77894 #endif
77895 };
77896
77897diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
77898index 2ba9de8..47bd6c7 100644
77899--- a/include/net/netns/ipv4.h
77900+++ b/include/net/netns/ipv4.h
77901@@ -67,7 +67,7 @@ struct netns_ipv4 {
77902 kgid_t sysctl_ping_group_range[2];
77903 long sysctl_tcp_mem[3];
77904
77905- atomic_t dev_addr_genid;
77906+ atomic_unchecked_t dev_addr_genid;
77907
77908 #ifdef CONFIG_IP_MROUTE
77909 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
77910diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
77911index 005e2c2..023d340 100644
77912--- a/include/net/netns/ipv6.h
77913+++ b/include/net/netns/ipv6.h
77914@@ -71,7 +71,7 @@ struct netns_ipv6 {
77915 struct fib_rules_ops *mr6_rules_ops;
77916 #endif
77917 #endif
77918- atomic_t dev_addr_genid;
77919+ atomic_unchecked_t dev_addr_genid;
77920 };
77921
77922 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
77923diff --git a/include/net/ping.h b/include/net/ping.h
77924index 5db0224..0d65365 100644
77925--- a/include/net/ping.h
77926+++ b/include/net/ping.h
77927@@ -55,7 +55,7 @@ struct ping_iter_state {
77928 extern struct proto ping_prot;
77929 extern struct ping_table ping_table;
77930 #if IS_ENABLED(CONFIG_IPV6)
77931-extern struct pingv6_ops pingv6_ops;
77932+extern struct pingv6_ops *pingv6_ops;
77933 #endif
77934
77935 struct pingfakehdr {
77936diff --git a/include/net/protocol.h b/include/net/protocol.h
77937index 047c047..b9dad15 100644
77938--- a/include/net/protocol.h
77939+++ b/include/net/protocol.h
77940@@ -44,7 +44,7 @@ struct net_protocol {
77941 void (*err_handler)(struct sk_buff *skb, u32 info);
77942 unsigned int no_policy:1,
77943 netns_ok:1;
77944-};
77945+} __do_const;
77946
77947 #if IS_ENABLED(CONFIG_IPV6)
77948 struct inet6_protocol {
77949@@ -57,7 +57,7 @@ struct inet6_protocol {
77950 u8 type, u8 code, int offset,
77951 __be32 info);
77952 unsigned int flags; /* INET6_PROTO_xxx */
77953-};
77954+} __do_const;
77955
77956 #define INET6_PROTO_NOPOLICY 0x1
77957 #define INET6_PROTO_FINAL 0x2
77958diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
77959index 7026648..584cc8c 100644
77960--- a/include/net/rtnetlink.h
77961+++ b/include/net/rtnetlink.h
77962@@ -81,7 +81,7 @@ struct rtnl_link_ops {
77963 const struct net_device *dev);
77964 unsigned int (*get_num_tx_queues)(void);
77965 unsigned int (*get_num_rx_queues)(void);
77966-};
77967+} __do_const;
77968
77969 extern int __rtnl_link_register(struct rtnl_link_ops *ops);
77970 extern void __rtnl_link_unregister(struct rtnl_link_ops *ops);
77971diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
77972index 2a82d13..62a31c2 100644
77973--- a/include/net/sctp/sm.h
77974+++ b/include/net/sctp/sm.h
77975@@ -87,7 +87,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
77976 typedef struct {
77977 sctp_state_fn_t *fn;
77978 const char *name;
77979-} sctp_sm_table_entry_t;
77980+} __do_const sctp_sm_table_entry_t;
77981
77982 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
77983 * currently in use.
77984@@ -299,7 +299,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
77985 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
77986
77987 /* Extern declarations for major data structures. */
77988-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
77989+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
77990
77991
77992 /* Get the size of a DATA chunk payload. */
77993diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
77994index e745c92..3641448 100644
77995--- a/include/net/sctp/structs.h
77996+++ b/include/net/sctp/structs.h
77997@@ -516,7 +516,7 @@ struct sctp_pf {
77998 struct sctp_association *asoc);
77999 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
78000 struct sctp_af *af;
78001-};
78002+} __do_const;
78003
78004
78005 /* Structure to track chunk fragments that have been acked, but peer
78006diff --git a/include/net/sock.h b/include/net/sock.h
78007index 31d5cfb..9ee0602 100644
78008--- a/include/net/sock.h
78009+++ b/include/net/sock.h
78010@@ -331,7 +331,7 @@ struct sock {
78011 unsigned int sk_napi_id;
78012 unsigned int sk_ll_usec;
78013 #endif
78014- atomic_t sk_drops;
78015+ atomic_unchecked_t sk_drops;
78016 int sk_rcvbuf;
78017
78018 struct sk_filter __rcu *sk_filter;
78019@@ -1803,7 +1803,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
78020 }
78021
78022 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
78023- char __user *from, char *to,
78024+ char __user *from, unsigned char *to,
78025 int copy, int offset)
78026 {
78027 if (skb->ip_summed == CHECKSUM_NONE) {
78028@@ -2065,7 +2065,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
78029 }
78030 }
78031
78032-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
78033+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
78034
78035 /**
78036 * sk_page_frag - return an appropriate page_frag
78037diff --git a/include/net/tcp.h b/include/net/tcp.h
78038index d198005..c974a393 100644
78039--- a/include/net/tcp.h
78040+++ b/include/net/tcp.h
78041@@ -521,7 +521,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
78042 extern void tcp_xmit_retransmit_queue(struct sock *);
78043 extern void tcp_simple_retransmit(struct sock *);
78044 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
78045-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
78046+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
78047
78048 extern void tcp_send_probe0(struct sock *);
78049 extern void tcp_send_partial(struct sock *);
78050@@ -694,8 +694,8 @@ struct tcp_skb_cb {
78051 struct inet6_skb_parm h6;
78052 #endif
78053 } header; /* For incoming frames */
78054- __u32 seq; /* Starting sequence number */
78055- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
78056+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
78057+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
78058 __u32 when; /* used to compute rtt's */
78059 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
78060
78061@@ -709,7 +709,7 @@ struct tcp_skb_cb {
78062
78063 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
78064 /* 1 byte hole */
78065- __u32 ack_seq; /* Sequence number ACK'd */
78066+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
78067 };
78068
78069 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
78070diff --git a/include/net/xfrm.h b/include/net/xfrm.h
78071index e823786..53b0608 100644
78072--- a/include/net/xfrm.h
78073+++ b/include/net/xfrm.h
78074@@ -287,7 +287,6 @@ struct xfrm_dst;
78075 struct xfrm_policy_afinfo {
78076 unsigned short family;
78077 struct dst_ops *dst_ops;
78078- void (*garbage_collect)(struct net *net);
78079 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
78080 const xfrm_address_t *saddr,
78081 const xfrm_address_t *daddr);
78082@@ -305,7 +304,7 @@ struct xfrm_policy_afinfo {
78083 struct net_device *dev,
78084 const struct flowi *fl);
78085 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
78086-};
78087+} __do_const;
78088
78089 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
78090 extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
78091@@ -342,7 +341,7 @@ struct xfrm_state_afinfo {
78092 int (*transport_finish)(struct sk_buff *skb,
78093 int async);
78094 void (*local_error)(struct sk_buff *skb, u32 mtu);
78095-};
78096+} __do_const;
78097
78098 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
78099 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
78100@@ -427,7 +426,7 @@ struct xfrm_mode {
78101 struct module *owner;
78102 unsigned int encap;
78103 int flags;
78104-};
78105+} __do_const;
78106
78107 /* Flags for xfrm_mode. */
78108 enum {
78109@@ -524,7 +523,7 @@ struct xfrm_policy {
78110 struct timer_list timer;
78111
78112 struct flow_cache_object flo;
78113- atomic_t genid;
78114+ atomic_unchecked_t genid;
78115 u32 priority;
78116 u32 index;
78117 struct xfrm_mark mark;
78118@@ -1164,6 +1163,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
78119 }
78120
78121 extern void xfrm_garbage_collect(struct net *net);
78122+extern void xfrm_garbage_collect_deferred(struct net *net);
78123
78124 #else
78125
78126@@ -1202,6 +1202,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
78127 static inline void xfrm_garbage_collect(struct net *net)
78128 {
78129 }
78130+static inline void xfrm_garbage_collect_deferred(struct net *net)
78131+{
78132+}
78133 #endif
78134
78135 static __inline__
78136diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
78137index 1a046b1..ee0bef0 100644
78138--- a/include/rdma/iw_cm.h
78139+++ b/include/rdma/iw_cm.h
78140@@ -122,7 +122,7 @@ struct iw_cm_verbs {
78141 int backlog);
78142
78143 int (*destroy_listen)(struct iw_cm_id *cm_id);
78144-};
78145+} __no_const;
78146
78147 /**
78148 * iw_create_cm_id - Create an IW CM identifier.
78149diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
78150index e1379b4..67eafbe 100644
78151--- a/include/scsi/libfc.h
78152+++ b/include/scsi/libfc.h
78153@@ -762,6 +762,7 @@ struct libfc_function_template {
78154 */
78155 void (*disc_stop_final) (struct fc_lport *);
78156 };
78157+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
78158
78159 /**
78160 * struct fc_disc - Discovery context
78161@@ -866,7 +867,7 @@ struct fc_lport {
78162 struct fc_vport *vport;
78163
78164 /* Operational Information */
78165- struct libfc_function_template tt;
78166+ libfc_function_template_no_const tt;
78167 u8 link_up;
78168 u8 qfull;
78169 enum fc_lport_state state;
78170diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
78171index a44954c..5da04b2 100644
78172--- a/include/scsi/scsi_device.h
78173+++ b/include/scsi/scsi_device.h
78174@@ -172,9 +172,9 @@ struct scsi_device {
78175 unsigned int max_device_blocked; /* what device_blocked counts down from */
78176 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
78177
78178- atomic_t iorequest_cnt;
78179- atomic_t iodone_cnt;
78180- atomic_t ioerr_cnt;
78181+ atomic_unchecked_t iorequest_cnt;
78182+ atomic_unchecked_t iodone_cnt;
78183+ atomic_unchecked_t ioerr_cnt;
78184
78185 struct device sdev_gendev,
78186 sdev_dev;
78187diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
78188index b797e8f..8e2c3aa 100644
78189--- a/include/scsi/scsi_transport_fc.h
78190+++ b/include/scsi/scsi_transport_fc.h
78191@@ -751,7 +751,8 @@ struct fc_function_template {
78192 unsigned long show_host_system_hostname:1;
78193
78194 unsigned long disable_target_scan:1;
78195-};
78196+} __do_const;
78197+typedef struct fc_function_template __no_const fc_function_template_no_const;
78198
78199
78200 /**
78201diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
78202index 9031a26..750d592 100644
78203--- a/include/sound/compress_driver.h
78204+++ b/include/sound/compress_driver.h
78205@@ -128,7 +128,7 @@ struct snd_compr_ops {
78206 struct snd_compr_caps *caps);
78207 int (*get_codec_caps) (struct snd_compr_stream *stream,
78208 struct snd_compr_codec_caps *codec);
78209-};
78210+} __no_const;
78211
78212 /**
78213 * struct snd_compr: Compressed device
78214diff --git a/include/sound/soc.h b/include/sound/soc.h
78215index 6eabee7..58afb50 100644
78216--- a/include/sound/soc.h
78217+++ b/include/sound/soc.h
78218@@ -783,7 +783,7 @@ struct snd_soc_codec_driver {
78219 /* probe ordering - for components with runtime dependencies */
78220 int probe_order;
78221 int remove_order;
78222-};
78223+} __do_const;
78224
78225 /* SoC platform interface */
78226 struct snd_soc_platform_driver {
78227@@ -829,7 +829,7 @@ struct snd_soc_platform_driver {
78228 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
78229 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
78230 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
78231-};
78232+} __do_const;
78233
78234 struct snd_soc_platform {
78235 const char *name;
78236diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
78237index e34fc90..ecefa2c 100644
78238--- a/include/target/target_core_base.h
78239+++ b/include/target/target_core_base.h
78240@@ -643,7 +643,7 @@ struct se_device {
78241 spinlock_t stats_lock;
78242 /* Active commands on this virtual SE device */
78243 atomic_t simple_cmds;
78244- atomic_t dev_ordered_id;
78245+ atomic_unchecked_t dev_ordered_id;
78246 atomic_t dev_ordered_sync;
78247 atomic_t dev_qf_count;
78248 int export_count;
78249diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
78250new file mode 100644
78251index 0000000..fb634b7
78252--- /dev/null
78253+++ b/include/trace/events/fs.h
78254@@ -0,0 +1,53 @@
78255+#undef TRACE_SYSTEM
78256+#define TRACE_SYSTEM fs
78257+
78258+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
78259+#define _TRACE_FS_H
78260+
78261+#include <linux/fs.h>
78262+#include <linux/tracepoint.h>
78263+
78264+TRACE_EVENT(do_sys_open,
78265+
78266+ TP_PROTO(const char *filename, int flags, int mode),
78267+
78268+ TP_ARGS(filename, flags, mode),
78269+
78270+ TP_STRUCT__entry(
78271+ __string( filename, filename )
78272+ __field( int, flags )
78273+ __field( int, mode )
78274+ ),
78275+
78276+ TP_fast_assign(
78277+ __assign_str(filename, filename);
78278+ __entry->flags = flags;
78279+ __entry->mode = mode;
78280+ ),
78281+
78282+ TP_printk("\"%s\" %x %o",
78283+ __get_str(filename), __entry->flags, __entry->mode)
78284+);
78285+
78286+TRACE_EVENT(open_exec,
78287+
78288+ TP_PROTO(const char *filename),
78289+
78290+ TP_ARGS(filename),
78291+
78292+ TP_STRUCT__entry(
78293+ __string( filename, filename )
78294+ ),
78295+
78296+ TP_fast_assign(
78297+ __assign_str(filename, filename);
78298+ ),
78299+
78300+ TP_printk("\"%s\"",
78301+ __get_str(filename))
78302+);
78303+
78304+#endif /* _TRACE_FS_H */
78305+
78306+/* This part must be outside protection */
78307+#include <trace/define_trace.h>
78308diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
78309index 1c09820..7f5ec79 100644
78310--- a/include/trace/events/irq.h
78311+++ b/include/trace/events/irq.h
78312@@ -36,7 +36,7 @@ struct softirq_action;
78313 */
78314 TRACE_EVENT(irq_handler_entry,
78315
78316- TP_PROTO(int irq, struct irqaction *action),
78317+ TP_PROTO(int irq, const struct irqaction *action),
78318
78319 TP_ARGS(irq, action),
78320
78321@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
78322 */
78323 TRACE_EVENT(irq_handler_exit,
78324
78325- TP_PROTO(int irq, struct irqaction *action, int ret),
78326+ TP_PROTO(int irq, const struct irqaction *action, int ret),
78327
78328 TP_ARGS(irq, action, ret),
78329
78330diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
78331index 7caf44c..23c6f27 100644
78332--- a/include/uapi/linux/a.out.h
78333+++ b/include/uapi/linux/a.out.h
78334@@ -39,6 +39,14 @@ enum machine_type {
78335 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
78336 };
78337
78338+/* Constants for the N_FLAGS field */
78339+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
78340+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
78341+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
78342+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
78343+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
78344+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
78345+
78346 #if !defined (N_MAGIC)
78347 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
78348 #endif
78349diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
78350index d876736..ccce5c0 100644
78351--- a/include/uapi/linux/byteorder/little_endian.h
78352+++ b/include/uapi/linux/byteorder/little_endian.h
78353@@ -42,51 +42,51 @@
78354
78355 static inline __le64 __cpu_to_le64p(const __u64 *p)
78356 {
78357- return (__force __le64)*p;
78358+ return (__force const __le64)*p;
78359 }
78360-static inline __u64 __le64_to_cpup(const __le64 *p)
78361+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
78362 {
78363- return (__force __u64)*p;
78364+ return (__force const __u64)*p;
78365 }
78366 static inline __le32 __cpu_to_le32p(const __u32 *p)
78367 {
78368- return (__force __le32)*p;
78369+ return (__force const __le32)*p;
78370 }
78371 static inline __u32 __le32_to_cpup(const __le32 *p)
78372 {
78373- return (__force __u32)*p;
78374+ return (__force const __u32)*p;
78375 }
78376 static inline __le16 __cpu_to_le16p(const __u16 *p)
78377 {
78378- return (__force __le16)*p;
78379+ return (__force const __le16)*p;
78380 }
78381 static inline __u16 __le16_to_cpup(const __le16 *p)
78382 {
78383- return (__force __u16)*p;
78384+ return (__force const __u16)*p;
78385 }
78386 static inline __be64 __cpu_to_be64p(const __u64 *p)
78387 {
78388- return (__force __be64)__swab64p(p);
78389+ return (__force const __be64)__swab64p(p);
78390 }
78391 static inline __u64 __be64_to_cpup(const __be64 *p)
78392 {
78393- return __swab64p((__u64 *)p);
78394+ return __swab64p((const __u64 *)p);
78395 }
78396 static inline __be32 __cpu_to_be32p(const __u32 *p)
78397 {
78398- return (__force __be32)__swab32p(p);
78399+ return (__force const __be32)__swab32p(p);
78400 }
78401-static inline __u32 __be32_to_cpup(const __be32 *p)
78402+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
78403 {
78404- return __swab32p((__u32 *)p);
78405+ return __swab32p((const __u32 *)p);
78406 }
78407 static inline __be16 __cpu_to_be16p(const __u16 *p)
78408 {
78409- return (__force __be16)__swab16p(p);
78410+ return (__force const __be16)__swab16p(p);
78411 }
78412 static inline __u16 __be16_to_cpup(const __be16 *p)
78413 {
78414- return __swab16p((__u16 *)p);
78415+ return __swab16p((const __u16 *)p);
78416 }
78417 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
78418 #define __le64_to_cpus(x) do { (void)(x); } while (0)
78419diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
78420index ef6103b..d4e65dd 100644
78421--- a/include/uapi/linux/elf.h
78422+++ b/include/uapi/linux/elf.h
78423@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
78424 #define PT_GNU_EH_FRAME 0x6474e550
78425
78426 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
78427+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
78428+
78429+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
78430+
78431+/* Constants for the e_flags field */
78432+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
78433+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
78434+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
78435+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
78436+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
78437+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
78438
78439 /*
78440 * Extended Numbering
78441@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
78442 #define DT_DEBUG 21
78443 #define DT_TEXTREL 22
78444 #define DT_JMPREL 23
78445+#define DT_FLAGS 30
78446+ #define DF_TEXTREL 0x00000004
78447 #define DT_ENCODING 32
78448 #define OLD_DT_LOOS 0x60000000
78449 #define DT_LOOS 0x6000000d
78450@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
78451 #define PF_W 0x2
78452 #define PF_X 0x1
78453
78454+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
78455+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
78456+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
78457+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
78458+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
78459+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
78460+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
78461+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
78462+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
78463+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
78464+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
78465+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
78466+
78467 typedef struct elf32_phdr{
78468 Elf32_Word p_type;
78469 Elf32_Off p_offset;
78470@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
78471 #define EI_OSABI 7
78472 #define EI_PAD 8
78473
78474+#define EI_PAX 14
78475+
78476 #define ELFMAG0 0x7f /* EI_MAG */
78477 #define ELFMAG1 'E'
78478 #define ELFMAG2 'L'
78479diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
78480index aa169c4..6a2771d 100644
78481--- a/include/uapi/linux/personality.h
78482+++ b/include/uapi/linux/personality.h
78483@@ -30,6 +30,7 @@ enum {
78484 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
78485 ADDR_NO_RANDOMIZE | \
78486 ADDR_COMPAT_LAYOUT | \
78487+ ADDR_LIMIT_3GB | \
78488 MMAP_PAGE_ZERO)
78489
78490 /*
78491diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
78492index 7530e74..e714828 100644
78493--- a/include/uapi/linux/screen_info.h
78494+++ b/include/uapi/linux/screen_info.h
78495@@ -43,7 +43,8 @@ struct screen_info {
78496 __u16 pages; /* 0x32 */
78497 __u16 vesa_attributes; /* 0x34 */
78498 __u32 capabilities; /* 0x36 */
78499- __u8 _reserved[6]; /* 0x3a */
78500+ __u16 vesapm_size; /* 0x3a */
78501+ __u8 _reserved[4]; /* 0x3c */
78502 } __attribute__((packed));
78503
78504 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
78505diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
78506index 0e011eb..82681b1 100644
78507--- a/include/uapi/linux/swab.h
78508+++ b/include/uapi/linux/swab.h
78509@@ -43,7 +43,7 @@
78510 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
78511 */
78512
78513-static inline __attribute_const__ __u16 __fswab16(__u16 val)
78514+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
78515 {
78516 #ifdef __HAVE_BUILTIN_BSWAP16__
78517 return __builtin_bswap16(val);
78518@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
78519 #endif
78520 }
78521
78522-static inline __attribute_const__ __u32 __fswab32(__u32 val)
78523+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
78524 {
78525 #ifdef __HAVE_BUILTIN_BSWAP32__
78526 return __builtin_bswap32(val);
78527@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
78528 #endif
78529 }
78530
78531-static inline __attribute_const__ __u64 __fswab64(__u64 val)
78532+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
78533 {
78534 #ifdef __HAVE_BUILTIN_BSWAP64__
78535 return __builtin_bswap64(val);
78536diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
78537index 6d67213..8dab561 100644
78538--- a/include/uapi/linux/sysctl.h
78539+++ b/include/uapi/linux/sysctl.h
78540@@ -155,7 +155,11 @@ enum
78541 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
78542 };
78543
78544-
78545+#ifdef CONFIG_PAX_SOFTMODE
78546+enum {
78547+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
78548+};
78549+#endif
78550
78551 /* CTL_VM names: */
78552 enum
78553diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
78554index e4629b9..6958086 100644
78555--- a/include/uapi/linux/xattr.h
78556+++ b/include/uapi/linux/xattr.h
78557@@ -63,5 +63,9 @@
78558 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
78559 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
78560
78561+/* User namespace */
78562+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
78563+#define XATTR_PAX_FLAGS_SUFFIX "flags"
78564+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
78565
78566 #endif /* _UAPI_LINUX_XATTR_H */
78567diff --git a/include/video/udlfb.h b/include/video/udlfb.h
78568index f9466fa..f4e2b81 100644
78569--- a/include/video/udlfb.h
78570+++ b/include/video/udlfb.h
78571@@ -53,10 +53,10 @@ struct dlfb_data {
78572 u32 pseudo_palette[256];
78573 int blank_mode; /*one of FB_BLANK_ */
78574 /* blit-only rendering path metrics, exposed through sysfs */
78575- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
78576- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
78577- atomic_t bytes_sent; /* to usb, after compression including overhead */
78578- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
78579+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
78580+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
78581+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
78582+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
78583 };
78584
78585 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
78586diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
78587index 30f5362..8ed8ac9 100644
78588--- a/include/video/uvesafb.h
78589+++ b/include/video/uvesafb.h
78590@@ -122,6 +122,7 @@ struct uvesafb_par {
78591 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
78592 u8 pmi_setpal; /* PMI for palette changes */
78593 u16 *pmi_base; /* protected mode interface location */
78594+ u8 *pmi_code; /* protected mode code location */
78595 void *pmi_start;
78596 void *pmi_pal;
78597 u8 *vbe_state_orig; /*
78598diff --git a/init/Kconfig b/init/Kconfig
78599index fed81b5..0d3b964 100644
78600--- a/init/Kconfig
78601+++ b/init/Kconfig
78602@@ -1069,6 +1069,7 @@ endif # CGROUPS
78603
78604 config CHECKPOINT_RESTORE
78605 bool "Checkpoint/restore support" if EXPERT
78606+ depends on !GRKERNSEC
78607 default n
78608 help
78609 Enables additional kernel features in a sake of checkpoint/restore.
78610@@ -1553,7 +1554,7 @@ config SLUB_DEBUG
78611
78612 config COMPAT_BRK
78613 bool "Disable heap randomization"
78614- default y
78615+ default n
78616 help
78617 Randomizing heap placement makes heap exploits harder, but it
78618 also breaks ancient binaries (including anything libc5 based).
78619@@ -1827,7 +1828,7 @@ config INIT_ALL_POSSIBLE
78620 config STOP_MACHINE
78621 bool
78622 default y
78623- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
78624+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
78625 help
78626 Need stop_machine() primitive.
78627
78628diff --git a/init/Makefile b/init/Makefile
78629index 7bc47ee..6da2dc7 100644
78630--- a/init/Makefile
78631+++ b/init/Makefile
78632@@ -2,6 +2,9 @@
78633 # Makefile for the linux kernel.
78634 #
78635
78636+ccflags-y := $(GCC_PLUGINS_CFLAGS)
78637+asflags-y := $(GCC_PLUGINS_AFLAGS)
78638+
78639 obj-y := main.o version.o mounts.o
78640 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
78641 obj-y += noinitramfs.o
78642diff --git a/init/do_mounts.c b/init/do_mounts.c
78643index 816014c..c2054db 100644
78644--- a/init/do_mounts.c
78645+++ b/init/do_mounts.c
78646@@ -355,11 +355,11 @@ static void __init get_fs_names(char *page)
78647 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
78648 {
78649 struct super_block *s;
78650- int err = sys_mount(name, "/root", fs, flags, data);
78651+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
78652 if (err)
78653 return err;
78654
78655- sys_chdir("/root");
78656+ sys_chdir((const char __force_user *)"/root");
78657 s = current->fs->pwd.dentry->d_sb;
78658 ROOT_DEV = s->s_dev;
78659 printk(KERN_INFO
78660@@ -480,18 +480,18 @@ void __init change_floppy(char *fmt, ...)
78661 va_start(args, fmt);
78662 vsprintf(buf, fmt, args);
78663 va_end(args);
78664- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
78665+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
78666 if (fd >= 0) {
78667 sys_ioctl(fd, FDEJECT, 0);
78668 sys_close(fd);
78669 }
78670 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
78671- fd = sys_open("/dev/console", O_RDWR, 0);
78672+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
78673 if (fd >= 0) {
78674 sys_ioctl(fd, TCGETS, (long)&termios);
78675 termios.c_lflag &= ~ICANON;
78676 sys_ioctl(fd, TCSETSF, (long)&termios);
78677- sys_read(fd, &c, 1);
78678+ sys_read(fd, (char __user *)&c, 1);
78679 termios.c_lflag |= ICANON;
78680 sys_ioctl(fd, TCSETSF, (long)&termios);
78681 sys_close(fd);
78682@@ -585,6 +585,6 @@ void __init prepare_namespace(void)
78683 mount_root();
78684 out:
78685 devtmpfs_mount("dev");
78686- sys_mount(".", "/", NULL, MS_MOVE, NULL);
78687- sys_chroot(".");
78688+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
78689+ sys_chroot((const char __force_user *)".");
78690 }
78691diff --git a/init/do_mounts.h b/init/do_mounts.h
78692index f5b978a..69dbfe8 100644
78693--- a/init/do_mounts.h
78694+++ b/init/do_mounts.h
78695@@ -15,15 +15,15 @@ extern int root_mountflags;
78696
78697 static inline int create_dev(char *name, dev_t dev)
78698 {
78699- sys_unlink(name);
78700- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
78701+ sys_unlink((char __force_user *)name);
78702+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
78703 }
78704
78705 #if BITS_PER_LONG == 32
78706 static inline u32 bstat(char *name)
78707 {
78708 struct stat64 stat;
78709- if (sys_stat64(name, &stat) != 0)
78710+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
78711 return 0;
78712 if (!S_ISBLK(stat.st_mode))
78713 return 0;
78714@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
78715 static inline u32 bstat(char *name)
78716 {
78717 struct stat stat;
78718- if (sys_newstat(name, &stat) != 0)
78719+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
78720 return 0;
78721 if (!S_ISBLK(stat.st_mode))
78722 return 0;
78723diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
78724index 3e0878e..8a9d7a0 100644
78725--- a/init/do_mounts_initrd.c
78726+++ b/init/do_mounts_initrd.c
78727@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
78728 {
78729 sys_unshare(CLONE_FS | CLONE_FILES);
78730 /* stdin/stdout/stderr for /linuxrc */
78731- sys_open("/dev/console", O_RDWR, 0);
78732+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
78733 sys_dup(0);
78734 sys_dup(0);
78735 /* move initrd over / and chdir/chroot in initrd root */
78736- sys_chdir("/root");
78737- sys_mount(".", "/", NULL, MS_MOVE, NULL);
78738- sys_chroot(".");
78739+ sys_chdir((const char __force_user *)"/root");
78740+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
78741+ sys_chroot((const char __force_user *)".");
78742 sys_setsid();
78743 return 0;
78744 }
78745@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
78746 create_dev("/dev/root.old", Root_RAM0);
78747 /* mount initrd on rootfs' /root */
78748 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
78749- sys_mkdir("/old", 0700);
78750- sys_chdir("/old");
78751+ sys_mkdir((const char __force_user *)"/old", 0700);
78752+ sys_chdir((const char __force_user *)"/old");
78753
78754 /* try loading default modules from initrd */
78755 load_default_modules();
78756@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
78757 current->flags &= ~PF_FREEZER_SKIP;
78758
78759 /* move initrd to rootfs' /old */
78760- sys_mount("..", ".", NULL, MS_MOVE, NULL);
78761+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
78762 /* switch root and cwd back to / of rootfs */
78763- sys_chroot("..");
78764+ sys_chroot((const char __force_user *)"..");
78765
78766 if (new_decode_dev(real_root_dev) == Root_RAM0) {
78767- sys_chdir("/old");
78768+ sys_chdir((const char __force_user *)"/old");
78769 return;
78770 }
78771
78772- sys_chdir("/");
78773+ sys_chdir((const char __force_user *)"/");
78774 ROOT_DEV = new_decode_dev(real_root_dev);
78775 mount_root();
78776
78777 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
78778- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
78779+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
78780 if (!error)
78781 printk("okay\n");
78782 else {
78783- int fd = sys_open("/dev/root.old", O_RDWR, 0);
78784+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
78785 if (error == -ENOENT)
78786 printk("/initrd does not exist. Ignored.\n");
78787 else
78788 printk("failed\n");
78789 printk(KERN_NOTICE "Unmounting old root\n");
78790- sys_umount("/old", MNT_DETACH);
78791+ sys_umount((char __force_user *)"/old", MNT_DETACH);
78792 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
78793 if (fd < 0) {
78794 error = fd;
78795@@ -127,11 +127,11 @@ int __init initrd_load(void)
78796 * mounted in the normal path.
78797 */
78798 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
78799- sys_unlink("/initrd.image");
78800+ sys_unlink((const char __force_user *)"/initrd.image");
78801 handle_initrd();
78802 return 1;
78803 }
78804 }
78805- sys_unlink("/initrd.image");
78806+ sys_unlink((const char __force_user *)"/initrd.image");
78807 return 0;
78808 }
78809diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
78810index 8cb6db5..d729f50 100644
78811--- a/init/do_mounts_md.c
78812+++ b/init/do_mounts_md.c
78813@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
78814 partitioned ? "_d" : "", minor,
78815 md_setup_args[ent].device_names);
78816
78817- fd = sys_open(name, 0, 0);
78818+ fd = sys_open((char __force_user *)name, 0, 0);
78819 if (fd < 0) {
78820 printk(KERN_ERR "md: open failed - cannot start "
78821 "array %s\n", name);
78822@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
78823 * array without it
78824 */
78825 sys_close(fd);
78826- fd = sys_open(name, 0, 0);
78827+ fd = sys_open((char __force_user *)name, 0, 0);
78828 sys_ioctl(fd, BLKRRPART, 0);
78829 }
78830 sys_close(fd);
78831@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
78832
78833 wait_for_device_probe();
78834
78835- fd = sys_open("/dev/md0", 0, 0);
78836+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
78837 if (fd >= 0) {
78838 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
78839 sys_close(fd);
78840diff --git a/init/init_task.c b/init/init_task.c
78841index ba0a7f36..2bcf1d5 100644
78842--- a/init/init_task.c
78843+++ b/init/init_task.c
78844@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
78845 * Initial thread structure. Alignment of this is handled by a special
78846 * linker map entry.
78847 */
78848+#ifdef CONFIG_X86
78849+union thread_union init_thread_union __init_task_data;
78850+#else
78851 union thread_union init_thread_union __init_task_data =
78852 { INIT_THREAD_INFO(init_task) };
78853+#endif
78854diff --git a/init/initramfs.c b/init/initramfs.c
78855index a67ef9d..2d17ed9 100644
78856--- a/init/initramfs.c
78857+++ b/init/initramfs.c
78858@@ -84,7 +84,7 @@ static void __init free_hash(void)
78859 }
78860 }
78861
78862-static long __init do_utime(char *filename, time_t mtime)
78863+static long __init do_utime(char __force_user *filename, time_t mtime)
78864 {
78865 struct timespec t[2];
78866
78867@@ -119,7 +119,7 @@ static void __init dir_utime(void)
78868 struct dir_entry *de, *tmp;
78869 list_for_each_entry_safe(de, tmp, &dir_list, list) {
78870 list_del(&de->list);
78871- do_utime(de->name, de->mtime);
78872+ do_utime((char __force_user *)de->name, de->mtime);
78873 kfree(de->name);
78874 kfree(de);
78875 }
78876@@ -281,7 +281,7 @@ static int __init maybe_link(void)
78877 if (nlink >= 2) {
78878 char *old = find_link(major, minor, ino, mode, collected);
78879 if (old)
78880- return (sys_link(old, collected) < 0) ? -1 : 1;
78881+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
78882 }
78883 return 0;
78884 }
78885@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
78886 {
78887 struct stat st;
78888
78889- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
78890+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
78891 if (S_ISDIR(st.st_mode))
78892- sys_rmdir(path);
78893+ sys_rmdir((char __force_user *)path);
78894 else
78895- sys_unlink(path);
78896+ sys_unlink((char __force_user *)path);
78897 }
78898 }
78899
78900@@ -315,7 +315,7 @@ static int __init do_name(void)
78901 int openflags = O_WRONLY|O_CREAT;
78902 if (ml != 1)
78903 openflags |= O_TRUNC;
78904- wfd = sys_open(collected, openflags, mode);
78905+ wfd = sys_open((char __force_user *)collected, openflags, mode);
78906
78907 if (wfd >= 0) {
78908 sys_fchown(wfd, uid, gid);
78909@@ -327,17 +327,17 @@ static int __init do_name(void)
78910 }
78911 }
78912 } else if (S_ISDIR(mode)) {
78913- sys_mkdir(collected, mode);
78914- sys_chown(collected, uid, gid);
78915- sys_chmod(collected, mode);
78916+ sys_mkdir((char __force_user *)collected, mode);
78917+ sys_chown((char __force_user *)collected, uid, gid);
78918+ sys_chmod((char __force_user *)collected, mode);
78919 dir_add(collected, mtime);
78920 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
78921 S_ISFIFO(mode) || S_ISSOCK(mode)) {
78922 if (maybe_link() == 0) {
78923- sys_mknod(collected, mode, rdev);
78924- sys_chown(collected, uid, gid);
78925- sys_chmod(collected, mode);
78926- do_utime(collected, mtime);
78927+ sys_mknod((char __force_user *)collected, mode, rdev);
78928+ sys_chown((char __force_user *)collected, uid, gid);
78929+ sys_chmod((char __force_user *)collected, mode);
78930+ do_utime((char __force_user *)collected, mtime);
78931 }
78932 }
78933 return 0;
78934@@ -346,15 +346,15 @@ static int __init do_name(void)
78935 static int __init do_copy(void)
78936 {
78937 if (count >= body_len) {
78938- sys_write(wfd, victim, body_len);
78939+ sys_write(wfd, (char __force_user *)victim, body_len);
78940 sys_close(wfd);
78941- do_utime(vcollected, mtime);
78942+ do_utime((char __force_user *)vcollected, mtime);
78943 kfree(vcollected);
78944 eat(body_len);
78945 state = SkipIt;
78946 return 0;
78947 } else {
78948- sys_write(wfd, victim, count);
78949+ sys_write(wfd, (char __force_user *)victim, count);
78950 body_len -= count;
78951 eat(count);
78952 return 1;
78953@@ -365,9 +365,9 @@ static int __init do_symlink(void)
78954 {
78955 collected[N_ALIGN(name_len) + body_len] = '\0';
78956 clean_path(collected, 0);
78957- sys_symlink(collected + N_ALIGN(name_len), collected);
78958- sys_lchown(collected, uid, gid);
78959- do_utime(collected, mtime);
78960+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
78961+ sys_lchown((char __force_user *)collected, uid, gid);
78962+ do_utime((char __force_user *)collected, mtime);
78963 state = SkipIt;
78964 next_state = Reset;
78965 return 0;
78966@@ -583,7 +583,7 @@ static int __init populate_rootfs(void)
78967 {
78968 char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
78969 if (err)
78970- panic(err); /* Failed to decompress INTERNAL initramfs */
78971+ panic("%s", err); /* Failed to decompress INTERNAL initramfs */
78972 if (initrd_start) {
78973 #ifdef CONFIG_BLK_DEV_RAM
78974 int fd;
78975diff --git a/init/main.c b/init/main.c
78976index 586cd33..f1af30f 100644
78977--- a/init/main.c
78978+++ b/init/main.c
78979@@ -102,6 +102,8 @@ static inline void mark_rodata_ro(void) { }
78980 extern void tc_init(void);
78981 #endif
78982
78983+extern void grsecurity_init(void);
78984+
78985 /*
78986 * Debug helper: via this flag we know that we are in 'early bootup code'
78987 * where only the boot processor is running with IRQ disabled. This means
78988@@ -155,6 +157,74 @@ static int __init set_reset_devices(char *str)
78989
78990 __setup("reset_devices", set_reset_devices);
78991
78992+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
78993+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
78994+static int __init setup_grsec_proc_gid(char *str)
78995+{
78996+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
78997+ return 1;
78998+}
78999+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
79000+#endif
79001+
79002+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
79003+unsigned long pax_user_shadow_base __read_only;
79004+EXPORT_SYMBOL(pax_user_shadow_base);
79005+extern char pax_enter_kernel_user[];
79006+extern char pax_exit_kernel_user[];
79007+#endif
79008+
79009+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
79010+static int __init setup_pax_nouderef(char *str)
79011+{
79012+#ifdef CONFIG_X86_32
79013+ unsigned int cpu;
79014+ struct desc_struct *gdt;
79015+
79016+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
79017+ gdt = get_cpu_gdt_table(cpu);
79018+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
79019+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
79020+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
79021+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
79022+ }
79023+ loadsegment(ds, __KERNEL_DS);
79024+ loadsegment(es, __KERNEL_DS);
79025+ loadsegment(ss, __KERNEL_DS);
79026+#else
79027+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
79028+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
79029+ clone_pgd_mask = ~(pgdval_t)0UL;
79030+ pax_user_shadow_base = 0UL;
79031+ setup_clear_cpu_cap(X86_FEATURE_PCID);
79032+#endif
79033+
79034+ return 0;
79035+}
79036+early_param("pax_nouderef", setup_pax_nouderef);
79037+
79038+#ifdef CONFIG_X86_64
79039+static int __init setup_pax_weakuderef(char *str)
79040+{
79041+ if (clone_pgd_mask != ~(pgdval_t)0UL)
79042+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
79043+ return 1;
79044+}
79045+__setup("pax_weakuderef", setup_pax_weakuderef);
79046+#endif
79047+#endif
79048+
79049+#ifdef CONFIG_PAX_SOFTMODE
79050+int pax_softmode;
79051+
79052+static int __init setup_pax_softmode(char *str)
79053+{
79054+ get_option(&str, &pax_softmode);
79055+ return 1;
79056+}
79057+__setup("pax_softmode=", setup_pax_softmode);
79058+#endif
79059+
79060 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
79061 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
79062 static const char *panic_later, *panic_param;
79063@@ -680,25 +750,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
79064 {
79065 int count = preempt_count();
79066 int ret;
79067- char msgbuf[64];
79068+ const char *msg1 = "", *msg2 = "";
79069
79070 if (initcall_debug)
79071 ret = do_one_initcall_debug(fn);
79072 else
79073 ret = fn();
79074
79075- msgbuf[0] = 0;
79076-
79077 if (preempt_count() != count) {
79078- sprintf(msgbuf, "preemption imbalance ");
79079+ msg1 = " preemption imbalance";
79080 preempt_count() = count;
79081 }
79082 if (irqs_disabled()) {
79083- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
79084+ msg2 = " disabled interrupts";
79085 local_irq_enable();
79086 }
79087- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
79088+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
79089
79090+ add_latent_entropy();
79091 return ret;
79092 }
79093
79094@@ -805,8 +874,8 @@ static int run_init_process(const char *init_filename)
79095 {
79096 argv_init[0] = init_filename;
79097 return do_execve(init_filename,
79098- (const char __user *const __user *)argv_init,
79099- (const char __user *const __user *)envp_init);
79100+ (const char __user *const __force_user *)argv_init,
79101+ (const char __user *const __force_user *)envp_init);
79102 }
79103
79104 static noinline void __init kernel_init_freeable(void);
79105@@ -883,7 +952,7 @@ static noinline void __init kernel_init_freeable(void)
79106 do_basic_setup();
79107
79108 /* Open the /dev/console on the rootfs, this should never fail */
79109- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
79110+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
79111 pr_err("Warning: unable to open an initial console.\n");
79112
79113 (void) sys_dup(0);
79114@@ -896,11 +965,13 @@ static noinline void __init kernel_init_freeable(void)
79115 if (!ramdisk_execute_command)
79116 ramdisk_execute_command = "/init";
79117
79118- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
79119+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
79120 ramdisk_execute_command = NULL;
79121 prepare_namespace();
79122 }
79123
79124+ grsecurity_init();
79125+
79126 /*
79127 * Ok, we have completed the initial bootup, and
79128 * we're essentially up and running. Get rid of the
79129diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
79130index 130dfec..cc88451 100644
79131--- a/ipc/ipc_sysctl.c
79132+++ b/ipc/ipc_sysctl.c
79133@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
79134 static int proc_ipc_dointvec(ctl_table *table, int write,
79135 void __user *buffer, size_t *lenp, loff_t *ppos)
79136 {
79137- struct ctl_table ipc_table;
79138+ ctl_table_no_const ipc_table;
79139
79140 memcpy(&ipc_table, table, sizeof(ipc_table));
79141 ipc_table.data = get_ipc(table);
79142@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
79143 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
79144 void __user *buffer, size_t *lenp, loff_t *ppos)
79145 {
79146- struct ctl_table ipc_table;
79147+ ctl_table_no_const ipc_table;
79148
79149 memcpy(&ipc_table, table, sizeof(ipc_table));
79150 ipc_table.data = get_ipc(table);
79151@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
79152 static int proc_ipc_callback_dointvec(ctl_table *table, int write,
79153 void __user *buffer, size_t *lenp, loff_t *ppos)
79154 {
79155- struct ctl_table ipc_table;
79156+ ctl_table_no_const ipc_table;
79157 size_t lenp_bef = *lenp;
79158 int rc;
79159
79160@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec(ctl_table *table, int write,
79161 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
79162 void __user *buffer, size_t *lenp, loff_t *ppos)
79163 {
79164- struct ctl_table ipc_table;
79165+ ctl_table_no_const ipc_table;
79166 memcpy(&ipc_table, table, sizeof(ipc_table));
79167 ipc_table.data = get_ipc(table);
79168
79169@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
79170 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
79171 void __user *buffer, size_t *lenp, loff_t *ppos)
79172 {
79173- struct ctl_table ipc_table;
79174+ ctl_table_no_const ipc_table;
79175 size_t lenp_bef = *lenp;
79176 int oldval;
79177 int rc;
79178diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
79179index 383d638..943fdbb 100644
79180--- a/ipc/mq_sysctl.c
79181+++ b/ipc/mq_sysctl.c
79182@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
79183 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
79184 void __user *buffer, size_t *lenp, loff_t *ppos)
79185 {
79186- struct ctl_table mq_table;
79187+ ctl_table_no_const mq_table;
79188 memcpy(&mq_table, table, sizeof(mq_table));
79189 mq_table.data = get_mq(table);
79190
79191diff --git a/ipc/mqueue.c b/ipc/mqueue.c
79192index ae1996d..a35f2cc 100644
79193--- a/ipc/mqueue.c
79194+++ b/ipc/mqueue.c
79195@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
79196 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
79197 info->attr.mq_msgsize);
79198
79199+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
79200 spin_lock(&mq_lock);
79201 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
79202 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
79203diff --git a/ipc/msg.c b/ipc/msg.c
79204index 558aa91..359e718 100644
79205--- a/ipc/msg.c
79206+++ b/ipc/msg.c
79207@@ -297,18 +297,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
79208 return security_msg_queue_associate(msq, msgflg);
79209 }
79210
79211+static struct ipc_ops msg_ops = {
79212+ .getnew = newque,
79213+ .associate = msg_security,
79214+ .more_checks = NULL
79215+};
79216+
79217 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
79218 {
79219 struct ipc_namespace *ns;
79220- struct ipc_ops msg_ops;
79221 struct ipc_params msg_params;
79222
79223 ns = current->nsproxy->ipc_ns;
79224
79225- msg_ops.getnew = newque;
79226- msg_ops.associate = msg_security;
79227- msg_ops.more_checks = NULL;
79228-
79229 msg_params.key = key;
79230 msg_params.flg = msgflg;
79231
79232diff --git a/ipc/sem.c b/ipc/sem.c
79233index 8e2bf30..a711151 100644
79234--- a/ipc/sem.c
79235+++ b/ipc/sem.c
79236@@ -562,10 +562,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
79237 return 0;
79238 }
79239
79240+static struct ipc_ops sem_ops = {
79241+ .getnew = newary,
79242+ .associate = sem_security,
79243+ .more_checks = sem_more_checks
79244+};
79245+
79246 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
79247 {
79248 struct ipc_namespace *ns;
79249- struct ipc_ops sem_ops;
79250 struct ipc_params sem_params;
79251
79252 ns = current->nsproxy->ipc_ns;
79253@@ -573,10 +578,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
79254 if (nsems < 0 || nsems > ns->sc_semmsl)
79255 return -EINVAL;
79256
79257- sem_ops.getnew = newary;
79258- sem_ops.associate = sem_security;
79259- sem_ops.more_checks = sem_more_checks;
79260-
79261 sem_params.key = key;
79262 sem_params.flg = semflg;
79263 sem_params.u.nsems = nsems;
79264diff --git a/ipc/shm.c b/ipc/shm.c
79265index d697396..40e887d 100644
79266--- a/ipc/shm.c
79267+++ b/ipc/shm.c
79268@@ -72,6 +72,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
79269 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
79270 #endif
79271
79272+#ifdef CONFIG_GRKERNSEC
79273+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
79274+ const time_t shm_createtime, const kuid_t cuid,
79275+ const int shmid);
79276+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
79277+ const time_t shm_createtime);
79278+#endif
79279+
79280 void shm_init_ns(struct ipc_namespace *ns)
79281 {
79282 ns->shm_ctlmax = SHMMAX;
79283@@ -551,6 +559,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
79284 shp->shm_lprid = 0;
79285 shp->shm_atim = shp->shm_dtim = 0;
79286 shp->shm_ctim = get_seconds();
79287+#ifdef CONFIG_GRKERNSEC
79288+ {
79289+ struct timespec timeval;
79290+ do_posix_clock_monotonic_gettime(&timeval);
79291+
79292+ shp->shm_createtime = timeval.tv_sec;
79293+ }
79294+#endif
79295 shp->shm_segsz = size;
79296 shp->shm_nattch = 0;
79297 shp->shm_file = file;
79298@@ -604,18 +620,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
79299 return 0;
79300 }
79301
79302+static struct ipc_ops shm_ops = {
79303+ .getnew = newseg,
79304+ .associate = shm_security,
79305+ .more_checks = shm_more_checks
79306+};
79307+
79308 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
79309 {
79310 struct ipc_namespace *ns;
79311- struct ipc_ops shm_ops;
79312 struct ipc_params shm_params;
79313
79314 ns = current->nsproxy->ipc_ns;
79315
79316- shm_ops.getnew = newseg;
79317- shm_ops.associate = shm_security;
79318- shm_ops.more_checks = shm_more_checks;
79319-
79320 shm_params.key = key;
79321 shm_params.flg = shmflg;
79322 shm_params.u.size = size;
79323@@ -1076,6 +1093,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
79324 f_mode = FMODE_READ | FMODE_WRITE;
79325 }
79326 if (shmflg & SHM_EXEC) {
79327+
79328+#ifdef CONFIG_PAX_MPROTECT
79329+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
79330+ goto out;
79331+#endif
79332+
79333 prot |= PROT_EXEC;
79334 acc_mode |= S_IXUGO;
79335 }
79336@@ -1100,10 +1123,22 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
79337 if (err)
79338 goto out_unlock;
79339
79340+#ifdef CONFIG_GRKERNSEC
79341+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
79342+ shp->shm_perm.cuid, shmid) ||
79343+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
79344+ err = -EACCES;
79345+ goto out_unlock;
79346+ }
79347+#endif
79348+
79349 ipc_lock_object(&shp->shm_perm);
79350 path = shp->shm_file->f_path;
79351 path_get(&path);
79352 shp->shm_nattch++;
79353+#ifdef CONFIG_GRKERNSEC
79354+ shp->shm_lapid = current->pid;
79355+#endif
79356 size = i_size_read(path.dentry->d_inode);
79357 ipc_unlock_object(&shp->shm_perm);
79358 rcu_read_unlock();
79359diff --git a/kernel/acct.c b/kernel/acct.c
79360index 8d6e145..33e0b1e 100644
79361--- a/kernel/acct.c
79362+++ b/kernel/acct.c
79363@@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
79364 */
79365 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
79366 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
79367- file->f_op->write(file, (char *)&ac,
79368+ file->f_op->write(file, (char __force_user *)&ac,
79369 sizeof(acct_t), &file->f_pos);
79370 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
79371 set_fs(fs);
79372diff --git a/kernel/audit.c b/kernel/audit.c
79373index 7b0e23a..5b27ab9 100644
79374--- a/kernel/audit.c
79375+++ b/kernel/audit.c
79376@@ -118,7 +118,7 @@ u32 audit_sig_sid = 0;
79377 3) suppressed due to audit_rate_limit
79378 4) suppressed due to audit_backlog_limit
79379 */
79380-static atomic_t audit_lost = ATOMIC_INIT(0);
79381+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
79382
79383 /* The netlink socket. */
79384 static struct sock *audit_sock;
79385@@ -240,7 +240,7 @@ void audit_log_lost(const char *message)
79386 unsigned long now;
79387 int print;
79388
79389- atomic_inc(&audit_lost);
79390+ atomic_inc_unchecked(&audit_lost);
79391
79392 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
79393
79394@@ -259,7 +259,7 @@ void audit_log_lost(const char *message)
79395 printk(KERN_WARNING
79396 "audit: audit_lost=%d audit_rate_limit=%d "
79397 "audit_backlog_limit=%d\n",
79398- atomic_read(&audit_lost),
79399+ atomic_read_unchecked(&audit_lost),
79400 audit_rate_limit,
79401 audit_backlog_limit);
79402 audit_panic(message);
79403@@ -659,18 +659,19 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
79404
79405 switch (msg_type) {
79406 case AUDIT_GET:
79407+ status_set.mask = 0;
79408 status_set.enabled = audit_enabled;
79409 status_set.failure = audit_failure;
79410 status_set.pid = audit_pid;
79411 status_set.rate_limit = audit_rate_limit;
79412 status_set.backlog_limit = audit_backlog_limit;
79413- status_set.lost = atomic_read(&audit_lost);
79414+ status_set.lost = atomic_read_unchecked(&audit_lost);
79415 status_set.backlog = skb_queue_len(&audit_skb_queue);
79416 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
79417 &status_set, sizeof(status_set));
79418 break;
79419 case AUDIT_SET:
79420- if (nlh->nlmsg_len < sizeof(struct audit_status))
79421+ if (nlmsg_len(nlh) < sizeof(struct audit_status))
79422 return -EINVAL;
79423 status_get = (struct audit_status *)data;
79424 if (status_get->mask & AUDIT_STATUS_ENABLED) {
79425@@ -832,7 +833,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
79426
79427 memset(&s, 0, sizeof(s));
79428 /* guard against past and future API changes */
79429- memcpy(&s, data, min(sizeof(s), (size_t)nlh->nlmsg_len));
79430+ memcpy(&s, data, min_t(size_t, sizeof(s), nlmsg_len(nlh)));
79431 if ((s.enabled != 0 && s.enabled != 1) ||
79432 (s.log_passwd != 0 && s.log_passwd != 1))
79433 return -EINVAL;
79434diff --git a/kernel/auditsc.c b/kernel/auditsc.c
79435index 9845cb3..3ec9369 100644
79436--- a/kernel/auditsc.c
79437+++ b/kernel/auditsc.c
79438@@ -1962,7 +1962,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
79439 }
79440
79441 /* global counter which is incremented every time something logs in */
79442-static atomic_t session_id = ATOMIC_INIT(0);
79443+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
79444
79445 /**
79446 * audit_set_loginuid - set current task's audit_context loginuid
79447@@ -1986,7 +1986,7 @@ int audit_set_loginuid(kuid_t loginuid)
79448 return -EPERM;
79449 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
79450
79451- sessionid = atomic_inc_return(&session_id);
79452+ sessionid = atomic_inc_return_unchecked(&session_id);
79453 if (context && context->in_syscall) {
79454 struct audit_buffer *ab;
79455
79456diff --git a/kernel/capability.c b/kernel/capability.c
79457index f6c2ce5..982c0f9 100644
79458--- a/kernel/capability.c
79459+++ b/kernel/capability.c
79460@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
79461 * before modification is attempted and the application
79462 * fails.
79463 */
79464+ if (tocopy > ARRAY_SIZE(kdata))
79465+ return -EFAULT;
79466+
79467 if (copy_to_user(dataptr, kdata, tocopy
79468 * sizeof(struct __user_cap_data_struct))) {
79469 return -EFAULT;
79470@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
79471 int ret;
79472
79473 rcu_read_lock();
79474- ret = security_capable(__task_cred(t), ns, cap);
79475+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
79476+ gr_task_is_capable(t, __task_cred(t), cap);
79477 rcu_read_unlock();
79478
79479- return (ret == 0);
79480+ return ret;
79481 }
79482
79483 /**
79484@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
79485 int ret;
79486
79487 rcu_read_lock();
79488- ret = security_capable_noaudit(__task_cred(t), ns, cap);
79489+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
79490 rcu_read_unlock();
79491
79492- return (ret == 0);
79493+ return ret;
79494 }
79495
79496 /**
79497@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
79498 BUG();
79499 }
79500
79501- if (security_capable(current_cred(), ns, cap) == 0) {
79502+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
79503 current->flags |= PF_SUPERPRIV;
79504 return true;
79505 }
79506@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
79507 }
79508 EXPORT_SYMBOL(ns_capable);
79509
79510+bool ns_capable_nolog(struct user_namespace *ns, int cap)
79511+{
79512+ if (unlikely(!cap_valid(cap))) {
79513+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
79514+ BUG();
79515+ }
79516+
79517+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
79518+ current->flags |= PF_SUPERPRIV;
79519+ return true;
79520+ }
79521+ return false;
79522+}
79523+EXPORT_SYMBOL(ns_capable_nolog);
79524+
79525 /**
79526 * file_ns_capable - Determine if the file's opener had a capability in effect
79527 * @file: The file we want to check
79528@@ -432,6 +451,12 @@ bool capable(int cap)
79529 }
79530 EXPORT_SYMBOL(capable);
79531
79532+bool capable_nolog(int cap)
79533+{
79534+ return ns_capable_nolog(&init_user_ns, cap);
79535+}
79536+EXPORT_SYMBOL(capable_nolog);
79537+
79538 /**
79539 * nsown_capable - Check superior capability to one's own user_ns
79540 * @cap: The capability in question
79541@@ -464,3 +489,10 @@ bool inode_capable(const struct inode *inode, int cap)
79542
79543 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
79544 }
79545+
79546+bool inode_capable_nolog(const struct inode *inode, int cap)
79547+{
79548+ struct user_namespace *ns = current_user_ns();
79549+
79550+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
79551+}
79552diff --git a/kernel/cgroup.c b/kernel/cgroup.c
79553index e919633..f46b08f 100644
79554--- a/kernel/cgroup.c
79555+++ b/kernel/cgroup.c
79556@@ -5623,7 +5623,7 @@ static int cgroup_css_links_read(struct cgroup *cgrp,
79557 struct css_set *cset = link->cset;
79558 struct task_struct *task;
79559 int count = 0;
79560- seq_printf(seq, "css_set %p\n", cset);
79561+ seq_printf(seq, "css_set %pK\n", cset);
79562 list_for_each_entry(task, &cset->tasks, cg_list) {
79563 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
79564 seq_puts(seq, " ...\n");
79565diff --git a/kernel/compat.c b/kernel/compat.c
79566index 0a09e48..f44f3f0 100644
79567--- a/kernel/compat.c
79568+++ b/kernel/compat.c
79569@@ -13,6 +13,7 @@
79570
79571 #include <linux/linkage.h>
79572 #include <linux/compat.h>
79573+#include <linux/module.h>
79574 #include <linux/errno.h>
79575 #include <linux/time.h>
79576 #include <linux/signal.h>
79577@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
79578 mm_segment_t oldfs;
79579 long ret;
79580
79581- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
79582+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
79583 oldfs = get_fs();
79584 set_fs(KERNEL_DS);
79585 ret = hrtimer_nanosleep_restart(restart);
79586@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
79587 oldfs = get_fs();
79588 set_fs(KERNEL_DS);
79589 ret = hrtimer_nanosleep(&tu,
79590- rmtp ? (struct timespec __user *)&rmt : NULL,
79591+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
79592 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
79593 set_fs(oldfs);
79594
79595@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
79596 mm_segment_t old_fs = get_fs();
79597
79598 set_fs(KERNEL_DS);
79599- ret = sys_sigpending((old_sigset_t __user *) &s);
79600+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
79601 set_fs(old_fs);
79602 if (ret == 0)
79603 ret = put_user(s, set);
79604@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
79605 mm_segment_t old_fs = get_fs();
79606
79607 set_fs(KERNEL_DS);
79608- ret = sys_old_getrlimit(resource, &r);
79609+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
79610 set_fs(old_fs);
79611
79612 if (!ret) {
79613@@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
79614 set_fs (KERNEL_DS);
79615 ret = sys_wait4(pid,
79616 (stat_addr ?
79617- (unsigned int __user *) &status : NULL),
79618- options, (struct rusage __user *) &r);
79619+ (unsigned int __force_user *) &status : NULL),
79620+ options, (struct rusage __force_user *) &r);
79621 set_fs (old_fs);
79622
79623 if (ret > 0) {
79624@@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
79625 memset(&info, 0, sizeof(info));
79626
79627 set_fs(KERNEL_DS);
79628- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
79629- uru ? (struct rusage __user *)&ru : NULL);
79630+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
79631+ uru ? (struct rusage __force_user *)&ru : NULL);
79632 set_fs(old_fs);
79633
79634 if ((ret < 0) || (info.si_signo == 0))
79635@@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
79636 oldfs = get_fs();
79637 set_fs(KERNEL_DS);
79638 err = sys_timer_settime(timer_id, flags,
79639- (struct itimerspec __user *) &newts,
79640- (struct itimerspec __user *) &oldts);
79641+ (struct itimerspec __force_user *) &newts,
79642+ (struct itimerspec __force_user *) &oldts);
79643 set_fs(oldfs);
79644 if (!err && old && put_compat_itimerspec(old, &oldts))
79645 return -EFAULT;
79646@@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
79647 oldfs = get_fs();
79648 set_fs(KERNEL_DS);
79649 err = sys_timer_gettime(timer_id,
79650- (struct itimerspec __user *) &ts);
79651+ (struct itimerspec __force_user *) &ts);
79652 set_fs(oldfs);
79653 if (!err && put_compat_itimerspec(setting, &ts))
79654 return -EFAULT;
79655@@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
79656 oldfs = get_fs();
79657 set_fs(KERNEL_DS);
79658 err = sys_clock_settime(which_clock,
79659- (struct timespec __user *) &ts);
79660+ (struct timespec __force_user *) &ts);
79661 set_fs(oldfs);
79662 return err;
79663 }
79664@@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
79665 oldfs = get_fs();
79666 set_fs(KERNEL_DS);
79667 err = sys_clock_gettime(which_clock,
79668- (struct timespec __user *) &ts);
79669+ (struct timespec __force_user *) &ts);
79670 set_fs(oldfs);
79671 if (!err && put_compat_timespec(&ts, tp))
79672 return -EFAULT;
79673@@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
79674
79675 oldfs = get_fs();
79676 set_fs(KERNEL_DS);
79677- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
79678+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
79679 set_fs(oldfs);
79680
79681 err = compat_put_timex(utp, &txc);
79682@@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
79683 oldfs = get_fs();
79684 set_fs(KERNEL_DS);
79685 err = sys_clock_getres(which_clock,
79686- (struct timespec __user *) &ts);
79687+ (struct timespec __force_user *) &ts);
79688 set_fs(oldfs);
79689 if (!err && tp && put_compat_timespec(&ts, tp))
79690 return -EFAULT;
79691@@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
79692 long err;
79693 mm_segment_t oldfs;
79694 struct timespec tu;
79695- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
79696+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
79697
79698- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
79699+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
79700 oldfs = get_fs();
79701 set_fs(KERNEL_DS);
79702 err = clock_nanosleep_restart(restart);
79703@@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
79704 oldfs = get_fs();
79705 set_fs(KERNEL_DS);
79706 err = sys_clock_nanosleep(which_clock, flags,
79707- (struct timespec __user *) &in,
79708- (struct timespec __user *) &out);
79709+ (struct timespec __force_user *) &in,
79710+ (struct timespec __force_user *) &out);
79711 set_fs(oldfs);
79712
79713 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
79714diff --git a/kernel/configs.c b/kernel/configs.c
79715index c18b1f1..b9a0132 100644
79716--- a/kernel/configs.c
79717+++ b/kernel/configs.c
79718@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
79719 struct proc_dir_entry *entry;
79720
79721 /* create the current config file */
79722+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
79723+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
79724+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
79725+ &ikconfig_file_ops);
79726+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
79727+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
79728+ &ikconfig_file_ops);
79729+#endif
79730+#else
79731 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
79732 &ikconfig_file_ops);
79733+#endif
79734+
79735 if (!entry)
79736 return -ENOMEM;
79737
79738diff --git a/kernel/cred.c b/kernel/cred.c
79739index e0573a4..3874e41 100644
79740--- a/kernel/cred.c
79741+++ b/kernel/cred.c
79742@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
79743 validate_creds(cred);
79744 alter_cred_subscribers(cred, -1);
79745 put_cred(cred);
79746+
79747+#ifdef CONFIG_GRKERNSEC_SETXID
79748+ cred = (struct cred *) tsk->delayed_cred;
79749+ if (cred != NULL) {
79750+ tsk->delayed_cred = NULL;
79751+ validate_creds(cred);
79752+ alter_cred_subscribers(cred, -1);
79753+ put_cred(cred);
79754+ }
79755+#endif
79756 }
79757
79758 /**
79759@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
79760 * Always returns 0 thus allowing this function to be tail-called at the end
79761 * of, say, sys_setgid().
79762 */
79763-int commit_creds(struct cred *new)
79764+static int __commit_creds(struct cred *new)
79765 {
79766 struct task_struct *task = current;
79767 const struct cred *old = task->real_cred;
79768@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
79769
79770 get_cred(new); /* we will require a ref for the subj creds too */
79771
79772+ gr_set_role_label(task, new->uid, new->gid);
79773+
79774 /* dumpability changes */
79775 if (!uid_eq(old->euid, new->euid) ||
79776 !gid_eq(old->egid, new->egid) ||
79777@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
79778 put_cred(old);
79779 return 0;
79780 }
79781+#ifdef CONFIG_GRKERNSEC_SETXID
79782+extern int set_user(struct cred *new);
79783+
79784+void gr_delayed_cred_worker(void)
79785+{
79786+ const struct cred *new = current->delayed_cred;
79787+ struct cred *ncred;
79788+
79789+ current->delayed_cred = NULL;
79790+
79791+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
79792+ // from doing get_cred on it when queueing this
79793+ put_cred(new);
79794+ return;
79795+ } else if (new == NULL)
79796+ return;
79797+
79798+ ncred = prepare_creds();
79799+ if (!ncred)
79800+ goto die;
79801+ // uids
79802+ ncred->uid = new->uid;
79803+ ncred->euid = new->euid;
79804+ ncred->suid = new->suid;
79805+ ncred->fsuid = new->fsuid;
79806+ // gids
79807+ ncred->gid = new->gid;
79808+ ncred->egid = new->egid;
79809+ ncred->sgid = new->sgid;
79810+ ncred->fsgid = new->fsgid;
79811+ // groups
79812+ if (set_groups(ncred, new->group_info) < 0) {
79813+ abort_creds(ncred);
79814+ goto die;
79815+ }
79816+ // caps
79817+ ncred->securebits = new->securebits;
79818+ ncred->cap_inheritable = new->cap_inheritable;
79819+ ncred->cap_permitted = new->cap_permitted;
79820+ ncred->cap_effective = new->cap_effective;
79821+ ncred->cap_bset = new->cap_bset;
79822+
79823+ if (set_user(ncred)) {
79824+ abort_creds(ncred);
79825+ goto die;
79826+ }
79827+
79828+ // from doing get_cred on it when queueing this
79829+ put_cred(new);
79830+
79831+ __commit_creds(ncred);
79832+ return;
79833+die:
79834+ // from doing get_cred on it when queueing this
79835+ put_cred(new);
79836+ do_group_exit(SIGKILL);
79837+}
79838+#endif
79839+
79840+int commit_creds(struct cred *new)
79841+{
79842+#ifdef CONFIG_GRKERNSEC_SETXID
79843+ int ret;
79844+ int schedule_it = 0;
79845+ struct task_struct *t;
79846+
79847+ /* we won't get called with tasklist_lock held for writing
79848+ and interrupts disabled as the cred struct in that case is
79849+ init_cred
79850+ */
79851+ if (grsec_enable_setxid && !current_is_single_threaded() &&
79852+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
79853+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
79854+ schedule_it = 1;
79855+ }
79856+ ret = __commit_creds(new);
79857+ if (schedule_it) {
79858+ rcu_read_lock();
79859+ read_lock(&tasklist_lock);
79860+ for (t = next_thread(current); t != current;
79861+ t = next_thread(t)) {
79862+ if (t->delayed_cred == NULL) {
79863+ t->delayed_cred = get_cred(new);
79864+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
79865+ set_tsk_need_resched(t);
79866+ }
79867+ }
79868+ read_unlock(&tasklist_lock);
79869+ rcu_read_unlock();
79870+ }
79871+ return ret;
79872+#else
79873+ return __commit_creds(new);
79874+#endif
79875+}
79876+
79877 EXPORT_SYMBOL(commit_creds);
79878
79879 /**
79880diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
79881index 0506d44..2c20034 100644
79882--- a/kernel/debug/debug_core.c
79883+++ b/kernel/debug/debug_core.c
79884@@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
79885 */
79886 static atomic_t masters_in_kgdb;
79887 static atomic_t slaves_in_kgdb;
79888-static atomic_t kgdb_break_tasklet_var;
79889+static atomic_unchecked_t kgdb_break_tasklet_var;
79890 atomic_t kgdb_setting_breakpoint;
79891
79892 struct task_struct *kgdb_usethread;
79893@@ -133,7 +133,7 @@ int kgdb_single_step;
79894 static pid_t kgdb_sstep_pid;
79895
79896 /* to keep track of the CPU which is doing the single stepping*/
79897-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
79898+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
79899
79900 /*
79901 * If you are debugging a problem where roundup (the collection of
79902@@ -541,7 +541,7 @@ return_normal:
79903 * kernel will only try for the value of sstep_tries before
79904 * giving up and continuing on.
79905 */
79906- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
79907+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
79908 (kgdb_info[cpu].task &&
79909 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
79910 atomic_set(&kgdb_active, -1);
79911@@ -635,8 +635,8 @@ cpu_master_loop:
79912 }
79913
79914 kgdb_restore:
79915- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
79916- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
79917+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
79918+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
79919 if (kgdb_info[sstep_cpu].task)
79920 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
79921 else
79922@@ -888,18 +888,18 @@ static void kgdb_unregister_callbacks(void)
79923 static void kgdb_tasklet_bpt(unsigned long ing)
79924 {
79925 kgdb_breakpoint();
79926- atomic_set(&kgdb_break_tasklet_var, 0);
79927+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
79928 }
79929
79930 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
79931
79932 void kgdb_schedule_breakpoint(void)
79933 {
79934- if (atomic_read(&kgdb_break_tasklet_var) ||
79935+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
79936 atomic_read(&kgdb_active) != -1 ||
79937 atomic_read(&kgdb_setting_breakpoint))
79938 return;
79939- atomic_inc(&kgdb_break_tasklet_var);
79940+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
79941 tasklet_schedule(&kgdb_tasklet_breakpoint);
79942 }
79943 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
79944diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
79945index 00eb8f7..d7e3244 100644
79946--- a/kernel/debug/kdb/kdb_main.c
79947+++ b/kernel/debug/kdb/kdb_main.c
79948@@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
79949 continue;
79950
79951 kdb_printf("%-20s%8u 0x%p ", mod->name,
79952- mod->core_size, (void *)mod);
79953+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
79954 #ifdef CONFIG_MODULE_UNLOAD
79955 kdb_printf("%4ld ", module_refcount(mod));
79956 #endif
79957@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
79958 kdb_printf(" (Loading)");
79959 else
79960 kdb_printf(" (Live)");
79961- kdb_printf(" 0x%p", mod->module_core);
79962+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
79963
79964 #ifdef CONFIG_MODULE_UNLOAD
79965 {
79966diff --git a/kernel/events/core.c b/kernel/events/core.c
79967index f86599e..b18b180 100644
79968--- a/kernel/events/core.c
79969+++ b/kernel/events/core.c
79970@@ -156,8 +156,15 @@ static struct srcu_struct pmus_srcu;
79971 * 0 - disallow raw tracepoint access for unpriv
79972 * 1 - disallow cpu events for unpriv
79973 * 2 - disallow kernel profiling for unpriv
79974+ * 3 - disallow all unpriv perf event use
79975 */
79976-int sysctl_perf_event_paranoid __read_mostly = 1;
79977+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
79978+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
79979+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
79980+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
79981+#else
79982+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
79983+#endif
79984
79985 /* Minimum for 512 kiB + 1 user control page */
79986 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
79987@@ -270,7 +277,7 @@ void perf_sample_event_took(u64 sample_len_ns)
79988 update_perf_cpu_limits();
79989 }
79990
79991-static atomic64_t perf_event_id;
79992+static atomic64_unchecked_t perf_event_id;
79993
79994 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
79995 enum event_type_t event_type);
79996@@ -2936,7 +2943,7 @@ static void __perf_event_read(void *info)
79997
79998 static inline u64 perf_event_count(struct perf_event *event)
79999 {
80000- return local64_read(&event->count) + atomic64_read(&event->child_count);
80001+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
80002 }
80003
80004 static u64 perf_event_read(struct perf_event *event)
80005@@ -3282,9 +3289,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
80006 mutex_lock(&event->child_mutex);
80007 total += perf_event_read(event);
80008 *enabled += event->total_time_enabled +
80009- atomic64_read(&event->child_total_time_enabled);
80010+ atomic64_read_unchecked(&event->child_total_time_enabled);
80011 *running += event->total_time_running +
80012- atomic64_read(&event->child_total_time_running);
80013+ atomic64_read_unchecked(&event->child_total_time_running);
80014
80015 list_for_each_entry(child, &event->child_list, child_list) {
80016 total += perf_event_read(child);
80017@@ -3670,10 +3677,10 @@ void perf_event_update_userpage(struct perf_event *event)
80018 userpg->offset -= local64_read(&event->hw.prev_count);
80019
80020 userpg->time_enabled = enabled +
80021- atomic64_read(&event->child_total_time_enabled);
80022+ atomic64_read_unchecked(&event->child_total_time_enabled);
80023
80024 userpg->time_running = running +
80025- atomic64_read(&event->child_total_time_running);
80026+ atomic64_read_unchecked(&event->child_total_time_running);
80027
80028 arch_perf_update_userpage(userpg, now);
80029
80030@@ -4223,7 +4230,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
80031
80032 /* Data. */
80033 sp = perf_user_stack_pointer(regs);
80034- rem = __output_copy_user(handle, (void *) sp, dump_size);
80035+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
80036 dyn_size = dump_size - rem;
80037
80038 perf_output_skip(handle, rem);
80039@@ -4311,11 +4318,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
80040 values[n++] = perf_event_count(event);
80041 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
80042 values[n++] = enabled +
80043- atomic64_read(&event->child_total_time_enabled);
80044+ atomic64_read_unchecked(&event->child_total_time_enabled);
80045 }
80046 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
80047 values[n++] = running +
80048- atomic64_read(&event->child_total_time_running);
80049+ atomic64_read_unchecked(&event->child_total_time_running);
80050 }
80051 if (read_format & PERF_FORMAT_ID)
80052 values[n++] = primary_event_id(event);
80053@@ -5024,12 +5031,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
80054 * need to add enough zero bytes after the string to handle
80055 * the 64bit alignment we do later.
80056 */
80057- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
80058+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
80059 if (!buf) {
80060 name = strncpy(tmp, "//enomem", sizeof(tmp));
80061 goto got_name;
80062 }
80063- name = d_path(&file->f_path, buf, PATH_MAX);
80064+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
80065 if (IS_ERR(name)) {
80066 name = strncpy(tmp, "//toolong", sizeof(tmp));
80067 goto got_name;
80068@@ -6498,7 +6505,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
80069 event->parent = parent_event;
80070
80071 event->ns = get_pid_ns(task_active_pid_ns(current));
80072- event->id = atomic64_inc_return(&perf_event_id);
80073+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
80074
80075 event->state = PERF_EVENT_STATE_INACTIVE;
80076
80077@@ -6807,6 +6814,11 @@ SYSCALL_DEFINE5(perf_event_open,
80078 if (flags & ~PERF_FLAG_ALL)
80079 return -EINVAL;
80080
80081+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
80082+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
80083+ return -EACCES;
80084+#endif
80085+
80086 err = perf_copy_attr(attr_uptr, &attr);
80087 if (err)
80088 return err;
80089@@ -7139,10 +7151,10 @@ static void sync_child_event(struct perf_event *child_event,
80090 /*
80091 * Add back the child's count to the parent's count:
80092 */
80093- atomic64_add(child_val, &parent_event->child_count);
80094- atomic64_add(child_event->total_time_enabled,
80095+ atomic64_add_unchecked(child_val, &parent_event->child_count);
80096+ atomic64_add_unchecked(child_event->total_time_enabled,
80097 &parent_event->child_total_time_enabled);
80098- atomic64_add(child_event->total_time_running,
80099+ atomic64_add_unchecked(child_event->total_time_running,
80100 &parent_event->child_total_time_running);
80101
80102 /*
80103diff --git a/kernel/events/internal.h b/kernel/events/internal.h
80104index ca65997..60df03d 100644
80105--- a/kernel/events/internal.h
80106+++ b/kernel/events/internal.h
80107@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
80108 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
80109 }
80110
80111-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
80112-static inline unsigned int \
80113+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
80114+static inline unsigned long \
80115 func_name(struct perf_output_handle *handle, \
80116- const void *buf, unsigned int len) \
80117+ const void user *buf, unsigned long len) \
80118 { \
80119 unsigned long size, written; \
80120 \
80121@@ -116,17 +116,17 @@ static inline int memcpy_common(void *dst, const void *src, size_t n)
80122 return n;
80123 }
80124
80125-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
80126+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
80127
80128 #define MEMCPY_SKIP(dst, src, n) (n)
80129
80130-DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP)
80131+DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP, )
80132
80133 #ifndef arch_perf_out_copy_user
80134 #define arch_perf_out_copy_user __copy_from_user_inatomic
80135 #endif
80136
80137-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
80138+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
80139
80140 /* Callchain handling */
80141 extern struct perf_callchain_entry *
80142diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
80143index ad8e1bd..fed7ba9 100644
80144--- a/kernel/events/uprobes.c
80145+++ b/kernel/events/uprobes.c
80146@@ -1556,7 +1556,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
80147 {
80148 struct page *page;
80149 uprobe_opcode_t opcode;
80150- int result;
80151+ long result;
80152
80153 pagefault_disable();
80154 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
80155diff --git a/kernel/exit.c b/kernel/exit.c
80156index a949819..a5f127d 100644
80157--- a/kernel/exit.c
80158+++ b/kernel/exit.c
80159@@ -172,6 +172,10 @@ void release_task(struct task_struct * p)
80160 struct task_struct *leader;
80161 int zap_leader;
80162 repeat:
80163+#ifdef CONFIG_NET
80164+ gr_del_task_from_ip_table(p);
80165+#endif
80166+
80167 /* don't need to get the RCU readlock here - the process is dead and
80168 * can't be modifying its own credentials. But shut RCU-lockdep up */
80169 rcu_read_lock();
80170@@ -329,7 +333,7 @@ int allow_signal(int sig)
80171 * know it'll be handled, so that they don't get converted to
80172 * SIGKILL or just silently dropped.
80173 */
80174- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
80175+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
80176 recalc_sigpending();
80177 spin_unlock_irq(&current->sighand->siglock);
80178 return 0;
80179@@ -698,6 +702,8 @@ void do_exit(long code)
80180 struct task_struct *tsk = current;
80181 int group_dead;
80182
80183+ set_fs(USER_DS);
80184+
80185 profile_task_exit(tsk);
80186
80187 WARN_ON(blk_needs_flush_plug(tsk));
80188@@ -714,7 +720,6 @@ void do_exit(long code)
80189 * mm_release()->clear_child_tid() from writing to a user-controlled
80190 * kernel address.
80191 */
80192- set_fs(USER_DS);
80193
80194 ptrace_event(PTRACE_EVENT_EXIT, code);
80195
80196@@ -773,6 +778,9 @@ void do_exit(long code)
80197 tsk->exit_code = code;
80198 taskstats_exit(tsk, group_dead);
80199
80200+ gr_acl_handle_psacct(tsk, code);
80201+ gr_acl_handle_exit();
80202+
80203 exit_mm(tsk);
80204
80205 if (group_dead)
80206@@ -894,7 +902,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
80207 * Take down every thread in the group. This is called by fatal signals
80208 * as well as by sys_exit_group (below).
80209 */
80210-void
80211+__noreturn void
80212 do_group_exit(int exit_code)
80213 {
80214 struct signal_struct *sig = current->signal;
80215diff --git a/kernel/fork.c b/kernel/fork.c
80216index 200a7a2..43e52da 100644
80217--- a/kernel/fork.c
80218+++ b/kernel/fork.c
80219@@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
80220 *stackend = STACK_END_MAGIC; /* for overflow detection */
80221
80222 #ifdef CONFIG_CC_STACKPROTECTOR
80223- tsk->stack_canary = get_random_int();
80224+ tsk->stack_canary = pax_get_random_long();
80225 #endif
80226
80227 /*
80228@@ -345,13 +345,81 @@ free_tsk:
80229 }
80230
80231 #ifdef CONFIG_MMU
80232-static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80233+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
80234 {
80235- struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
80236- struct rb_node **rb_link, *rb_parent;
80237- int retval;
80238+ struct vm_area_struct *tmp;
80239 unsigned long charge;
80240 struct mempolicy *pol;
80241+ struct file *file;
80242+
80243+ charge = 0;
80244+ if (mpnt->vm_flags & VM_ACCOUNT) {
80245+ unsigned long len = vma_pages(mpnt);
80246+
80247+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
80248+ goto fail_nomem;
80249+ charge = len;
80250+ }
80251+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
80252+ if (!tmp)
80253+ goto fail_nomem;
80254+ *tmp = *mpnt;
80255+ tmp->vm_mm = mm;
80256+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
80257+ pol = mpol_dup(vma_policy(mpnt));
80258+ if (IS_ERR(pol))
80259+ goto fail_nomem_policy;
80260+ vma_set_policy(tmp, pol);
80261+ if (anon_vma_fork(tmp, mpnt))
80262+ goto fail_nomem_anon_vma_fork;
80263+ tmp->vm_flags &= ~VM_LOCKED;
80264+ tmp->vm_next = tmp->vm_prev = NULL;
80265+ tmp->vm_mirror = NULL;
80266+ file = tmp->vm_file;
80267+ if (file) {
80268+ struct inode *inode = file_inode(file);
80269+ struct address_space *mapping = file->f_mapping;
80270+
80271+ get_file(file);
80272+ if (tmp->vm_flags & VM_DENYWRITE)
80273+ atomic_dec(&inode->i_writecount);
80274+ mutex_lock(&mapping->i_mmap_mutex);
80275+ if (tmp->vm_flags & VM_SHARED)
80276+ mapping->i_mmap_writable++;
80277+ flush_dcache_mmap_lock(mapping);
80278+ /* insert tmp into the share list, just after mpnt */
80279+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
80280+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
80281+ else
80282+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
80283+ flush_dcache_mmap_unlock(mapping);
80284+ mutex_unlock(&mapping->i_mmap_mutex);
80285+ }
80286+
80287+ /*
80288+ * Clear hugetlb-related page reserves for children. This only
80289+ * affects MAP_PRIVATE mappings. Faults generated by the child
80290+ * are not guaranteed to succeed, even if read-only
80291+ */
80292+ if (is_vm_hugetlb_page(tmp))
80293+ reset_vma_resv_huge_pages(tmp);
80294+
80295+ return tmp;
80296+
80297+fail_nomem_anon_vma_fork:
80298+ mpol_put(pol);
80299+fail_nomem_policy:
80300+ kmem_cache_free(vm_area_cachep, tmp);
80301+fail_nomem:
80302+ vm_unacct_memory(charge);
80303+ return NULL;
80304+}
80305+
80306+static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80307+{
80308+ struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
80309+ struct rb_node **rb_link, *rb_parent;
80310+ int retval;
80311
80312 uprobe_start_dup_mmap();
80313 down_write(&oldmm->mmap_sem);
80314@@ -380,57 +448,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80315
80316 prev = NULL;
80317 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
80318- struct file *file;
80319-
80320 if (mpnt->vm_flags & VM_DONTCOPY) {
80321 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
80322 -vma_pages(mpnt));
80323 continue;
80324 }
80325- charge = 0;
80326- if (mpnt->vm_flags & VM_ACCOUNT) {
80327- unsigned long len = vma_pages(mpnt);
80328-
80329- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
80330- goto fail_nomem;
80331- charge = len;
80332- }
80333- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
80334- if (!tmp)
80335- goto fail_nomem;
80336- *tmp = *mpnt;
80337- INIT_LIST_HEAD(&tmp->anon_vma_chain);
80338- pol = mpol_dup(vma_policy(mpnt));
80339- retval = PTR_ERR(pol);
80340- if (IS_ERR(pol))
80341- goto fail_nomem_policy;
80342- vma_set_policy(tmp, pol);
80343- tmp->vm_mm = mm;
80344- if (anon_vma_fork(tmp, mpnt))
80345- goto fail_nomem_anon_vma_fork;
80346- tmp->vm_flags &= ~VM_LOCKED;
80347- tmp->vm_next = tmp->vm_prev = NULL;
80348- file = tmp->vm_file;
80349- if (file) {
80350- struct inode *inode = file_inode(file);
80351- struct address_space *mapping = file->f_mapping;
80352-
80353- get_file(file);
80354- if (tmp->vm_flags & VM_DENYWRITE)
80355- atomic_dec(&inode->i_writecount);
80356- mutex_lock(&mapping->i_mmap_mutex);
80357- if (tmp->vm_flags & VM_SHARED)
80358- mapping->i_mmap_writable++;
80359- flush_dcache_mmap_lock(mapping);
80360- /* insert tmp into the share list, just after mpnt */
80361- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
80362- vma_nonlinear_insert(tmp,
80363- &mapping->i_mmap_nonlinear);
80364- else
80365- vma_interval_tree_insert_after(tmp, mpnt,
80366- &mapping->i_mmap);
80367- flush_dcache_mmap_unlock(mapping);
80368- mutex_unlock(&mapping->i_mmap_mutex);
80369+ tmp = dup_vma(mm, oldmm, mpnt);
80370+ if (!tmp) {
80371+ retval = -ENOMEM;
80372+ goto out;
80373 }
80374
80375 /*
80376@@ -462,6 +488,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80377 if (retval)
80378 goto out;
80379 }
80380+
80381+#ifdef CONFIG_PAX_SEGMEXEC
80382+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
80383+ struct vm_area_struct *mpnt_m;
80384+
80385+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
80386+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
80387+
80388+ if (!mpnt->vm_mirror)
80389+ continue;
80390+
80391+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
80392+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
80393+ mpnt->vm_mirror = mpnt_m;
80394+ } else {
80395+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
80396+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
80397+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
80398+ mpnt->vm_mirror->vm_mirror = mpnt;
80399+ }
80400+ }
80401+ BUG_ON(mpnt_m);
80402+ }
80403+#endif
80404+
80405 /* a new mm has just been created */
80406 arch_dup_mmap(oldmm, mm);
80407 retval = 0;
80408@@ -471,14 +522,6 @@ out:
80409 up_write(&oldmm->mmap_sem);
80410 uprobe_end_dup_mmap();
80411 return retval;
80412-fail_nomem_anon_vma_fork:
80413- mpol_put(pol);
80414-fail_nomem_policy:
80415- kmem_cache_free(vm_area_cachep, tmp);
80416-fail_nomem:
80417- retval = -ENOMEM;
80418- vm_unacct_memory(charge);
80419- goto out;
80420 }
80421
80422 static inline int mm_alloc_pgd(struct mm_struct *mm)
80423@@ -691,8 +734,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
80424 return ERR_PTR(err);
80425
80426 mm = get_task_mm(task);
80427- if (mm && mm != current->mm &&
80428- !ptrace_may_access(task, mode)) {
80429+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
80430+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
80431 mmput(mm);
80432 mm = ERR_PTR(-EACCES);
80433 }
80434@@ -914,13 +957,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
80435 spin_unlock(&fs->lock);
80436 return -EAGAIN;
80437 }
80438- fs->users++;
80439+ atomic_inc(&fs->users);
80440 spin_unlock(&fs->lock);
80441 return 0;
80442 }
80443 tsk->fs = copy_fs_struct(fs);
80444 if (!tsk->fs)
80445 return -ENOMEM;
80446+ /* Carry through gr_chroot_dentry and is_chrooted instead
80447+ of recomputing it here. Already copied when the task struct
80448+ is duplicated. This allows pivot_root to not be treated as
80449+ a chroot
80450+ */
80451+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
80452+
80453 return 0;
80454 }
80455
80456@@ -1131,7 +1181,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
80457 * parts of the process environment (as per the clone
80458 * flags). The actual kick-off is left to the caller.
80459 */
80460-static struct task_struct *copy_process(unsigned long clone_flags,
80461+static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
80462 unsigned long stack_start,
80463 unsigned long stack_size,
80464 int __user *child_tidptr,
80465@@ -1201,6 +1251,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
80466 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
80467 #endif
80468 retval = -EAGAIN;
80469+
80470+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
80471+
80472 if (atomic_read(&p->real_cred->user->processes) >=
80473 task_rlimit(p, RLIMIT_NPROC)) {
80474 if (p->real_cred->user != INIT_USER &&
80475@@ -1450,6 +1503,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
80476 goto bad_fork_free_pid;
80477 }
80478
80479+ /* synchronizes with gr_set_acls()
80480+ we need to call this past the point of no return for fork()
80481+ */
80482+ gr_copy_label(p);
80483+
80484 if (likely(p->pid)) {
80485 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
80486
80487@@ -1535,6 +1593,8 @@ bad_fork_cleanup_count:
80488 bad_fork_free:
80489 free_task(p);
80490 fork_out:
80491+ gr_log_forkfail(retval);
80492+
80493 return ERR_PTR(retval);
80494 }
80495
80496@@ -1605,6 +1665,7 @@ long do_fork(unsigned long clone_flags,
80497
80498 p = copy_process(clone_flags, stack_start, stack_size,
80499 child_tidptr, NULL, trace);
80500+ add_latent_entropy();
80501 /*
80502 * Do this prior waking up the new thread - the thread pointer
80503 * might get invalid after that point, if the thread exits quickly.
80504@@ -1619,6 +1680,8 @@ long do_fork(unsigned long clone_flags,
80505 if (clone_flags & CLONE_PARENT_SETTID)
80506 put_user(nr, parent_tidptr);
80507
80508+ gr_handle_brute_check();
80509+
80510 if (clone_flags & CLONE_VFORK) {
80511 p->vfork_done = &vfork;
80512 init_completion(&vfork);
80513@@ -1735,7 +1798,7 @@ void __init proc_caches_init(void)
80514 mm_cachep = kmem_cache_create("mm_struct",
80515 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
80516 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
80517- vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
80518+ vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
80519 mmap_init();
80520 nsproxy_cache_init();
80521 }
80522@@ -1775,7 +1838,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
80523 return 0;
80524
80525 /* don't need lock here; in the worst case we'll do useless copy */
80526- if (fs->users == 1)
80527+ if (atomic_read(&fs->users) == 1)
80528 return 0;
80529
80530 *new_fsp = copy_fs_struct(fs);
80531@@ -1887,7 +1950,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
80532 fs = current->fs;
80533 spin_lock(&fs->lock);
80534 current->fs = new_fs;
80535- if (--fs->users)
80536+ gr_set_chroot_entries(current, &current->fs->root);
80537+ if (atomic_dec_return(&fs->users))
80538 new_fs = NULL;
80539 else
80540 new_fs = fs;
80541diff --git a/kernel/futex.c b/kernel/futex.c
80542index c3a1a55..e32b4a98 100644
80543--- a/kernel/futex.c
80544+++ b/kernel/futex.c
80545@@ -54,6 +54,7 @@
80546 #include <linux/mount.h>
80547 #include <linux/pagemap.h>
80548 #include <linux/syscalls.h>
80549+#include <linux/ptrace.h>
80550 #include <linux/signal.h>
80551 #include <linux/export.h>
80552 #include <linux/magic.h>
80553@@ -243,6 +244,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
80554 struct page *page, *page_head;
80555 int err, ro = 0;
80556
80557+#ifdef CONFIG_PAX_SEGMEXEC
80558+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
80559+ return -EFAULT;
80560+#endif
80561+
80562 /*
80563 * The futex address must be "naturally" aligned.
80564 */
80565@@ -441,7 +447,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
80566
80567 static int get_futex_value_locked(u32 *dest, u32 __user *from)
80568 {
80569- int ret;
80570+ unsigned long ret;
80571
80572 pagefault_disable();
80573 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
80574@@ -2734,6 +2740,7 @@ static int __init futex_init(void)
80575 {
80576 u32 curval;
80577 int i;
80578+ mm_segment_t oldfs;
80579
80580 /*
80581 * This will fail and we want it. Some arch implementations do
80582@@ -2745,8 +2752,11 @@ static int __init futex_init(void)
80583 * implementation, the non-functional ones will return
80584 * -ENOSYS.
80585 */
80586+ oldfs = get_fs();
80587+ set_fs(USER_DS);
80588 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
80589 futex_cmpxchg_enabled = 1;
80590+ set_fs(oldfs);
80591
80592 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
80593 plist_head_init(&futex_queues[i].chain);
80594diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
80595index f9f44fd..29885e4 100644
80596--- a/kernel/futex_compat.c
80597+++ b/kernel/futex_compat.c
80598@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
80599 return 0;
80600 }
80601
80602-static void __user *futex_uaddr(struct robust_list __user *entry,
80603+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
80604 compat_long_t futex_offset)
80605 {
80606 compat_uptr_t base = ptr_to_compat(entry);
80607diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
80608index 9b22d03..6295b62 100644
80609--- a/kernel/gcov/base.c
80610+++ b/kernel/gcov/base.c
80611@@ -102,11 +102,6 @@ void gcov_enable_events(void)
80612 }
80613
80614 #ifdef CONFIG_MODULES
80615-static inline int within(void *addr, void *start, unsigned long size)
80616-{
80617- return ((addr >= start) && (addr < start + size));
80618-}
80619-
80620 /* Update list and generate events when modules are unloaded. */
80621 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
80622 void *data)
80623@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
80624 prev = NULL;
80625 /* Remove entries located in module from linked list. */
80626 for (info = gcov_info_head; info; info = info->next) {
80627- if (within(info, mod->module_core, mod->core_size)) {
80628+ if (within_module_core_rw((unsigned long)info, mod)) {
80629 if (prev)
80630 prev->next = info->next;
80631 else
80632diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
80633index 383319b..56ebb13 100644
80634--- a/kernel/hrtimer.c
80635+++ b/kernel/hrtimer.c
80636@@ -1438,7 +1438,7 @@ void hrtimer_peek_ahead_timers(void)
80637 local_irq_restore(flags);
80638 }
80639
80640-static void run_hrtimer_softirq(struct softirq_action *h)
80641+static __latent_entropy void run_hrtimer_softirq(void)
80642 {
80643 hrtimer_peek_ahead_timers();
80644 }
80645diff --git a/kernel/irq_work.c b/kernel/irq_work.c
80646index 55fcce6..0e4cf34 100644
80647--- a/kernel/irq_work.c
80648+++ b/kernel/irq_work.c
80649@@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
80650 return NOTIFY_OK;
80651 }
80652
80653-static struct notifier_block cpu_notify;
80654+static struct notifier_block cpu_notify = {
80655+ .notifier_call = irq_work_cpu_notify,
80656+ .priority = 0,
80657+};
80658
80659 static __init int irq_work_init_cpu_notifier(void)
80660 {
80661- cpu_notify.notifier_call = irq_work_cpu_notify;
80662- cpu_notify.priority = 0;
80663 register_cpu_notifier(&cpu_notify);
80664 return 0;
80665 }
80666diff --git a/kernel/jump_label.c b/kernel/jump_label.c
80667index 60f48fa..7f3a770 100644
80668--- a/kernel/jump_label.c
80669+++ b/kernel/jump_label.c
80670@@ -13,6 +13,7 @@
80671 #include <linux/sort.h>
80672 #include <linux/err.h>
80673 #include <linux/static_key.h>
80674+#include <linux/mm.h>
80675
80676 #ifdef HAVE_JUMP_LABEL
80677
80678@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
80679
80680 size = (((unsigned long)stop - (unsigned long)start)
80681 / sizeof(struct jump_entry));
80682+ pax_open_kernel();
80683 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
80684+ pax_close_kernel();
80685 }
80686
80687 static void jump_label_update(struct static_key *key, int enable);
80688@@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
80689 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
80690 struct jump_entry *iter;
80691
80692+ pax_open_kernel();
80693 for (iter = iter_start; iter < iter_stop; iter++) {
80694 if (within_module_init(iter->code, mod))
80695 iter->code = 0;
80696 }
80697+ pax_close_kernel();
80698 }
80699
80700 static int
80701diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
80702index 3127ad5..159d880 100644
80703--- a/kernel/kallsyms.c
80704+++ b/kernel/kallsyms.c
80705@@ -11,6 +11,9 @@
80706 * Changed the compression method from stem compression to "table lookup"
80707 * compression (see scripts/kallsyms.c for a more complete description)
80708 */
80709+#ifdef CONFIG_GRKERNSEC_HIDESYM
80710+#define __INCLUDED_BY_HIDESYM 1
80711+#endif
80712 #include <linux/kallsyms.h>
80713 #include <linux/module.h>
80714 #include <linux/init.h>
80715@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
80716
80717 static inline int is_kernel_inittext(unsigned long addr)
80718 {
80719+ if (system_state != SYSTEM_BOOTING)
80720+ return 0;
80721+
80722 if (addr >= (unsigned long)_sinittext
80723 && addr <= (unsigned long)_einittext)
80724 return 1;
80725 return 0;
80726 }
80727
80728+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
80729+#ifdef CONFIG_MODULES
80730+static inline int is_module_text(unsigned long addr)
80731+{
80732+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
80733+ return 1;
80734+
80735+ addr = ktla_ktva(addr);
80736+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
80737+}
80738+#else
80739+static inline int is_module_text(unsigned long addr)
80740+{
80741+ return 0;
80742+}
80743+#endif
80744+#endif
80745+
80746 static inline int is_kernel_text(unsigned long addr)
80747 {
80748 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
80749@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
80750
80751 static inline int is_kernel(unsigned long addr)
80752 {
80753+
80754+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
80755+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
80756+ return 1;
80757+
80758+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
80759+#else
80760 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
80761+#endif
80762+
80763 return 1;
80764 return in_gate_area_no_mm(addr);
80765 }
80766
80767 static int is_ksym_addr(unsigned long addr)
80768 {
80769+
80770+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
80771+ if (is_module_text(addr))
80772+ return 0;
80773+#endif
80774+
80775 if (all_var)
80776 return is_kernel(addr);
80777
80778@@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
80779
80780 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
80781 {
80782- iter->name[0] = '\0';
80783 iter->nameoff = get_symbol_offset(new_pos);
80784 iter->pos = new_pos;
80785 }
80786@@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
80787 {
80788 struct kallsym_iter *iter = m->private;
80789
80790+#ifdef CONFIG_GRKERNSEC_HIDESYM
80791+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
80792+ return 0;
80793+#endif
80794+
80795 /* Some debugging symbols have no name. Ignore them. */
80796 if (!iter->name[0])
80797 return 0;
80798@@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
80799 */
80800 type = iter->exported ? toupper(iter->type) :
80801 tolower(iter->type);
80802+
80803 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
80804 type, iter->name, iter->module_name);
80805 } else
80806@@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
80807 struct kallsym_iter *iter;
80808 int ret;
80809
80810- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
80811+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
80812 if (!iter)
80813 return -ENOMEM;
80814 reset_iter(iter, 0);
80815diff --git a/kernel/kcmp.c b/kernel/kcmp.c
80816index e30ac0f..3528cac 100644
80817--- a/kernel/kcmp.c
80818+++ b/kernel/kcmp.c
80819@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
80820 struct task_struct *task1, *task2;
80821 int ret;
80822
80823+#ifdef CONFIG_GRKERNSEC
80824+ return -ENOSYS;
80825+#endif
80826+
80827 rcu_read_lock();
80828
80829 /*
80830diff --git a/kernel/kexec.c b/kernel/kexec.c
80831index 59f7b55..4022f65 100644
80832--- a/kernel/kexec.c
80833+++ b/kernel/kexec.c
80834@@ -1041,7 +1041,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
80835 unsigned long flags)
80836 {
80837 struct compat_kexec_segment in;
80838- struct kexec_segment out, __user *ksegments;
80839+ struct kexec_segment out;
80840+ struct kexec_segment __user *ksegments;
80841 unsigned long i, result;
80842
80843 /* Don't allow clients that don't understand the native
80844diff --git a/kernel/kmod.c b/kernel/kmod.c
80845index b086006..a27913b 100644
80846--- a/kernel/kmod.c
80847+++ b/kernel/kmod.c
80848@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
80849 kfree(info->argv);
80850 }
80851
80852-static int call_modprobe(char *module_name, int wait)
80853+static int call_modprobe(char *module_name, char *module_param, int wait)
80854 {
80855 struct subprocess_info *info;
80856 static char *envp[] = {
80857@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
80858 NULL
80859 };
80860
80861- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
80862+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
80863 if (!argv)
80864 goto out;
80865
80866@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
80867 argv[1] = "-q";
80868 argv[2] = "--";
80869 argv[3] = module_name; /* check free_modprobe_argv() */
80870- argv[4] = NULL;
80871+ argv[4] = module_param;
80872+ argv[5] = NULL;
80873
80874 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
80875 NULL, free_modprobe_argv, NULL);
80876@@ -129,9 +130,8 @@ out:
80877 * If module auto-loading support is disabled then this function
80878 * becomes a no-operation.
80879 */
80880-int __request_module(bool wait, const char *fmt, ...)
80881+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
80882 {
80883- va_list args;
80884 char module_name[MODULE_NAME_LEN];
80885 unsigned int max_modprobes;
80886 int ret;
80887@@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
80888 if (!modprobe_path[0])
80889 return 0;
80890
80891- va_start(args, fmt);
80892- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
80893- va_end(args);
80894+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
80895 if (ret >= MODULE_NAME_LEN)
80896 return -ENAMETOOLONG;
80897
80898@@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
80899 if (ret)
80900 return ret;
80901
80902+#ifdef CONFIG_GRKERNSEC_MODHARDEN
80903+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
80904+ /* hack to workaround consolekit/udisks stupidity */
80905+ read_lock(&tasklist_lock);
80906+ if (!strcmp(current->comm, "mount") &&
80907+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
80908+ read_unlock(&tasklist_lock);
80909+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
80910+ return -EPERM;
80911+ }
80912+ read_unlock(&tasklist_lock);
80913+ }
80914+#endif
80915+
80916 /* If modprobe needs a service that is in a module, we get a recursive
80917 * loop. Limit the number of running kmod threads to max_threads/2 or
80918 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
80919@@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
80920
80921 trace_module_request(module_name, wait, _RET_IP_);
80922
80923- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
80924+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
80925
80926 atomic_dec(&kmod_concurrent);
80927 return ret;
80928 }
80929+
80930+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
80931+{
80932+ va_list args;
80933+ int ret;
80934+
80935+ va_start(args, fmt);
80936+ ret = ____request_module(wait, module_param, fmt, args);
80937+ va_end(args);
80938+
80939+ return ret;
80940+}
80941+
80942+int __request_module(bool wait, const char *fmt, ...)
80943+{
80944+ va_list args;
80945+ int ret;
80946+
80947+#ifdef CONFIG_GRKERNSEC_MODHARDEN
80948+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
80949+ char module_param[MODULE_NAME_LEN];
80950+
80951+ memset(module_param, 0, sizeof(module_param));
80952+
80953+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
80954+
80955+ va_start(args, fmt);
80956+ ret = ____request_module(wait, module_param, fmt, args);
80957+ va_end(args);
80958+
80959+ return ret;
80960+ }
80961+#endif
80962+
80963+ va_start(args, fmt);
80964+ ret = ____request_module(wait, NULL, fmt, args);
80965+ va_end(args);
80966+
80967+ return ret;
80968+}
80969+
80970 EXPORT_SYMBOL(__request_module);
80971 #endif /* CONFIG_MODULES */
80972
80973@@ -303,7 +356,7 @@ static int wait_for_helper(void *data)
80974 *
80975 * Thus the __user pointer cast is valid here.
80976 */
80977- sys_wait4(pid, (int __user *)&ret, 0, NULL);
80978+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
80979
80980 /*
80981 * If ret is 0, either ____call_usermodehelper failed and the
80982@@ -650,7 +703,7 @@ EXPORT_SYMBOL(call_usermodehelper);
80983 static int proc_cap_handler(struct ctl_table *table, int write,
80984 void __user *buffer, size_t *lenp, loff_t *ppos)
80985 {
80986- struct ctl_table t;
80987+ ctl_table_no_const t;
80988 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
80989 kernel_cap_t new_cap;
80990 int err, i;
80991diff --git a/kernel/kprobes.c b/kernel/kprobes.c
80992index 6e33498..3133bd3 100644
80993--- a/kernel/kprobes.c
80994+++ b/kernel/kprobes.c
80995@@ -31,6 +31,9 @@
80996 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
80997 * <prasanna@in.ibm.com> added function-return probes.
80998 */
80999+#ifdef CONFIG_GRKERNSEC_HIDESYM
81000+#define __INCLUDED_BY_HIDESYM 1
81001+#endif
81002 #include <linux/kprobes.h>
81003 #include <linux/hash.h>
81004 #include <linux/init.h>
81005@@ -185,7 +188,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
81006 * kernel image and loaded module images reside. This is required
81007 * so x86_64 can correctly handle the %rip-relative fixups.
81008 */
81009- kip->insns = module_alloc(PAGE_SIZE);
81010+ kip->insns = module_alloc_exec(PAGE_SIZE);
81011 if (!kip->insns) {
81012 kfree(kip);
81013 return NULL;
81014@@ -225,7 +228,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
81015 */
81016 if (!list_is_singular(&kip->list)) {
81017 list_del(&kip->list);
81018- module_free(NULL, kip->insns);
81019+ module_free_exec(NULL, kip->insns);
81020 kfree(kip);
81021 }
81022 return 1;
81023@@ -2083,7 +2086,7 @@ static int __init init_kprobes(void)
81024 {
81025 int i, err = 0;
81026 unsigned long offset = 0, size = 0;
81027- char *modname, namebuf[128];
81028+ char *modname, namebuf[KSYM_NAME_LEN];
81029 const char *symbol_name;
81030 void *addr;
81031 struct kprobe_blackpoint *kb;
81032@@ -2168,11 +2171,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
81033 kprobe_type = "k";
81034
81035 if (sym)
81036- seq_printf(pi, "%p %s %s+0x%x %s ",
81037+ seq_printf(pi, "%pK %s %s+0x%x %s ",
81038 p->addr, kprobe_type, sym, offset,
81039 (modname ? modname : " "));
81040 else
81041- seq_printf(pi, "%p %s %p ",
81042+ seq_printf(pi, "%pK %s %pK ",
81043 p->addr, kprobe_type, p->addr);
81044
81045 if (!pp)
81046@@ -2209,7 +2212,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
81047 const char *sym = NULL;
81048 unsigned int i = *(loff_t *) v;
81049 unsigned long offset = 0;
81050- char *modname, namebuf[128];
81051+ char *modname, namebuf[KSYM_NAME_LEN];
81052
81053 head = &kprobe_table[i];
81054 preempt_disable();
81055diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
81056index 6ada93c..dce7d5d 100644
81057--- a/kernel/ksysfs.c
81058+++ b/kernel/ksysfs.c
81059@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
81060 {
81061 if (count+1 > UEVENT_HELPER_PATH_LEN)
81062 return -ENOENT;
81063+ if (!capable(CAP_SYS_ADMIN))
81064+ return -EPERM;
81065 memcpy(uevent_helper, buf, count);
81066 uevent_helper[count] = '\0';
81067 if (count && uevent_helper[count-1] == '\n')
81068@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
81069 return count;
81070 }
81071
81072-static struct bin_attribute notes_attr = {
81073+static bin_attribute_no_const notes_attr __read_only = {
81074 .attr = {
81075 .name = "notes",
81076 .mode = S_IRUGO,
81077diff --git a/kernel/lockdep.c b/kernel/lockdep.c
81078index e16c45b..6f49c48 100644
81079--- a/kernel/lockdep.c
81080+++ b/kernel/lockdep.c
81081@@ -596,6 +596,10 @@ static int static_obj(void *obj)
81082 end = (unsigned long) &_end,
81083 addr = (unsigned long) obj;
81084
81085+#ifdef CONFIG_PAX_KERNEXEC
81086+ start = ktla_ktva(start);
81087+#endif
81088+
81089 /*
81090 * static variable?
81091 */
81092@@ -736,6 +740,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
81093 if (!static_obj(lock->key)) {
81094 debug_locks_off();
81095 printk("INFO: trying to register non-static key.\n");
81096+ printk("lock:%pS key:%pS.\n", lock, lock->key);
81097 printk("the code is fine but needs lockdep annotation.\n");
81098 printk("turning off the locking correctness validator.\n");
81099 dump_stack();
81100@@ -3080,7 +3085,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
81101 if (!class)
81102 return 0;
81103 }
81104- atomic_inc((atomic_t *)&class->ops);
81105+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
81106 if (very_verbose(class)) {
81107 printk("\nacquire class [%p] %s", class->key, class->name);
81108 if (class->name_version > 1)
81109diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
81110index b2c71c5..7b88d63 100644
81111--- a/kernel/lockdep_proc.c
81112+++ b/kernel/lockdep_proc.c
81113@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
81114 return 0;
81115 }
81116
81117- seq_printf(m, "%p", class->key);
81118+ seq_printf(m, "%pK", class->key);
81119 #ifdef CONFIG_DEBUG_LOCKDEP
81120 seq_printf(m, " OPS:%8ld", class->ops);
81121 #endif
81122@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
81123
81124 list_for_each_entry(entry, &class->locks_after, entry) {
81125 if (entry->distance == 1) {
81126- seq_printf(m, " -> [%p] ", entry->class->key);
81127+ seq_printf(m, " -> [%pK] ", entry->class->key);
81128 print_name(m, entry->class);
81129 seq_puts(m, "\n");
81130 }
81131@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
81132 if (!class->key)
81133 continue;
81134
81135- seq_printf(m, "[%p] ", class->key);
81136+ seq_printf(m, "[%pK] ", class->key);
81137 print_name(m, class);
81138 seq_puts(m, "\n");
81139 }
81140@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
81141 if (!i)
81142 seq_line(m, '-', 40-namelen, namelen);
81143
81144- snprintf(ip, sizeof(ip), "[<%p>]",
81145+ snprintf(ip, sizeof(ip), "[<%pK>]",
81146 (void *)class->contention_point[i]);
81147 seq_printf(m, "%40s %14lu %29s %pS\n",
81148 name, stats->contention_point[i],
81149@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
81150 if (!i)
81151 seq_line(m, '-', 40-namelen, namelen);
81152
81153- snprintf(ip, sizeof(ip), "[<%p>]",
81154+ snprintf(ip, sizeof(ip), "[<%pK>]",
81155 (void *)class->contending_point[i]);
81156 seq_printf(m, "%40s %14lu %29s %pS\n",
81157 name, stats->contending_point[i],
81158diff --git a/kernel/module.c b/kernel/module.c
81159index 2069158..71101bb 100644
81160--- a/kernel/module.c
81161+++ b/kernel/module.c
81162@@ -61,6 +61,7 @@
81163 #include <linux/pfn.h>
81164 #include <linux/bsearch.h>
81165 #include <linux/fips.h>
81166+#include <linux/grsecurity.h>
81167 #include <uapi/linux/module.h>
81168 #include "module-internal.h"
81169
81170@@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
81171
81172 /* Bounds of module allocation, for speeding __module_address.
81173 * Protected by module_mutex. */
81174-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
81175+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
81176+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
81177
81178 int register_module_notifier(struct notifier_block * nb)
81179 {
81180@@ -323,7 +325,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
81181 return true;
81182
81183 list_for_each_entry_rcu(mod, &modules, list) {
81184- struct symsearch arr[] = {
81185+ struct symsearch modarr[] = {
81186 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
81187 NOT_GPL_ONLY, false },
81188 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
81189@@ -348,7 +350,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
81190 if (mod->state == MODULE_STATE_UNFORMED)
81191 continue;
81192
81193- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
81194+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
81195 return true;
81196 }
81197 return false;
81198@@ -490,7 +492,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
81199 if (!pcpusec->sh_size)
81200 return 0;
81201
81202- if (align > PAGE_SIZE) {
81203+ if (align-1 >= PAGE_SIZE) {
81204 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
81205 mod->name, align, PAGE_SIZE);
81206 align = PAGE_SIZE;
81207@@ -1096,7 +1098,7 @@ struct module_attribute module_uevent =
81208 static ssize_t show_coresize(struct module_attribute *mattr,
81209 struct module_kobject *mk, char *buffer)
81210 {
81211- return sprintf(buffer, "%u\n", mk->mod->core_size);
81212+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
81213 }
81214
81215 static struct module_attribute modinfo_coresize =
81216@@ -1105,7 +1107,7 @@ static struct module_attribute modinfo_coresize =
81217 static ssize_t show_initsize(struct module_attribute *mattr,
81218 struct module_kobject *mk, char *buffer)
81219 {
81220- return sprintf(buffer, "%u\n", mk->mod->init_size);
81221+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
81222 }
81223
81224 static struct module_attribute modinfo_initsize =
81225@@ -1320,7 +1322,7 @@ resolve_symbol_wait(struct module *mod,
81226 */
81227 #ifdef CONFIG_SYSFS
81228
81229-#ifdef CONFIG_KALLSYMS
81230+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
81231 static inline bool sect_empty(const Elf_Shdr *sect)
81232 {
81233 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
81234@@ -1460,7 +1462,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
81235 {
81236 unsigned int notes, loaded, i;
81237 struct module_notes_attrs *notes_attrs;
81238- struct bin_attribute *nattr;
81239+ bin_attribute_no_const *nattr;
81240
81241 /* failed to create section attributes, so can't create notes */
81242 if (!mod->sect_attrs)
81243@@ -1572,7 +1574,7 @@ static void del_usage_links(struct module *mod)
81244 static int module_add_modinfo_attrs(struct module *mod)
81245 {
81246 struct module_attribute *attr;
81247- struct module_attribute *temp_attr;
81248+ module_attribute_no_const *temp_attr;
81249 int error = 0;
81250 int i;
81251
81252@@ -1786,21 +1788,21 @@ static void set_section_ro_nx(void *base,
81253
81254 static void unset_module_core_ro_nx(struct module *mod)
81255 {
81256- set_page_attributes(mod->module_core + mod->core_text_size,
81257- mod->module_core + mod->core_size,
81258+ set_page_attributes(mod->module_core_rw,
81259+ mod->module_core_rw + mod->core_size_rw,
81260 set_memory_x);
81261- set_page_attributes(mod->module_core,
81262- mod->module_core + mod->core_ro_size,
81263+ set_page_attributes(mod->module_core_rx,
81264+ mod->module_core_rx + mod->core_size_rx,
81265 set_memory_rw);
81266 }
81267
81268 static void unset_module_init_ro_nx(struct module *mod)
81269 {
81270- set_page_attributes(mod->module_init + mod->init_text_size,
81271- mod->module_init + mod->init_size,
81272+ set_page_attributes(mod->module_init_rw,
81273+ mod->module_init_rw + mod->init_size_rw,
81274 set_memory_x);
81275- set_page_attributes(mod->module_init,
81276- mod->module_init + mod->init_ro_size,
81277+ set_page_attributes(mod->module_init_rx,
81278+ mod->module_init_rx + mod->init_size_rx,
81279 set_memory_rw);
81280 }
81281
81282@@ -1813,14 +1815,14 @@ void set_all_modules_text_rw(void)
81283 list_for_each_entry_rcu(mod, &modules, list) {
81284 if (mod->state == MODULE_STATE_UNFORMED)
81285 continue;
81286- if ((mod->module_core) && (mod->core_text_size)) {
81287- set_page_attributes(mod->module_core,
81288- mod->module_core + mod->core_text_size,
81289+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
81290+ set_page_attributes(mod->module_core_rx,
81291+ mod->module_core_rx + mod->core_size_rx,
81292 set_memory_rw);
81293 }
81294- if ((mod->module_init) && (mod->init_text_size)) {
81295- set_page_attributes(mod->module_init,
81296- mod->module_init + mod->init_text_size,
81297+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
81298+ set_page_attributes(mod->module_init_rx,
81299+ mod->module_init_rx + mod->init_size_rx,
81300 set_memory_rw);
81301 }
81302 }
81303@@ -1836,14 +1838,14 @@ void set_all_modules_text_ro(void)
81304 list_for_each_entry_rcu(mod, &modules, list) {
81305 if (mod->state == MODULE_STATE_UNFORMED)
81306 continue;
81307- if ((mod->module_core) && (mod->core_text_size)) {
81308- set_page_attributes(mod->module_core,
81309- mod->module_core + mod->core_text_size,
81310+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
81311+ set_page_attributes(mod->module_core_rx,
81312+ mod->module_core_rx + mod->core_size_rx,
81313 set_memory_ro);
81314 }
81315- if ((mod->module_init) && (mod->init_text_size)) {
81316- set_page_attributes(mod->module_init,
81317- mod->module_init + mod->init_text_size,
81318+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
81319+ set_page_attributes(mod->module_init_rx,
81320+ mod->module_init_rx + mod->init_size_rx,
81321 set_memory_ro);
81322 }
81323 }
81324@@ -1894,16 +1896,19 @@ static void free_module(struct module *mod)
81325
81326 /* This may be NULL, but that's OK */
81327 unset_module_init_ro_nx(mod);
81328- module_free(mod, mod->module_init);
81329+ module_free(mod, mod->module_init_rw);
81330+ module_free_exec(mod, mod->module_init_rx);
81331 kfree(mod->args);
81332 percpu_modfree(mod);
81333
81334 /* Free lock-classes: */
81335- lockdep_free_key_range(mod->module_core, mod->core_size);
81336+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
81337+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
81338
81339 /* Finally, free the core (containing the module structure) */
81340 unset_module_core_ro_nx(mod);
81341- module_free(mod, mod->module_core);
81342+ module_free_exec(mod, mod->module_core_rx);
81343+ module_free(mod, mod->module_core_rw);
81344
81345 #ifdef CONFIG_MPU
81346 update_protections(current->mm);
81347@@ -1973,9 +1978,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
81348 int ret = 0;
81349 const struct kernel_symbol *ksym;
81350
81351+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81352+ int is_fs_load = 0;
81353+ int register_filesystem_found = 0;
81354+ char *p;
81355+
81356+ p = strstr(mod->args, "grsec_modharden_fs");
81357+ if (p) {
81358+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
81359+ /* copy \0 as well */
81360+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
81361+ is_fs_load = 1;
81362+ }
81363+#endif
81364+
81365 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
81366 const char *name = info->strtab + sym[i].st_name;
81367
81368+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81369+ /* it's a real shame this will never get ripped and copied
81370+ upstream! ;(
81371+ */
81372+ if (is_fs_load && !strcmp(name, "register_filesystem"))
81373+ register_filesystem_found = 1;
81374+#endif
81375+
81376 switch (sym[i].st_shndx) {
81377 case SHN_COMMON:
81378 /* We compiled with -fno-common. These are not
81379@@ -1996,7 +2023,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
81380 ksym = resolve_symbol_wait(mod, info, name);
81381 /* Ok if resolved. */
81382 if (ksym && !IS_ERR(ksym)) {
81383+ pax_open_kernel();
81384 sym[i].st_value = ksym->value;
81385+ pax_close_kernel();
81386 break;
81387 }
81388
81389@@ -2015,11 +2044,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
81390 secbase = (unsigned long)mod_percpu(mod);
81391 else
81392 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
81393+ pax_open_kernel();
81394 sym[i].st_value += secbase;
81395+ pax_close_kernel();
81396 break;
81397 }
81398 }
81399
81400+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81401+ if (is_fs_load && !register_filesystem_found) {
81402+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
81403+ ret = -EPERM;
81404+ }
81405+#endif
81406+
81407 return ret;
81408 }
81409
81410@@ -2103,22 +2141,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
81411 || s->sh_entsize != ~0UL
81412 || strstarts(sname, ".init"))
81413 continue;
81414- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
81415+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
81416+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
81417+ else
81418+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
81419 pr_debug("\t%s\n", sname);
81420 }
81421- switch (m) {
81422- case 0: /* executable */
81423- mod->core_size = debug_align(mod->core_size);
81424- mod->core_text_size = mod->core_size;
81425- break;
81426- case 1: /* RO: text and ro-data */
81427- mod->core_size = debug_align(mod->core_size);
81428- mod->core_ro_size = mod->core_size;
81429- break;
81430- case 3: /* whole core */
81431- mod->core_size = debug_align(mod->core_size);
81432- break;
81433- }
81434 }
81435
81436 pr_debug("Init section allocation order:\n");
81437@@ -2132,23 +2160,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
81438 || s->sh_entsize != ~0UL
81439 || !strstarts(sname, ".init"))
81440 continue;
81441- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
81442- | INIT_OFFSET_MASK);
81443+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
81444+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
81445+ else
81446+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
81447+ s->sh_entsize |= INIT_OFFSET_MASK;
81448 pr_debug("\t%s\n", sname);
81449 }
81450- switch (m) {
81451- case 0: /* executable */
81452- mod->init_size = debug_align(mod->init_size);
81453- mod->init_text_size = mod->init_size;
81454- break;
81455- case 1: /* RO: text and ro-data */
81456- mod->init_size = debug_align(mod->init_size);
81457- mod->init_ro_size = mod->init_size;
81458- break;
81459- case 3: /* whole init */
81460- mod->init_size = debug_align(mod->init_size);
81461- break;
81462- }
81463 }
81464 }
81465
81466@@ -2321,7 +2339,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
81467
81468 /* Put symbol section at end of init part of module. */
81469 symsect->sh_flags |= SHF_ALLOC;
81470- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
81471+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
81472 info->index.sym) | INIT_OFFSET_MASK;
81473 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
81474
81475@@ -2338,13 +2356,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
81476 }
81477
81478 /* Append room for core symbols at end of core part. */
81479- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
81480- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
81481- mod->core_size += strtab_size;
81482+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
81483+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
81484+ mod->core_size_rx += strtab_size;
81485
81486 /* Put string table section at end of init part of module. */
81487 strsect->sh_flags |= SHF_ALLOC;
81488- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
81489+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
81490 info->index.str) | INIT_OFFSET_MASK;
81491 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
81492 }
81493@@ -2362,12 +2380,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
81494 /* Make sure we get permanent strtab: don't use info->strtab. */
81495 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
81496
81497+ pax_open_kernel();
81498+
81499 /* Set types up while we still have access to sections. */
81500 for (i = 0; i < mod->num_symtab; i++)
81501 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
81502
81503- mod->core_symtab = dst = mod->module_core + info->symoffs;
81504- mod->core_strtab = s = mod->module_core + info->stroffs;
81505+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
81506+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
81507 src = mod->symtab;
81508 for (ndst = i = 0; i < mod->num_symtab; i++) {
81509 if (i == 0 ||
81510@@ -2379,6 +2399,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
81511 }
81512 }
81513 mod->core_num_syms = ndst;
81514+
81515+ pax_close_kernel();
81516 }
81517 #else
81518 static inline void layout_symtab(struct module *mod, struct load_info *info)
81519@@ -2412,17 +2434,33 @@ void * __weak module_alloc(unsigned long size)
81520 return vmalloc_exec(size);
81521 }
81522
81523-static void *module_alloc_update_bounds(unsigned long size)
81524+static void *module_alloc_update_bounds_rw(unsigned long size)
81525 {
81526 void *ret = module_alloc(size);
81527
81528 if (ret) {
81529 mutex_lock(&module_mutex);
81530 /* Update module bounds. */
81531- if ((unsigned long)ret < module_addr_min)
81532- module_addr_min = (unsigned long)ret;
81533- if ((unsigned long)ret + size > module_addr_max)
81534- module_addr_max = (unsigned long)ret + size;
81535+ if ((unsigned long)ret < module_addr_min_rw)
81536+ module_addr_min_rw = (unsigned long)ret;
81537+ if ((unsigned long)ret + size > module_addr_max_rw)
81538+ module_addr_max_rw = (unsigned long)ret + size;
81539+ mutex_unlock(&module_mutex);
81540+ }
81541+ return ret;
81542+}
81543+
81544+static void *module_alloc_update_bounds_rx(unsigned long size)
81545+{
81546+ void *ret = module_alloc_exec(size);
81547+
81548+ if (ret) {
81549+ mutex_lock(&module_mutex);
81550+ /* Update module bounds. */
81551+ if ((unsigned long)ret < module_addr_min_rx)
81552+ module_addr_min_rx = (unsigned long)ret;
81553+ if ((unsigned long)ret + size > module_addr_max_rx)
81554+ module_addr_max_rx = (unsigned long)ret + size;
81555 mutex_unlock(&module_mutex);
81556 }
81557 return ret;
81558@@ -2698,8 +2736,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
81559 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
81560 {
81561 const char *modmagic = get_modinfo(info, "vermagic");
81562+ const char *license = get_modinfo(info, "license");
81563 int err;
81564
81565+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
81566+ if (!license || !license_is_gpl_compatible(license))
81567+ return -ENOEXEC;
81568+#endif
81569+
81570 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
81571 modmagic = NULL;
81572
81573@@ -2725,7 +2769,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
81574 }
81575
81576 /* Set up license info based on the info section */
81577- set_license(mod, get_modinfo(info, "license"));
81578+ set_license(mod, license);
81579
81580 return 0;
81581 }
81582@@ -2806,7 +2850,7 @@ static int move_module(struct module *mod, struct load_info *info)
81583 void *ptr;
81584
81585 /* Do the allocs. */
81586- ptr = module_alloc_update_bounds(mod->core_size);
81587+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
81588 /*
81589 * The pointer to this block is stored in the module structure
81590 * which is inside the block. Just mark it as not being a
81591@@ -2816,11 +2860,11 @@ static int move_module(struct module *mod, struct load_info *info)
81592 if (!ptr)
81593 return -ENOMEM;
81594
81595- memset(ptr, 0, mod->core_size);
81596- mod->module_core = ptr;
81597+ memset(ptr, 0, mod->core_size_rw);
81598+ mod->module_core_rw = ptr;
81599
81600- if (mod->init_size) {
81601- ptr = module_alloc_update_bounds(mod->init_size);
81602+ if (mod->init_size_rw) {
81603+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
81604 /*
81605 * The pointer to this block is stored in the module structure
81606 * which is inside the block. This block doesn't need to be
81607@@ -2829,13 +2873,45 @@ static int move_module(struct module *mod, struct load_info *info)
81608 */
81609 kmemleak_ignore(ptr);
81610 if (!ptr) {
81611- module_free(mod, mod->module_core);
81612+ module_free(mod, mod->module_core_rw);
81613 return -ENOMEM;
81614 }
81615- memset(ptr, 0, mod->init_size);
81616- mod->module_init = ptr;
81617+ memset(ptr, 0, mod->init_size_rw);
81618+ mod->module_init_rw = ptr;
81619 } else
81620- mod->module_init = NULL;
81621+ mod->module_init_rw = NULL;
81622+
81623+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
81624+ kmemleak_not_leak(ptr);
81625+ if (!ptr) {
81626+ if (mod->module_init_rw)
81627+ module_free(mod, mod->module_init_rw);
81628+ module_free(mod, mod->module_core_rw);
81629+ return -ENOMEM;
81630+ }
81631+
81632+ pax_open_kernel();
81633+ memset(ptr, 0, mod->core_size_rx);
81634+ pax_close_kernel();
81635+ mod->module_core_rx = ptr;
81636+
81637+ if (mod->init_size_rx) {
81638+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
81639+ kmemleak_ignore(ptr);
81640+ if (!ptr && mod->init_size_rx) {
81641+ module_free_exec(mod, mod->module_core_rx);
81642+ if (mod->module_init_rw)
81643+ module_free(mod, mod->module_init_rw);
81644+ module_free(mod, mod->module_core_rw);
81645+ return -ENOMEM;
81646+ }
81647+
81648+ pax_open_kernel();
81649+ memset(ptr, 0, mod->init_size_rx);
81650+ pax_close_kernel();
81651+ mod->module_init_rx = ptr;
81652+ } else
81653+ mod->module_init_rx = NULL;
81654
81655 /* Transfer each section which specifies SHF_ALLOC */
81656 pr_debug("final section addresses:\n");
81657@@ -2846,16 +2922,45 @@ static int move_module(struct module *mod, struct load_info *info)
81658 if (!(shdr->sh_flags & SHF_ALLOC))
81659 continue;
81660
81661- if (shdr->sh_entsize & INIT_OFFSET_MASK)
81662- dest = mod->module_init
81663- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
81664- else
81665- dest = mod->module_core + shdr->sh_entsize;
81666+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
81667+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
81668+ dest = mod->module_init_rw
81669+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
81670+ else
81671+ dest = mod->module_init_rx
81672+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
81673+ } else {
81674+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
81675+ dest = mod->module_core_rw + shdr->sh_entsize;
81676+ else
81677+ dest = mod->module_core_rx + shdr->sh_entsize;
81678+ }
81679+
81680+ if (shdr->sh_type != SHT_NOBITS) {
81681+
81682+#ifdef CONFIG_PAX_KERNEXEC
81683+#ifdef CONFIG_X86_64
81684+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
81685+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
81686+#endif
81687+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
81688+ pax_open_kernel();
81689+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
81690+ pax_close_kernel();
81691+ } else
81692+#endif
81693
81694- if (shdr->sh_type != SHT_NOBITS)
81695 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
81696+ }
81697 /* Update sh_addr to point to copy in image. */
81698- shdr->sh_addr = (unsigned long)dest;
81699+
81700+#ifdef CONFIG_PAX_KERNEXEC
81701+ if (shdr->sh_flags & SHF_EXECINSTR)
81702+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
81703+ else
81704+#endif
81705+
81706+ shdr->sh_addr = (unsigned long)dest;
81707 pr_debug("\t0x%lx %s\n",
81708 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
81709 }
81710@@ -2912,12 +3017,12 @@ static void flush_module_icache(const struct module *mod)
81711 * Do it before processing of module parameters, so the module
81712 * can provide parameter accessor functions of its own.
81713 */
81714- if (mod->module_init)
81715- flush_icache_range((unsigned long)mod->module_init,
81716- (unsigned long)mod->module_init
81717- + mod->init_size);
81718- flush_icache_range((unsigned long)mod->module_core,
81719- (unsigned long)mod->module_core + mod->core_size);
81720+ if (mod->module_init_rx)
81721+ flush_icache_range((unsigned long)mod->module_init_rx,
81722+ (unsigned long)mod->module_init_rx
81723+ + mod->init_size_rx);
81724+ flush_icache_range((unsigned long)mod->module_core_rx,
81725+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
81726
81727 set_fs(old_fs);
81728 }
81729@@ -2974,8 +3079,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
81730 static void module_deallocate(struct module *mod, struct load_info *info)
81731 {
81732 percpu_modfree(mod);
81733- module_free(mod, mod->module_init);
81734- module_free(mod, mod->module_core);
81735+ module_free_exec(mod, mod->module_init_rx);
81736+ module_free_exec(mod, mod->module_core_rx);
81737+ module_free(mod, mod->module_init_rw);
81738+ module_free(mod, mod->module_core_rw);
81739 }
81740
81741 int __weak module_finalize(const Elf_Ehdr *hdr,
81742@@ -2988,7 +3095,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
81743 static int post_relocation(struct module *mod, const struct load_info *info)
81744 {
81745 /* Sort exception table now relocations are done. */
81746+ pax_open_kernel();
81747 sort_extable(mod->extable, mod->extable + mod->num_exentries);
81748+ pax_close_kernel();
81749
81750 /* Copy relocated percpu area over. */
81751 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
81752@@ -3042,16 +3151,16 @@ static int do_init_module(struct module *mod)
81753 MODULE_STATE_COMING, mod);
81754
81755 /* Set RO and NX regions for core */
81756- set_section_ro_nx(mod->module_core,
81757- mod->core_text_size,
81758- mod->core_ro_size,
81759- mod->core_size);
81760+ set_section_ro_nx(mod->module_core_rx,
81761+ mod->core_size_rx,
81762+ mod->core_size_rx,
81763+ mod->core_size_rx);
81764
81765 /* Set RO and NX regions for init */
81766- set_section_ro_nx(mod->module_init,
81767- mod->init_text_size,
81768- mod->init_ro_size,
81769- mod->init_size);
81770+ set_section_ro_nx(mod->module_init_rx,
81771+ mod->init_size_rx,
81772+ mod->init_size_rx,
81773+ mod->init_size_rx);
81774
81775 do_mod_ctors(mod);
81776 /* Start the module */
81777@@ -3113,11 +3222,12 @@ static int do_init_module(struct module *mod)
81778 mod->strtab = mod->core_strtab;
81779 #endif
81780 unset_module_init_ro_nx(mod);
81781- module_free(mod, mod->module_init);
81782- mod->module_init = NULL;
81783- mod->init_size = 0;
81784- mod->init_ro_size = 0;
81785- mod->init_text_size = 0;
81786+ module_free(mod, mod->module_init_rw);
81787+ module_free_exec(mod, mod->module_init_rx);
81788+ mod->module_init_rw = NULL;
81789+ mod->module_init_rx = NULL;
81790+ mod->init_size_rw = 0;
81791+ mod->init_size_rx = 0;
81792 mutex_unlock(&module_mutex);
81793 wake_up_all(&module_wq);
81794
81795@@ -3261,9 +3371,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
81796 if (err)
81797 goto free_unload;
81798
81799+ /* Now copy in args */
81800+ mod->args = strndup_user(uargs, ~0UL >> 1);
81801+ if (IS_ERR(mod->args)) {
81802+ err = PTR_ERR(mod->args);
81803+ goto free_unload;
81804+ }
81805+
81806 /* Set up MODINFO_ATTR fields */
81807 setup_modinfo(mod, info);
81808
81809+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81810+ {
81811+ char *p, *p2;
81812+
81813+ if (strstr(mod->args, "grsec_modharden_netdev")) {
81814+ 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);
81815+ err = -EPERM;
81816+ goto free_modinfo;
81817+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
81818+ p += sizeof("grsec_modharden_normal") - 1;
81819+ p2 = strstr(p, "_");
81820+ if (p2) {
81821+ *p2 = '\0';
81822+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
81823+ *p2 = '_';
81824+ }
81825+ err = -EPERM;
81826+ goto free_modinfo;
81827+ }
81828+ }
81829+#endif
81830+
81831 /* Fix up syms, so that st_value is a pointer to location. */
81832 err = simplify_symbols(mod, info);
81833 if (err < 0)
81834@@ -3279,13 +3418,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
81835
81836 flush_module_icache(mod);
81837
81838- /* Now copy in args */
81839- mod->args = strndup_user(uargs, ~0UL >> 1);
81840- if (IS_ERR(mod->args)) {
81841- err = PTR_ERR(mod->args);
81842- goto free_arch_cleanup;
81843- }
81844-
81845 dynamic_debug_setup(info->debug, info->num_debug);
81846
81847 /* Finally it's fully formed, ready to start executing. */
81848@@ -3320,11 +3452,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
81849 ddebug_cleanup:
81850 dynamic_debug_remove(info->debug);
81851 synchronize_sched();
81852- kfree(mod->args);
81853- free_arch_cleanup:
81854 module_arch_cleanup(mod);
81855 free_modinfo:
81856 free_modinfo(mod);
81857+ kfree(mod->args);
81858 free_unload:
81859 module_unload_free(mod);
81860 unlink_mod:
81861@@ -3407,10 +3538,16 @@ static const char *get_ksymbol(struct module *mod,
81862 unsigned long nextval;
81863
81864 /* At worse, next value is at end of module */
81865- if (within_module_init(addr, mod))
81866- nextval = (unsigned long)mod->module_init+mod->init_text_size;
81867+ if (within_module_init_rx(addr, mod))
81868+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
81869+ else if (within_module_init_rw(addr, mod))
81870+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
81871+ else if (within_module_core_rx(addr, mod))
81872+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
81873+ else if (within_module_core_rw(addr, mod))
81874+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
81875 else
81876- nextval = (unsigned long)mod->module_core+mod->core_text_size;
81877+ return NULL;
81878
81879 /* Scan for closest preceding symbol, and next symbol. (ELF
81880 starts real symbols at 1). */
81881@@ -3661,7 +3798,7 @@ static int m_show(struct seq_file *m, void *p)
81882 return 0;
81883
81884 seq_printf(m, "%s %u",
81885- mod->name, mod->init_size + mod->core_size);
81886+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
81887 print_unload_info(m, mod);
81888
81889 /* Informative for users. */
81890@@ -3670,7 +3807,7 @@ static int m_show(struct seq_file *m, void *p)
81891 mod->state == MODULE_STATE_COMING ? "Loading":
81892 "Live");
81893 /* Used by oprofile and other similar tools. */
81894- seq_printf(m, " 0x%pK", mod->module_core);
81895+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
81896
81897 /* Taints info */
81898 if (mod->taints)
81899@@ -3706,7 +3843,17 @@ static const struct file_operations proc_modules_operations = {
81900
81901 static int __init proc_modules_init(void)
81902 {
81903+#ifndef CONFIG_GRKERNSEC_HIDESYM
81904+#ifdef CONFIG_GRKERNSEC_PROC_USER
81905+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
81906+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
81907+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
81908+#else
81909 proc_create("modules", 0, NULL, &proc_modules_operations);
81910+#endif
81911+#else
81912+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
81913+#endif
81914 return 0;
81915 }
81916 module_init(proc_modules_init);
81917@@ -3767,14 +3914,14 @@ struct module *__module_address(unsigned long addr)
81918 {
81919 struct module *mod;
81920
81921- if (addr < module_addr_min || addr > module_addr_max)
81922+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
81923+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
81924 return NULL;
81925
81926 list_for_each_entry_rcu(mod, &modules, list) {
81927 if (mod->state == MODULE_STATE_UNFORMED)
81928 continue;
81929- if (within_module_core(addr, mod)
81930- || within_module_init(addr, mod))
81931+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
81932 return mod;
81933 }
81934 return NULL;
81935@@ -3809,11 +3956,20 @@ bool is_module_text_address(unsigned long addr)
81936 */
81937 struct module *__module_text_address(unsigned long addr)
81938 {
81939- struct module *mod = __module_address(addr);
81940+ struct module *mod;
81941+
81942+#ifdef CONFIG_X86_32
81943+ addr = ktla_ktva(addr);
81944+#endif
81945+
81946+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
81947+ return NULL;
81948+
81949+ mod = __module_address(addr);
81950+
81951 if (mod) {
81952 /* Make sure it's within the text section. */
81953- if (!within(addr, mod->module_init, mod->init_text_size)
81954- && !within(addr, mod->module_core, mod->core_text_size))
81955+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
81956 mod = NULL;
81957 }
81958 return mod;
81959diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
81960index 7e3443f..b2a1e6b 100644
81961--- a/kernel/mutex-debug.c
81962+++ b/kernel/mutex-debug.c
81963@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
81964 }
81965
81966 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
81967- struct thread_info *ti)
81968+ struct task_struct *task)
81969 {
81970 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
81971
81972 /* Mark the current thread as blocked on the lock: */
81973- ti->task->blocked_on = waiter;
81974+ task->blocked_on = waiter;
81975 }
81976
81977 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
81978- struct thread_info *ti)
81979+ struct task_struct *task)
81980 {
81981 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
81982- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
81983- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
81984- ti->task->blocked_on = NULL;
81985+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
81986+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
81987+ task->blocked_on = NULL;
81988
81989 list_del_init(&waiter->list);
81990 waiter->task = NULL;
81991diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
81992index 0799fd3..d06ae3b 100644
81993--- a/kernel/mutex-debug.h
81994+++ b/kernel/mutex-debug.h
81995@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
81996 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
81997 extern void debug_mutex_add_waiter(struct mutex *lock,
81998 struct mutex_waiter *waiter,
81999- struct thread_info *ti);
82000+ struct task_struct *task);
82001 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
82002- struct thread_info *ti);
82003+ struct task_struct *task);
82004 extern void debug_mutex_unlock(struct mutex *lock);
82005 extern void debug_mutex_init(struct mutex *lock, const char *name,
82006 struct lock_class_key *key);
82007diff --git a/kernel/mutex.c b/kernel/mutex.c
82008index a52ee7bb..f361f16 100644
82009--- a/kernel/mutex.c
82010+++ b/kernel/mutex.c
82011@@ -135,7 +135,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
82012 node->locked = 1;
82013 return;
82014 }
82015- ACCESS_ONCE(prev->next) = node;
82016+ ACCESS_ONCE_RW(prev->next) = node;
82017 smp_wmb();
82018 /* Wait until the lock holder passes the lock down */
82019 while (!ACCESS_ONCE(node->locked))
82020@@ -156,7 +156,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
82021 while (!(next = ACCESS_ONCE(node->next)))
82022 arch_mutex_cpu_relax();
82023 }
82024- ACCESS_ONCE(next->locked) = 1;
82025+ ACCESS_ONCE_RW(next->locked) = 1;
82026 smp_wmb();
82027 }
82028
82029@@ -514,7 +514,7 @@ slowpath:
82030 spin_lock_mutex(&lock->wait_lock, flags);
82031
82032 debug_mutex_lock_common(lock, &waiter);
82033- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
82034+ debug_mutex_add_waiter(lock, &waiter, task);
82035
82036 /* add waiting tasks to the end of the waitqueue (FIFO): */
82037 list_add_tail(&waiter.list, &lock->wait_list);
82038@@ -565,7 +565,7 @@ slowpath:
82039 done:
82040 lock_acquired(&lock->dep_map, ip);
82041 /* got the lock - rejoice! */
82042- mutex_remove_waiter(lock, &waiter, current_thread_info());
82043+ mutex_remove_waiter(lock, &waiter, task);
82044 mutex_set_owner(lock);
82045
82046 if (!__builtin_constant_p(ww_ctx == NULL)) {
82047@@ -604,7 +604,7 @@ done:
82048 return 0;
82049
82050 err:
82051- mutex_remove_waiter(lock, &waiter, task_thread_info(task));
82052+ mutex_remove_waiter(lock, &waiter, task);
82053 spin_unlock_mutex(&lock->wait_lock, flags);
82054 debug_mutex_free_waiter(&waiter);
82055 mutex_release(&lock->dep_map, 1, ip);
82056diff --git a/kernel/notifier.c b/kernel/notifier.c
82057index 2d5cc4c..d9ea600 100644
82058--- a/kernel/notifier.c
82059+++ b/kernel/notifier.c
82060@@ -5,6 +5,7 @@
82061 #include <linux/rcupdate.h>
82062 #include <linux/vmalloc.h>
82063 #include <linux/reboot.h>
82064+#include <linux/mm.h>
82065
82066 /*
82067 * Notifier list for kernel code which wants to be called
82068@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
82069 while ((*nl) != NULL) {
82070 if (n->priority > (*nl)->priority)
82071 break;
82072- nl = &((*nl)->next);
82073+ nl = (struct notifier_block **)&((*nl)->next);
82074 }
82075- n->next = *nl;
82076+ pax_open_kernel();
82077+ *(const void **)&n->next = *nl;
82078 rcu_assign_pointer(*nl, n);
82079+ pax_close_kernel();
82080 return 0;
82081 }
82082
82083@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
82084 return 0;
82085 if (n->priority > (*nl)->priority)
82086 break;
82087- nl = &((*nl)->next);
82088+ nl = (struct notifier_block **)&((*nl)->next);
82089 }
82090- n->next = *nl;
82091+ pax_open_kernel();
82092+ *(const void **)&n->next = *nl;
82093 rcu_assign_pointer(*nl, n);
82094+ pax_close_kernel();
82095 return 0;
82096 }
82097
82098@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
82099 {
82100 while ((*nl) != NULL) {
82101 if ((*nl) == n) {
82102+ pax_open_kernel();
82103 rcu_assign_pointer(*nl, n->next);
82104+ pax_close_kernel();
82105 return 0;
82106 }
82107- nl = &((*nl)->next);
82108+ nl = (struct notifier_block **)&((*nl)->next);
82109 }
82110 return -ENOENT;
82111 }
82112diff --git a/kernel/panic.c b/kernel/panic.c
82113index 8018646..b6a5b4f 100644
82114--- a/kernel/panic.c
82115+++ b/kernel/panic.c
82116@@ -403,7 +403,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
82117 disable_trace_on_warning();
82118
82119 pr_warn("------------[ cut here ]------------\n");
82120- pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
82121+ pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
82122 raw_smp_processor_id(), current->pid, file, line, caller);
82123
82124 if (args)
82125@@ -457,7 +457,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
82126 */
82127 void __stack_chk_fail(void)
82128 {
82129- panic("stack-protector: Kernel stack is corrupted in: %p\n",
82130+ dump_stack();
82131+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
82132 __builtin_return_address(0));
82133 }
82134 EXPORT_SYMBOL(__stack_chk_fail);
82135diff --git a/kernel/pid.c b/kernel/pid.c
82136index ebe5e80..5d6d634 100644
82137--- a/kernel/pid.c
82138+++ b/kernel/pid.c
82139@@ -33,6 +33,7 @@
82140 #include <linux/rculist.h>
82141 #include <linux/bootmem.h>
82142 #include <linux/hash.h>
82143+#include <linux/security.h>
82144 #include <linux/pid_namespace.h>
82145 #include <linux/init_task.h>
82146 #include <linux/syscalls.h>
82147@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
82148
82149 int pid_max = PID_MAX_DEFAULT;
82150
82151-#define RESERVED_PIDS 300
82152+#define RESERVED_PIDS 500
82153
82154 int pid_max_min = RESERVED_PIDS + 1;
82155 int pid_max_max = PID_MAX_LIMIT;
82156@@ -440,10 +441,18 @@ EXPORT_SYMBOL(pid_task);
82157 */
82158 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
82159 {
82160+ struct task_struct *task;
82161+
82162 rcu_lockdep_assert(rcu_read_lock_held(),
82163 "find_task_by_pid_ns() needs rcu_read_lock()"
82164 " protection");
82165- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
82166+
82167+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
82168+
82169+ if (gr_pid_is_chrooted(task))
82170+ return NULL;
82171+
82172+ return task;
82173 }
82174
82175 struct task_struct *find_task_by_vpid(pid_t vnr)
82176@@ -451,6 +460,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
82177 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
82178 }
82179
82180+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
82181+{
82182+ rcu_lockdep_assert(rcu_read_lock_held(),
82183+ "find_task_by_pid_ns() needs rcu_read_lock()"
82184+ " protection");
82185+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
82186+}
82187+
82188 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
82189 {
82190 struct pid *pid;
82191diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
82192index 601bb36..f7e6f34 100644
82193--- a/kernel/pid_namespace.c
82194+++ b/kernel/pid_namespace.c
82195@@ -247,7 +247,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
82196 void __user *buffer, size_t *lenp, loff_t *ppos)
82197 {
82198 struct pid_namespace *pid_ns = task_active_pid_ns(current);
82199- struct ctl_table tmp = *table;
82200+ ctl_table_no_const tmp = *table;
82201
82202 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
82203 return -EPERM;
82204diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
82205index c7f31aa..2b44977 100644
82206--- a/kernel/posix-cpu-timers.c
82207+++ b/kernel/posix-cpu-timers.c
82208@@ -1521,14 +1521,14 @@ struct k_clock clock_posix_cpu = {
82209
82210 static __init int init_posix_cpu_timers(void)
82211 {
82212- struct k_clock process = {
82213+ static struct k_clock process = {
82214 .clock_getres = process_cpu_clock_getres,
82215 .clock_get = process_cpu_clock_get,
82216 .timer_create = process_cpu_timer_create,
82217 .nsleep = process_cpu_nsleep,
82218 .nsleep_restart = process_cpu_nsleep_restart,
82219 };
82220- struct k_clock thread = {
82221+ static struct k_clock thread = {
82222 .clock_getres = thread_cpu_clock_getres,
82223 .clock_get = thread_cpu_clock_get,
82224 .timer_create = thread_cpu_timer_create,
82225diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
82226index 424c2d4..679242f 100644
82227--- a/kernel/posix-timers.c
82228+++ b/kernel/posix-timers.c
82229@@ -43,6 +43,7 @@
82230 #include <linux/hash.h>
82231 #include <linux/posix-clock.h>
82232 #include <linux/posix-timers.h>
82233+#include <linux/grsecurity.h>
82234 #include <linux/syscalls.h>
82235 #include <linux/wait.h>
82236 #include <linux/workqueue.h>
82237@@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
82238 * which we beg off on and pass to do_sys_settimeofday().
82239 */
82240
82241-static struct k_clock posix_clocks[MAX_CLOCKS];
82242+static struct k_clock *posix_clocks[MAX_CLOCKS];
82243
82244 /*
82245 * These ones are defined below.
82246@@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
82247 */
82248 static __init int init_posix_timers(void)
82249 {
82250- struct k_clock clock_realtime = {
82251+ static struct k_clock clock_realtime = {
82252 .clock_getres = hrtimer_get_res,
82253 .clock_get = posix_clock_realtime_get,
82254 .clock_set = posix_clock_realtime_set,
82255@@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
82256 .timer_get = common_timer_get,
82257 .timer_del = common_timer_del,
82258 };
82259- struct k_clock clock_monotonic = {
82260+ static struct k_clock clock_monotonic = {
82261 .clock_getres = hrtimer_get_res,
82262 .clock_get = posix_ktime_get_ts,
82263 .nsleep = common_nsleep,
82264@@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
82265 .timer_get = common_timer_get,
82266 .timer_del = common_timer_del,
82267 };
82268- struct k_clock clock_monotonic_raw = {
82269+ static struct k_clock clock_monotonic_raw = {
82270 .clock_getres = hrtimer_get_res,
82271 .clock_get = posix_get_monotonic_raw,
82272 };
82273- struct k_clock clock_realtime_coarse = {
82274+ static struct k_clock clock_realtime_coarse = {
82275 .clock_getres = posix_get_coarse_res,
82276 .clock_get = posix_get_realtime_coarse,
82277 };
82278- struct k_clock clock_monotonic_coarse = {
82279+ static struct k_clock clock_monotonic_coarse = {
82280 .clock_getres = posix_get_coarse_res,
82281 .clock_get = posix_get_monotonic_coarse,
82282 };
82283- struct k_clock clock_tai = {
82284+ static struct k_clock clock_tai = {
82285 .clock_getres = hrtimer_get_res,
82286 .clock_get = posix_get_tai,
82287 .nsleep = common_nsleep,
82288@@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
82289 .timer_get = common_timer_get,
82290 .timer_del = common_timer_del,
82291 };
82292- struct k_clock clock_boottime = {
82293+ static struct k_clock clock_boottime = {
82294 .clock_getres = hrtimer_get_res,
82295 .clock_get = posix_get_boottime,
82296 .nsleep = common_nsleep,
82297@@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
82298 return;
82299 }
82300
82301- posix_clocks[clock_id] = *new_clock;
82302+ posix_clocks[clock_id] = new_clock;
82303 }
82304 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
82305
82306@@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
82307 return (id & CLOCKFD_MASK) == CLOCKFD ?
82308 &clock_posix_dynamic : &clock_posix_cpu;
82309
82310- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
82311+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
82312 return NULL;
82313- return &posix_clocks[id];
82314+ return posix_clocks[id];
82315 }
82316
82317 static int common_timer_create(struct k_itimer *new_timer)
82318@@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
82319 struct k_clock *kc = clockid_to_kclock(which_clock);
82320 struct k_itimer *new_timer;
82321 int error, new_timer_id;
82322- sigevent_t event;
82323+ sigevent_t event = { };
82324 int it_id_set = IT_ID_NOT_SET;
82325
82326 if (!kc)
82327@@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
82328 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
82329 return -EFAULT;
82330
82331+ /* only the CLOCK_REALTIME clock can be set, all other clocks
82332+ have their clock_set fptr set to a nosettime dummy function
82333+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
82334+ call common_clock_set, which calls do_sys_settimeofday, which
82335+ we hook
82336+ */
82337+
82338 return kc->clock_set(which_clock, &new_tp);
82339 }
82340
82341diff --git a/kernel/power/process.c b/kernel/power/process.c
82342index 06ec886..9dba35e 100644
82343--- a/kernel/power/process.c
82344+++ b/kernel/power/process.c
82345@@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
82346 unsigned int elapsed_msecs;
82347 bool wakeup = false;
82348 int sleep_usecs = USEC_PER_MSEC;
82349+ bool timedout = false;
82350
82351 do_gettimeofday(&start);
82352
82353@@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
82354
82355 while (true) {
82356 todo = 0;
82357+ if (time_after(jiffies, end_time))
82358+ timedout = true;
82359 read_lock(&tasklist_lock);
82360 do_each_thread(g, p) {
82361 if (p == current || !freeze_task(p))
82362 continue;
82363
82364- if (!freezer_should_skip(p))
82365+ if (!freezer_should_skip(p)) {
82366 todo++;
82367+ if (timedout) {
82368+ printk(KERN_ERR "Task refusing to freeze:\n");
82369+ sched_show_task(p);
82370+ }
82371+ }
82372 } while_each_thread(g, p);
82373 read_unlock(&tasklist_lock);
82374
82375@@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
82376 todo += wq_busy;
82377 }
82378
82379- if (!todo || time_after(jiffies, end_time))
82380+ if (!todo || timedout)
82381 break;
82382
82383 if (pm_wakeup_pending()) {
82384diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
82385index 5b5a708..ec7637e 100644
82386--- a/kernel/printk/printk.c
82387+++ b/kernel/printk/printk.c
82388@@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
82389 if (from_file && type != SYSLOG_ACTION_OPEN)
82390 return 0;
82391
82392+#ifdef CONFIG_GRKERNSEC_DMESG
82393+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
82394+ return -EPERM;
82395+#endif
82396+
82397 if (syslog_action_restricted(type)) {
82398 if (capable(CAP_SYSLOG))
82399 return 0;
82400diff --git a/kernel/profile.c b/kernel/profile.c
82401index 6631e1e..310c266 100644
82402--- a/kernel/profile.c
82403+++ b/kernel/profile.c
82404@@ -37,7 +37,7 @@ struct profile_hit {
82405 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
82406 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
82407
82408-static atomic_t *prof_buffer;
82409+static atomic_unchecked_t *prof_buffer;
82410 static unsigned long prof_len, prof_shift;
82411
82412 int prof_on __read_mostly;
82413@@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
82414 hits[i].pc = 0;
82415 continue;
82416 }
82417- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
82418+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
82419 hits[i].hits = hits[i].pc = 0;
82420 }
82421 }
82422@@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
82423 * Add the current hit(s) and flush the write-queue out
82424 * to the global buffer:
82425 */
82426- atomic_add(nr_hits, &prof_buffer[pc]);
82427+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
82428 for (i = 0; i < NR_PROFILE_HIT; ++i) {
82429- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
82430+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
82431 hits[i].pc = hits[i].hits = 0;
82432 }
82433 out:
82434@@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
82435 {
82436 unsigned long pc;
82437 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
82438- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
82439+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
82440 }
82441 #endif /* !CONFIG_SMP */
82442
82443@@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
82444 return -EFAULT;
82445 buf++; p++; count--; read++;
82446 }
82447- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
82448+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
82449 if (copy_to_user(buf, (void *)pnt, count))
82450 return -EFAULT;
82451 read += count;
82452@@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
82453 }
82454 #endif
82455 profile_discard_flip_buffers();
82456- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
82457+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
82458 return count;
82459 }
82460
82461diff --git a/kernel/ptrace.c b/kernel/ptrace.c
82462index a146ee3..ffed4c3 100644
82463--- a/kernel/ptrace.c
82464+++ b/kernel/ptrace.c
82465@@ -326,7 +326,7 @@ static int ptrace_attach(struct task_struct *task, long request,
82466 if (seize)
82467 flags |= PT_SEIZED;
82468 rcu_read_lock();
82469- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
82470+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
82471 flags |= PT_PTRACE_CAP;
82472 rcu_read_unlock();
82473 task->ptrace = flags;
82474@@ -537,7 +537,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
82475 break;
82476 return -EIO;
82477 }
82478- if (copy_to_user(dst, buf, retval))
82479+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
82480 return -EFAULT;
82481 copied += retval;
82482 src += retval;
82483@@ -805,7 +805,7 @@ int ptrace_request(struct task_struct *child, long request,
82484 bool seized = child->ptrace & PT_SEIZED;
82485 int ret = -EIO;
82486 siginfo_t siginfo, *si;
82487- void __user *datavp = (void __user *) data;
82488+ void __user *datavp = (__force void __user *) data;
82489 unsigned long __user *datalp = datavp;
82490 unsigned long flags;
82491
82492@@ -1051,14 +1051,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
82493 goto out;
82494 }
82495
82496+ if (gr_handle_ptrace(child, request)) {
82497+ ret = -EPERM;
82498+ goto out_put_task_struct;
82499+ }
82500+
82501 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
82502 ret = ptrace_attach(child, request, addr, data);
82503 /*
82504 * Some architectures need to do book-keeping after
82505 * a ptrace attach.
82506 */
82507- if (!ret)
82508+ if (!ret) {
82509 arch_ptrace_attach(child);
82510+ gr_audit_ptrace(child);
82511+ }
82512 goto out_put_task_struct;
82513 }
82514
82515@@ -1086,7 +1093,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
82516 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
82517 if (copied != sizeof(tmp))
82518 return -EIO;
82519- return put_user(tmp, (unsigned long __user *)data);
82520+ return put_user(tmp, (__force unsigned long __user *)data);
82521 }
82522
82523 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
82524@@ -1180,7 +1187,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
82525 }
82526
82527 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
82528- compat_long_t addr, compat_long_t data)
82529+ compat_ulong_t addr, compat_ulong_t data)
82530 {
82531 struct task_struct *child;
82532 long ret;
82533@@ -1196,14 +1203,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
82534 goto out;
82535 }
82536
82537+ if (gr_handle_ptrace(child, request)) {
82538+ ret = -EPERM;
82539+ goto out_put_task_struct;
82540+ }
82541+
82542 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
82543 ret = ptrace_attach(child, request, addr, data);
82544 /*
82545 * Some architectures need to do book-keeping after
82546 * a ptrace attach.
82547 */
82548- if (!ret)
82549+ if (!ret) {
82550 arch_ptrace_attach(child);
82551+ gr_audit_ptrace(child);
82552+ }
82553 goto out_put_task_struct;
82554 }
82555
82556diff --git a/kernel/rcupdate.c b/kernel/rcupdate.c
82557index cce6ba8..7c758b1f 100644
82558--- a/kernel/rcupdate.c
82559+++ b/kernel/rcupdate.c
82560@@ -412,10 +412,10 @@ int rcu_jiffies_till_stall_check(void)
82561 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
82562 */
82563 if (till_stall_check < 3) {
82564- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
82565+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
82566 till_stall_check = 3;
82567 } else if (till_stall_check > 300) {
82568- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
82569+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
82570 till_stall_check = 300;
82571 }
82572 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
82573diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
82574index aa34411..4832cd4 100644
82575--- a/kernel/rcutiny.c
82576+++ b/kernel/rcutiny.c
82577@@ -45,7 +45,7 @@
82578 /* Forward declarations for rcutiny_plugin.h. */
82579 struct rcu_ctrlblk;
82580 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
82581-static void rcu_process_callbacks(struct softirq_action *unused);
82582+static void rcu_process_callbacks(void);
82583 static void __call_rcu(struct rcu_head *head,
82584 void (*func)(struct rcu_head *rcu),
82585 struct rcu_ctrlblk *rcp);
82586@@ -309,7 +309,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
82587 false));
82588 }
82589
82590-static void rcu_process_callbacks(struct softirq_action *unused)
82591+static __latent_entropy void rcu_process_callbacks(void)
82592 {
82593 __rcu_process_callbacks(&rcu_sched_ctrlblk);
82594 __rcu_process_callbacks(&rcu_bh_ctrlblk);
82595diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
82596index f4871e5..8ef5741 100644
82597--- a/kernel/rcutorture.c
82598+++ b/kernel/rcutorture.c
82599@@ -164,12 +164,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
82600 { 0 };
82601 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
82602 { 0 };
82603-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
82604-static atomic_t n_rcu_torture_alloc;
82605-static atomic_t n_rcu_torture_alloc_fail;
82606-static atomic_t n_rcu_torture_free;
82607-static atomic_t n_rcu_torture_mberror;
82608-static atomic_t n_rcu_torture_error;
82609+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
82610+static atomic_unchecked_t n_rcu_torture_alloc;
82611+static atomic_unchecked_t n_rcu_torture_alloc_fail;
82612+static atomic_unchecked_t n_rcu_torture_free;
82613+static atomic_unchecked_t n_rcu_torture_mberror;
82614+static atomic_unchecked_t n_rcu_torture_error;
82615 static long n_rcu_torture_barrier_error;
82616 static long n_rcu_torture_boost_ktrerror;
82617 static long n_rcu_torture_boost_rterror;
82618@@ -287,11 +287,11 @@ rcu_torture_alloc(void)
82619
82620 spin_lock_bh(&rcu_torture_lock);
82621 if (list_empty(&rcu_torture_freelist)) {
82622- atomic_inc(&n_rcu_torture_alloc_fail);
82623+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
82624 spin_unlock_bh(&rcu_torture_lock);
82625 return NULL;
82626 }
82627- atomic_inc(&n_rcu_torture_alloc);
82628+ atomic_inc_unchecked(&n_rcu_torture_alloc);
82629 p = rcu_torture_freelist.next;
82630 list_del_init(p);
82631 spin_unlock_bh(&rcu_torture_lock);
82632@@ -304,7 +304,7 @@ rcu_torture_alloc(void)
82633 static void
82634 rcu_torture_free(struct rcu_torture *p)
82635 {
82636- atomic_inc(&n_rcu_torture_free);
82637+ atomic_inc_unchecked(&n_rcu_torture_free);
82638 spin_lock_bh(&rcu_torture_lock);
82639 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
82640 spin_unlock_bh(&rcu_torture_lock);
82641@@ -424,7 +424,7 @@ rcu_torture_cb(struct rcu_head *p)
82642 i = rp->rtort_pipe_count;
82643 if (i > RCU_TORTURE_PIPE_LEN)
82644 i = RCU_TORTURE_PIPE_LEN;
82645- atomic_inc(&rcu_torture_wcount[i]);
82646+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
82647 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
82648 rp->rtort_mbtest = 0;
82649 rcu_torture_free(rp);
82650@@ -472,7 +472,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
82651 i = rp->rtort_pipe_count;
82652 if (i > RCU_TORTURE_PIPE_LEN)
82653 i = RCU_TORTURE_PIPE_LEN;
82654- atomic_inc(&rcu_torture_wcount[i]);
82655+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
82656 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
82657 rp->rtort_mbtest = 0;
82658 list_del(&rp->rtort_free);
82659@@ -952,7 +952,7 @@ rcu_torture_writer(void *arg)
82660 i = old_rp->rtort_pipe_count;
82661 if (i > RCU_TORTURE_PIPE_LEN)
82662 i = RCU_TORTURE_PIPE_LEN;
82663- atomic_inc(&rcu_torture_wcount[i]);
82664+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
82665 old_rp->rtort_pipe_count++;
82666 cur_ops->deferred_free(old_rp);
82667 }
82668@@ -1038,7 +1038,7 @@ static void rcu_torture_timer(unsigned long unused)
82669 return;
82670 }
82671 if (p->rtort_mbtest == 0)
82672- atomic_inc(&n_rcu_torture_mberror);
82673+ atomic_inc_unchecked(&n_rcu_torture_mberror);
82674 spin_lock(&rand_lock);
82675 cur_ops->read_delay(&rand);
82676 n_rcu_torture_timers++;
82677@@ -1108,7 +1108,7 @@ rcu_torture_reader(void *arg)
82678 continue;
82679 }
82680 if (p->rtort_mbtest == 0)
82681- atomic_inc(&n_rcu_torture_mberror);
82682+ atomic_inc_unchecked(&n_rcu_torture_mberror);
82683 cur_ops->read_delay(&rand);
82684 preempt_disable();
82685 pipe_count = p->rtort_pipe_count;
82686@@ -1171,11 +1171,11 @@ rcu_torture_printk(char *page)
82687 rcu_torture_current,
82688 rcu_torture_current_version,
82689 list_empty(&rcu_torture_freelist),
82690- atomic_read(&n_rcu_torture_alloc),
82691- atomic_read(&n_rcu_torture_alloc_fail),
82692- atomic_read(&n_rcu_torture_free));
82693+ atomic_read_unchecked(&n_rcu_torture_alloc),
82694+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
82695+ atomic_read_unchecked(&n_rcu_torture_free));
82696 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
82697- atomic_read(&n_rcu_torture_mberror),
82698+ atomic_read_unchecked(&n_rcu_torture_mberror),
82699 n_rcu_torture_boost_ktrerror,
82700 n_rcu_torture_boost_rterror);
82701 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
82702@@ -1194,14 +1194,14 @@ rcu_torture_printk(char *page)
82703 n_barrier_attempts,
82704 n_rcu_torture_barrier_error);
82705 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
82706- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
82707+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
82708 n_rcu_torture_barrier_error != 0 ||
82709 n_rcu_torture_boost_ktrerror != 0 ||
82710 n_rcu_torture_boost_rterror != 0 ||
82711 n_rcu_torture_boost_failure != 0 ||
82712 i > 1) {
82713 cnt += sprintf(&page[cnt], "!!! ");
82714- atomic_inc(&n_rcu_torture_error);
82715+ atomic_inc_unchecked(&n_rcu_torture_error);
82716 WARN_ON_ONCE(1);
82717 }
82718 cnt += sprintf(&page[cnt], "Reader Pipe: ");
82719@@ -1215,7 +1215,7 @@ rcu_torture_printk(char *page)
82720 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
82721 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
82722 cnt += sprintf(&page[cnt], " %d",
82723- atomic_read(&rcu_torture_wcount[i]));
82724+ atomic_read_unchecked(&rcu_torture_wcount[i]));
82725 }
82726 cnt += sprintf(&page[cnt], "\n");
82727 if (cur_ops->stats)
82728@@ -1924,7 +1924,7 @@ rcu_torture_cleanup(void)
82729
82730 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
82731
82732- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
82733+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
82734 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
82735 else if (n_online_successes != n_online_attempts ||
82736 n_offline_successes != n_offline_attempts)
82737@@ -1992,18 +1992,18 @@ rcu_torture_init(void)
82738
82739 rcu_torture_current = NULL;
82740 rcu_torture_current_version = 0;
82741- atomic_set(&n_rcu_torture_alloc, 0);
82742- atomic_set(&n_rcu_torture_alloc_fail, 0);
82743- atomic_set(&n_rcu_torture_free, 0);
82744- atomic_set(&n_rcu_torture_mberror, 0);
82745- atomic_set(&n_rcu_torture_error, 0);
82746+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
82747+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
82748+ atomic_set_unchecked(&n_rcu_torture_free, 0);
82749+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
82750+ atomic_set_unchecked(&n_rcu_torture_error, 0);
82751 n_rcu_torture_barrier_error = 0;
82752 n_rcu_torture_boost_ktrerror = 0;
82753 n_rcu_torture_boost_rterror = 0;
82754 n_rcu_torture_boost_failure = 0;
82755 n_rcu_torture_boosts = 0;
82756 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
82757- atomic_set(&rcu_torture_wcount[i], 0);
82758+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
82759 for_each_possible_cpu(cpu) {
82760 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
82761 per_cpu(rcu_torture_count, cpu)[i] = 0;
82762diff --git a/kernel/rcutree.c b/kernel/rcutree.c
82763index 068de3a..5e7db2f 100644
82764--- a/kernel/rcutree.c
82765+++ b/kernel/rcutree.c
82766@@ -358,9 +358,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
82767 rcu_prepare_for_idle(smp_processor_id());
82768 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
82769 smp_mb__before_atomic_inc(); /* See above. */
82770- atomic_inc(&rdtp->dynticks);
82771+ atomic_inc_unchecked(&rdtp->dynticks);
82772 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
82773- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
82774+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
82775
82776 /*
82777 * It is illegal to enter an extended quiescent state while
82778@@ -496,10 +496,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
82779 int user)
82780 {
82781 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
82782- atomic_inc(&rdtp->dynticks);
82783+ atomic_inc_unchecked(&rdtp->dynticks);
82784 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
82785 smp_mb__after_atomic_inc(); /* See above. */
82786- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
82787+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
82788 rcu_cleanup_after_idle(smp_processor_id());
82789 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
82790 if (!user && !is_idle_task(current)) {
82791@@ -638,14 +638,14 @@ void rcu_nmi_enter(void)
82792 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
82793
82794 if (rdtp->dynticks_nmi_nesting == 0 &&
82795- (atomic_read(&rdtp->dynticks) & 0x1))
82796+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
82797 return;
82798 rdtp->dynticks_nmi_nesting++;
82799 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
82800- atomic_inc(&rdtp->dynticks);
82801+ atomic_inc_unchecked(&rdtp->dynticks);
82802 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
82803 smp_mb__after_atomic_inc(); /* See above. */
82804- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
82805+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
82806 }
82807
82808 /**
82809@@ -664,9 +664,9 @@ void rcu_nmi_exit(void)
82810 return;
82811 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
82812 smp_mb__before_atomic_inc(); /* See above. */
82813- atomic_inc(&rdtp->dynticks);
82814+ atomic_inc_unchecked(&rdtp->dynticks);
82815 smp_mb__after_atomic_inc(); /* Force delay to next write. */
82816- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
82817+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
82818 }
82819
82820 /**
82821@@ -680,7 +680,7 @@ int rcu_is_cpu_idle(void)
82822 int ret;
82823
82824 preempt_disable();
82825- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
82826+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
82827 preempt_enable();
82828 return ret;
82829 }
82830@@ -748,7 +748,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
82831 */
82832 static int dyntick_save_progress_counter(struct rcu_data *rdp)
82833 {
82834- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
82835+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
82836 return (rdp->dynticks_snap & 0x1) == 0;
82837 }
82838
82839@@ -763,7 +763,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
82840 unsigned int curr;
82841 unsigned int snap;
82842
82843- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
82844+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
82845 snap = (unsigned int)rdp->dynticks_snap;
82846
82847 /*
82848@@ -1351,9 +1351,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
82849 rdp = this_cpu_ptr(rsp->rda);
82850 rcu_preempt_check_blocked_tasks(rnp);
82851 rnp->qsmask = rnp->qsmaskinit;
82852- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
82853+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
82854 WARN_ON_ONCE(rnp->completed != rsp->completed);
82855- ACCESS_ONCE(rnp->completed) = rsp->completed;
82856+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
82857 if (rnp == rdp->mynode)
82858 __note_gp_changes(rsp, rnp, rdp);
82859 rcu_preempt_boost_start_gp(rnp);
82860@@ -1435,7 +1435,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
82861 */
82862 rcu_for_each_node_breadth_first(rsp, rnp) {
82863 raw_spin_lock_irq(&rnp->lock);
82864- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
82865+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
82866 rdp = this_cpu_ptr(rsp->rda);
82867 if (rnp == rdp->mynode)
82868 __note_gp_changes(rsp, rnp, rdp);
82869@@ -1765,7 +1765,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
82870 rsp->qlen += rdp->qlen;
82871 rdp->n_cbs_orphaned += rdp->qlen;
82872 rdp->qlen_lazy = 0;
82873- ACCESS_ONCE(rdp->qlen) = 0;
82874+ ACCESS_ONCE_RW(rdp->qlen) = 0;
82875 }
82876
82877 /*
82878@@ -2011,7 +2011,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
82879 }
82880 smp_mb(); /* List handling before counting for rcu_barrier(). */
82881 rdp->qlen_lazy -= count_lazy;
82882- ACCESS_ONCE(rdp->qlen) -= count;
82883+ ACCESS_ONCE_RW(rdp->qlen) -= count;
82884 rdp->n_cbs_invoked += count;
82885
82886 /* Reinstate batch limit if we have worked down the excess. */
82887@@ -2202,7 +2202,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
82888 /*
82889 * Do RCU core processing for the current CPU.
82890 */
82891-static void rcu_process_callbacks(struct softirq_action *unused)
82892+static __latent_entropy void rcu_process_callbacks(void)
82893 {
82894 struct rcu_state *rsp;
82895
82896@@ -2325,7 +2325,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
82897 local_irq_restore(flags);
82898 return;
82899 }
82900- ACCESS_ONCE(rdp->qlen)++;
82901+ ACCESS_ONCE_RW(rdp->qlen)++;
82902 if (lazy)
82903 rdp->qlen_lazy++;
82904 else
82905@@ -2534,11 +2534,11 @@ void synchronize_sched_expedited(void)
82906 * counter wrap on a 32-bit system. Quite a few more CPUs would of
82907 * course be required on a 64-bit system.
82908 */
82909- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
82910+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
82911 (ulong)atomic_long_read(&rsp->expedited_done) +
82912 ULONG_MAX / 8)) {
82913 synchronize_sched();
82914- atomic_long_inc(&rsp->expedited_wrap);
82915+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
82916 return;
82917 }
82918
82919@@ -2546,7 +2546,7 @@ void synchronize_sched_expedited(void)
82920 * Take a ticket. Note that atomic_inc_return() implies a
82921 * full memory barrier.
82922 */
82923- snap = atomic_long_inc_return(&rsp->expedited_start);
82924+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
82925 firstsnap = snap;
82926 get_online_cpus();
82927 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
82928@@ -2559,14 +2559,14 @@ void synchronize_sched_expedited(void)
82929 synchronize_sched_expedited_cpu_stop,
82930 NULL) == -EAGAIN) {
82931 put_online_cpus();
82932- atomic_long_inc(&rsp->expedited_tryfail);
82933+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
82934
82935 /* Check to see if someone else did our work for us. */
82936 s = atomic_long_read(&rsp->expedited_done);
82937 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
82938 /* ensure test happens before caller kfree */
82939 smp_mb__before_atomic_inc(); /* ^^^ */
82940- atomic_long_inc(&rsp->expedited_workdone1);
82941+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
82942 return;
82943 }
82944
82945@@ -2575,7 +2575,7 @@ void synchronize_sched_expedited(void)
82946 udelay(trycount * num_online_cpus());
82947 } else {
82948 wait_rcu_gp(call_rcu_sched);
82949- atomic_long_inc(&rsp->expedited_normal);
82950+ atomic_long_inc_unchecked(&rsp->expedited_normal);
82951 return;
82952 }
82953
82954@@ -2584,7 +2584,7 @@ void synchronize_sched_expedited(void)
82955 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
82956 /* ensure test happens before caller kfree */
82957 smp_mb__before_atomic_inc(); /* ^^^ */
82958- atomic_long_inc(&rsp->expedited_workdone2);
82959+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
82960 return;
82961 }
82962
82963@@ -2596,10 +2596,10 @@ void synchronize_sched_expedited(void)
82964 * period works for us.
82965 */
82966 get_online_cpus();
82967- snap = atomic_long_read(&rsp->expedited_start);
82968+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
82969 smp_mb(); /* ensure read is before try_stop_cpus(). */
82970 }
82971- atomic_long_inc(&rsp->expedited_stoppedcpus);
82972+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
82973
82974 /*
82975 * Everyone up to our most recent fetch is covered by our grace
82976@@ -2608,16 +2608,16 @@ void synchronize_sched_expedited(void)
82977 * than we did already did their update.
82978 */
82979 do {
82980- atomic_long_inc(&rsp->expedited_done_tries);
82981+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
82982 s = atomic_long_read(&rsp->expedited_done);
82983 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
82984 /* ensure test happens before caller kfree */
82985 smp_mb__before_atomic_inc(); /* ^^^ */
82986- atomic_long_inc(&rsp->expedited_done_lost);
82987+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
82988 break;
82989 }
82990 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
82991- atomic_long_inc(&rsp->expedited_done_exit);
82992+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
82993
82994 put_online_cpus();
82995 }
82996@@ -2799,7 +2799,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
82997 * ACCESS_ONCE() to prevent the compiler from speculating
82998 * the increment to precede the early-exit check.
82999 */
83000- ACCESS_ONCE(rsp->n_barrier_done)++;
83001+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
83002 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
83003 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
83004 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
83005@@ -2849,7 +2849,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
83006
83007 /* Increment ->n_barrier_done to prevent duplicate work. */
83008 smp_mb(); /* Keep increment after above mechanism. */
83009- ACCESS_ONCE(rsp->n_barrier_done)++;
83010+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
83011 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
83012 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
83013 smp_mb(); /* Keep increment before caller's subsequent code. */
83014@@ -2894,10 +2894,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
83015 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
83016 init_callback_list(rdp);
83017 rdp->qlen_lazy = 0;
83018- ACCESS_ONCE(rdp->qlen) = 0;
83019+ ACCESS_ONCE_RW(rdp->qlen) = 0;
83020 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
83021 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
83022- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
83023+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
83024 rdp->cpu = cpu;
83025 rdp->rsp = rsp;
83026 rcu_boot_init_nocb_percpu_data(rdp);
83027@@ -2930,8 +2930,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
83028 rdp->blimit = blimit;
83029 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
83030 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
83031- atomic_set(&rdp->dynticks->dynticks,
83032- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
83033+ atomic_set_unchecked(&rdp->dynticks->dynticks,
83034+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
83035 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
83036
83037 /* Add CPU to rcu_node bitmasks. */
83038diff --git a/kernel/rcutree.h b/kernel/rcutree.h
83039index b383258..2440c1e 100644
83040--- a/kernel/rcutree.h
83041+++ b/kernel/rcutree.h
83042@@ -87,7 +87,7 @@ struct rcu_dynticks {
83043 long long dynticks_nesting; /* Track irq/process nesting level. */
83044 /* Process level is worth LLONG_MAX/2. */
83045 int dynticks_nmi_nesting; /* Track NMI nesting level. */
83046- atomic_t dynticks; /* Even value for idle, else odd. */
83047+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
83048 #ifdef CONFIG_RCU_FAST_NO_HZ
83049 bool all_lazy; /* Are all CPU's CBs lazy? */
83050 unsigned long nonlazy_posted;
83051@@ -419,17 +419,17 @@ struct rcu_state {
83052 /* _rcu_barrier(). */
83053 /* End of fields guarded by barrier_mutex. */
83054
83055- atomic_long_t expedited_start; /* Starting ticket. */
83056- atomic_long_t expedited_done; /* Done ticket. */
83057- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
83058- atomic_long_t expedited_tryfail; /* # acquisition failures. */
83059- atomic_long_t expedited_workdone1; /* # done by others #1. */
83060- atomic_long_t expedited_workdone2; /* # done by others #2. */
83061- atomic_long_t expedited_normal; /* # fallbacks to normal. */
83062- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
83063- atomic_long_t expedited_done_tries; /* # tries to update _done. */
83064- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
83065- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
83066+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
83067+ atomic_long_t expedited_done; /* Done ticket. */
83068+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
83069+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
83070+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
83071+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
83072+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
83073+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
83074+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
83075+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
83076+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
83077
83078 unsigned long jiffies_force_qs; /* Time at which to invoke */
83079 /* force_quiescent_state(). */
83080diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
83081index 769e12e..7b2139b 100644
83082--- a/kernel/rcutree_plugin.h
83083+++ b/kernel/rcutree_plugin.h
83084@@ -902,7 +902,7 @@ void synchronize_rcu_expedited(void)
83085
83086 /* Clean up and exit. */
83087 smp_mb(); /* ensure expedited GP seen before counter increment. */
83088- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
83089+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
83090 unlock_mb_ret:
83091 mutex_unlock(&sync_rcu_preempt_exp_mutex);
83092 mb_ret:
83093@@ -1476,7 +1476,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
83094 free_cpumask_var(cm);
83095 }
83096
83097-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
83098+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
83099 .store = &rcu_cpu_kthread_task,
83100 .thread_should_run = rcu_cpu_kthread_should_run,
83101 .thread_fn = rcu_cpu_kthread,
83102@@ -1941,7 +1941,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
83103 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
83104 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
83105 cpu, ticks_value, ticks_title,
83106- atomic_read(&rdtp->dynticks) & 0xfff,
83107+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
83108 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
83109 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
83110 fast_no_hz);
83111@@ -2104,7 +2104,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
83112
83113 /* Enqueue the callback on the nocb list and update counts. */
83114 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
83115- ACCESS_ONCE(*old_rhpp) = rhp;
83116+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
83117 atomic_long_add(rhcount, &rdp->nocb_q_count);
83118 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
83119
83120@@ -2244,12 +2244,12 @@ static int rcu_nocb_kthread(void *arg)
83121 * Extract queued callbacks, update counts, and wait
83122 * for a grace period to elapse.
83123 */
83124- ACCESS_ONCE(rdp->nocb_head) = NULL;
83125+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
83126 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
83127 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
83128 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
83129- ACCESS_ONCE(rdp->nocb_p_count) += c;
83130- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
83131+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
83132+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
83133 rcu_nocb_wait_gp(rdp);
83134
83135 /* Each pass through the following loop invokes a callback. */
83136@@ -2271,8 +2271,8 @@ static int rcu_nocb_kthread(void *arg)
83137 list = next;
83138 }
83139 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
83140- ACCESS_ONCE(rdp->nocb_p_count) -= c;
83141- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
83142+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
83143+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
83144 rdp->n_nocbs_invoked += c;
83145 }
83146 return 0;
83147@@ -2299,7 +2299,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
83148 t = kthread_run(rcu_nocb_kthread, rdp,
83149 "rcuo%c/%d", rsp->abbr, cpu);
83150 BUG_ON(IS_ERR(t));
83151- ACCESS_ONCE(rdp->nocb_kthread) = t;
83152+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
83153 }
83154 }
83155
83156diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
83157index cf6c174..a8f4b50 100644
83158--- a/kernel/rcutree_trace.c
83159+++ b/kernel/rcutree_trace.c
83160@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
83161 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
83162 rdp->passed_quiesce, rdp->qs_pending);
83163 seq_printf(m, " dt=%d/%llx/%d df=%lu",
83164- atomic_read(&rdp->dynticks->dynticks),
83165+ atomic_read_unchecked(&rdp->dynticks->dynticks),
83166 rdp->dynticks->dynticks_nesting,
83167 rdp->dynticks->dynticks_nmi_nesting,
83168 rdp->dynticks_fqs);
83169@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
83170 struct rcu_state *rsp = (struct rcu_state *)m->private;
83171
83172 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",
83173- atomic_long_read(&rsp->expedited_start),
83174+ atomic_long_read_unchecked(&rsp->expedited_start),
83175 atomic_long_read(&rsp->expedited_done),
83176- atomic_long_read(&rsp->expedited_wrap),
83177- atomic_long_read(&rsp->expedited_tryfail),
83178- atomic_long_read(&rsp->expedited_workdone1),
83179- atomic_long_read(&rsp->expedited_workdone2),
83180- atomic_long_read(&rsp->expedited_normal),
83181- atomic_long_read(&rsp->expedited_stoppedcpus),
83182- atomic_long_read(&rsp->expedited_done_tries),
83183- atomic_long_read(&rsp->expedited_done_lost),
83184- atomic_long_read(&rsp->expedited_done_exit));
83185+ atomic_long_read_unchecked(&rsp->expedited_wrap),
83186+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
83187+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
83188+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
83189+ atomic_long_read_unchecked(&rsp->expedited_normal),
83190+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
83191+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
83192+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
83193+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
83194 return 0;
83195 }
83196
83197diff --git a/kernel/resource.c b/kernel/resource.c
83198index 3f285dc..5755f62 100644
83199--- a/kernel/resource.c
83200+++ b/kernel/resource.c
83201@@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
83202
83203 static int __init ioresources_init(void)
83204 {
83205+#ifdef CONFIG_GRKERNSEC_PROC_ADD
83206+#ifdef CONFIG_GRKERNSEC_PROC_USER
83207+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
83208+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
83209+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
83210+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
83211+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
83212+#endif
83213+#else
83214 proc_create("ioports", 0, NULL, &proc_ioports_operations);
83215 proc_create("iomem", 0, NULL, &proc_iomem_operations);
83216+#endif
83217 return 0;
83218 }
83219 __initcall(ioresources_init);
83220diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
83221index 1d96dd0..994ff19 100644
83222--- a/kernel/rtmutex-tester.c
83223+++ b/kernel/rtmutex-tester.c
83224@@ -22,7 +22,7 @@
83225 #define MAX_RT_TEST_MUTEXES 8
83226
83227 static spinlock_t rttest_lock;
83228-static atomic_t rttest_event;
83229+static atomic_unchecked_t rttest_event;
83230
83231 struct test_thread_data {
83232 int opcode;
83233@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83234
83235 case RTTEST_LOCKCONT:
83236 td->mutexes[td->opdata] = 1;
83237- td->event = atomic_add_return(1, &rttest_event);
83238+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83239 return 0;
83240
83241 case RTTEST_RESET:
83242@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83243 return 0;
83244
83245 case RTTEST_RESETEVENT:
83246- atomic_set(&rttest_event, 0);
83247+ atomic_set_unchecked(&rttest_event, 0);
83248 return 0;
83249
83250 default:
83251@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83252 return ret;
83253
83254 td->mutexes[id] = 1;
83255- td->event = atomic_add_return(1, &rttest_event);
83256+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83257 rt_mutex_lock(&mutexes[id]);
83258- td->event = atomic_add_return(1, &rttest_event);
83259+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83260 td->mutexes[id] = 4;
83261 return 0;
83262
83263@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83264 return ret;
83265
83266 td->mutexes[id] = 1;
83267- td->event = atomic_add_return(1, &rttest_event);
83268+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83269 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
83270- td->event = atomic_add_return(1, &rttest_event);
83271+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83272 td->mutexes[id] = ret ? 0 : 4;
83273 return ret ? -EINTR : 0;
83274
83275@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83276 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
83277 return ret;
83278
83279- td->event = atomic_add_return(1, &rttest_event);
83280+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83281 rt_mutex_unlock(&mutexes[id]);
83282- td->event = atomic_add_return(1, &rttest_event);
83283+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83284 td->mutexes[id] = 0;
83285 return 0;
83286
83287@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
83288 break;
83289
83290 td->mutexes[dat] = 2;
83291- td->event = atomic_add_return(1, &rttest_event);
83292+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83293 break;
83294
83295 default:
83296@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
83297 return;
83298
83299 td->mutexes[dat] = 3;
83300- td->event = atomic_add_return(1, &rttest_event);
83301+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83302 break;
83303
83304 case RTTEST_LOCKNOWAIT:
83305@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
83306 return;
83307
83308 td->mutexes[dat] = 1;
83309- td->event = atomic_add_return(1, &rttest_event);
83310+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83311 return;
83312
83313 default:
83314diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
83315index 4a07353..66b5291 100644
83316--- a/kernel/sched/auto_group.c
83317+++ b/kernel/sched/auto_group.c
83318@@ -11,7 +11,7 @@
83319
83320 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
83321 static struct autogroup autogroup_default;
83322-static atomic_t autogroup_seq_nr;
83323+static atomic_unchecked_t autogroup_seq_nr;
83324
83325 void __init autogroup_init(struct task_struct *init_task)
83326 {
83327@@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
83328
83329 kref_init(&ag->kref);
83330 init_rwsem(&ag->lock);
83331- ag->id = atomic_inc_return(&autogroup_seq_nr);
83332+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
83333 ag->tg = tg;
83334 #ifdef CONFIG_RT_GROUP_SCHED
83335 /*
83336diff --git a/kernel/sched/core.c b/kernel/sched/core.c
83337index 05c39f0..442e6fe 100644
83338--- a/kernel/sched/core.c
83339+++ b/kernel/sched/core.c
83340@@ -2885,7 +2885,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
83341 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
83342 * or number of jiffies left till timeout) if completed.
83343 */
83344-long __sched
83345+long __sched __intentional_overflow(-1)
83346 wait_for_completion_interruptible_timeout(struct completion *x,
83347 unsigned long timeout)
83348 {
83349@@ -2902,7 +2902,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
83350 *
83351 * Return: -ERESTARTSYS if interrupted, 0 if completed.
83352 */
83353-int __sched wait_for_completion_killable(struct completion *x)
83354+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
83355 {
83356 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
83357 if (t == -ERESTARTSYS)
83358@@ -2923,7 +2923,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
83359 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
83360 * or number of jiffies left till timeout) if completed.
83361 */
83362-long __sched
83363+long __sched __intentional_overflow(-1)
83364 wait_for_completion_killable_timeout(struct completion *x,
83365 unsigned long timeout)
83366 {
83367@@ -3149,6 +3149,8 @@ int can_nice(const struct task_struct *p, const int nice)
83368 /* convert nice value [19,-20] to rlimit style value [1,40] */
83369 int nice_rlim = 20 - nice;
83370
83371+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
83372+
83373 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
83374 capable(CAP_SYS_NICE));
83375 }
83376@@ -3182,7 +3184,8 @@ SYSCALL_DEFINE1(nice, int, increment)
83377 if (nice > 19)
83378 nice = 19;
83379
83380- if (increment < 0 && !can_nice(current, nice))
83381+ if (increment < 0 && (!can_nice(current, nice) ||
83382+ gr_handle_chroot_nice()))
83383 return -EPERM;
83384
83385 retval = security_task_setnice(current, nice);
83386@@ -3344,6 +3347,7 @@ recheck:
83387 unsigned long rlim_rtprio =
83388 task_rlimit(p, RLIMIT_RTPRIO);
83389
83390+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
83391 /* can't set/change the rt policy */
83392 if (policy != p->policy && !rlim_rtprio)
83393 return -EPERM;
83394@@ -4473,7 +4477,7 @@ static void migrate_tasks(unsigned int dead_cpu)
83395
83396 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
83397
83398-static struct ctl_table sd_ctl_dir[] = {
83399+static ctl_table_no_const sd_ctl_dir[] __read_only = {
83400 {
83401 .procname = "sched_domain",
83402 .mode = 0555,
83403@@ -4490,17 +4494,17 @@ static struct ctl_table sd_ctl_root[] = {
83404 {}
83405 };
83406
83407-static struct ctl_table *sd_alloc_ctl_entry(int n)
83408+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
83409 {
83410- struct ctl_table *entry =
83411+ ctl_table_no_const *entry =
83412 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
83413
83414 return entry;
83415 }
83416
83417-static void sd_free_ctl_entry(struct ctl_table **tablep)
83418+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
83419 {
83420- struct ctl_table *entry;
83421+ ctl_table_no_const *entry;
83422
83423 /*
83424 * In the intermediate directories, both the child directory and
83425@@ -4508,22 +4512,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
83426 * will always be set. In the lowest directory the names are
83427 * static strings and all have proc handlers.
83428 */
83429- for (entry = *tablep; entry->mode; entry++) {
83430- if (entry->child)
83431- sd_free_ctl_entry(&entry->child);
83432+ for (entry = tablep; entry->mode; entry++) {
83433+ if (entry->child) {
83434+ sd_free_ctl_entry(entry->child);
83435+ pax_open_kernel();
83436+ entry->child = NULL;
83437+ pax_close_kernel();
83438+ }
83439 if (entry->proc_handler == NULL)
83440 kfree(entry->procname);
83441 }
83442
83443- kfree(*tablep);
83444- *tablep = NULL;
83445+ kfree(tablep);
83446 }
83447
83448 static int min_load_idx = 0;
83449 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
83450
83451 static void
83452-set_table_entry(struct ctl_table *entry,
83453+set_table_entry(ctl_table_no_const *entry,
83454 const char *procname, void *data, int maxlen,
83455 umode_t mode, proc_handler *proc_handler,
83456 bool load_idx)
83457@@ -4543,7 +4550,7 @@ set_table_entry(struct ctl_table *entry,
83458 static struct ctl_table *
83459 sd_alloc_ctl_domain_table(struct sched_domain *sd)
83460 {
83461- struct ctl_table *table = sd_alloc_ctl_entry(13);
83462+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
83463
83464 if (table == NULL)
83465 return NULL;
83466@@ -4578,9 +4585,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
83467 return table;
83468 }
83469
83470-static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
83471+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
83472 {
83473- struct ctl_table *entry, *table;
83474+ ctl_table_no_const *entry, *table;
83475 struct sched_domain *sd;
83476 int domain_num = 0, i;
83477 char buf[32];
83478@@ -4607,11 +4614,13 @@ static struct ctl_table_header *sd_sysctl_header;
83479 static void register_sched_domain_sysctl(void)
83480 {
83481 int i, cpu_num = num_possible_cpus();
83482- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
83483+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
83484 char buf[32];
83485
83486 WARN_ON(sd_ctl_dir[0].child);
83487+ pax_open_kernel();
83488 sd_ctl_dir[0].child = entry;
83489+ pax_close_kernel();
83490
83491 if (entry == NULL)
83492 return;
83493@@ -4634,8 +4643,12 @@ static void unregister_sched_domain_sysctl(void)
83494 if (sd_sysctl_header)
83495 unregister_sysctl_table(sd_sysctl_header);
83496 sd_sysctl_header = NULL;
83497- if (sd_ctl_dir[0].child)
83498- sd_free_ctl_entry(&sd_ctl_dir[0].child);
83499+ if (sd_ctl_dir[0].child) {
83500+ sd_free_ctl_entry(sd_ctl_dir[0].child);
83501+ pax_open_kernel();
83502+ sd_ctl_dir[0].child = NULL;
83503+ pax_close_kernel();
83504+ }
83505 }
83506 #else
83507 static void register_sched_domain_sysctl(void)
83508diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
83509index 31cbc15..ba68c15 100644
83510--- a/kernel/sched/fair.c
83511+++ b/kernel/sched/fair.c
83512@@ -869,7 +869,7 @@ void task_numa_fault(int node, int pages, bool migrated)
83513
83514 static void reset_ptenuma_scan(struct task_struct *p)
83515 {
83516- ACCESS_ONCE(p->mm->numa_scan_seq)++;
83517+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
83518 p->mm->numa_scan_offset = 0;
83519 }
83520
83521@@ -5727,7 +5727,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
83522 * run_rebalance_domains is triggered when needed from the scheduler tick.
83523 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
83524 */
83525-static void run_rebalance_domains(struct softirq_action *h)
83526+static __latent_entropy void run_rebalance_domains(void)
83527 {
83528 int this_cpu = smp_processor_id();
83529 struct rq *this_rq = cpu_rq(this_cpu);
83530diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
83531index ef0a7b2..1b728c1 100644
83532--- a/kernel/sched/sched.h
83533+++ b/kernel/sched/sched.h
83534@@ -1004,7 +1004,7 @@ struct sched_class {
83535 #ifdef CONFIG_FAIR_GROUP_SCHED
83536 void (*task_move_group) (struct task_struct *p, int on_rq);
83537 #endif
83538-};
83539+} __do_const;
83540
83541 #define sched_class_highest (&stop_sched_class)
83542 #define for_each_class(class) \
83543diff --git a/kernel/signal.c b/kernel/signal.c
83544index 50e4107..9409983 100644
83545--- a/kernel/signal.c
83546+++ b/kernel/signal.c
83547@@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
83548
83549 int print_fatal_signals __read_mostly;
83550
83551-static void __user *sig_handler(struct task_struct *t, int sig)
83552+static __sighandler_t sig_handler(struct task_struct *t, int sig)
83553 {
83554 return t->sighand->action[sig - 1].sa.sa_handler;
83555 }
83556
83557-static int sig_handler_ignored(void __user *handler, int sig)
83558+static int sig_handler_ignored(__sighandler_t handler, int sig)
83559 {
83560 /* Is it explicitly or implicitly ignored? */
83561 return handler == SIG_IGN ||
83562@@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
83563
83564 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
83565 {
83566- void __user *handler;
83567+ __sighandler_t handler;
83568
83569 handler = sig_handler(t, sig);
83570
83571@@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
83572 atomic_inc(&user->sigpending);
83573 rcu_read_unlock();
83574
83575+ if (!override_rlimit)
83576+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
83577+
83578 if (override_rlimit ||
83579 atomic_read(&user->sigpending) <=
83580 task_rlimit(t, RLIMIT_SIGPENDING)) {
83581@@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
83582
83583 int unhandled_signal(struct task_struct *tsk, int sig)
83584 {
83585- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
83586+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
83587 if (is_global_init(tsk))
83588 return 1;
83589 if (handler != SIG_IGN && handler != SIG_DFL)
83590@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
83591 }
83592 }
83593
83594+ /* allow glibc communication via tgkill to other threads in our
83595+ thread group */
83596+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
83597+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
83598+ && gr_handle_signal(t, sig))
83599+ return -EPERM;
83600+
83601 return security_task_kill(t, info, sig, 0);
83602 }
83603
83604@@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
83605 return send_signal(sig, info, p, 1);
83606 }
83607
83608-static int
83609+int
83610 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
83611 {
83612 return send_signal(sig, info, t, 0);
83613@@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
83614 unsigned long int flags;
83615 int ret, blocked, ignored;
83616 struct k_sigaction *action;
83617+ int is_unhandled = 0;
83618
83619 spin_lock_irqsave(&t->sighand->siglock, flags);
83620 action = &t->sighand->action[sig-1];
83621@@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
83622 }
83623 if (action->sa.sa_handler == SIG_DFL)
83624 t->signal->flags &= ~SIGNAL_UNKILLABLE;
83625+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
83626+ is_unhandled = 1;
83627 ret = specific_send_sig_info(sig, info, t);
83628 spin_unlock_irqrestore(&t->sighand->siglock, flags);
83629
83630+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
83631+ normal operation */
83632+ if (is_unhandled) {
83633+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
83634+ gr_handle_crash(t, sig);
83635+ }
83636+
83637 return ret;
83638 }
83639
83640@@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
83641 ret = check_kill_permission(sig, info, p);
83642 rcu_read_unlock();
83643
83644- if (!ret && sig)
83645+ if (!ret && sig) {
83646 ret = do_send_sig_info(sig, info, p, true);
83647+ if (!ret)
83648+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
83649+ }
83650
83651 return ret;
83652 }
83653@@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
83654 int error = -ESRCH;
83655
83656 rcu_read_lock();
83657- p = find_task_by_vpid(pid);
83658+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
83659+ /* allow glibc communication via tgkill to other threads in our
83660+ thread group */
83661+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
83662+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
83663+ p = find_task_by_vpid_unrestricted(pid);
83664+ else
83665+#endif
83666+ p = find_task_by_vpid(pid);
83667 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
83668 error = check_kill_permission(sig, info, p);
83669 /*
83670@@ -3240,8 +3271,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
83671 }
83672 seg = get_fs();
83673 set_fs(KERNEL_DS);
83674- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
83675- (stack_t __force __user *) &uoss,
83676+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
83677+ (stack_t __force_user *) &uoss,
83678 compat_user_stack_pointer());
83679 set_fs(seg);
83680 if (ret >= 0 && uoss_ptr) {
83681diff --git a/kernel/smpboot.c b/kernel/smpboot.c
83682index eb89e18..a4e6792 100644
83683--- a/kernel/smpboot.c
83684+++ b/kernel/smpboot.c
83685@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
83686 }
83687 smpboot_unpark_thread(plug_thread, cpu);
83688 }
83689- list_add(&plug_thread->list, &hotplug_threads);
83690+ pax_list_add(&plug_thread->list, &hotplug_threads);
83691 out:
83692 mutex_unlock(&smpboot_threads_lock);
83693 return ret;
83694@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
83695 {
83696 get_online_cpus();
83697 mutex_lock(&smpboot_threads_lock);
83698- list_del(&plug_thread->list);
83699+ pax_list_del(&plug_thread->list);
83700 smpboot_destroy_threads(plug_thread);
83701 mutex_unlock(&smpboot_threads_lock);
83702 put_online_cpus();
83703diff --git a/kernel/softirq.c b/kernel/softirq.c
83704index adf6c00..5d89b73 100644
83705--- a/kernel/softirq.c
83706+++ b/kernel/softirq.c
83707@@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
83708 EXPORT_SYMBOL(irq_stat);
83709 #endif
83710
83711-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
83712+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
83713
83714 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
83715
83716-char *softirq_to_name[NR_SOFTIRQS] = {
83717+const char * const softirq_to_name[NR_SOFTIRQS] = {
83718 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
83719 "TASKLET", "SCHED", "HRTIMER", "RCU"
83720 };
83721@@ -248,7 +248,7 @@ restart:
83722 kstat_incr_softirqs_this_cpu(vec_nr);
83723
83724 trace_softirq_entry(vec_nr);
83725- h->action(h);
83726+ h->action();
83727 trace_softirq_exit(vec_nr);
83728 if (unlikely(prev_count != preempt_count())) {
83729 printk(KERN_ERR "huh, entered softirq %u %s %p"
83730@@ -412,7 +412,7 @@ void __raise_softirq_irqoff(unsigned int nr)
83731 or_softirq_pending(1UL << nr);
83732 }
83733
83734-void open_softirq(int nr, void (*action)(struct softirq_action *))
83735+void __init open_softirq(int nr, void (*action)(void))
83736 {
83737 softirq_vec[nr].action = action;
83738 }
83739@@ -468,7 +468,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
83740
83741 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
83742
83743-static void tasklet_action(struct softirq_action *a)
83744+static __latent_entropy void tasklet_action(void)
83745 {
83746 struct tasklet_struct *list;
83747
83748@@ -503,7 +503,7 @@ static void tasklet_action(struct softirq_action *a)
83749 }
83750 }
83751
83752-static void tasklet_hi_action(struct softirq_action *a)
83753+static __latent_entropy void tasklet_hi_action(void)
83754 {
83755 struct tasklet_struct *list;
83756
83757@@ -858,7 +858,7 @@ static struct notifier_block cpu_nfb = {
83758 .notifier_call = cpu_callback
83759 };
83760
83761-static struct smp_hotplug_thread softirq_threads = {
83762+static struct smp_hotplug_thread softirq_threads __read_only = {
83763 .store = &ksoftirqd,
83764 .thread_should_run = ksoftirqd_should_run,
83765 .thread_fn = run_ksoftirqd,
83766diff --git a/kernel/srcu.c b/kernel/srcu.c
83767index 01d5ccb..cdcbee6 100644
83768--- a/kernel/srcu.c
83769+++ b/kernel/srcu.c
83770@@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
83771
83772 idx = ACCESS_ONCE(sp->completed) & 0x1;
83773 preempt_disable();
83774- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
83775+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
83776 smp_mb(); /* B */ /* Avoid leaking the critical section. */
83777- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
83778+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
83779 preempt_enable();
83780 return idx;
83781 }
83782diff --git a/kernel/sys.c b/kernel/sys.c
83783index 771129b..dc0c7e3 100644
83784--- a/kernel/sys.c
83785+++ b/kernel/sys.c
83786@@ -149,6 +149,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
83787 error = -EACCES;
83788 goto out;
83789 }
83790+
83791+ if (gr_handle_chroot_setpriority(p, niceval)) {
83792+ error = -EACCES;
83793+ goto out;
83794+ }
83795+
83796 no_nice = security_task_setnice(p, niceval);
83797 if (no_nice) {
83798 error = no_nice;
83799@@ -352,6 +358,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
83800 goto error;
83801 }
83802
83803+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
83804+ goto error;
83805+
83806 if (rgid != (gid_t) -1 ||
83807 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
83808 new->sgid = new->egid;
83809@@ -387,6 +396,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
83810 old = current_cred();
83811
83812 retval = -EPERM;
83813+
83814+ if (gr_check_group_change(kgid, kgid, kgid))
83815+ goto error;
83816+
83817 if (nsown_capable(CAP_SETGID))
83818 new->gid = new->egid = new->sgid = new->fsgid = kgid;
83819 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
83820@@ -404,7 +417,7 @@ error:
83821 /*
83822 * change the user struct in a credentials set to match the new UID
83823 */
83824-static int set_user(struct cred *new)
83825+int set_user(struct cred *new)
83826 {
83827 struct user_struct *new_user;
83828
83829@@ -484,6 +497,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
83830 goto error;
83831 }
83832
83833+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
83834+ goto error;
83835+
83836 if (!uid_eq(new->uid, old->uid)) {
83837 retval = set_user(new);
83838 if (retval < 0)
83839@@ -534,6 +550,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
83840 old = current_cred();
83841
83842 retval = -EPERM;
83843+
83844+ if (gr_check_crash_uid(kuid))
83845+ goto error;
83846+ if (gr_check_user_change(kuid, kuid, kuid))
83847+ goto error;
83848+
83849 if (nsown_capable(CAP_SETUID)) {
83850 new->suid = new->uid = kuid;
83851 if (!uid_eq(kuid, old->uid)) {
83852@@ -603,6 +625,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
83853 goto error;
83854 }
83855
83856+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
83857+ goto error;
83858+
83859 if (ruid != (uid_t) -1) {
83860 new->uid = kruid;
83861 if (!uid_eq(kruid, old->uid)) {
83862@@ -685,6 +710,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
83863 goto error;
83864 }
83865
83866+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
83867+ goto error;
83868+
83869 if (rgid != (gid_t) -1)
83870 new->gid = krgid;
83871 if (egid != (gid_t) -1)
83872@@ -746,12 +774,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
83873 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
83874 nsown_capable(CAP_SETUID)) {
83875 if (!uid_eq(kuid, old->fsuid)) {
83876+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
83877+ goto error;
83878+
83879 new->fsuid = kuid;
83880 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
83881 goto change_okay;
83882 }
83883 }
83884
83885+error:
83886 abort_creds(new);
83887 return old_fsuid;
83888
83889@@ -784,12 +816,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
83890 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
83891 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
83892 nsown_capable(CAP_SETGID)) {
83893+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
83894+ goto error;
83895+
83896 if (!gid_eq(kgid, old->fsgid)) {
83897 new->fsgid = kgid;
83898 goto change_okay;
83899 }
83900 }
83901
83902+error:
83903 abort_creds(new);
83904 return old_fsgid;
83905
83906@@ -1169,19 +1205,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
83907 return -EFAULT;
83908
83909 down_read(&uts_sem);
83910- error = __copy_to_user(&name->sysname, &utsname()->sysname,
83911+ error = __copy_to_user(name->sysname, &utsname()->sysname,
83912 __OLD_UTS_LEN);
83913 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
83914- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
83915+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
83916 __OLD_UTS_LEN);
83917 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
83918- error |= __copy_to_user(&name->release, &utsname()->release,
83919+ error |= __copy_to_user(name->release, &utsname()->release,
83920 __OLD_UTS_LEN);
83921 error |= __put_user(0, name->release + __OLD_UTS_LEN);
83922- error |= __copy_to_user(&name->version, &utsname()->version,
83923+ error |= __copy_to_user(name->version, &utsname()->version,
83924 __OLD_UTS_LEN);
83925 error |= __put_user(0, name->version + __OLD_UTS_LEN);
83926- error |= __copy_to_user(&name->machine, &utsname()->machine,
83927+ error |= __copy_to_user(name->machine, &utsname()->machine,
83928 __OLD_UTS_LEN);
83929 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
83930 up_read(&uts_sem);
83931@@ -1383,6 +1419,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
83932 */
83933 new_rlim->rlim_cur = 1;
83934 }
83935+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
83936+ is changed to a lower value. Since tasks can be created by the same
83937+ user in between this limit change and an execve by this task, force
83938+ a recheck only for this task by setting PF_NPROC_EXCEEDED
83939+ */
83940+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
83941+ tsk->flags |= PF_NPROC_EXCEEDED;
83942 }
83943 if (!retval) {
83944 if (old_rlim)
83945diff --git a/kernel/sysctl.c b/kernel/sysctl.c
83946index 07f6fc4..65fb3d4 100644
83947--- a/kernel/sysctl.c
83948+++ b/kernel/sysctl.c
83949@@ -93,7 +93,6 @@
83950
83951
83952 #if defined(CONFIG_SYSCTL)
83953-
83954 /* External variables not in a header file. */
83955 extern int sysctl_overcommit_memory;
83956 extern int sysctl_overcommit_ratio;
83957@@ -119,17 +118,18 @@ extern int blk_iopoll_enabled;
83958
83959 /* Constants used for minimum and maximum */
83960 #ifdef CONFIG_LOCKUP_DETECTOR
83961-static int sixty = 60;
83962+static int sixty __read_only = 60;
83963 #endif
83964
83965-static int zero;
83966-static int __maybe_unused one = 1;
83967-static int __maybe_unused two = 2;
83968-static int __maybe_unused three = 3;
83969-static unsigned long one_ul = 1;
83970-static int one_hundred = 100;
83971+static int neg_one __read_only = -1;
83972+static int zero __read_only = 0;
83973+static int __maybe_unused one __read_only = 1;
83974+static int __maybe_unused two __read_only = 2;
83975+static int __maybe_unused three __read_only = 3;
83976+static unsigned long one_ul __read_only = 1;
83977+static int one_hundred __read_only = 100;
83978 #ifdef CONFIG_PRINTK
83979-static int ten_thousand = 10000;
83980+static int ten_thousand __read_only = 10000;
83981 #endif
83982
83983 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
83984@@ -176,10 +176,8 @@ static int proc_taint(struct ctl_table *table, int write,
83985 void __user *buffer, size_t *lenp, loff_t *ppos);
83986 #endif
83987
83988-#ifdef CONFIG_PRINTK
83989 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
83990 void __user *buffer, size_t *lenp, loff_t *ppos);
83991-#endif
83992
83993 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
83994 void __user *buffer, size_t *lenp, loff_t *ppos);
83995@@ -210,6 +208,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
83996
83997 #endif
83998
83999+extern struct ctl_table grsecurity_table[];
84000+
84001 static struct ctl_table kern_table[];
84002 static struct ctl_table vm_table[];
84003 static struct ctl_table fs_table[];
84004@@ -224,6 +224,20 @@ extern struct ctl_table epoll_table[];
84005 int sysctl_legacy_va_layout;
84006 #endif
84007
84008+#ifdef CONFIG_PAX_SOFTMODE
84009+static ctl_table pax_table[] = {
84010+ {
84011+ .procname = "softmode",
84012+ .data = &pax_softmode,
84013+ .maxlen = sizeof(unsigned int),
84014+ .mode = 0600,
84015+ .proc_handler = &proc_dointvec,
84016+ },
84017+
84018+ { }
84019+};
84020+#endif
84021+
84022 /* The default sysctl tables: */
84023
84024 static struct ctl_table sysctl_base_table[] = {
84025@@ -272,6 +286,22 @@ static int max_extfrag_threshold = 1000;
84026 #endif
84027
84028 static struct ctl_table kern_table[] = {
84029+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
84030+ {
84031+ .procname = "grsecurity",
84032+ .mode = 0500,
84033+ .child = grsecurity_table,
84034+ },
84035+#endif
84036+
84037+#ifdef CONFIG_PAX_SOFTMODE
84038+ {
84039+ .procname = "pax",
84040+ .mode = 0500,
84041+ .child = pax_table,
84042+ },
84043+#endif
84044+
84045 {
84046 .procname = "sched_child_runs_first",
84047 .data = &sysctl_sched_child_runs_first,
84048@@ -613,7 +643,7 @@ static struct ctl_table kern_table[] = {
84049 .data = &modprobe_path,
84050 .maxlen = KMOD_PATH_LEN,
84051 .mode = 0644,
84052- .proc_handler = proc_dostring,
84053+ .proc_handler = proc_dostring_modpriv,
84054 },
84055 {
84056 .procname = "modules_disabled",
84057@@ -780,16 +810,20 @@ static struct ctl_table kern_table[] = {
84058 .extra1 = &zero,
84059 .extra2 = &one,
84060 },
84061+#endif
84062 {
84063 .procname = "kptr_restrict",
84064 .data = &kptr_restrict,
84065 .maxlen = sizeof(int),
84066 .mode = 0644,
84067 .proc_handler = proc_dointvec_minmax_sysadmin,
84068+#ifdef CONFIG_GRKERNSEC_HIDESYM
84069+ .extra1 = &two,
84070+#else
84071 .extra1 = &zero,
84072+#endif
84073 .extra2 = &two,
84074 },
84075-#endif
84076 {
84077 .procname = "ngroups_max",
84078 .data = &ngroups_max,
84079@@ -1031,10 +1065,17 @@ static struct ctl_table kern_table[] = {
84080 */
84081 {
84082 .procname = "perf_event_paranoid",
84083- .data = &sysctl_perf_event_paranoid,
84084- .maxlen = sizeof(sysctl_perf_event_paranoid),
84085+ .data = &sysctl_perf_event_legitimately_concerned,
84086+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
84087 .mode = 0644,
84088- .proc_handler = proc_dointvec,
84089+ /* go ahead, be a hero */
84090+ .proc_handler = proc_dointvec_minmax_sysadmin,
84091+ .extra1 = &neg_one,
84092+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
84093+ .extra2 = &three,
84094+#else
84095+ .extra2 = &two,
84096+#endif
84097 },
84098 {
84099 .procname = "perf_event_mlock_kb",
84100@@ -1297,6 +1338,13 @@ static struct ctl_table vm_table[] = {
84101 .proc_handler = proc_dointvec_minmax,
84102 .extra1 = &zero,
84103 },
84104+ {
84105+ .procname = "heap_stack_gap",
84106+ .data = &sysctl_heap_stack_gap,
84107+ .maxlen = sizeof(sysctl_heap_stack_gap),
84108+ .mode = 0644,
84109+ .proc_handler = proc_doulongvec_minmax,
84110+ },
84111 #else
84112 {
84113 .procname = "nr_trim_pages",
84114@@ -1761,6 +1809,16 @@ int proc_dostring(struct ctl_table *table, int write,
84115 buffer, lenp, ppos);
84116 }
84117
84118+int proc_dostring_modpriv(struct ctl_table *table, int write,
84119+ void __user *buffer, size_t *lenp, loff_t *ppos)
84120+{
84121+ if (write && !capable(CAP_SYS_MODULE))
84122+ return -EPERM;
84123+
84124+ return _proc_do_string(table->data, table->maxlen, write,
84125+ buffer, lenp, ppos);
84126+}
84127+
84128 static size_t proc_skip_spaces(char **buf)
84129 {
84130 size_t ret;
84131@@ -1866,6 +1924,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
84132 len = strlen(tmp);
84133 if (len > *size)
84134 len = *size;
84135+ if (len > sizeof(tmp))
84136+ len = sizeof(tmp);
84137 if (copy_to_user(*buf, tmp, len))
84138 return -EFAULT;
84139 *size -= len;
84140@@ -2030,7 +2090,7 @@ int proc_dointvec(struct ctl_table *table, int write,
84141 static int proc_taint(struct ctl_table *table, int write,
84142 void __user *buffer, size_t *lenp, loff_t *ppos)
84143 {
84144- struct ctl_table t;
84145+ ctl_table_no_const t;
84146 unsigned long tmptaint = get_taint();
84147 int err;
84148
84149@@ -2058,7 +2118,6 @@ static int proc_taint(struct ctl_table *table, int write,
84150 return err;
84151 }
84152
84153-#ifdef CONFIG_PRINTK
84154 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
84155 void __user *buffer, size_t *lenp, loff_t *ppos)
84156 {
84157@@ -2067,7 +2126,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
84158
84159 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
84160 }
84161-#endif
84162
84163 struct do_proc_dointvec_minmax_conv_param {
84164 int *min;
84165@@ -2214,8 +2272,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
84166 *i = val;
84167 } else {
84168 val = convdiv * (*i) / convmul;
84169- if (!first)
84170+ if (!first) {
84171 err = proc_put_char(&buffer, &left, '\t');
84172+ if (err)
84173+ break;
84174+ }
84175 err = proc_put_long(&buffer, &left, val, false);
84176 if (err)
84177 break;
84178@@ -2611,6 +2672,12 @@ int proc_dostring(struct ctl_table *table, int write,
84179 return -ENOSYS;
84180 }
84181
84182+int proc_dostring_modpriv(struct ctl_table *table, int write,
84183+ void __user *buffer, size_t *lenp, loff_t *ppos)
84184+{
84185+ return -ENOSYS;
84186+}
84187+
84188 int proc_dointvec(struct ctl_table *table, int write,
84189 void __user *buffer, size_t *lenp, loff_t *ppos)
84190 {
84191@@ -2667,5 +2734,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
84192 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
84193 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
84194 EXPORT_SYMBOL(proc_dostring);
84195+EXPORT_SYMBOL(proc_dostring_modpriv);
84196 EXPORT_SYMBOL(proc_doulongvec_minmax);
84197 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
84198diff --git a/kernel/taskstats.c b/kernel/taskstats.c
84199index 145bb4d..b2aa969 100644
84200--- a/kernel/taskstats.c
84201+++ b/kernel/taskstats.c
84202@@ -28,9 +28,12 @@
84203 #include <linux/fs.h>
84204 #include <linux/file.h>
84205 #include <linux/pid_namespace.h>
84206+#include <linux/grsecurity.h>
84207 #include <net/genetlink.h>
84208 #include <linux/atomic.h>
84209
84210+extern int gr_is_taskstats_denied(int pid);
84211+
84212 /*
84213 * Maximum length of a cpumask that can be specified in
84214 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
84215@@ -570,6 +573,9 @@ err:
84216
84217 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
84218 {
84219+ if (gr_is_taskstats_denied(current->pid))
84220+ return -EACCES;
84221+
84222 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
84223 return cmd_attr_register_cpumask(info);
84224 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
84225diff --git a/kernel/time.c b/kernel/time.c
84226index 7c7964c..784a599 100644
84227--- a/kernel/time.c
84228+++ b/kernel/time.c
84229@@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
84230 return error;
84231
84232 if (tz) {
84233+ /* we log in do_settimeofday called below, so don't log twice
84234+ */
84235+ if (!tv)
84236+ gr_log_timechange();
84237+
84238 sys_tz = *tz;
84239 update_vsyscall_tz();
84240 if (firsttime) {
84241@@ -502,7 +507,7 @@ EXPORT_SYMBOL(usecs_to_jiffies);
84242 * The >> (NSEC_JIFFIE_SC - SEC_JIFFIE_SC) converts the scaled nsec
84243 * value to a scaled second value.
84244 */
84245-unsigned long
84246+unsigned long __intentional_overflow(-1)
84247 timespec_to_jiffies(const struct timespec *value)
84248 {
84249 unsigned long sec = value->tv_sec;
84250diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
84251index eec50fc..65e5df6 100644
84252--- a/kernel/time/alarmtimer.c
84253+++ b/kernel/time/alarmtimer.c
84254@@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
84255 struct platform_device *pdev;
84256 int error = 0;
84257 int i;
84258- struct k_clock alarm_clock = {
84259+ static struct k_clock alarm_clock = {
84260 .clock_getres = alarm_clock_getres,
84261 .clock_get = alarm_clock_get,
84262 .timer_create = alarm_timer_create,
84263diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
84264index 947ba25..20cbade 100644
84265--- a/kernel/time/timekeeping.c
84266+++ b/kernel/time/timekeeping.c
84267@@ -15,6 +15,7 @@
84268 #include <linux/init.h>
84269 #include <linux/mm.h>
84270 #include <linux/sched.h>
84271+#include <linux/grsecurity.h>
84272 #include <linux/syscore_ops.h>
84273 #include <linux/clocksource.h>
84274 #include <linux/jiffies.h>
84275@@ -500,6 +501,8 @@ int do_settimeofday(const struct timespec *tv)
84276 if (!timespec_valid_strict(tv))
84277 return -EINVAL;
84278
84279+ gr_log_timechange();
84280+
84281 raw_spin_lock_irqsave(&timekeeper_lock, flags);
84282 write_seqcount_begin(&timekeeper_seq);
84283
84284diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
84285index 61ed862..3b52c65 100644
84286--- a/kernel/time/timer_list.c
84287+++ b/kernel/time/timer_list.c
84288@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
84289
84290 static void print_name_offset(struct seq_file *m, void *sym)
84291 {
84292+#ifdef CONFIG_GRKERNSEC_HIDESYM
84293+ SEQ_printf(m, "<%p>", NULL);
84294+#else
84295 char symname[KSYM_NAME_LEN];
84296
84297 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
84298 SEQ_printf(m, "<%pK>", sym);
84299 else
84300 SEQ_printf(m, "%s", symname);
84301+#endif
84302 }
84303
84304 static void
84305@@ -119,7 +123,11 @@ next_one:
84306 static void
84307 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
84308 {
84309+#ifdef CONFIG_GRKERNSEC_HIDESYM
84310+ SEQ_printf(m, " .base: %p\n", NULL);
84311+#else
84312 SEQ_printf(m, " .base: %pK\n", base);
84313+#endif
84314 SEQ_printf(m, " .index: %d\n",
84315 base->index);
84316 SEQ_printf(m, " .resolution: %Lu nsecs\n",
84317@@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
84318 {
84319 struct proc_dir_entry *pe;
84320
84321+#ifdef CONFIG_GRKERNSEC_PROC_ADD
84322+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
84323+#else
84324 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
84325+#endif
84326 if (!pe)
84327 return -ENOMEM;
84328 return 0;
84329diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
84330index 0b537f2..40d6c20 100644
84331--- a/kernel/time/timer_stats.c
84332+++ b/kernel/time/timer_stats.c
84333@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
84334 static unsigned long nr_entries;
84335 static struct entry entries[MAX_ENTRIES];
84336
84337-static atomic_t overflow_count;
84338+static atomic_unchecked_t overflow_count;
84339
84340 /*
84341 * The entries are in a hash-table, for fast lookup:
84342@@ -140,7 +140,7 @@ static void reset_entries(void)
84343 nr_entries = 0;
84344 memset(entries, 0, sizeof(entries));
84345 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
84346- atomic_set(&overflow_count, 0);
84347+ atomic_set_unchecked(&overflow_count, 0);
84348 }
84349
84350 static struct entry *alloc_entry(void)
84351@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
84352 if (likely(entry))
84353 entry->count++;
84354 else
84355- atomic_inc(&overflow_count);
84356+ atomic_inc_unchecked(&overflow_count);
84357
84358 out_unlock:
84359 raw_spin_unlock_irqrestore(lock, flags);
84360@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
84361
84362 static void print_name_offset(struct seq_file *m, unsigned long addr)
84363 {
84364+#ifdef CONFIG_GRKERNSEC_HIDESYM
84365+ seq_printf(m, "<%p>", NULL);
84366+#else
84367 char symname[KSYM_NAME_LEN];
84368
84369 if (lookup_symbol_name(addr, symname) < 0)
84370- seq_printf(m, "<%p>", (void *)addr);
84371+ seq_printf(m, "<%pK>", (void *)addr);
84372 else
84373 seq_printf(m, "%s", symname);
84374+#endif
84375 }
84376
84377 static int tstats_show(struct seq_file *m, void *v)
84378@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
84379
84380 seq_puts(m, "Timer Stats Version: v0.2\n");
84381 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
84382- if (atomic_read(&overflow_count))
84383+ if (atomic_read_unchecked(&overflow_count))
84384 seq_printf(m, "Overflow: %d entries\n",
84385- atomic_read(&overflow_count));
84386+ atomic_read_unchecked(&overflow_count));
84387
84388 for (i = 0; i < nr_entries; i++) {
84389 entry = entries + i;
84390@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
84391 {
84392 struct proc_dir_entry *pe;
84393
84394+#ifdef CONFIG_GRKERNSEC_PROC_ADD
84395+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
84396+#else
84397 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
84398+#endif
84399 if (!pe)
84400 return -ENOMEM;
84401 return 0;
84402diff --git a/kernel/timer.c b/kernel/timer.c
84403index 4296d13..0164b04 100644
84404--- a/kernel/timer.c
84405+++ b/kernel/timer.c
84406@@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
84407 /*
84408 * This function runs timers and the timer-tq in bottom half context.
84409 */
84410-static void run_timer_softirq(struct softirq_action *h)
84411+static __latent_entropy void run_timer_softirq(void)
84412 {
84413 struct tvec_base *base = __this_cpu_read(tvec_bases);
84414
84415@@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
84416 *
84417 * In all cases the return value is guaranteed to be non-negative.
84418 */
84419-signed long __sched schedule_timeout(signed long timeout)
84420+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
84421 {
84422 struct timer_list timer;
84423 unsigned long expire;
84424diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
84425index b8b8560..75b1a09 100644
84426--- a/kernel/trace/blktrace.c
84427+++ b/kernel/trace/blktrace.c
84428@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
84429 struct blk_trace *bt = filp->private_data;
84430 char buf[16];
84431
84432- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
84433+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
84434
84435 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
84436 }
84437@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
84438 return 1;
84439
84440 bt = buf->chan->private_data;
84441- atomic_inc(&bt->dropped);
84442+ atomic_inc_unchecked(&bt->dropped);
84443 return 0;
84444 }
84445
84446@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
84447
84448 bt->dir = dir;
84449 bt->dev = dev;
84450- atomic_set(&bt->dropped, 0);
84451+ atomic_set_unchecked(&bt->dropped, 0);
84452
84453 ret = -EIO;
84454 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
84455diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
84456index a6d098c..bb8cf65 100644
84457--- a/kernel/trace/ftrace.c
84458+++ b/kernel/trace/ftrace.c
84459@@ -1950,12 +1950,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
84460 if (unlikely(ftrace_disabled))
84461 return 0;
84462
84463+ ret = ftrace_arch_code_modify_prepare();
84464+ FTRACE_WARN_ON(ret);
84465+ if (ret)
84466+ return 0;
84467+
84468 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
84469+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
84470 if (ret) {
84471 ftrace_bug(ret, ip);
84472- return 0;
84473 }
84474- return 1;
84475+ return ret ? 0 : 1;
84476 }
84477
84478 /*
84479@@ -4028,8 +4033,10 @@ static int ftrace_process_locs(struct module *mod,
84480 if (!count)
84481 return 0;
84482
84483+ pax_open_kernel();
84484 sort(start, count, sizeof(*start),
84485 ftrace_cmp_ips, ftrace_swap_ips);
84486+ pax_close_kernel();
84487
84488 start_pg = ftrace_allocate_pages(count);
84489 if (!start_pg)
84490@@ -4752,8 +4759,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
84491 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
84492
84493 static int ftrace_graph_active;
84494-static struct notifier_block ftrace_suspend_notifier;
84495-
84496 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
84497 {
84498 return 0;
84499@@ -4897,6 +4902,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
84500 return NOTIFY_DONE;
84501 }
84502
84503+static struct notifier_block ftrace_suspend_notifier = {
84504+ .notifier_call = ftrace_suspend_notifier_call
84505+};
84506+
84507 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
84508 trace_func_graph_ent_t entryfunc)
84509 {
84510@@ -4910,7 +4919,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
84511 goto out;
84512 }
84513
84514- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
84515 register_pm_notifier(&ftrace_suspend_notifier);
84516
84517 ftrace_graph_active++;
84518diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
84519index cc2f66f..05edd54 100644
84520--- a/kernel/trace/ring_buffer.c
84521+++ b/kernel/trace/ring_buffer.c
84522@@ -352,9 +352,9 @@ struct buffer_data_page {
84523 */
84524 struct buffer_page {
84525 struct list_head list; /* list of buffer pages */
84526- local_t write; /* index for next write */
84527+ local_unchecked_t write; /* index for next write */
84528 unsigned read; /* index for next read */
84529- local_t entries; /* entries on this page */
84530+ local_unchecked_t entries; /* entries on this page */
84531 unsigned long real_end; /* real end of data */
84532 struct buffer_data_page *page; /* Actual data page */
84533 };
84534@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
84535 unsigned long last_overrun;
84536 local_t entries_bytes;
84537 local_t entries;
84538- local_t overrun;
84539- local_t commit_overrun;
84540+ local_unchecked_t overrun;
84541+ local_unchecked_t commit_overrun;
84542 local_t dropped_events;
84543 local_t committing;
84544 local_t commits;
84545@@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
84546 *
84547 * We add a counter to the write field to denote this.
84548 */
84549- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
84550- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
84551+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
84552+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
84553
84554 /*
84555 * Just make sure we have seen our old_write and synchronize
84556@@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
84557 * cmpxchg to only update if an interrupt did not already
84558 * do it for us. If the cmpxchg fails, we don't care.
84559 */
84560- (void)local_cmpxchg(&next_page->write, old_write, val);
84561- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
84562+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
84563+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
84564
84565 /*
84566 * No need to worry about races with clearing out the commit.
84567@@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
84568
84569 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
84570 {
84571- return local_read(&bpage->entries) & RB_WRITE_MASK;
84572+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
84573 }
84574
84575 static inline unsigned long rb_page_write(struct buffer_page *bpage)
84576 {
84577- return local_read(&bpage->write) & RB_WRITE_MASK;
84578+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
84579 }
84580
84581 static int
84582@@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
84583 * bytes consumed in ring buffer from here.
84584 * Increment overrun to account for the lost events.
84585 */
84586- local_add(page_entries, &cpu_buffer->overrun);
84587+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
84588 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
84589 }
84590
84591@@ -2064,7 +2064,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
84592 * it is our responsibility to update
84593 * the counters.
84594 */
84595- local_add(entries, &cpu_buffer->overrun);
84596+ local_add_unchecked(entries, &cpu_buffer->overrun);
84597 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
84598
84599 /*
84600@@ -2214,7 +2214,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
84601 if (tail == BUF_PAGE_SIZE)
84602 tail_page->real_end = 0;
84603
84604- local_sub(length, &tail_page->write);
84605+ local_sub_unchecked(length, &tail_page->write);
84606 return;
84607 }
84608
84609@@ -2249,7 +2249,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
84610 rb_event_set_padding(event);
84611
84612 /* Set the write back to the previous setting */
84613- local_sub(length, &tail_page->write);
84614+ local_sub_unchecked(length, &tail_page->write);
84615 return;
84616 }
84617
84618@@ -2261,7 +2261,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
84619
84620 /* Set write to end of buffer */
84621 length = (tail + length) - BUF_PAGE_SIZE;
84622- local_sub(length, &tail_page->write);
84623+ local_sub_unchecked(length, &tail_page->write);
84624 }
84625
84626 /*
84627@@ -2287,7 +2287,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
84628 * about it.
84629 */
84630 if (unlikely(next_page == commit_page)) {
84631- local_inc(&cpu_buffer->commit_overrun);
84632+ local_inc_unchecked(&cpu_buffer->commit_overrun);
84633 goto out_reset;
84634 }
84635
84636@@ -2343,7 +2343,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
84637 cpu_buffer->tail_page) &&
84638 (cpu_buffer->commit_page ==
84639 cpu_buffer->reader_page))) {
84640- local_inc(&cpu_buffer->commit_overrun);
84641+ local_inc_unchecked(&cpu_buffer->commit_overrun);
84642 goto out_reset;
84643 }
84644 }
84645@@ -2391,7 +2391,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
84646 length += RB_LEN_TIME_EXTEND;
84647
84648 tail_page = cpu_buffer->tail_page;
84649- write = local_add_return(length, &tail_page->write);
84650+ write = local_add_return_unchecked(length, &tail_page->write);
84651
84652 /* set write to only the index of the write */
84653 write &= RB_WRITE_MASK;
84654@@ -2408,7 +2408,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
84655 kmemcheck_annotate_bitfield(event, bitfield);
84656 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
84657
84658- local_inc(&tail_page->entries);
84659+ local_inc_unchecked(&tail_page->entries);
84660
84661 /*
84662 * If this is the first commit on the page, then update
84663@@ -2441,7 +2441,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
84664
84665 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
84666 unsigned long write_mask =
84667- local_read(&bpage->write) & ~RB_WRITE_MASK;
84668+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
84669 unsigned long event_length = rb_event_length(event);
84670 /*
84671 * This is on the tail page. It is possible that
84672@@ -2451,7 +2451,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
84673 */
84674 old_index += write_mask;
84675 new_index += write_mask;
84676- index = local_cmpxchg(&bpage->write, old_index, new_index);
84677+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
84678 if (index == old_index) {
84679 /* update counters */
84680 local_sub(event_length, &cpu_buffer->entries_bytes);
84681@@ -2843,7 +2843,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
84682
84683 /* Do the likely case first */
84684 if (likely(bpage->page == (void *)addr)) {
84685- local_dec(&bpage->entries);
84686+ local_dec_unchecked(&bpage->entries);
84687 return;
84688 }
84689
84690@@ -2855,7 +2855,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
84691 start = bpage;
84692 do {
84693 if (bpage->page == (void *)addr) {
84694- local_dec(&bpage->entries);
84695+ local_dec_unchecked(&bpage->entries);
84696 return;
84697 }
84698 rb_inc_page(cpu_buffer, &bpage);
84699@@ -3139,7 +3139,7 @@ static inline unsigned long
84700 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
84701 {
84702 return local_read(&cpu_buffer->entries) -
84703- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
84704+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
84705 }
84706
84707 /**
84708@@ -3228,7 +3228,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
84709 return 0;
84710
84711 cpu_buffer = buffer->buffers[cpu];
84712- ret = local_read(&cpu_buffer->overrun);
84713+ ret = local_read_unchecked(&cpu_buffer->overrun);
84714
84715 return ret;
84716 }
84717@@ -3251,7 +3251,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
84718 return 0;
84719
84720 cpu_buffer = buffer->buffers[cpu];
84721- ret = local_read(&cpu_buffer->commit_overrun);
84722+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
84723
84724 return ret;
84725 }
84726@@ -3336,7 +3336,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
84727 /* if you care about this being correct, lock the buffer */
84728 for_each_buffer_cpu(buffer, cpu) {
84729 cpu_buffer = buffer->buffers[cpu];
84730- overruns += local_read(&cpu_buffer->overrun);
84731+ overruns += local_read_unchecked(&cpu_buffer->overrun);
84732 }
84733
84734 return overruns;
84735@@ -3512,8 +3512,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
84736 /*
84737 * Reset the reader page to size zero.
84738 */
84739- local_set(&cpu_buffer->reader_page->write, 0);
84740- local_set(&cpu_buffer->reader_page->entries, 0);
84741+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
84742+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
84743 local_set(&cpu_buffer->reader_page->page->commit, 0);
84744 cpu_buffer->reader_page->real_end = 0;
84745
84746@@ -3547,7 +3547,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
84747 * want to compare with the last_overrun.
84748 */
84749 smp_mb();
84750- overwrite = local_read(&(cpu_buffer->overrun));
84751+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
84752
84753 /*
84754 * Here's the tricky part.
84755@@ -4117,8 +4117,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
84756
84757 cpu_buffer->head_page
84758 = list_entry(cpu_buffer->pages, struct buffer_page, list);
84759- local_set(&cpu_buffer->head_page->write, 0);
84760- local_set(&cpu_buffer->head_page->entries, 0);
84761+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
84762+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
84763 local_set(&cpu_buffer->head_page->page->commit, 0);
84764
84765 cpu_buffer->head_page->read = 0;
84766@@ -4128,14 +4128,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
84767
84768 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
84769 INIT_LIST_HEAD(&cpu_buffer->new_pages);
84770- local_set(&cpu_buffer->reader_page->write, 0);
84771- local_set(&cpu_buffer->reader_page->entries, 0);
84772+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
84773+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
84774 local_set(&cpu_buffer->reader_page->page->commit, 0);
84775 cpu_buffer->reader_page->read = 0;
84776
84777 local_set(&cpu_buffer->entries_bytes, 0);
84778- local_set(&cpu_buffer->overrun, 0);
84779- local_set(&cpu_buffer->commit_overrun, 0);
84780+ local_set_unchecked(&cpu_buffer->overrun, 0);
84781+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
84782 local_set(&cpu_buffer->dropped_events, 0);
84783 local_set(&cpu_buffer->entries, 0);
84784 local_set(&cpu_buffer->committing, 0);
84785@@ -4540,8 +4540,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
84786 rb_init_page(bpage);
84787 bpage = reader->page;
84788 reader->page = *data_page;
84789- local_set(&reader->write, 0);
84790- local_set(&reader->entries, 0);
84791+ local_set_unchecked(&reader->write, 0);
84792+ local_set_unchecked(&reader->entries, 0);
84793 reader->read = 0;
84794 *data_page = bpage;
84795
84796diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
84797index 496f94d..754aeea 100644
84798--- a/kernel/trace/trace.c
84799+++ b/kernel/trace/trace.c
84800@@ -3335,7 +3335,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
84801 return 0;
84802 }
84803
84804-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
84805+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
84806 {
84807 /* do nothing if flag is already set */
84808 if (!!(trace_flags & mask) == !!enabled)
84809diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
84810index afaae41..64871f8 100644
84811--- a/kernel/trace/trace.h
84812+++ b/kernel/trace/trace.h
84813@@ -1025,7 +1025,7 @@ extern const char *__stop___trace_bprintk_fmt[];
84814 void trace_printk_init_buffers(void);
84815 void trace_printk_start_comm(void);
84816 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
84817-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
84818+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
84819
84820 /*
84821 * Normal trace_printk() and friends allocates special buffers
84822diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
84823index 26dc348..8708ca7 100644
84824--- a/kernel/trace/trace_clock.c
84825+++ b/kernel/trace/trace_clock.c
84826@@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
84827 return now;
84828 }
84829
84830-static atomic64_t trace_counter;
84831+static atomic64_unchecked_t trace_counter;
84832
84833 /*
84834 * trace_clock_counter(): simply an atomic counter.
84835@@ -132,5 +132,5 @@ static atomic64_t trace_counter;
84836 */
84837 u64 notrace trace_clock_counter(void)
84838 {
84839- return atomic64_add_return(1, &trace_counter);
84840+ return atomic64_inc_return_unchecked(&trace_counter);
84841 }
84842diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
84843index 29a7ebc..eb473cf 100644
84844--- a/kernel/trace/trace_events.c
84845+++ b/kernel/trace/trace_events.c
84846@@ -1778,10 +1778,6 @@ static LIST_HEAD(ftrace_module_file_list);
84847 struct ftrace_module_file_ops {
84848 struct list_head list;
84849 struct module *mod;
84850- struct file_operations id;
84851- struct file_operations enable;
84852- struct file_operations format;
84853- struct file_operations filter;
84854 };
84855
84856 static struct ftrace_module_file_ops *
84857@@ -1822,17 +1818,12 @@ trace_create_file_ops(struct module *mod)
84858
84859 file_ops->mod = mod;
84860
84861- file_ops->id = ftrace_event_id_fops;
84862- file_ops->id.owner = mod;
84863-
84864- file_ops->enable = ftrace_enable_fops;
84865- file_ops->enable.owner = mod;
84866-
84867- file_ops->filter = ftrace_event_filter_fops;
84868- file_ops->filter.owner = mod;
84869-
84870- file_ops->format = ftrace_event_format_fops;
84871- file_ops->format.owner = mod;
84872+ pax_open_kernel();
84873+ mod->trace_id.owner = mod;
84874+ mod->trace_enable.owner = mod;
84875+ mod->trace_filter.owner = mod;
84876+ mod->trace_format.owner = mod;
84877+ pax_close_kernel();
84878
84879 list_add(&file_ops->list, &ftrace_module_file_list);
84880
84881@@ -1925,8 +1916,8 @@ __trace_add_new_mod_event(struct ftrace_event_call *call,
84882 struct ftrace_module_file_ops *file_ops)
84883 {
84884 return __trace_add_new_event(call, tr,
84885- &file_ops->id, &file_ops->enable,
84886- &file_ops->filter, &file_ops->format);
84887+ &file_ops->mod->trace_id, &file_ops->mod->trace_enable,
84888+ &file_ops->mod->trace_filter, &file_ops->mod->trace_format);
84889 }
84890
84891 #else
84892diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
84893index b3dcfb2..ebee344 100644
84894--- a/kernel/trace/trace_mmiotrace.c
84895+++ b/kernel/trace/trace_mmiotrace.c
84896@@ -24,7 +24,7 @@ struct header_iter {
84897 static struct trace_array *mmio_trace_array;
84898 static bool overrun_detected;
84899 static unsigned long prev_overruns;
84900-static atomic_t dropped_count;
84901+static atomic_unchecked_t dropped_count;
84902
84903 static void mmio_reset_data(struct trace_array *tr)
84904 {
84905@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
84906
84907 static unsigned long count_overruns(struct trace_iterator *iter)
84908 {
84909- unsigned long cnt = atomic_xchg(&dropped_count, 0);
84910+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
84911 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
84912
84913 if (over > prev_overruns)
84914@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
84915 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
84916 sizeof(*entry), 0, pc);
84917 if (!event) {
84918- atomic_inc(&dropped_count);
84919+ atomic_inc_unchecked(&dropped_count);
84920 return;
84921 }
84922 entry = ring_buffer_event_data(event);
84923@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
84924 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
84925 sizeof(*entry), 0, pc);
84926 if (!event) {
84927- atomic_inc(&dropped_count);
84928+ atomic_inc_unchecked(&dropped_count);
84929 return;
84930 }
84931 entry = ring_buffer_event_data(event);
84932diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
84933index 34e7cba..6f9a729 100644
84934--- a/kernel/trace/trace_output.c
84935+++ b/kernel/trace/trace_output.c
84936@@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
84937
84938 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
84939 if (!IS_ERR(p)) {
84940- p = mangle_path(s->buffer + s->len, p, "\n");
84941+ p = mangle_path(s->buffer + s->len, p, "\n\\");
84942 if (p) {
84943 s->len = p - s->buffer;
84944 return 1;
84945@@ -893,14 +893,16 @@ int register_ftrace_event(struct trace_event *event)
84946 goto out;
84947 }
84948
84949+ pax_open_kernel();
84950 if (event->funcs->trace == NULL)
84951- event->funcs->trace = trace_nop_print;
84952+ *(void **)&event->funcs->trace = trace_nop_print;
84953 if (event->funcs->raw == NULL)
84954- event->funcs->raw = trace_nop_print;
84955+ *(void **)&event->funcs->raw = trace_nop_print;
84956 if (event->funcs->hex == NULL)
84957- event->funcs->hex = trace_nop_print;
84958+ *(void **)&event->funcs->hex = trace_nop_print;
84959 if (event->funcs->binary == NULL)
84960- event->funcs->binary = trace_nop_print;
84961+ *(void **)&event->funcs->binary = trace_nop_print;
84962+ pax_close_kernel();
84963
84964 key = event->type & (EVENT_HASHSIZE - 1);
84965
84966diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
84967index b20428c..4845a10 100644
84968--- a/kernel/trace/trace_stack.c
84969+++ b/kernel/trace/trace_stack.c
84970@@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
84971 return;
84972
84973 /* we do not handle interrupt stacks yet */
84974- if (!object_is_on_stack(stack))
84975+ if (!object_starts_on_stack(stack))
84976 return;
84977
84978 local_irq_save(flags);
84979diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
84980index 9064b91..1f5d2f8 100644
84981--- a/kernel/user_namespace.c
84982+++ b/kernel/user_namespace.c
84983@@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
84984 !kgid_has_mapping(parent_ns, group))
84985 return -EPERM;
84986
84987+#ifdef CONFIG_GRKERNSEC
84988+ /*
84989+ * This doesn't really inspire confidence:
84990+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
84991+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
84992+ * Increases kernel attack surface in areas developers
84993+ * previously cared little about ("low importance due
84994+ * to requiring "root" capability")
84995+ * To be removed when this code receives *proper* review
84996+ */
84997+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
84998+ !capable(CAP_SETGID))
84999+ return -EPERM;
85000+#endif
85001+
85002 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
85003 if (!ns)
85004 return -ENOMEM;
85005@@ -862,7 +877,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
85006 if (atomic_read(&current->mm->mm_users) > 1)
85007 return -EINVAL;
85008
85009- if (current->fs->users != 1)
85010+ if (atomic_read(&current->fs->users) != 1)
85011 return -EINVAL;
85012
85013 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
85014diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
85015index 4f69f9a..7c6f8f8 100644
85016--- a/kernel/utsname_sysctl.c
85017+++ b/kernel/utsname_sysctl.c
85018@@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
85019 static int proc_do_uts_string(ctl_table *table, int write,
85020 void __user *buffer, size_t *lenp, loff_t *ppos)
85021 {
85022- struct ctl_table uts_table;
85023+ ctl_table_no_const uts_table;
85024 int r;
85025 memcpy(&uts_table, table, sizeof(uts_table));
85026 uts_table.data = get_uts(table, write);
85027diff --git a/kernel/watchdog.c b/kernel/watchdog.c
85028index 1241d8c..d5cfc28 100644
85029--- a/kernel/watchdog.c
85030+++ b/kernel/watchdog.c
85031@@ -475,7 +475,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
85032 static void watchdog_nmi_disable(unsigned int cpu) { return; }
85033 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
85034
85035-static struct smp_hotplug_thread watchdog_threads = {
85036+static struct smp_hotplug_thread watchdog_threads __read_only = {
85037 .store = &softlockup_watchdog,
85038 .thread_should_run = watchdog_should_run,
85039 .thread_fn = watchdog,
85040diff --git a/kernel/workqueue.c b/kernel/workqueue.c
85041index e93f7b9..989fcd7 100644
85042--- a/kernel/workqueue.c
85043+++ b/kernel/workqueue.c
85044@@ -4627,7 +4627,7 @@ static void rebind_workers(struct worker_pool *pool)
85045 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
85046 worker_flags |= WORKER_REBOUND;
85047 worker_flags &= ~WORKER_UNBOUND;
85048- ACCESS_ONCE(worker->flags) = worker_flags;
85049+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
85050 }
85051
85052 spin_unlock_irq(&pool->lock);
85053diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
85054index 1501aa5..e771896 100644
85055--- a/lib/Kconfig.debug
85056+++ b/lib/Kconfig.debug
85057@@ -836,7 +836,7 @@ config DEBUG_MUTEXES
85058
85059 config DEBUG_WW_MUTEX_SLOWPATH
85060 bool "Wait/wound mutex debugging: Slowpath testing"
85061- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
85062+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
85063 select DEBUG_LOCK_ALLOC
85064 select DEBUG_SPINLOCK
85065 select DEBUG_MUTEXES
85066@@ -849,7 +849,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
85067
85068 config DEBUG_LOCK_ALLOC
85069 bool "Lock debugging: detect incorrect freeing of live locks"
85070- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
85071+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
85072 select DEBUG_SPINLOCK
85073 select DEBUG_MUTEXES
85074 select LOCKDEP
85075@@ -863,7 +863,7 @@ config DEBUG_LOCK_ALLOC
85076
85077 config PROVE_LOCKING
85078 bool "Lock debugging: prove locking correctness"
85079- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
85080+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
85081 select LOCKDEP
85082 select DEBUG_SPINLOCK
85083 select DEBUG_MUTEXES
85084@@ -914,7 +914,7 @@ config LOCKDEP
85085
85086 config LOCK_STAT
85087 bool "Lock usage statistics"
85088- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
85089+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
85090 select LOCKDEP
85091 select DEBUG_SPINLOCK
85092 select DEBUG_MUTEXES
85093@@ -1357,6 +1357,7 @@ config LATENCYTOP
85094 depends on DEBUG_KERNEL
85095 depends on STACKTRACE_SUPPORT
85096 depends on PROC_FS
85097+ depends on !GRKERNSEC_HIDESYM
85098 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
85099 select KALLSYMS
85100 select KALLSYMS_ALL
85101@@ -1373,7 +1374,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
85102 config DEBUG_STRICT_USER_COPY_CHECKS
85103 bool "Strict user copy size checks"
85104 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
85105- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
85106+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
85107 help
85108 Enabling this option turns a certain set of sanity checks for user
85109 copy operations into compile time failures.
85110@@ -1483,7 +1484,7 @@ endmenu # runtime tests
85111
85112 config PROVIDE_OHCI1394_DMA_INIT
85113 bool "Remote debugging over FireWire early on boot"
85114- depends on PCI && X86
85115+ depends on PCI && X86 && !GRKERNSEC
85116 help
85117 If you want to debug problems which hang or crash the kernel early
85118 on boot and the crashing machine has a FireWire port, you can use
85119@@ -1512,7 +1513,7 @@ config PROVIDE_OHCI1394_DMA_INIT
85120
85121 config FIREWIRE_OHCI_REMOTE_DMA
85122 bool "Remote debugging over FireWire with firewire-ohci"
85123- depends on FIREWIRE_OHCI
85124+ depends on FIREWIRE_OHCI && !GRKERNSEC
85125 help
85126 This option lets you use the FireWire bus for remote debugging
85127 with help of the firewire-ohci driver. It enables unfiltered
85128diff --git a/lib/Makefile b/lib/Makefile
85129index 7baccfd..3ceb95f 100644
85130--- a/lib/Makefile
85131+++ b/lib/Makefile
85132@@ -50,7 +50,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
85133
85134 obj-$(CONFIG_BTREE) += btree.o
85135 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
85136-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
85137+obj-y += list_debug.o
85138 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
85139
85140 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
85141diff --git a/lib/bitmap.c b/lib/bitmap.c
85142index 06f7e4f..f3cf2b0 100644
85143--- a/lib/bitmap.c
85144+++ b/lib/bitmap.c
85145@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
85146 {
85147 int c, old_c, totaldigits, ndigits, nchunks, nbits;
85148 u32 chunk;
85149- const char __user __force *ubuf = (const char __user __force *)buf;
85150+ const char __user *ubuf = (const char __force_user *)buf;
85151
85152 bitmap_zero(maskp, nmaskbits);
85153
85154@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
85155 {
85156 if (!access_ok(VERIFY_READ, ubuf, ulen))
85157 return -EFAULT;
85158- return __bitmap_parse((const char __force *)ubuf,
85159+ return __bitmap_parse((const char __force_kernel *)ubuf,
85160 ulen, 1, maskp, nmaskbits);
85161
85162 }
85163@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
85164 {
85165 unsigned a, b;
85166 int c, old_c, totaldigits;
85167- const char __user __force *ubuf = (const char __user __force *)buf;
85168+ const char __user *ubuf = (const char __force_user *)buf;
85169 int exp_digit, in_range;
85170
85171 totaldigits = c = 0;
85172@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
85173 {
85174 if (!access_ok(VERIFY_READ, ubuf, ulen))
85175 return -EFAULT;
85176- return __bitmap_parselist((const char __force *)ubuf,
85177+ return __bitmap_parselist((const char __force_kernel *)ubuf,
85178 ulen, 1, maskp, nmaskbits);
85179 }
85180 EXPORT_SYMBOL(bitmap_parselist_user);
85181diff --git a/lib/bug.c b/lib/bug.c
85182index 1686034..a9c00c8 100644
85183--- a/lib/bug.c
85184+++ b/lib/bug.c
85185@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
85186 return BUG_TRAP_TYPE_NONE;
85187
85188 bug = find_bug(bugaddr);
85189+ if (!bug)
85190+ return BUG_TRAP_TYPE_NONE;
85191
85192 file = NULL;
85193 line = 0;
85194diff --git a/lib/debugobjects.c b/lib/debugobjects.c
85195index 37061ed..da83f48 100644
85196--- a/lib/debugobjects.c
85197+++ b/lib/debugobjects.c
85198@@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
85199 if (limit > 4)
85200 return;
85201
85202- is_on_stack = object_is_on_stack(addr);
85203+ is_on_stack = object_starts_on_stack(addr);
85204 if (is_on_stack == onstack)
85205 return;
85206
85207diff --git a/lib/devres.c b/lib/devres.c
85208index 8235331..5881053 100644
85209--- a/lib/devres.c
85210+++ b/lib/devres.c
85211@@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
85212 void devm_iounmap(struct device *dev, void __iomem *addr)
85213 {
85214 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
85215- (void *)addr));
85216+ (void __force *)addr));
85217 iounmap(addr);
85218 }
85219 EXPORT_SYMBOL(devm_iounmap);
85220@@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
85221 {
85222 ioport_unmap(addr);
85223 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
85224- devm_ioport_map_match, (void *)addr));
85225+ devm_ioport_map_match, (void __force *)addr));
85226 }
85227 EXPORT_SYMBOL(devm_ioport_unmap);
85228 #endif /* CONFIG_HAS_IOPORT */
85229diff --git a/lib/div64.c b/lib/div64.c
85230index a163b6c..9618fa5 100644
85231--- a/lib/div64.c
85232+++ b/lib/div64.c
85233@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
85234 EXPORT_SYMBOL(__div64_32);
85235
85236 #ifndef div_s64_rem
85237-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
85238+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
85239 {
85240 u64 quotient;
85241
85242@@ -90,7 +90,7 @@ EXPORT_SYMBOL(div_s64_rem);
85243 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
85244 */
85245 #ifndef div64_u64
85246-u64 div64_u64(u64 dividend, u64 divisor)
85247+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
85248 {
85249 u32 high = divisor >> 32;
85250 u64 quot;
85251diff --git a/lib/dma-debug.c b/lib/dma-debug.c
85252index d87a17a..ac0d79a 100644
85253--- a/lib/dma-debug.c
85254+++ b/lib/dma-debug.c
85255@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
85256
85257 void dma_debug_add_bus(struct bus_type *bus)
85258 {
85259- struct notifier_block *nb;
85260+ notifier_block_no_const *nb;
85261
85262 if (global_disable)
85263 return;
85264@@ -945,7 +945,7 @@ static void check_unmap(struct dma_debug_entry *ref)
85265
85266 static void check_for_stack(struct device *dev, void *addr)
85267 {
85268- if (object_is_on_stack(addr))
85269+ if (object_starts_on_stack(addr))
85270 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
85271 "stack [addr=%p]\n", addr);
85272 }
85273diff --git a/lib/inflate.c b/lib/inflate.c
85274index 013a761..c28f3fc 100644
85275--- a/lib/inflate.c
85276+++ b/lib/inflate.c
85277@@ -269,7 +269,7 @@ static void free(void *where)
85278 malloc_ptr = free_mem_ptr;
85279 }
85280 #else
85281-#define malloc(a) kmalloc(a, GFP_KERNEL)
85282+#define malloc(a) kmalloc((a), GFP_KERNEL)
85283 #define free(a) kfree(a)
85284 #endif
85285
85286diff --git a/lib/ioremap.c b/lib/ioremap.c
85287index 0c9216c..863bd89 100644
85288--- a/lib/ioremap.c
85289+++ b/lib/ioremap.c
85290@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
85291 unsigned long next;
85292
85293 phys_addr -= addr;
85294- pmd = pmd_alloc(&init_mm, pud, addr);
85295+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
85296 if (!pmd)
85297 return -ENOMEM;
85298 do {
85299@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
85300 unsigned long next;
85301
85302 phys_addr -= addr;
85303- pud = pud_alloc(&init_mm, pgd, addr);
85304+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
85305 if (!pud)
85306 return -ENOMEM;
85307 do {
85308diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
85309index bd2bea9..6b3c95e 100644
85310--- a/lib/is_single_threaded.c
85311+++ b/lib/is_single_threaded.c
85312@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
85313 struct task_struct *p, *t;
85314 bool ret;
85315
85316+ if (!mm)
85317+ return true;
85318+
85319 if (atomic_read(&task->signal->live) != 1)
85320 return false;
85321
85322diff --git a/lib/kobject.c b/lib/kobject.c
85323index 4a1f33d..2f3ca75 100644
85324--- a/lib/kobject.c
85325+++ b/lib/kobject.c
85326@@ -859,9 +859,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
85327
85328
85329 static DEFINE_SPINLOCK(kobj_ns_type_lock);
85330-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
85331+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
85332
85333-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
85334+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
85335 {
85336 enum kobj_ns_type type = ops->type;
85337 int error;
85338diff --git a/lib/list_debug.c b/lib/list_debug.c
85339index c24c2f7..06e070b 100644
85340--- a/lib/list_debug.c
85341+++ b/lib/list_debug.c
85342@@ -11,7 +11,9 @@
85343 #include <linux/bug.h>
85344 #include <linux/kernel.h>
85345 #include <linux/rculist.h>
85346+#include <linux/mm.h>
85347
85348+#ifdef CONFIG_DEBUG_LIST
85349 /*
85350 * Insert a new entry between two known consecutive entries.
85351 *
85352@@ -19,21 +21,32 @@
85353 * the prev/next entries already!
85354 */
85355
85356-void __list_add(struct list_head *new,
85357- struct list_head *prev,
85358- struct list_head *next)
85359+static bool __list_add_debug(struct list_head *new,
85360+ struct list_head *prev,
85361+ struct list_head *next)
85362 {
85363- WARN(next->prev != prev,
85364+ if (WARN(next->prev != prev,
85365 "list_add corruption. next->prev should be "
85366 "prev (%p), but was %p. (next=%p).\n",
85367- prev, next->prev, next);
85368- WARN(prev->next != next,
85369+ prev, next->prev, next) ||
85370+ WARN(prev->next != next,
85371 "list_add corruption. prev->next should be "
85372 "next (%p), but was %p. (prev=%p).\n",
85373- next, prev->next, prev);
85374- WARN(new == prev || new == next,
85375- "list_add double add: new=%p, prev=%p, next=%p.\n",
85376- new, prev, next);
85377+ next, prev->next, prev) ||
85378+ WARN(new == prev || new == next,
85379+ "list_add double add: new=%p, prev=%p, next=%p.\n",
85380+ new, prev, next))
85381+ return false;
85382+ return true;
85383+}
85384+
85385+void __list_add(struct list_head *new,
85386+ struct list_head *prev,
85387+ struct list_head *next)
85388+{
85389+ if (!__list_add_debug(new, prev, next))
85390+ return;
85391+
85392 next->prev = new;
85393 new->next = next;
85394 new->prev = prev;
85395@@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
85396 }
85397 EXPORT_SYMBOL(__list_add);
85398
85399-void __list_del_entry(struct list_head *entry)
85400+static bool __list_del_entry_debug(struct list_head *entry)
85401 {
85402 struct list_head *prev, *next;
85403
85404@@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
85405 WARN(next->prev != entry,
85406 "list_del corruption. next->prev should be %p, "
85407 "but was %p\n", entry, next->prev))
85408+ return false;
85409+ return true;
85410+}
85411+
85412+void __list_del_entry(struct list_head *entry)
85413+{
85414+ if (!__list_del_entry_debug(entry))
85415 return;
85416
85417- __list_del(prev, next);
85418+ __list_del(entry->prev, entry->next);
85419 }
85420 EXPORT_SYMBOL(__list_del_entry);
85421
85422@@ -86,15 +106,85 @@ EXPORT_SYMBOL(list_del);
85423 void __list_add_rcu(struct list_head *new,
85424 struct list_head *prev, struct list_head *next)
85425 {
85426- WARN(next->prev != prev,
85427- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
85428- prev, next->prev, next);
85429- WARN(prev->next != next,
85430- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
85431- next, prev->next, prev);
85432+ if (!__list_add_debug(new, prev, next))
85433+ return;
85434+
85435 new->next = next;
85436 new->prev = prev;
85437 rcu_assign_pointer(list_next_rcu(prev), new);
85438 next->prev = new;
85439 }
85440 EXPORT_SYMBOL(__list_add_rcu);
85441+#endif
85442+
85443+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
85444+{
85445+#ifdef CONFIG_DEBUG_LIST
85446+ if (!__list_add_debug(new, prev, next))
85447+ return;
85448+#endif
85449+
85450+ pax_open_kernel();
85451+ next->prev = new;
85452+ new->next = next;
85453+ new->prev = prev;
85454+ prev->next = new;
85455+ pax_close_kernel();
85456+}
85457+EXPORT_SYMBOL(__pax_list_add);
85458+
85459+void pax_list_del(struct list_head *entry)
85460+{
85461+#ifdef CONFIG_DEBUG_LIST
85462+ if (!__list_del_entry_debug(entry))
85463+ return;
85464+#endif
85465+
85466+ pax_open_kernel();
85467+ __list_del(entry->prev, entry->next);
85468+ entry->next = LIST_POISON1;
85469+ entry->prev = LIST_POISON2;
85470+ pax_close_kernel();
85471+}
85472+EXPORT_SYMBOL(pax_list_del);
85473+
85474+void pax_list_del_init(struct list_head *entry)
85475+{
85476+ pax_open_kernel();
85477+ __list_del(entry->prev, entry->next);
85478+ INIT_LIST_HEAD(entry);
85479+ pax_close_kernel();
85480+}
85481+EXPORT_SYMBOL(pax_list_del_init);
85482+
85483+void __pax_list_add_rcu(struct list_head *new,
85484+ struct list_head *prev, struct list_head *next)
85485+{
85486+#ifdef CONFIG_DEBUG_LIST
85487+ if (!__list_add_debug(new, prev, next))
85488+ return;
85489+#endif
85490+
85491+ pax_open_kernel();
85492+ new->next = next;
85493+ new->prev = prev;
85494+ rcu_assign_pointer(list_next_rcu(prev), new);
85495+ next->prev = new;
85496+ pax_close_kernel();
85497+}
85498+EXPORT_SYMBOL(__pax_list_add_rcu);
85499+
85500+void pax_list_del_rcu(struct list_head *entry)
85501+{
85502+#ifdef CONFIG_DEBUG_LIST
85503+ if (!__list_del_entry_debug(entry))
85504+ return;
85505+#endif
85506+
85507+ pax_open_kernel();
85508+ __list_del(entry->prev, entry->next);
85509+ entry->next = LIST_POISON1;
85510+ entry->prev = LIST_POISON2;
85511+ pax_close_kernel();
85512+}
85513+EXPORT_SYMBOL(pax_list_del_rcu);
85514diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
85515index 7deeb62..144eb47 100644
85516--- a/lib/percpu-refcount.c
85517+++ b/lib/percpu-refcount.c
85518@@ -29,7 +29,7 @@
85519 * can't hit 0 before we've added up all the percpu refs.
85520 */
85521
85522-#define PCPU_COUNT_BIAS (1U << 31)
85523+#define PCPU_COUNT_BIAS (1U << 30)
85524
85525 /**
85526 * percpu_ref_init - initialize a percpu refcount
85527diff --git a/lib/radix-tree.c b/lib/radix-tree.c
85528index e796429..6e38f9f 100644
85529--- a/lib/radix-tree.c
85530+++ b/lib/radix-tree.c
85531@@ -92,7 +92,7 @@ struct radix_tree_preload {
85532 int nr;
85533 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
85534 };
85535-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
85536+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
85537
85538 static inline void *ptr_to_indirect(void *ptr)
85539 {
85540diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
85541index bb2b201..46abaf9 100644
85542--- a/lib/strncpy_from_user.c
85543+++ b/lib/strncpy_from_user.c
85544@@ -21,7 +21,7 @@
85545 */
85546 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
85547 {
85548- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85549+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85550 long res = 0;
85551
85552 /*
85553diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
85554index a28df52..3d55877 100644
85555--- a/lib/strnlen_user.c
85556+++ b/lib/strnlen_user.c
85557@@ -26,7 +26,7 @@
85558 */
85559 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
85560 {
85561- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85562+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85563 long align, res = 0;
85564 unsigned long c;
85565
85566diff --git a/lib/swiotlb.c b/lib/swiotlb.c
85567index d23762e..e21eab2 100644
85568--- a/lib/swiotlb.c
85569+++ b/lib/swiotlb.c
85570@@ -664,7 +664,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
85571
85572 void
85573 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
85574- dma_addr_t dev_addr)
85575+ dma_addr_t dev_addr, struct dma_attrs *attrs)
85576 {
85577 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
85578
85579diff --git a/lib/usercopy.c b/lib/usercopy.c
85580index 4f5b1dd..7cab418 100644
85581--- a/lib/usercopy.c
85582+++ b/lib/usercopy.c
85583@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
85584 WARN(1, "Buffer overflow detected!\n");
85585 }
85586 EXPORT_SYMBOL(copy_from_user_overflow);
85587+
85588+void copy_to_user_overflow(void)
85589+{
85590+ WARN(1, "Buffer overflow detected!\n");
85591+}
85592+EXPORT_SYMBOL(copy_to_user_overflow);
85593diff --git a/lib/vsprintf.c b/lib/vsprintf.c
85594index 739a363..aa668d7 100644
85595--- a/lib/vsprintf.c
85596+++ b/lib/vsprintf.c
85597@@ -16,6 +16,9 @@
85598 * - scnprintf and vscnprintf
85599 */
85600
85601+#ifdef CONFIG_GRKERNSEC_HIDESYM
85602+#define __INCLUDED_BY_HIDESYM 1
85603+#endif
85604 #include <stdarg.h>
85605 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
85606 #include <linux/types.h>
85607@@ -1078,7 +1081,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
85608 return number(buf, end, *(const netdev_features_t *)addr, spec);
85609 }
85610
85611+#ifdef CONFIG_GRKERNSEC_HIDESYM
85612+int kptr_restrict __read_mostly = 2;
85613+#else
85614 int kptr_restrict __read_mostly;
85615+#endif
85616
85617 /*
85618 * Show a '%p' thing. A kernel extension is that the '%p' is followed
85619@@ -1091,6 +1098,7 @@ int kptr_restrict __read_mostly;
85620 * - 'f' For simple symbolic function names without offset
85621 * - 'S' For symbolic direct pointers with offset
85622 * - 's' For symbolic direct pointers without offset
85623+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
85624 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
85625 * - 'B' For backtraced symbolic direct pointers with offset
85626 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
85627@@ -1155,12 +1163,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85628
85629 if (!ptr && *fmt != 'K') {
85630 /*
85631- * Print (null) with the same width as a pointer so it makes
85632+ * Print (nil) with the same width as a pointer so it makes
85633 * tabular output look nice.
85634 */
85635 if (spec.field_width == -1)
85636 spec.field_width = default_width;
85637- return string(buf, end, "(null)", spec);
85638+ return string(buf, end, "(nil)", spec);
85639 }
85640
85641 switch (*fmt) {
85642@@ -1170,6 +1178,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85643 /* Fallthrough */
85644 case 'S':
85645 case 's':
85646+#ifdef CONFIG_GRKERNSEC_HIDESYM
85647+ break;
85648+#else
85649+ return symbol_string(buf, end, ptr, spec, fmt);
85650+#endif
85651+ case 'A':
85652 case 'B':
85653 return symbol_string(buf, end, ptr, spec, fmt);
85654 case 'R':
85655@@ -1225,6 +1239,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85656 va_end(va);
85657 return buf;
85658 }
85659+ case 'P':
85660+ break;
85661 case 'K':
85662 /*
85663 * %pK cannot be used in IRQ context because its test
85664@@ -1254,6 +1270,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85665 return number(buf, end,
85666 (unsigned long long) *((phys_addr_t *)ptr), spec);
85667 }
85668+
85669+#ifdef CONFIG_GRKERNSEC_HIDESYM
85670+ /* 'P' = approved pointers to copy to userland,
85671+ as in the /proc/kallsyms case, as we make it display nothing
85672+ for non-root users, and the real contents for root users
85673+ Also ignore 'K' pointers, since we force their NULLing for non-root users
85674+ above
85675+ */
85676+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
85677+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
85678+ dump_stack();
85679+ ptr = NULL;
85680+ }
85681+#endif
85682+
85683 spec.flags |= SMALL;
85684 if (spec.field_width == -1) {
85685 spec.field_width = default_width;
85686@@ -1977,11 +2008,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
85687 typeof(type) value; \
85688 if (sizeof(type) == 8) { \
85689 args = PTR_ALIGN(args, sizeof(u32)); \
85690- *(u32 *)&value = *(u32 *)args; \
85691- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
85692+ *(u32 *)&value = *(const u32 *)args; \
85693+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
85694 } else { \
85695 args = PTR_ALIGN(args, sizeof(type)); \
85696- value = *(typeof(type) *)args; \
85697+ value = *(const typeof(type) *)args; \
85698 } \
85699 args += sizeof(type); \
85700 value; \
85701@@ -2044,7 +2075,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
85702 case FORMAT_TYPE_STR: {
85703 const char *str_arg = args;
85704 args += strlen(str_arg) + 1;
85705- str = string(str, end, (char *)str_arg, spec);
85706+ str = string(str, end, str_arg, spec);
85707 break;
85708 }
85709
85710diff --git a/localversion-grsec b/localversion-grsec
85711new file mode 100644
85712index 0000000..7cd6065
85713--- /dev/null
85714+++ b/localversion-grsec
85715@@ -0,0 +1 @@
85716+-grsec
85717diff --git a/mm/Kconfig b/mm/Kconfig
85718index 6509d27..dbec5b8 100644
85719--- a/mm/Kconfig
85720+++ b/mm/Kconfig
85721@@ -317,10 +317,10 @@ config KSM
85722 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
85723
85724 config DEFAULT_MMAP_MIN_ADDR
85725- int "Low address space to protect from user allocation"
85726+ int "Low address space to protect from user allocation"
85727 depends on MMU
85728- default 4096
85729- help
85730+ default 65536
85731+ help
85732 This is the portion of low virtual memory which should be protected
85733 from userspace allocation. Keeping a user from writing to low pages
85734 can help reduce the impact of kernel NULL pointer bugs.
85735@@ -351,7 +351,7 @@ config MEMORY_FAILURE
85736
85737 config HWPOISON_INJECT
85738 tristate "HWPoison pages injector"
85739- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
85740+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
85741 select PROC_PAGE_MONITOR
85742
85743 config NOMMU_INITIAL_TRIM_EXCESS
85744diff --git a/mm/backing-dev.c b/mm/backing-dev.c
85745index e04454c..ca5be3e 100644
85746--- a/mm/backing-dev.c
85747+++ b/mm/backing-dev.c
85748@@ -12,7 +12,7 @@
85749 #include <linux/device.h>
85750 #include <trace/events/writeback.h>
85751
85752-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
85753+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
85754
85755 struct backing_dev_info default_backing_dev_info = {
85756 .name = "default",
85757@@ -522,7 +522,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
85758 return err;
85759
85760 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
85761- atomic_long_inc_return(&bdi_seq));
85762+ atomic_long_inc_return_unchecked(&bdi_seq));
85763 if (err) {
85764 bdi_destroy(bdi);
85765 return err;
85766diff --git a/mm/filemap.c b/mm/filemap.c
85767index 4b51ac1..5aa90ff 100644
85768--- a/mm/filemap.c
85769+++ b/mm/filemap.c
85770@@ -1766,7 +1766,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
85771 struct address_space *mapping = file->f_mapping;
85772
85773 if (!mapping->a_ops->readpage)
85774- return -ENOEXEC;
85775+ return -ENODEV;
85776 file_accessed(file);
85777 vma->vm_ops = &generic_file_vm_ops;
85778 return 0;
85779@@ -1948,7 +1948,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
85780
85781 while (bytes) {
85782 char __user *buf = iov->iov_base + base;
85783- int copy = min(bytes, iov->iov_len - base);
85784+ size_t copy = min(bytes, iov->iov_len - base);
85785
85786 base = 0;
85787 left = __copy_from_user_inatomic(vaddr, buf, copy);
85788@@ -1977,7 +1977,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
85789 BUG_ON(!in_atomic());
85790 kaddr = kmap_atomic(page);
85791 if (likely(i->nr_segs == 1)) {
85792- int left;
85793+ size_t left;
85794 char __user *buf = i->iov->iov_base + i->iov_offset;
85795 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
85796 copied = bytes - left;
85797@@ -2005,7 +2005,7 @@ size_t iov_iter_copy_from_user(struct page *page,
85798
85799 kaddr = kmap(page);
85800 if (likely(i->nr_segs == 1)) {
85801- int left;
85802+ size_t left;
85803 char __user *buf = i->iov->iov_base + i->iov_offset;
85804 left = __copy_from_user(kaddr + offset, buf, bytes);
85805 copied = bytes - left;
85806@@ -2035,7 +2035,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
85807 * zero-length segments (without overruning the iovec).
85808 */
85809 while (bytes || unlikely(i->count && !iov->iov_len)) {
85810- int copy;
85811+ size_t copy;
85812
85813 copy = min(bytes, iov->iov_len - base);
85814 BUG_ON(!i->count || i->count < copy);
85815@@ -2106,6 +2106,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
85816 *pos = i_size_read(inode);
85817
85818 if (limit != RLIM_INFINITY) {
85819+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
85820 if (*pos >= limit) {
85821 send_sig(SIGXFSZ, current, 0);
85822 return -EFBIG;
85823diff --git a/mm/fremap.c b/mm/fremap.c
85824index 5bff081..d8189a9 100644
85825--- a/mm/fremap.c
85826+++ b/mm/fremap.c
85827@@ -163,6 +163,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
85828 retry:
85829 vma = find_vma(mm, start);
85830
85831+#ifdef CONFIG_PAX_SEGMEXEC
85832+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
85833+ goto out;
85834+#endif
85835+
85836 /*
85837 * Make sure the vma is shared, that it supports prefaulting,
85838 * and that the remapped range is valid and fully within
85839diff --git a/mm/highmem.c b/mm/highmem.c
85840index b32b70c..e512eb0 100644
85841--- a/mm/highmem.c
85842+++ b/mm/highmem.c
85843@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
85844 * So no dangers, even with speculative execution.
85845 */
85846 page = pte_page(pkmap_page_table[i]);
85847+ pax_open_kernel();
85848 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
85849-
85850+ pax_close_kernel();
85851 set_page_address(page, NULL);
85852 need_flush = 1;
85853 }
85854@@ -198,9 +199,11 @@ start:
85855 }
85856 }
85857 vaddr = PKMAP_ADDR(last_pkmap_nr);
85858+
85859+ pax_open_kernel();
85860 set_pte_at(&init_mm, vaddr,
85861 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
85862-
85863+ pax_close_kernel();
85864 pkmap_count[last_pkmap_nr] = 1;
85865 set_page_address(page, (void *)vaddr);
85866
85867diff --git a/mm/hugetlb.c b/mm/hugetlb.c
85868index b60f330..ee7de7e 100644
85869--- a/mm/hugetlb.c
85870+++ b/mm/hugetlb.c
85871@@ -2022,15 +2022,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
85872 struct hstate *h = &default_hstate;
85873 unsigned long tmp;
85874 int ret;
85875+ ctl_table_no_const hugetlb_table;
85876
85877 tmp = h->max_huge_pages;
85878
85879 if (write && h->order >= MAX_ORDER)
85880 return -EINVAL;
85881
85882- table->data = &tmp;
85883- table->maxlen = sizeof(unsigned long);
85884- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
85885+ hugetlb_table = *table;
85886+ hugetlb_table.data = &tmp;
85887+ hugetlb_table.maxlen = sizeof(unsigned long);
85888+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
85889 if (ret)
85890 goto out;
85891
85892@@ -2087,15 +2089,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
85893 struct hstate *h = &default_hstate;
85894 unsigned long tmp;
85895 int ret;
85896+ ctl_table_no_const hugetlb_table;
85897
85898 tmp = h->nr_overcommit_huge_pages;
85899
85900 if (write && h->order >= MAX_ORDER)
85901 return -EINVAL;
85902
85903- table->data = &tmp;
85904- table->maxlen = sizeof(unsigned long);
85905- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
85906+ hugetlb_table = *table;
85907+ hugetlb_table.data = &tmp;
85908+ hugetlb_table.maxlen = sizeof(unsigned long);
85909+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
85910 if (ret)
85911 goto out;
85912
85913@@ -2545,6 +2549,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
85914 return 1;
85915 }
85916
85917+#ifdef CONFIG_PAX_SEGMEXEC
85918+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
85919+{
85920+ struct mm_struct *mm = vma->vm_mm;
85921+ struct vm_area_struct *vma_m;
85922+ unsigned long address_m;
85923+ pte_t *ptep_m;
85924+
85925+ vma_m = pax_find_mirror_vma(vma);
85926+ if (!vma_m)
85927+ return;
85928+
85929+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
85930+ address_m = address + SEGMEXEC_TASK_SIZE;
85931+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
85932+ get_page(page_m);
85933+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
85934+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
85935+}
85936+#endif
85937+
85938 /*
85939 * Hugetlb_cow() should be called with page lock of the original hugepage held.
85940 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
85941@@ -2663,6 +2688,11 @@ retry_avoidcopy:
85942 make_huge_pte(vma, new_page, 1));
85943 page_remove_rmap(old_page);
85944 hugepage_add_new_anon_rmap(new_page, vma, address);
85945+
85946+#ifdef CONFIG_PAX_SEGMEXEC
85947+ pax_mirror_huge_pte(vma, address, new_page);
85948+#endif
85949+
85950 /* Make the old page be freed below */
85951 new_page = old_page;
85952 }
85953@@ -2821,6 +2851,10 @@ retry:
85954 && (vma->vm_flags & VM_SHARED)));
85955 set_huge_pte_at(mm, address, ptep, new_pte);
85956
85957+#ifdef CONFIG_PAX_SEGMEXEC
85958+ pax_mirror_huge_pte(vma, address, page);
85959+#endif
85960+
85961 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
85962 /* Optimization, do the COW without a second fault */
85963 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
85964@@ -2850,6 +2884,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
85965 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
85966 struct hstate *h = hstate_vma(vma);
85967
85968+#ifdef CONFIG_PAX_SEGMEXEC
85969+ struct vm_area_struct *vma_m;
85970+#endif
85971+
85972 address &= huge_page_mask(h);
85973
85974 ptep = huge_pte_offset(mm, address);
85975@@ -2863,6 +2901,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
85976 VM_FAULT_SET_HINDEX(hstate_index(h));
85977 }
85978
85979+#ifdef CONFIG_PAX_SEGMEXEC
85980+ vma_m = pax_find_mirror_vma(vma);
85981+ if (vma_m) {
85982+ unsigned long address_m;
85983+
85984+ if (vma->vm_start > vma_m->vm_start) {
85985+ address_m = address;
85986+ address -= SEGMEXEC_TASK_SIZE;
85987+ vma = vma_m;
85988+ h = hstate_vma(vma);
85989+ } else
85990+ address_m = address + SEGMEXEC_TASK_SIZE;
85991+
85992+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
85993+ return VM_FAULT_OOM;
85994+ address_m &= HPAGE_MASK;
85995+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
85996+ }
85997+#endif
85998+
85999 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
86000 if (!ptep)
86001 return VM_FAULT_OOM;
86002diff --git a/mm/internal.h b/mm/internal.h
86003index 4390ac6..fc60373c 100644
86004--- a/mm/internal.h
86005+++ b/mm/internal.h
86006@@ -95,6 +95,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
86007 * in mm/page_alloc.c
86008 */
86009 extern void __free_pages_bootmem(struct page *page, unsigned int order);
86010+extern void free_compound_page(struct page *page);
86011 extern void prep_compound_page(struct page *page, unsigned long order);
86012 #ifdef CONFIG_MEMORY_FAILURE
86013 extern bool is_free_buddy_page(struct page *page);
86014@@ -350,7 +351,7 @@ extern u32 hwpoison_filter_enable;
86015
86016 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
86017 unsigned long, unsigned long,
86018- unsigned long, unsigned long);
86019+ unsigned long, unsigned long) __intentional_overflow(-1);
86020
86021 extern void set_pageblock_order(void);
86022 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
86023diff --git a/mm/kmemleak.c b/mm/kmemleak.c
86024index c8d7f31..2dbeffd 100644
86025--- a/mm/kmemleak.c
86026+++ b/mm/kmemleak.c
86027@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
86028
86029 for (i = 0; i < object->trace_len; i++) {
86030 void *ptr = (void *)object->trace[i];
86031- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
86032+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
86033 }
86034 }
86035
86036@@ -1851,7 +1851,7 @@ static int __init kmemleak_late_init(void)
86037 return -ENOMEM;
86038 }
86039
86040- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
86041+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
86042 &kmemleak_fops);
86043 if (!dentry)
86044 pr_warning("Failed to create the debugfs kmemleak file\n");
86045diff --git a/mm/maccess.c b/mm/maccess.c
86046index d53adf9..03a24bf 100644
86047--- a/mm/maccess.c
86048+++ b/mm/maccess.c
86049@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
86050 set_fs(KERNEL_DS);
86051 pagefault_disable();
86052 ret = __copy_from_user_inatomic(dst,
86053- (__force const void __user *)src, size);
86054+ (const void __force_user *)src, size);
86055 pagefault_enable();
86056 set_fs(old_fs);
86057
86058@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
86059
86060 set_fs(KERNEL_DS);
86061 pagefault_disable();
86062- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
86063+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
86064 pagefault_enable();
86065 set_fs(old_fs);
86066
86067diff --git a/mm/madvise.c b/mm/madvise.c
86068index 7055883..aafb1ed 100644
86069--- a/mm/madvise.c
86070+++ b/mm/madvise.c
86071@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
86072 pgoff_t pgoff;
86073 unsigned long new_flags = vma->vm_flags;
86074
86075+#ifdef CONFIG_PAX_SEGMEXEC
86076+ struct vm_area_struct *vma_m;
86077+#endif
86078+
86079 switch (behavior) {
86080 case MADV_NORMAL:
86081 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
86082@@ -126,6 +130,13 @@ success:
86083 /*
86084 * vm_flags is protected by the mmap_sem held in write mode.
86085 */
86086+
86087+#ifdef CONFIG_PAX_SEGMEXEC
86088+ vma_m = pax_find_mirror_vma(vma);
86089+ if (vma_m)
86090+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
86091+#endif
86092+
86093 vma->vm_flags = new_flags;
86094
86095 out:
86096@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
86097 struct vm_area_struct ** prev,
86098 unsigned long start, unsigned long end)
86099 {
86100+
86101+#ifdef CONFIG_PAX_SEGMEXEC
86102+ struct vm_area_struct *vma_m;
86103+#endif
86104+
86105 *prev = vma;
86106 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
86107 return -EINVAL;
86108@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
86109 zap_page_range(vma, start, end - start, &details);
86110 } else
86111 zap_page_range(vma, start, end - start, NULL);
86112+
86113+#ifdef CONFIG_PAX_SEGMEXEC
86114+ vma_m = pax_find_mirror_vma(vma);
86115+ if (vma_m) {
86116+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
86117+ struct zap_details details = {
86118+ .nonlinear_vma = vma_m,
86119+ .last_index = ULONG_MAX,
86120+ };
86121+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
86122+ } else
86123+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
86124+ }
86125+#endif
86126+
86127 return 0;
86128 }
86129
86130@@ -485,6 +516,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
86131 if (end < start)
86132 return error;
86133
86134+#ifdef CONFIG_PAX_SEGMEXEC
86135+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
86136+ if (end > SEGMEXEC_TASK_SIZE)
86137+ return error;
86138+ } else
86139+#endif
86140+
86141+ if (end > TASK_SIZE)
86142+ return error;
86143+
86144 error = 0;
86145 if (end == start)
86146 return error;
86147diff --git a/mm/memcontrol.c b/mm/memcontrol.c
86148index aa44621..99011b3 100644
86149--- a/mm/memcontrol.c
86150+++ b/mm/memcontrol.c
86151@@ -2772,6 +2772,8 @@ done:
86152 return 0;
86153 nomem:
86154 *ptr = NULL;
86155+ if (gfp_mask & __GFP_NOFAIL)
86156+ return 0;
86157 return -ENOMEM;
86158 bypass:
86159 *ptr = root_mem_cgroup;
86160diff --git a/mm/memory-failure.c b/mm/memory-failure.c
86161index 2c13aa7..64cbc3f 100644
86162--- a/mm/memory-failure.c
86163+++ b/mm/memory-failure.c
86164@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
86165
86166 int sysctl_memory_failure_recovery __read_mostly = 1;
86167
86168-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
86169+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
86170
86171 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
86172
86173@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
86174 pfn, t->comm, t->pid);
86175 si.si_signo = SIGBUS;
86176 si.si_errno = 0;
86177- si.si_addr = (void *)addr;
86178+ si.si_addr = (void __user *)addr;
86179 #ifdef __ARCH_SI_TRAPNO
86180 si.si_trapno = trapno;
86181 #endif
86182@@ -760,7 +760,7 @@ static struct page_state {
86183 unsigned long res;
86184 char *msg;
86185 int (*action)(struct page *p, unsigned long pfn);
86186-} error_states[] = {
86187+} __do_const error_states[] = {
86188 { reserved, reserved, "reserved kernel", me_kernel },
86189 /*
86190 * free pages are specially detected outside this table:
86191@@ -1051,7 +1051,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
86192 nr_pages = 1 << compound_order(hpage);
86193 else /* normal page or thp */
86194 nr_pages = 1;
86195- atomic_long_add(nr_pages, &num_poisoned_pages);
86196+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
86197
86198 /*
86199 * We need/can do nothing about count=0 pages.
86200@@ -1081,7 +1081,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
86201 if (!PageHWPoison(hpage)
86202 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
86203 || (p != hpage && TestSetPageHWPoison(hpage))) {
86204- atomic_long_sub(nr_pages, &num_poisoned_pages);
86205+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
86206 return 0;
86207 }
86208 set_page_hwpoison_huge_page(hpage);
86209@@ -1148,7 +1148,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
86210 }
86211 if (hwpoison_filter(p)) {
86212 if (TestClearPageHWPoison(p))
86213- atomic_long_sub(nr_pages, &num_poisoned_pages);
86214+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
86215 unlock_page(hpage);
86216 put_page(hpage);
86217 return 0;
86218@@ -1350,7 +1350,7 @@ int unpoison_memory(unsigned long pfn)
86219 return 0;
86220 }
86221 if (TestClearPageHWPoison(p))
86222- atomic_long_sub(nr_pages, &num_poisoned_pages);
86223+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
86224 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
86225 return 0;
86226 }
86227@@ -1364,7 +1364,7 @@ int unpoison_memory(unsigned long pfn)
86228 */
86229 if (TestClearPageHWPoison(page)) {
86230 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
86231- atomic_long_sub(nr_pages, &num_poisoned_pages);
86232+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
86233 freeit = 1;
86234 if (PageHuge(page))
86235 clear_page_hwpoison_huge_page(page);
86236@@ -1491,7 +1491,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
86237 } else {
86238 set_page_hwpoison_huge_page(hpage);
86239 dequeue_hwpoisoned_huge_page(hpage);
86240- atomic_long_add(1 << compound_trans_order(hpage),
86241+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
86242 &num_poisoned_pages);
86243 }
86244 return ret;
86245@@ -1551,11 +1551,11 @@ int soft_offline_page(struct page *page, int flags)
86246 if (PageHuge(page)) {
86247 set_page_hwpoison_huge_page(hpage);
86248 dequeue_hwpoisoned_huge_page(hpage);
86249- atomic_long_add(1 << compound_trans_order(hpage),
86250+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
86251 &num_poisoned_pages);
86252 } else {
86253 SetPageHWPoison(page);
86254- atomic_long_inc(&num_poisoned_pages);
86255+ atomic_long_inc_unchecked(&num_poisoned_pages);
86256 }
86257 }
86258 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
86259@@ -1595,7 +1595,7 @@ static int __soft_offline_page(struct page *page, int flags)
86260 put_page(page);
86261 pr_info("soft_offline: %#lx: invalidated\n", pfn);
86262 SetPageHWPoison(page);
86263- atomic_long_inc(&num_poisoned_pages);
86264+ atomic_long_inc_unchecked(&num_poisoned_pages);
86265 return 0;
86266 }
86267
86268@@ -1640,7 +1640,7 @@ static int __soft_offline_page(struct page *page, int flags)
86269 if (!is_free_buddy_page(page))
86270 pr_info("soft offline: %#lx: page leaked\n",
86271 pfn);
86272- atomic_long_inc(&num_poisoned_pages);
86273+ atomic_long_inc_unchecked(&num_poisoned_pages);
86274 }
86275 } else {
86276 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
86277diff --git a/mm/memory.c b/mm/memory.c
86278index af84bc0..2ed0816 100644
86279--- a/mm/memory.c
86280+++ b/mm/memory.c
86281@@ -426,6 +426,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
86282 free_pte_range(tlb, pmd, addr);
86283 } while (pmd++, addr = next, addr != end);
86284
86285+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
86286 start &= PUD_MASK;
86287 if (start < floor)
86288 return;
86289@@ -440,6 +441,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
86290 pmd = pmd_offset(pud, start);
86291 pud_clear(pud);
86292 pmd_free_tlb(tlb, pmd, start);
86293+#endif
86294+
86295 }
86296
86297 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
86298@@ -459,6 +462,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
86299 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
86300 } while (pud++, addr = next, addr != end);
86301
86302+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
86303 start &= PGDIR_MASK;
86304 if (start < floor)
86305 return;
86306@@ -473,6 +477,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
86307 pud = pud_offset(pgd, start);
86308 pgd_clear(pgd);
86309 pud_free_tlb(tlb, pud, start);
86310+#endif
86311+
86312 }
86313
86314 /*
86315@@ -1645,12 +1651,6 @@ no_page_table:
86316 return page;
86317 }
86318
86319-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
86320-{
86321- return stack_guard_page_start(vma, addr) ||
86322- stack_guard_page_end(vma, addr+PAGE_SIZE);
86323-}
86324-
86325 /**
86326 * __get_user_pages() - pin user pages in memory
86327 * @tsk: task_struct of target task
86328@@ -1737,10 +1737,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
86329
86330 i = 0;
86331
86332- do {
86333+ while (nr_pages) {
86334 struct vm_area_struct *vma;
86335
86336- vma = find_extend_vma(mm, start);
86337+ vma = find_vma(mm, start);
86338 if (!vma && in_gate_area(mm, start)) {
86339 unsigned long pg = start & PAGE_MASK;
86340 pgd_t *pgd;
86341@@ -1789,7 +1789,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
86342 goto next_page;
86343 }
86344
86345- if (!vma ||
86346+ if (!vma || start < vma->vm_start ||
86347 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
86348 !(vm_flags & vma->vm_flags))
86349 return i ? : -EFAULT;
86350@@ -1818,11 +1818,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
86351 int ret;
86352 unsigned int fault_flags = 0;
86353
86354- /* For mlock, just skip the stack guard page. */
86355- if (foll_flags & FOLL_MLOCK) {
86356- if (stack_guard_page(vma, start))
86357- goto next_page;
86358- }
86359 if (foll_flags & FOLL_WRITE)
86360 fault_flags |= FAULT_FLAG_WRITE;
86361 if (nonblocking)
86362@@ -1902,7 +1897,7 @@ next_page:
86363 start += page_increm * PAGE_SIZE;
86364 nr_pages -= page_increm;
86365 } while (nr_pages && start < vma->vm_end);
86366- } while (nr_pages);
86367+ }
86368 return i;
86369 }
86370 EXPORT_SYMBOL(__get_user_pages);
86371@@ -2109,6 +2104,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
86372 page_add_file_rmap(page);
86373 set_pte_at(mm, addr, pte, mk_pte(page, prot));
86374
86375+#ifdef CONFIG_PAX_SEGMEXEC
86376+ pax_mirror_file_pte(vma, addr, page, ptl);
86377+#endif
86378+
86379 retval = 0;
86380 pte_unmap_unlock(pte, ptl);
86381 return retval;
86382@@ -2153,9 +2152,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
86383 if (!page_count(page))
86384 return -EINVAL;
86385 if (!(vma->vm_flags & VM_MIXEDMAP)) {
86386+
86387+#ifdef CONFIG_PAX_SEGMEXEC
86388+ struct vm_area_struct *vma_m;
86389+#endif
86390+
86391 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
86392 BUG_ON(vma->vm_flags & VM_PFNMAP);
86393 vma->vm_flags |= VM_MIXEDMAP;
86394+
86395+#ifdef CONFIG_PAX_SEGMEXEC
86396+ vma_m = pax_find_mirror_vma(vma);
86397+ if (vma_m)
86398+ vma_m->vm_flags |= VM_MIXEDMAP;
86399+#endif
86400+
86401 }
86402 return insert_page(vma, addr, page, vma->vm_page_prot);
86403 }
86404@@ -2238,6 +2249,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
86405 unsigned long pfn)
86406 {
86407 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
86408+ BUG_ON(vma->vm_mirror);
86409
86410 if (addr < vma->vm_start || addr >= vma->vm_end)
86411 return -EFAULT;
86412@@ -2485,7 +2497,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
86413
86414 BUG_ON(pud_huge(*pud));
86415
86416- pmd = pmd_alloc(mm, pud, addr);
86417+ pmd = (mm == &init_mm) ?
86418+ pmd_alloc_kernel(mm, pud, addr) :
86419+ pmd_alloc(mm, pud, addr);
86420 if (!pmd)
86421 return -ENOMEM;
86422 do {
86423@@ -2505,7 +2519,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
86424 unsigned long next;
86425 int err;
86426
86427- pud = pud_alloc(mm, pgd, addr);
86428+ pud = (mm == &init_mm) ?
86429+ pud_alloc_kernel(mm, pgd, addr) :
86430+ pud_alloc(mm, pgd, addr);
86431 if (!pud)
86432 return -ENOMEM;
86433 do {
86434@@ -2593,6 +2609,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
86435 copy_user_highpage(dst, src, va, vma);
86436 }
86437
86438+#ifdef CONFIG_PAX_SEGMEXEC
86439+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
86440+{
86441+ struct mm_struct *mm = vma->vm_mm;
86442+ spinlock_t *ptl;
86443+ pte_t *pte, entry;
86444+
86445+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
86446+ entry = *pte;
86447+ if (!pte_present(entry)) {
86448+ if (!pte_none(entry)) {
86449+ BUG_ON(pte_file(entry));
86450+ free_swap_and_cache(pte_to_swp_entry(entry));
86451+ pte_clear_not_present_full(mm, address, pte, 0);
86452+ }
86453+ } else {
86454+ struct page *page;
86455+
86456+ flush_cache_page(vma, address, pte_pfn(entry));
86457+ entry = ptep_clear_flush(vma, address, pte);
86458+ BUG_ON(pte_dirty(entry));
86459+ page = vm_normal_page(vma, address, entry);
86460+ if (page) {
86461+ update_hiwater_rss(mm);
86462+ if (PageAnon(page))
86463+ dec_mm_counter_fast(mm, MM_ANONPAGES);
86464+ else
86465+ dec_mm_counter_fast(mm, MM_FILEPAGES);
86466+ page_remove_rmap(page);
86467+ page_cache_release(page);
86468+ }
86469+ }
86470+ pte_unmap_unlock(pte, ptl);
86471+}
86472+
86473+/* PaX: if vma is mirrored, synchronize the mirror's PTE
86474+ *
86475+ * the ptl of the lower mapped page is held on entry and is not released on exit
86476+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
86477+ */
86478+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
86479+{
86480+ struct mm_struct *mm = vma->vm_mm;
86481+ unsigned long address_m;
86482+ spinlock_t *ptl_m;
86483+ struct vm_area_struct *vma_m;
86484+ pmd_t *pmd_m;
86485+ pte_t *pte_m, entry_m;
86486+
86487+ BUG_ON(!page_m || !PageAnon(page_m));
86488+
86489+ vma_m = pax_find_mirror_vma(vma);
86490+ if (!vma_m)
86491+ return;
86492+
86493+ BUG_ON(!PageLocked(page_m));
86494+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
86495+ address_m = address + SEGMEXEC_TASK_SIZE;
86496+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
86497+ pte_m = pte_offset_map(pmd_m, address_m);
86498+ ptl_m = pte_lockptr(mm, pmd_m);
86499+ if (ptl != ptl_m) {
86500+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
86501+ if (!pte_none(*pte_m))
86502+ goto out;
86503+ }
86504+
86505+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
86506+ page_cache_get(page_m);
86507+ page_add_anon_rmap(page_m, vma_m, address_m);
86508+ inc_mm_counter_fast(mm, MM_ANONPAGES);
86509+ set_pte_at(mm, address_m, pte_m, entry_m);
86510+ update_mmu_cache(vma_m, address_m, pte_m);
86511+out:
86512+ if (ptl != ptl_m)
86513+ spin_unlock(ptl_m);
86514+ pte_unmap(pte_m);
86515+ unlock_page(page_m);
86516+}
86517+
86518+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
86519+{
86520+ struct mm_struct *mm = vma->vm_mm;
86521+ unsigned long address_m;
86522+ spinlock_t *ptl_m;
86523+ struct vm_area_struct *vma_m;
86524+ pmd_t *pmd_m;
86525+ pte_t *pte_m, entry_m;
86526+
86527+ BUG_ON(!page_m || PageAnon(page_m));
86528+
86529+ vma_m = pax_find_mirror_vma(vma);
86530+ if (!vma_m)
86531+ return;
86532+
86533+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
86534+ address_m = address + SEGMEXEC_TASK_SIZE;
86535+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
86536+ pte_m = pte_offset_map(pmd_m, address_m);
86537+ ptl_m = pte_lockptr(mm, pmd_m);
86538+ if (ptl != ptl_m) {
86539+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
86540+ if (!pte_none(*pte_m))
86541+ goto out;
86542+ }
86543+
86544+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
86545+ page_cache_get(page_m);
86546+ page_add_file_rmap(page_m);
86547+ inc_mm_counter_fast(mm, MM_FILEPAGES);
86548+ set_pte_at(mm, address_m, pte_m, entry_m);
86549+ update_mmu_cache(vma_m, address_m, pte_m);
86550+out:
86551+ if (ptl != ptl_m)
86552+ spin_unlock(ptl_m);
86553+ pte_unmap(pte_m);
86554+}
86555+
86556+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
86557+{
86558+ struct mm_struct *mm = vma->vm_mm;
86559+ unsigned long address_m;
86560+ spinlock_t *ptl_m;
86561+ struct vm_area_struct *vma_m;
86562+ pmd_t *pmd_m;
86563+ pte_t *pte_m, entry_m;
86564+
86565+ vma_m = pax_find_mirror_vma(vma);
86566+ if (!vma_m)
86567+ return;
86568+
86569+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
86570+ address_m = address + SEGMEXEC_TASK_SIZE;
86571+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
86572+ pte_m = pte_offset_map(pmd_m, address_m);
86573+ ptl_m = pte_lockptr(mm, pmd_m);
86574+ if (ptl != ptl_m) {
86575+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
86576+ if (!pte_none(*pte_m))
86577+ goto out;
86578+ }
86579+
86580+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
86581+ set_pte_at(mm, address_m, pte_m, entry_m);
86582+out:
86583+ if (ptl != ptl_m)
86584+ spin_unlock(ptl_m);
86585+ pte_unmap(pte_m);
86586+}
86587+
86588+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
86589+{
86590+ struct page *page_m;
86591+ pte_t entry;
86592+
86593+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
86594+ goto out;
86595+
86596+ entry = *pte;
86597+ page_m = vm_normal_page(vma, address, entry);
86598+ if (!page_m)
86599+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
86600+ else if (PageAnon(page_m)) {
86601+ if (pax_find_mirror_vma(vma)) {
86602+ pte_unmap_unlock(pte, ptl);
86603+ lock_page(page_m);
86604+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
86605+ if (pte_same(entry, *pte))
86606+ pax_mirror_anon_pte(vma, address, page_m, ptl);
86607+ else
86608+ unlock_page(page_m);
86609+ }
86610+ } else
86611+ pax_mirror_file_pte(vma, address, page_m, ptl);
86612+
86613+out:
86614+ pte_unmap_unlock(pte, ptl);
86615+}
86616+#endif
86617+
86618 /*
86619 * This routine handles present pages, when users try to write
86620 * to a shared page. It is done by copying the page to a new address
86621@@ -2809,6 +3005,12 @@ gotten:
86622 */
86623 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
86624 if (likely(pte_same(*page_table, orig_pte))) {
86625+
86626+#ifdef CONFIG_PAX_SEGMEXEC
86627+ if (pax_find_mirror_vma(vma))
86628+ BUG_ON(!trylock_page(new_page));
86629+#endif
86630+
86631 if (old_page) {
86632 if (!PageAnon(old_page)) {
86633 dec_mm_counter_fast(mm, MM_FILEPAGES);
86634@@ -2860,6 +3062,10 @@ gotten:
86635 page_remove_rmap(old_page);
86636 }
86637
86638+#ifdef CONFIG_PAX_SEGMEXEC
86639+ pax_mirror_anon_pte(vma, address, new_page, ptl);
86640+#endif
86641+
86642 /* Free the old page.. */
86643 new_page = old_page;
86644 ret |= VM_FAULT_WRITE;
86645@@ -3137,6 +3343,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
86646 swap_free(entry);
86647 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
86648 try_to_free_swap(page);
86649+
86650+#ifdef CONFIG_PAX_SEGMEXEC
86651+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
86652+#endif
86653+
86654 unlock_page(page);
86655 if (page != swapcache) {
86656 /*
86657@@ -3160,6 +3371,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
86658
86659 /* No need to invalidate - it was non-present before */
86660 update_mmu_cache(vma, address, page_table);
86661+
86662+#ifdef CONFIG_PAX_SEGMEXEC
86663+ pax_mirror_anon_pte(vma, address, page, ptl);
86664+#endif
86665+
86666 unlock:
86667 pte_unmap_unlock(page_table, ptl);
86668 out:
86669@@ -3179,40 +3395,6 @@ out_release:
86670 }
86671
86672 /*
86673- * This is like a special single-page "expand_{down|up}wards()",
86674- * except we must first make sure that 'address{-|+}PAGE_SIZE'
86675- * doesn't hit another vma.
86676- */
86677-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
86678-{
86679- address &= PAGE_MASK;
86680- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
86681- struct vm_area_struct *prev = vma->vm_prev;
86682-
86683- /*
86684- * Is there a mapping abutting this one below?
86685- *
86686- * That's only ok if it's the same stack mapping
86687- * that has gotten split..
86688- */
86689- if (prev && prev->vm_end == address)
86690- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
86691-
86692- expand_downwards(vma, address - PAGE_SIZE);
86693- }
86694- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
86695- struct vm_area_struct *next = vma->vm_next;
86696-
86697- /* As VM_GROWSDOWN but s/below/above/ */
86698- if (next && next->vm_start == address + PAGE_SIZE)
86699- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
86700-
86701- expand_upwards(vma, address + PAGE_SIZE);
86702- }
86703- return 0;
86704-}
86705-
86706-/*
86707 * We enter with non-exclusive mmap_sem (to exclude vma changes,
86708 * but allow concurrent faults), and pte mapped but not yet locked.
86709 * We return with mmap_sem still held, but pte unmapped and unlocked.
86710@@ -3221,27 +3403,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
86711 unsigned long address, pte_t *page_table, pmd_t *pmd,
86712 unsigned int flags)
86713 {
86714- struct page *page;
86715+ struct page *page = NULL;
86716 spinlock_t *ptl;
86717 pte_t entry;
86718
86719- pte_unmap(page_table);
86720-
86721- /* Check if we need to add a guard page to the stack */
86722- if (check_stack_guard_page(vma, address) < 0)
86723- return VM_FAULT_SIGBUS;
86724-
86725- /* Use the zero-page for reads */
86726 if (!(flags & FAULT_FLAG_WRITE)) {
86727 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
86728 vma->vm_page_prot));
86729- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
86730+ ptl = pte_lockptr(mm, pmd);
86731+ spin_lock(ptl);
86732 if (!pte_none(*page_table))
86733 goto unlock;
86734 goto setpte;
86735 }
86736
86737 /* Allocate our own private page. */
86738+ pte_unmap(page_table);
86739+
86740 if (unlikely(anon_vma_prepare(vma)))
86741 goto oom;
86742 page = alloc_zeroed_user_highpage_movable(vma, address);
86743@@ -3265,6 +3443,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
86744 if (!pte_none(*page_table))
86745 goto release;
86746
86747+#ifdef CONFIG_PAX_SEGMEXEC
86748+ if (pax_find_mirror_vma(vma))
86749+ BUG_ON(!trylock_page(page));
86750+#endif
86751+
86752 inc_mm_counter_fast(mm, MM_ANONPAGES);
86753 page_add_new_anon_rmap(page, vma, address);
86754 setpte:
86755@@ -3272,6 +3455,12 @@ setpte:
86756
86757 /* No need to invalidate - it was non-present before */
86758 update_mmu_cache(vma, address, page_table);
86759+
86760+#ifdef CONFIG_PAX_SEGMEXEC
86761+ if (page)
86762+ pax_mirror_anon_pte(vma, address, page, ptl);
86763+#endif
86764+
86765 unlock:
86766 pte_unmap_unlock(page_table, ptl);
86767 return 0;
86768@@ -3415,6 +3604,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86769 */
86770 /* Only go through if we didn't race with anybody else... */
86771 if (likely(pte_same(*page_table, orig_pte))) {
86772+
86773+#ifdef CONFIG_PAX_SEGMEXEC
86774+ if (anon && pax_find_mirror_vma(vma))
86775+ BUG_ON(!trylock_page(page));
86776+#endif
86777+
86778 flush_icache_page(vma, page);
86779 entry = mk_pte(page, vma->vm_page_prot);
86780 if (flags & FAULT_FLAG_WRITE)
86781@@ -3436,6 +3631,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86782
86783 /* no need to invalidate: a not-present page won't be cached */
86784 update_mmu_cache(vma, address, page_table);
86785+
86786+#ifdef CONFIG_PAX_SEGMEXEC
86787+ if (anon)
86788+ pax_mirror_anon_pte(vma, address, page, ptl);
86789+ else
86790+ pax_mirror_file_pte(vma, address, page, ptl);
86791+#endif
86792+
86793 } else {
86794 if (cow_page)
86795 mem_cgroup_uncharge_page(cow_page);
86796@@ -3757,6 +3960,12 @@ int handle_pte_fault(struct mm_struct *mm,
86797 if (flags & FAULT_FLAG_WRITE)
86798 flush_tlb_fix_spurious_fault(vma, address);
86799 }
86800+
86801+#ifdef CONFIG_PAX_SEGMEXEC
86802+ pax_mirror_pte(vma, address, pte, pmd, ptl);
86803+ return 0;
86804+#endif
86805+
86806 unlock:
86807 pte_unmap_unlock(pte, ptl);
86808 return 0;
86809@@ -3773,6 +3982,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86810 pmd_t *pmd;
86811 pte_t *pte;
86812
86813+#ifdef CONFIG_PAX_SEGMEXEC
86814+ struct vm_area_struct *vma_m;
86815+#endif
86816+
86817 __set_current_state(TASK_RUNNING);
86818
86819 count_vm_event(PGFAULT);
86820@@ -3784,6 +3997,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86821 if (unlikely(is_vm_hugetlb_page(vma)))
86822 return hugetlb_fault(mm, vma, address, flags);
86823
86824+#ifdef CONFIG_PAX_SEGMEXEC
86825+ vma_m = pax_find_mirror_vma(vma);
86826+ if (vma_m) {
86827+ unsigned long address_m;
86828+ pgd_t *pgd_m;
86829+ pud_t *pud_m;
86830+ pmd_t *pmd_m;
86831+
86832+ if (vma->vm_start > vma_m->vm_start) {
86833+ address_m = address;
86834+ address -= SEGMEXEC_TASK_SIZE;
86835+ vma = vma_m;
86836+ } else
86837+ address_m = address + SEGMEXEC_TASK_SIZE;
86838+
86839+ pgd_m = pgd_offset(mm, address_m);
86840+ pud_m = pud_alloc(mm, pgd_m, address_m);
86841+ if (!pud_m)
86842+ return VM_FAULT_OOM;
86843+ pmd_m = pmd_alloc(mm, pud_m, address_m);
86844+ if (!pmd_m)
86845+ return VM_FAULT_OOM;
86846+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
86847+ return VM_FAULT_OOM;
86848+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
86849+ }
86850+#endif
86851+
86852 retry:
86853 pgd = pgd_offset(mm, address);
86854 pud = pud_alloc(mm, pgd, address);
86855@@ -3882,6 +4123,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
86856 spin_unlock(&mm->page_table_lock);
86857 return 0;
86858 }
86859+
86860+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
86861+{
86862+ pud_t *new = pud_alloc_one(mm, address);
86863+ if (!new)
86864+ return -ENOMEM;
86865+
86866+ smp_wmb(); /* See comment in __pte_alloc */
86867+
86868+ spin_lock(&mm->page_table_lock);
86869+ if (pgd_present(*pgd)) /* Another has populated it */
86870+ pud_free(mm, new);
86871+ else
86872+ pgd_populate_kernel(mm, pgd, new);
86873+ spin_unlock(&mm->page_table_lock);
86874+ return 0;
86875+}
86876 #endif /* __PAGETABLE_PUD_FOLDED */
86877
86878 #ifndef __PAGETABLE_PMD_FOLDED
86879@@ -3912,6 +4170,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
86880 spin_unlock(&mm->page_table_lock);
86881 return 0;
86882 }
86883+
86884+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
86885+{
86886+ pmd_t *new = pmd_alloc_one(mm, address);
86887+ if (!new)
86888+ return -ENOMEM;
86889+
86890+ smp_wmb(); /* See comment in __pte_alloc */
86891+
86892+ spin_lock(&mm->page_table_lock);
86893+#ifndef __ARCH_HAS_4LEVEL_HACK
86894+ if (pud_present(*pud)) /* Another has populated it */
86895+ pmd_free(mm, new);
86896+ else
86897+ pud_populate_kernel(mm, pud, new);
86898+#else
86899+ if (pgd_present(*pud)) /* Another has populated it */
86900+ pmd_free(mm, new);
86901+ else
86902+ pgd_populate_kernel(mm, pud, new);
86903+#endif /* __ARCH_HAS_4LEVEL_HACK */
86904+ spin_unlock(&mm->page_table_lock);
86905+ return 0;
86906+}
86907 #endif /* __PAGETABLE_PMD_FOLDED */
86908
86909 #if !defined(__HAVE_ARCH_GATE_AREA)
86910@@ -3925,7 +4207,7 @@ static int __init gate_vma_init(void)
86911 gate_vma.vm_start = FIXADDR_USER_START;
86912 gate_vma.vm_end = FIXADDR_USER_END;
86913 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
86914- gate_vma.vm_page_prot = __P101;
86915+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
86916
86917 return 0;
86918 }
86919@@ -4059,8 +4341,8 @@ out:
86920 return ret;
86921 }
86922
86923-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
86924- void *buf, int len, int write)
86925+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
86926+ void *buf, size_t len, int write)
86927 {
86928 resource_size_t phys_addr;
86929 unsigned long prot = 0;
86930@@ -4085,8 +4367,8 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
86931 * Access another process' address space as given in mm. If non-NULL, use the
86932 * given task for page fault accounting.
86933 */
86934-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
86935- unsigned long addr, void *buf, int len, int write)
86936+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
86937+ unsigned long addr, void *buf, size_t len, int write)
86938 {
86939 struct vm_area_struct *vma;
86940 void *old_buf = buf;
86941@@ -4094,7 +4376,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
86942 down_read(&mm->mmap_sem);
86943 /* ignore errors, just check how much was successfully transferred */
86944 while (len) {
86945- int bytes, ret, offset;
86946+ ssize_t bytes, ret, offset;
86947 void *maddr;
86948 struct page *page = NULL;
86949
86950@@ -4153,8 +4435,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
86951 *
86952 * The caller must hold a reference on @mm.
86953 */
86954-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
86955- void *buf, int len, int write)
86956+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
86957+ void *buf, size_t len, int write)
86958 {
86959 return __access_remote_vm(NULL, mm, addr, buf, len, write);
86960 }
86961@@ -4164,11 +4446,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
86962 * Source/target buffer must be kernel space,
86963 * Do not walk the page table directly, use get_user_pages
86964 */
86965-int access_process_vm(struct task_struct *tsk, unsigned long addr,
86966- void *buf, int len, int write)
86967+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
86968+ void *buf, size_t len, int write)
86969 {
86970 struct mm_struct *mm;
86971- int ret;
86972+ ssize_t ret;
86973
86974 mm = get_task_mm(tsk);
86975 if (!mm)
86976diff --git a/mm/mempolicy.c b/mm/mempolicy.c
86977index 4baf12e..5497066 100644
86978--- a/mm/mempolicy.c
86979+++ b/mm/mempolicy.c
86980@@ -708,6 +708,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
86981 unsigned long vmstart;
86982 unsigned long vmend;
86983
86984+#ifdef CONFIG_PAX_SEGMEXEC
86985+ struct vm_area_struct *vma_m;
86986+#endif
86987+
86988 vma = find_vma(mm, start);
86989 if (!vma || vma->vm_start > start)
86990 return -EFAULT;
86991@@ -751,6 +755,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
86992 err = vma_replace_policy(vma, new_pol);
86993 if (err)
86994 goto out;
86995+
86996+#ifdef CONFIG_PAX_SEGMEXEC
86997+ vma_m = pax_find_mirror_vma(vma);
86998+ if (vma_m) {
86999+ err = vma_replace_policy(vma_m, new_pol);
87000+ if (err)
87001+ goto out;
87002+ }
87003+#endif
87004+
87005 }
87006
87007 out:
87008@@ -1206,6 +1220,17 @@ static long do_mbind(unsigned long start, unsigned long len,
87009
87010 if (end < start)
87011 return -EINVAL;
87012+
87013+#ifdef CONFIG_PAX_SEGMEXEC
87014+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
87015+ if (end > SEGMEXEC_TASK_SIZE)
87016+ return -EINVAL;
87017+ } else
87018+#endif
87019+
87020+ if (end > TASK_SIZE)
87021+ return -EINVAL;
87022+
87023 if (end == start)
87024 return 0;
87025
87026@@ -1434,8 +1459,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
87027 */
87028 tcred = __task_cred(task);
87029 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
87030- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
87031- !capable(CAP_SYS_NICE)) {
87032+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
87033 rcu_read_unlock();
87034 err = -EPERM;
87035 goto out_put;
87036@@ -1466,6 +1490,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
87037 goto out;
87038 }
87039
87040+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
87041+ if (mm != current->mm &&
87042+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
87043+ mmput(mm);
87044+ err = -EPERM;
87045+ goto out;
87046+ }
87047+#endif
87048+
87049 err = do_migrate_pages(mm, old, new,
87050 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
87051
87052diff --git a/mm/migrate.c b/mm/migrate.c
87053index 25ca7ca..abe1836 100644
87054--- a/mm/migrate.c
87055+++ b/mm/migrate.c
87056@@ -1399,8 +1399,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
87057 */
87058 tcred = __task_cred(task);
87059 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
87060- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
87061- !capable(CAP_SYS_NICE)) {
87062+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
87063 rcu_read_unlock();
87064 err = -EPERM;
87065 goto out;
87066diff --git a/mm/mlock.c b/mm/mlock.c
87067index 79b7cf7..37472bf 100644
87068--- a/mm/mlock.c
87069+++ b/mm/mlock.c
87070@@ -13,6 +13,7 @@
87071 #include <linux/pagemap.h>
87072 #include <linux/mempolicy.h>
87073 #include <linux/syscalls.h>
87074+#include <linux/security.h>
87075 #include <linux/sched.h>
87076 #include <linux/export.h>
87077 #include <linux/rmap.h>
87078@@ -334,7 +335,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
87079 {
87080 unsigned long nstart, end, tmp;
87081 struct vm_area_struct * vma, * prev;
87082- int error;
87083+ int error = 0;
87084
87085 VM_BUG_ON(start & ~PAGE_MASK);
87086 VM_BUG_ON(len != PAGE_ALIGN(len));
87087@@ -343,6 +344,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
87088 return -EINVAL;
87089 if (end == start)
87090 return 0;
87091+ if (end > TASK_SIZE)
87092+ return -EINVAL;
87093+
87094 vma = find_vma(current->mm, start);
87095 if (!vma || vma->vm_start > start)
87096 return -ENOMEM;
87097@@ -354,6 +358,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
87098 for (nstart = start ; ; ) {
87099 vm_flags_t newflags;
87100
87101+#ifdef CONFIG_PAX_SEGMEXEC
87102+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
87103+ break;
87104+#endif
87105+
87106 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
87107
87108 newflags = vma->vm_flags & ~VM_LOCKED;
87109@@ -466,6 +475,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
87110 lock_limit >>= PAGE_SHIFT;
87111
87112 /* check against resource limits */
87113+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
87114 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
87115 error = do_mlock(start, len, 1);
87116 up_write(&current->mm->mmap_sem);
87117@@ -500,12 +510,18 @@ static int do_mlockall(int flags)
87118 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
87119 vm_flags_t newflags;
87120
87121+#ifdef CONFIG_PAX_SEGMEXEC
87122+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
87123+ break;
87124+#endif
87125+
87126 newflags = vma->vm_flags & ~VM_LOCKED;
87127 if (flags & MCL_CURRENT)
87128 newflags |= VM_LOCKED;
87129
87130 /* Ignore errors */
87131 mlock_fixup(vma, &prev, vma->vm_start, vma->vm_end, newflags);
87132+ cond_resched();
87133 }
87134 out:
87135 return 0;
87136@@ -532,6 +548,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
87137 lock_limit >>= PAGE_SHIFT;
87138
87139 ret = -ENOMEM;
87140+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
87141 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
87142 capable(CAP_IPC_LOCK))
87143 ret = do_mlockall(flags);
87144diff --git a/mm/mmap.c b/mm/mmap.c
87145index f9c97d1..3468d3b 100644
87146--- a/mm/mmap.c
87147+++ b/mm/mmap.c
87148@@ -36,6 +36,7 @@
87149 #include <linux/sched/sysctl.h>
87150 #include <linux/notifier.h>
87151 #include <linux/memory.h>
87152+#include <linux/random.h>
87153
87154 #include <asm/uaccess.h>
87155 #include <asm/cacheflush.h>
87156@@ -52,6 +53,16 @@
87157 #define arch_rebalance_pgtables(addr, len) (addr)
87158 #endif
87159
87160+static inline void verify_mm_writelocked(struct mm_struct *mm)
87161+{
87162+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
87163+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
87164+ up_read(&mm->mmap_sem);
87165+ BUG();
87166+ }
87167+#endif
87168+}
87169+
87170 static void unmap_region(struct mm_struct *mm,
87171 struct vm_area_struct *vma, struct vm_area_struct *prev,
87172 unsigned long start, unsigned long end);
87173@@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
87174 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
87175 *
87176 */
87177-pgprot_t protection_map[16] = {
87178+pgprot_t protection_map[16] __read_only = {
87179 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
87180 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
87181 };
87182
87183-pgprot_t vm_get_page_prot(unsigned long vm_flags)
87184+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
87185 {
87186- return __pgprot(pgprot_val(protection_map[vm_flags &
87187+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
87188 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
87189 pgprot_val(arch_vm_get_page_prot(vm_flags)));
87190+
87191+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
87192+ if (!(__supported_pte_mask & _PAGE_NX) &&
87193+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
87194+ (vm_flags & (VM_READ | VM_WRITE)))
87195+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
87196+#endif
87197+
87198+ return prot;
87199 }
87200 EXPORT_SYMBOL(vm_get_page_prot);
87201
87202@@ -89,6 +109,7 @@ int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
87203 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
87204 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
87205 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
87206+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
87207 /*
87208 * Make sure vm_committed_as in one cacheline and not cacheline shared with
87209 * other variables. It can be updated by several CPUs frequently.
87210@@ -247,6 +268,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
87211 struct vm_area_struct *next = vma->vm_next;
87212
87213 might_sleep();
87214+ BUG_ON(vma->vm_mirror);
87215 if (vma->vm_ops && vma->vm_ops->close)
87216 vma->vm_ops->close(vma);
87217 if (vma->vm_file)
87218@@ -291,6 +313,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
87219 * not page aligned -Ram Gupta
87220 */
87221 rlim = rlimit(RLIMIT_DATA);
87222+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
87223 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
87224 (mm->end_data - mm->start_data) > rlim)
87225 goto out;
87226@@ -933,6 +956,12 @@ static int
87227 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
87228 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
87229 {
87230+
87231+#ifdef CONFIG_PAX_SEGMEXEC
87232+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
87233+ return 0;
87234+#endif
87235+
87236 if (is_mergeable_vma(vma, file, vm_flags) &&
87237 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
87238 if (vma->vm_pgoff == vm_pgoff)
87239@@ -952,6 +981,12 @@ static int
87240 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
87241 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
87242 {
87243+
87244+#ifdef CONFIG_PAX_SEGMEXEC
87245+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
87246+ return 0;
87247+#endif
87248+
87249 if (is_mergeable_vma(vma, file, vm_flags) &&
87250 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
87251 pgoff_t vm_pglen;
87252@@ -994,13 +1029,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
87253 struct vm_area_struct *vma_merge(struct mm_struct *mm,
87254 struct vm_area_struct *prev, unsigned long addr,
87255 unsigned long end, unsigned long vm_flags,
87256- struct anon_vma *anon_vma, struct file *file,
87257+ struct anon_vma *anon_vma, struct file *file,
87258 pgoff_t pgoff, struct mempolicy *policy)
87259 {
87260 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
87261 struct vm_area_struct *area, *next;
87262 int err;
87263
87264+#ifdef CONFIG_PAX_SEGMEXEC
87265+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
87266+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
87267+
87268+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
87269+#endif
87270+
87271 /*
87272 * We later require that vma->vm_flags == vm_flags,
87273 * so this tests vma->vm_flags & VM_SPECIAL, too.
87274@@ -1016,6 +1058,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
87275 if (next && next->vm_end == end) /* cases 6, 7, 8 */
87276 next = next->vm_next;
87277
87278+#ifdef CONFIG_PAX_SEGMEXEC
87279+ if (prev)
87280+ prev_m = pax_find_mirror_vma(prev);
87281+ if (area)
87282+ area_m = pax_find_mirror_vma(area);
87283+ if (next)
87284+ next_m = pax_find_mirror_vma(next);
87285+#endif
87286+
87287 /*
87288 * Can it merge with the predecessor?
87289 */
87290@@ -1035,9 +1086,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
87291 /* cases 1, 6 */
87292 err = vma_adjust(prev, prev->vm_start,
87293 next->vm_end, prev->vm_pgoff, NULL);
87294- } else /* cases 2, 5, 7 */
87295+
87296+#ifdef CONFIG_PAX_SEGMEXEC
87297+ if (!err && prev_m)
87298+ err = vma_adjust(prev_m, prev_m->vm_start,
87299+ next_m->vm_end, prev_m->vm_pgoff, NULL);
87300+#endif
87301+
87302+ } else { /* cases 2, 5, 7 */
87303 err = vma_adjust(prev, prev->vm_start,
87304 end, prev->vm_pgoff, NULL);
87305+
87306+#ifdef CONFIG_PAX_SEGMEXEC
87307+ if (!err && prev_m)
87308+ err = vma_adjust(prev_m, prev_m->vm_start,
87309+ end_m, prev_m->vm_pgoff, NULL);
87310+#endif
87311+
87312+ }
87313 if (err)
87314 return NULL;
87315 khugepaged_enter_vma_merge(prev);
87316@@ -1051,12 +1117,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
87317 mpol_equal(policy, vma_policy(next)) &&
87318 can_vma_merge_before(next, vm_flags,
87319 anon_vma, file, pgoff+pglen)) {
87320- if (prev && addr < prev->vm_end) /* case 4 */
87321+ if (prev && addr < prev->vm_end) { /* case 4 */
87322 err = vma_adjust(prev, prev->vm_start,
87323 addr, prev->vm_pgoff, NULL);
87324- else /* cases 3, 8 */
87325+
87326+#ifdef CONFIG_PAX_SEGMEXEC
87327+ if (!err && prev_m)
87328+ err = vma_adjust(prev_m, prev_m->vm_start,
87329+ addr_m, prev_m->vm_pgoff, NULL);
87330+#endif
87331+
87332+ } else { /* cases 3, 8 */
87333 err = vma_adjust(area, addr, next->vm_end,
87334 next->vm_pgoff - pglen, NULL);
87335+
87336+#ifdef CONFIG_PAX_SEGMEXEC
87337+ if (!err && area_m)
87338+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
87339+ next_m->vm_pgoff - pglen, NULL);
87340+#endif
87341+
87342+ }
87343 if (err)
87344 return NULL;
87345 khugepaged_enter_vma_merge(area);
87346@@ -1165,8 +1246,10 @@ none:
87347 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
87348 struct file *file, long pages)
87349 {
87350- const unsigned long stack_flags
87351- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
87352+
87353+#ifdef CONFIG_PAX_RANDMMAP
87354+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
87355+#endif
87356
87357 mm->total_vm += pages;
87358
87359@@ -1174,7 +1257,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
87360 mm->shared_vm += pages;
87361 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
87362 mm->exec_vm += pages;
87363- } else if (flags & stack_flags)
87364+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
87365 mm->stack_vm += pages;
87366 }
87367 #endif /* CONFIG_PROC_FS */
87368@@ -1213,7 +1296,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87369 * (the exception is when the underlying filesystem is noexec
87370 * mounted, in which case we dont add PROT_EXEC.)
87371 */
87372- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
87373+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
87374 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
87375 prot |= PROT_EXEC;
87376
87377@@ -1239,7 +1322,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87378 /* Obtain the address to map to. we verify (or select) it and ensure
87379 * that it represents a valid section of the address space.
87380 */
87381- addr = get_unmapped_area(file, addr, len, pgoff, flags);
87382+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
87383 if (addr & ~PAGE_MASK)
87384 return addr;
87385
87386@@ -1250,6 +1333,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87387 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
87388 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
87389
87390+#ifdef CONFIG_PAX_MPROTECT
87391+ if (mm->pax_flags & MF_PAX_MPROTECT) {
87392+
87393+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
87394+ if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
87395+ mm->binfmt->handle_mmap)
87396+ mm->binfmt->handle_mmap(file);
87397+#endif
87398+
87399+#ifndef CONFIG_PAX_MPROTECT_COMPAT
87400+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
87401+ gr_log_rwxmmap(file);
87402+
87403+#ifdef CONFIG_PAX_EMUPLT
87404+ vm_flags &= ~VM_EXEC;
87405+#else
87406+ return -EPERM;
87407+#endif
87408+
87409+ }
87410+
87411+ if (!(vm_flags & VM_EXEC))
87412+ vm_flags &= ~VM_MAYEXEC;
87413+#else
87414+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
87415+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
87416+#endif
87417+ else
87418+ vm_flags &= ~VM_MAYWRITE;
87419+ }
87420+#endif
87421+
87422+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
87423+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
87424+ vm_flags &= ~VM_PAGEEXEC;
87425+#endif
87426+
87427 if (flags & MAP_LOCKED)
87428 if (!can_do_mlock())
87429 return -EPERM;
87430@@ -1261,6 +1381,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87431 locked += mm->locked_vm;
87432 lock_limit = rlimit(RLIMIT_MEMLOCK);
87433 lock_limit >>= PAGE_SHIFT;
87434+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
87435 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
87436 return -EAGAIN;
87437 }
87438@@ -1341,6 +1462,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87439 vm_flags |= VM_NORESERVE;
87440 }
87441
87442+ if (!gr_acl_handle_mmap(file, prot))
87443+ return -EACCES;
87444+
87445 addr = mmap_region(file, addr, len, vm_flags, pgoff);
87446 if (!IS_ERR_VALUE(addr) &&
87447 ((vm_flags & VM_LOCKED) ||
87448@@ -1434,7 +1558,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
87449 vm_flags_t vm_flags = vma->vm_flags;
87450
87451 /* If it was private or non-writable, the write bit is already clear */
87452- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
87453+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
87454 return 0;
87455
87456 /* The backer wishes to know when pages are first written to? */
87457@@ -1482,7 +1606,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
87458 unsigned long charged = 0;
87459 struct inode *inode = file ? file_inode(file) : NULL;
87460
87461+#ifdef CONFIG_PAX_SEGMEXEC
87462+ struct vm_area_struct *vma_m = NULL;
87463+#endif
87464+
87465+ /*
87466+ * mm->mmap_sem is required to protect against another thread
87467+ * changing the mappings in case we sleep.
87468+ */
87469+ verify_mm_writelocked(mm);
87470+
87471 /* Check against address space limit. */
87472+
87473+#ifdef CONFIG_PAX_RANDMMAP
87474+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
87475+#endif
87476+
87477 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
87478 unsigned long nr_pages;
87479
87480@@ -1501,11 +1640,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
87481
87482 /* Clear old maps */
87483 error = -ENOMEM;
87484-munmap_back:
87485 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
87486 if (do_munmap(mm, addr, len))
87487 return -ENOMEM;
87488- goto munmap_back;
87489+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
87490 }
87491
87492 /*
87493@@ -1536,6 +1674,16 @@ munmap_back:
87494 goto unacct_error;
87495 }
87496
87497+#ifdef CONFIG_PAX_SEGMEXEC
87498+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
87499+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
87500+ if (!vma_m) {
87501+ error = -ENOMEM;
87502+ goto free_vma;
87503+ }
87504+ }
87505+#endif
87506+
87507 vma->vm_mm = mm;
87508 vma->vm_start = addr;
87509 vma->vm_end = addr + len;
87510@@ -1560,6 +1708,13 @@ munmap_back:
87511 if (error)
87512 goto unmap_and_free_vma;
87513
87514+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
87515+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
87516+ vma->vm_flags |= VM_PAGEEXEC;
87517+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
87518+ }
87519+#endif
87520+
87521 /* Can addr have changed??
87522 *
87523 * Answer: Yes, several device drivers can do it in their
87524@@ -1598,6 +1753,11 @@ munmap_back:
87525 vma_link(mm, vma, prev, rb_link, rb_parent);
87526 file = vma->vm_file;
87527
87528+#ifdef CONFIG_PAX_SEGMEXEC
87529+ if (vma_m)
87530+ BUG_ON(pax_mirror_vma(vma_m, vma));
87531+#endif
87532+
87533 /* Once vma denies write, undo our temporary denial count */
87534 if (correct_wcount)
87535 atomic_inc(&inode->i_writecount);
87536@@ -1605,6 +1765,7 @@ out:
87537 perf_event_mmap(vma);
87538
87539 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
87540+ track_exec_limit(mm, addr, addr + len, vm_flags);
87541 if (vm_flags & VM_LOCKED) {
87542 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
87543 vma == get_gate_vma(current->mm)))
87544@@ -1628,6 +1789,12 @@ unmap_and_free_vma:
87545 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
87546 charged = 0;
87547 free_vma:
87548+
87549+#ifdef CONFIG_PAX_SEGMEXEC
87550+ if (vma_m)
87551+ kmem_cache_free(vm_area_cachep, vma_m);
87552+#endif
87553+
87554 kmem_cache_free(vm_area_cachep, vma);
87555 unacct_error:
87556 if (charged)
87557@@ -1635,7 +1802,63 @@ unacct_error:
87558 return error;
87559 }
87560
87561-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
87562+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
87563+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
87564+{
87565+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
87566+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
87567+
87568+ return 0;
87569+}
87570+#endif
87571+
87572+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
87573+{
87574+ if (!vma) {
87575+#ifdef CONFIG_STACK_GROWSUP
87576+ if (addr > sysctl_heap_stack_gap)
87577+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
87578+ else
87579+ vma = find_vma(current->mm, 0);
87580+ if (vma && (vma->vm_flags & VM_GROWSUP))
87581+ return false;
87582+#endif
87583+ return true;
87584+ }
87585+
87586+ if (addr + len > vma->vm_start)
87587+ return false;
87588+
87589+ if (vma->vm_flags & VM_GROWSDOWN)
87590+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
87591+#ifdef CONFIG_STACK_GROWSUP
87592+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
87593+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
87594+#endif
87595+ else if (offset)
87596+ return offset <= vma->vm_start - addr - len;
87597+
87598+ return true;
87599+}
87600+
87601+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
87602+{
87603+ if (vma->vm_start < len)
87604+ return -ENOMEM;
87605+
87606+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
87607+ if (offset <= vma->vm_start - len)
87608+ return vma->vm_start - len - offset;
87609+ else
87610+ return -ENOMEM;
87611+ }
87612+
87613+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
87614+ return vma->vm_start - len - sysctl_heap_stack_gap;
87615+ return -ENOMEM;
87616+}
87617+
87618+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
87619 {
87620 /*
87621 * We implement the search by looking for an rbtree node that
87622@@ -1683,11 +1906,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
87623 }
87624 }
87625
87626- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
87627+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
87628 check_current:
87629 /* Check if current node has a suitable gap */
87630 if (gap_start > high_limit)
87631 return -ENOMEM;
87632+
87633+ if (gap_end - gap_start > info->threadstack_offset)
87634+ gap_start += info->threadstack_offset;
87635+ else
87636+ gap_start = gap_end;
87637+
87638+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
87639+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87640+ gap_start += sysctl_heap_stack_gap;
87641+ else
87642+ gap_start = gap_end;
87643+ }
87644+ if (vma->vm_flags & VM_GROWSDOWN) {
87645+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87646+ gap_end -= sysctl_heap_stack_gap;
87647+ else
87648+ gap_end = gap_start;
87649+ }
87650 if (gap_end >= low_limit && gap_end - gap_start >= length)
87651 goto found;
87652
87653@@ -1737,7 +1978,7 @@ found:
87654 return gap_start;
87655 }
87656
87657-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
87658+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
87659 {
87660 struct mm_struct *mm = current->mm;
87661 struct vm_area_struct *vma;
87662@@ -1791,6 +2032,24 @@ check_current:
87663 gap_end = vma->vm_start;
87664 if (gap_end < low_limit)
87665 return -ENOMEM;
87666+
87667+ if (gap_end - gap_start > info->threadstack_offset)
87668+ gap_end -= info->threadstack_offset;
87669+ else
87670+ gap_end = gap_start;
87671+
87672+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
87673+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87674+ gap_start += sysctl_heap_stack_gap;
87675+ else
87676+ gap_start = gap_end;
87677+ }
87678+ if (vma->vm_flags & VM_GROWSDOWN) {
87679+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87680+ gap_end -= sysctl_heap_stack_gap;
87681+ else
87682+ gap_end = gap_start;
87683+ }
87684 if (gap_start <= high_limit && gap_end - gap_start >= length)
87685 goto found;
87686
87687@@ -1854,6 +2113,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
87688 struct mm_struct *mm = current->mm;
87689 struct vm_area_struct *vma;
87690 struct vm_unmapped_area_info info;
87691+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
87692
87693 if (len > TASK_SIZE)
87694 return -ENOMEM;
87695@@ -1861,19 +2121,29 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
87696 if (flags & MAP_FIXED)
87697 return addr;
87698
87699+#ifdef CONFIG_PAX_RANDMMAP
87700+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
87701+#endif
87702+
87703 if (addr) {
87704 addr = PAGE_ALIGN(addr);
87705 vma = find_vma(mm, addr);
87706- if (TASK_SIZE - len >= addr &&
87707- (!vma || addr + len <= vma->vm_start))
87708+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
87709 return addr;
87710 }
87711
87712 info.flags = 0;
87713 info.length = len;
87714 info.low_limit = TASK_UNMAPPED_BASE;
87715+
87716+#ifdef CONFIG_PAX_RANDMMAP
87717+ if (mm->pax_flags & MF_PAX_RANDMMAP)
87718+ info.low_limit += mm->delta_mmap;
87719+#endif
87720+
87721 info.high_limit = TASK_SIZE;
87722 info.align_mask = 0;
87723+ info.threadstack_offset = offset;
87724 return vm_unmapped_area(&info);
87725 }
87726 #endif
87727@@ -1892,6 +2162,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
87728 struct mm_struct *mm = current->mm;
87729 unsigned long addr = addr0;
87730 struct vm_unmapped_area_info info;
87731+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
87732
87733 /* requested length too big for entire address space */
87734 if (len > TASK_SIZE)
87735@@ -1900,12 +2171,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
87736 if (flags & MAP_FIXED)
87737 return addr;
87738
87739+#ifdef CONFIG_PAX_RANDMMAP
87740+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
87741+#endif
87742+
87743 /* requesting a specific address */
87744 if (addr) {
87745 addr = PAGE_ALIGN(addr);
87746 vma = find_vma(mm, addr);
87747- if (TASK_SIZE - len >= addr &&
87748- (!vma || addr + len <= vma->vm_start))
87749+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
87750 return addr;
87751 }
87752
87753@@ -1914,6 +2188,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
87754 info.low_limit = PAGE_SIZE;
87755 info.high_limit = mm->mmap_base;
87756 info.align_mask = 0;
87757+ info.threadstack_offset = offset;
87758 addr = vm_unmapped_area(&info);
87759
87760 /*
87761@@ -1926,6 +2201,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
87762 VM_BUG_ON(addr != -ENOMEM);
87763 info.flags = 0;
87764 info.low_limit = TASK_UNMAPPED_BASE;
87765+
87766+#ifdef CONFIG_PAX_RANDMMAP
87767+ if (mm->pax_flags & MF_PAX_RANDMMAP)
87768+ info.low_limit += mm->delta_mmap;
87769+#endif
87770+
87771 info.high_limit = TASK_SIZE;
87772 addr = vm_unmapped_area(&info);
87773 }
87774@@ -2027,6 +2308,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
87775 return vma;
87776 }
87777
87778+#ifdef CONFIG_PAX_SEGMEXEC
87779+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
87780+{
87781+ struct vm_area_struct *vma_m;
87782+
87783+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
87784+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
87785+ BUG_ON(vma->vm_mirror);
87786+ return NULL;
87787+ }
87788+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
87789+ vma_m = vma->vm_mirror;
87790+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
87791+ BUG_ON(vma->vm_file != vma_m->vm_file);
87792+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
87793+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
87794+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
87795+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
87796+ return vma_m;
87797+}
87798+#endif
87799+
87800 /*
87801 * Verify that the stack growth is acceptable and
87802 * update accounting. This is shared with both the
87803@@ -2043,6 +2346,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
87804 return -ENOMEM;
87805
87806 /* Stack limit test */
87807+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
87808 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
87809 return -ENOMEM;
87810
87811@@ -2053,6 +2357,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
87812 locked = mm->locked_vm + grow;
87813 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
87814 limit >>= PAGE_SHIFT;
87815+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
87816 if (locked > limit && !capable(CAP_IPC_LOCK))
87817 return -ENOMEM;
87818 }
87819@@ -2082,37 +2387,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
87820 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
87821 * vma is the last one with address > vma->vm_end. Have to extend vma.
87822 */
87823+#ifndef CONFIG_IA64
87824+static
87825+#endif
87826 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
87827 {
87828 int error;
87829+ bool locknext;
87830
87831 if (!(vma->vm_flags & VM_GROWSUP))
87832 return -EFAULT;
87833
87834+ /* Also guard against wrapping around to address 0. */
87835+ if (address < PAGE_ALIGN(address+1))
87836+ address = PAGE_ALIGN(address+1);
87837+ else
87838+ return -ENOMEM;
87839+
87840 /*
87841 * We must make sure the anon_vma is allocated
87842 * so that the anon_vma locking is not a noop.
87843 */
87844 if (unlikely(anon_vma_prepare(vma)))
87845 return -ENOMEM;
87846+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
87847+ if (locknext && anon_vma_prepare(vma->vm_next))
87848+ return -ENOMEM;
87849 vma_lock_anon_vma(vma);
87850+ if (locknext)
87851+ vma_lock_anon_vma(vma->vm_next);
87852
87853 /*
87854 * vma->vm_start/vm_end cannot change under us because the caller
87855 * is required to hold the mmap_sem in read mode. We need the
87856- * anon_vma lock to serialize against concurrent expand_stacks.
87857- * Also guard against wrapping around to address 0.
87858+ * anon_vma locks to serialize against concurrent expand_stacks
87859+ * and expand_upwards.
87860 */
87861- if (address < PAGE_ALIGN(address+4))
87862- address = PAGE_ALIGN(address+4);
87863- else {
87864- vma_unlock_anon_vma(vma);
87865- return -ENOMEM;
87866- }
87867 error = 0;
87868
87869 /* Somebody else might have raced and expanded it already */
87870- if (address > vma->vm_end) {
87871+ 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)
87872+ error = -ENOMEM;
87873+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
87874 unsigned long size, grow;
87875
87876 size = address - vma->vm_start;
87877@@ -2147,6 +2463,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
87878 }
87879 }
87880 }
87881+ if (locknext)
87882+ vma_unlock_anon_vma(vma->vm_next);
87883 vma_unlock_anon_vma(vma);
87884 khugepaged_enter_vma_merge(vma);
87885 validate_mm(vma->vm_mm);
87886@@ -2161,6 +2479,8 @@ int expand_downwards(struct vm_area_struct *vma,
87887 unsigned long address)
87888 {
87889 int error;
87890+ bool lockprev = false;
87891+ struct vm_area_struct *prev;
87892
87893 /*
87894 * We must make sure the anon_vma is allocated
87895@@ -2174,6 +2494,15 @@ int expand_downwards(struct vm_area_struct *vma,
87896 if (error)
87897 return error;
87898
87899+ prev = vma->vm_prev;
87900+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
87901+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
87902+#endif
87903+ if (lockprev && anon_vma_prepare(prev))
87904+ return -ENOMEM;
87905+ if (lockprev)
87906+ vma_lock_anon_vma(prev);
87907+
87908 vma_lock_anon_vma(vma);
87909
87910 /*
87911@@ -2183,9 +2512,17 @@ int expand_downwards(struct vm_area_struct *vma,
87912 */
87913
87914 /* Somebody else might have raced and expanded it already */
87915- if (address < vma->vm_start) {
87916+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
87917+ error = -ENOMEM;
87918+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
87919 unsigned long size, grow;
87920
87921+#ifdef CONFIG_PAX_SEGMEXEC
87922+ struct vm_area_struct *vma_m;
87923+
87924+ vma_m = pax_find_mirror_vma(vma);
87925+#endif
87926+
87927 size = vma->vm_end - address;
87928 grow = (vma->vm_start - address) >> PAGE_SHIFT;
87929
87930@@ -2210,13 +2547,27 @@ int expand_downwards(struct vm_area_struct *vma,
87931 vma->vm_pgoff -= grow;
87932 anon_vma_interval_tree_post_update_vma(vma);
87933 vma_gap_update(vma);
87934+
87935+#ifdef CONFIG_PAX_SEGMEXEC
87936+ if (vma_m) {
87937+ anon_vma_interval_tree_pre_update_vma(vma_m);
87938+ vma_m->vm_start -= grow << PAGE_SHIFT;
87939+ vma_m->vm_pgoff -= grow;
87940+ anon_vma_interval_tree_post_update_vma(vma_m);
87941+ vma_gap_update(vma_m);
87942+ }
87943+#endif
87944+
87945 spin_unlock(&vma->vm_mm->page_table_lock);
87946
87947+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
87948 perf_event_mmap(vma);
87949 }
87950 }
87951 }
87952 vma_unlock_anon_vma(vma);
87953+ if (lockprev)
87954+ vma_unlock_anon_vma(prev);
87955 khugepaged_enter_vma_merge(vma);
87956 validate_mm(vma->vm_mm);
87957 return error;
87958@@ -2314,6 +2665,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
87959 do {
87960 long nrpages = vma_pages(vma);
87961
87962+#ifdef CONFIG_PAX_SEGMEXEC
87963+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
87964+ vma = remove_vma(vma);
87965+ continue;
87966+ }
87967+#endif
87968+
87969 if (vma->vm_flags & VM_ACCOUNT)
87970 nr_accounted += nrpages;
87971 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
87972@@ -2358,6 +2716,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
87973 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
87974 vma->vm_prev = NULL;
87975 do {
87976+
87977+#ifdef CONFIG_PAX_SEGMEXEC
87978+ if (vma->vm_mirror) {
87979+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
87980+ vma->vm_mirror->vm_mirror = NULL;
87981+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
87982+ vma->vm_mirror = NULL;
87983+ }
87984+#endif
87985+
87986 vma_rb_erase(vma, &mm->mm_rb);
87987 mm->map_count--;
87988 tail_vma = vma;
87989@@ -2384,14 +2752,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
87990 struct vm_area_struct *new;
87991 int err = -ENOMEM;
87992
87993+#ifdef CONFIG_PAX_SEGMEXEC
87994+ struct vm_area_struct *vma_m, *new_m = NULL;
87995+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
87996+#endif
87997+
87998 if (is_vm_hugetlb_page(vma) && (addr &
87999 ~(huge_page_mask(hstate_vma(vma)))))
88000 return -EINVAL;
88001
88002+#ifdef CONFIG_PAX_SEGMEXEC
88003+ vma_m = pax_find_mirror_vma(vma);
88004+#endif
88005+
88006 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
88007 if (!new)
88008 goto out_err;
88009
88010+#ifdef CONFIG_PAX_SEGMEXEC
88011+ if (vma_m) {
88012+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
88013+ if (!new_m) {
88014+ kmem_cache_free(vm_area_cachep, new);
88015+ goto out_err;
88016+ }
88017+ }
88018+#endif
88019+
88020 /* most fields are the same, copy all, and then fixup */
88021 *new = *vma;
88022
88023@@ -2404,6 +2791,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88024 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
88025 }
88026
88027+#ifdef CONFIG_PAX_SEGMEXEC
88028+ if (vma_m) {
88029+ *new_m = *vma_m;
88030+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
88031+ new_m->vm_mirror = new;
88032+ new->vm_mirror = new_m;
88033+
88034+ if (new_below)
88035+ new_m->vm_end = addr_m;
88036+ else {
88037+ new_m->vm_start = addr_m;
88038+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
88039+ }
88040+ }
88041+#endif
88042+
88043 pol = mpol_dup(vma_policy(vma));
88044 if (IS_ERR(pol)) {
88045 err = PTR_ERR(pol);
88046@@ -2426,6 +2829,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88047 else
88048 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
88049
88050+#ifdef CONFIG_PAX_SEGMEXEC
88051+ if (!err && vma_m) {
88052+ if (anon_vma_clone(new_m, vma_m))
88053+ goto out_free_mpol;
88054+
88055+ mpol_get(pol);
88056+ vma_set_policy(new_m, pol);
88057+
88058+ if (new_m->vm_file)
88059+ get_file(new_m->vm_file);
88060+
88061+ if (new_m->vm_ops && new_m->vm_ops->open)
88062+ new_m->vm_ops->open(new_m);
88063+
88064+ if (new_below)
88065+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
88066+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
88067+ else
88068+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
88069+
88070+ if (err) {
88071+ if (new_m->vm_ops && new_m->vm_ops->close)
88072+ new_m->vm_ops->close(new_m);
88073+ if (new_m->vm_file)
88074+ fput(new_m->vm_file);
88075+ mpol_put(pol);
88076+ }
88077+ }
88078+#endif
88079+
88080 /* Success. */
88081 if (!err)
88082 return 0;
88083@@ -2435,10 +2868,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88084 new->vm_ops->close(new);
88085 if (new->vm_file)
88086 fput(new->vm_file);
88087- unlink_anon_vmas(new);
88088 out_free_mpol:
88089 mpol_put(pol);
88090 out_free_vma:
88091+
88092+#ifdef CONFIG_PAX_SEGMEXEC
88093+ if (new_m) {
88094+ unlink_anon_vmas(new_m);
88095+ kmem_cache_free(vm_area_cachep, new_m);
88096+ }
88097+#endif
88098+
88099+ unlink_anon_vmas(new);
88100 kmem_cache_free(vm_area_cachep, new);
88101 out_err:
88102 return err;
88103@@ -2451,6 +2892,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88104 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
88105 unsigned long addr, int new_below)
88106 {
88107+
88108+#ifdef CONFIG_PAX_SEGMEXEC
88109+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
88110+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
88111+ if (mm->map_count >= sysctl_max_map_count-1)
88112+ return -ENOMEM;
88113+ } else
88114+#endif
88115+
88116 if (mm->map_count >= sysctl_max_map_count)
88117 return -ENOMEM;
88118
88119@@ -2462,11 +2912,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
88120 * work. This now handles partial unmappings.
88121 * Jeremy Fitzhardinge <jeremy@goop.org>
88122 */
88123+#ifdef CONFIG_PAX_SEGMEXEC
88124 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
88125 {
88126+ int ret = __do_munmap(mm, start, len);
88127+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
88128+ return ret;
88129+
88130+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
88131+}
88132+
88133+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
88134+#else
88135+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
88136+#endif
88137+{
88138 unsigned long end;
88139 struct vm_area_struct *vma, *prev, *last;
88140
88141+ /*
88142+ * mm->mmap_sem is required to protect against another thread
88143+ * changing the mappings in case we sleep.
88144+ */
88145+ verify_mm_writelocked(mm);
88146+
88147 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
88148 return -EINVAL;
88149
88150@@ -2541,6 +3010,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
88151 /* Fix up all other VM information */
88152 remove_vma_list(mm, vma);
88153
88154+ track_exec_limit(mm, start, end, 0UL);
88155+
88156 return 0;
88157 }
88158
88159@@ -2549,6 +3020,13 @@ int vm_munmap(unsigned long start, size_t len)
88160 int ret;
88161 struct mm_struct *mm = current->mm;
88162
88163+
88164+#ifdef CONFIG_PAX_SEGMEXEC
88165+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
88166+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
88167+ return -EINVAL;
88168+#endif
88169+
88170 down_write(&mm->mmap_sem);
88171 ret = do_munmap(mm, start, len);
88172 up_write(&mm->mmap_sem);
88173@@ -2562,16 +3040,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
88174 return vm_munmap(addr, len);
88175 }
88176
88177-static inline void verify_mm_writelocked(struct mm_struct *mm)
88178-{
88179-#ifdef CONFIG_DEBUG_VM
88180- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
88181- WARN_ON(1);
88182- up_read(&mm->mmap_sem);
88183- }
88184-#endif
88185-}
88186-
88187 /*
88188 * this is really a simplified "do_mmap". it only handles
88189 * anonymous maps. eventually we may be able to do some
88190@@ -2585,6 +3053,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88191 struct rb_node ** rb_link, * rb_parent;
88192 pgoff_t pgoff = addr >> PAGE_SHIFT;
88193 int error;
88194+ unsigned long charged;
88195
88196 len = PAGE_ALIGN(len);
88197 if (!len)
88198@@ -2592,16 +3061,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88199
88200 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
88201
88202+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
88203+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
88204+ flags &= ~VM_EXEC;
88205+
88206+#ifdef CONFIG_PAX_MPROTECT
88207+ if (mm->pax_flags & MF_PAX_MPROTECT)
88208+ flags &= ~VM_MAYEXEC;
88209+#endif
88210+
88211+ }
88212+#endif
88213+
88214 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
88215 if (error & ~PAGE_MASK)
88216 return error;
88217
88218+ charged = len >> PAGE_SHIFT;
88219+
88220 /*
88221 * mlock MCL_FUTURE?
88222 */
88223 if (mm->def_flags & VM_LOCKED) {
88224 unsigned long locked, lock_limit;
88225- locked = len >> PAGE_SHIFT;
88226+ locked = charged;
88227 locked += mm->locked_vm;
88228 lock_limit = rlimit(RLIMIT_MEMLOCK);
88229 lock_limit >>= PAGE_SHIFT;
88230@@ -2618,21 +3101,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88231 /*
88232 * Clear old maps. this also does some error checking for us
88233 */
88234- munmap_back:
88235 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
88236 if (do_munmap(mm, addr, len))
88237 return -ENOMEM;
88238- goto munmap_back;
88239+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
88240 }
88241
88242 /* Check against address space limits *after* clearing old maps... */
88243- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
88244+ if (!may_expand_vm(mm, charged))
88245 return -ENOMEM;
88246
88247 if (mm->map_count > sysctl_max_map_count)
88248 return -ENOMEM;
88249
88250- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
88251+ if (security_vm_enough_memory_mm(mm, charged))
88252 return -ENOMEM;
88253
88254 /* Can we just expand an old private anonymous mapping? */
88255@@ -2646,7 +3128,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88256 */
88257 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
88258 if (!vma) {
88259- vm_unacct_memory(len >> PAGE_SHIFT);
88260+ vm_unacct_memory(charged);
88261 return -ENOMEM;
88262 }
88263
88264@@ -2660,9 +3142,10 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88265 vma_link(mm, vma, prev, rb_link, rb_parent);
88266 out:
88267 perf_event_mmap(vma);
88268- mm->total_vm += len >> PAGE_SHIFT;
88269+ mm->total_vm += charged;
88270 if (flags & VM_LOCKED)
88271- mm->locked_vm += (len >> PAGE_SHIFT);
88272+ mm->locked_vm += charged;
88273+ track_exec_limit(mm, addr, addr + len, flags);
88274 return addr;
88275 }
88276
88277@@ -2724,6 +3207,7 @@ void exit_mmap(struct mm_struct *mm)
88278 while (vma) {
88279 if (vma->vm_flags & VM_ACCOUNT)
88280 nr_accounted += vma_pages(vma);
88281+ vma->vm_mirror = NULL;
88282 vma = remove_vma(vma);
88283 }
88284 vm_unacct_memory(nr_accounted);
88285@@ -2740,6 +3224,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
88286 struct vm_area_struct *prev;
88287 struct rb_node **rb_link, *rb_parent;
88288
88289+#ifdef CONFIG_PAX_SEGMEXEC
88290+ struct vm_area_struct *vma_m = NULL;
88291+#endif
88292+
88293+ if (security_mmap_addr(vma->vm_start))
88294+ return -EPERM;
88295+
88296 /*
88297 * The vm_pgoff of a purely anonymous vma should be irrelevant
88298 * until its first write fault, when page's anon_vma and index
88299@@ -2763,7 +3254,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
88300 security_vm_enough_memory_mm(mm, vma_pages(vma)))
88301 return -ENOMEM;
88302
88303+#ifdef CONFIG_PAX_SEGMEXEC
88304+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
88305+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
88306+ if (!vma_m)
88307+ return -ENOMEM;
88308+ }
88309+#endif
88310+
88311 vma_link(mm, vma, prev, rb_link, rb_parent);
88312+
88313+#ifdef CONFIG_PAX_SEGMEXEC
88314+ if (vma_m)
88315+ BUG_ON(pax_mirror_vma(vma_m, vma));
88316+#endif
88317+
88318 return 0;
88319 }
88320
88321@@ -2783,6 +3288,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
88322 struct mempolicy *pol;
88323 bool faulted_in_anon_vma = true;
88324
88325+ BUG_ON(vma->vm_mirror);
88326+
88327 /*
88328 * If anonymous vma has not yet been faulted, update new pgoff
88329 * to match new location, to increase its chance of merging.
88330@@ -2849,6 +3356,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
88331 return NULL;
88332 }
88333
88334+#ifdef CONFIG_PAX_SEGMEXEC
88335+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
88336+{
88337+ struct vm_area_struct *prev_m;
88338+ struct rb_node **rb_link_m, *rb_parent_m;
88339+ struct mempolicy *pol_m;
88340+
88341+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
88342+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
88343+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
88344+ *vma_m = *vma;
88345+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
88346+ if (anon_vma_clone(vma_m, vma))
88347+ return -ENOMEM;
88348+ pol_m = vma_policy(vma_m);
88349+ mpol_get(pol_m);
88350+ vma_set_policy(vma_m, pol_m);
88351+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
88352+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
88353+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
88354+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
88355+ if (vma_m->vm_file)
88356+ get_file(vma_m->vm_file);
88357+ if (vma_m->vm_ops && vma_m->vm_ops->open)
88358+ vma_m->vm_ops->open(vma_m);
88359+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
88360+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
88361+ vma_m->vm_mirror = vma;
88362+ vma->vm_mirror = vma_m;
88363+ return 0;
88364+}
88365+#endif
88366+
88367 /*
88368 * Return true if the calling process may expand its vm space by the passed
88369 * number of pages
88370@@ -2860,6 +3400,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
88371
88372 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
88373
88374+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
88375 if (cur + npages > lim)
88376 return 0;
88377 return 1;
88378@@ -2930,6 +3471,22 @@ int install_special_mapping(struct mm_struct *mm,
88379 vma->vm_start = addr;
88380 vma->vm_end = addr + len;
88381
88382+#ifdef CONFIG_PAX_MPROTECT
88383+ if (mm->pax_flags & MF_PAX_MPROTECT) {
88384+#ifndef CONFIG_PAX_MPROTECT_COMPAT
88385+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
88386+ return -EPERM;
88387+ if (!(vm_flags & VM_EXEC))
88388+ vm_flags &= ~VM_MAYEXEC;
88389+#else
88390+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
88391+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
88392+#endif
88393+ else
88394+ vm_flags &= ~VM_MAYWRITE;
88395+ }
88396+#endif
88397+
88398 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
88399 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
88400
88401diff --git a/mm/mprotect.c b/mm/mprotect.c
88402index 94722a4..e661e29 100644
88403--- a/mm/mprotect.c
88404+++ b/mm/mprotect.c
88405@@ -23,10 +23,18 @@
88406 #include <linux/mmu_notifier.h>
88407 #include <linux/migrate.h>
88408 #include <linux/perf_event.h>
88409+#include <linux/sched/sysctl.h>
88410+
88411+#ifdef CONFIG_PAX_MPROTECT
88412+#include <linux/elf.h>
88413+#include <linux/binfmts.h>
88414+#endif
88415+
88416 #include <asm/uaccess.h>
88417 #include <asm/pgtable.h>
88418 #include <asm/cacheflush.h>
88419 #include <asm/tlbflush.h>
88420+#include <asm/mmu_context.h>
88421
88422 #ifndef pgprot_modify
88423 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
88424@@ -233,6 +241,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
88425 return pages;
88426 }
88427
88428+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
88429+/* called while holding the mmap semaphor for writing except stack expansion */
88430+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
88431+{
88432+ unsigned long oldlimit, newlimit = 0UL;
88433+
88434+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
88435+ return;
88436+
88437+ spin_lock(&mm->page_table_lock);
88438+ oldlimit = mm->context.user_cs_limit;
88439+ if ((prot & VM_EXEC) && oldlimit < end)
88440+ /* USER_CS limit moved up */
88441+ newlimit = end;
88442+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
88443+ /* USER_CS limit moved down */
88444+ newlimit = start;
88445+
88446+ if (newlimit) {
88447+ mm->context.user_cs_limit = newlimit;
88448+
88449+#ifdef CONFIG_SMP
88450+ wmb();
88451+ cpus_clear(mm->context.cpu_user_cs_mask);
88452+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
88453+#endif
88454+
88455+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
88456+ }
88457+ spin_unlock(&mm->page_table_lock);
88458+ if (newlimit == end) {
88459+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
88460+
88461+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
88462+ if (is_vm_hugetlb_page(vma))
88463+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
88464+ else
88465+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
88466+ }
88467+}
88468+#endif
88469+
88470 int
88471 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
88472 unsigned long start, unsigned long end, unsigned long newflags)
88473@@ -245,11 +295,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
88474 int error;
88475 int dirty_accountable = 0;
88476
88477+#ifdef CONFIG_PAX_SEGMEXEC
88478+ struct vm_area_struct *vma_m = NULL;
88479+ unsigned long start_m, end_m;
88480+
88481+ start_m = start + SEGMEXEC_TASK_SIZE;
88482+ end_m = end + SEGMEXEC_TASK_SIZE;
88483+#endif
88484+
88485 if (newflags == oldflags) {
88486 *pprev = vma;
88487 return 0;
88488 }
88489
88490+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
88491+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
88492+
88493+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
88494+ return -ENOMEM;
88495+
88496+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
88497+ return -ENOMEM;
88498+ }
88499+
88500 /*
88501 * If we make a private mapping writable we increase our commit;
88502 * but (without finer accounting) cannot reduce our commit if we
88503@@ -266,6 +334,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
88504 }
88505 }
88506
88507+#ifdef CONFIG_PAX_SEGMEXEC
88508+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
88509+ if (start != vma->vm_start) {
88510+ error = split_vma(mm, vma, start, 1);
88511+ if (error)
88512+ goto fail;
88513+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
88514+ *pprev = (*pprev)->vm_next;
88515+ }
88516+
88517+ if (end != vma->vm_end) {
88518+ error = split_vma(mm, vma, end, 0);
88519+ if (error)
88520+ goto fail;
88521+ }
88522+
88523+ if (pax_find_mirror_vma(vma)) {
88524+ error = __do_munmap(mm, start_m, end_m - start_m);
88525+ if (error)
88526+ goto fail;
88527+ } else {
88528+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
88529+ if (!vma_m) {
88530+ error = -ENOMEM;
88531+ goto fail;
88532+ }
88533+ vma->vm_flags = newflags;
88534+ error = pax_mirror_vma(vma_m, vma);
88535+ if (error) {
88536+ vma->vm_flags = oldflags;
88537+ goto fail;
88538+ }
88539+ }
88540+ }
88541+#endif
88542+
88543 /*
88544 * First try to merge with previous and/or next vma.
88545 */
88546@@ -296,9 +400,21 @@ success:
88547 * vm_flags and vm_page_prot are protected by the mmap_sem
88548 * held in write mode.
88549 */
88550+
88551+#ifdef CONFIG_PAX_SEGMEXEC
88552+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
88553+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
88554+#endif
88555+
88556 vma->vm_flags = newflags;
88557+
88558+#ifdef CONFIG_PAX_MPROTECT
88559+ if (mm->binfmt && mm->binfmt->handle_mprotect)
88560+ mm->binfmt->handle_mprotect(vma, newflags);
88561+#endif
88562+
88563 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
88564- vm_get_page_prot(newflags));
88565+ vm_get_page_prot(vma->vm_flags));
88566
88567 if (vma_wants_writenotify(vma)) {
88568 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
88569@@ -337,6 +453,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88570 end = start + len;
88571 if (end <= start)
88572 return -ENOMEM;
88573+
88574+#ifdef CONFIG_PAX_SEGMEXEC
88575+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
88576+ if (end > SEGMEXEC_TASK_SIZE)
88577+ return -EINVAL;
88578+ } else
88579+#endif
88580+
88581+ if (end > TASK_SIZE)
88582+ return -EINVAL;
88583+
88584 if (!arch_validate_prot(prot))
88585 return -EINVAL;
88586
88587@@ -344,7 +471,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88588 /*
88589 * Does the application expect PROT_READ to imply PROT_EXEC:
88590 */
88591- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
88592+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
88593 prot |= PROT_EXEC;
88594
88595 vm_flags = calc_vm_prot_bits(prot);
88596@@ -376,6 +503,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88597 if (start > vma->vm_start)
88598 prev = vma;
88599
88600+#ifdef CONFIG_PAX_MPROTECT
88601+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
88602+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
88603+#endif
88604+
88605 for (nstart = start ; ; ) {
88606 unsigned long newflags;
88607
88608@@ -386,6 +518,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88609
88610 /* newflags >> 4 shift VM_MAY% in place of VM_% */
88611 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
88612+ if (prot & (PROT_WRITE | PROT_EXEC))
88613+ gr_log_rwxmprotect(vma);
88614+
88615+ error = -EACCES;
88616+ goto out;
88617+ }
88618+
88619+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
88620 error = -EACCES;
88621 goto out;
88622 }
88623@@ -400,6 +540,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88624 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
88625 if (error)
88626 goto out;
88627+
88628+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
88629+
88630 nstart = tmp;
88631
88632 if (nstart < prev->vm_end)
88633diff --git a/mm/mremap.c b/mm/mremap.c
88634index 0843feb..5607f47 100644
88635--- a/mm/mremap.c
88636+++ b/mm/mremap.c
88637@@ -25,6 +25,7 @@
88638 #include <asm/uaccess.h>
88639 #include <asm/cacheflush.h>
88640 #include <asm/tlbflush.h>
88641+#include <asm/pgalloc.h>
88642
88643 #include "internal.h"
88644
88645@@ -62,8 +63,10 @@ static pmd_t *alloc_new_pmd(struct mm_struct *mm, struct vm_area_struct *vma,
88646 return NULL;
88647
88648 pmd = pmd_alloc(mm, pud, addr);
88649- if (!pmd)
88650+ if (!pmd) {
88651+ pud_free(mm, pud);
88652 return NULL;
88653+ }
88654
88655 VM_BUG_ON(pmd_trans_huge(*pmd));
88656
88657@@ -144,6 +147,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
88658 continue;
88659 pte = ptep_get_and_clear(mm, old_addr, old_pte);
88660 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
88661+
88662+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
88663+ if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
88664+ pte = pte_exprotect(pte);
88665+#endif
88666+
88667 pte = move_soft_dirty_pte(pte);
88668 set_pte_at(mm, new_addr, new_pte, pte);
88669 }
88670@@ -337,6 +346,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
88671 if (is_vm_hugetlb_page(vma))
88672 goto Einval;
88673
88674+#ifdef CONFIG_PAX_SEGMEXEC
88675+ if (pax_find_mirror_vma(vma))
88676+ goto Einval;
88677+#endif
88678+
88679 /* We can't remap across vm area boundaries */
88680 if (old_len > vma->vm_end - addr)
88681 goto Efault;
88682@@ -392,20 +406,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
88683 unsigned long ret = -EINVAL;
88684 unsigned long charged = 0;
88685 unsigned long map_flags;
88686+ unsigned long pax_task_size = TASK_SIZE;
88687
88688 if (new_addr & ~PAGE_MASK)
88689 goto out;
88690
88691- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
88692+#ifdef CONFIG_PAX_SEGMEXEC
88693+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
88694+ pax_task_size = SEGMEXEC_TASK_SIZE;
88695+#endif
88696+
88697+ pax_task_size -= PAGE_SIZE;
88698+
88699+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
88700 goto out;
88701
88702 /* Check if the location we're moving into overlaps the
88703 * old location at all, and fail if it does.
88704 */
88705- if ((new_addr <= addr) && (new_addr+new_len) > addr)
88706- goto out;
88707-
88708- if ((addr <= new_addr) && (addr+old_len) > new_addr)
88709+ if (addr + old_len > new_addr && new_addr + new_len > addr)
88710 goto out;
88711
88712 ret = do_munmap(mm, new_addr, new_len);
88713@@ -474,6 +493,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
88714 unsigned long ret = -EINVAL;
88715 unsigned long charged = 0;
88716 bool locked = false;
88717+ unsigned long pax_task_size = TASK_SIZE;
88718
88719 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
88720 return ret;
88721@@ -495,6 +515,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
88722 if (!new_len)
88723 return ret;
88724
88725+#ifdef CONFIG_PAX_SEGMEXEC
88726+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
88727+ pax_task_size = SEGMEXEC_TASK_SIZE;
88728+#endif
88729+
88730+ pax_task_size -= PAGE_SIZE;
88731+
88732+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
88733+ old_len > pax_task_size || addr > pax_task_size-old_len)
88734+ return ret;
88735+
88736 down_write(&current->mm->mmap_sem);
88737
88738 if (flags & MREMAP_FIXED) {
88739@@ -545,6 +576,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
88740 new_addr = addr;
88741 }
88742 ret = addr;
88743+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
88744 goto out;
88745 }
88746 }
88747@@ -568,7 +600,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
88748 goto out;
88749 }
88750
88751+ map_flags = vma->vm_flags;
88752 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
88753+ if (!(ret & ~PAGE_MASK)) {
88754+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
88755+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
88756+ }
88757 }
88758 out:
88759 if (ret & ~PAGE_MASK)
88760diff --git a/mm/nommu.c b/mm/nommu.c
88761index ecd1f15..77039bd 100644
88762--- a/mm/nommu.c
88763+++ b/mm/nommu.c
88764@@ -64,7 +64,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
88765 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
88766 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
88767 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
88768-int heap_stack_gap = 0;
88769
88770 atomic_long_t mmap_pages_allocated;
88771
88772@@ -844,15 +843,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
88773 EXPORT_SYMBOL(find_vma);
88774
88775 /*
88776- * find a VMA
88777- * - we don't extend stack VMAs under NOMMU conditions
88778- */
88779-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
88780-{
88781- return find_vma(mm, addr);
88782-}
88783-
88784-/*
88785 * expand a stack to a given address
88786 * - not supported under NOMMU conditions
88787 */
88788@@ -1563,6 +1553,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
88789
88790 /* most fields are the same, copy all, and then fixup */
88791 *new = *vma;
88792+ INIT_LIST_HEAD(&new->anon_vma_chain);
88793 *region = *vma->vm_region;
88794 new->vm_region = region;
88795
88796@@ -1993,8 +1984,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
88797 }
88798 EXPORT_SYMBOL(generic_file_remap_pages);
88799
88800-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
88801- unsigned long addr, void *buf, int len, int write)
88802+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
88803+ unsigned long addr, void *buf, size_t len, int write)
88804 {
88805 struct vm_area_struct *vma;
88806
88807@@ -2035,8 +2026,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
88808 *
88809 * The caller must hold a reference on @mm.
88810 */
88811-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
88812- void *buf, int len, int write)
88813+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
88814+ void *buf, size_t len, int write)
88815 {
88816 return __access_remote_vm(NULL, mm, addr, buf, len, write);
88817 }
88818@@ -2045,7 +2036,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
88819 * Access another process' address space.
88820 * - source/target buffer must be kernel space
88821 */
88822-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
88823+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
88824 {
88825 struct mm_struct *mm;
88826
88827diff --git a/mm/page-writeback.c b/mm/page-writeback.c
88828index 3f0c895..60cd104 100644
88829--- a/mm/page-writeback.c
88830+++ b/mm/page-writeback.c
88831@@ -659,7 +659,7 @@ unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty)
88832 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
88833 * - the bdi dirty thresh drops quickly due to change of JBOD workload
88834 */
88835-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
88836+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
88837 unsigned long thresh,
88838 unsigned long bg_thresh,
88839 unsigned long dirty,
88840diff --git a/mm/page_alloc.c b/mm/page_alloc.c
88841index b100255..fba1254 100644
88842--- a/mm/page_alloc.c
88843+++ b/mm/page_alloc.c
88844@@ -60,6 +60,7 @@
88845 #include <linux/page-debug-flags.h>
88846 #include <linux/hugetlb.h>
88847 #include <linux/sched/rt.h>
88848+#include <linux/random.h>
88849
88850 #include <asm/sections.h>
88851 #include <asm/tlbflush.h>
88852@@ -353,7 +354,7 @@ out:
88853 * This usage means that zero-order pages may not be compound.
88854 */
88855
88856-static void free_compound_page(struct page *page)
88857+void free_compound_page(struct page *page)
88858 {
88859 __free_pages_ok(page, compound_order(page));
88860 }
88861@@ -710,6 +711,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
88862 int i;
88863 int bad = 0;
88864
88865+#ifdef CONFIG_PAX_MEMORY_SANITIZE
88866+ unsigned long index = 1UL << order;
88867+#endif
88868+
88869 trace_mm_page_free(page, order);
88870 kmemcheck_free_shadow(page, order);
88871
88872@@ -725,6 +730,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
88873 debug_check_no_obj_freed(page_address(page),
88874 PAGE_SIZE << order);
88875 }
88876+
88877+#ifdef CONFIG_PAX_MEMORY_SANITIZE
88878+ for (; index; --index)
88879+ sanitize_highpage(page + index - 1);
88880+#endif
88881+
88882 arch_free_page(page, order);
88883 kernel_map_pages(page, 1 << order, 0);
88884
88885@@ -747,6 +758,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
88886 local_irq_restore(flags);
88887 }
88888
88889+#ifdef CONFIG_PAX_LATENT_ENTROPY
88890+bool __meminitdata extra_latent_entropy;
88891+
88892+static int __init setup_pax_extra_latent_entropy(char *str)
88893+{
88894+ extra_latent_entropy = true;
88895+ return 0;
88896+}
88897+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
88898+
88899+volatile u64 latent_entropy;
88900+EXPORT_SYMBOL(latent_entropy);
88901+#endif
88902+
88903 void __init __free_pages_bootmem(struct page *page, unsigned int order)
88904 {
88905 unsigned int nr_pages = 1 << order;
88906@@ -762,6 +787,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
88907 set_page_count(p, 0);
88908 }
88909
88910+#ifdef CONFIG_PAX_LATENT_ENTROPY
88911+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
88912+ u64 hash = 0;
88913+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
88914+ const u64 *data = lowmem_page_address(page);
88915+
88916+ for (index = 0; index < end; index++)
88917+ hash ^= hash + data[index];
88918+ latent_entropy ^= hash;
88919+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
88920+ }
88921+#endif
88922+
88923 page_zone(page)->managed_pages += 1 << order;
88924 set_page_refcounted(page);
88925 __free_pages(page, order);
88926@@ -867,8 +905,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
88927 arch_alloc_page(page, order);
88928 kernel_map_pages(page, 1 << order, 1);
88929
88930+#ifndef CONFIG_PAX_MEMORY_SANITIZE
88931 if (gfp_flags & __GFP_ZERO)
88932 prep_zero_page(page, order, gfp_flags);
88933+#endif
88934
88935 if (order && (gfp_flags & __GFP_COMP))
88936 prep_compound_page(page, order);
88937diff --git a/mm/page_io.c b/mm/page_io.c
88938index ba05b64..ef2f314 100644
88939--- a/mm/page_io.c
88940+++ b/mm/page_io.c
88941@@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
88942 struct file *swap_file = sis->swap_file;
88943 struct address_space *mapping = swap_file->f_mapping;
88944 struct iovec iov = {
88945- .iov_base = kmap(page),
88946+ .iov_base = (void __force_user *)kmap(page),
88947 .iov_len = PAGE_SIZE,
88948 };
88949
88950diff --git a/mm/percpu.c b/mm/percpu.c
88951index 8c8e08f..73a5cda 100644
88952--- a/mm/percpu.c
88953+++ b/mm/percpu.c
88954@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
88955 static unsigned int pcpu_high_unit_cpu __read_mostly;
88956
88957 /* the address of the first chunk which starts with the kernel static area */
88958-void *pcpu_base_addr __read_mostly;
88959+void *pcpu_base_addr __read_only;
88960 EXPORT_SYMBOL_GPL(pcpu_base_addr);
88961
88962 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
88963diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
88964index fd26d04..0cea1b0 100644
88965--- a/mm/process_vm_access.c
88966+++ b/mm/process_vm_access.c
88967@@ -13,6 +13,7 @@
88968 #include <linux/uio.h>
88969 #include <linux/sched.h>
88970 #include <linux/highmem.h>
88971+#include <linux/security.h>
88972 #include <linux/ptrace.h>
88973 #include <linux/slab.h>
88974 #include <linux/syscalls.h>
88975@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
88976 size_t iov_l_curr_offset = 0;
88977 ssize_t iov_len;
88978
88979+ return -ENOSYS; // PaX: until properly audited
88980+
88981 /*
88982 * Work out how many pages of struct pages we're going to need
88983 * when eventually calling get_user_pages
88984 */
88985 for (i = 0; i < riovcnt; i++) {
88986 iov_len = rvec[i].iov_len;
88987- if (iov_len > 0) {
88988- nr_pages_iov = ((unsigned long)rvec[i].iov_base
88989- + iov_len)
88990- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
88991- / PAGE_SIZE + 1;
88992- nr_pages = max(nr_pages, nr_pages_iov);
88993- }
88994+ if (iov_len <= 0)
88995+ continue;
88996+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
88997+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
88998+ nr_pages = max(nr_pages, nr_pages_iov);
88999 }
89000
89001 if (nr_pages == 0)
89002@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
89003 goto free_proc_pages;
89004 }
89005
89006+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
89007+ rc = -EPERM;
89008+ goto put_task_struct;
89009+ }
89010+
89011 mm = mm_access(task, PTRACE_MODE_ATTACH);
89012 if (!mm || IS_ERR(mm)) {
89013 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
89014diff --git a/mm/rmap.c b/mm/rmap.c
89015index b2e29ac..4168491 100644
89016--- a/mm/rmap.c
89017+++ b/mm/rmap.c
89018@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
89019 struct anon_vma *anon_vma = vma->anon_vma;
89020 struct anon_vma_chain *avc;
89021
89022+#ifdef CONFIG_PAX_SEGMEXEC
89023+ struct anon_vma_chain *avc_m = NULL;
89024+#endif
89025+
89026 might_sleep();
89027 if (unlikely(!anon_vma)) {
89028 struct mm_struct *mm = vma->vm_mm;
89029@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
89030 if (!avc)
89031 goto out_enomem;
89032
89033+#ifdef CONFIG_PAX_SEGMEXEC
89034+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
89035+ if (!avc_m)
89036+ goto out_enomem_free_avc;
89037+#endif
89038+
89039 anon_vma = find_mergeable_anon_vma(vma);
89040 allocated = NULL;
89041 if (!anon_vma) {
89042@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
89043 /* page_table_lock to protect against threads */
89044 spin_lock(&mm->page_table_lock);
89045 if (likely(!vma->anon_vma)) {
89046+
89047+#ifdef CONFIG_PAX_SEGMEXEC
89048+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
89049+
89050+ if (vma_m) {
89051+ BUG_ON(vma_m->anon_vma);
89052+ vma_m->anon_vma = anon_vma;
89053+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
89054+ avc_m = NULL;
89055+ }
89056+#endif
89057+
89058 vma->anon_vma = anon_vma;
89059 anon_vma_chain_link(vma, avc, anon_vma);
89060 allocated = NULL;
89061@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
89062
89063 if (unlikely(allocated))
89064 put_anon_vma(allocated);
89065+
89066+#ifdef CONFIG_PAX_SEGMEXEC
89067+ if (unlikely(avc_m))
89068+ anon_vma_chain_free(avc_m);
89069+#endif
89070+
89071 if (unlikely(avc))
89072 anon_vma_chain_free(avc);
89073 }
89074 return 0;
89075
89076 out_enomem_free_avc:
89077+
89078+#ifdef CONFIG_PAX_SEGMEXEC
89079+ if (avc_m)
89080+ anon_vma_chain_free(avc_m);
89081+#endif
89082+
89083 anon_vma_chain_free(avc);
89084 out_enomem:
89085 return -ENOMEM;
89086@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
89087 * Attach the anon_vmas from src to dst.
89088 * Returns 0 on success, -ENOMEM on failure.
89089 */
89090-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
89091+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
89092 {
89093 struct anon_vma_chain *avc, *pavc;
89094 struct anon_vma *root = NULL;
89095@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
89096 * the corresponding VMA in the parent process is attached to.
89097 * Returns 0 on success, non-zero on failure.
89098 */
89099-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
89100+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
89101 {
89102 struct anon_vma_chain *avc;
89103 struct anon_vma *anon_vma;
89104@@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
89105 void __init anon_vma_init(void)
89106 {
89107 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
89108- 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
89109- anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
89110+ 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
89111+ anon_vma_ctor);
89112+ anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
89113+ SLAB_PANIC|SLAB_NO_SANITIZE);
89114 }
89115
89116 /*
89117diff --git a/mm/shmem.c b/mm/shmem.c
89118index e43dc55..930e3a2 100644
89119--- a/mm/shmem.c
89120+++ b/mm/shmem.c
89121@@ -33,7 +33,7 @@
89122 #include <linux/swap.h>
89123 #include <linux/aio.h>
89124
89125-static struct vfsmount *shm_mnt;
89126+struct vfsmount *shm_mnt;
89127
89128 #ifdef CONFIG_SHMEM
89129 /*
89130@@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
89131 #define BOGO_DIRENT_SIZE 20
89132
89133 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
89134-#define SHORT_SYMLINK_LEN 128
89135+#define SHORT_SYMLINK_LEN 64
89136
89137 /*
89138 * shmem_fallocate and shmem_writepage communicate via inode->i_private
89139@@ -2232,6 +2232,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
89140 static int shmem_xattr_validate(const char *name)
89141 {
89142 struct { const char *prefix; size_t len; } arr[] = {
89143+
89144+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
89145+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
89146+#endif
89147+
89148 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
89149 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
89150 };
89151@@ -2287,6 +2292,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
89152 if (err)
89153 return err;
89154
89155+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
89156+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
89157+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
89158+ return -EOPNOTSUPP;
89159+ if (size > 8)
89160+ return -EINVAL;
89161+ }
89162+#endif
89163+
89164 return simple_xattr_set(&info->xattrs, name, value, size, flags);
89165 }
89166
89167@@ -2599,8 +2613,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
89168 int err = -ENOMEM;
89169
89170 /* Round up to L1_CACHE_BYTES to resist false sharing */
89171- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
89172- L1_CACHE_BYTES), GFP_KERNEL);
89173+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
89174 if (!sbinfo)
89175 return -ENOMEM;
89176
89177diff --git a/mm/slab.c b/mm/slab.c
89178index 2580db0..0523956 100644
89179--- a/mm/slab.c
89180+++ b/mm/slab.c
89181@@ -366,10 +366,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
89182 if ((x)->max_freeable < i) \
89183 (x)->max_freeable = i; \
89184 } while (0)
89185-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
89186-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
89187-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
89188-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
89189+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
89190+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
89191+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
89192+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
89193+#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
89194+#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
89195 #else
89196 #define STATS_INC_ACTIVE(x) do { } while (0)
89197 #define STATS_DEC_ACTIVE(x) do { } while (0)
89198@@ -386,6 +388,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
89199 #define STATS_INC_ALLOCMISS(x) do { } while (0)
89200 #define STATS_INC_FREEHIT(x) do { } while (0)
89201 #define STATS_INC_FREEMISS(x) do { } while (0)
89202+#define STATS_INC_SANITIZED(x) do { } while (0)
89203+#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
89204 #endif
89205
89206 #if DEBUG
89207@@ -477,7 +481,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
89208 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
89209 */
89210 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
89211- const struct slab *slab, void *obj)
89212+ const struct slab *slab, const void *obj)
89213 {
89214 u32 offset = (obj - slab->s_mem);
89215 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
89216@@ -1571,12 +1575,12 @@ void __init kmem_cache_init(void)
89217 */
89218
89219 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
89220- kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
89221+ kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
89222
89223 if (INDEX_AC != INDEX_NODE)
89224 kmalloc_caches[INDEX_NODE] =
89225 create_kmalloc_cache("kmalloc-node",
89226- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
89227+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
89228
89229 slab_early_init = 0;
89230
89231@@ -3577,6 +3581,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
89232 struct array_cache *ac = cpu_cache_get(cachep);
89233
89234 check_irq_off();
89235+
89236+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89237+ if (pax_sanitize_slab) {
89238+ if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
89239+ memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
89240+
89241+ if (cachep->ctor)
89242+ cachep->ctor(objp);
89243+
89244+ STATS_INC_SANITIZED(cachep);
89245+ } else
89246+ STATS_INC_NOT_SANITIZED(cachep);
89247+ }
89248+#endif
89249+
89250 kmemleak_free_recursive(objp, cachep->flags);
89251 objp = cache_free_debugcheck(cachep, objp, caller);
89252
89253@@ -3805,6 +3824,7 @@ void kfree(const void *objp)
89254
89255 if (unlikely(ZERO_OR_NULL_PTR(objp)))
89256 return;
89257+ VM_BUG_ON(!virt_addr_valid(objp));
89258 local_irq_save(flags);
89259 kfree_debugcheck(objp);
89260 c = virt_to_cache(objp);
89261@@ -4246,14 +4266,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
89262 }
89263 /* cpu stats */
89264 {
89265- unsigned long allochit = atomic_read(&cachep->allochit);
89266- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
89267- unsigned long freehit = atomic_read(&cachep->freehit);
89268- unsigned long freemiss = atomic_read(&cachep->freemiss);
89269+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
89270+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
89271+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
89272+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
89273
89274 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
89275 allochit, allocmiss, freehit, freemiss);
89276 }
89277+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89278+ {
89279+ unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
89280+ unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
89281+
89282+ seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
89283+ }
89284+#endif
89285 #endif
89286 }
89287
89288@@ -4471,13 +4499,71 @@ static const struct file_operations proc_slabstats_operations = {
89289 static int __init slab_proc_init(void)
89290 {
89291 #ifdef CONFIG_DEBUG_SLAB_LEAK
89292- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
89293+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
89294 #endif
89295 return 0;
89296 }
89297 module_init(slab_proc_init);
89298 #endif
89299
89300+bool is_usercopy_object(const void *ptr)
89301+{
89302+ struct page *page;
89303+ struct kmem_cache *cachep;
89304+
89305+ if (ZERO_OR_NULL_PTR(ptr))
89306+ return false;
89307+
89308+ if (!slab_is_available())
89309+ return false;
89310+
89311+ if (!virt_addr_valid(ptr))
89312+ return false;
89313+
89314+ page = virt_to_head_page(ptr);
89315+
89316+ if (!PageSlab(page))
89317+ return false;
89318+
89319+ cachep = page->slab_cache;
89320+ return cachep->flags & SLAB_USERCOPY;
89321+}
89322+
89323+#ifdef CONFIG_PAX_USERCOPY
89324+const char *check_heap_object(const void *ptr, unsigned long n)
89325+{
89326+ struct page *page;
89327+ struct kmem_cache *cachep;
89328+ struct slab *slabp;
89329+ unsigned int objnr;
89330+ unsigned long offset;
89331+
89332+ if (ZERO_OR_NULL_PTR(ptr))
89333+ return "<null>";
89334+
89335+ if (!virt_addr_valid(ptr))
89336+ return NULL;
89337+
89338+ page = virt_to_head_page(ptr);
89339+
89340+ if (!PageSlab(page))
89341+ return NULL;
89342+
89343+ cachep = page->slab_cache;
89344+ if (!(cachep->flags & SLAB_USERCOPY))
89345+ return cachep->name;
89346+
89347+ slabp = page->slab_page;
89348+ objnr = obj_to_index(cachep, slabp, ptr);
89349+ BUG_ON(objnr >= cachep->num);
89350+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
89351+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
89352+ return NULL;
89353+
89354+ return cachep->name;
89355+}
89356+#endif
89357+
89358 /**
89359 * ksize - get the actual amount of memory allocated for a given object
89360 * @objp: Pointer to the object
89361diff --git a/mm/slab.h b/mm/slab.h
89362index a535033..2f98fe5 100644
89363--- a/mm/slab.h
89364+++ b/mm/slab.h
89365@@ -32,6 +32,15 @@ extern struct list_head slab_caches;
89366 /* The slab cache that manages slab cache information */
89367 extern struct kmem_cache *kmem_cache;
89368
89369+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89370+#ifdef CONFIG_X86_64
89371+#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
89372+#else
89373+#define PAX_MEMORY_SANITIZE_VALUE '\xff'
89374+#endif
89375+extern bool pax_sanitize_slab;
89376+#endif
89377+
89378 unsigned long calculate_alignment(unsigned long flags,
89379 unsigned long align, unsigned long size);
89380
89381@@ -67,7 +76,8 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
89382
89383 /* Legal flag mask for kmem_cache_create(), for various configurations */
89384 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
89385- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
89386+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
89387+ SLAB_USERCOPY | SLAB_NO_SANITIZE)
89388
89389 #if defined(CONFIG_DEBUG_SLAB)
89390 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
89391@@ -231,6 +241,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
89392 return s;
89393
89394 page = virt_to_head_page(x);
89395+
89396+ BUG_ON(!PageSlab(page));
89397+
89398 cachep = page->slab_cache;
89399 if (slab_equal_or_root(cachep, s))
89400 return cachep;
89401diff --git a/mm/slab_common.c b/mm/slab_common.c
89402index 538bade..36fed99 100644
89403--- a/mm/slab_common.c
89404+++ b/mm/slab_common.c
89405@@ -22,11 +22,22 @@
89406
89407 #include "slab.h"
89408
89409-enum slab_state slab_state;
89410+enum slab_state slab_state __read_only;
89411 LIST_HEAD(slab_caches);
89412 DEFINE_MUTEX(slab_mutex);
89413 struct kmem_cache *kmem_cache;
89414
89415+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89416+bool pax_sanitize_slab __read_only = true;
89417+static int __init pax_sanitize_slab_setup(char *str)
89418+{
89419+ pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
89420+ printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
89421+ return 1;
89422+}
89423+__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
89424+#endif
89425+
89426 #ifdef CONFIG_DEBUG_VM
89427 static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
89428 size_t size)
89429@@ -209,7 +220,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
89430
89431 err = __kmem_cache_create(s, flags);
89432 if (!err) {
89433- s->refcount = 1;
89434+ atomic_set(&s->refcount, 1);
89435 list_add(&s->list, &slab_caches);
89436 memcg_cache_list_add(memcg, s);
89437 } else {
89438@@ -255,8 +266,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
89439
89440 get_online_cpus();
89441 mutex_lock(&slab_mutex);
89442- s->refcount--;
89443- if (!s->refcount) {
89444+ if (atomic_dec_and_test(&s->refcount)) {
89445 list_del(&s->list);
89446
89447 if (!__kmem_cache_shutdown(s)) {
89448@@ -302,7 +312,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
89449 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
89450 name, size, err);
89451
89452- s->refcount = -1; /* Exempt from merging for now */
89453+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
89454 }
89455
89456 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
89457@@ -315,7 +325,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
89458
89459 create_boot_cache(s, name, size, flags);
89460 list_add(&s->list, &slab_caches);
89461- s->refcount = 1;
89462+ atomic_set(&s->refcount, 1);
89463 return s;
89464 }
89465
89466@@ -327,6 +337,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
89467 EXPORT_SYMBOL(kmalloc_dma_caches);
89468 #endif
89469
89470+#ifdef CONFIG_PAX_USERCOPY_SLABS
89471+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
89472+EXPORT_SYMBOL(kmalloc_usercopy_caches);
89473+#endif
89474+
89475 /*
89476 * Conversion table for small slabs sizes / 8 to the index in the
89477 * kmalloc array. This is necessary for slabs < 192 since we have non power
89478@@ -391,6 +406,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
89479 return kmalloc_dma_caches[index];
89480
89481 #endif
89482+
89483+#ifdef CONFIG_PAX_USERCOPY_SLABS
89484+ if (unlikely((flags & GFP_USERCOPY)))
89485+ return kmalloc_usercopy_caches[index];
89486+
89487+#endif
89488+
89489 return kmalloc_caches[index];
89490 }
89491
89492@@ -447,7 +469,7 @@ void __init create_kmalloc_caches(unsigned long flags)
89493 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
89494 if (!kmalloc_caches[i]) {
89495 kmalloc_caches[i] = create_kmalloc_cache(NULL,
89496- 1 << i, flags);
89497+ 1 << i, SLAB_USERCOPY | flags);
89498 }
89499
89500 /*
89501@@ -456,10 +478,10 @@ void __init create_kmalloc_caches(unsigned long flags)
89502 * earlier power of two caches
89503 */
89504 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
89505- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
89506+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
89507
89508 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
89509- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
89510+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
89511 }
89512
89513 /* Kmalloc array is now usable */
89514@@ -492,6 +514,23 @@ void __init create_kmalloc_caches(unsigned long flags)
89515 }
89516 }
89517 #endif
89518+
89519+#ifdef CONFIG_PAX_USERCOPY_SLABS
89520+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
89521+ struct kmem_cache *s = kmalloc_caches[i];
89522+
89523+ if (s) {
89524+ int size = kmalloc_size(i);
89525+ char *n = kasprintf(GFP_NOWAIT,
89526+ "usercopy-kmalloc-%d", size);
89527+
89528+ BUG_ON(!n);
89529+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
89530+ size, SLAB_USERCOPY | flags);
89531+ }
89532+ }
89533+#endif
89534+
89535 }
89536 #endif /* !CONFIG_SLOB */
89537
89538@@ -523,6 +562,9 @@ void print_slabinfo_header(struct seq_file *m)
89539 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
89540 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
89541 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
89542+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89543+ seq_puts(m, " : pax <sanitized> <not_sanitized>");
89544+#endif
89545 #endif
89546 seq_putc(m, '\n');
89547 }
89548diff --git a/mm/slob.c b/mm/slob.c
89549index 91bd3f2..e2f549e 100644
89550--- a/mm/slob.c
89551+++ b/mm/slob.c
89552@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
89553 /*
89554 * Return the size of a slob block.
89555 */
89556-static slobidx_t slob_units(slob_t *s)
89557+static slobidx_t slob_units(const slob_t *s)
89558 {
89559 if (s->units > 0)
89560 return s->units;
89561@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
89562 /*
89563 * Return the next free slob block pointer after this one.
89564 */
89565-static slob_t *slob_next(slob_t *s)
89566+static slob_t *slob_next(const slob_t *s)
89567 {
89568 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
89569 slobidx_t next;
89570@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
89571 /*
89572 * Returns true if s is the last free block in its page.
89573 */
89574-static int slob_last(slob_t *s)
89575+static int slob_last(const slob_t *s)
89576 {
89577 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
89578 }
89579
89580-static void *slob_new_pages(gfp_t gfp, int order, int node)
89581+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
89582 {
89583- void *page;
89584+ struct page *page;
89585
89586 #ifdef CONFIG_NUMA
89587 if (node != NUMA_NO_NODE)
89588@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
89589 if (!page)
89590 return NULL;
89591
89592- return page_address(page);
89593+ __SetPageSlab(page);
89594+ return page;
89595 }
89596
89597-static void slob_free_pages(void *b, int order)
89598+static void slob_free_pages(struct page *sp, int order)
89599 {
89600 if (current->reclaim_state)
89601 current->reclaim_state->reclaimed_slab += 1 << order;
89602- free_pages((unsigned long)b, order);
89603+ __ClearPageSlab(sp);
89604+ page_mapcount_reset(sp);
89605+ sp->private = 0;
89606+ __free_pages(sp, order);
89607 }
89608
89609 /*
89610@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
89611
89612 /* Not enough space: must allocate a new page */
89613 if (!b) {
89614- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
89615- if (!b)
89616+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
89617+ if (!sp)
89618 return NULL;
89619- sp = virt_to_page(b);
89620- __SetPageSlab(sp);
89621+ b = page_address(sp);
89622
89623 spin_lock_irqsave(&slob_lock, flags);
89624 sp->units = SLOB_UNITS(PAGE_SIZE);
89625 sp->freelist = b;
89626+ sp->private = 0;
89627 INIT_LIST_HEAD(&sp->list);
89628 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
89629 set_slob_page_free(sp, slob_list);
89630@@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
89631 if (slob_page_free(sp))
89632 clear_slob_page_free(sp);
89633 spin_unlock_irqrestore(&slob_lock, flags);
89634- __ClearPageSlab(sp);
89635- page_mapcount_reset(sp);
89636- slob_free_pages(b, 0);
89637+ slob_free_pages(sp, 0);
89638 return;
89639 }
89640
89641+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89642+ if (pax_sanitize_slab)
89643+ memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
89644+#endif
89645+
89646 if (!slob_page_free(sp)) {
89647 /* This slob page is about to become partially free. Easy! */
89648 sp->units = units;
89649@@ -424,11 +431,10 @@ out:
89650 */
89651
89652 static __always_inline void *
89653-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
89654+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
89655 {
89656- unsigned int *m;
89657- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
89658- void *ret;
89659+ slob_t *m;
89660+ void *ret = NULL;
89661
89662 gfp &= gfp_allowed_mask;
89663
89664@@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
89665
89666 if (!m)
89667 return NULL;
89668- *m = size;
89669+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
89670+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
89671+ m[0].units = size;
89672+ m[1].units = align;
89673 ret = (void *)m + align;
89674
89675 trace_kmalloc_node(caller, ret,
89676 size, size + align, gfp, node);
89677 } else {
89678 unsigned int order = get_order(size);
89679+ struct page *page;
89680
89681 if (likely(order))
89682 gfp |= __GFP_COMP;
89683- ret = slob_new_pages(gfp, order, node);
89684+ page = slob_new_pages(gfp, order, node);
89685+ if (page) {
89686+ ret = page_address(page);
89687+ page->private = size;
89688+ }
89689
89690 trace_kmalloc_node(caller, ret,
89691 size, PAGE_SIZE << order, gfp, node);
89692 }
89693
89694- kmemleak_alloc(ret, size, 1, gfp);
89695+ return ret;
89696+}
89697+
89698+static __always_inline void *
89699+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
89700+{
89701+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
89702+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
89703+
89704+ if (!ZERO_OR_NULL_PTR(ret))
89705+ kmemleak_alloc(ret, size, 1, gfp);
89706 return ret;
89707 }
89708
89709@@ -493,34 +517,112 @@ void kfree(const void *block)
89710 return;
89711 kmemleak_free(block);
89712
89713+ VM_BUG_ON(!virt_addr_valid(block));
89714 sp = virt_to_page(block);
89715- if (PageSlab(sp)) {
89716+ VM_BUG_ON(!PageSlab(sp));
89717+ if (!sp->private) {
89718 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
89719- unsigned int *m = (unsigned int *)(block - align);
89720- slob_free(m, *m + align);
89721- } else
89722+ slob_t *m = (slob_t *)(block - align);
89723+ slob_free(m, m[0].units + align);
89724+ } else {
89725+ __ClearPageSlab(sp);
89726+ page_mapcount_reset(sp);
89727+ sp->private = 0;
89728 __free_pages(sp, compound_order(sp));
89729+ }
89730 }
89731 EXPORT_SYMBOL(kfree);
89732
89733+bool is_usercopy_object(const void *ptr)
89734+{
89735+ if (!slab_is_available())
89736+ return false;
89737+
89738+ // PAX: TODO
89739+
89740+ return false;
89741+}
89742+
89743+#ifdef CONFIG_PAX_USERCOPY
89744+const char *check_heap_object(const void *ptr, unsigned long n)
89745+{
89746+ struct page *page;
89747+ const slob_t *free;
89748+ const void *base;
89749+ unsigned long flags;
89750+
89751+ if (ZERO_OR_NULL_PTR(ptr))
89752+ return "<null>";
89753+
89754+ if (!virt_addr_valid(ptr))
89755+ return NULL;
89756+
89757+ page = virt_to_head_page(ptr);
89758+ if (!PageSlab(page))
89759+ return NULL;
89760+
89761+ if (page->private) {
89762+ base = page;
89763+ if (base <= ptr && n <= page->private - (ptr - base))
89764+ return NULL;
89765+ return "<slob>";
89766+ }
89767+
89768+ /* some tricky double walking to find the chunk */
89769+ spin_lock_irqsave(&slob_lock, flags);
89770+ base = (void *)((unsigned long)ptr & PAGE_MASK);
89771+ free = page->freelist;
89772+
89773+ while (!slob_last(free) && (void *)free <= ptr) {
89774+ base = free + slob_units(free);
89775+ free = slob_next(free);
89776+ }
89777+
89778+ while (base < (void *)free) {
89779+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
89780+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
89781+ int offset;
89782+
89783+ if (ptr < base + align)
89784+ break;
89785+
89786+ offset = ptr - base - align;
89787+ if (offset >= m) {
89788+ base += size;
89789+ continue;
89790+ }
89791+
89792+ if (n > m - offset)
89793+ break;
89794+
89795+ spin_unlock_irqrestore(&slob_lock, flags);
89796+ return NULL;
89797+ }
89798+
89799+ spin_unlock_irqrestore(&slob_lock, flags);
89800+ return "<slob>";
89801+}
89802+#endif
89803+
89804 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
89805 size_t ksize(const void *block)
89806 {
89807 struct page *sp;
89808 int align;
89809- unsigned int *m;
89810+ slob_t *m;
89811
89812 BUG_ON(!block);
89813 if (unlikely(block == ZERO_SIZE_PTR))
89814 return 0;
89815
89816 sp = virt_to_page(block);
89817- if (unlikely(!PageSlab(sp)))
89818- return PAGE_SIZE << compound_order(sp);
89819+ VM_BUG_ON(!PageSlab(sp));
89820+ if (sp->private)
89821+ return sp->private;
89822
89823 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
89824- m = (unsigned int *)(block - align);
89825- return SLOB_UNITS(*m) * SLOB_UNIT;
89826+ m = (slob_t *)(block - align);
89827+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
89828 }
89829 EXPORT_SYMBOL(ksize);
89830
89831@@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
89832
89833 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
89834 {
89835- void *b;
89836+ void *b = NULL;
89837
89838 flags &= gfp_allowed_mask;
89839
89840 lockdep_trace_alloc(flags);
89841
89842+#ifdef CONFIG_PAX_USERCOPY_SLABS
89843+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
89844+#else
89845 if (c->size < PAGE_SIZE) {
89846 b = slob_alloc(c->size, flags, c->align, node);
89847 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
89848 SLOB_UNITS(c->size) * SLOB_UNIT,
89849 flags, node);
89850 } else {
89851- b = slob_new_pages(flags, get_order(c->size), node);
89852+ struct page *sp;
89853+
89854+ sp = slob_new_pages(flags, get_order(c->size), node);
89855+ if (sp) {
89856+ b = page_address(sp);
89857+ sp->private = c->size;
89858+ }
89859 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
89860 PAGE_SIZE << get_order(c->size),
89861 flags, node);
89862 }
89863+#endif
89864
89865 if (b && c->ctor)
89866 c->ctor(b);
89867@@ -564,10 +676,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
89868
89869 static void __kmem_cache_free(void *b, int size)
89870 {
89871- if (size < PAGE_SIZE)
89872+ struct page *sp;
89873+
89874+ sp = virt_to_page(b);
89875+ BUG_ON(!PageSlab(sp));
89876+ if (!sp->private)
89877 slob_free(b, size);
89878 else
89879- slob_free_pages(b, get_order(size));
89880+ slob_free_pages(sp, get_order(size));
89881 }
89882
89883 static void kmem_rcu_free(struct rcu_head *head)
89884@@ -580,17 +696,31 @@ static void kmem_rcu_free(struct rcu_head *head)
89885
89886 void kmem_cache_free(struct kmem_cache *c, void *b)
89887 {
89888+ int size = c->size;
89889+
89890+#ifdef CONFIG_PAX_USERCOPY_SLABS
89891+ if (size + c->align < PAGE_SIZE) {
89892+ size += c->align;
89893+ b -= c->align;
89894+ }
89895+#endif
89896+
89897 kmemleak_free_recursive(b, c->flags);
89898 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
89899 struct slob_rcu *slob_rcu;
89900- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
89901- slob_rcu->size = c->size;
89902+ slob_rcu = b + (size - sizeof(struct slob_rcu));
89903+ slob_rcu->size = size;
89904 call_rcu(&slob_rcu->head, kmem_rcu_free);
89905 } else {
89906- __kmem_cache_free(b, c->size);
89907+ __kmem_cache_free(b, size);
89908 }
89909
89910+#ifdef CONFIG_PAX_USERCOPY_SLABS
89911+ trace_kfree(_RET_IP_, b);
89912+#else
89913 trace_kmem_cache_free(_RET_IP_, b);
89914+#endif
89915+
89916 }
89917 EXPORT_SYMBOL(kmem_cache_free);
89918
89919diff --git a/mm/slub.c b/mm/slub.c
89920index e3ba1f2..bd45dac 100644
89921--- a/mm/slub.c
89922+++ b/mm/slub.c
89923@@ -207,7 +207,7 @@ struct track {
89924
89925 enum track_item { TRACK_ALLOC, TRACK_FREE };
89926
89927-#ifdef CONFIG_SYSFS
89928+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
89929 static int sysfs_slab_add(struct kmem_cache *);
89930 static int sysfs_slab_alias(struct kmem_cache *, const char *);
89931 static void sysfs_slab_remove(struct kmem_cache *);
89932@@ -528,7 +528,7 @@ static void print_track(const char *s, struct track *t)
89933 if (!t->addr)
89934 return;
89935
89936- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
89937+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
89938 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
89939 #ifdef CONFIG_STACKTRACE
89940 {
89941@@ -2609,6 +2609,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
89942
89943 slab_free_hook(s, x);
89944
89945+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89946+ if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
89947+ memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
89948+ if (s->ctor)
89949+ s->ctor(x);
89950+ }
89951+#endif
89952+
89953 redo:
89954 /*
89955 * Determine the currently cpus per cpu slab.
89956@@ -2676,7 +2684,7 @@ static int slub_min_objects;
89957 * Merge control. If this is set then no merging of slab caches will occur.
89958 * (Could be removed. This was introduced to pacify the merge skeptics.)
89959 */
89960-static int slub_nomerge;
89961+static int slub_nomerge = 1;
89962
89963 /*
89964 * Calculate the order of allocation given an slab object size.
89965@@ -2953,6 +2961,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
89966 s->inuse = size;
89967
89968 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
89969+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89970+ (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
89971+#endif
89972 s->ctor)) {
89973 /*
89974 * Relocate free pointer after the object if it is not
89975@@ -3298,6 +3309,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
89976 EXPORT_SYMBOL(__kmalloc_node);
89977 #endif
89978
89979+bool is_usercopy_object(const void *ptr)
89980+{
89981+ struct page *page;
89982+ struct kmem_cache *s;
89983+
89984+ if (ZERO_OR_NULL_PTR(ptr))
89985+ return false;
89986+
89987+ if (!slab_is_available())
89988+ return false;
89989+
89990+ if (!virt_addr_valid(ptr))
89991+ return false;
89992+
89993+ page = virt_to_head_page(ptr);
89994+
89995+ if (!PageSlab(page))
89996+ return false;
89997+
89998+ s = page->slab_cache;
89999+ return s->flags & SLAB_USERCOPY;
90000+}
90001+
90002+#ifdef CONFIG_PAX_USERCOPY
90003+const char *check_heap_object(const void *ptr, unsigned long n)
90004+{
90005+ struct page *page;
90006+ struct kmem_cache *s;
90007+ unsigned long offset;
90008+
90009+ if (ZERO_OR_NULL_PTR(ptr))
90010+ return "<null>";
90011+
90012+ if (!virt_addr_valid(ptr))
90013+ return NULL;
90014+
90015+ page = virt_to_head_page(ptr);
90016+
90017+ if (!PageSlab(page))
90018+ return NULL;
90019+
90020+ s = page->slab_cache;
90021+ if (!(s->flags & SLAB_USERCOPY))
90022+ return s->name;
90023+
90024+ offset = (ptr - page_address(page)) % s->size;
90025+ if (offset <= s->object_size && n <= s->object_size - offset)
90026+ return NULL;
90027+
90028+ return s->name;
90029+}
90030+#endif
90031+
90032 size_t ksize(const void *object)
90033 {
90034 struct page *page;
90035@@ -3362,6 +3426,7 @@ void kfree(const void *x)
90036 if (unlikely(ZERO_OR_NULL_PTR(x)))
90037 return;
90038
90039+ VM_BUG_ON(!virt_addr_valid(x));
90040 page = virt_to_head_page(x);
90041 if (unlikely(!PageSlab(page))) {
90042 BUG_ON(!PageCompound(page));
90043@@ -3667,7 +3732,7 @@ static int slab_unmergeable(struct kmem_cache *s)
90044 /*
90045 * We may have set a slab to be unmergeable during bootstrap.
90046 */
90047- if (s->refcount < 0)
90048+ if (atomic_read(&s->refcount) < 0)
90049 return 1;
90050
90051 return 0;
90052@@ -3725,7 +3790,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
90053
90054 s = find_mergeable(memcg, size, align, flags, name, ctor);
90055 if (s) {
90056- s->refcount++;
90057+ atomic_inc(&s->refcount);
90058 /*
90059 * Adjust the object sizes so that we clear
90060 * the complete object on kzalloc.
90061@@ -3734,7 +3799,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
90062 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
90063
90064 if (sysfs_slab_alias(s, name)) {
90065- s->refcount--;
90066+ atomic_dec(&s->refcount);
90067 s = NULL;
90068 }
90069 }
90070@@ -3854,7 +3919,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
90071 }
90072 #endif
90073
90074-#ifdef CONFIG_SYSFS
90075+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90076 static int count_inuse(struct page *page)
90077 {
90078 return page->inuse;
90079@@ -4241,12 +4306,12 @@ static void resiliency_test(void)
90080 validate_slab_cache(kmalloc_caches[9]);
90081 }
90082 #else
90083-#ifdef CONFIG_SYSFS
90084+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90085 static void resiliency_test(void) {};
90086 #endif
90087 #endif
90088
90089-#ifdef CONFIG_SYSFS
90090+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90091 enum slab_stat_type {
90092 SL_ALL, /* All slabs */
90093 SL_PARTIAL, /* Only partially allocated slabs */
90094@@ -4490,7 +4555,7 @@ SLAB_ATTR_RO(ctor);
90095
90096 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
90097 {
90098- return sprintf(buf, "%d\n", s->refcount - 1);
90099+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
90100 }
90101 SLAB_ATTR_RO(aliases);
90102
90103@@ -4578,6 +4643,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
90104 SLAB_ATTR_RO(cache_dma);
90105 #endif
90106
90107+#ifdef CONFIG_PAX_USERCOPY_SLABS
90108+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
90109+{
90110+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
90111+}
90112+SLAB_ATTR_RO(usercopy);
90113+#endif
90114+
90115 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
90116 {
90117 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
90118@@ -4912,6 +4985,9 @@ static struct attribute *slab_attrs[] = {
90119 #ifdef CONFIG_ZONE_DMA
90120 &cache_dma_attr.attr,
90121 #endif
90122+#ifdef CONFIG_PAX_USERCOPY_SLABS
90123+ &usercopy_attr.attr,
90124+#endif
90125 #ifdef CONFIG_NUMA
90126 &remote_node_defrag_ratio_attr.attr,
90127 #endif
90128@@ -5143,6 +5219,7 @@ static char *create_unique_id(struct kmem_cache *s)
90129 return name;
90130 }
90131
90132+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90133 static int sysfs_slab_add(struct kmem_cache *s)
90134 {
90135 int err;
90136@@ -5166,7 +5243,7 @@ static int sysfs_slab_add(struct kmem_cache *s)
90137 }
90138
90139 s->kobj.kset = slab_kset;
90140- err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, name);
90141+ err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
90142 if (err) {
90143 kobject_put(&s->kobj);
90144 return err;
90145@@ -5200,6 +5277,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
90146 kobject_del(&s->kobj);
90147 kobject_put(&s->kobj);
90148 }
90149+#endif
90150
90151 /*
90152 * Need to buffer aliases during bootup until sysfs becomes
90153@@ -5213,6 +5291,7 @@ struct saved_alias {
90154
90155 static struct saved_alias *alias_list;
90156
90157+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90158 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
90159 {
90160 struct saved_alias *al;
90161@@ -5235,6 +5314,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
90162 alias_list = al;
90163 return 0;
90164 }
90165+#endif
90166
90167 static int __init slab_sysfs_init(void)
90168 {
90169diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
90170index 27eeab3..7c3f7f2 100644
90171--- a/mm/sparse-vmemmap.c
90172+++ b/mm/sparse-vmemmap.c
90173@@ -130,7 +130,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
90174 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
90175 if (!p)
90176 return NULL;
90177- pud_populate(&init_mm, pud, p);
90178+ pud_populate_kernel(&init_mm, pud, p);
90179 }
90180 return pud;
90181 }
90182@@ -142,7 +142,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
90183 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
90184 if (!p)
90185 return NULL;
90186- pgd_populate(&init_mm, pgd, p);
90187+ pgd_populate_kernel(&init_mm, pgd, p);
90188 }
90189 return pgd;
90190 }
90191diff --git a/mm/sparse.c b/mm/sparse.c
90192index 308d503..3dbbd04 100644
90193--- a/mm/sparse.c
90194+++ b/mm/sparse.c
90195@@ -764,7 +764,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
90196
90197 for (i = 0; i < PAGES_PER_SECTION; i++) {
90198 if (PageHWPoison(&memmap[i])) {
90199- atomic_long_sub(1, &num_poisoned_pages);
90200+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
90201 ClearPageHWPoison(&memmap[i]);
90202 }
90203 }
90204diff --git a/mm/swap.c b/mm/swap.c
90205index c899502..d4dc2cd 100644
90206--- a/mm/swap.c
90207+++ b/mm/swap.c
90208@@ -77,6 +77,8 @@ static void __put_compound_page(struct page *page)
90209
90210 __page_cache_release(page);
90211 dtor = get_compound_page_dtor(page);
90212+ if (!PageHuge(page))
90213+ BUG_ON(dtor != free_compound_page);
90214 (*dtor)(page);
90215 }
90216
90217diff --git a/mm/swapfile.c b/mm/swapfile.c
90218index 6cf2e60..d204b3e 100644
90219--- a/mm/swapfile.c
90220+++ b/mm/swapfile.c
90221@@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
90222
90223 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
90224 /* Activity counter to indicate that a swapon or swapoff has occurred */
90225-static atomic_t proc_poll_event = ATOMIC_INIT(0);
90226+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
90227
90228 static inline unsigned char swap_count(unsigned char ent)
90229 {
90230@@ -1699,7 +1699,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
90231 }
90232 filp_close(swap_file, NULL);
90233 err = 0;
90234- atomic_inc(&proc_poll_event);
90235+ atomic_inc_unchecked(&proc_poll_event);
90236 wake_up_interruptible(&proc_poll_wait);
90237
90238 out_dput:
90239@@ -1716,8 +1716,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
90240
90241 poll_wait(file, &proc_poll_wait, wait);
90242
90243- if (seq->poll_event != atomic_read(&proc_poll_event)) {
90244- seq->poll_event = atomic_read(&proc_poll_event);
90245+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
90246+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
90247 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
90248 }
90249
90250@@ -1815,7 +1815,7 @@ static int swaps_open(struct inode *inode, struct file *file)
90251 return ret;
90252
90253 seq = file->private_data;
90254- seq->poll_event = atomic_read(&proc_poll_event);
90255+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
90256 return 0;
90257 }
90258
90259@@ -2203,7 +2203,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
90260 (frontswap_map) ? "FS" : "");
90261
90262 mutex_unlock(&swapon_mutex);
90263- atomic_inc(&proc_poll_event);
90264+ atomic_inc_unchecked(&proc_poll_event);
90265 wake_up_interruptible(&proc_poll_wait);
90266
90267 if (S_ISREG(inode->i_mode))
90268diff --git a/mm/util.c b/mm/util.c
90269index 7441c41..c3de793 100644
90270--- a/mm/util.c
90271+++ b/mm/util.c
90272@@ -294,6 +294,12 @@ done:
90273 void arch_pick_mmap_layout(struct mm_struct *mm)
90274 {
90275 mm->mmap_base = TASK_UNMAPPED_BASE;
90276+
90277+#ifdef CONFIG_PAX_RANDMMAP
90278+ if (mm->pax_flags & MF_PAX_RANDMMAP)
90279+ mm->mmap_base += mm->delta_mmap;
90280+#endif
90281+
90282 mm->get_unmapped_area = arch_get_unmapped_area;
90283 }
90284 #endif
90285diff --git a/mm/vmalloc.c b/mm/vmalloc.c
90286index 13a5495..6707d97 100644
90287--- a/mm/vmalloc.c
90288+++ b/mm/vmalloc.c
90289@@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
90290
90291 pte = pte_offset_kernel(pmd, addr);
90292 do {
90293- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
90294- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
90295+
90296+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90297+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
90298+ BUG_ON(!pte_exec(*pte));
90299+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
90300+ continue;
90301+ }
90302+#endif
90303+
90304+ {
90305+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
90306+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
90307+ }
90308 } while (pte++, addr += PAGE_SIZE, addr != end);
90309 }
90310
90311@@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
90312 pte = pte_alloc_kernel(pmd, addr);
90313 if (!pte)
90314 return -ENOMEM;
90315+
90316+ pax_open_kernel();
90317 do {
90318 struct page *page = pages[*nr];
90319
90320- if (WARN_ON(!pte_none(*pte)))
90321+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90322+ if (pgprot_val(prot) & _PAGE_NX)
90323+#endif
90324+
90325+ if (!pte_none(*pte)) {
90326+ pax_close_kernel();
90327+ WARN_ON(1);
90328 return -EBUSY;
90329- if (WARN_ON(!page))
90330+ }
90331+ if (!page) {
90332+ pax_close_kernel();
90333+ WARN_ON(1);
90334 return -ENOMEM;
90335+ }
90336 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
90337 (*nr)++;
90338 } while (pte++, addr += PAGE_SIZE, addr != end);
90339+ pax_close_kernel();
90340 return 0;
90341 }
90342
90343@@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
90344 pmd_t *pmd;
90345 unsigned long next;
90346
90347- pmd = pmd_alloc(&init_mm, pud, addr);
90348+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
90349 if (!pmd)
90350 return -ENOMEM;
90351 do {
90352@@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
90353 pud_t *pud;
90354 unsigned long next;
90355
90356- pud = pud_alloc(&init_mm, pgd, addr);
90357+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
90358 if (!pud)
90359 return -ENOMEM;
90360 do {
90361@@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
90362 if (addr >= MODULES_VADDR && addr < MODULES_END)
90363 return 1;
90364 #endif
90365+
90366+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90367+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
90368+ return 1;
90369+#endif
90370+
90371 return is_vmalloc_addr(x);
90372 }
90373
90374@@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
90375
90376 if (!pgd_none(*pgd)) {
90377 pud_t *pud = pud_offset(pgd, addr);
90378+#ifdef CONFIG_X86
90379+ if (!pud_large(*pud))
90380+#endif
90381 if (!pud_none(*pud)) {
90382 pmd_t *pmd = pmd_offset(pud, addr);
90383+#ifdef CONFIG_X86
90384+ if (!pmd_large(*pmd))
90385+#endif
90386 if (!pmd_none(*pmd)) {
90387 pte_t *ptep, pte;
90388
90389@@ -339,7 +375,7 @@ static void purge_vmap_area_lazy(void);
90390 * Allocate a region of KVA of the specified size and alignment, within the
90391 * vstart and vend.
90392 */
90393-static struct vmap_area *alloc_vmap_area(unsigned long size,
90394+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
90395 unsigned long align,
90396 unsigned long vstart, unsigned long vend,
90397 int node, gfp_t gfp_mask)
90398@@ -1308,6 +1344,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
90399 struct vm_struct *area;
90400
90401 BUG_ON(in_interrupt());
90402+
90403+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
90404+ if (flags & VM_KERNEXEC) {
90405+ if (start != VMALLOC_START || end != VMALLOC_END)
90406+ return NULL;
90407+ start = (unsigned long)MODULES_EXEC_VADDR;
90408+ end = (unsigned long)MODULES_EXEC_END;
90409+ }
90410+#endif
90411+
90412 if (flags & VM_IOREMAP)
90413 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
90414
90415@@ -1533,6 +1579,11 @@ void *vmap(struct page **pages, unsigned int count,
90416 if (count > totalram_pages)
90417 return NULL;
90418
90419+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
90420+ if (!(pgprot_val(prot) & _PAGE_NX))
90421+ flags |= VM_KERNEXEC;
90422+#endif
90423+
90424 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
90425 __builtin_return_address(0));
90426 if (!area)
90427@@ -1634,6 +1685,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
90428 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
90429 goto fail;
90430
90431+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
90432+ if (!(pgprot_val(prot) & _PAGE_NX))
90433+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
90434+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
90435+ else
90436+#endif
90437+
90438 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
90439 start, end, node, gfp_mask, caller);
90440 if (!area)
90441@@ -1810,10 +1868,9 @@ EXPORT_SYMBOL(vzalloc_node);
90442 * For tight control over page level allocator and protection flags
90443 * use __vmalloc() instead.
90444 */
90445-
90446 void *vmalloc_exec(unsigned long size)
90447 {
90448- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
90449+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
90450 NUMA_NO_NODE, __builtin_return_address(0));
90451 }
90452
90453@@ -2120,6 +2177,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
90454 {
90455 struct vm_struct *area;
90456
90457+ BUG_ON(vma->vm_mirror);
90458+
90459 size = PAGE_ALIGN(size);
90460
90461 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
90462@@ -2605,7 +2664,11 @@ static int s_show(struct seq_file *m, void *p)
90463 v->addr, v->addr + v->size, v->size);
90464
90465 if (v->caller)
90466+#ifdef CONFIG_GRKERNSEC_HIDESYM
90467+ seq_printf(m, " %pK", v->caller);
90468+#else
90469 seq_printf(m, " %pS", v->caller);
90470+#endif
90471
90472 if (v->nr_pages)
90473 seq_printf(m, " pages=%d", v->nr_pages);
90474diff --git a/mm/vmstat.c b/mm/vmstat.c
90475index 20c2ef4..15e7ab7 100644
90476--- a/mm/vmstat.c
90477+++ b/mm/vmstat.c
90478@@ -76,7 +76,7 @@ void vm_events_fold_cpu(int cpu)
90479 *
90480 * vm_stat contains the global counters
90481 */
90482-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
90483+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
90484 EXPORT_SYMBOL(vm_stat);
90485
90486 #ifdef CONFIG_SMP
90487@@ -452,7 +452,7 @@ void refresh_cpu_vm_stats(int cpu)
90488 v = p->vm_stat_diff[i];
90489 p->vm_stat_diff[i] = 0;
90490 local_irq_restore(flags);
90491- atomic_long_add(v, &zone->vm_stat[i]);
90492+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
90493 global_diff[i] += v;
90494 #ifdef CONFIG_NUMA
90495 /* 3 seconds idle till flush */
90496@@ -490,7 +490,7 @@ void refresh_cpu_vm_stats(int cpu)
90497
90498 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
90499 if (global_diff[i])
90500- atomic_long_add(global_diff[i], &vm_stat[i]);
90501+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
90502 }
90503
90504 /*
90505@@ -505,8 +505,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
90506 if (pset->vm_stat_diff[i]) {
90507 int v = pset->vm_stat_diff[i];
90508 pset->vm_stat_diff[i] = 0;
90509- atomic_long_add(v, &zone->vm_stat[i]);
90510- atomic_long_add(v, &vm_stat[i]);
90511+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
90512+ atomic_long_add_unchecked(v, &vm_stat[i]);
90513 }
90514 }
90515 #endif
90516@@ -1241,10 +1241,20 @@ static int __init setup_vmstat(void)
90517 start_cpu_timer(cpu);
90518 #endif
90519 #ifdef CONFIG_PROC_FS
90520- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
90521- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
90522- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
90523- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
90524+ {
90525+ mode_t gr_mode = S_IRUGO;
90526+#ifdef CONFIG_GRKERNSEC_PROC_ADD
90527+ gr_mode = S_IRUSR;
90528+#endif
90529+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
90530+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
90531+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
90532+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
90533+#else
90534+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
90535+#endif
90536+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
90537+ }
90538 #endif
90539 return 0;
90540 }
90541diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
90542index 2fb2d88..8c06e40 100644
90543--- a/net/8021q/vlan.c
90544+++ b/net/8021q/vlan.c
90545@@ -469,7 +469,7 @@ out:
90546 return NOTIFY_DONE;
90547 }
90548
90549-static struct notifier_block vlan_notifier_block __read_mostly = {
90550+static struct notifier_block vlan_notifier_block = {
90551 .notifier_call = vlan_device_event,
90552 };
90553
90554@@ -544,8 +544,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
90555 err = -EPERM;
90556 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
90557 break;
90558- if ((args.u.name_type >= 0) &&
90559- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
90560+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
90561 struct vlan_net *vn;
90562
90563 vn = net_generic(net, vlan_net_id);
90564diff --git a/net/8021q/vlan_netlink.c b/net/8021q/vlan_netlink.c
90565index 3091297..c7e634a 100644
90566--- a/net/8021q/vlan_netlink.c
90567+++ b/net/8021q/vlan_netlink.c
90568@@ -171,7 +171,7 @@ static size_t vlan_get_size(const struct net_device *dev)
90569
90570 return nla_total_size(2) + /* IFLA_VLAN_PROTOCOL */
90571 nla_total_size(2) + /* IFLA_VLAN_ID */
90572- sizeof(struct ifla_vlan_flags) + /* IFLA_VLAN_FLAGS */
90573+ nla_total_size(sizeof(struct ifla_vlan_flags)) + /* IFLA_VLAN_FLAGS */
90574 vlan_qos_map_size(vlan->nr_ingress_mappings) +
90575 vlan_qos_map_size(vlan->nr_egress_mappings);
90576 }
90577diff --git a/net/9p/mod.c b/net/9p/mod.c
90578index 6ab36ae..6f1841b 100644
90579--- a/net/9p/mod.c
90580+++ b/net/9p/mod.c
90581@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
90582 void v9fs_register_trans(struct p9_trans_module *m)
90583 {
90584 spin_lock(&v9fs_trans_lock);
90585- list_add_tail(&m->list, &v9fs_trans_list);
90586+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
90587 spin_unlock(&v9fs_trans_lock);
90588 }
90589 EXPORT_SYMBOL(v9fs_register_trans);
90590@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
90591 void v9fs_unregister_trans(struct p9_trans_module *m)
90592 {
90593 spin_lock(&v9fs_trans_lock);
90594- list_del_init(&m->list);
90595+ pax_list_del_init((struct list_head *)&m->list);
90596 spin_unlock(&v9fs_trans_lock);
90597 }
90598 EXPORT_SYMBOL(v9fs_unregister_trans);
90599diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
90600index 3ffda1b..fceac96 100644
90601--- a/net/9p/trans_fd.c
90602+++ b/net/9p/trans_fd.c
90603@@ -432,7 +432,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
90604 oldfs = get_fs();
90605 set_fs(get_ds());
90606 /* The cast to a user pointer is valid due to the set_fs() */
90607- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
90608+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
90609 set_fs(oldfs);
90610
90611 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
90612diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
90613index 876fbe8..8bbea9f 100644
90614--- a/net/atm/atm_misc.c
90615+++ b/net/atm/atm_misc.c
90616@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
90617 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
90618 return 1;
90619 atm_return(vcc, truesize);
90620- atomic_inc(&vcc->stats->rx_drop);
90621+ atomic_inc_unchecked(&vcc->stats->rx_drop);
90622 return 0;
90623 }
90624 EXPORT_SYMBOL(atm_charge);
90625@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
90626 }
90627 }
90628 atm_return(vcc, guess);
90629- atomic_inc(&vcc->stats->rx_drop);
90630+ atomic_inc_unchecked(&vcc->stats->rx_drop);
90631 return NULL;
90632 }
90633 EXPORT_SYMBOL(atm_alloc_charge);
90634@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
90635
90636 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
90637 {
90638-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
90639+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
90640 __SONET_ITEMS
90641 #undef __HANDLE_ITEM
90642 }
90643@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
90644
90645 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
90646 {
90647-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
90648+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
90649 __SONET_ITEMS
90650 #undef __HANDLE_ITEM
90651 }
90652diff --git a/net/atm/lec.h b/net/atm/lec.h
90653index 4149db1..f2ab682 100644
90654--- a/net/atm/lec.h
90655+++ b/net/atm/lec.h
90656@@ -48,7 +48,7 @@ struct lane2_ops {
90657 const u8 *tlvs, u32 sizeoftlvs);
90658 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
90659 const u8 *tlvs, u32 sizeoftlvs);
90660-};
90661+} __no_const;
90662
90663 /*
90664 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
90665diff --git a/net/atm/proc.c b/net/atm/proc.c
90666index bbb6461..cf04016 100644
90667--- a/net/atm/proc.c
90668+++ b/net/atm/proc.c
90669@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
90670 const struct k_atm_aal_stats *stats)
90671 {
90672 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
90673- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
90674- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
90675- atomic_read(&stats->rx_drop));
90676+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
90677+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
90678+ atomic_read_unchecked(&stats->rx_drop));
90679 }
90680
90681 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
90682diff --git a/net/atm/resources.c b/net/atm/resources.c
90683index 0447d5d..3cf4728 100644
90684--- a/net/atm/resources.c
90685+++ b/net/atm/resources.c
90686@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
90687 static void copy_aal_stats(struct k_atm_aal_stats *from,
90688 struct atm_aal_stats *to)
90689 {
90690-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
90691+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
90692 __AAL_STAT_ITEMS
90693 #undef __HANDLE_ITEM
90694 }
90695@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
90696 static void subtract_aal_stats(struct k_atm_aal_stats *from,
90697 struct atm_aal_stats *to)
90698 {
90699-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
90700+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
90701 __AAL_STAT_ITEMS
90702 #undef __HANDLE_ITEM
90703 }
90704diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
90705index 919a5ce..cc6b444 100644
90706--- a/net/ax25/sysctl_net_ax25.c
90707+++ b/net/ax25/sysctl_net_ax25.c
90708@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
90709 {
90710 char path[sizeof("net/ax25/") + IFNAMSIZ];
90711 int k;
90712- struct ctl_table *table;
90713+ ctl_table_no_const *table;
90714
90715 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
90716 if (!table)
90717diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
90718index 62da527..aa27535 100644
90719--- a/net/batman-adv/bat_iv_ogm.c
90720+++ b/net/batman-adv/bat_iv_ogm.c
90721@@ -120,7 +120,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
90722
90723 /* randomize initial seqno to avoid collision */
90724 get_random_bytes(&random_seqno, sizeof(random_seqno));
90725- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
90726+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
90727
90728 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
90729 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
90730@@ -701,9 +701,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
90731 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
90732
90733 /* change sequence number to network order */
90734- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
90735+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
90736 batadv_ogm_packet->seqno = htonl(seqno);
90737- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
90738+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
90739
90740 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
90741 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
90742@@ -1109,7 +1109,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
90743 return;
90744
90745 /* could be changed by schedule_own_packet() */
90746- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
90747+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
90748
90749 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
90750 has_directlink_flag = 1;
90751diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
90752index c478e6b..469fd2f 100644
90753--- a/net/batman-adv/hard-interface.c
90754+++ b/net/batman-adv/hard-interface.c
90755@@ -453,7 +453,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
90756 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
90757 dev_add_pack(&hard_iface->batman_adv_ptype);
90758
90759- atomic_set(&hard_iface->frag_seqno, 1);
90760+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
90761 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
90762 hard_iface->net_dev->name);
90763
90764diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
90765index 33b6144..3212ac5 100644
90766--- a/net/batman-adv/soft-interface.c
90767+++ b/net/batman-adv/soft-interface.c
90768@@ -261,7 +261,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
90769 primary_if->net_dev->dev_addr, ETH_ALEN);
90770
90771 /* set broadcast sequence number */
90772- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
90773+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
90774 bcast_packet->seqno = htonl(seqno);
90775
90776 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
90777@@ -481,7 +481,7 @@ static int batadv_softif_init_late(struct net_device *dev)
90778 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
90779
90780 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
90781- atomic_set(&bat_priv->bcast_seqno, 1);
90782+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
90783 atomic_set(&bat_priv->tt.vn, 0);
90784 atomic_set(&bat_priv->tt.local_changes, 0);
90785 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
90786diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
90787index b2c94e1..3d47e07 100644
90788--- a/net/batman-adv/types.h
90789+++ b/net/batman-adv/types.h
90790@@ -51,7 +51,7 @@
90791 struct batadv_hard_iface_bat_iv {
90792 unsigned char *ogm_buff;
90793 int ogm_buff_len;
90794- atomic_t ogm_seqno;
90795+ atomic_unchecked_t ogm_seqno;
90796 };
90797
90798 /**
90799@@ -76,7 +76,7 @@ struct batadv_hard_iface {
90800 int16_t if_num;
90801 char if_status;
90802 struct net_device *net_dev;
90803- atomic_t frag_seqno;
90804+ atomic_unchecked_t frag_seqno;
90805 uint8_t num_bcasts;
90806 struct kobject *hardif_obj;
90807 atomic_t refcount;
90808@@ -560,7 +560,7 @@ struct batadv_priv {
90809 #ifdef CONFIG_BATMAN_ADV_DEBUG
90810 atomic_t log_level;
90811 #endif
90812- atomic_t bcast_seqno;
90813+ atomic_unchecked_t bcast_seqno;
90814 atomic_t bcast_queue_left;
90815 atomic_t batman_queue_left;
90816 char num_ifaces;
90817diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
90818index 857e1b8..5ad07b2 100644
90819--- a/net/batman-adv/unicast.c
90820+++ b/net/batman-adv/unicast.c
90821@@ -270,7 +270,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
90822 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
90823 frag2->flags = large_tail;
90824
90825- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
90826+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
90827 frag1->seqno = htons(seqno - 1);
90828 frag2->seqno = htons(seqno);
90829
90830diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
90831index 9bd7d95..6c4884f 100644
90832--- a/net/bluetooth/hci_sock.c
90833+++ b/net/bluetooth/hci_sock.c
90834@@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
90835 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
90836 }
90837
90838- len = min_t(unsigned int, len, sizeof(uf));
90839+ len = min((size_t)len, sizeof(uf));
90840 if (copy_from_user(&uf, optval, len)) {
90841 err = -EFAULT;
90842 break;
90843diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
90844index 8c3499b..2661c6a 100644
90845--- a/net/bluetooth/l2cap_core.c
90846+++ b/net/bluetooth/l2cap_core.c
90847@@ -3510,8 +3510,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
90848 break;
90849
90850 case L2CAP_CONF_RFC:
90851- if (olen == sizeof(rfc))
90852- memcpy(&rfc, (void *)val, olen);
90853+ if (olen != sizeof(rfc))
90854+ break;
90855+
90856+ memcpy(&rfc, (void *)val, olen);
90857
90858 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
90859 rfc.mode != chan->mode)
90860diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
90861index 0098af8..fb5a31f 100644
90862--- a/net/bluetooth/l2cap_sock.c
90863+++ b/net/bluetooth/l2cap_sock.c
90864@@ -485,7 +485,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
90865 struct sock *sk = sock->sk;
90866 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
90867 struct l2cap_options opts;
90868- int len, err = 0;
90869+ int err = 0;
90870+ size_t len = optlen;
90871 u32 opt;
90872
90873 BT_DBG("sk %p", sk);
90874@@ -507,7 +508,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
90875 opts.max_tx = chan->max_tx;
90876 opts.txwin_size = chan->tx_win;
90877
90878- len = min_t(unsigned int, sizeof(opts), optlen);
90879+ len = min(sizeof(opts), len);
90880 if (copy_from_user((char *) &opts, optval, len)) {
90881 err = -EFAULT;
90882 break;
90883@@ -587,7 +588,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
90884 struct bt_security sec;
90885 struct bt_power pwr;
90886 struct l2cap_conn *conn;
90887- int len, err = 0;
90888+ int err = 0;
90889+ size_t len = optlen;
90890 u32 opt;
90891
90892 BT_DBG("sk %p", sk);
90893@@ -610,7 +612,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
90894
90895 sec.level = BT_SECURITY_LOW;
90896
90897- len = min_t(unsigned int, sizeof(sec), optlen);
90898+ len = min(sizeof(sec), len);
90899 if (copy_from_user((char *) &sec, optval, len)) {
90900 err = -EFAULT;
90901 break;
90902@@ -707,7 +709,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
90903
90904 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
90905
90906- len = min_t(unsigned int, sizeof(pwr), optlen);
90907+ len = min(sizeof(pwr), len);
90908 if (copy_from_user((char *) &pwr, optval, len)) {
90909 err = -EFAULT;
90910 break;
90911diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
90912index 30b3721..c1bd0a0 100644
90913--- a/net/bluetooth/rfcomm/sock.c
90914+++ b/net/bluetooth/rfcomm/sock.c
90915@@ -666,7 +666,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
90916 struct sock *sk = sock->sk;
90917 struct bt_security sec;
90918 int err = 0;
90919- size_t len;
90920+ size_t len = optlen;
90921 u32 opt;
90922
90923 BT_DBG("sk %p", sk);
90924@@ -688,7 +688,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
90925
90926 sec.level = BT_SECURITY_LOW;
90927
90928- len = min_t(unsigned int, sizeof(sec), optlen);
90929+ len = min(sizeof(sec), len);
90930 if (copy_from_user((char *) &sec, optval, len)) {
90931 err = -EFAULT;
90932 break;
90933diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
90934index b6e44ad..5b0d514 100644
90935--- a/net/bluetooth/rfcomm/tty.c
90936+++ b/net/bluetooth/rfcomm/tty.c
90937@@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
90938 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
90939
90940 spin_lock_irqsave(&dev->port.lock, flags);
90941- if (dev->port.count > 0) {
90942+ if (atomic_read(&dev->port.count) > 0) {
90943 spin_unlock_irqrestore(&dev->port.lock, flags);
90944 return;
90945 }
90946@@ -659,10 +659,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
90947 return -ENODEV;
90948
90949 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
90950- dev->channel, dev->port.count);
90951+ dev->channel, atomic_read(&dev->port.count));
90952
90953 spin_lock_irqsave(&dev->port.lock, flags);
90954- if (++dev->port.count > 1) {
90955+ if (atomic_inc_return(&dev->port.count) > 1) {
90956 spin_unlock_irqrestore(&dev->port.lock, flags);
90957 return 0;
90958 }
90959@@ -727,10 +727,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
90960 return;
90961
90962 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
90963- dev->port.count);
90964+ atomic_read(&dev->port.count));
90965
90966 spin_lock_irqsave(&dev->port.lock, flags);
90967- if (!--dev->port.count) {
90968+ if (!atomic_dec_return(&dev->port.count)) {
90969 spin_unlock_irqrestore(&dev->port.lock, flags);
90970 if (dev->tty_dev->parent)
90971 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
90972diff --git a/net/bridge/netfilter/ebt_ulog.c b/net/bridge/netfilter/ebt_ulog.c
90973index 5180938..7c470c3 100644
90974--- a/net/bridge/netfilter/ebt_ulog.c
90975+++ b/net/bridge/netfilter/ebt_ulog.c
90976@@ -181,6 +181,7 @@ static void ebt_ulog_packet(struct net *net, unsigned int hooknr,
90977 ub->qlen++;
90978
90979 pm = nlmsg_data(nlh);
90980+ memset(pm, 0, sizeof(*pm));
90981
90982 /* Fill in the ulog data */
90983 pm->version = EBT_ULOG_VERSION;
90984@@ -193,8 +194,6 @@ static void ebt_ulog_packet(struct net *net, unsigned int hooknr,
90985 pm->hook = hooknr;
90986 if (uloginfo->prefix != NULL)
90987 strcpy(pm->prefix, uloginfo->prefix);
90988- else
90989- *(pm->prefix) = '\0';
90990
90991 if (in) {
90992 strcpy(pm->physindev, in->name);
90993@@ -204,16 +203,14 @@ static void ebt_ulog_packet(struct net *net, unsigned int hooknr,
90994 strcpy(pm->indev, br_port_get_rcu(in)->br->dev->name);
90995 else
90996 strcpy(pm->indev, in->name);
90997- } else
90998- pm->indev[0] = pm->physindev[0] = '\0';
90999+ }
91000
91001 if (out) {
91002 /* If out exists, then out is a bridge port */
91003 strcpy(pm->physoutdev, out->name);
91004 /* rcu_read_lock()ed by nf_hook_slow */
91005 strcpy(pm->outdev, br_port_get_rcu(out)->br->dev->name);
91006- } else
91007- pm->outdev[0] = pm->physoutdev[0] = '\0';
91008+ }
91009
91010 if (skb_copy_bits(skb, -ETH_HLEN, pm->data, copy_len) < 0)
91011 BUG();
91012diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
91013index ac78024..161a80c 100644
91014--- a/net/bridge/netfilter/ebtables.c
91015+++ b/net/bridge/netfilter/ebtables.c
91016@@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
91017 tmp.valid_hooks = t->table->valid_hooks;
91018 }
91019 mutex_unlock(&ebt_mutex);
91020- if (copy_to_user(user, &tmp, *len) != 0){
91021+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
91022 BUGPRINT("c2u Didn't work\n");
91023 ret = -EFAULT;
91024 break;
91025@@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
91026 goto out;
91027 tmp.valid_hooks = t->valid_hooks;
91028
91029- if (copy_to_user(user, &tmp, *len) != 0) {
91030+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
91031 ret = -EFAULT;
91032 break;
91033 }
91034@@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
91035 tmp.entries_size = t->table->entries_size;
91036 tmp.valid_hooks = t->table->valid_hooks;
91037
91038- if (copy_to_user(user, &tmp, *len) != 0) {
91039+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
91040 ret = -EFAULT;
91041 break;
91042 }
91043diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
91044index 0f45522..dab651f 100644
91045--- a/net/caif/cfctrl.c
91046+++ b/net/caif/cfctrl.c
91047@@ -10,6 +10,7 @@
91048 #include <linux/spinlock.h>
91049 #include <linux/slab.h>
91050 #include <linux/pkt_sched.h>
91051+#include <linux/sched.h>
91052 #include <net/caif/caif_layer.h>
91053 #include <net/caif/cfpkt.h>
91054 #include <net/caif/cfctrl.h>
91055@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
91056 memset(&dev_info, 0, sizeof(dev_info));
91057 dev_info.id = 0xff;
91058 cfsrvl_init(&this->serv, 0, &dev_info, false);
91059- atomic_set(&this->req_seq_no, 1);
91060- atomic_set(&this->rsp_seq_no, 1);
91061+ atomic_set_unchecked(&this->req_seq_no, 1);
91062+ atomic_set_unchecked(&this->rsp_seq_no, 1);
91063 this->serv.layer.receive = cfctrl_recv;
91064 sprintf(this->serv.layer.name, "ctrl");
91065 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
91066@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
91067 struct cfctrl_request_info *req)
91068 {
91069 spin_lock_bh(&ctrl->info_list_lock);
91070- atomic_inc(&ctrl->req_seq_no);
91071- req->sequence_no = atomic_read(&ctrl->req_seq_no);
91072+ atomic_inc_unchecked(&ctrl->req_seq_no);
91073+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
91074 list_add_tail(&req->list, &ctrl->list);
91075 spin_unlock_bh(&ctrl->info_list_lock);
91076 }
91077@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
91078 if (p != first)
91079 pr_warn("Requests are not received in order\n");
91080
91081- atomic_set(&ctrl->rsp_seq_no,
91082+ atomic_set_unchecked(&ctrl->rsp_seq_no,
91083 p->sequence_no);
91084 list_del(&p->list);
91085 goto out;
91086diff --git a/net/can/af_can.c b/net/can/af_can.c
91087index 3ab8dd2..b9aef13 100644
91088--- a/net/can/af_can.c
91089+++ b/net/can/af_can.c
91090@@ -862,7 +862,7 @@ static const struct net_proto_family can_family_ops = {
91091 };
91092
91093 /* notifier block for netdevice event */
91094-static struct notifier_block can_netdev_notifier __read_mostly = {
91095+static struct notifier_block can_netdev_notifier = {
91096 .notifier_call = can_notifier,
91097 };
91098
91099diff --git a/net/can/gw.c b/net/can/gw.c
91100index 2f291f9..98c986a 100644
91101--- a/net/can/gw.c
91102+++ b/net/can/gw.c
91103@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
91104 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
91105
91106 static HLIST_HEAD(cgw_list);
91107-static struct notifier_block notifier;
91108
91109 static struct kmem_cache *cgw_cache __read_mostly;
91110
91111@@ -927,6 +926,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
91112 return err;
91113 }
91114
91115+static struct notifier_block notifier = {
91116+ .notifier_call = cgw_notifier
91117+};
91118+
91119 static __init int cgw_module_init(void)
91120 {
91121 /* sanitize given module parameter */
91122@@ -942,7 +945,6 @@ static __init int cgw_module_init(void)
91123 return -ENOMEM;
91124
91125 /* set notifier */
91126- notifier.notifier_call = cgw_notifier;
91127 register_netdevice_notifier(&notifier);
91128
91129 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
91130diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
91131index eb0a46a..5f3bae8 100644
91132--- a/net/ceph/messenger.c
91133+++ b/net/ceph/messenger.c
91134@@ -186,7 +186,7 @@ static void con_fault(struct ceph_connection *con);
91135 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
91136
91137 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
91138-static atomic_t addr_str_seq = ATOMIC_INIT(0);
91139+static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
91140
91141 static struct page *zero_page; /* used in certain error cases */
91142
91143@@ -197,7 +197,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
91144 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
91145 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
91146
91147- i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
91148+ i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
91149 s = addr_str[i];
91150
91151 switch (ss->ss_family) {
91152diff --git a/net/compat.c b/net/compat.c
91153index f0a1ba6..0541331 100644
91154--- a/net/compat.c
91155+++ b/net/compat.c
91156@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
91157 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
91158 __get_user(kmsg->msg_flags, &umsg->msg_flags))
91159 return -EFAULT;
91160- kmsg->msg_name = compat_ptr(tmp1);
91161- kmsg->msg_iov = compat_ptr(tmp2);
91162- kmsg->msg_control = compat_ptr(tmp3);
91163+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
91164+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
91165+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
91166 return 0;
91167 }
91168
91169@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
91170
91171 if (kern_msg->msg_namelen) {
91172 if (mode == VERIFY_READ) {
91173- int err = move_addr_to_kernel(kern_msg->msg_name,
91174+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
91175 kern_msg->msg_namelen,
91176 kern_address);
91177 if (err < 0)
91178@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
91179 kern_msg->msg_name = NULL;
91180
91181 tot_len = iov_from_user_compat_to_kern(kern_iov,
91182- (struct compat_iovec __user *)kern_msg->msg_iov,
91183+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
91184 kern_msg->msg_iovlen);
91185 if (tot_len >= 0)
91186 kern_msg->msg_iov = kern_iov;
91187@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
91188
91189 #define CMSG_COMPAT_FIRSTHDR(msg) \
91190 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
91191- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
91192+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
91193 (struct compat_cmsghdr __user *)NULL)
91194
91195 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
91196 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
91197 (ucmlen) <= (unsigned long) \
91198 ((mhdr)->msg_controllen - \
91199- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
91200+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
91201
91202 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
91203 struct compat_cmsghdr __user *cmsg, int cmsg_len)
91204 {
91205 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
91206- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
91207+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
91208 msg->msg_controllen)
91209 return NULL;
91210 return (struct compat_cmsghdr __user *)ptr;
91211@@ -219,7 +219,7 @@ Efault:
91212
91213 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
91214 {
91215- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
91216+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
91217 struct compat_cmsghdr cmhdr;
91218 struct compat_timeval ctv;
91219 struct compat_timespec cts[3];
91220@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
91221
91222 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
91223 {
91224- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
91225+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
91226 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
91227 int fdnum = scm->fp->count;
91228 struct file **fp = scm->fp->fp;
91229@@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
91230 return -EFAULT;
91231 old_fs = get_fs();
91232 set_fs(KERNEL_DS);
91233- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
91234+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
91235 set_fs(old_fs);
91236
91237 return err;
91238@@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
91239 len = sizeof(ktime);
91240 old_fs = get_fs();
91241 set_fs(KERNEL_DS);
91242- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
91243+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
91244 set_fs(old_fs);
91245
91246 if (!err) {
91247@@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
91248 case MCAST_JOIN_GROUP:
91249 case MCAST_LEAVE_GROUP:
91250 {
91251- struct compat_group_req __user *gr32 = (void *)optval;
91252+ struct compat_group_req __user *gr32 = (void __user *)optval;
91253 struct group_req __user *kgr =
91254 compat_alloc_user_space(sizeof(struct group_req));
91255 u32 interface;
91256@@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
91257 case MCAST_BLOCK_SOURCE:
91258 case MCAST_UNBLOCK_SOURCE:
91259 {
91260- struct compat_group_source_req __user *gsr32 = (void *)optval;
91261+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
91262 struct group_source_req __user *kgsr = compat_alloc_user_space(
91263 sizeof(struct group_source_req));
91264 u32 interface;
91265@@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
91266 }
91267 case MCAST_MSFILTER:
91268 {
91269- struct compat_group_filter __user *gf32 = (void *)optval;
91270+ struct compat_group_filter __user *gf32 = (void __user *)optval;
91271 struct group_filter __user *kgf;
91272 u32 interface, fmode, numsrc;
91273
91274@@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
91275 char __user *optval, int __user *optlen,
91276 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
91277 {
91278- struct compat_group_filter __user *gf32 = (void *)optval;
91279+ struct compat_group_filter __user *gf32 = (void __user *)optval;
91280 struct group_filter __user *kgf;
91281 int __user *koptlen;
91282 u32 interface, fmode, numsrc;
91283@@ -805,7 +805,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
91284
91285 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
91286 return -EINVAL;
91287- if (copy_from_user(a, args, nas[call]))
91288+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
91289 return -EFAULT;
91290 a0 = a[0];
91291 a1 = a[1];
91292diff --git a/net/core/datagram.c b/net/core/datagram.c
91293index 8ab48cd..57b1a80 100644
91294--- a/net/core/datagram.c
91295+++ b/net/core/datagram.c
91296@@ -300,7 +300,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
91297 }
91298
91299 kfree_skb(skb);
91300- atomic_inc(&sk->sk_drops);
91301+ atomic_inc_unchecked(&sk->sk_drops);
91302 sk_mem_reclaim_partial(sk);
91303
91304 return err;
91305diff --git a/net/core/dev.c b/net/core/dev.c
91306index 26755dd..2a232de 100644
91307--- a/net/core/dev.c
91308+++ b/net/core/dev.c
91309@@ -1680,14 +1680,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
91310 {
91311 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
91312 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
91313- atomic_long_inc(&dev->rx_dropped);
91314+ atomic_long_inc_unchecked(&dev->rx_dropped);
91315 kfree_skb(skb);
91316 return NET_RX_DROP;
91317 }
91318 }
91319
91320 if (unlikely(!is_skb_forwardable(dev, skb))) {
91321- atomic_long_inc(&dev->rx_dropped);
91322+ atomic_long_inc_unchecked(&dev->rx_dropped);
91323 kfree_skb(skb);
91324 return NET_RX_DROP;
91325 }
91326@@ -2431,7 +2431,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
91327
91328 struct dev_gso_cb {
91329 void (*destructor)(struct sk_buff *skb);
91330-};
91331+} __no_const;
91332
91333 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
91334
91335@@ -3206,7 +3206,7 @@ enqueue:
91336
91337 local_irq_restore(flags);
91338
91339- atomic_long_inc(&skb->dev->rx_dropped);
91340+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
91341 kfree_skb(skb);
91342 return NET_RX_DROP;
91343 }
91344@@ -3278,7 +3278,7 @@ int netif_rx_ni(struct sk_buff *skb)
91345 }
91346 EXPORT_SYMBOL(netif_rx_ni);
91347
91348-static void net_tx_action(struct softirq_action *h)
91349+static __latent_entropy void net_tx_action(void)
91350 {
91351 struct softnet_data *sd = &__get_cpu_var(softnet_data);
91352
91353@@ -3612,7 +3612,7 @@ ncls:
91354 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
91355 } else {
91356 drop:
91357- atomic_long_inc(&skb->dev->rx_dropped);
91358+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
91359 kfree_skb(skb);
91360 /* Jamal, now you will not able to escape explaining
91361 * me how you were going to use this. :-)
91362@@ -4272,7 +4272,7 @@ void netif_napi_del(struct napi_struct *napi)
91363 }
91364 EXPORT_SYMBOL(netif_napi_del);
91365
91366-static void net_rx_action(struct softirq_action *h)
91367+static __latent_entropy void net_rx_action(void)
91368 {
91369 struct softnet_data *sd = &__get_cpu_var(softnet_data);
91370 unsigned long time_limit = jiffies + 2;
91371@@ -5730,7 +5730,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
91372 } else {
91373 netdev_stats_to_stats64(storage, &dev->stats);
91374 }
91375- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
91376+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
91377 return storage;
91378 }
91379 EXPORT_SYMBOL(dev_get_stats);
91380diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
91381index 5b7d0e1..cb960fc 100644
91382--- a/net/core/dev_ioctl.c
91383+++ b/net/core/dev_ioctl.c
91384@@ -365,9 +365,13 @@ void dev_load(struct net *net, const char *name)
91385 if (no_module && capable(CAP_NET_ADMIN))
91386 no_module = request_module("netdev-%s", name);
91387 if (no_module && capable(CAP_SYS_MODULE)) {
91388+#ifdef CONFIG_GRKERNSEC_MODHARDEN
91389+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
91390+#else
91391 if (!request_module("%s", name))
91392 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
91393 name);
91394+#endif
91395 }
91396 }
91397 EXPORT_SYMBOL(dev_load);
91398diff --git a/net/core/flow.c b/net/core/flow.c
91399index dfa602c..3103d88 100644
91400--- a/net/core/flow.c
91401+++ b/net/core/flow.c
91402@@ -61,7 +61,7 @@ struct flow_cache {
91403 struct timer_list rnd_timer;
91404 };
91405
91406-atomic_t flow_cache_genid = ATOMIC_INIT(0);
91407+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
91408 EXPORT_SYMBOL(flow_cache_genid);
91409 static struct flow_cache flow_cache_global;
91410 static struct kmem_cache *flow_cachep __read_mostly;
91411@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
91412
91413 static int flow_entry_valid(struct flow_cache_entry *fle)
91414 {
91415- if (atomic_read(&flow_cache_genid) != fle->genid)
91416+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
91417 return 0;
91418 if (fle->object && !fle->object->ops->check(fle->object))
91419 return 0;
91420@@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
91421 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
91422 fcp->hash_count++;
91423 }
91424- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
91425+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
91426 flo = fle->object;
91427 if (!flo)
91428 goto ret_object;
91429@@ -279,7 +279,7 @@ nocache:
91430 }
91431 flo = resolver(net, key, family, dir, flo, ctx);
91432 if (fle) {
91433- fle->genid = atomic_read(&flow_cache_genid);
91434+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
91435 if (!IS_ERR(flo))
91436 fle->object = flo;
91437 else
91438diff --git a/net/core/iovec.c b/net/core/iovec.c
91439index de178e4..1dabd8b 100644
91440--- a/net/core/iovec.c
91441+++ b/net/core/iovec.c
91442@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
91443 if (m->msg_namelen) {
91444 if (mode == VERIFY_READ) {
91445 void __user *namep;
91446- namep = (void __user __force *) m->msg_name;
91447+ namep = (void __force_user *) m->msg_name;
91448 err = move_addr_to_kernel(namep, m->msg_namelen,
91449 address);
91450 if (err < 0)
91451@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
91452 }
91453
91454 size = m->msg_iovlen * sizeof(struct iovec);
91455- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
91456+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
91457 return -EFAULT;
91458
91459 m->msg_iov = iov;
91460diff --git a/net/core/neighbour.c b/net/core/neighbour.c
91461index 60533db..14842cc 100644
91462--- a/net/core/neighbour.c
91463+++ b/net/core/neighbour.c
91464@@ -2776,7 +2776,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
91465 void __user *buffer, size_t *lenp, loff_t *ppos)
91466 {
91467 int size, ret;
91468- struct ctl_table tmp = *ctl;
91469+ ctl_table_no_const tmp = *ctl;
91470
91471 tmp.extra1 = &zero;
91472 tmp.extra2 = &unres_qlen_max;
91473diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
91474index 2bf8329..7960607 100644
91475--- a/net/core/net-procfs.c
91476+++ b/net/core/net-procfs.c
91477@@ -283,8 +283,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
91478 else
91479 seq_printf(seq, "%04x", ntohs(pt->type));
91480
91481+#ifdef CONFIG_GRKERNSEC_HIDESYM
91482+ seq_printf(seq, " %-8s %pf\n",
91483+ pt->dev ? pt->dev->name : "", NULL);
91484+#else
91485 seq_printf(seq, " %-8s %pf\n",
91486 pt->dev ? pt->dev->name : "", pt->func);
91487+#endif
91488 }
91489
91490 return 0;
91491diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
91492index 981fed3..536af34 100644
91493--- a/net/core/net-sysfs.c
91494+++ b/net/core/net-sysfs.c
91495@@ -1311,7 +1311,7 @@ void netdev_class_remove_file(struct class_attribute *class_attr)
91496 }
91497 EXPORT_SYMBOL(netdev_class_remove_file);
91498
91499-int netdev_kobject_init(void)
91500+int __init netdev_kobject_init(void)
91501 {
91502 kobj_ns_type_register(&net_ns_type_operations);
91503 return class_register(&net_class);
91504diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
91505index f9765203..9feaef8 100644
91506--- a/net/core/net_namespace.c
91507+++ b/net/core/net_namespace.c
91508@@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
91509 int error;
91510 LIST_HEAD(net_exit_list);
91511
91512- list_add_tail(&ops->list, list);
91513+ pax_list_add_tail((struct list_head *)&ops->list, list);
91514 if (ops->init || (ops->id && ops->size)) {
91515 for_each_net(net) {
91516 error = ops_init(ops, net);
91517@@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
91518
91519 out_undo:
91520 /* If I have an error cleanup all namespaces I initialized */
91521- list_del(&ops->list);
91522+ pax_list_del((struct list_head *)&ops->list);
91523 ops_exit_list(ops, &net_exit_list);
91524 ops_free_list(ops, &net_exit_list);
91525 return error;
91526@@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
91527 struct net *net;
91528 LIST_HEAD(net_exit_list);
91529
91530- list_del(&ops->list);
91531+ pax_list_del((struct list_head *)&ops->list);
91532 for_each_net(net)
91533 list_add_tail(&net->exit_list, &net_exit_list);
91534 ops_exit_list(ops, &net_exit_list);
91535@@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
91536 mutex_lock(&net_mutex);
91537 error = register_pernet_operations(&pernet_list, ops);
91538 if (!error && (first_device == &pernet_list))
91539- first_device = &ops->list;
91540+ first_device = (struct list_head *)&ops->list;
91541 mutex_unlock(&net_mutex);
91542 return error;
91543 }
91544diff --git a/net/core/netpoll.c b/net/core/netpoll.c
91545index fc75c9e..8c8e9be 100644
91546--- a/net/core/netpoll.c
91547+++ b/net/core/netpoll.c
91548@@ -428,7 +428,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
91549 struct udphdr *udph;
91550 struct iphdr *iph;
91551 struct ethhdr *eth;
91552- static atomic_t ip_ident;
91553+ static atomic_unchecked_t ip_ident;
91554 struct ipv6hdr *ip6h;
91555
91556 udp_len = len + sizeof(*udph);
91557@@ -499,7 +499,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
91558 put_unaligned(0x45, (unsigned char *)iph);
91559 iph->tos = 0;
91560 put_unaligned(htons(ip_len), &(iph->tot_len));
91561- iph->id = htons(atomic_inc_return(&ip_ident));
91562+ iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
91563 iph->frag_off = 0;
91564 iph->ttl = 64;
91565 iph->protocol = IPPROTO_UDP;
91566diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
91567index ca198c1d1..125372f 100644
91568--- a/net/core/rtnetlink.c
91569+++ b/net/core/rtnetlink.c
91570@@ -58,7 +58,7 @@ struct rtnl_link {
91571 rtnl_doit_func doit;
91572 rtnl_dumpit_func dumpit;
91573 rtnl_calcit_func calcit;
91574-};
91575+} __no_const;
91576
91577 static DEFINE_MUTEX(rtnl_mutex);
91578
91579@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
91580 if (rtnl_link_ops_get(ops->kind))
91581 return -EEXIST;
91582
91583- if (!ops->dellink)
91584- ops->dellink = unregister_netdevice_queue;
91585+ if (!ops->dellink) {
91586+ pax_open_kernel();
91587+ *(void **)&ops->dellink = unregister_netdevice_queue;
91588+ pax_close_kernel();
91589+ }
91590
91591- list_add_tail(&ops->list, &link_ops);
91592+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
91593 return 0;
91594 }
91595 EXPORT_SYMBOL_GPL(__rtnl_link_register);
91596@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
91597 for_each_net(net) {
91598 __rtnl_kill_links(net, ops);
91599 }
91600- list_del(&ops->list);
91601+ pax_list_del((struct list_head *)&ops->list);
91602 }
91603 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
91604
91605diff --git a/net/core/scm.c b/net/core/scm.c
91606index b4da80b..98d6bdb 100644
91607--- a/net/core/scm.c
91608+++ b/net/core/scm.c
91609@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
91610 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
91611 {
91612 struct cmsghdr __user *cm
91613- = (__force struct cmsghdr __user *)msg->msg_control;
91614+ = (struct cmsghdr __force_user *)msg->msg_control;
91615 struct cmsghdr cmhdr;
91616 int cmlen = CMSG_LEN(len);
91617 int err;
91618@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
91619 err = -EFAULT;
91620 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
91621 goto out;
91622- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
91623+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
91624 goto out;
91625 cmlen = CMSG_SPACE(len);
91626 if (msg->msg_controllen < cmlen)
91627@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
91628 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
91629 {
91630 struct cmsghdr __user *cm
91631- = (__force struct cmsghdr __user*)msg->msg_control;
91632+ = (struct cmsghdr __force_user *)msg->msg_control;
91633
91634 int fdmax = 0;
91635 int fdnum = scm->fp->count;
91636@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
91637 if (fdnum < fdmax)
91638 fdmax = fdnum;
91639
91640- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
91641+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
91642 i++, cmfptr++)
91643 {
91644 struct socket *sock;
91645diff --git a/net/core/skbuff.c b/net/core/skbuff.c
91646index 2c3d0f5..f5a326f 100644
91647--- a/net/core/skbuff.c
91648+++ b/net/core/skbuff.c
91649@@ -3082,13 +3082,15 @@ void __init skb_init(void)
91650 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
91651 sizeof(struct sk_buff),
91652 0,
91653- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
91654+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
91655+ SLAB_NO_SANITIZE,
91656 NULL);
91657 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
91658 (2*sizeof(struct sk_buff)) +
91659 sizeof(atomic_t),
91660 0,
91661- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
91662+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
91663+ SLAB_NO_SANITIZE,
91664 NULL);
91665 }
91666
91667diff --git a/net/core/sock.c b/net/core/sock.c
91668index 2c097c5..bf72858 100644
91669--- a/net/core/sock.c
91670+++ b/net/core/sock.c
91671@@ -392,7 +392,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
91672 struct sk_buff_head *list = &sk->sk_receive_queue;
91673
91674 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
91675- atomic_inc(&sk->sk_drops);
91676+ atomic_inc_unchecked(&sk->sk_drops);
91677 trace_sock_rcvqueue_full(sk, skb);
91678 return -ENOMEM;
91679 }
91680@@ -402,7 +402,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
91681 return err;
91682
91683 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
91684- atomic_inc(&sk->sk_drops);
91685+ atomic_inc_unchecked(&sk->sk_drops);
91686 return -ENOBUFS;
91687 }
91688
91689@@ -422,7 +422,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
91690 skb_dst_force(skb);
91691
91692 spin_lock_irqsave(&list->lock, flags);
91693- skb->dropcount = atomic_read(&sk->sk_drops);
91694+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
91695 __skb_queue_tail(list, skb);
91696 spin_unlock_irqrestore(&list->lock, flags);
91697
91698@@ -442,7 +442,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
91699 skb->dev = NULL;
91700
91701 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
91702- atomic_inc(&sk->sk_drops);
91703+ atomic_inc_unchecked(&sk->sk_drops);
91704 goto discard_and_relse;
91705 }
91706 if (nested)
91707@@ -460,7 +460,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
91708 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
91709 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
91710 bh_unlock_sock(sk);
91711- atomic_inc(&sk->sk_drops);
91712+ atomic_inc_unchecked(&sk->sk_drops);
91713 goto discard_and_relse;
91714 }
91715
91716@@ -948,12 +948,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
91717 struct timeval tm;
91718 } v;
91719
91720- int lv = sizeof(int);
91721- int len;
91722+ unsigned int lv = sizeof(int);
91723+ unsigned int len;
91724
91725 if (get_user(len, optlen))
91726 return -EFAULT;
91727- if (len < 0)
91728+ if (len > INT_MAX)
91729 return -EINVAL;
91730
91731 memset(&v, 0, sizeof(v));
91732@@ -1105,11 +1105,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
91733
91734 case SO_PEERNAME:
91735 {
91736- char address[128];
91737+ char address[_K_SS_MAXSIZE];
91738
91739 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
91740 return -ENOTCONN;
91741- if (lv < len)
91742+ if (lv < len || sizeof address < len)
91743 return -EINVAL;
91744 if (copy_to_user(optval, address, len))
91745 return -EFAULT;
91746@@ -1182,7 +1182,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
91747
91748 if (len > lv)
91749 len = lv;
91750- if (copy_to_user(optval, &v, len))
91751+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
91752 return -EFAULT;
91753 lenout:
91754 if (put_user(len, optlen))
91755@@ -2303,7 +2303,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
91756 */
91757 smp_wmb();
91758 atomic_set(&sk->sk_refcnt, 1);
91759- atomic_set(&sk->sk_drops, 0);
91760+ atomic_set_unchecked(&sk->sk_drops, 0);
91761 }
91762 EXPORT_SYMBOL(sock_init_data);
91763
91764diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
91765index a0e9cf6..ef7f9ed 100644
91766--- a/net/core/sock_diag.c
91767+++ b/net/core/sock_diag.c
91768@@ -9,26 +9,33 @@
91769 #include <linux/inet_diag.h>
91770 #include <linux/sock_diag.h>
91771
91772-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
91773+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
91774 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
91775 static DEFINE_MUTEX(sock_diag_table_mutex);
91776
91777 int sock_diag_check_cookie(void *sk, __u32 *cookie)
91778 {
91779+#ifndef CONFIG_GRKERNSEC_HIDESYM
91780 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
91781 cookie[1] != INET_DIAG_NOCOOKIE) &&
91782 ((u32)(unsigned long)sk != cookie[0] ||
91783 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
91784 return -ESTALE;
91785 else
91786+#endif
91787 return 0;
91788 }
91789 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
91790
91791 void sock_diag_save_cookie(void *sk, __u32 *cookie)
91792 {
91793+#ifdef CONFIG_GRKERNSEC_HIDESYM
91794+ cookie[0] = 0;
91795+ cookie[1] = 0;
91796+#else
91797 cookie[0] = (u32)(unsigned long)sk;
91798 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
91799+#endif
91800 }
91801 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
91802
91803@@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
91804 mutex_lock(&sock_diag_table_mutex);
91805 if (sock_diag_handlers[hndl->family])
91806 err = -EBUSY;
91807- else
91808+ else {
91809+ pax_open_kernel();
91810 sock_diag_handlers[hndl->family] = hndl;
91811+ pax_close_kernel();
91812+ }
91813 mutex_unlock(&sock_diag_table_mutex);
91814
91815 return err;
91816@@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
91817
91818 mutex_lock(&sock_diag_table_mutex);
91819 BUG_ON(sock_diag_handlers[family] != hnld);
91820+ pax_open_kernel();
91821 sock_diag_handlers[family] = NULL;
91822+ pax_close_kernel();
91823 mutex_unlock(&sock_diag_table_mutex);
91824 }
91825 EXPORT_SYMBOL_GPL(sock_diag_unregister);
91826diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
91827index 31107ab..ae03d5a 100644
91828--- a/net/core/sysctl_net_core.c
91829+++ b/net/core/sysctl_net_core.c
91830@@ -31,7 +31,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
91831 {
91832 unsigned int orig_size, size;
91833 int ret, i;
91834- struct ctl_table tmp = {
91835+ ctl_table_no_const tmp = {
91836 .data = &size,
91837 .maxlen = sizeof(size),
91838 .mode = table->mode
91839@@ -350,13 +350,12 @@ static struct ctl_table netns_core_table[] = {
91840
91841 static __net_init int sysctl_core_net_init(struct net *net)
91842 {
91843- struct ctl_table *tbl;
91844+ ctl_table_no_const *tbl = NULL;
91845
91846 net->core.sysctl_somaxconn = SOMAXCONN;
91847
91848- tbl = netns_core_table;
91849 if (!net_eq(net, &init_net)) {
91850- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
91851+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
91852 if (tbl == NULL)
91853 goto err_dup;
91854
91855@@ -366,17 +365,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
91856 if (net->user_ns != &init_user_ns) {
91857 tbl[0].procname = NULL;
91858 }
91859- }
91860-
91861- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
91862+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
91863+ } else
91864+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
91865 if (net->core.sysctl_hdr == NULL)
91866 goto err_reg;
91867
91868 return 0;
91869
91870 err_reg:
91871- if (tbl != netns_core_table)
91872- kfree(tbl);
91873+ kfree(tbl);
91874 err_dup:
91875 return -ENOMEM;
91876 }
91877@@ -391,7 +389,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
91878 kfree(tbl);
91879 }
91880
91881-static __net_initdata struct pernet_operations sysctl_core_ops = {
91882+static __net_initconst struct pernet_operations sysctl_core_ops = {
91883 .init = sysctl_core_net_init,
91884 .exit = sysctl_core_net_exit,
91885 };
91886diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
91887index dd4d506..fb2fb87 100644
91888--- a/net/decnet/af_decnet.c
91889+++ b/net/decnet/af_decnet.c
91890@@ -465,6 +465,7 @@ static struct proto dn_proto = {
91891 .sysctl_rmem = sysctl_decnet_rmem,
91892 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
91893 .obj_size = sizeof(struct dn_sock),
91894+ .slab_flags = SLAB_USERCOPY,
91895 };
91896
91897 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
91898diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
91899index 5325b54..a0d4d69 100644
91900--- a/net/decnet/sysctl_net_decnet.c
91901+++ b/net/decnet/sysctl_net_decnet.c
91902@@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
91903
91904 if (len > *lenp) len = *lenp;
91905
91906- if (copy_to_user(buffer, addr, len))
91907+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
91908 return -EFAULT;
91909
91910 *lenp = len;
91911@@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
91912
91913 if (len > *lenp) len = *lenp;
91914
91915- if (copy_to_user(buffer, devname, len))
91916+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
91917 return -EFAULT;
91918
91919 *lenp = len;
91920diff --git a/net/ieee802154/6lowpan.c b/net/ieee802154/6lowpan.c
91921index 3b9d5f2..d7015c6 100644
91922--- a/net/ieee802154/6lowpan.c
91923+++ b/net/ieee802154/6lowpan.c
91924@@ -459,7 +459,7 @@ static int lowpan_header_create(struct sk_buff *skb,
91925 hc06_ptr += 3;
91926 } else {
91927 /* compress nothing */
91928- memcpy(hc06_ptr, &hdr, 4);
91929+ memcpy(hc06_ptr, hdr, 4);
91930 /* replace the top byte with new ECN | DSCP format */
91931 *hc06_ptr = tmp;
91932 hc06_ptr += 4;
91933diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
91934index dd6b523..dfe558f 100644
91935--- a/net/ipv4/af_inet.c
91936+++ b/net/ipv4/af_inet.c
91937@@ -1687,13 +1687,9 @@ static int __init inet_init(void)
91938
91939 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
91940
91941- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
91942- if (!sysctl_local_reserved_ports)
91943- goto out;
91944-
91945 rc = proto_register(&tcp_prot, 1);
91946 if (rc)
91947- goto out_free_reserved_ports;
91948+ goto out;
91949
91950 rc = proto_register(&udp_prot, 1);
91951 if (rc)
91952@@ -1802,8 +1798,6 @@ out_unregister_udp_proto:
91953 proto_unregister(&udp_prot);
91954 out_unregister_tcp_proto:
91955 proto_unregister(&tcp_prot);
91956-out_free_reserved_ports:
91957- kfree(sysctl_local_reserved_ports);
91958 goto out;
91959 }
91960
91961diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
91962index 34ca6d5..b6421e8 100644
91963--- a/net/ipv4/devinet.c
91964+++ b/net/ipv4/devinet.c
91965@@ -1532,7 +1532,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
91966 idx = 0;
91967 head = &net->dev_index_head[h];
91968 rcu_read_lock();
91969- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
91970+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
91971 net->dev_base_seq;
91972 hlist_for_each_entry_rcu(dev, head, index_hlist) {
91973 if (idx < s_idx)
91974@@ -1843,7 +1843,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
91975 idx = 0;
91976 head = &net->dev_index_head[h];
91977 rcu_read_lock();
91978- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
91979+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
91980 net->dev_base_seq;
91981 hlist_for_each_entry_rcu(dev, head, index_hlist) {
91982 if (idx < s_idx)
91983@@ -2068,7 +2068,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
91984 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
91985 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
91986
91987-static struct devinet_sysctl_table {
91988+static const struct devinet_sysctl_table {
91989 struct ctl_table_header *sysctl_header;
91990 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
91991 } devinet_sysctl = {
91992@@ -2186,7 +2186,7 @@ static __net_init int devinet_init_net(struct net *net)
91993 int err;
91994 struct ipv4_devconf *all, *dflt;
91995 #ifdef CONFIG_SYSCTL
91996- struct ctl_table *tbl = ctl_forward_entry;
91997+ ctl_table_no_const *tbl = NULL;
91998 struct ctl_table_header *forw_hdr;
91999 #endif
92000
92001@@ -2204,7 +2204,7 @@ static __net_init int devinet_init_net(struct net *net)
92002 goto err_alloc_dflt;
92003
92004 #ifdef CONFIG_SYSCTL
92005- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
92006+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
92007 if (tbl == NULL)
92008 goto err_alloc_ctl;
92009
92010@@ -2224,7 +2224,10 @@ static __net_init int devinet_init_net(struct net *net)
92011 goto err_reg_dflt;
92012
92013 err = -ENOMEM;
92014- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
92015+ if (!net_eq(net, &init_net))
92016+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
92017+ else
92018+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
92019 if (forw_hdr == NULL)
92020 goto err_reg_ctl;
92021 net->ipv4.forw_hdr = forw_hdr;
92022@@ -2240,8 +2243,7 @@ err_reg_ctl:
92023 err_reg_dflt:
92024 __devinet_sysctl_unregister(all);
92025 err_reg_all:
92026- if (tbl != ctl_forward_entry)
92027- kfree(tbl);
92028+ kfree(tbl);
92029 err_alloc_ctl:
92030 #endif
92031 if (dflt != &ipv4_devconf_dflt)
92032diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
92033index b3f627a..b0f3e99 100644
92034--- a/net/ipv4/fib_frontend.c
92035+++ b/net/ipv4/fib_frontend.c
92036@@ -1017,12 +1017,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
92037 #ifdef CONFIG_IP_ROUTE_MULTIPATH
92038 fib_sync_up(dev);
92039 #endif
92040- atomic_inc(&net->ipv4.dev_addr_genid);
92041+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
92042 rt_cache_flush(dev_net(dev));
92043 break;
92044 case NETDEV_DOWN:
92045 fib_del_ifaddr(ifa, NULL);
92046- atomic_inc(&net->ipv4.dev_addr_genid);
92047+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
92048 if (ifa->ifa_dev->ifa_list == NULL) {
92049 /* Last address was deleted from this interface.
92050 * Disable IP.
92051@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
92052 #ifdef CONFIG_IP_ROUTE_MULTIPATH
92053 fib_sync_up(dev);
92054 #endif
92055- atomic_inc(&net->ipv4.dev_addr_genid);
92056+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
92057 rt_cache_flush(net);
92058 break;
92059 case NETDEV_DOWN:
92060diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
92061index d5dbca5..6251d5f 100644
92062--- a/net/ipv4/fib_semantics.c
92063+++ b/net/ipv4/fib_semantics.c
92064@@ -766,7 +766,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
92065 nh->nh_saddr = inet_select_addr(nh->nh_dev,
92066 nh->nh_gw,
92067 nh->nh_parent->fib_scope);
92068- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
92069+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
92070
92071 return nh->nh_saddr;
92072 }
92073diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
92074index 6acb541..9ea617d 100644
92075--- a/net/ipv4/inet_connection_sock.c
92076+++ b/net/ipv4/inet_connection_sock.c
92077@@ -37,7 +37,7 @@ struct local_ports sysctl_local_ports __read_mostly = {
92078 .range = { 32768, 61000 },
92079 };
92080
92081-unsigned long *sysctl_local_reserved_ports;
92082+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
92083 EXPORT_SYMBOL(sysctl_local_reserved_ports);
92084
92085 void inet_get_local_port_range(int *low, int *high)
92086diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
92087index 7bd8983..3abdcf6 100644
92088--- a/net/ipv4/inet_hashtables.c
92089+++ b/net/ipv4/inet_hashtables.c
92090@@ -18,12 +18,15 @@
92091 #include <linux/sched.h>
92092 #include <linux/slab.h>
92093 #include <linux/wait.h>
92094+#include <linux/security.h>
92095
92096 #include <net/inet_connection_sock.h>
92097 #include <net/inet_hashtables.h>
92098 #include <net/secure_seq.h>
92099 #include <net/ip.h>
92100
92101+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
92102+
92103 /*
92104 * Allocate and initialize a new local port bind bucket.
92105 * The bindhash mutex for snum's hash chain must be held here.
92106@@ -554,6 +557,8 @@ ok:
92107 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
92108 spin_unlock(&head->lock);
92109
92110+ gr_update_task_in_ip_table(current, inet_sk(sk));
92111+
92112 if (tw) {
92113 inet_twsk_deschedule(tw, death_row);
92114 while (twrefcnt) {
92115diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
92116index 33d5537..da337a4 100644
92117--- a/net/ipv4/inetpeer.c
92118+++ b/net/ipv4/inetpeer.c
92119@@ -503,8 +503,8 @@ relookup:
92120 if (p) {
92121 p->daddr = *daddr;
92122 atomic_set(&p->refcnt, 1);
92123- atomic_set(&p->rid, 0);
92124- atomic_set(&p->ip_id_count,
92125+ atomic_set_unchecked(&p->rid, 0);
92126+ atomic_set_unchecked(&p->ip_id_count,
92127 (daddr->family == AF_INET) ?
92128 secure_ip_id(daddr->addr.a4) :
92129 secure_ipv6_id(daddr->addr.a6));
92130diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
92131index b66910a..cfe416e 100644
92132--- a/net/ipv4/ip_fragment.c
92133+++ b/net/ipv4/ip_fragment.c
92134@@ -282,7 +282,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
92135 return 0;
92136
92137 start = qp->rid;
92138- end = atomic_inc_return(&peer->rid);
92139+ end = atomic_inc_return_unchecked(&peer->rid);
92140 qp->rid = end;
92141
92142 rc = qp->q.fragments && (end - start) > max;
92143@@ -759,12 +759,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
92144
92145 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
92146 {
92147- struct ctl_table *table;
92148+ ctl_table_no_const *table = NULL;
92149 struct ctl_table_header *hdr;
92150
92151- table = ip4_frags_ns_ctl_table;
92152 if (!net_eq(net, &init_net)) {
92153- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
92154+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
92155 if (table == NULL)
92156 goto err_alloc;
92157
92158@@ -775,9 +774,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
92159 /* Don't export sysctls to unprivileged users */
92160 if (net->user_ns != &init_user_ns)
92161 table[0].procname = NULL;
92162- }
92163+ hdr = register_net_sysctl(net, "net/ipv4", table);
92164+ } else
92165+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
92166
92167- hdr = register_net_sysctl(net, "net/ipv4", table);
92168 if (hdr == NULL)
92169 goto err_reg;
92170
92171@@ -785,8 +785,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
92172 return 0;
92173
92174 err_reg:
92175- if (!net_eq(net, &init_net))
92176- kfree(table);
92177+ kfree(table);
92178 err_alloc:
92179 return -ENOMEM;
92180 }
92181diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
92182index 8d6939e..19d0a95 100644
92183--- a/net/ipv4/ip_gre.c
92184+++ b/net/ipv4/ip_gre.c
92185@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
92186 module_param(log_ecn_error, bool, 0644);
92187 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
92188
92189-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
92190+static struct rtnl_link_ops ipgre_link_ops;
92191 static int ipgre_tunnel_init(struct net_device *dev);
92192
92193 static int ipgre_net_id __read_mostly;
92194@@ -731,7 +731,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
92195 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
92196 };
92197
92198-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
92199+static struct rtnl_link_ops ipgre_link_ops = {
92200 .kind = "gre",
92201 .maxtype = IFLA_GRE_MAX,
92202 .policy = ipgre_policy,
92203@@ -745,7 +745,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
92204 .fill_info = ipgre_fill_info,
92205 };
92206
92207-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
92208+static struct rtnl_link_ops ipgre_tap_ops = {
92209 .kind = "gretap",
92210 .maxtype = IFLA_GRE_MAX,
92211 .policy = ipgre_policy,
92212diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
92213index d9c4f11..02b82dbc 100644
92214--- a/net/ipv4/ip_sockglue.c
92215+++ b/net/ipv4/ip_sockglue.c
92216@@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
92217 len = min_t(unsigned int, len, opt->optlen);
92218 if (put_user(len, optlen))
92219 return -EFAULT;
92220- if (copy_to_user(optval, opt->__data, len))
92221+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
92222+ copy_to_user(optval, opt->__data, len))
92223 return -EFAULT;
92224 return 0;
92225 }
92226@@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
92227 if (sk->sk_type != SOCK_STREAM)
92228 return -ENOPROTOOPT;
92229
92230- msg.msg_control = optval;
92231+ msg.msg_control = (void __force_kernel *)optval;
92232 msg.msg_controllen = len;
92233 msg.msg_flags = flags;
92234
92235diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
92236index 17cc0ff..63856c4 100644
92237--- a/net/ipv4/ip_vti.c
92238+++ b/net/ipv4/ip_vti.c
92239@@ -47,7 +47,7 @@
92240 #define HASH_SIZE 16
92241 #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&(HASH_SIZE-1))
92242
92243-static struct rtnl_link_ops vti_link_ops __read_mostly;
92244+static struct rtnl_link_ops vti_link_ops;
92245
92246 static int vti_net_id __read_mostly;
92247 struct vti_net {
92248@@ -840,7 +840,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
92249 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
92250 };
92251
92252-static struct rtnl_link_ops vti_link_ops __read_mostly = {
92253+static struct rtnl_link_ops vti_link_ops = {
92254 .kind = "vti",
92255 .maxtype = IFLA_VTI_MAX,
92256 .policy = vti_policy,
92257diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
92258index efa1138..20dbba0 100644
92259--- a/net/ipv4/ipconfig.c
92260+++ b/net/ipv4/ipconfig.c
92261@@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
92262
92263 mm_segment_t oldfs = get_fs();
92264 set_fs(get_ds());
92265- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
92266+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
92267 set_fs(oldfs);
92268 return res;
92269 }
92270@@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
92271
92272 mm_segment_t oldfs = get_fs();
92273 set_fs(get_ds());
92274- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
92275+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
92276 set_fs(oldfs);
92277 return res;
92278 }
92279@@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
92280
92281 mm_segment_t oldfs = get_fs();
92282 set_fs(get_ds());
92283- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
92284+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
92285 set_fs(oldfs);
92286 return res;
92287 }
92288diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
92289index b3ac3c3..ec6bd95 100644
92290--- a/net/ipv4/ipip.c
92291+++ b/net/ipv4/ipip.c
92292@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
92293 static int ipip_net_id __read_mostly;
92294
92295 static int ipip_tunnel_init(struct net_device *dev);
92296-static struct rtnl_link_ops ipip_link_ops __read_mostly;
92297+static struct rtnl_link_ops ipip_link_ops;
92298
92299 static int ipip_err(struct sk_buff *skb, u32 info)
92300 {
92301@@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
92302 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
92303 };
92304
92305-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
92306+static struct rtnl_link_ops ipip_link_ops = {
92307 .kind = "ipip",
92308 .maxtype = IFLA_IPTUN_MAX,
92309 .policy = ipip_policy,
92310diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
92311index 85a4f21..1beb1f5 100644
92312--- a/net/ipv4/netfilter/arp_tables.c
92313+++ b/net/ipv4/netfilter/arp_tables.c
92314@@ -880,14 +880,14 @@ static int compat_table_info(const struct xt_table_info *info,
92315 #endif
92316
92317 static int get_info(struct net *net, void __user *user,
92318- const int *len, int compat)
92319+ int len, int compat)
92320 {
92321 char name[XT_TABLE_MAXNAMELEN];
92322 struct xt_table *t;
92323 int ret;
92324
92325- if (*len != sizeof(struct arpt_getinfo)) {
92326- duprintf("length %u != %Zu\n", *len,
92327+ if (len != sizeof(struct arpt_getinfo)) {
92328+ duprintf("length %u != %Zu\n", len,
92329 sizeof(struct arpt_getinfo));
92330 return -EINVAL;
92331 }
92332@@ -924,7 +924,7 @@ static int get_info(struct net *net, void __user *user,
92333 info.size = private->size;
92334 strcpy(info.name, name);
92335
92336- if (copy_to_user(user, &info, *len) != 0)
92337+ if (copy_to_user(user, &info, len) != 0)
92338 ret = -EFAULT;
92339 else
92340 ret = 0;
92341@@ -1683,7 +1683,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
92342
92343 switch (cmd) {
92344 case ARPT_SO_GET_INFO:
92345- ret = get_info(sock_net(sk), user, len, 1);
92346+ ret = get_info(sock_net(sk), user, *len, 1);
92347 break;
92348 case ARPT_SO_GET_ENTRIES:
92349 ret = compat_get_entries(sock_net(sk), user, len);
92350@@ -1728,7 +1728,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
92351
92352 switch (cmd) {
92353 case ARPT_SO_GET_INFO:
92354- ret = get_info(sock_net(sk), user, len, 0);
92355+ ret = get_info(sock_net(sk), user, *len, 0);
92356 break;
92357
92358 case ARPT_SO_GET_ENTRIES:
92359diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
92360index d23118d..6ad7277 100644
92361--- a/net/ipv4/netfilter/ip_tables.c
92362+++ b/net/ipv4/netfilter/ip_tables.c
92363@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
92364 #endif
92365
92366 static int get_info(struct net *net, void __user *user,
92367- const int *len, int compat)
92368+ int len, int compat)
92369 {
92370 char name[XT_TABLE_MAXNAMELEN];
92371 struct xt_table *t;
92372 int ret;
92373
92374- if (*len != sizeof(struct ipt_getinfo)) {
92375- duprintf("length %u != %zu\n", *len,
92376+ if (len != sizeof(struct ipt_getinfo)) {
92377+ duprintf("length %u != %zu\n", len,
92378 sizeof(struct ipt_getinfo));
92379 return -EINVAL;
92380 }
92381@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
92382 info.size = private->size;
92383 strcpy(info.name, name);
92384
92385- if (copy_to_user(user, &info, *len) != 0)
92386+ if (copy_to_user(user, &info, len) != 0)
92387 ret = -EFAULT;
92388 else
92389 ret = 0;
92390@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
92391
92392 switch (cmd) {
92393 case IPT_SO_GET_INFO:
92394- ret = get_info(sock_net(sk), user, len, 1);
92395+ ret = get_info(sock_net(sk), user, *len, 1);
92396 break;
92397 case IPT_SO_GET_ENTRIES:
92398 ret = compat_get_entries(sock_net(sk), user, len);
92399@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
92400
92401 switch (cmd) {
92402 case IPT_SO_GET_INFO:
92403- ret = get_info(sock_net(sk), user, len, 0);
92404+ ret = get_info(sock_net(sk), user, *len, 0);
92405 break;
92406
92407 case IPT_SO_GET_ENTRIES:
92408diff --git a/net/ipv4/netfilter/ipt_ULOG.c b/net/ipv4/netfilter/ipt_ULOG.c
92409index cbc2215..9cb993c 100644
92410--- a/net/ipv4/netfilter/ipt_ULOG.c
92411+++ b/net/ipv4/netfilter/ipt_ULOG.c
92412@@ -220,6 +220,7 @@ static void ipt_ulog_packet(struct net *net,
92413 ub->qlen++;
92414
92415 pm = nlmsg_data(nlh);
92416+ memset(pm, 0, sizeof(*pm));
92417
92418 /* We might not have a timestamp, get one */
92419 if (skb->tstamp.tv64 == 0)
92420@@ -238,8 +239,6 @@ static void ipt_ulog_packet(struct net *net,
92421 }
92422 else if (loginfo->prefix[0] != '\0')
92423 strncpy(pm->prefix, loginfo->prefix, sizeof(pm->prefix));
92424- else
92425- *(pm->prefix) = '\0';
92426
92427 if (in && in->hard_header_len > 0 &&
92428 skb->mac_header != skb->network_header &&
92429@@ -251,13 +250,9 @@ static void ipt_ulog_packet(struct net *net,
92430
92431 if (in)
92432 strncpy(pm->indev_name, in->name, sizeof(pm->indev_name));
92433- else
92434- pm->indev_name[0] = '\0';
92435
92436 if (out)
92437 strncpy(pm->outdev_name, out->name, sizeof(pm->outdev_name));
92438- else
92439- pm->outdev_name[0] = '\0';
92440
92441 /* copy_len <= skb->len, so can't fail. */
92442 if (skb_copy_bits(skb, 0, pm->payload, copy_len) < 0)
92443diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
92444index 746427c..80eab72 100644
92445--- a/net/ipv4/ping.c
92446+++ b/net/ipv4/ping.c
92447@@ -55,7 +55,7 @@
92448
92449
92450 struct ping_table ping_table;
92451-struct pingv6_ops pingv6_ops;
92452+struct pingv6_ops *pingv6_ops;
92453 EXPORT_SYMBOL_GPL(pingv6_ops);
92454
92455 static u16 ping_port_rover;
92456@@ -335,7 +335,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
92457 return -ENODEV;
92458 }
92459 }
92460- has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
92461+ has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
92462 scoped);
92463 rcu_read_unlock();
92464
92465@@ -541,7 +541,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
92466 }
92467 #if IS_ENABLED(CONFIG_IPV6)
92468 } else if (skb->protocol == htons(ETH_P_IPV6)) {
92469- harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
92470+ harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
92471 #endif
92472 }
92473
92474@@ -559,7 +559,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
92475 info, (u8 *)icmph);
92476 #if IS_ENABLED(CONFIG_IPV6)
92477 } else if (family == AF_INET6) {
92478- pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
92479+ pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
92480 info, (u8 *)icmph);
92481 #endif
92482 }
92483@@ -850,7 +850,7 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
92484 return ip_recv_error(sk, msg, len);
92485 #if IS_ENABLED(CONFIG_IPV6)
92486 } else if (family == AF_INET6) {
92487- return pingv6_ops.ipv6_recv_error(sk, msg, len);
92488+ return pingv6_ops->ipv6_recv_error(sk, msg, len);
92489 #endif
92490 }
92491 }
92492@@ -900,7 +900,7 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
92493 IP6CB(skb)->iif);
92494
92495 if (inet6_sk(sk)->rxopt.all)
92496- pingv6_ops.ip6_datagram_recv_ctl(sk, msg, skb);
92497+ pingv6_ops->ip6_datagram_recv_ctl(sk, msg, skb);
92498 #endif
92499 } else {
92500 BUG();
92501@@ -1090,7 +1090,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
92502 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
92503 0, sock_i_ino(sp),
92504 atomic_read(&sp->sk_refcnt), sp,
92505- atomic_read(&sp->sk_drops), len);
92506+ atomic_read_unchecked(&sp->sk_drops), len);
92507 }
92508
92509 static int ping_v4_seq_show(struct seq_file *seq, void *v)
92510diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
92511index 6fb2337..9cd6b20 100644
92512--- a/net/ipv4/raw.c
92513+++ b/net/ipv4/raw.c
92514@@ -309,7 +309,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
92515 int raw_rcv(struct sock *sk, struct sk_buff *skb)
92516 {
92517 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
92518- atomic_inc(&sk->sk_drops);
92519+ atomic_inc_unchecked(&sk->sk_drops);
92520 kfree_skb(skb);
92521 return NET_RX_DROP;
92522 }
92523@@ -746,16 +746,20 @@ static int raw_init(struct sock *sk)
92524
92525 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
92526 {
92527+ struct icmp_filter filter;
92528+
92529 if (optlen > sizeof(struct icmp_filter))
92530 optlen = sizeof(struct icmp_filter);
92531- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
92532+ if (copy_from_user(&filter, optval, optlen))
92533 return -EFAULT;
92534+ raw_sk(sk)->filter = filter;
92535 return 0;
92536 }
92537
92538 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
92539 {
92540 int len, ret = -EFAULT;
92541+ struct icmp_filter filter;
92542
92543 if (get_user(len, optlen))
92544 goto out;
92545@@ -765,8 +769,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
92546 if (len > sizeof(struct icmp_filter))
92547 len = sizeof(struct icmp_filter);
92548 ret = -EFAULT;
92549- if (put_user(len, optlen) ||
92550- copy_to_user(optval, &raw_sk(sk)->filter, len))
92551+ filter = raw_sk(sk)->filter;
92552+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
92553 goto out;
92554 ret = 0;
92555 out: return ret;
92556@@ -995,7 +999,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
92557 0, 0L, 0,
92558 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
92559 0, sock_i_ino(sp),
92560- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
92561+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
92562 }
92563
92564 static int raw_seq_show(struct seq_file *seq, void *v)
92565diff --git a/net/ipv4/route.c b/net/ipv4/route.c
92566index a9a54a2..647316e 100644
92567--- a/net/ipv4/route.c
92568+++ b/net/ipv4/route.c
92569@@ -2615,34 +2615,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
92570 .maxlen = sizeof(int),
92571 .mode = 0200,
92572 .proc_handler = ipv4_sysctl_rtcache_flush,
92573+ .extra1 = &init_net,
92574 },
92575 { },
92576 };
92577
92578 static __net_init int sysctl_route_net_init(struct net *net)
92579 {
92580- struct ctl_table *tbl;
92581+ ctl_table_no_const *tbl = NULL;
92582
92583- tbl = ipv4_route_flush_table;
92584 if (!net_eq(net, &init_net)) {
92585- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
92586+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
92587 if (tbl == NULL)
92588 goto err_dup;
92589
92590 /* Don't export sysctls to unprivileged users */
92591 if (net->user_ns != &init_user_ns)
92592 tbl[0].procname = NULL;
92593- }
92594- tbl[0].extra1 = net;
92595+ tbl[0].extra1 = net;
92596+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
92597+ } else
92598+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
92599
92600- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
92601 if (net->ipv4.route_hdr == NULL)
92602 goto err_reg;
92603 return 0;
92604
92605 err_reg:
92606- if (tbl != ipv4_route_flush_table)
92607- kfree(tbl);
92608+ kfree(tbl);
92609 err_dup:
92610 return -ENOMEM;
92611 }
92612@@ -2665,8 +2665,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
92613
92614 static __net_init int rt_genid_init(struct net *net)
92615 {
92616- atomic_set(&net->rt_genid, 0);
92617- atomic_set(&net->fnhe_genid, 0);
92618+ atomic_set_unchecked(&net->rt_genid, 0);
92619+ atomic_set_unchecked(&net->fnhe_genid, 0);
92620 get_random_bytes(&net->ipv4.dev_addr_genid,
92621 sizeof(net->ipv4.dev_addr_genid));
92622 return 0;
92623diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
92624index 610e324..fd42e75 100644
92625--- a/net/ipv4/sysctl_net_ipv4.c
92626+++ b/net/ipv4/sysctl_net_ipv4.c
92627@@ -57,7 +57,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
92628 {
92629 int ret;
92630 int range[2];
92631- struct ctl_table tmp = {
92632+ ctl_table_no_const tmp = {
92633 .data = &range,
92634 .maxlen = sizeof(range),
92635 .mode = table->mode,
92636@@ -110,7 +110,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
92637 int ret;
92638 gid_t urange[2];
92639 kgid_t low, high;
92640- struct ctl_table tmp = {
92641+ ctl_table_no_const tmp = {
92642 .data = &urange,
92643 .maxlen = sizeof(urange),
92644 .mode = table->mode,
92645@@ -141,7 +141,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
92646 void __user *buffer, size_t *lenp, loff_t *ppos)
92647 {
92648 char val[TCP_CA_NAME_MAX];
92649- struct ctl_table tbl = {
92650+ ctl_table_no_const tbl = {
92651 .data = val,
92652 .maxlen = TCP_CA_NAME_MAX,
92653 };
92654@@ -160,7 +160,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
92655 void __user *buffer, size_t *lenp,
92656 loff_t *ppos)
92657 {
92658- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
92659+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
92660 int ret;
92661
92662 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
92663@@ -177,7 +177,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
92664 void __user *buffer, size_t *lenp,
92665 loff_t *ppos)
92666 {
92667- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
92668+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
92669 int ret;
92670
92671 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
92672@@ -203,15 +203,17 @@ static int ipv4_tcp_mem(struct ctl_table *ctl, int write,
92673 struct mem_cgroup *memcg;
92674 #endif
92675
92676- struct ctl_table tmp = {
92677+ ctl_table_no_const tmp = {
92678 .data = &vec,
92679 .maxlen = sizeof(vec),
92680 .mode = ctl->mode,
92681 };
92682
92683 if (!write) {
92684- ctl->data = &net->ipv4.sysctl_tcp_mem;
92685- return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
92686+ ctl_table_no_const tcp_mem = *ctl;
92687+
92688+ tcp_mem.data = &net->ipv4.sysctl_tcp_mem;
92689+ return proc_doulongvec_minmax(&tcp_mem, write, buffer, lenp, ppos);
92690 }
92691
92692 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
92693@@ -239,7 +241,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
92694 void __user *buffer, size_t *lenp,
92695 loff_t *ppos)
92696 {
92697- struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
92698+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
92699 struct tcp_fastopen_context *ctxt;
92700 int ret;
92701 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
92702@@ -482,7 +484,7 @@ static struct ctl_table ipv4_table[] = {
92703 },
92704 {
92705 .procname = "ip_local_reserved_ports",
92706- .data = NULL, /* initialized in sysctl_ipv4_init */
92707+ .data = sysctl_local_reserved_ports,
92708 .maxlen = 65536,
92709 .mode = 0644,
92710 .proc_handler = proc_do_large_bitmap,
92711@@ -847,11 +849,10 @@ static struct ctl_table ipv4_net_table[] = {
92712
92713 static __net_init int ipv4_sysctl_init_net(struct net *net)
92714 {
92715- struct ctl_table *table;
92716+ ctl_table_no_const *table = NULL;
92717
92718- table = ipv4_net_table;
92719 if (!net_eq(net, &init_net)) {
92720- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
92721+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
92722 if (table == NULL)
92723 goto err_alloc;
92724
92725@@ -886,15 +887,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
92726
92727 tcp_init_mem(net);
92728
92729- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
92730+ if (!net_eq(net, &init_net))
92731+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
92732+ else
92733+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
92734 if (net->ipv4.ipv4_hdr == NULL)
92735 goto err_reg;
92736
92737 return 0;
92738
92739 err_reg:
92740- if (!net_eq(net, &init_net))
92741- kfree(table);
92742+ kfree(table);
92743 err_alloc:
92744 return -ENOMEM;
92745 }
92746@@ -916,16 +919,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
92747 static __init int sysctl_ipv4_init(void)
92748 {
92749 struct ctl_table_header *hdr;
92750- struct ctl_table *i;
92751-
92752- for (i = ipv4_table; i->procname; i++) {
92753- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
92754- i->data = sysctl_local_reserved_ports;
92755- break;
92756- }
92757- }
92758- if (!i->procname)
92759- return -EINVAL;
92760
92761 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
92762 if (hdr == NULL)
92763diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
92764index 3ca2139..c4cc060 100644
92765--- a/net/ipv4/tcp_input.c
92766+++ b/net/ipv4/tcp_input.c
92767@@ -4379,7 +4379,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
92768 * simplifies code)
92769 */
92770 static void
92771-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
92772+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
92773 struct sk_buff *head, struct sk_buff *tail,
92774 u32 start, u32 end)
92775 {
92776@@ -5465,6 +5465,7 @@ discard:
92777 tcp_paws_reject(&tp->rx_opt, 0))
92778 goto discard_and_undo;
92779
92780+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
92781 if (th->syn) {
92782 /* We see SYN without ACK. It is attempt of
92783 * simultaneous connect with crossed SYNs.
92784@@ -5515,6 +5516,7 @@ discard:
92785 goto discard;
92786 #endif
92787 }
92788+#endif
92789 /* "fifth, if neither of the SYN or RST bits is set then
92790 * drop the segment and return."
92791 */
92792@@ -5560,7 +5562,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
92793 goto discard;
92794
92795 if (th->syn) {
92796- if (th->fin)
92797+ if (th->fin || th->urg || th->psh)
92798 goto discard;
92799 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
92800 return 1;
92801diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
92802index b299da5..097db06 100644
92803--- a/net/ipv4/tcp_ipv4.c
92804+++ b/net/ipv4/tcp_ipv4.c
92805@@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
92806 EXPORT_SYMBOL(sysctl_tcp_low_latency);
92807
92808
92809+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92810+extern int grsec_enable_blackhole;
92811+#endif
92812+
92813 #ifdef CONFIG_TCP_MD5SIG
92814 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
92815 __be32 daddr, __be32 saddr, const struct tcphdr *th);
92816@@ -1830,6 +1834,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
92817 return 0;
92818
92819 reset:
92820+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92821+ if (!grsec_enable_blackhole)
92822+#endif
92823 tcp_v4_send_reset(rsk, skb);
92824 discard:
92825 kfree_skb(skb);
92826@@ -1975,12 +1982,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
92827 TCP_SKB_CB(skb)->sacked = 0;
92828
92829 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
92830- if (!sk)
92831+ if (!sk) {
92832+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92833+ ret = 1;
92834+#endif
92835 goto no_tcp_socket;
92836-
92837+ }
92838 process:
92839- if (sk->sk_state == TCP_TIME_WAIT)
92840+ if (sk->sk_state == TCP_TIME_WAIT) {
92841+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92842+ ret = 2;
92843+#endif
92844 goto do_time_wait;
92845+ }
92846
92847 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
92848 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
92849@@ -2034,6 +2048,10 @@ csum_error:
92850 bad_packet:
92851 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
92852 } else {
92853+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92854+ if (!grsec_enable_blackhole || (ret == 1 &&
92855+ (skb->dev->flags & IFF_LOOPBACK)))
92856+#endif
92857 tcp_v4_send_reset(NULL, skb);
92858 }
92859
92860diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
92861index ab1c086..2a8d76b 100644
92862--- a/net/ipv4/tcp_minisocks.c
92863+++ b/net/ipv4/tcp_minisocks.c
92864@@ -27,6 +27,10 @@
92865 #include <net/inet_common.h>
92866 #include <net/xfrm.h>
92867
92868+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92869+extern int grsec_enable_blackhole;
92870+#endif
92871+
92872 int sysctl_tcp_syncookies __read_mostly = 1;
92873 EXPORT_SYMBOL(sysctl_tcp_syncookies);
92874
92875@@ -715,7 +719,10 @@ embryonic_reset:
92876 * avoid becoming vulnerable to outside attack aiming at
92877 * resetting legit local connections.
92878 */
92879- req->rsk_ops->send_reset(sk, skb);
92880+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92881+ if (!grsec_enable_blackhole)
92882+#endif
92883+ req->rsk_ops->send_reset(sk, skb);
92884 } else if (fastopen) { /* received a valid RST pkt */
92885 reqsk_fastopen_remove(sk, req, true);
92886 tcp_reset(sk);
92887diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
92888index 170737a..75cbd26 100644
92889--- a/net/ipv4/tcp_output.c
92890+++ b/net/ipv4/tcp_output.c
92891@@ -982,6 +982,9 @@ static void tcp_queue_skb(struct sock *sk, struct sk_buff *skb)
92892 static void tcp_set_skb_tso_segs(const struct sock *sk, struct sk_buff *skb,
92893 unsigned int mss_now)
92894 {
92895+ /* Make sure we own this skb before messing gso_size/gso_segs */
92896+ WARN_ON_ONCE(skb_cloned(skb));
92897+
92898 if (skb->len <= mss_now || !sk_can_gso(sk) ||
92899 skb->ip_summed == CHECKSUM_NONE) {
92900 /* Avoid the costly divide in the normal
92901@@ -1063,9 +1066,7 @@ int tcp_fragment(struct sock *sk, struct sk_buff *skb, u32 len,
92902 if (nsize < 0)
92903 nsize = 0;
92904
92905- if (skb_cloned(skb) &&
92906- skb_is_nonlinear(skb) &&
92907- pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
92908+ if (skb_unclone(skb, GFP_ATOMIC))
92909 return -ENOMEM;
92910
92911 /* Get a new skb... force flag on. */
92912@@ -2334,6 +2335,8 @@ int __tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb)
92913 int oldpcount = tcp_skb_pcount(skb);
92914
92915 if (unlikely(oldpcount > 1)) {
92916+ if (skb_unclone(skb, GFP_ATOMIC))
92917+ return -ENOMEM;
92918 tcp_init_tso_segs(sk, skb, cur_mss);
92919 tcp_adjust_pcount(sk, skb, oldpcount - tcp_skb_pcount(skb));
92920 }
92921diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
92922index d4943f6..e7a74a5 100644
92923--- a/net/ipv4/tcp_probe.c
92924+++ b/net/ipv4/tcp_probe.c
92925@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
92926 if (cnt + width >= len)
92927 break;
92928
92929- if (copy_to_user(buf + cnt, tbuf, width))
92930+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
92931 return -EFAULT;
92932 cnt += width;
92933 }
92934diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
92935index 4b85e6f..22f9ac9 100644
92936--- a/net/ipv4/tcp_timer.c
92937+++ b/net/ipv4/tcp_timer.c
92938@@ -22,6 +22,10 @@
92939 #include <linux/gfp.h>
92940 #include <net/tcp.h>
92941
92942+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92943+extern int grsec_lastack_retries;
92944+#endif
92945+
92946 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
92947 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
92948 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
92949@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
92950 }
92951 }
92952
92953+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92954+ if ((sk->sk_state == TCP_LAST_ACK) &&
92955+ (grsec_lastack_retries > 0) &&
92956+ (grsec_lastack_retries < retry_until))
92957+ retry_until = grsec_lastack_retries;
92958+#endif
92959+
92960 if (retransmits_timed_out(sk, retry_until,
92961 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
92962 /* Has it gone just too far? */
92963diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
92964index 766e6ba..aff2f8d 100644
92965--- a/net/ipv4/udp.c
92966+++ b/net/ipv4/udp.c
92967@@ -87,6 +87,7 @@
92968 #include <linux/types.h>
92969 #include <linux/fcntl.h>
92970 #include <linux/module.h>
92971+#include <linux/security.h>
92972 #include <linux/socket.h>
92973 #include <linux/sockios.h>
92974 #include <linux/igmp.h>
92975@@ -112,6 +113,10 @@
92976 #include <net/busy_poll.h>
92977 #include "udp_impl.h"
92978
92979+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92980+extern int grsec_enable_blackhole;
92981+#endif
92982+
92983 struct udp_table udp_table __read_mostly;
92984 EXPORT_SYMBOL(udp_table);
92985
92986@@ -595,6 +600,9 @@ found:
92987 return s;
92988 }
92989
92990+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
92991+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
92992+
92993 /*
92994 * This routine is called by the ICMP module when it gets some
92995 * sort of error condition. If err < 0 then the socket should
92996@@ -891,9 +899,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
92997 dport = usin->sin_port;
92998 if (dport == 0)
92999 return -EINVAL;
93000+
93001+ err = gr_search_udp_sendmsg(sk, usin);
93002+ if (err)
93003+ return err;
93004 } else {
93005 if (sk->sk_state != TCP_ESTABLISHED)
93006 return -EDESTADDRREQ;
93007+
93008+ err = gr_search_udp_sendmsg(sk, NULL);
93009+ if (err)
93010+ return err;
93011+
93012 daddr = inet->inet_daddr;
93013 dport = inet->inet_dport;
93014 /* Open fast path for connected socket.
93015@@ -1137,7 +1154,7 @@ static unsigned int first_packet_length(struct sock *sk)
93016 IS_UDPLITE(sk));
93017 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
93018 IS_UDPLITE(sk));
93019- atomic_inc(&sk->sk_drops);
93020+ atomic_inc_unchecked(&sk->sk_drops);
93021 __skb_unlink(skb, rcvq);
93022 __skb_queue_tail(&list_kill, skb);
93023 }
93024@@ -1223,6 +1240,10 @@ try_again:
93025 if (!skb)
93026 goto out;
93027
93028+ err = gr_search_udp_recvmsg(sk, skb);
93029+ if (err)
93030+ goto out_free;
93031+
93032 ulen = skb->len - sizeof(struct udphdr);
93033 copied = len;
93034 if (copied > ulen)
93035@@ -1256,7 +1277,7 @@ try_again:
93036 if (unlikely(err)) {
93037 trace_kfree_skb(skb, udp_recvmsg);
93038 if (!peeked) {
93039- atomic_inc(&sk->sk_drops);
93040+ atomic_inc_unchecked(&sk->sk_drops);
93041 UDP_INC_STATS_USER(sock_net(sk),
93042 UDP_MIB_INERRORS, is_udplite);
93043 }
93044@@ -1543,7 +1564,7 @@ csum_error:
93045 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
93046 drop:
93047 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
93048- atomic_inc(&sk->sk_drops);
93049+ atomic_inc_unchecked(&sk->sk_drops);
93050 kfree_skb(skb);
93051 return -1;
93052 }
93053@@ -1562,7 +1583,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
93054 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
93055
93056 if (!skb1) {
93057- atomic_inc(&sk->sk_drops);
93058+ atomic_inc_unchecked(&sk->sk_drops);
93059 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
93060 IS_UDPLITE(sk));
93061 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
93062@@ -1734,6 +1755,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
93063 goto csum_error;
93064
93065 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
93066+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93067+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
93068+#endif
93069 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
93070
93071 /*
93072@@ -2166,7 +2190,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
93073 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
93074 0, sock_i_ino(sp),
93075 atomic_read(&sp->sk_refcnt), sp,
93076- atomic_read(&sp->sk_drops), len);
93077+ atomic_read_unchecked(&sp->sk_drops), len);
93078 }
93079
93080 int udp4_seq_show(struct seq_file *seq, void *v)
93081diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
93082index 9a459be..c7bc04c 100644
93083--- a/net/ipv4/xfrm4_policy.c
93084+++ b/net/ipv4/xfrm4_policy.c
93085@@ -181,11 +181,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
93086 fl4->flowi4_tos = iph->tos;
93087 }
93088
93089-static inline int xfrm4_garbage_collect(struct dst_ops *ops)
93090+static int xfrm4_garbage_collect(struct dst_ops *ops)
93091 {
93092 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
93093
93094- xfrm4_policy_afinfo.garbage_collect(net);
93095+ xfrm_garbage_collect_deferred(net);
93096 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
93097 }
93098
93099@@ -264,19 +264,18 @@ static struct ctl_table xfrm4_policy_table[] = {
93100
93101 static int __net_init xfrm4_net_init(struct net *net)
93102 {
93103- struct ctl_table *table;
93104+ ctl_table_no_const *table = NULL;
93105 struct ctl_table_header *hdr;
93106
93107- table = xfrm4_policy_table;
93108 if (!net_eq(net, &init_net)) {
93109- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
93110+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
93111 if (!table)
93112 goto err_alloc;
93113
93114 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
93115- }
93116-
93117- hdr = register_net_sysctl(net, "net/ipv4", table);
93118+ hdr = register_net_sysctl(net, "net/ipv4", table);
93119+ } else
93120+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
93121 if (!hdr)
93122 goto err_reg;
93123
93124@@ -284,8 +283,7 @@ static int __net_init xfrm4_net_init(struct net *net)
93125 return 0;
93126
93127 err_reg:
93128- if (!net_eq(net, &init_net))
93129- kfree(table);
93130+ kfree(table);
93131 err_alloc:
93132 return -ENOMEM;
93133 }
93134diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
93135index 0f99f7b..9375cf5 100644
93136--- a/net/ipv6/addrconf.c
93137+++ b/net/ipv6/addrconf.c
93138@@ -618,7 +618,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
93139 idx = 0;
93140 head = &net->dev_index_head[h];
93141 rcu_read_lock();
93142- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
93143+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
93144 net->dev_base_seq;
93145 hlist_for_each_entry_rcu(dev, head, index_hlist) {
93146 if (idx < s_idx)
93147@@ -2408,7 +2408,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
93148 p.iph.ihl = 5;
93149 p.iph.protocol = IPPROTO_IPV6;
93150 p.iph.ttl = 64;
93151- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
93152+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
93153
93154 if (ops->ndo_do_ioctl) {
93155 mm_segment_t oldfs = get_fs();
93156@@ -4057,7 +4057,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
93157 s_ip_idx = ip_idx = cb->args[2];
93158
93159 rcu_read_lock();
93160- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
93161+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
93162 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
93163 idx = 0;
93164 head = &net->dev_index_head[h];
93165@@ -4678,7 +4678,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
93166 dst_free(&ifp->rt->dst);
93167 break;
93168 }
93169- atomic_inc(&net->ipv6.dev_addr_genid);
93170+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
93171 }
93172
93173 static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
93174@@ -4698,7 +4698,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
93175 int *valp = ctl->data;
93176 int val = *valp;
93177 loff_t pos = *ppos;
93178- struct ctl_table lctl;
93179+ ctl_table_no_const lctl;
93180 int ret;
93181
93182 /*
93183@@ -4783,7 +4783,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
93184 int *valp = ctl->data;
93185 int val = *valp;
93186 loff_t pos = *ppos;
93187- struct ctl_table lctl;
93188+ ctl_table_no_const lctl;
93189 int ret;
93190
93191 /*
93192diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
93193index 197e6f4..16d8396 100644
93194--- a/net/ipv6/datagram.c
93195+++ b/net/ipv6/datagram.c
93196@@ -904,5 +904,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
93197 0,
93198 sock_i_ino(sp),
93199 atomic_read(&sp->sk_refcnt), sp,
93200- atomic_read(&sp->sk_drops));
93201+ atomic_read_unchecked(&sp->sk_drops));
93202 }
93203diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
93204index 7cfc8d2..c5394b6 100644
93205--- a/net/ipv6/icmp.c
93206+++ b/net/ipv6/icmp.c
93207@@ -989,7 +989,7 @@ struct ctl_table ipv6_icmp_table_template[] = {
93208
93209 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
93210 {
93211- struct ctl_table *table;
93212+ ctl_table_no_const *table;
93213
93214 table = kmemdup(ipv6_icmp_table_template,
93215 sizeof(ipv6_icmp_table_template),
93216diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
93217index 8bc717b..76fbb5d 100644
93218--- a/net/ipv6/ip6_gre.c
93219+++ b/net/ipv6/ip6_gre.c
93220@@ -74,7 +74,7 @@ struct ip6gre_net {
93221 struct net_device *fb_tunnel_dev;
93222 };
93223
93224-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
93225+static struct rtnl_link_ops ip6gre_link_ops;
93226 static int ip6gre_tunnel_init(struct net_device *dev);
93227 static void ip6gre_tunnel_setup(struct net_device *dev);
93228 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
93229@@ -1288,7 +1288,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
93230 }
93231
93232
93233-static struct inet6_protocol ip6gre_protocol __read_mostly = {
93234+static struct inet6_protocol ip6gre_protocol = {
93235 .handler = ip6gre_rcv,
93236 .err_handler = ip6gre_err,
93237 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
93238@@ -1622,7 +1622,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
93239 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
93240 };
93241
93242-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
93243+static struct rtnl_link_ops ip6gre_link_ops = {
93244 .kind = "ip6gre",
93245 .maxtype = IFLA_GRE_MAX,
93246 .policy = ip6gre_policy,
93247@@ -1635,7 +1635,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
93248 .fill_info = ip6gre_fill_info,
93249 };
93250
93251-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
93252+static struct rtnl_link_ops ip6gre_tap_ops = {
93253 .kind = "ip6gretap",
93254 .maxtype = IFLA_GRE_MAX,
93255 .policy = ip6gre_policy,
93256diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
93257index cf5d490..30946f0 100644
93258--- a/net/ipv6/ip6_tunnel.c
93259+++ b/net/ipv6/ip6_tunnel.c
93260@@ -88,7 +88,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
93261
93262 static int ip6_tnl_dev_init(struct net_device *dev);
93263 static void ip6_tnl_dev_setup(struct net_device *dev);
93264-static struct rtnl_link_ops ip6_link_ops __read_mostly;
93265+static struct rtnl_link_ops ip6_link_ops;
93266
93267 static int ip6_tnl_net_id __read_mostly;
93268 struct ip6_tnl_net {
93269@@ -1678,7 +1678,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
93270 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
93271 };
93272
93273-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
93274+static struct rtnl_link_ops ip6_link_ops = {
93275 .kind = "ip6tnl",
93276 .maxtype = IFLA_IPTUN_MAX,
93277 .policy = ip6_tnl_policy,
93278diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
93279index d1e2e8e..51c19ae 100644
93280--- a/net/ipv6/ipv6_sockglue.c
93281+++ b/net/ipv6/ipv6_sockglue.c
93282@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
93283 if (sk->sk_type != SOCK_STREAM)
93284 return -ENOPROTOOPT;
93285
93286- msg.msg_control = optval;
93287+ msg.msg_control = (void __force_kernel *)optval;
93288 msg.msg_controllen = len;
93289 msg.msg_flags = flags;
93290
93291diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
93292index 44400c2..8e11f52 100644
93293--- a/net/ipv6/netfilter/ip6_tables.c
93294+++ b/net/ipv6/netfilter/ip6_tables.c
93295@@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
93296 #endif
93297
93298 static int get_info(struct net *net, void __user *user,
93299- const int *len, int compat)
93300+ int len, int compat)
93301 {
93302 char name[XT_TABLE_MAXNAMELEN];
93303 struct xt_table *t;
93304 int ret;
93305
93306- if (*len != sizeof(struct ip6t_getinfo)) {
93307- duprintf("length %u != %zu\n", *len,
93308+ if (len != sizeof(struct ip6t_getinfo)) {
93309+ duprintf("length %u != %zu\n", len,
93310 sizeof(struct ip6t_getinfo));
93311 return -EINVAL;
93312 }
93313@@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
93314 info.size = private->size;
93315 strcpy(info.name, name);
93316
93317- if (copy_to_user(user, &info, *len) != 0)
93318+ if (copy_to_user(user, &info, len) != 0)
93319 ret = -EFAULT;
93320 else
93321 ret = 0;
93322@@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
93323
93324 switch (cmd) {
93325 case IP6T_SO_GET_INFO:
93326- ret = get_info(sock_net(sk), user, len, 1);
93327+ ret = get_info(sock_net(sk), user, *len, 1);
93328 break;
93329 case IP6T_SO_GET_ENTRIES:
93330 ret = compat_get_entries(sock_net(sk), user, len);
93331@@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
93332
93333 switch (cmd) {
93334 case IP6T_SO_GET_INFO:
93335- ret = get_info(sock_net(sk), user, len, 0);
93336+ ret = get_info(sock_net(sk), user, *len, 0);
93337 break;
93338
93339 case IP6T_SO_GET_ENTRIES:
93340diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
93341index dffdc1a..ccc6678 100644
93342--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
93343+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
93344@@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
93345
93346 static int nf_ct_frag6_sysctl_register(struct net *net)
93347 {
93348- struct ctl_table *table;
93349+ ctl_table_no_const *table = NULL;
93350 struct ctl_table_header *hdr;
93351
93352- table = nf_ct_frag6_sysctl_table;
93353 if (!net_eq(net, &init_net)) {
93354- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
93355+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
93356 GFP_KERNEL);
93357 if (table == NULL)
93358 goto err_alloc;
93359@@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
93360 table[0].data = &net->nf_frag.frags.timeout;
93361 table[1].data = &net->nf_frag.frags.low_thresh;
93362 table[2].data = &net->nf_frag.frags.high_thresh;
93363- }
93364-
93365- hdr = register_net_sysctl(net, "net/netfilter", table);
93366+ hdr = register_net_sysctl(net, "net/netfilter", table);
93367+ } else
93368+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
93369 if (hdr == NULL)
93370 goto err_reg;
93371
93372@@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
93373 return 0;
93374
93375 err_reg:
93376- if (!net_eq(net, &init_net))
93377- kfree(table);
93378+ kfree(table);
93379 err_alloc:
93380 return -ENOMEM;
93381 }
93382diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
93383index ab92a36..bb4a528 100644
93384--- a/net/ipv6/output_core.c
93385+++ b/net/ipv6/output_core.c
93386@@ -8,8 +8,8 @@
93387
93388 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
93389 {
93390- static atomic_t ipv6_fragmentation_id;
93391- int old, new;
93392+ static atomic_unchecked_t ipv6_fragmentation_id;
93393+ int id;
93394
93395 #if IS_ENABLED(CONFIG_IPV6)
93396 if (rt && !(rt->dst.flags & DST_NOPEER)) {
93397@@ -25,13 +25,10 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
93398 }
93399 }
93400 #endif
93401- do {
93402- old = atomic_read(&ipv6_fragmentation_id);
93403- new = old + 1;
93404- if (!new)
93405- new = 1;
93406- } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
93407- fhdr->identification = htonl(new);
93408+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
93409+ if (!id)
93410+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
93411+ fhdr->identification = htonl(id);
93412 }
93413 EXPORT_SYMBOL(ipv6_select_ident);
93414
93415diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
93416index 18f19df..b46ada1 100644
93417--- a/net/ipv6/ping.c
93418+++ b/net/ipv6/ping.c
93419@@ -245,6 +245,22 @@ static struct pernet_operations ping_v6_net_ops = {
93420 };
93421 #endif
93422
93423+static struct pingv6_ops real_pingv6_ops = {
93424+ .ipv6_recv_error = ipv6_recv_error,
93425+ .ip6_datagram_recv_ctl = ip6_datagram_recv_ctl,
93426+ .icmpv6_err_convert = icmpv6_err_convert,
93427+ .ipv6_icmp_error = ipv6_icmp_error,
93428+ .ipv6_chk_addr = ipv6_chk_addr,
93429+};
93430+
93431+static struct pingv6_ops dummy_pingv6_ops = {
93432+ .ipv6_recv_error = dummy_ipv6_recv_error,
93433+ .ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl,
93434+ .icmpv6_err_convert = dummy_icmpv6_err_convert,
93435+ .ipv6_icmp_error = dummy_ipv6_icmp_error,
93436+ .ipv6_chk_addr = dummy_ipv6_chk_addr,
93437+};
93438+
93439 int __init pingv6_init(void)
93440 {
93441 #ifdef CONFIG_PROC_FS
93442@@ -252,11 +268,7 @@ int __init pingv6_init(void)
93443 if (ret)
93444 return ret;
93445 #endif
93446- pingv6_ops.ipv6_recv_error = ipv6_recv_error;
93447- pingv6_ops.ip6_datagram_recv_ctl = ip6_datagram_recv_ctl;
93448- pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
93449- pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
93450- pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
93451+ pingv6_ops = &real_pingv6_ops;
93452 return inet6_register_protosw(&pingv6_protosw);
93453 }
93454
93455@@ -265,11 +277,7 @@ int __init pingv6_init(void)
93456 */
93457 void pingv6_exit(void)
93458 {
93459- pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
93460- pingv6_ops.ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl;
93461- pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
93462- pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
93463- pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
93464+ pingv6_ops = &dummy_pingv6_ops;
93465 #ifdef CONFIG_PROC_FS
93466 unregister_pernet_subsys(&ping_v6_net_ops);
93467 #endif
93468diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
93469index cdaed47..515edde9 100644
93470--- a/net/ipv6/raw.c
93471+++ b/net/ipv6/raw.c
93472@@ -108,7 +108,7 @@ found:
93473 */
93474 static int icmpv6_filter(const struct sock *sk, const struct sk_buff *skb)
93475 {
93476- struct icmp6hdr *_hdr;
93477+ struct icmp6hdr _hdr;
93478 const struct icmp6hdr *hdr;
93479
93480 hdr = skb_header_pointer(skb, skb_transport_offset(skb),
93481@@ -378,7 +378,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
93482 {
93483 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
93484 skb_checksum_complete(skb)) {
93485- atomic_inc(&sk->sk_drops);
93486+ atomic_inc_unchecked(&sk->sk_drops);
93487 kfree_skb(skb);
93488 return NET_RX_DROP;
93489 }
93490@@ -406,7 +406,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
93491 struct raw6_sock *rp = raw6_sk(sk);
93492
93493 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
93494- atomic_inc(&sk->sk_drops);
93495+ atomic_inc_unchecked(&sk->sk_drops);
93496 kfree_skb(skb);
93497 return NET_RX_DROP;
93498 }
93499@@ -430,7 +430,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
93500
93501 if (inet->hdrincl) {
93502 if (skb_checksum_complete(skb)) {
93503- atomic_inc(&sk->sk_drops);
93504+ atomic_inc_unchecked(&sk->sk_drops);
93505 kfree_skb(skb);
93506 return NET_RX_DROP;
93507 }
93508@@ -602,7 +602,7 @@ out:
93509 return err;
93510 }
93511
93512-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
93513+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
93514 struct flowi6 *fl6, struct dst_entry **dstp,
93515 unsigned int flags)
93516 {
93517@@ -915,12 +915,15 @@ do_confirm:
93518 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
93519 char __user *optval, int optlen)
93520 {
93521+ struct icmp6_filter filter;
93522+
93523 switch (optname) {
93524 case ICMPV6_FILTER:
93525 if (optlen > sizeof(struct icmp6_filter))
93526 optlen = sizeof(struct icmp6_filter);
93527- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
93528+ if (copy_from_user(&filter, optval, optlen))
93529 return -EFAULT;
93530+ raw6_sk(sk)->filter = filter;
93531 return 0;
93532 default:
93533 return -ENOPROTOOPT;
93534@@ -933,6 +936,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
93535 char __user *optval, int __user *optlen)
93536 {
93537 int len;
93538+ struct icmp6_filter filter;
93539
93540 switch (optname) {
93541 case ICMPV6_FILTER:
93542@@ -944,7 +948,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
93543 len = sizeof(struct icmp6_filter);
93544 if (put_user(len, optlen))
93545 return -EFAULT;
93546- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
93547+ filter = raw6_sk(sk)->filter;
93548+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
93549 return -EFAULT;
93550 return 0;
93551 default:
93552diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
93553index 1aeb473..bea761c 100644
93554--- a/net/ipv6/reassembly.c
93555+++ b/net/ipv6/reassembly.c
93556@@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
93557
93558 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
93559 {
93560- struct ctl_table *table;
93561+ ctl_table_no_const *table = NULL;
93562 struct ctl_table_header *hdr;
93563
93564- table = ip6_frags_ns_ctl_table;
93565 if (!net_eq(net, &init_net)) {
93566- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
93567+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
93568 if (table == NULL)
93569 goto err_alloc;
93570
93571@@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
93572 /* Don't export sysctls to unprivileged users */
93573 if (net->user_ns != &init_user_ns)
93574 table[0].procname = NULL;
93575- }
93576+ hdr = register_net_sysctl(net, "net/ipv6", table);
93577+ } else
93578+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
93579
93580- hdr = register_net_sysctl(net, "net/ipv6", table);
93581 if (hdr == NULL)
93582 goto err_reg;
93583
93584@@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
93585 return 0;
93586
93587 err_reg:
93588- if (!net_eq(net, &init_net))
93589- kfree(table);
93590+ kfree(table);
93591 err_alloc:
93592 return -ENOMEM;
93593 }
93594diff --git a/net/ipv6/route.c b/net/ipv6/route.c
93595index 8d9a93ed..cd89616 100644
93596--- a/net/ipv6/route.c
93597+++ b/net/ipv6/route.c
93598@@ -2926,7 +2926,7 @@ struct ctl_table ipv6_route_table_template[] = {
93599
93600 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
93601 {
93602- struct ctl_table *table;
93603+ ctl_table_no_const *table;
93604
93605 table = kmemdup(ipv6_route_table_template,
93606 sizeof(ipv6_route_table_template),
93607diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
93608index 86f639b..71e355e 100644
93609--- a/net/ipv6/sit.c
93610+++ b/net/ipv6/sit.c
93611@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
93612 static void ipip6_dev_free(struct net_device *dev);
93613 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
93614 __be32 *v4dst);
93615-static struct rtnl_link_ops sit_link_ops __read_mostly;
93616+static struct rtnl_link_ops sit_link_ops;
93617
93618 static int sit_net_id __read_mostly;
93619 struct sit_net {
93620@@ -1601,7 +1601,7 @@ static const struct nla_policy ipip6_policy[IFLA_IPTUN_MAX + 1] = {
93621 #endif
93622 };
93623
93624-static struct rtnl_link_ops sit_link_ops __read_mostly = {
93625+static struct rtnl_link_ops sit_link_ops = {
93626 .kind = "sit",
93627 .maxtype = IFLA_IPTUN_MAX,
93628 .policy = ipip6_policy,
93629diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
93630index 107b2f1..72741a9 100644
93631--- a/net/ipv6/sysctl_net_ipv6.c
93632+++ b/net/ipv6/sysctl_net_ipv6.c
93633@@ -40,7 +40,7 @@ static struct ctl_table ipv6_rotable[] = {
93634
93635 static int __net_init ipv6_sysctl_net_init(struct net *net)
93636 {
93637- struct ctl_table *ipv6_table;
93638+ ctl_table_no_const *ipv6_table;
93639 struct ctl_table *ipv6_route_table;
93640 struct ctl_table *ipv6_icmp_table;
93641 int err;
93642diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
93643index 6e1649d..75ddb4c 100644
93644--- a/net/ipv6/tcp_ipv6.c
93645+++ b/net/ipv6/tcp_ipv6.c
93646@@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
93647 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
93648 }
93649
93650+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93651+extern int grsec_enable_blackhole;
93652+#endif
93653+
93654 static void tcp_v6_hash(struct sock *sk)
93655 {
93656 if (sk->sk_state != TCP_CLOSE) {
93657@@ -1399,6 +1403,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
93658 return 0;
93659
93660 reset:
93661+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93662+ if (!grsec_enable_blackhole)
93663+#endif
93664 tcp_v6_send_reset(sk, skb);
93665 discard:
93666 if (opt_skb)
93667@@ -1427,7 +1434,7 @@ ipv6_pktoptions:
93668 if (np->rxopt.bits.rxhlim || np->rxopt.bits.rxohlim)
93669 np->mcast_hops = ipv6_hdr(opt_skb)->hop_limit;
93670 if (np->rxopt.bits.rxtclass)
93671- np->rcv_tclass = ipv6_get_dsfield(ipv6_hdr(skb));
93672+ np->rcv_tclass = ipv6_get_dsfield(ipv6_hdr(opt_skb));
93673 if (ipv6_opt_accepted(sk, opt_skb)) {
93674 skb_set_owner_r(opt_skb, sk);
93675 opt_skb = xchg(&np->pktoptions, opt_skb);
93676@@ -1481,12 +1488,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
93677 TCP_SKB_CB(skb)->sacked = 0;
93678
93679 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
93680- if (!sk)
93681+ if (!sk) {
93682+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93683+ ret = 1;
93684+#endif
93685 goto no_tcp_socket;
93686+ }
93687
93688 process:
93689- if (sk->sk_state == TCP_TIME_WAIT)
93690+ if (sk->sk_state == TCP_TIME_WAIT) {
93691+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93692+ ret = 2;
93693+#endif
93694 goto do_time_wait;
93695+ }
93696
93697 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
93698 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
93699@@ -1538,6 +1553,10 @@ csum_error:
93700 bad_packet:
93701 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
93702 } else {
93703+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93704+ if (!grsec_enable_blackhole || (ret == 1 &&
93705+ (skb->dev->flags & IFF_LOOPBACK)))
93706+#endif
93707 tcp_v6_send_reset(NULL, skb);
93708 }
93709
93710diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
93711index f405815..45a68a6 100644
93712--- a/net/ipv6/udp.c
93713+++ b/net/ipv6/udp.c
93714@@ -53,6 +53,10 @@
93715 #include <trace/events/skb.h>
93716 #include "udp_impl.h"
93717
93718+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93719+extern int grsec_enable_blackhole;
93720+#endif
93721+
93722 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
93723 {
93724 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
93725@@ -420,7 +424,7 @@ try_again:
93726 if (unlikely(err)) {
93727 trace_kfree_skb(skb, udpv6_recvmsg);
93728 if (!peeked) {
93729- atomic_inc(&sk->sk_drops);
93730+ atomic_inc_unchecked(&sk->sk_drops);
93731 if (is_udp4)
93732 UDP_INC_STATS_USER(sock_net(sk),
93733 UDP_MIB_INERRORS,
93734@@ -666,7 +670,7 @@ csum_error:
93735 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
93736 drop:
93737 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
93738- atomic_inc(&sk->sk_drops);
93739+ atomic_inc_unchecked(&sk->sk_drops);
93740 kfree_skb(skb);
93741 return -1;
93742 }
93743@@ -724,7 +728,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
93744 if (likely(skb1 == NULL))
93745 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
93746 if (!skb1) {
93747- atomic_inc(&sk->sk_drops);
93748+ atomic_inc_unchecked(&sk->sk_drops);
93749 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
93750 IS_UDPLITE(sk));
93751 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
93752@@ -864,6 +868,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
93753 goto csum_error;
93754
93755 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
93756+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93757+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
93758+#endif
93759 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
93760
93761 kfree_skb(skb);
93762diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
93763index 23ed03d..6532e67 100644
93764--- a/net/ipv6/xfrm6_policy.c
93765+++ b/net/ipv6/xfrm6_policy.c
93766@@ -207,11 +207,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
93767 }
93768 }
93769
93770-static inline int xfrm6_garbage_collect(struct dst_ops *ops)
93771+static int xfrm6_garbage_collect(struct dst_ops *ops)
93772 {
93773 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
93774
93775- xfrm6_policy_afinfo.garbage_collect(net);
93776+ xfrm_garbage_collect_deferred(net);
93777 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
93778 }
93779
93780@@ -324,19 +324,19 @@ static struct ctl_table xfrm6_policy_table[] = {
93781
93782 static int __net_init xfrm6_net_init(struct net *net)
93783 {
93784- struct ctl_table *table;
93785+ ctl_table_no_const *table = NULL;
93786 struct ctl_table_header *hdr;
93787
93788- table = xfrm6_policy_table;
93789 if (!net_eq(net, &init_net)) {
93790- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
93791+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
93792 if (!table)
93793 goto err_alloc;
93794
93795 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
93796- }
93797+ hdr = register_net_sysctl(net, "net/ipv6", table);
93798+ } else
93799+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
93800
93801- hdr = register_net_sysctl(net, "net/ipv6", table);
93802 if (!hdr)
93803 goto err_reg;
93804
93805@@ -344,8 +344,7 @@ static int __net_init xfrm6_net_init(struct net *net)
93806 return 0;
93807
93808 err_reg:
93809- if (!net_eq(net, &init_net))
93810- kfree(table);
93811+ kfree(table);
93812 err_alloc:
93813 return -ENOMEM;
93814 }
93815diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
93816index 41ac7938..75e3bb1 100644
93817--- a/net/irda/ircomm/ircomm_tty.c
93818+++ b/net/irda/ircomm/ircomm_tty.c
93819@@ -319,11 +319,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
93820 add_wait_queue(&port->open_wait, &wait);
93821
93822 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
93823- __FILE__, __LINE__, tty->driver->name, port->count);
93824+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
93825
93826 spin_lock_irqsave(&port->lock, flags);
93827 if (!tty_hung_up_p(filp))
93828- port->count--;
93829+ atomic_dec(&port->count);
93830 port->blocked_open++;
93831 spin_unlock_irqrestore(&port->lock, flags);
93832
93833@@ -358,7 +358,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
93834 }
93835
93836 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
93837- __FILE__, __LINE__, tty->driver->name, port->count);
93838+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
93839
93840 schedule();
93841 }
93842@@ -368,12 +368,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
93843
93844 spin_lock_irqsave(&port->lock, flags);
93845 if (!tty_hung_up_p(filp))
93846- port->count++;
93847+ atomic_inc(&port->count);
93848 port->blocked_open--;
93849 spin_unlock_irqrestore(&port->lock, flags);
93850
93851 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
93852- __FILE__, __LINE__, tty->driver->name, port->count);
93853+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
93854
93855 if (!retval)
93856 port->flags |= ASYNC_NORMAL_ACTIVE;
93857@@ -447,12 +447,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
93858
93859 /* ++ is not atomic, so this should be protected - Jean II */
93860 spin_lock_irqsave(&self->port.lock, flags);
93861- self->port.count++;
93862+ atomic_inc(&self->port.count);
93863 spin_unlock_irqrestore(&self->port.lock, flags);
93864 tty_port_tty_set(&self->port, tty);
93865
93866 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
93867- self->line, self->port.count);
93868+ self->line, atomic_read(&self->port.count));
93869
93870 /* Not really used by us, but lets do it anyway */
93871 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
93872@@ -989,7 +989,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
93873 tty_kref_put(port->tty);
93874 }
93875 port->tty = NULL;
93876- port->count = 0;
93877+ atomic_set(&port->count, 0);
93878 spin_unlock_irqrestore(&port->lock, flags);
93879
93880 wake_up_interruptible(&port->open_wait);
93881@@ -1346,7 +1346,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
93882 seq_putc(m, '\n');
93883
93884 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
93885- seq_printf(m, "Open count: %d\n", self->port.count);
93886+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
93887 seq_printf(m, "Max data size: %d\n", self->max_data_size);
93888 seq_printf(m, "Max header size: %d\n", self->max_header_size);
93889
93890diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
93891index 168aff5..9d43132 100644
93892--- a/net/iucv/af_iucv.c
93893+++ b/net/iucv/af_iucv.c
93894@@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
93895
93896 write_lock_bh(&iucv_sk_list.lock);
93897
93898- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
93899+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
93900 while (__iucv_get_sock_by_name(name)) {
93901 sprintf(name, "%08x",
93902- atomic_inc_return(&iucv_sk_list.autobind_name));
93903+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
93904 }
93905
93906 write_unlock_bh(&iucv_sk_list.lock);
93907diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
93908index cd5b8ec..f205e6b 100644
93909--- a/net/iucv/iucv.c
93910+++ b/net/iucv/iucv.c
93911@@ -690,7 +690,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
93912 return NOTIFY_OK;
93913 }
93914
93915-static struct notifier_block __refdata iucv_cpu_notifier = {
93916+static struct notifier_block iucv_cpu_notifier = {
93917 .notifier_call = iucv_cpu_notify,
93918 };
93919
93920diff --git a/net/key/af_key.c b/net/key/af_key.c
93921index ab8bd2c..3a3eb81 100644
93922--- a/net/key/af_key.c
93923+++ b/net/key/af_key.c
93924@@ -1098,7 +1098,8 @@ static struct xfrm_state * pfkey_msg2xfrm_state(struct net *net,
93925
93926 x->id.proto = proto;
93927 x->id.spi = sa->sadb_sa_spi;
93928- x->props.replay_window = sa->sadb_sa_replay;
93929+ x->props.replay_window = min_t(unsigned int, sa->sadb_sa_replay,
93930+ (sizeof(x->replay.bitmap) * 8));
93931 if (sa->sadb_sa_flags & SADB_SAFLAGS_NOECN)
93932 x->props.flags |= XFRM_STATE_NOECN;
93933 if (sa->sadb_sa_flags & SADB_SAFLAGS_DECAP_DSCP)
93934@@ -3048,10 +3049,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
93935 static u32 get_acqseq(void)
93936 {
93937 u32 res;
93938- static atomic_t acqseq;
93939+ static atomic_unchecked_t acqseq;
93940
93941 do {
93942- res = atomic_inc_return(&acqseq);
93943+ res = atomic_inc_return_unchecked(&acqseq);
93944 } while (!res);
93945 return res;
93946 }
93947diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c
93948index feae495..aedaa2c 100644
93949--- a/net/l2tp/l2tp_core.c
93950+++ b/net/l2tp/l2tp_core.c
93951@@ -496,6 +496,7 @@ out:
93952 static inline int l2tp_verify_udp_checksum(struct sock *sk,
93953 struct sk_buff *skb)
93954 {
93955+ struct l2tp_tunnel *tunnel = (struct l2tp_tunnel *)sk->sk_user_data;
93956 struct udphdr *uh = udp_hdr(skb);
93957 u16 ulen = ntohs(uh->len);
93958 __wsum psum;
93959@@ -504,7 +505,7 @@ static inline int l2tp_verify_udp_checksum(struct sock *sk,
93960 return 0;
93961
93962 #if IS_ENABLED(CONFIG_IPV6)
93963- if (sk->sk_family == PF_INET6) {
93964+ if (sk->sk_family == PF_INET6 && !tunnel->v4mapped) {
93965 if (!uh->check) {
93966 LIMIT_NETDEBUG(KERN_INFO "L2TP: IPv6: checksum is 0\n");
93967 return 1;
93968@@ -1128,7 +1129,7 @@ static int l2tp_xmit_core(struct l2tp_session *session, struct sk_buff *skb,
93969 /* Queue the packet to IP for output */
93970 skb->local_df = 1;
93971 #if IS_ENABLED(CONFIG_IPV6)
93972- if (skb->sk->sk_family == PF_INET6)
93973+ if (skb->sk->sk_family == PF_INET6 && !tunnel->v4mapped)
93974 error = inet6_csk_xmit(skb, NULL);
93975 else
93976 #endif
93977@@ -1255,7 +1256,7 @@ int l2tp_xmit_skb(struct l2tp_session *session, struct sk_buff *skb, int hdr_len
93978
93979 /* Calculate UDP checksum if configured to do so */
93980 #if IS_ENABLED(CONFIG_IPV6)
93981- if (sk->sk_family == PF_INET6)
93982+ if (sk->sk_family == PF_INET6 && !tunnel->v4mapped)
93983 l2tp_xmit_ipv6_csum(sk, skb, udp_len);
93984 else
93985 #endif
93986@@ -1704,6 +1705,24 @@ int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32
93987 if (cfg != NULL)
93988 tunnel->debug = cfg->debug;
93989
93990+#if IS_ENABLED(CONFIG_IPV6)
93991+ if (sk->sk_family == PF_INET6) {
93992+ struct ipv6_pinfo *np = inet6_sk(sk);
93993+
93994+ if (ipv6_addr_v4mapped(&np->saddr) &&
93995+ ipv6_addr_v4mapped(&np->daddr)) {
93996+ struct inet_sock *inet = inet_sk(sk);
93997+
93998+ tunnel->v4mapped = true;
93999+ inet->inet_saddr = np->saddr.s6_addr32[3];
94000+ inet->inet_rcv_saddr = np->rcv_saddr.s6_addr32[3];
94001+ inet->inet_daddr = np->daddr.s6_addr32[3];
94002+ } else {
94003+ tunnel->v4mapped = false;
94004+ }
94005+ }
94006+#endif
94007+
94008 /* Mark socket as an encapsulation socket. See net/ipv4/udp.c */
94009 tunnel->encap = encap;
94010 if (encap == L2TP_ENCAPTYPE_UDP) {
94011@@ -1712,7 +1731,7 @@ int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32
94012 udp_sk(sk)->encap_rcv = l2tp_udp_encap_recv;
94013 udp_sk(sk)->encap_destroy = l2tp_udp_encap_destroy;
94014 #if IS_ENABLED(CONFIG_IPV6)
94015- if (sk->sk_family == PF_INET6)
94016+ if (sk->sk_family == PF_INET6 && !tunnel->v4mapped)
94017 udpv6_encap_enable();
94018 else
94019 #endif
94020diff --git a/net/l2tp/l2tp_core.h b/net/l2tp/l2tp_core.h
94021index 66a559b..6f251cb 100644
94022--- a/net/l2tp/l2tp_core.h
94023+++ b/net/l2tp/l2tp_core.h
94024@@ -194,6 +194,9 @@ struct l2tp_tunnel {
94025 struct sock *sock; /* Parent socket */
94026 int fd; /* Parent fd, if tunnel socket
94027 * was created by userspace */
94028+#if IS_ENABLED(CONFIG_IPV6)
94029+ bool v4mapped;
94030+#endif
94031
94032 struct work_struct del_work;
94033
94034diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
94035index 43dd752..63a23bc 100644
94036--- a/net/mac80211/cfg.c
94037+++ b/net/mac80211/cfg.c
94038@@ -820,7 +820,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
94039 ret = ieee80211_vif_use_channel(sdata, chandef,
94040 IEEE80211_CHANCTX_EXCLUSIVE);
94041 }
94042- } else if (local->open_count == local->monitors) {
94043+ } else if (local_read(&local->open_count) == local->monitors) {
94044 local->_oper_chandef = *chandef;
94045 ieee80211_hw_config(local, 0);
94046 }
94047@@ -2941,7 +2941,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
94048 else
94049 local->probe_req_reg--;
94050
94051- if (!local->open_count)
94052+ if (!local_read(&local->open_count))
94053 break;
94054
94055 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
94056@@ -3404,8 +3404,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
94057 if (chanctx_conf) {
94058 *chandef = chanctx_conf->def;
94059 ret = 0;
94060- } else if (local->open_count > 0 &&
94061- local->open_count == local->monitors &&
94062+ } else if (local_read(&local->open_count) > 0 &&
94063+ local_read(&local->open_count) == local->monitors &&
94064 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
94065 if (local->use_chanctx)
94066 *chandef = local->monitor_chandef;
94067diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
94068index 8412a30..6e00181 100644
94069--- a/net/mac80211/ieee80211_i.h
94070+++ b/net/mac80211/ieee80211_i.h
94071@@ -28,6 +28,7 @@
94072 #include <net/ieee80211_radiotap.h>
94073 #include <net/cfg80211.h>
94074 #include <net/mac80211.h>
94075+#include <asm/local.h>
94076 #include "key.h"
94077 #include "sta_info.h"
94078 #include "debug.h"
94079@@ -907,7 +908,7 @@ struct ieee80211_local {
94080 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
94081 spinlock_t queue_stop_reason_lock;
94082
94083- int open_count;
94084+ local_t open_count;
94085 int monitors, cooked_mntrs;
94086 /* number of interfaces with corresponding FIF_ flags */
94087 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
94088diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
94089index cc11759..11d5541 100644
94090--- a/net/mac80211/iface.c
94091+++ b/net/mac80211/iface.c
94092@@ -511,7 +511,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
94093 break;
94094 }
94095
94096- if (local->open_count == 0) {
94097+ if (local_read(&local->open_count) == 0) {
94098 res = drv_start(local);
94099 if (res)
94100 goto err_del_bss;
94101@@ -558,7 +558,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
94102 res = drv_add_interface(local, sdata);
94103 if (res)
94104 goto err_stop;
94105- } else if (local->monitors == 0 && local->open_count == 0) {
94106+ } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
94107 res = ieee80211_add_virtual_monitor(local);
94108 if (res)
94109 goto err_stop;
94110@@ -666,7 +666,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
94111 atomic_inc(&local->iff_promiscs);
94112
94113 if (coming_up)
94114- local->open_count++;
94115+ local_inc(&local->open_count);
94116
94117 if (hw_reconf_flags)
94118 ieee80211_hw_config(local, hw_reconf_flags);
94119@@ -704,7 +704,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
94120 err_del_interface:
94121 drv_remove_interface(local, sdata);
94122 err_stop:
94123- if (!local->open_count)
94124+ if (!local_read(&local->open_count))
94125 drv_stop(local);
94126 err_del_bss:
94127 sdata->bss = NULL;
94128@@ -841,7 +841,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
94129 }
94130
94131 if (going_down)
94132- local->open_count--;
94133+ local_dec(&local->open_count);
94134
94135 switch (sdata->vif.type) {
94136 case NL80211_IFTYPE_AP_VLAN:
94137@@ -908,7 +908,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
94138 }
94139 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
94140
94141- if (local->open_count == 0)
94142+ if (local_read(&local->open_count) == 0)
94143 ieee80211_clear_tx_pending(local);
94144
94145 /*
94146@@ -948,7 +948,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
94147
94148 ieee80211_recalc_ps(local, -1);
94149
94150- if (local->open_count == 0) {
94151+ if (local_read(&local->open_count) == 0) {
94152 ieee80211_stop_device(local);
94153
94154 /* no reconfiguring after stop! */
94155@@ -959,7 +959,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
94156 ieee80211_configure_filter(local);
94157 ieee80211_hw_config(local, hw_reconf_flags);
94158
94159- if (local->monitors == local->open_count)
94160+ if (local->monitors == local_read(&local->open_count))
94161 ieee80211_add_virtual_monitor(local);
94162 }
94163
94164diff --git a/net/mac80211/main.c b/net/mac80211/main.c
94165index 091088a..daf43c7 100644
94166--- a/net/mac80211/main.c
94167+++ b/net/mac80211/main.c
94168@@ -181,7 +181,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
94169 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
94170 IEEE80211_CONF_CHANGE_POWER);
94171
94172- if (changed && local->open_count) {
94173+ if (changed && local_read(&local->open_count)) {
94174 ret = drv_config(local, changed);
94175 /*
94176 * Goal:
94177diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
94178index 3401262..d5cd68d 100644
94179--- a/net/mac80211/pm.c
94180+++ b/net/mac80211/pm.c
94181@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
94182 struct ieee80211_sub_if_data *sdata;
94183 struct sta_info *sta;
94184
94185- if (!local->open_count)
94186+ if (!local_read(&local->open_count))
94187 goto suspend;
94188
94189 ieee80211_scan_cancel(local);
94190@@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
94191 cancel_work_sync(&local->dynamic_ps_enable_work);
94192 del_timer_sync(&local->dynamic_ps_timer);
94193
94194- local->wowlan = wowlan && local->open_count;
94195+ local->wowlan = wowlan && local_read(&local->open_count);
94196 if (local->wowlan) {
94197 int err = drv_suspend(local, wowlan);
94198 if (err < 0) {
94199@@ -116,7 +116,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
94200 WARN_ON(!list_empty(&local->chanctx_list));
94201
94202 /* stop hardware - this must stop RX */
94203- if (local->open_count)
94204+ if (local_read(&local->open_count))
94205 ieee80211_stop_device(local);
94206
94207 suspend:
94208diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
94209index 30d58d2..449ac8e 100644
94210--- a/net/mac80211/rate.c
94211+++ b/net/mac80211/rate.c
94212@@ -718,7 +718,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
94213
94214 ASSERT_RTNL();
94215
94216- if (local->open_count)
94217+ if (local_read(&local->open_count))
94218 return -EBUSY;
94219
94220 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
94221diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
94222index c97a065..ff61928 100644
94223--- a/net/mac80211/rc80211_pid_debugfs.c
94224+++ b/net/mac80211/rc80211_pid_debugfs.c
94225@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
94226
94227 spin_unlock_irqrestore(&events->lock, status);
94228
94229- if (copy_to_user(buf, pb, p))
94230+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
94231 return -EFAULT;
94232
94233 return p;
94234diff --git a/net/mac80211/util.c b/net/mac80211/util.c
94235index 2265445..ba14971 100644
94236--- a/net/mac80211/util.c
94237+++ b/net/mac80211/util.c
94238@@ -1452,7 +1452,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
94239 }
94240 #endif
94241 /* everything else happens only if HW was up & running */
94242- if (!local->open_count)
94243+ if (!local_read(&local->open_count))
94244 goto wake_up;
94245
94246 /*
94247@@ -1677,7 +1677,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
94248 local->in_reconfig = false;
94249 barrier();
94250
94251- if (local->monitors == local->open_count && local->monitors > 0)
94252+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
94253 ieee80211_add_virtual_monitor(local);
94254
94255 /*
94256diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
94257index 56d22ca..87c778f 100644
94258--- a/net/netfilter/Kconfig
94259+++ b/net/netfilter/Kconfig
94260@@ -958,6 +958,16 @@ config NETFILTER_XT_MATCH_ESP
94261
94262 To compile it as a module, choose M here. If unsure, say N.
94263
94264+config NETFILTER_XT_MATCH_GRADM
94265+ tristate '"gradm" match support'
94266+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
94267+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
94268+ ---help---
94269+ The gradm match allows to match on grsecurity RBAC being enabled.
94270+ It is useful when iptables rules are applied early on bootup to
94271+ prevent connections to the machine (except from a trusted host)
94272+ while the RBAC system is disabled.
94273+
94274 config NETFILTER_XT_MATCH_HASHLIMIT
94275 tristate '"hashlimit" match support'
94276 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
94277diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
94278index a1abf87..dbcb7ee 100644
94279--- a/net/netfilter/Makefile
94280+++ b/net/netfilter/Makefile
94281@@ -112,6 +112,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
94282 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
94283 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
94284 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
94285+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
94286 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
94287 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
94288 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
94289diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
94290index f771390..145b765 100644
94291--- a/net/netfilter/ipset/ip_set_core.c
94292+++ b/net/netfilter/ipset/ip_set_core.c
94293@@ -1820,7 +1820,7 @@ done:
94294 return ret;
94295 }
94296
94297-static struct nf_sockopt_ops so_set __read_mostly = {
94298+static struct nf_sockopt_ops so_set = {
94299 .pf = PF_INET,
94300 .get_optmin = SO_IP_SET,
94301 .get_optmax = SO_IP_SET + 1,
94302diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
94303index 4c8e5c0..5a79b4d 100644
94304--- a/net/netfilter/ipvs/ip_vs_conn.c
94305+++ b/net/netfilter/ipvs/ip_vs_conn.c
94306@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
94307 /* Increase the refcnt counter of the dest */
94308 ip_vs_dest_hold(dest);
94309
94310- conn_flags = atomic_read(&dest->conn_flags);
94311+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
94312 if (cp->protocol != IPPROTO_UDP)
94313 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
94314 flags = cp->flags;
94315@@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
94316
94317 cp->control = NULL;
94318 atomic_set(&cp->n_control, 0);
94319- atomic_set(&cp->in_pkts, 0);
94320+ atomic_set_unchecked(&cp->in_pkts, 0);
94321
94322 cp->packet_xmit = NULL;
94323 cp->app = NULL;
94324@@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
94325
94326 /* Don't drop the entry if its number of incoming packets is not
94327 located in [0, 8] */
94328- i = atomic_read(&cp->in_pkts);
94329+ i = atomic_read_unchecked(&cp->in_pkts);
94330 if (i > 8 || i < 0) return 0;
94331
94332 if (!todrop_rate[i]) return 0;
94333diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
94334index 4f69e83..da2d8bf 100644
94335--- a/net/netfilter/ipvs/ip_vs_core.c
94336+++ b/net/netfilter/ipvs/ip_vs_core.c
94337@@ -559,7 +559,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
94338 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
94339 /* do not touch skb anymore */
94340
94341- atomic_inc(&cp->in_pkts);
94342+ atomic_inc_unchecked(&cp->in_pkts);
94343 ip_vs_conn_put(cp);
94344 return ret;
94345 }
94346@@ -1711,7 +1711,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
94347 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
94348 pkts = sysctl_sync_threshold(ipvs);
94349 else
94350- pkts = atomic_add_return(1, &cp->in_pkts);
94351+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
94352
94353 if (ipvs->sync_state & IP_VS_STATE_MASTER)
94354 ip_vs_sync_conn(net, cp, pkts);
94355diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
94356index c8148e4..eff604f 100644
94357--- a/net/netfilter/ipvs/ip_vs_ctl.c
94358+++ b/net/netfilter/ipvs/ip_vs_ctl.c
94359@@ -789,7 +789,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
94360 */
94361 ip_vs_rs_hash(ipvs, dest);
94362 }
94363- atomic_set(&dest->conn_flags, conn_flags);
94364+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
94365
94366 /* bind the service */
94367 if (!dest->svc) {
94368@@ -1657,7 +1657,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
94369 * align with netns init in ip_vs_control_net_init()
94370 */
94371
94372-static struct ctl_table vs_vars[] = {
94373+static ctl_table_no_const vs_vars[] __read_only = {
94374 {
94375 .procname = "amemthresh",
94376 .maxlen = sizeof(int),
94377@@ -2078,7 +2078,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
94378 " %-7s %-6d %-10d %-10d\n",
94379 &dest->addr.in6,
94380 ntohs(dest->port),
94381- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
94382+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
94383 atomic_read(&dest->weight),
94384 atomic_read(&dest->activeconns),
94385 atomic_read(&dest->inactconns));
94386@@ -2089,7 +2089,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
94387 "%-7s %-6d %-10d %-10d\n",
94388 ntohl(dest->addr.ip),
94389 ntohs(dest->port),
94390- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
94391+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
94392 atomic_read(&dest->weight),
94393 atomic_read(&dest->activeconns),
94394 atomic_read(&dest->inactconns));
94395@@ -2567,7 +2567,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
94396
94397 entry.addr = dest->addr.ip;
94398 entry.port = dest->port;
94399- entry.conn_flags = atomic_read(&dest->conn_flags);
94400+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
94401 entry.weight = atomic_read(&dest->weight);
94402 entry.u_threshold = dest->u_threshold;
94403 entry.l_threshold = dest->l_threshold;
94404@@ -3110,7 +3110,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
94405 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
94406 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
94407 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
94408- (atomic_read(&dest->conn_flags) &
94409+ (atomic_read_unchecked(&dest->conn_flags) &
94410 IP_VS_CONN_F_FWD_MASK)) ||
94411 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
94412 atomic_read(&dest->weight)) ||
94413@@ -3700,7 +3700,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
94414 {
94415 int idx;
94416 struct netns_ipvs *ipvs = net_ipvs(net);
94417- struct ctl_table *tbl;
94418+ ctl_table_no_const *tbl;
94419
94420 atomic_set(&ipvs->dropentry, 0);
94421 spin_lock_init(&ipvs->dropentry_lock);
94422diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
94423index 1383b0e..a486da1 100644
94424--- a/net/netfilter/ipvs/ip_vs_lblc.c
94425+++ b/net/netfilter/ipvs/ip_vs_lblc.c
94426@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
94427 * IPVS LBLC sysctl table
94428 */
94429 #ifdef CONFIG_SYSCTL
94430-static struct ctl_table vs_vars_table[] = {
94431+static ctl_table_no_const vs_vars_table[] __read_only = {
94432 {
94433 .procname = "lblc_expiration",
94434 .data = NULL,
94435diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
94436index 3cd85b2..dfab2b8 100644
94437--- a/net/netfilter/ipvs/ip_vs_lblcr.c
94438+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
94439@@ -299,7 +299,7 @@ struct ip_vs_lblcr_table {
94440 * IPVS LBLCR sysctl table
94441 */
94442
94443-static struct ctl_table vs_vars_table[] = {
94444+static ctl_table_no_const vs_vars_table[] __read_only = {
94445 {
94446 .procname = "lblcr_expiration",
94447 .data = NULL,
94448diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
94449index f448471..995f131 100644
94450--- a/net/netfilter/ipvs/ip_vs_sync.c
94451+++ b/net/netfilter/ipvs/ip_vs_sync.c
94452@@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
94453 cp = cp->control;
94454 if (cp) {
94455 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
94456- pkts = atomic_add_return(1, &cp->in_pkts);
94457+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
94458 else
94459 pkts = sysctl_sync_threshold(ipvs);
94460 ip_vs_sync_conn(net, cp->control, pkts);
94461@@ -771,7 +771,7 @@ control:
94462 if (!cp)
94463 return;
94464 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
94465- pkts = atomic_add_return(1, &cp->in_pkts);
94466+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
94467 else
94468 pkts = sysctl_sync_threshold(ipvs);
94469 goto sloop;
94470@@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
94471
94472 if (opt)
94473 memcpy(&cp->in_seq, opt, sizeof(*opt));
94474- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
94475+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
94476 cp->state = state;
94477 cp->old_state = cp->state;
94478 /*
94479diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
94480index c47444e..b0961c6 100644
94481--- a/net/netfilter/ipvs/ip_vs_xmit.c
94482+++ b/net/netfilter/ipvs/ip_vs_xmit.c
94483@@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
94484 else
94485 rc = NF_ACCEPT;
94486 /* do not touch skb anymore */
94487- atomic_inc(&cp->in_pkts);
94488+ atomic_inc_unchecked(&cp->in_pkts);
94489 goto out;
94490 }
94491
94492@@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
94493 else
94494 rc = NF_ACCEPT;
94495 /* do not touch skb anymore */
94496- atomic_inc(&cp->in_pkts);
94497+ atomic_inc_unchecked(&cp->in_pkts);
94498 goto out;
94499 }
94500
94501diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
94502index 2d3030a..7ba1c0a 100644
94503--- a/net/netfilter/nf_conntrack_acct.c
94504+++ b/net/netfilter/nf_conntrack_acct.c
94505@@ -60,7 +60,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
94506 #ifdef CONFIG_SYSCTL
94507 static int nf_conntrack_acct_init_sysctl(struct net *net)
94508 {
94509- struct ctl_table *table;
94510+ ctl_table_no_const *table;
94511
94512 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
94513 GFP_KERNEL);
94514diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
94515index 0283bae..5febcb0 100644
94516--- a/net/netfilter/nf_conntrack_core.c
94517+++ b/net/netfilter/nf_conntrack_core.c
94518@@ -1614,6 +1614,10 @@ void nf_conntrack_init_end(void)
94519 #define DYING_NULLS_VAL ((1<<30)+1)
94520 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
94521
94522+#ifdef CONFIG_GRKERNSEC_HIDESYM
94523+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
94524+#endif
94525+
94526 int nf_conntrack_init_net(struct net *net)
94527 {
94528 int ret;
94529@@ -1628,7 +1632,11 @@ int nf_conntrack_init_net(struct net *net)
94530 goto err_stat;
94531 }
94532
94533+#ifdef CONFIG_GRKERNSEC_HIDESYM
94534+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
94535+#else
94536 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
94537+#endif
94538 if (!net->ct.slabname) {
94539 ret = -ENOMEM;
94540 goto err_slabname;
94541diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
94542index 1df1761..ce8b88a 100644
94543--- a/net/netfilter/nf_conntrack_ecache.c
94544+++ b/net/netfilter/nf_conntrack_ecache.c
94545@@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
94546 #ifdef CONFIG_SYSCTL
94547 static int nf_conntrack_event_init_sysctl(struct net *net)
94548 {
94549- struct ctl_table *table;
94550+ ctl_table_no_const *table;
94551
94552 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
94553 GFP_KERNEL);
94554diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
94555index 974a2a4..52cc6ff 100644
94556--- a/net/netfilter/nf_conntrack_helper.c
94557+++ b/net/netfilter/nf_conntrack_helper.c
94558@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
94559
94560 static int nf_conntrack_helper_init_sysctl(struct net *net)
94561 {
94562- struct ctl_table *table;
94563+ ctl_table_no_const *table;
94564
94565 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
94566 GFP_KERNEL);
94567diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
94568index 0ab9636..cea3c6a 100644
94569--- a/net/netfilter/nf_conntrack_proto.c
94570+++ b/net/netfilter/nf_conntrack_proto.c
94571@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
94572
94573 static void
94574 nf_ct_unregister_sysctl(struct ctl_table_header **header,
94575- struct ctl_table **table,
94576+ ctl_table_no_const **table,
94577 unsigned int users)
94578 {
94579 if (users > 0)
94580diff --git a/net/netfilter/nf_conntrack_proto_dccp.c b/net/netfilter/nf_conntrack_proto_dccp.c
94581index a99b6c3..cb372f9 100644
94582--- a/net/netfilter/nf_conntrack_proto_dccp.c
94583+++ b/net/netfilter/nf_conntrack_proto_dccp.c
94584@@ -428,7 +428,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
94585 const char *msg;
94586 u_int8_t state;
94587
94588- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
94589+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
94590 BUG_ON(dh == NULL);
94591
94592 state = dccp_state_table[CT_DCCP_ROLE_CLIENT][dh->dccph_type][CT_DCCP_NONE];
94593@@ -457,7 +457,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
94594 out_invalid:
94595 if (LOG_INVALID(net, IPPROTO_DCCP))
94596 nf_log_packet(net, nf_ct_l3num(ct), 0, skb, NULL, NULL,
94597- NULL, msg);
94598+ NULL, "%s", msg);
94599 return false;
94600 }
94601
94602@@ -486,7 +486,7 @@ static int dccp_packet(struct nf_conn *ct, const struct sk_buff *skb,
94603 u_int8_t type, old_state, new_state;
94604 enum ct_dccp_roles role;
94605
94606- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
94607+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
94608 BUG_ON(dh == NULL);
94609 type = dh->dccph_type;
94610
94611@@ -577,7 +577,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
94612 unsigned int cscov;
94613 const char *msg;
94614
94615- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
94616+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
94617 if (dh == NULL) {
94618 msg = "nf_ct_dccp: short packet ";
94619 goto out_invalid;
94620@@ -614,7 +614,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
94621
94622 out_invalid:
94623 if (LOG_INVALID(net, IPPROTO_DCCP))
94624- nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, msg);
94625+ nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, "%s", msg);
94626 return -NF_ACCEPT;
94627 }
94628
94629diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
94630index f641751..d3c5b51 100644
94631--- a/net/netfilter/nf_conntrack_standalone.c
94632+++ b/net/netfilter/nf_conntrack_standalone.c
94633@@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
94634
94635 static int nf_conntrack_standalone_init_sysctl(struct net *net)
94636 {
94637- struct ctl_table *table;
94638+ ctl_table_no_const *table;
94639
94640 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
94641 GFP_KERNEL);
94642diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
94643index 902fb0a..87f7fdb 100644
94644--- a/net/netfilter/nf_conntrack_timestamp.c
94645+++ b/net/netfilter/nf_conntrack_timestamp.c
94646@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
94647 #ifdef CONFIG_SYSCTL
94648 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
94649 {
94650- struct ctl_table *table;
94651+ ctl_table_no_const *table;
94652
94653 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
94654 GFP_KERNEL);
94655diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
94656index 85296d4..8becdec 100644
94657--- a/net/netfilter/nf_log.c
94658+++ b/net/netfilter/nf_log.c
94659@@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
94660
94661 #ifdef CONFIG_SYSCTL
94662 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
94663-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
94664+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
94665
94666 static int nf_log_proc_dostring(struct ctl_table *table, int write,
94667 void __user *buffer, size_t *lenp, loff_t *ppos)
94668@@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
94669 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
94670 mutex_unlock(&nf_log_mutex);
94671 } else {
94672+ ctl_table_no_const nf_log_table = *table;
94673+
94674 mutex_lock(&nf_log_mutex);
94675 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
94676 lockdep_is_held(&nf_log_mutex));
94677 if (!logger)
94678- table->data = "NONE";
94679+ nf_log_table.data = "NONE";
94680 else
94681- table->data = logger->name;
94682- r = proc_dostring(table, write, buffer, lenp, ppos);
94683+ nf_log_table.data = logger->name;
94684+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
94685 mutex_unlock(&nf_log_mutex);
94686 }
94687
94688diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
94689index f042ae5..30ea486 100644
94690--- a/net/netfilter/nf_sockopt.c
94691+++ b/net/netfilter/nf_sockopt.c
94692@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
94693 }
94694 }
94695
94696- list_add(&reg->list, &nf_sockopts);
94697+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
94698 out:
94699 mutex_unlock(&nf_sockopt_mutex);
94700 return ret;
94701@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
94702 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
94703 {
94704 mutex_lock(&nf_sockopt_mutex);
94705- list_del(&reg->list);
94706+ pax_list_del((struct list_head *)&reg->list);
94707 mutex_unlock(&nf_sockopt_mutex);
94708 }
94709 EXPORT_SYMBOL(nf_unregister_sockopt);
94710diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
94711index d92cc31..e46f350 100644
94712--- a/net/netfilter/nfnetlink_log.c
94713+++ b/net/netfilter/nfnetlink_log.c
94714@@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
94715 struct nfnl_log_net {
94716 spinlock_t instances_lock;
94717 struct hlist_head instance_table[INSTANCE_BUCKETS];
94718- atomic_t global_seq;
94719+ atomic_unchecked_t global_seq;
94720 };
94721
94722 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
94723@@ -563,7 +563,7 @@ __build_packet_message(struct nfnl_log_net *log,
94724 /* global sequence number */
94725 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
94726 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
94727- htonl(atomic_inc_return(&log->global_seq))))
94728+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
94729 goto nla_put_failure;
94730
94731 if (data_len) {
94732diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
94733new file mode 100644
94734index 0000000..c566332
94735--- /dev/null
94736+++ b/net/netfilter/xt_gradm.c
94737@@ -0,0 +1,51 @@
94738+/*
94739+ * gradm match for netfilter
94740