]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.11.7-201311071634.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.11.7-201311071634.patch
CommitLineData
1d726e34
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 686adf7..f2e53a7 100644
285--- a/Makefile
286+++ b/Makefile
287@@ -241,8 +241,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
288
289 HOSTCC = gcc
290 HOSTCXX = g++
291-HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
292-HOSTCXXFLAGS = -O2
293+HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
294+HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
295+HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
296
297 # Decide whether to build built-in, modular, or both.
298 # Normally, just do built-in.
299@@ -414,8 +415,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
300 # Rules shared between *config targets and build targets
301
302 # Basic helpers built in scripts/
303-PHONY += scripts_basic
304-scripts_basic:
305+PHONY += scripts_basic gcc-plugins
306+scripts_basic: gcc-plugins
307 $(Q)$(MAKE) $(build)=scripts/basic
308 $(Q)rm -f .tmp_quiet_recordmcount
309
310@@ -576,6 +577,65 @@ else
311 KBUILD_CFLAGS += -O2
312 endif
313
314+ifndef DISABLE_PAX_PLUGINS
315+ifeq ($(call cc-ifversion, -ge, 0408, y), y)
316+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
317+else
318+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
319+endif
320+ifneq ($(PLUGINCC),)
321+ifdef CONFIG_PAX_CONSTIFY_PLUGIN
322+CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
323+endif
324+ifdef CONFIG_PAX_MEMORY_STACKLEAK
325+STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
326+STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
327+endif
328+ifdef CONFIG_KALLOCSTAT_PLUGIN
329+KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
330+endif
331+ifdef CONFIG_PAX_KERNEXEC_PLUGIN
332+KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
333+KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
334+KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
335+endif
336+ifdef CONFIG_CHECKER_PLUGIN
337+ifeq ($(call cc-ifversion, -ge, 0406, y), y)
338+CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
339+endif
340+endif
341+COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
342+ifdef CONFIG_PAX_SIZE_OVERFLOW
343+SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
344+endif
345+ifdef CONFIG_PAX_LATENT_ENTROPY
346+LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
347+endif
348+ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
349+STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
350+endif
351+GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
352+GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
353+GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
354+GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
355+export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN
356+ifeq ($(KBUILD_EXTMOD),)
357+gcc-plugins:
358+ $(Q)$(MAKE) $(build)=tools/gcc
359+else
360+gcc-plugins: ;
361+endif
362+else
363+gcc-plugins:
364+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
365+ $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
366+else
367+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
368+endif
369+ $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
370+endif
371+endif
372+
373 include $(srctree)/arch/$(SRCARCH)/Makefile
374
375 ifdef CONFIG_READABLE_ASM
376@@ -733,7 +793,7 @@ export mod_sign_cmd
377
378
379 ifeq ($(KBUILD_EXTMOD),)
380-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
381+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
382
383 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
384 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
385@@ -782,6 +842,8 @@ endif
386
387 # The actual objects are generated when descending,
388 # make sure no implicit rule kicks in
389+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
390+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
391 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
392
393 # Handle descending into subdirectories listed in $(vmlinux-dirs)
394@@ -791,7 +853,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
395 # Error messages still appears in the original language
396
397 PHONY += $(vmlinux-dirs)
398-$(vmlinux-dirs): prepare scripts
399+$(vmlinux-dirs): gcc-plugins prepare scripts
400 $(Q)$(MAKE) $(build)=$@
401
402 # Store (new) KERNELRELEASE string in include/config/kernel.release
403@@ -835,6 +897,7 @@ prepare0: archprepare FORCE
404 $(Q)$(MAKE) $(build)=.
405
406 # All the preparing..
407+prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
408 prepare: prepare0
409
410 # Generate some files
411@@ -942,6 +1005,8 @@ all: modules
412 # using awk while concatenating to the final file.
413
414 PHONY += modules
415+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
416+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
417 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
418 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
419 @$(kecho) ' Building modules, stage 2.';
420@@ -957,7 +1022,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
421
422 # Target to prepare building external modules
423 PHONY += modules_prepare
424-modules_prepare: prepare scripts
425+modules_prepare: gcc-plugins prepare scripts
426
427 # Target to install modules
428 PHONY += modules_install
429@@ -1023,7 +1088,7 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
430 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
431 signing_key.priv signing_key.x509 x509.genkey \
432 extra_certificates signing_key.x509.keyid \
433- signing_key.x509.signer
434+ signing_key.x509.signer tools/gcc/size_overflow_hash.h
435
436 # clean - Delete most, but leave enough to build external modules
437 #
438@@ -1063,6 +1128,7 @@ distclean: mrproper
439 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
440 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
441 -o -name '.*.rej' \
442+ -o -name '.*.rej' -o -name '*.so' \
443 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
444 -type f -print | xargs rm -f
445
446@@ -1224,6 +1290,8 @@ PHONY += $(module-dirs) modules
447 $(module-dirs): crmodverdir $(objtree)/Module.symvers
448 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
449
450+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
451+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
452 modules: $(module-dirs)
453 @$(kecho) ' Building modules, stage 2.';
454 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
455@@ -1363,17 +1431,21 @@ else
456 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
457 endif
458
459-%.s: %.c prepare scripts FORCE
460+%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
461+%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
462+%.s: %.c gcc-plugins prepare scripts FORCE
463 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
464 %.i: %.c prepare scripts FORCE
465 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
466-%.o: %.c prepare scripts FORCE
467+%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
468+%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
469+%.o: %.c gcc-plugins prepare scripts FORCE
470 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
471 %.lst: %.c prepare scripts FORCE
472 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
473-%.s: %.S prepare scripts FORCE
474+%.s: %.S gcc-plugins prepare scripts FORCE
475 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
476-%.o: %.S prepare scripts FORCE
477+%.o: %.S gcc-plugins prepare scripts FORCE
478 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
479 %.symtypes: %.c prepare scripts FORCE
480 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
481@@ -1383,11 +1455,15 @@ endif
482 $(cmd_crmodverdir)
483 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
484 $(build)=$(build-dir)
485-%/: prepare scripts FORCE
486+%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
487+%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
488+%/: gcc-plugins prepare scripts FORCE
489 $(cmd_crmodverdir)
490 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
491 $(build)=$(build-dir)
492-%.ko: prepare scripts FORCE
493+%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
494+%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
495+%.ko: gcc-plugins prepare scripts FORCE
496 $(cmd_crmodverdir)
497 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
498 $(build)=$(build-dir) $(@:.ko=.o)
499diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
500index 78b03ef..da28a51 100644
501--- a/arch/alpha/include/asm/atomic.h
502+++ b/arch/alpha/include/asm/atomic.h
503@@ -292,6 +292,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
504 #define atomic_dec(v) atomic_sub(1,(v))
505 #define atomic64_dec(v) atomic64_sub(1,(v))
506
507+#define atomic64_read_unchecked(v) atomic64_read(v)
508+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
509+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
510+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
511+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
512+#define atomic64_inc_unchecked(v) atomic64_inc(v)
513+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
514+#define atomic64_dec_unchecked(v) atomic64_dec(v)
515+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
516+
517 #define smp_mb__before_atomic_dec() smp_mb()
518 #define smp_mb__after_atomic_dec() smp_mb()
519 #define smp_mb__before_atomic_inc() smp_mb()
520diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
521index ad368a9..fbe0f25 100644
522--- a/arch/alpha/include/asm/cache.h
523+++ b/arch/alpha/include/asm/cache.h
524@@ -4,19 +4,19 @@
525 #ifndef __ARCH_ALPHA_CACHE_H
526 #define __ARCH_ALPHA_CACHE_H
527
528+#include <linux/const.h>
529
530 /* Bytes per L1 (data) cache line. */
531 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
532-# define L1_CACHE_BYTES 64
533 # define L1_CACHE_SHIFT 6
534 #else
535 /* Both EV4 and EV5 are write-through, read-allocate,
536 direct-mapped, physical.
537 */
538-# define L1_CACHE_BYTES 32
539 # define L1_CACHE_SHIFT 5
540 #endif
541
542+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
543 #define SMP_CACHE_BYTES L1_CACHE_BYTES
544
545 #endif
546diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
547index 968d999..d36b2df 100644
548--- a/arch/alpha/include/asm/elf.h
549+++ b/arch/alpha/include/asm/elf.h
550@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
551
552 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
553
554+#ifdef CONFIG_PAX_ASLR
555+#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
556+
557+#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
558+#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
559+#endif
560+
561 /* $0 is set by ld.so to a pointer to a function which might be
562 registered using atexit. This provides a mean for the dynamic
563 linker to call DT_FINI functions for shared libraries that have
564diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
565index bc2a0da..8ad11ee 100644
566--- a/arch/alpha/include/asm/pgalloc.h
567+++ b/arch/alpha/include/asm/pgalloc.h
568@@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
569 pgd_set(pgd, pmd);
570 }
571
572+static inline void
573+pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
574+{
575+ pgd_populate(mm, pgd, pmd);
576+}
577+
578 extern pgd_t *pgd_alloc(struct mm_struct *mm);
579
580 static inline void
581diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
582index d8f9b7e..f6222fa 100644
583--- a/arch/alpha/include/asm/pgtable.h
584+++ b/arch/alpha/include/asm/pgtable.h
585@@ -102,6 +102,17 @@ struct vm_area_struct;
586 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
587 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
588 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
589+
590+#ifdef CONFIG_PAX_PAGEEXEC
591+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
592+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
593+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
594+#else
595+# define PAGE_SHARED_NOEXEC PAGE_SHARED
596+# define PAGE_COPY_NOEXEC PAGE_COPY
597+# define PAGE_READONLY_NOEXEC PAGE_READONLY
598+#endif
599+
600 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
601
602 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
603diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
604index 2fd00b7..cfd5069 100644
605--- a/arch/alpha/kernel/module.c
606+++ b/arch/alpha/kernel/module.c
607@@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
608
609 /* The small sections were sorted to the end of the segment.
610 The following should definitely cover them. */
611- gp = (u64)me->module_core + me->core_size - 0x8000;
612+ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
613 got = sechdrs[me->arch.gotsecindex].sh_addr;
614
615 for (i = 0; i < n; i++) {
616diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
617index 1402fcc..0b1abd2 100644
618--- a/arch/alpha/kernel/osf_sys.c
619+++ b/arch/alpha/kernel/osf_sys.c
620@@ -1298,10 +1298,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
621 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
622
623 static unsigned long
624-arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
625- unsigned long limit)
626+arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
627+ unsigned long limit, unsigned long flags)
628 {
629 struct vm_unmapped_area_info info;
630+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
631
632 info.flags = 0;
633 info.length = len;
634@@ -1309,6 +1310,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
635 info.high_limit = limit;
636 info.align_mask = 0;
637 info.align_offset = 0;
638+ info.threadstack_offset = offset;
639 return vm_unmapped_area(&info);
640 }
641
642@@ -1341,20 +1343,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
643 merely specific addresses, but regions of memory -- perhaps
644 this feature should be incorporated into all ports? */
645
646+#ifdef CONFIG_PAX_RANDMMAP
647+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
648+#endif
649+
650 if (addr) {
651- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
652+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
653 if (addr != (unsigned long) -ENOMEM)
654 return addr;
655 }
656
657 /* Next, try allocating at TASK_UNMAPPED_BASE. */
658- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
659- len, limit);
660+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
661+
662 if (addr != (unsigned long) -ENOMEM)
663 return addr;
664
665 /* Finally, try allocating in low memory. */
666- addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
667+ addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
668
669 return addr;
670 }
671diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
672index 0c4132d..88f0d53 100644
673--- a/arch/alpha/mm/fault.c
674+++ b/arch/alpha/mm/fault.c
675@@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
676 __reload_thread(pcb);
677 }
678
679+#ifdef CONFIG_PAX_PAGEEXEC
680+/*
681+ * PaX: decide what to do with offenders (regs->pc = fault address)
682+ *
683+ * returns 1 when task should be killed
684+ * 2 when patched PLT trampoline was detected
685+ * 3 when unpatched PLT trampoline was detected
686+ */
687+static int pax_handle_fetch_fault(struct pt_regs *regs)
688+{
689+
690+#ifdef CONFIG_PAX_EMUPLT
691+ int err;
692+
693+ do { /* PaX: patched PLT emulation #1 */
694+ unsigned int ldah, ldq, jmp;
695+
696+ err = get_user(ldah, (unsigned int *)regs->pc);
697+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
698+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
699+
700+ if (err)
701+ break;
702+
703+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
704+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
705+ jmp == 0x6BFB0000U)
706+ {
707+ unsigned long r27, addr;
708+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
709+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
710+
711+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
712+ err = get_user(r27, (unsigned long *)addr);
713+ if (err)
714+ break;
715+
716+ regs->r27 = r27;
717+ regs->pc = r27;
718+ return 2;
719+ }
720+ } while (0);
721+
722+ do { /* PaX: patched PLT emulation #2 */
723+ unsigned int ldah, lda, br;
724+
725+ err = get_user(ldah, (unsigned int *)regs->pc);
726+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
727+ err |= get_user(br, (unsigned int *)(regs->pc+8));
728+
729+ if (err)
730+ break;
731+
732+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
733+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
734+ (br & 0xFFE00000U) == 0xC3E00000U)
735+ {
736+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
737+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
738+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
739+
740+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
741+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
742+ return 2;
743+ }
744+ } while (0);
745+
746+ do { /* PaX: unpatched PLT emulation */
747+ unsigned int br;
748+
749+ err = get_user(br, (unsigned int *)regs->pc);
750+
751+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
752+ unsigned int br2, ldq, nop, jmp;
753+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
754+
755+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
756+ err = get_user(br2, (unsigned int *)addr);
757+ err |= get_user(ldq, (unsigned int *)(addr+4));
758+ err |= get_user(nop, (unsigned int *)(addr+8));
759+ err |= get_user(jmp, (unsigned int *)(addr+12));
760+ err |= get_user(resolver, (unsigned long *)(addr+16));
761+
762+ if (err)
763+ break;
764+
765+ if (br2 == 0xC3600000U &&
766+ ldq == 0xA77B000CU &&
767+ nop == 0x47FF041FU &&
768+ jmp == 0x6B7B0000U)
769+ {
770+ regs->r28 = regs->pc+4;
771+ regs->r27 = addr+16;
772+ regs->pc = resolver;
773+ return 3;
774+ }
775+ }
776+ } while (0);
777+#endif
778+
779+ return 1;
780+}
781+
782+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
783+{
784+ unsigned long i;
785+
786+ printk(KERN_ERR "PAX: bytes at PC: ");
787+ for (i = 0; i < 5; i++) {
788+ unsigned int c;
789+ if (get_user(c, (unsigned int *)pc+i))
790+ printk(KERN_CONT "???????? ");
791+ else
792+ printk(KERN_CONT "%08x ", c);
793+ }
794+ printk("\n");
795+}
796+#endif
797
798 /*
799 * This routine handles page faults. It determines the address,
800@@ -133,8 +251,29 @@ retry:
801 good_area:
802 si_code = SEGV_ACCERR;
803 if (cause < 0) {
804- if (!(vma->vm_flags & VM_EXEC))
805+ if (!(vma->vm_flags & VM_EXEC)) {
806+
807+#ifdef CONFIG_PAX_PAGEEXEC
808+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
809+ goto bad_area;
810+
811+ up_read(&mm->mmap_sem);
812+ switch (pax_handle_fetch_fault(regs)) {
813+
814+#ifdef CONFIG_PAX_EMUPLT
815+ case 2:
816+ case 3:
817+ return;
818+#endif
819+
820+ }
821+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
822+ do_group_exit(SIGKILL);
823+#else
824 goto bad_area;
825+#endif
826+
827+ }
828 } else if (!cause) {
829 /* Allow reads even for write-only mappings */
830 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
831diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
832index 43594d5..da71e62 100644
833--- a/arch/arm/Kconfig
834+++ b/arch/arm/Kconfig
835@@ -1791,7 +1791,7 @@ config ALIGNMENT_TRAP
836
837 config UACCESS_WITH_MEMCPY
838 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
839- depends on MMU
840+ depends on MMU && !PAX_MEMORY_UDEREF
841 default y if CPU_FEROCEON
842 help
843 Implement faster copy_to_user and clear_user methods for CPU
844diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
845index da1c77d..2ee6056 100644
846--- a/arch/arm/include/asm/atomic.h
847+++ b/arch/arm/include/asm/atomic.h
848@@ -17,17 +17,35 @@
849 #include <asm/barrier.h>
850 #include <asm/cmpxchg.h>
851
852+#ifdef CONFIG_GENERIC_ATOMIC64
853+#include <asm-generic/atomic64.h>
854+#endif
855+
856 #define ATOMIC_INIT(i) { (i) }
857
858 #ifdef __KERNEL__
859
860+#define _ASM_EXTABLE(from, to) \
861+" .pushsection __ex_table,\"a\"\n"\
862+" .align 3\n" \
863+" .long " #from ", " #to"\n" \
864+" .popsection"
865+
866 /*
867 * On ARM, ordinary assignment (str instruction) doesn't clear the local
868 * strex/ldrex monitor on some implementations. The reason we can use it for
869 * atomic_set() is the clrex or dummy strex done on every exception return.
870 */
871 #define atomic_read(v) (*(volatile int *)&(v)->counter)
872+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
873+{
874+ return v->counter;
875+}
876 #define atomic_set(v,i) (((v)->counter) = (i))
877+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
878+{
879+ v->counter = i;
880+}
881
882 #if __LINUX_ARM_ARCH__ >= 6
883
884@@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
885 int result;
886
887 __asm__ __volatile__("@ atomic_add\n"
888+"1: ldrex %1, [%3]\n"
889+" adds %0, %1, %4\n"
890+
891+#ifdef CONFIG_PAX_REFCOUNT
892+" bvc 3f\n"
893+"2: bkpt 0xf103\n"
894+"3:\n"
895+#endif
896+
897+" strex %1, %0, [%3]\n"
898+" teq %1, #0\n"
899+" bne 1b"
900+
901+#ifdef CONFIG_PAX_REFCOUNT
902+"\n4:\n"
903+ _ASM_EXTABLE(2b, 4b)
904+#endif
905+
906+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
907+ : "r" (&v->counter), "Ir" (i)
908+ : "cc");
909+}
910+
911+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
912+{
913+ unsigned long tmp;
914+ int result;
915+
916+ __asm__ __volatile__("@ atomic_add_unchecked\n"
917 "1: ldrex %0, [%3]\n"
918 " add %0, %0, %4\n"
919 " strex %1, %0, [%3]\n"
920@@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
921 smp_mb();
922
923 __asm__ __volatile__("@ atomic_add_return\n"
924+"1: ldrex %1, [%3]\n"
925+" adds %0, %1, %4\n"
926+
927+#ifdef CONFIG_PAX_REFCOUNT
928+" bvc 3f\n"
929+" mov %0, %1\n"
930+"2: bkpt 0xf103\n"
931+"3:\n"
932+#endif
933+
934+" strex %1, %0, [%3]\n"
935+" teq %1, #0\n"
936+" bne 1b"
937+
938+#ifdef CONFIG_PAX_REFCOUNT
939+"\n4:\n"
940+ _ASM_EXTABLE(2b, 4b)
941+#endif
942+
943+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
944+ : "r" (&v->counter), "Ir" (i)
945+ : "cc");
946+
947+ smp_mb();
948+
949+ return result;
950+}
951+
952+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
953+{
954+ unsigned long tmp;
955+ int result;
956+
957+ smp_mb();
958+
959+ __asm__ __volatile__("@ atomic_add_return_unchecked\n"
960 "1: ldrex %0, [%3]\n"
961 " add %0, %0, %4\n"
962 " strex %1, %0, [%3]\n"
963@@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
964 int result;
965
966 __asm__ __volatile__("@ atomic_sub\n"
967+"1: ldrex %1, [%3]\n"
968+" subs %0, %1, %4\n"
969+
970+#ifdef CONFIG_PAX_REFCOUNT
971+" bvc 3f\n"
972+"2: bkpt 0xf103\n"
973+"3:\n"
974+#endif
975+
976+" strex %1, %0, [%3]\n"
977+" teq %1, #0\n"
978+" bne 1b"
979+
980+#ifdef CONFIG_PAX_REFCOUNT
981+"\n4:\n"
982+ _ASM_EXTABLE(2b, 4b)
983+#endif
984+
985+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
986+ : "r" (&v->counter), "Ir" (i)
987+ : "cc");
988+}
989+
990+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
991+{
992+ unsigned long tmp;
993+ int result;
994+
995+ __asm__ __volatile__("@ atomic_sub_unchecked\n"
996 "1: ldrex %0, [%3]\n"
997 " sub %0, %0, %4\n"
998 " strex %1, %0, [%3]\n"
999@@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1000 smp_mb();
1001
1002 __asm__ __volatile__("@ atomic_sub_return\n"
1003-"1: ldrex %0, [%3]\n"
1004-" sub %0, %0, %4\n"
1005+"1: ldrex %1, [%3]\n"
1006+" subs %0, %1, %4\n"
1007+
1008+#ifdef CONFIG_PAX_REFCOUNT
1009+" bvc 3f\n"
1010+" mov %0, %1\n"
1011+"2: bkpt 0xf103\n"
1012+"3:\n"
1013+#endif
1014+
1015 " strex %1, %0, [%3]\n"
1016 " teq %1, #0\n"
1017 " bne 1b"
1018+
1019+#ifdef CONFIG_PAX_REFCOUNT
1020+"\n4:\n"
1021+ _ASM_EXTABLE(2b, 4b)
1022+#endif
1023+
1024 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1025 : "r" (&v->counter), "Ir" (i)
1026 : "cc");
1027@@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
1028 return oldval;
1029 }
1030
1031+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1032+{
1033+ unsigned long oldval, res;
1034+
1035+ smp_mb();
1036+
1037+ do {
1038+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1039+ "ldrex %1, [%3]\n"
1040+ "mov %0, #0\n"
1041+ "teq %1, %4\n"
1042+ "strexeq %0, %5, [%3]\n"
1043+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1044+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
1045+ : "cc");
1046+ } while (res);
1047+
1048+ smp_mb();
1049+
1050+ return oldval;
1051+}
1052+
1053 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1054 {
1055 unsigned long tmp, tmp2;
1056@@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1057
1058 return val;
1059 }
1060+
1061+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1062+{
1063+ return atomic_add_return(i, v);
1064+}
1065+
1066 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1067+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1068+{
1069+ (void) atomic_add_return(i, v);
1070+}
1071
1072 static inline int atomic_sub_return(int i, atomic_t *v)
1073 {
1074@@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1075 return val;
1076 }
1077 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1078+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1079+{
1080+ (void) atomic_sub_return(i, v);
1081+}
1082
1083 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1084 {
1085@@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1086 return ret;
1087 }
1088
1089+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1090+{
1091+ return atomic_cmpxchg(v, old, new);
1092+}
1093+
1094 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1095 {
1096 unsigned long flags;
1097@@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1098 #endif /* __LINUX_ARM_ARCH__ */
1099
1100 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1101+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1102+{
1103+ return xchg(&v->counter, new);
1104+}
1105
1106 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1107 {
1108@@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1109 }
1110
1111 #define atomic_inc(v) atomic_add(1, v)
1112+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1113+{
1114+ atomic_add_unchecked(1, v);
1115+}
1116 #define atomic_dec(v) atomic_sub(1, v)
1117+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1118+{
1119+ atomic_sub_unchecked(1, v);
1120+}
1121
1122 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1123+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1124+{
1125+ return atomic_add_return_unchecked(1, v) == 0;
1126+}
1127 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1128 #define atomic_inc_return(v) (atomic_add_return(1, v))
1129+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1130+{
1131+ return atomic_add_return_unchecked(1, v);
1132+}
1133 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1134 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1135
1136@@ -241,6 +428,14 @@ typedef struct {
1137 u64 __aligned(8) counter;
1138 } atomic64_t;
1139
1140+#ifdef CONFIG_PAX_REFCOUNT
1141+typedef struct {
1142+ u64 __aligned(8) counter;
1143+} atomic64_unchecked_t;
1144+#else
1145+typedef atomic64_t atomic64_unchecked_t;
1146+#endif
1147+
1148 #define ATOMIC64_INIT(i) { (i) }
1149
1150 #ifdef CONFIG_ARM_LPAE
1151@@ -257,6 +452,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1152 return result;
1153 }
1154
1155+static inline u64 atomic64_read_unchecked(const atomic64_unchecked_t *v)
1156+{
1157+ u64 result;
1158+
1159+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1160+" ldrd %0, %H0, [%1]"
1161+ : "=&r" (result)
1162+ : "r" (&v->counter), "Qo" (v->counter)
1163+ );
1164+
1165+ return result;
1166+}
1167+
1168 static inline void atomic64_set(atomic64_t *v, u64 i)
1169 {
1170 __asm__ __volatile__("@ atomic64_set\n"
1171@@ -265,6 +473,15 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1172 : "r" (&v->counter), "r" (i)
1173 );
1174 }
1175+
1176+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1177+{
1178+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1179+" strd %2, %H2, [%1]"
1180+ : "=Qo" (v->counter)
1181+ : "r" (&v->counter), "r" (i)
1182+ );
1183+}
1184 #else
1185 static inline u64 atomic64_read(const atomic64_t *v)
1186 {
1187@@ -279,6 +496,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1188 return result;
1189 }
1190
1191+static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1192+{
1193+ u64 result;
1194+
1195+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1196+" ldrexd %0, %H0, [%1]"
1197+ : "=&r" (result)
1198+ : "r" (&v->counter), "Qo" (v->counter)
1199+ );
1200+
1201+ return result;
1202+}
1203+
1204 static inline void atomic64_set(atomic64_t *v, u64 i)
1205 {
1206 u64 tmp;
1207@@ -292,6 +522,21 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1208 : "r" (&v->counter), "r" (i)
1209 : "cc");
1210 }
1211+
1212+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1213+{
1214+ u64 tmp;
1215+
1216+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1217+"1: ldrexd %0, %H0, [%2]\n"
1218+" strexd %0, %3, %H3, [%2]\n"
1219+" teq %0, #0\n"
1220+" bne 1b"
1221+ : "=&r" (tmp), "=Qo" (v->counter)
1222+ : "r" (&v->counter), "r" (i)
1223+ : "cc");
1224+}
1225+
1226 #endif
1227
1228 static inline void atomic64_add(u64 i, atomic64_t *v)
1229@@ -302,6 +547,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1230 __asm__ __volatile__("@ atomic64_add\n"
1231 "1: ldrexd %0, %H0, [%3]\n"
1232 " adds %0, %0, %4\n"
1233+" adcs %H0, %H0, %H4\n"
1234+
1235+#ifdef CONFIG_PAX_REFCOUNT
1236+" bvc 3f\n"
1237+"2: bkpt 0xf103\n"
1238+"3:\n"
1239+#endif
1240+
1241+" strexd %1, %0, %H0, [%3]\n"
1242+" teq %1, #0\n"
1243+" bne 1b"
1244+
1245+#ifdef CONFIG_PAX_REFCOUNT
1246+"\n4:\n"
1247+ _ASM_EXTABLE(2b, 4b)
1248+#endif
1249+
1250+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1251+ : "r" (&v->counter), "r" (i)
1252+ : "cc");
1253+}
1254+
1255+static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1256+{
1257+ u64 result;
1258+ unsigned long tmp;
1259+
1260+ __asm__ __volatile__("@ atomic64_add_unchecked\n"
1261+"1: ldrexd %0, %H0, [%3]\n"
1262+" adds %0, %0, %4\n"
1263 " adc %H0, %H0, %H4\n"
1264 " strexd %1, %0, %H0, [%3]\n"
1265 " teq %1, #0\n"
1266@@ -313,12 +588,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1267
1268 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1269 {
1270- u64 result;
1271- unsigned long tmp;
1272+ u64 result, tmp;
1273
1274 smp_mb();
1275
1276 __asm__ __volatile__("@ atomic64_add_return\n"
1277+"1: ldrexd %1, %H1, [%3]\n"
1278+" adds %0, %1, %4\n"
1279+" adcs %H0, %H1, %H4\n"
1280+
1281+#ifdef CONFIG_PAX_REFCOUNT
1282+" bvc 3f\n"
1283+" mov %0, %1\n"
1284+" mov %H0, %H1\n"
1285+"2: bkpt 0xf103\n"
1286+"3:\n"
1287+#endif
1288+
1289+" strexd %1, %0, %H0, [%3]\n"
1290+" teq %1, #0\n"
1291+" bne 1b"
1292+
1293+#ifdef CONFIG_PAX_REFCOUNT
1294+"\n4:\n"
1295+ _ASM_EXTABLE(2b, 4b)
1296+#endif
1297+
1298+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1299+ : "r" (&v->counter), "r" (i)
1300+ : "cc");
1301+
1302+ smp_mb();
1303+
1304+ return result;
1305+}
1306+
1307+static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1308+{
1309+ u64 result;
1310+ unsigned long tmp;
1311+
1312+ smp_mb();
1313+
1314+ __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1315 "1: ldrexd %0, %H0, [%3]\n"
1316 " adds %0, %0, %4\n"
1317 " adc %H0, %H0, %H4\n"
1318@@ -342,6 +654,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1319 __asm__ __volatile__("@ atomic64_sub\n"
1320 "1: ldrexd %0, %H0, [%3]\n"
1321 " subs %0, %0, %4\n"
1322+" sbcs %H0, %H0, %H4\n"
1323+
1324+#ifdef CONFIG_PAX_REFCOUNT
1325+" bvc 3f\n"
1326+"2: bkpt 0xf103\n"
1327+"3:\n"
1328+#endif
1329+
1330+" strexd %1, %0, %H0, [%3]\n"
1331+" teq %1, #0\n"
1332+" bne 1b"
1333+
1334+#ifdef CONFIG_PAX_REFCOUNT
1335+"\n4:\n"
1336+ _ASM_EXTABLE(2b, 4b)
1337+#endif
1338+
1339+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1340+ : "r" (&v->counter), "r" (i)
1341+ : "cc");
1342+}
1343+
1344+static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1345+{
1346+ u64 result;
1347+ unsigned long tmp;
1348+
1349+ __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1350+"1: ldrexd %0, %H0, [%3]\n"
1351+" subs %0, %0, %4\n"
1352 " sbc %H0, %H0, %H4\n"
1353 " strexd %1, %0, %H0, [%3]\n"
1354 " teq %1, #0\n"
1355@@ -353,18 +695,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1356
1357 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1358 {
1359- u64 result;
1360- unsigned long tmp;
1361+ u64 result, tmp;
1362
1363 smp_mb();
1364
1365 __asm__ __volatile__("@ atomic64_sub_return\n"
1366-"1: ldrexd %0, %H0, [%3]\n"
1367-" subs %0, %0, %4\n"
1368-" sbc %H0, %H0, %H4\n"
1369+"1: ldrexd %1, %H1, [%3]\n"
1370+" subs %0, %1, %4\n"
1371+" sbcs %H0, %H1, %H4\n"
1372+
1373+#ifdef CONFIG_PAX_REFCOUNT
1374+" bvc 3f\n"
1375+" mov %0, %1\n"
1376+" mov %H0, %H1\n"
1377+"2: bkpt 0xf103\n"
1378+"3:\n"
1379+#endif
1380+
1381 " strexd %1, %0, %H0, [%3]\n"
1382 " teq %1, #0\n"
1383 " bne 1b"
1384+
1385+#ifdef CONFIG_PAX_REFCOUNT
1386+"\n4:\n"
1387+ _ASM_EXTABLE(2b, 4b)
1388+#endif
1389+
1390 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1391 : "r" (&v->counter), "r" (i)
1392 : "cc");
1393@@ -398,6 +754,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1394 return oldval;
1395 }
1396
1397+static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1398+{
1399+ u64 oldval;
1400+ unsigned long res;
1401+
1402+ smp_mb();
1403+
1404+ do {
1405+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1406+ "ldrexd %1, %H1, [%3]\n"
1407+ "mov %0, #0\n"
1408+ "teq %1, %4\n"
1409+ "teqeq %H1, %H4\n"
1410+ "strexdeq %0, %5, %H5, [%3]"
1411+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1412+ : "r" (&ptr->counter), "r" (old), "r" (new)
1413+ : "cc");
1414+ } while (res);
1415+
1416+ smp_mb();
1417+
1418+ return oldval;
1419+}
1420+
1421 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1422 {
1423 u64 result;
1424@@ -421,21 +801,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1425
1426 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1427 {
1428- u64 result;
1429- unsigned long tmp;
1430+ u64 result, tmp;
1431
1432 smp_mb();
1433
1434 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1435-"1: ldrexd %0, %H0, [%3]\n"
1436-" subs %0, %0, #1\n"
1437-" sbc %H0, %H0, #0\n"
1438+"1: ldrexd %1, %H1, [%3]\n"
1439+" subs %0, %1, #1\n"
1440+" sbcs %H0, %H1, #0\n"
1441+
1442+#ifdef CONFIG_PAX_REFCOUNT
1443+" bvc 3f\n"
1444+" mov %0, %1\n"
1445+" mov %H0, %H1\n"
1446+"2: bkpt 0xf103\n"
1447+"3:\n"
1448+#endif
1449+
1450 " teq %H0, #0\n"
1451-" bmi 2f\n"
1452+" bmi 4f\n"
1453 " strexd %1, %0, %H0, [%3]\n"
1454 " teq %1, #0\n"
1455 " bne 1b\n"
1456-"2:"
1457+"4:\n"
1458+
1459+#ifdef CONFIG_PAX_REFCOUNT
1460+ _ASM_EXTABLE(2b, 4b)
1461+#endif
1462+
1463 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1464 : "r" (&v->counter)
1465 : "cc");
1466@@ -458,13 +851,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1467 " teq %0, %5\n"
1468 " teqeq %H0, %H5\n"
1469 " moveq %1, #0\n"
1470-" beq 2f\n"
1471+" beq 4f\n"
1472 " adds %0, %0, %6\n"
1473-" adc %H0, %H0, %H6\n"
1474+" adcs %H0, %H0, %H6\n"
1475+
1476+#ifdef CONFIG_PAX_REFCOUNT
1477+" bvc 3f\n"
1478+"2: bkpt 0xf103\n"
1479+"3:\n"
1480+#endif
1481+
1482 " strexd %2, %0, %H0, [%4]\n"
1483 " teq %2, #0\n"
1484 " bne 1b\n"
1485-"2:"
1486+"4:\n"
1487+
1488+#ifdef CONFIG_PAX_REFCOUNT
1489+ _ASM_EXTABLE(2b, 4b)
1490+#endif
1491+
1492 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1493 : "r" (&v->counter), "r" (u), "r" (a)
1494 : "cc");
1495@@ -477,10 +882,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1496
1497 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1498 #define atomic64_inc(v) atomic64_add(1LL, (v))
1499+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1500 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1501+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1502 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1503 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1504 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1505+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1506 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1507 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1508 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1509diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1510index 75fe66b..ba3dee4 100644
1511--- a/arch/arm/include/asm/cache.h
1512+++ b/arch/arm/include/asm/cache.h
1513@@ -4,8 +4,10 @@
1514 #ifndef __ASMARM_CACHE_H
1515 #define __ASMARM_CACHE_H
1516
1517+#include <linux/const.h>
1518+
1519 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1520-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1521+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1522
1523 /*
1524 * Memory returned by kmalloc() may be used for DMA, so we must make
1525@@ -24,5 +26,6 @@
1526 #endif
1527
1528 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1529+#define __read_only __attribute__ ((__section__(".data..read_only")))
1530
1531 #endif
1532diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1533index 17d0ae8..014e350 100644
1534--- a/arch/arm/include/asm/cacheflush.h
1535+++ b/arch/arm/include/asm/cacheflush.h
1536@@ -116,7 +116,7 @@ struct cpu_cache_fns {
1537 void (*dma_unmap_area)(const void *, size_t, int);
1538
1539 void (*dma_flush_range)(const void *, const void *);
1540-};
1541+} __no_const;
1542
1543 /*
1544 * Select the calling method
1545diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1546index 6dcc164..b14d917 100644
1547--- a/arch/arm/include/asm/checksum.h
1548+++ b/arch/arm/include/asm/checksum.h
1549@@ -37,7 +37,19 @@ __wsum
1550 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1551
1552 __wsum
1553-csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1554+__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1555+
1556+static inline __wsum
1557+csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1558+{
1559+ __wsum ret;
1560+ pax_open_userland();
1561+ ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1562+ pax_close_userland();
1563+ return ret;
1564+}
1565+
1566+
1567
1568 /*
1569 * Fold a partial checksum without adding pseudo headers
1570diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1571index 4f009c1..466c59b 100644
1572--- a/arch/arm/include/asm/cmpxchg.h
1573+++ b/arch/arm/include/asm/cmpxchg.h
1574@@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1575
1576 #define xchg(ptr,x) \
1577 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1578+#define xchg_unchecked(ptr,x) \
1579+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1580
1581 #include <asm-generic/cmpxchg-local.h>
1582
1583diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1584index 6ddbe44..b5e38b1 100644
1585--- a/arch/arm/include/asm/domain.h
1586+++ b/arch/arm/include/asm/domain.h
1587@@ -48,18 +48,37 @@
1588 * Domain types
1589 */
1590 #define DOMAIN_NOACCESS 0
1591-#define DOMAIN_CLIENT 1
1592 #ifdef CONFIG_CPU_USE_DOMAINS
1593+#define DOMAIN_USERCLIENT 1
1594+#define DOMAIN_KERNELCLIENT 1
1595 #define DOMAIN_MANAGER 3
1596+#define DOMAIN_VECTORS DOMAIN_USER
1597 #else
1598+
1599+#ifdef CONFIG_PAX_KERNEXEC
1600 #define DOMAIN_MANAGER 1
1601+#define DOMAIN_KERNEXEC 3
1602+#else
1603+#define DOMAIN_MANAGER 1
1604+#endif
1605+
1606+#ifdef CONFIG_PAX_MEMORY_UDEREF
1607+#define DOMAIN_USERCLIENT 0
1608+#define DOMAIN_UDEREF 1
1609+#define DOMAIN_VECTORS DOMAIN_KERNEL
1610+#else
1611+#define DOMAIN_USERCLIENT 1
1612+#define DOMAIN_VECTORS DOMAIN_USER
1613+#endif
1614+#define DOMAIN_KERNELCLIENT 1
1615+
1616 #endif
1617
1618 #define domain_val(dom,type) ((type) << (2*(dom)))
1619
1620 #ifndef __ASSEMBLY__
1621
1622-#ifdef CONFIG_CPU_USE_DOMAINS
1623+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1624 static inline void set_domain(unsigned val)
1625 {
1626 asm volatile(
1627@@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1628 isb();
1629 }
1630
1631-#define modify_domain(dom,type) \
1632- do { \
1633- struct thread_info *thread = current_thread_info(); \
1634- unsigned int domain = thread->cpu_domain; \
1635- domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1636- thread->cpu_domain = domain | domain_val(dom, type); \
1637- set_domain(thread->cpu_domain); \
1638- } while (0)
1639-
1640+extern void modify_domain(unsigned int dom, unsigned int type);
1641 #else
1642 static inline void set_domain(unsigned val) { }
1643 static inline void modify_domain(unsigned dom, unsigned type) { }
1644diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1645index 56211f2..17e8a25 100644
1646--- a/arch/arm/include/asm/elf.h
1647+++ b/arch/arm/include/asm/elf.h
1648@@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1649 the loader. We need to make sure that it is out of the way of the program
1650 that it will "exec", and that there is sufficient room for the brk. */
1651
1652-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1653+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1654+
1655+#ifdef CONFIG_PAX_ASLR
1656+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1657+
1658+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1659+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1660+#endif
1661
1662 /* When the program starts, a1 contains a pointer to a function to be
1663 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1664@@ -126,10 +133,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1665 extern void elf_set_personality(const struct elf32_hdr *);
1666 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1667
1668-struct mm_struct;
1669-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1670-#define arch_randomize_brk arch_randomize_brk
1671-
1672 #ifdef CONFIG_MMU
1673 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1674 struct linux_binprm;
1675diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1676index de53547..52b9a28 100644
1677--- a/arch/arm/include/asm/fncpy.h
1678+++ b/arch/arm/include/asm/fncpy.h
1679@@ -81,7 +81,9 @@
1680 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1681 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1682 \
1683+ pax_open_kernel(); \
1684 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1685+ pax_close_kernel(); \
1686 flush_icache_range((unsigned long)(dest_buf), \
1687 (unsigned long)(dest_buf) + (size)); \
1688 \
1689diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1690index e42cf59..7b94b8f 100644
1691--- a/arch/arm/include/asm/futex.h
1692+++ b/arch/arm/include/asm/futex.h
1693@@ -50,6 +50,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1694 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1695 return -EFAULT;
1696
1697+ pax_open_userland();
1698+
1699 smp_mb();
1700 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1701 "1: ldrex %1, [%4]\n"
1702@@ -65,6 +67,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1703 : "cc", "memory");
1704 smp_mb();
1705
1706+ pax_close_userland();
1707+
1708 *uval = val;
1709 return ret;
1710 }
1711@@ -95,6 +99,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1712 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1713 return -EFAULT;
1714
1715+ pax_open_userland();
1716+
1717 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1718 "1: " TUSER(ldr) " %1, [%4]\n"
1719 " teq %1, %2\n"
1720@@ -105,6 +111,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1721 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1722 : "cc", "memory");
1723
1724+ pax_close_userland();
1725+
1726 *uval = val;
1727 return ret;
1728 }
1729@@ -127,6 +135,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1730 return -EFAULT;
1731
1732 pagefault_disable(); /* implies preempt_disable() */
1733+ pax_open_userland();
1734
1735 switch (op) {
1736 case FUTEX_OP_SET:
1737@@ -148,6 +157,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1738 ret = -ENOSYS;
1739 }
1740
1741+ pax_close_userland();
1742 pagefault_enable(); /* subsumes preempt_enable() */
1743
1744 if (!ret) {
1745diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1746index 83eb2f7..ed77159 100644
1747--- a/arch/arm/include/asm/kmap_types.h
1748+++ b/arch/arm/include/asm/kmap_types.h
1749@@ -4,6 +4,6 @@
1750 /*
1751 * This is the "bare minimum". AIO seems to require this.
1752 */
1753-#define KM_TYPE_NR 16
1754+#define KM_TYPE_NR 17
1755
1756 #endif
1757diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1758index 9e614a1..3302cca 100644
1759--- a/arch/arm/include/asm/mach/dma.h
1760+++ b/arch/arm/include/asm/mach/dma.h
1761@@ -22,7 +22,7 @@ struct dma_ops {
1762 int (*residue)(unsigned int, dma_t *); /* optional */
1763 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1764 const char *type;
1765-};
1766+} __do_const;
1767
1768 struct dma_struct {
1769 void *addr; /* single DMA address */
1770diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1771index 2fe141f..192dc01 100644
1772--- a/arch/arm/include/asm/mach/map.h
1773+++ b/arch/arm/include/asm/mach/map.h
1774@@ -27,13 +27,16 @@ struct map_desc {
1775 #define MT_MINICLEAN 6
1776 #define MT_LOW_VECTORS 7
1777 #define MT_HIGH_VECTORS 8
1778-#define MT_MEMORY 9
1779+#define MT_MEMORY_RWX 9
1780 #define MT_ROM 10
1781-#define MT_MEMORY_NONCACHED 11
1782+#define MT_MEMORY_NONCACHED_RX 11
1783 #define MT_MEMORY_DTCM 12
1784 #define MT_MEMORY_ITCM 13
1785 #define MT_MEMORY_SO 14
1786 #define MT_MEMORY_DMA_READY 15
1787+#define MT_MEMORY_RW 16
1788+#define MT_MEMORY_RX 17
1789+#define MT_MEMORY_NONCACHED_RW 18
1790
1791 #ifdef CONFIG_MMU
1792 extern void iotable_init(struct map_desc *, int);
1793diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1794index 12f71a1..04e063c 100644
1795--- a/arch/arm/include/asm/outercache.h
1796+++ b/arch/arm/include/asm/outercache.h
1797@@ -35,7 +35,7 @@ struct outer_cache_fns {
1798 #endif
1799 void (*set_debug)(unsigned long);
1800 void (*resume)(void);
1801-};
1802+} __no_const;
1803
1804 #ifdef CONFIG_OUTER_CACHE
1805
1806diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1807index 4355f0e..c229913 100644
1808--- a/arch/arm/include/asm/page.h
1809+++ b/arch/arm/include/asm/page.h
1810@@ -114,7 +114,7 @@ struct cpu_user_fns {
1811 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1812 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1813 unsigned long vaddr, struct vm_area_struct *vma);
1814-};
1815+} __no_const;
1816
1817 #ifdef MULTI_USER
1818 extern struct cpu_user_fns cpu_user;
1819diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1820index 943504f..c37a730 100644
1821--- a/arch/arm/include/asm/pgalloc.h
1822+++ b/arch/arm/include/asm/pgalloc.h
1823@@ -17,6 +17,7 @@
1824 #include <asm/processor.h>
1825 #include <asm/cacheflush.h>
1826 #include <asm/tlbflush.h>
1827+#include <asm/system_info.h>
1828
1829 #define check_pgt_cache() do { } while (0)
1830
1831@@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1832 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1833 }
1834
1835+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1836+{
1837+ pud_populate(mm, pud, pmd);
1838+}
1839+
1840 #else /* !CONFIG_ARM_LPAE */
1841
1842 /*
1843@@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1844 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1845 #define pmd_free(mm, pmd) do { } while (0)
1846 #define pud_populate(mm,pmd,pte) BUG()
1847+#define pud_populate_kernel(mm,pmd,pte) BUG()
1848
1849 #endif /* CONFIG_ARM_LPAE */
1850
1851@@ -126,6 +133,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1852 __free_page(pte);
1853 }
1854
1855+static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1856+{
1857+#ifdef CONFIG_ARM_LPAE
1858+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1859+#else
1860+ if (addr & SECTION_SIZE)
1861+ pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1862+ else
1863+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1864+#endif
1865+ flush_pmd_entry(pmdp);
1866+}
1867+
1868 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1869 pmdval_t prot)
1870 {
1871@@ -155,7 +175,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1872 static inline void
1873 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1874 {
1875- __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1876+ __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1877 }
1878 #define pmd_pgtable(pmd) pmd_page(pmd)
1879
1880diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1881index 5cfba15..f415e1a 100644
1882--- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1883+++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1884@@ -20,12 +20,15 @@
1885 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1886 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1887 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1888+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1889 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1890 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1891 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1892+
1893 /*
1894 * - section
1895 */
1896+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1897 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1898 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1899 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1900@@ -37,6 +40,7 @@
1901 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1902 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1903 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1904+#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1905
1906 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1907 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1908@@ -66,6 +70,7 @@
1909 * - extended small page/tiny page
1910 */
1911 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1912+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1913 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1914 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1915 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1916diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1917index f97ee02..cc9fe9e 100644
1918--- a/arch/arm/include/asm/pgtable-2level.h
1919+++ b/arch/arm/include/asm/pgtable-2level.h
1920@@ -126,6 +126,9 @@
1921 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1922 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1923
1924+/* Two-level page tables only have PXN in the PGD, not in the PTE. */
1925+#define L_PTE_PXN (_AT(pteval_t, 0))
1926+
1927 /*
1928 * These are the memory types, defined to be compatible with
1929 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
1930diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1931index 626989f..9d67a33 100644
1932--- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1933+++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1934@@ -75,6 +75,7 @@
1935 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1936 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1937 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1938+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1939 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1940
1941 /*
1942diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1943index 5689c18..eea12f9 100644
1944--- a/arch/arm/include/asm/pgtable-3level.h
1945+++ b/arch/arm/include/asm/pgtable-3level.h
1946@@ -82,6 +82,7 @@
1947 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1948 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1949 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1950+#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1951 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1952 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1953 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1954@@ -95,6 +96,7 @@
1955 /*
1956 * To be used in assembly code with the upper page attributes.
1957 */
1958+#define L_PTE_PXN_HIGH (1 << (53 - 32))
1959 #define L_PTE_XN_HIGH (1 << (54 - 32))
1960 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1961
1962diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1963index 04aeb02..73b70dd 100644
1964--- a/arch/arm/include/asm/pgtable.h
1965+++ b/arch/arm/include/asm/pgtable.h
1966@@ -33,6 +33,9 @@
1967 #include <asm/pgtable-2level.h>
1968 #endif
1969
1970+#define ktla_ktva(addr) (addr)
1971+#define ktva_ktla(addr) (addr)
1972+
1973 /*
1974 * Just any arbitrary offset to the start of the vmalloc VM area: the
1975 * current 8MB value just means that there will be a 8MB "hole" after the
1976@@ -48,6 +51,9 @@
1977 #define LIBRARY_TEXT_START 0x0c000000
1978
1979 #ifndef __ASSEMBLY__
1980+extern pteval_t __supported_pte_mask;
1981+extern pmdval_t __supported_pmd_mask;
1982+
1983 extern void __pte_error(const char *file, int line, pte_t);
1984 extern void __pmd_error(const char *file, int line, pmd_t);
1985 extern void __pgd_error(const char *file, int line, pgd_t);
1986@@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
1987 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
1988 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
1989
1990+#define __HAVE_ARCH_PAX_OPEN_KERNEL
1991+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
1992+
1993+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1994+#include <asm/domain.h>
1995+#include <linux/thread_info.h>
1996+#include <linux/preempt.h>
1997+
1998+static inline int test_domain(int domain, int domaintype)
1999+{
2000+ return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2001+}
2002+#endif
2003+
2004+#ifdef CONFIG_PAX_KERNEXEC
2005+static inline unsigned long pax_open_kernel(void) {
2006+#ifdef CONFIG_ARM_LPAE
2007+ /* TODO */
2008+#else
2009+ preempt_disable();
2010+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2011+ modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2012+#endif
2013+ return 0;
2014+}
2015+
2016+static inline unsigned long pax_close_kernel(void) {
2017+#ifdef CONFIG_ARM_LPAE
2018+ /* TODO */
2019+#else
2020+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2021+ /* DOMAIN_MANAGER = "client" under KERNEXEC */
2022+ modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2023+ preempt_enable_no_resched();
2024+#endif
2025+ return 0;
2026+}
2027+#else
2028+static inline unsigned long pax_open_kernel(void) { return 0; }
2029+static inline unsigned long pax_close_kernel(void) { return 0; }
2030+#endif
2031+
2032 /*
2033 * This is the lowest virtual address we can permit any user space
2034 * mapping to be mapped at. This is particularly important for
2035@@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2036 /*
2037 * The pgprot_* and protection_map entries will be fixed up in runtime
2038 * to include the cachable and bufferable bits based on memory policy,
2039- * as well as any architecture dependent bits like global/ASID and SMP
2040- * shared mapping bits.
2041+ * as well as any architecture dependent bits like global/ASID, PXN,
2042+ * and SMP shared mapping bits.
2043 */
2044 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2045
2046@@ -260,7 +308,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2047 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2048 {
2049 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2050- L_PTE_NONE | L_PTE_VALID;
2051+ L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2052 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2053 return pte;
2054 }
2055diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
2056index 5324c11..bcae5f0 100644
2057--- a/arch/arm/include/asm/proc-fns.h
2058+++ b/arch/arm/include/asm/proc-fns.h
2059@@ -75,7 +75,7 @@ extern struct processor {
2060 unsigned int suspend_size;
2061 void (*do_suspend)(void *);
2062 void (*do_resume)(void *);
2063-} processor;
2064+} __do_const processor;
2065
2066 #ifndef MULTI_CPU
2067 extern void cpu_proc_init(void);
2068diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2069index c4ae171..ea0c0c2 100644
2070--- a/arch/arm/include/asm/psci.h
2071+++ b/arch/arm/include/asm/psci.h
2072@@ -29,7 +29,7 @@ struct psci_operations {
2073 int (*cpu_off)(struct psci_power_state state);
2074 int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
2075 int (*migrate)(unsigned long cpuid);
2076-};
2077+} __no_const;
2078
2079 extern struct psci_operations psci_ops;
2080 extern struct smp_operations psci_smp_ops;
2081diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2082index a8cae71c..65dd797 100644
2083--- a/arch/arm/include/asm/smp.h
2084+++ b/arch/arm/include/asm/smp.h
2085@@ -110,7 +110,7 @@ struct smp_operations {
2086 int (*cpu_disable)(unsigned int cpu);
2087 #endif
2088 #endif
2089-};
2090+} __no_const;
2091
2092 /*
2093 * set platform specific SMP operations
2094diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2095index 2b8114f..8fe9bcf 100644
2096--- a/arch/arm/include/asm/thread_info.h
2097+++ b/arch/arm/include/asm/thread_info.h
2098@@ -77,9 +77,9 @@ struct thread_info {
2099 .flags = 0, \
2100 .preempt_count = INIT_PREEMPT_COUNT, \
2101 .addr_limit = KERNEL_DS, \
2102- .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2103- domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2104- domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2105+ .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2106+ domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2107+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2108 .restart_block = { \
2109 .fn = do_no_restart_syscall, \
2110 }, \
2111@@ -152,7 +152,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2112 #define TIF_SYSCALL_AUDIT 9
2113 #define TIF_SYSCALL_TRACEPOINT 10
2114 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2115-#define TIF_NOHZ 12 /* in adaptive nohz mode */
2116+/* within 8 bits of TIF_SYSCALL_TRACE
2117+ * to meet flexible second operand requirements
2118+ */
2119+#define TIF_GRSEC_SETXID 12
2120+#define TIF_NOHZ 13 /* in adaptive nohz mode */
2121 #define TIF_USING_IWMMXT 17
2122 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2123 #define TIF_RESTORE_SIGMASK 20
2124@@ -165,10 +169,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2125 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2126 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2127 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2128+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2129
2130 /* Checks for any syscall work in entry-common.S */
2131 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2132- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2133+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2134
2135 /*
2136 * Change these and you break ASM code in entry-common.S
2137diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2138index 7e1f760..de33b13 100644
2139--- a/arch/arm/include/asm/uaccess.h
2140+++ b/arch/arm/include/asm/uaccess.h
2141@@ -18,6 +18,7 @@
2142 #include <asm/domain.h>
2143 #include <asm/unified.h>
2144 #include <asm/compiler.h>
2145+#include <asm/pgtable.h>
2146
2147 #define VERIFY_READ 0
2148 #define VERIFY_WRITE 1
2149@@ -63,11 +64,38 @@ extern int __put_user_bad(void);
2150 static inline void set_fs(mm_segment_t fs)
2151 {
2152 current_thread_info()->addr_limit = fs;
2153- modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2154+ modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2155 }
2156
2157 #define segment_eq(a,b) ((a) == (b))
2158
2159+#define __HAVE_ARCH_PAX_OPEN_USERLAND
2160+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2161+
2162+static inline void pax_open_userland(void)
2163+{
2164+
2165+#ifdef CONFIG_PAX_MEMORY_UDEREF
2166+ if (segment_eq(get_fs(), USER_DS)) {
2167+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2168+ modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2169+ }
2170+#endif
2171+
2172+}
2173+
2174+static inline void pax_close_userland(void)
2175+{
2176+
2177+#ifdef CONFIG_PAX_MEMORY_UDEREF
2178+ if (segment_eq(get_fs(), USER_DS)) {
2179+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2180+ modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2181+ }
2182+#endif
2183+
2184+}
2185+
2186 #define __addr_ok(addr) ({ \
2187 unsigned long flag; \
2188 __asm__("cmp %2, %0; movlo %0, #0" \
2189@@ -143,8 +171,12 @@ extern int __get_user_4(void *);
2190
2191 #define get_user(x,p) \
2192 ({ \
2193+ int __e; \
2194 might_fault(); \
2195- __get_user_check(x,p); \
2196+ pax_open_userland(); \
2197+ __e = __get_user_check(x,p); \
2198+ pax_close_userland(); \
2199+ __e; \
2200 })
2201
2202 extern int __put_user_1(void *, unsigned int);
2203@@ -188,8 +220,12 @@ extern int __put_user_8(void *, unsigned long long);
2204
2205 #define put_user(x,p) \
2206 ({ \
2207+ int __e; \
2208 might_fault(); \
2209- __put_user_check(x,p); \
2210+ pax_open_userland(); \
2211+ __e = __put_user_check(x,p); \
2212+ pax_close_userland(); \
2213+ __e; \
2214 })
2215
2216 #else /* CONFIG_MMU */
2217@@ -230,13 +266,17 @@ static inline void set_fs(mm_segment_t fs)
2218 #define __get_user(x,ptr) \
2219 ({ \
2220 long __gu_err = 0; \
2221+ pax_open_userland(); \
2222 __get_user_err((x),(ptr),__gu_err); \
2223+ pax_close_userland(); \
2224 __gu_err; \
2225 })
2226
2227 #define __get_user_error(x,ptr,err) \
2228 ({ \
2229+ pax_open_userland(); \
2230 __get_user_err((x),(ptr),err); \
2231+ pax_close_userland(); \
2232 (void) 0; \
2233 })
2234
2235@@ -312,13 +352,17 @@ do { \
2236 #define __put_user(x,ptr) \
2237 ({ \
2238 long __pu_err = 0; \
2239+ pax_open_userland(); \
2240 __put_user_err((x),(ptr),__pu_err); \
2241+ pax_close_userland(); \
2242 __pu_err; \
2243 })
2244
2245 #define __put_user_error(x,ptr,err) \
2246 ({ \
2247+ pax_open_userland(); \
2248 __put_user_err((x),(ptr),err); \
2249+ pax_close_userland(); \
2250 (void) 0; \
2251 })
2252
2253@@ -418,11 +462,44 @@ do { \
2254
2255
2256 #ifdef CONFIG_MMU
2257-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2258-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2259+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2260+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2261+
2262+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2263+{
2264+ unsigned long ret;
2265+
2266+ check_object_size(to, n, false);
2267+ pax_open_userland();
2268+ ret = ___copy_from_user(to, from, n);
2269+ pax_close_userland();
2270+ return ret;
2271+}
2272+
2273+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2274+{
2275+ unsigned long ret;
2276+
2277+ check_object_size(from, n, true);
2278+ pax_open_userland();
2279+ ret = ___copy_to_user(to, from, n);
2280+ pax_close_userland();
2281+ return ret;
2282+}
2283+
2284 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2285-extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2286+extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2287 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2288+
2289+static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2290+{
2291+ unsigned long ret;
2292+ pax_open_userland();
2293+ ret = ___clear_user(addr, n);
2294+ pax_close_userland();
2295+ return ret;
2296+}
2297+
2298 #else
2299 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2300 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2301@@ -431,6 +508,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2302
2303 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2304 {
2305+ if ((long)n < 0)
2306+ return n;
2307+
2308 if (access_ok(VERIFY_READ, from, n))
2309 n = __copy_from_user(to, from, n);
2310 else /* security hole - plug it */
2311@@ -440,6 +520,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2312
2313 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2314 {
2315+ if ((long)n < 0)
2316+ return n;
2317+
2318 if (access_ok(VERIFY_WRITE, to, n))
2319 n = __copy_to_user(to, from, n);
2320 return n;
2321diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2322index 5af0ed1..cea83883 100644
2323--- a/arch/arm/include/uapi/asm/ptrace.h
2324+++ b/arch/arm/include/uapi/asm/ptrace.h
2325@@ -92,7 +92,7 @@
2326 * ARMv7 groups of PSR bits
2327 */
2328 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2329-#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2330+#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2331 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2332 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2333
2334diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2335index 60d3b73..e5a0f22 100644
2336--- a/arch/arm/kernel/armksyms.c
2337+++ b/arch/arm/kernel/armksyms.c
2338@@ -53,7 +53,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2339
2340 /* networking */
2341 EXPORT_SYMBOL(csum_partial);
2342-EXPORT_SYMBOL(csum_partial_copy_from_user);
2343+EXPORT_SYMBOL(__csum_partial_copy_from_user);
2344 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2345 EXPORT_SYMBOL(__csum_ipv6_magic);
2346
2347@@ -89,9 +89,9 @@ EXPORT_SYMBOL(__memzero);
2348 #ifdef CONFIG_MMU
2349 EXPORT_SYMBOL(copy_page);
2350
2351-EXPORT_SYMBOL(__copy_from_user);
2352-EXPORT_SYMBOL(__copy_to_user);
2353-EXPORT_SYMBOL(__clear_user);
2354+EXPORT_SYMBOL(___copy_from_user);
2355+EXPORT_SYMBOL(___copy_to_user);
2356+EXPORT_SYMBOL(___clear_user);
2357
2358 EXPORT_SYMBOL(__get_user_1);
2359 EXPORT_SYMBOL(__get_user_2);
2360diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2361index 9cbe70c..a7b5e34 100644
2362--- a/arch/arm/kernel/entry-armv.S
2363+++ b/arch/arm/kernel/entry-armv.S
2364@@ -47,6 +47,87 @@
2365 9997:
2366 .endm
2367
2368+ .macro pax_enter_kernel
2369+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2370+ @ make aligned space for saved DACR
2371+ sub sp, sp, #8
2372+ @ save regs
2373+ stmdb sp!, {r1, r2}
2374+ @ read DACR from cpu_domain into r1
2375+ mov r2, sp
2376+ @ assume 8K pages, since we have to split the immediate in two
2377+ bic r2, r2, #(0x1fc0)
2378+ bic r2, r2, #(0x3f)
2379+ ldr r1, [r2, #TI_CPU_DOMAIN]
2380+ @ store old DACR on stack
2381+ str r1, [sp, #8]
2382+#ifdef CONFIG_PAX_KERNEXEC
2383+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2384+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2385+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2386+#endif
2387+#ifdef CONFIG_PAX_MEMORY_UDEREF
2388+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2389+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2390+#endif
2391+ @ write r1 to current_thread_info()->cpu_domain
2392+ str r1, [r2, #TI_CPU_DOMAIN]
2393+ @ write r1 to DACR
2394+ mcr p15, 0, r1, c3, c0, 0
2395+ @ instruction sync
2396+ instr_sync
2397+ @ restore regs
2398+ ldmia sp!, {r1, r2}
2399+#endif
2400+ .endm
2401+
2402+ .macro pax_open_userland
2403+#ifdef CONFIG_PAX_MEMORY_UDEREF
2404+ @ save regs
2405+ stmdb sp!, {r0, r1}
2406+ @ read DACR from cpu_domain into r1
2407+ mov r0, sp
2408+ @ assume 8K pages, since we have to split the immediate in two
2409+ bic r0, r0, #(0x1fc0)
2410+ bic r0, r0, #(0x3f)
2411+ ldr r1, [r0, #TI_CPU_DOMAIN]
2412+ @ set current DOMAIN_USER to DOMAIN_CLIENT
2413+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2414+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2415+ @ write r1 to current_thread_info()->cpu_domain
2416+ str r1, [r0, #TI_CPU_DOMAIN]
2417+ @ write r1 to DACR
2418+ mcr p15, 0, r1, c3, c0, 0
2419+ @ instruction sync
2420+ instr_sync
2421+ @ restore regs
2422+ ldmia sp!, {r0, r1}
2423+#endif
2424+ .endm
2425+
2426+ .macro pax_close_userland
2427+#ifdef CONFIG_PAX_MEMORY_UDEREF
2428+ @ save regs
2429+ stmdb sp!, {r0, r1}
2430+ @ read DACR from cpu_domain into r1
2431+ mov r0, sp
2432+ @ assume 8K pages, since we have to split the immediate in two
2433+ bic r0, r0, #(0x1fc0)
2434+ bic r0, r0, #(0x3f)
2435+ ldr r1, [r0, #TI_CPU_DOMAIN]
2436+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2437+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2438+ @ write r1 to current_thread_info()->cpu_domain
2439+ str r1, [r0, #TI_CPU_DOMAIN]
2440+ @ write r1 to DACR
2441+ mcr p15, 0, r1, c3, c0, 0
2442+ @ instruction sync
2443+ instr_sync
2444+ @ restore regs
2445+ ldmia sp!, {r0, r1}
2446+#endif
2447+ .endm
2448+
2449 .macro pabt_helper
2450 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2451 #ifdef MULTI_PABORT
2452@@ -89,11 +170,15 @@
2453 * Invalid mode handlers
2454 */
2455 .macro inv_entry, reason
2456+
2457+ pax_enter_kernel
2458+
2459 sub sp, sp, #S_FRAME_SIZE
2460 ARM( stmib sp, {r1 - lr} )
2461 THUMB( stmia sp, {r0 - r12} )
2462 THUMB( str sp, [sp, #S_SP] )
2463 THUMB( str lr, [sp, #S_LR] )
2464+
2465 mov r1, #\reason
2466 .endm
2467
2468@@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2469 .macro svc_entry, stack_hole=0
2470 UNWIND(.fnstart )
2471 UNWIND(.save {r0 - pc} )
2472+
2473+ pax_enter_kernel
2474+
2475 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2476+
2477 #ifdef CONFIG_THUMB2_KERNEL
2478 SPFIX( str r0, [sp] ) @ temporarily saved
2479 SPFIX( mov r0, sp )
2480@@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2481 ldmia r0, {r3 - r5}
2482 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2483 mov r6, #-1 @ "" "" "" ""
2484+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2485+ @ offset sp by 8 as done in pax_enter_kernel
2486+ add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2487+#else
2488 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2489+#endif
2490 SPFIX( addeq r2, r2, #4 )
2491 str r3, [sp, #-4]! @ save the "real" r0 copied
2492 @ from the exception stack
2493@@ -316,6 +410,9 @@ ENDPROC(__pabt_svc)
2494 .macro usr_entry
2495 UNWIND(.fnstart )
2496 UNWIND(.cantunwind ) @ don't unwind the user space
2497+
2498+ pax_enter_kernel_user
2499+
2500 sub sp, sp, #S_FRAME_SIZE
2501 ARM( stmib sp, {r1 - r12} )
2502 THUMB( stmia sp, {r0 - r12} )
2503@@ -415,7 +512,9 @@ __und_usr:
2504 tst r3, #PSR_T_BIT @ Thumb mode?
2505 bne __und_usr_thumb
2506 sub r4, r2, #4 @ ARM instr at LR - 4
2507+ pax_open_userland
2508 1: ldrt r0, [r4]
2509+ pax_close_userland
2510 #ifdef CONFIG_CPU_ENDIAN_BE8
2511 rev r0, r0 @ little endian instruction
2512 #endif
2513@@ -450,10 +549,14 @@ __und_usr_thumb:
2514 */
2515 .arch armv6t2
2516 #endif
2517+ pax_open_userland
2518 2: ldrht r5, [r4]
2519+ pax_close_userland
2520 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2521 blo __und_usr_fault_16 @ 16bit undefined instruction
2522+ pax_open_userland
2523 3: ldrht r0, [r2]
2524+ pax_close_userland
2525 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2526 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2527 orr r0, r0, r5, lsl #16
2528@@ -482,7 +585,8 @@ ENDPROC(__und_usr)
2529 */
2530 .pushsection .fixup, "ax"
2531 .align 2
2532-4: mov pc, r9
2533+4: pax_close_userland
2534+ mov pc, r9
2535 .popsection
2536 .pushsection __ex_table,"a"
2537 .long 1b, 4b
2538@@ -692,7 +796,7 @@ ENTRY(__switch_to)
2539 THUMB( str lr, [ip], #4 )
2540 ldr r4, [r2, #TI_TP_VALUE]
2541 ldr r5, [r2, #TI_TP_VALUE + 4]
2542-#ifdef CONFIG_CPU_USE_DOMAINS
2543+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2544 ldr r6, [r2, #TI_CPU_DOMAIN]
2545 #endif
2546 switch_tls r1, r4, r5, r3, r7
2547@@ -701,7 +805,7 @@ ENTRY(__switch_to)
2548 ldr r8, =__stack_chk_guard
2549 ldr r7, [r7, #TSK_STACK_CANARY]
2550 #endif
2551-#ifdef CONFIG_CPU_USE_DOMAINS
2552+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2553 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2554 #endif
2555 mov r5, r0
2556diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2557index 94104bf..e425391 100644
2558--- a/arch/arm/kernel/entry-common.S
2559+++ b/arch/arm/kernel/entry-common.S
2560@@ -10,18 +10,46 @@
2561
2562 #include <asm/unistd.h>
2563 #include <asm/ftrace.h>
2564+#include <asm/domain.h>
2565 #include <asm/unwind.h>
2566
2567+#include "entry-header.S"
2568+
2569 #ifdef CONFIG_NEED_RET_TO_USER
2570 #include <mach/entry-macro.S>
2571 #else
2572 .macro arch_ret_to_user, tmp1, tmp2
2573+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2574+ @ save regs
2575+ stmdb sp!, {r1, r2}
2576+ @ read DACR from cpu_domain into r1
2577+ mov r2, sp
2578+ @ assume 8K pages, since we have to split the immediate in two
2579+ bic r2, r2, #(0x1fc0)
2580+ bic r2, r2, #(0x3f)
2581+ ldr r1, [r2, #TI_CPU_DOMAIN]
2582+#ifdef CONFIG_PAX_KERNEXEC
2583+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2584+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2585+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2586+#endif
2587+#ifdef CONFIG_PAX_MEMORY_UDEREF
2588+ @ set current DOMAIN_USER to DOMAIN_UDEREF
2589+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2590+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2591+#endif
2592+ @ write r1 to current_thread_info()->cpu_domain
2593+ str r1, [r2, #TI_CPU_DOMAIN]
2594+ @ write r1 to DACR
2595+ mcr p15, 0, r1, c3, c0, 0
2596+ @ instruction sync
2597+ instr_sync
2598+ @ restore regs
2599+ ldmia sp!, {r1, r2}
2600+#endif
2601 .endm
2602 #endif
2603
2604-#include "entry-header.S"
2605-
2606-
2607 .align 5
2608 /*
2609 * This is the fast syscall return path. We do as little as
2610@@ -413,6 +441,12 @@ ENTRY(vector_swi)
2611 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2612 #endif
2613
2614+ /*
2615+ * do this here to avoid a performance hit of wrapping the code above
2616+ * that directly dereferences userland to parse the SWI instruction
2617+ */
2618+ pax_enter_kernel_user
2619+
2620 adr tbl, sys_call_table @ load syscall table pointer
2621
2622 #if defined(CONFIG_OABI_COMPAT)
2623diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2624index de23a9b..94c37c4 100644
2625--- a/arch/arm/kernel/entry-header.S
2626+++ b/arch/arm/kernel/entry-header.S
2627@@ -184,6 +184,60 @@
2628 msr cpsr_c, \rtemp @ switch back to the SVC mode
2629 .endm
2630
2631+ .macro pax_enter_kernel_user
2632+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2633+ @ save regs
2634+ stmdb sp!, {r0, r1}
2635+ @ read DACR from cpu_domain into r1
2636+ mov r0, sp
2637+ @ assume 8K pages, since we have to split the immediate in two
2638+ bic r0, r0, #(0x1fc0)
2639+ bic r0, r0, #(0x3f)
2640+ ldr r1, [r0, #TI_CPU_DOMAIN]
2641+#ifdef CONFIG_PAX_MEMORY_UDEREF
2642+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2643+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2644+#endif
2645+#ifdef CONFIG_PAX_KERNEXEC
2646+ @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2647+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2648+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2649+#endif
2650+ @ write r1 to current_thread_info()->cpu_domain
2651+ str r1, [r0, #TI_CPU_DOMAIN]
2652+ @ write r1 to DACR
2653+ mcr p15, 0, r1, c3, c0, 0
2654+ @ instruction sync
2655+ instr_sync
2656+ @ restore regs
2657+ ldmia sp!, {r0, r1}
2658+#endif
2659+ .endm
2660+
2661+ .macro pax_exit_kernel
2662+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2663+ @ save regs
2664+ stmdb sp!, {r0, r1}
2665+ @ read old DACR from stack into r1
2666+ ldr r1, [sp, #(8 + S_SP)]
2667+ sub r1, r1, #8
2668+ ldr r1, [r1]
2669+
2670+ @ write r1 to current_thread_info()->cpu_domain
2671+ mov r0, sp
2672+ @ assume 8K pages, since we have to split the immediate in two
2673+ bic r0, r0, #(0x1fc0)
2674+ bic r0, r0, #(0x3f)
2675+ str r1, [r0, #TI_CPU_DOMAIN]
2676+ @ write r1 to DACR
2677+ mcr p15, 0, r1, c3, c0, 0
2678+ @ instruction sync
2679+ instr_sync
2680+ @ restore regs
2681+ ldmia sp!, {r0, r1}
2682+#endif
2683+ .endm
2684+
2685 #ifndef CONFIG_THUMB2_KERNEL
2686 .macro svc_exit, rpsr, irq = 0
2687 .if \irq != 0
2688@@ -203,6 +257,9 @@
2689 blne trace_hardirqs_off
2690 #endif
2691 .endif
2692+
2693+ pax_exit_kernel
2694+
2695 msr spsr_cxsf, \rpsr
2696 #if defined(CONFIG_CPU_V6)
2697 ldr r0, [sp]
2698@@ -266,6 +323,9 @@
2699 blne trace_hardirqs_off
2700 #endif
2701 .endif
2702+
2703+ pax_exit_kernel
2704+
2705 ldr lr, [sp, #S_SP] @ top of the stack
2706 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2707 clrex @ clear the exclusive monitor
2708diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2709index 918875d..cd5fa27 100644
2710--- a/arch/arm/kernel/fiq.c
2711+++ b/arch/arm/kernel/fiq.c
2712@@ -87,7 +87,10 @@ void set_fiq_handler(void *start, unsigned int length)
2713 void *base = vectors_page;
2714 unsigned offset = FIQ_OFFSET;
2715
2716+ pax_open_kernel();
2717 memcpy(base + offset, start, length);
2718+ pax_close_kernel();
2719+
2720 if (!cache_is_vipt_nonaliasing())
2721 flush_icache_range((unsigned long)base + offset, offset +
2722 length);
2723diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2724index 2c7cc1e..ab2e911 100644
2725--- a/arch/arm/kernel/head.S
2726+++ b/arch/arm/kernel/head.S
2727@@ -52,7 +52,9 @@
2728 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
2729
2730 .macro pgtbl, rd, phys
2731- add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
2732+ mov \rd, #TEXT_OFFSET
2733+ sub \rd, #PG_DIR_SIZE
2734+ add \rd, \rd, \phys
2735 .endm
2736
2737 /*
2738@@ -432,7 +434,7 @@ __enable_mmu:
2739 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2740 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2741 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2742- domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2743+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2744 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2745 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2746 #endif
2747diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2748index 85c3fb6..054c2dc 100644
2749--- a/arch/arm/kernel/module.c
2750+++ b/arch/arm/kernel/module.c
2751@@ -37,12 +37,39 @@
2752 #endif
2753
2754 #ifdef CONFIG_MMU
2755-void *module_alloc(unsigned long size)
2756+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2757 {
2758+ if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2759+ return NULL;
2760 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2761- GFP_KERNEL, PAGE_KERNEL_EXEC, -1,
2762+ GFP_KERNEL, prot, -1,
2763 __builtin_return_address(0));
2764 }
2765+
2766+void *module_alloc(unsigned long size)
2767+{
2768+
2769+#ifdef CONFIG_PAX_KERNEXEC
2770+ return __module_alloc(size, PAGE_KERNEL);
2771+#else
2772+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2773+#endif
2774+
2775+}
2776+
2777+#ifdef CONFIG_PAX_KERNEXEC
2778+void module_free_exec(struct module *mod, void *module_region)
2779+{
2780+ module_free(mod, module_region);
2781+}
2782+EXPORT_SYMBOL(module_free_exec);
2783+
2784+void *module_alloc_exec(unsigned long size)
2785+{
2786+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2787+}
2788+EXPORT_SYMBOL(module_alloc_exec);
2789+#endif
2790 #endif
2791
2792 int
2793diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2794index 07314af..c46655c 100644
2795--- a/arch/arm/kernel/patch.c
2796+++ b/arch/arm/kernel/patch.c
2797@@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2798 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2799 int size;
2800
2801+ pax_open_kernel();
2802 if (thumb2 && __opcode_is_thumb16(insn)) {
2803 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2804 size = sizeof(u16);
2805@@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2806 *(u32 *)addr = insn;
2807 size = sizeof(u32);
2808 }
2809+ pax_close_kernel();
2810
2811 flush_icache_range((uintptr_t)(addr),
2812 (uintptr_t)(addr) + size);
2813diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2814index 94f6b05..efd7312 100644
2815--- a/arch/arm/kernel/process.c
2816+++ b/arch/arm/kernel/process.c
2817@@ -217,6 +217,7 @@ void machine_power_off(void)
2818
2819 if (pm_power_off)
2820 pm_power_off();
2821+ BUG();
2822 }
2823
2824 /*
2825@@ -230,7 +231,7 @@ void machine_power_off(void)
2826 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2827 * to use. Implementing such co-ordination would be essentially impossible.
2828 */
2829-void machine_restart(char *cmd)
2830+__noreturn void machine_restart(char *cmd)
2831 {
2832 local_irq_disable();
2833 smp_send_stop();
2834@@ -253,8 +254,8 @@ void __show_regs(struct pt_regs *regs)
2835
2836 show_regs_print_info(KERN_DEFAULT);
2837
2838- print_symbol("PC is at %s\n", instruction_pointer(regs));
2839- print_symbol("LR is at %s\n", regs->ARM_lr);
2840+ printk("PC is at %pA\n", (void *)instruction_pointer(regs));
2841+ printk("LR is at %pA\n", (void *)regs->ARM_lr);
2842 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2843 "sp : %08lx ip : %08lx fp : %08lx\n",
2844 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2845@@ -422,12 +423,6 @@ unsigned long get_wchan(struct task_struct *p)
2846 return 0;
2847 }
2848
2849-unsigned long arch_randomize_brk(struct mm_struct *mm)
2850-{
2851- unsigned long range_end = mm->brk + 0x02000000;
2852- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2853-}
2854-
2855 #ifdef CONFIG_MMU
2856 #ifdef CONFIG_KUSER_HELPERS
2857 /*
2858@@ -443,7 +438,7 @@ static struct vm_area_struct gate_vma = {
2859
2860 static int __init gate_vma_init(void)
2861 {
2862- gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2863+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2864 return 0;
2865 }
2866 arch_initcall(gate_vma_init);
2867@@ -469,41 +464,16 @@ int in_gate_area_no_mm(unsigned long addr)
2868
2869 const char *arch_vma_name(struct vm_area_struct *vma)
2870 {
2871- return is_gate_vma(vma) ? "[vectors]" :
2872- (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
2873- "[sigpage]" : NULL;
2874+ return is_gate_vma(vma) ? "[vectors]" : NULL;
2875 }
2876
2877-static struct page *signal_page;
2878-extern struct page *get_signal_page(void);
2879-
2880 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2881 {
2882 struct mm_struct *mm = current->mm;
2883- unsigned long addr;
2884- int ret;
2885-
2886- if (!signal_page)
2887- signal_page = get_signal_page();
2888- if (!signal_page)
2889- return -ENOMEM;
2890
2891 down_write(&mm->mmap_sem);
2892- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
2893- if (IS_ERR_VALUE(addr)) {
2894- ret = addr;
2895- goto up_fail;
2896- }
2897-
2898- ret = install_special_mapping(mm, addr, PAGE_SIZE,
2899- VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
2900- &signal_page);
2901-
2902- if (ret == 0)
2903- mm->context.sigpage = addr;
2904-
2905- up_fail:
2906+ mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
2907 up_write(&mm->mmap_sem);
2908- return ret;
2909+ return 0;
2910 }
2911 #endif
2912diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
2913index 4693188..4596c5e 100644
2914--- a/arch/arm/kernel/psci.c
2915+++ b/arch/arm/kernel/psci.c
2916@@ -24,7 +24,7 @@
2917 #include <asm/opcodes-virt.h>
2918 #include <asm/psci.h>
2919
2920-struct psci_operations psci_ops;
2921+struct psci_operations psci_ops __read_only;
2922
2923 static int (*invoke_psci_fn)(u32, u32, u32, u32);
2924
2925diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2926index 0dd3b79..e018f64 100644
2927--- a/arch/arm/kernel/ptrace.c
2928+++ b/arch/arm/kernel/ptrace.c
2929@@ -929,10 +929,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2930 return current_thread_info()->syscall;
2931 }
2932
2933+#ifdef CONFIG_GRKERNSEC_SETXID
2934+extern void gr_delayed_cred_worker(void);
2935+#endif
2936+
2937 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2938 {
2939 current_thread_info()->syscall = scno;
2940
2941+#ifdef CONFIG_GRKERNSEC_SETXID
2942+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2943+ gr_delayed_cred_worker();
2944+#endif
2945+
2946 /* Do the secure computing check first; failures should be fast. */
2947 if (secure_computing(scno) == -1)
2948 return -1;
2949diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2950index afc2489..6372bc8 100644
2951--- a/arch/arm/kernel/setup.c
2952+++ b/arch/arm/kernel/setup.c
2953@@ -98,21 +98,23 @@ EXPORT_SYMBOL(system_serial_high);
2954 unsigned int elf_hwcap __read_mostly;
2955 EXPORT_SYMBOL(elf_hwcap);
2956
2957+pteval_t __supported_pte_mask __read_only;
2958+pmdval_t __supported_pmd_mask __read_only;
2959
2960 #ifdef MULTI_CPU
2961-struct processor processor __read_mostly;
2962+struct processor processor;
2963 #endif
2964 #ifdef MULTI_TLB
2965-struct cpu_tlb_fns cpu_tlb __read_mostly;
2966+struct cpu_tlb_fns cpu_tlb __read_only;
2967 #endif
2968 #ifdef MULTI_USER
2969-struct cpu_user_fns cpu_user __read_mostly;
2970+struct cpu_user_fns cpu_user __read_only;
2971 #endif
2972 #ifdef MULTI_CACHE
2973-struct cpu_cache_fns cpu_cache __read_mostly;
2974+struct cpu_cache_fns cpu_cache __read_only;
2975 #endif
2976 #ifdef CONFIG_OUTER_CACHE
2977-struct outer_cache_fns outer_cache __read_mostly;
2978+struct outer_cache_fns outer_cache __read_only;
2979 EXPORT_SYMBOL(outer_cache);
2980 #endif
2981
2982@@ -245,9 +247,13 @@ static int __get_cpu_architecture(void)
2983 asm("mrc p15, 0, %0, c0, c1, 4"
2984 : "=r" (mmfr0));
2985 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
2986- (mmfr0 & 0x000000f0) >= 0x00000030)
2987+ (mmfr0 & 0x000000f0) >= 0x00000030) {
2988 cpu_arch = CPU_ARCH_ARMv7;
2989- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2990+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
2991+ __supported_pte_mask |= L_PTE_PXN;
2992+ __supported_pmd_mask |= PMD_PXNTABLE;
2993+ }
2994+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2995 (mmfr0 & 0x000000f0) == 0x00000020)
2996 cpu_arch = CPU_ARCH_ARMv6;
2997 else
2998@@ -571,7 +577,7 @@ static void __init setup_processor(void)
2999 __cpu_architecture = __get_cpu_architecture();
3000
3001 #ifdef MULTI_CPU
3002- processor = *list->proc;
3003+ memcpy((void *)&processor, list->proc, sizeof processor);
3004 #endif
3005 #ifdef MULTI_TLB
3006 cpu_tlb = *list->tlb;
3007diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3008index ab33042..11248a8 100644
3009--- a/arch/arm/kernel/signal.c
3010+++ b/arch/arm/kernel/signal.c
3011@@ -45,8 +45,6 @@ static const unsigned long sigreturn_codes[7] = {
3012 MOV_R7_NR_RT_SIGRETURN, SWI_SYS_RT_SIGRETURN, SWI_THUMB_RT_SIGRETURN,
3013 };
3014
3015-static unsigned long signal_return_offset;
3016-
3017 #ifdef CONFIG_CRUNCH
3018 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3019 {
3020@@ -411,8 +409,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3021 * except when the MPU has protected the vectors
3022 * page from PL0
3023 */
3024- retcode = mm->context.sigpage + signal_return_offset +
3025- (idx << 2) + thumb;
3026+ retcode = mm->context.sigpage + (idx << 2) + thumb;
3027 } else
3028 #endif
3029 {
3030@@ -616,33 +613,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3031 } while (thread_flags & _TIF_WORK_MASK);
3032 return 0;
3033 }
3034-
3035-struct page *get_signal_page(void)
3036-{
3037- unsigned long ptr;
3038- unsigned offset;
3039- struct page *page;
3040- void *addr;
3041-
3042- page = alloc_pages(GFP_KERNEL, 0);
3043-
3044- if (!page)
3045- return NULL;
3046-
3047- addr = page_address(page);
3048-
3049- /* Give the signal return code some randomness */
3050- offset = 0x200 + (get_random_int() & 0x7fc);
3051- signal_return_offset = offset;
3052-
3053- /*
3054- * Copy signal return handlers into the vector page, and
3055- * set sigreturn to be a pointer to these.
3056- */
3057- memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3058-
3059- ptr = (unsigned long)addr + offset;
3060- flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3061-
3062- return page;
3063-}
3064diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3065index 2dc1934..ecf0e21 100644
3066--- a/arch/arm/kernel/smp.c
3067+++ b/arch/arm/kernel/smp.c
3068@@ -71,7 +71,7 @@ enum ipi_msg_type {
3069
3070 static DECLARE_COMPLETION(cpu_running);
3071
3072-static struct smp_operations smp_ops;
3073+static struct smp_operations smp_ops __read_only;
3074
3075 void __init smp_set_ops(struct smp_operations *ops)
3076 {
3077diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3078index ab517fc..9adf2fa 100644
3079--- a/arch/arm/kernel/traps.c
3080+++ b/arch/arm/kernel/traps.c
3081@@ -55,7 +55,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3082 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3083 {
3084 #ifdef CONFIG_KALLSYMS
3085- printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3086+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3087 #else
3088 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3089 #endif
3090@@ -257,6 +257,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3091 static int die_owner = -1;
3092 static unsigned int die_nest_count;
3093
3094+extern void gr_handle_kernel_exploit(void);
3095+
3096 static unsigned long oops_begin(void)
3097 {
3098 int cpu;
3099@@ -299,6 +301,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3100 panic("Fatal exception in interrupt");
3101 if (panic_on_oops)
3102 panic("Fatal exception");
3103+
3104+ gr_handle_kernel_exploit();
3105+
3106 if (signr)
3107 do_exit(signr);
3108 }
3109@@ -592,7 +597,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3110 * The user helper at 0xffff0fe0 must be used instead.
3111 * (see entry-armv.S for details)
3112 */
3113+ pax_open_kernel();
3114 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3115+ pax_close_kernel();
3116 }
3117 return 0;
3118
3119@@ -849,7 +856,11 @@ void __init early_trap_init(void *vectors_base)
3120 kuser_init(vectors_base);
3121
3122 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3123- modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3124+
3125+#ifndef CONFIG_PAX_MEMORY_UDEREF
3126+ modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3127+#endif
3128+
3129 #else /* ifndef CONFIG_CPU_V7M */
3130 /*
3131 * on V7-M there is no need to copy the vector table to a dedicated
3132diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3133index 7bcee5c..e2f3249 100644
3134--- a/arch/arm/kernel/vmlinux.lds.S
3135+++ b/arch/arm/kernel/vmlinux.lds.S
3136@@ -8,7 +8,11 @@
3137 #include <asm/thread_info.h>
3138 #include <asm/memory.h>
3139 #include <asm/page.h>
3140-
3141+
3142+#ifdef CONFIG_PAX_KERNEXEC
3143+#include <asm/pgtable.h>
3144+#endif
3145+
3146 #define PROC_INFO \
3147 . = ALIGN(4); \
3148 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3149@@ -34,7 +38,7 @@
3150 #endif
3151
3152 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3153- defined(CONFIG_GENERIC_BUG)
3154+ defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3155 #define ARM_EXIT_KEEP(x) x
3156 #define ARM_EXIT_DISCARD(x)
3157 #else
3158@@ -90,6 +94,11 @@ SECTIONS
3159 _text = .;
3160 HEAD_TEXT
3161 }
3162+
3163+#ifdef CONFIG_PAX_KERNEXEC
3164+ . = ALIGN(1<<SECTION_SHIFT);
3165+#endif
3166+
3167 .text : { /* Real text segment */
3168 _stext = .; /* Text and read-only data */
3169 __exception_text_start = .;
3170@@ -112,6 +121,8 @@ SECTIONS
3171 ARM_CPU_KEEP(PROC_INFO)
3172 }
3173
3174+ _etext = .; /* End of text section */
3175+
3176 RO_DATA(PAGE_SIZE)
3177
3178 . = ALIGN(4);
3179@@ -142,7 +153,9 @@ SECTIONS
3180
3181 NOTES
3182
3183- _etext = .; /* End of text and rodata section */
3184+#ifdef CONFIG_PAX_KERNEXEC
3185+ . = ALIGN(1<<SECTION_SHIFT);
3186+#endif
3187
3188 #ifndef CONFIG_XIP_KERNEL
3189 . = ALIGN(PAGE_SIZE);
3190@@ -220,6 +233,11 @@ SECTIONS
3191 . = PAGE_OFFSET + TEXT_OFFSET;
3192 #else
3193 __init_end = .;
3194+
3195+#ifdef CONFIG_PAX_KERNEXEC
3196+ . = ALIGN(1<<SECTION_SHIFT);
3197+#endif
3198+
3199 . = ALIGN(THREAD_SIZE);
3200 __data_loc = .;
3201 #endif
3202diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3203index 741f66a..8a5615c 100644
3204--- a/arch/arm/kvm/arm.c
3205+++ b/arch/arm/kvm/arm.c
3206@@ -56,7 +56,7 @@ static unsigned long hyp_default_vectors;
3207 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3208
3209 /* The VMID used in the VTTBR */
3210-static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3211+static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3212 static u8 kvm_next_vmid;
3213 static DEFINE_SPINLOCK(kvm_vmid_lock);
3214
3215@@ -392,7 +392,7 @@ void force_vm_exit(const cpumask_t *mask)
3216 */
3217 static bool need_new_vmid_gen(struct kvm *kvm)
3218 {
3219- return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3220+ return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3221 }
3222
3223 /**
3224@@ -425,7 +425,7 @@ static void update_vttbr(struct kvm *kvm)
3225
3226 /* First user of a new VMID generation? */
3227 if (unlikely(kvm_next_vmid == 0)) {
3228- atomic64_inc(&kvm_vmid_gen);
3229+ atomic64_inc_unchecked(&kvm_vmid_gen);
3230 kvm_next_vmid = 1;
3231
3232 /*
3233@@ -442,7 +442,7 @@ static void update_vttbr(struct kvm *kvm)
3234 kvm_call_hyp(__kvm_flush_vm_context);
3235 }
3236
3237- kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3238+ kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3239 kvm->arch.vmid = kvm_next_vmid;
3240 kvm_next_vmid++;
3241
3242diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3243index 14a0d98..7771a7d 100644
3244--- a/arch/arm/lib/clear_user.S
3245+++ b/arch/arm/lib/clear_user.S
3246@@ -12,14 +12,14 @@
3247
3248 .text
3249
3250-/* Prototype: int __clear_user(void *addr, size_t sz)
3251+/* Prototype: int ___clear_user(void *addr, size_t sz)
3252 * Purpose : clear some user memory
3253 * Params : addr - user memory address to clear
3254 * : sz - number of bytes to clear
3255 * Returns : number of bytes NOT cleared
3256 */
3257 ENTRY(__clear_user_std)
3258-WEAK(__clear_user)
3259+WEAK(___clear_user)
3260 stmfd sp!, {r1, lr}
3261 mov r2, #0
3262 cmp r1, #4
3263@@ -44,7 +44,7 @@ WEAK(__clear_user)
3264 USER( strnebt r2, [r0])
3265 mov r0, #0
3266 ldmfd sp!, {r1, pc}
3267-ENDPROC(__clear_user)
3268+ENDPROC(___clear_user)
3269 ENDPROC(__clear_user_std)
3270
3271 .pushsection .fixup,"ax"
3272diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3273index 66a477a..bee61d3 100644
3274--- a/arch/arm/lib/copy_from_user.S
3275+++ b/arch/arm/lib/copy_from_user.S
3276@@ -16,7 +16,7 @@
3277 /*
3278 * Prototype:
3279 *
3280- * size_t __copy_from_user(void *to, const void *from, size_t n)
3281+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
3282 *
3283 * Purpose:
3284 *
3285@@ -84,11 +84,11 @@
3286
3287 .text
3288
3289-ENTRY(__copy_from_user)
3290+ENTRY(___copy_from_user)
3291
3292 #include "copy_template.S"
3293
3294-ENDPROC(__copy_from_user)
3295+ENDPROC(___copy_from_user)
3296
3297 .pushsection .fixup,"ax"
3298 .align 0
3299diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3300index 6ee2f67..d1cce76 100644
3301--- a/arch/arm/lib/copy_page.S
3302+++ b/arch/arm/lib/copy_page.S
3303@@ -10,6 +10,7 @@
3304 * ASM optimised string functions
3305 */
3306 #include <linux/linkage.h>
3307+#include <linux/const.h>
3308 #include <asm/assembler.h>
3309 #include <asm/asm-offsets.h>
3310 #include <asm/cache.h>
3311diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3312index d066df6..df28194 100644
3313--- a/arch/arm/lib/copy_to_user.S
3314+++ b/arch/arm/lib/copy_to_user.S
3315@@ -16,7 +16,7 @@
3316 /*
3317 * Prototype:
3318 *
3319- * size_t __copy_to_user(void *to, const void *from, size_t n)
3320+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
3321 *
3322 * Purpose:
3323 *
3324@@ -88,11 +88,11 @@
3325 .text
3326
3327 ENTRY(__copy_to_user_std)
3328-WEAK(__copy_to_user)
3329+WEAK(___copy_to_user)
3330
3331 #include "copy_template.S"
3332
3333-ENDPROC(__copy_to_user)
3334+ENDPROC(___copy_to_user)
3335 ENDPROC(__copy_to_user_std)
3336
3337 .pushsection .fixup,"ax"
3338diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3339index 7d08b43..f7ca7ea 100644
3340--- a/arch/arm/lib/csumpartialcopyuser.S
3341+++ b/arch/arm/lib/csumpartialcopyuser.S
3342@@ -57,8 +57,8 @@
3343 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3344 */
3345
3346-#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3347-#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3348+#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3349+#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3350
3351 #include "csumpartialcopygeneric.S"
3352
3353diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3354index 5306de3..aed6d03 100644
3355--- a/arch/arm/lib/delay.c
3356+++ b/arch/arm/lib/delay.c
3357@@ -28,7 +28,7 @@
3358 /*
3359 * Default to the loop-based delay implementation.
3360 */
3361-struct arm_delay_ops arm_delay_ops = {
3362+struct arm_delay_ops arm_delay_ops __read_only = {
3363 .delay = __loop_delay,
3364 .const_udelay = __loop_const_udelay,
3365 .udelay = __loop_udelay,
3366diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3367index 025f742..a9e5b3b 100644
3368--- a/arch/arm/lib/uaccess_with_memcpy.c
3369+++ b/arch/arm/lib/uaccess_with_memcpy.c
3370@@ -104,7 +104,7 @@ out:
3371 }
3372
3373 unsigned long
3374-__copy_to_user(void __user *to, const void *from, unsigned long n)
3375+___copy_to_user(void __user *to, const void *from, unsigned long n)
3376 {
3377 /*
3378 * This test is stubbed out of the main function above to keep
3379@@ -155,7 +155,7 @@ out:
3380 return n;
3381 }
3382
3383-unsigned long __clear_user(void __user *addr, unsigned long n)
3384+unsigned long ___clear_user(void __user *addr, unsigned long n)
3385 {
3386 /* See rational for this in __copy_to_user() above. */
3387 if (n < 64)
3388diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3389index e9238b5..6ed904a 100644
3390--- a/arch/arm/mach-kirkwood/common.c
3391+++ b/arch/arm/mach-kirkwood/common.c
3392@@ -150,7 +150,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3393 clk_gate_ops.disable(hw);
3394 }
3395
3396-static struct clk_ops clk_gate_fn_ops;
3397+static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3398+{
3399+ return clk_gate_ops.is_enabled(hw);
3400+}
3401+
3402+static struct clk_ops clk_gate_fn_ops = {
3403+ .enable = clk_gate_fn_enable,
3404+ .disable = clk_gate_fn_disable,
3405+ .is_enabled = clk_gate_fn_is_enabled,
3406+};
3407
3408 static struct clk __init *clk_register_gate_fn(struct device *dev,
3409 const char *name,
3410@@ -184,14 +193,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3411 gate_fn->fn_en = fn_en;
3412 gate_fn->fn_dis = fn_dis;
3413
3414- /* ops is the gate ops, but with our enable/disable functions */
3415- if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3416- clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3417- clk_gate_fn_ops = clk_gate_ops;
3418- clk_gate_fn_ops.enable = clk_gate_fn_enable;
3419- clk_gate_fn_ops.disable = clk_gate_fn_disable;
3420- }
3421-
3422 clk = clk_register(dev, &gate_fn->gate.hw);
3423
3424 if (IS_ERR(clk))
3425diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3426index 827d1500..2885dc6 100644
3427--- a/arch/arm/mach-omap2/board-n8x0.c
3428+++ b/arch/arm/mach-omap2/board-n8x0.c
3429@@ -627,7 +627,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3430 }
3431 #endif
3432
3433-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3434+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3435 .late_init = n8x0_menelaus_late_init,
3436 };
3437
3438diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3439index f3fdd6a..3564800 100644
3440--- a/arch/arm/mach-omap2/gpmc.c
3441+++ b/arch/arm/mach-omap2/gpmc.c
3442@@ -148,7 +148,6 @@ struct omap3_gpmc_regs {
3443 };
3444
3445 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3446-static struct irq_chip gpmc_irq_chip;
3447 static unsigned gpmc_irq_start;
3448
3449 static struct resource gpmc_mem_root;
3450@@ -716,6 +715,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3451
3452 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3453
3454+static struct irq_chip gpmc_irq_chip = {
3455+ .name = "gpmc",
3456+ .irq_startup = gpmc_irq_noop_ret,
3457+ .irq_enable = gpmc_irq_enable,
3458+ .irq_disable = gpmc_irq_disable,
3459+ .irq_shutdown = gpmc_irq_noop,
3460+ .irq_ack = gpmc_irq_noop,
3461+ .irq_mask = gpmc_irq_noop,
3462+ .irq_unmask = gpmc_irq_noop,
3463+
3464+};
3465+
3466 static int gpmc_setup_irq(void)
3467 {
3468 int i;
3469@@ -730,15 +741,6 @@ static int gpmc_setup_irq(void)
3470 return gpmc_irq_start;
3471 }
3472
3473- gpmc_irq_chip.name = "gpmc";
3474- gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3475- gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3476- gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3477- gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3478- gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3479- gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3480- gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3481-
3482 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3483 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3484
3485diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3486index f991016..145ebeb 100644
3487--- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3488+++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3489@@ -84,7 +84,7 @@ struct cpu_pm_ops {
3490 int (*finish_suspend)(unsigned long cpu_state);
3491 void (*resume)(void);
3492 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3493-};
3494+} __no_const;
3495
3496 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3497 static struct powerdomain *mpuss_pd;
3498@@ -102,7 +102,7 @@ static void dummy_cpu_resume(void)
3499 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3500 {}
3501
3502-struct cpu_pm_ops omap_pm_ops = {
3503+static struct cpu_pm_ops omap_pm_ops __read_only = {
3504 .finish_suspend = default_finish_suspend,
3505 .resume = dummy_cpu_resume,
3506 .scu_prepare = dummy_scu_prepare,
3507diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3508index 813c615..ce467c6 100644
3509--- a/arch/arm/mach-omap2/omap-wakeupgen.c
3510+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3511@@ -339,7 +339,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3512 return NOTIFY_OK;
3513 }
3514
3515-static struct notifier_block __refdata irq_hotplug_notifier = {
3516+static struct notifier_block irq_hotplug_notifier = {
3517 .notifier_call = irq_cpu_hotplug_notify,
3518 };
3519
3520diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3521index f99f68e..e573e20 100644
3522--- a/arch/arm/mach-omap2/omap_device.c
3523+++ b/arch/arm/mach-omap2/omap_device.c
3524@@ -504,7 +504,7 @@ void omap_device_delete(struct omap_device *od)
3525 struct platform_device __init *omap_device_build(const char *pdev_name,
3526 int pdev_id,
3527 struct omap_hwmod *oh,
3528- void *pdata, int pdata_len)
3529+ const void *pdata, int pdata_len)
3530 {
3531 struct omap_hwmod *ohs[] = { oh };
3532
3533@@ -532,7 +532,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3534 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3535 int pdev_id,
3536 struct omap_hwmod **ohs,
3537- int oh_cnt, void *pdata,
3538+ int oh_cnt, const void *pdata,
3539 int pdata_len)
3540 {
3541 int ret = -ENOMEM;
3542diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3543index 17ca1ae..beba869 100644
3544--- a/arch/arm/mach-omap2/omap_device.h
3545+++ b/arch/arm/mach-omap2/omap_device.h
3546@@ -71,12 +71,12 @@ int omap_device_idle(struct platform_device *pdev);
3547 /* Core code interface */
3548
3549 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3550- struct omap_hwmod *oh, void *pdata,
3551+ struct omap_hwmod *oh, const void *pdata,
3552 int pdata_len);
3553
3554 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3555 struct omap_hwmod **oh, int oh_cnt,
3556- void *pdata, int pdata_len);
3557+ const void *pdata, int pdata_len);
3558
3559 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3560 struct omap_hwmod **ohs, int oh_cnt);
3561diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3562index 7f4db12..0243012 100644
3563--- a/arch/arm/mach-omap2/omap_hwmod.c
3564+++ b/arch/arm/mach-omap2/omap_hwmod.c
3565@@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3566 int (*init_clkdm)(struct omap_hwmod *oh);
3567 void (*update_context_lost)(struct omap_hwmod *oh);
3568 int (*get_context_lost)(struct omap_hwmod *oh);
3569-};
3570+} __no_const;
3571
3572 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3573-static struct omap_hwmod_soc_ops soc_ops;
3574+static struct omap_hwmod_soc_ops soc_ops __read_only;
3575
3576 /* omap_hwmod_list contains all registered struct omap_hwmods */
3577 static LIST_HEAD(omap_hwmod_list);
3578diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3579index d15c7bb..b2d1f0c 100644
3580--- a/arch/arm/mach-omap2/wd_timer.c
3581+++ b/arch/arm/mach-omap2/wd_timer.c
3582@@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3583 struct omap_hwmod *oh;
3584 char *oh_name = "wd_timer2";
3585 char *dev_name = "omap_wdt";
3586- struct omap_wd_timer_platform_data pdata;
3587+ static struct omap_wd_timer_platform_data pdata = {
3588+ .read_reset_sources = prm_read_reset_sources
3589+ };
3590
3591 if (!cpu_class_is_omap2() || of_have_populated_dt())
3592 return 0;
3593@@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3594 return -EINVAL;
3595 }
3596
3597- pdata.read_reset_sources = prm_read_reset_sources;
3598-
3599 pdev = omap_device_build(dev_name, id, oh, &pdata,
3600 sizeof(struct omap_wd_timer_platform_data));
3601 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3602diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3603index 706aa42..f85e9131 100644
3604--- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3605+++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3606@@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3607 bool entered_lp2 = false;
3608
3609 if (tegra_pending_sgi())
3610- ACCESS_ONCE(abort_flag) = true;
3611+ ACCESS_ONCE_RW(abort_flag) = true;
3612
3613 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3614
3615diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3616index cad3ca86..1d79e0f 100644
3617--- a/arch/arm/mach-ux500/setup.h
3618+++ b/arch/arm/mach-ux500/setup.h
3619@@ -37,13 +37,6 @@ extern void ux500_timer_init(void);
3620 .type = MT_DEVICE, \
3621 }
3622
3623-#define __MEM_DEV_DESC(x, sz) { \
3624- .virtual = IO_ADDRESS(x), \
3625- .pfn = __phys_to_pfn(x), \
3626- .length = sz, \
3627- .type = MT_MEMORY, \
3628-}
3629-
3630 extern struct smp_operations ux500_smp_ops;
3631 extern void ux500_cpu_die(unsigned int cpu);
3632
3633diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3634index cd2c88e..7430282 100644
3635--- a/arch/arm/mm/Kconfig
3636+++ b/arch/arm/mm/Kconfig
3637@@ -446,7 +446,7 @@ config CPU_32v5
3638
3639 config CPU_32v6
3640 bool
3641- select CPU_USE_DOMAINS if CPU_V6 && MMU
3642+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3643 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3644
3645 config CPU_32v6K
3646@@ -601,6 +601,7 @@ config CPU_CP15_MPU
3647
3648 config CPU_USE_DOMAINS
3649 bool
3650+ depends on !ARM_LPAE && !PAX_KERNEXEC
3651 help
3652 This option enables or disables the use of domain switching
3653 via the set_fs() function.
3654@@ -800,6 +801,7 @@ config NEED_KUSER_HELPERS
3655 config KUSER_HELPERS
3656 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3657 default y
3658+ depends on !(CPU_V6 || CPU_V6K || CPU_V7)
3659 help
3660 Warning: disabling this option may break user programs.
3661
3662@@ -812,7 +814,7 @@ config KUSER_HELPERS
3663 See Documentation/arm/kernel_user_helpers.txt for details.
3664
3665 However, the fixed address nature of these helpers can be used
3666- by ROP (return orientated programming) authors when creating
3667+ by ROP (Return Oriented Programming) authors when creating
3668 exploits.
3669
3670 If all of the binaries and libraries which run on your platform
3671diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3672index 6f4585b..7b6f52b 100644
3673--- a/arch/arm/mm/alignment.c
3674+++ b/arch/arm/mm/alignment.c
3675@@ -211,10 +211,12 @@ union offset_union {
3676 #define __get16_unaligned_check(ins,val,addr) \
3677 do { \
3678 unsigned int err = 0, v, a = addr; \
3679+ pax_open_userland(); \
3680 __get8_unaligned_check(ins,v,a,err); \
3681 val = v << ((BE) ? 8 : 0); \
3682 __get8_unaligned_check(ins,v,a,err); \
3683 val |= v << ((BE) ? 0 : 8); \
3684+ pax_close_userland(); \
3685 if (err) \
3686 goto fault; \
3687 } while (0)
3688@@ -228,6 +230,7 @@ union offset_union {
3689 #define __get32_unaligned_check(ins,val,addr) \
3690 do { \
3691 unsigned int err = 0, v, a = addr; \
3692+ pax_open_userland(); \
3693 __get8_unaligned_check(ins,v,a,err); \
3694 val = v << ((BE) ? 24 : 0); \
3695 __get8_unaligned_check(ins,v,a,err); \
3696@@ -236,6 +239,7 @@ union offset_union {
3697 val |= v << ((BE) ? 8 : 16); \
3698 __get8_unaligned_check(ins,v,a,err); \
3699 val |= v << ((BE) ? 0 : 24); \
3700+ pax_close_userland(); \
3701 if (err) \
3702 goto fault; \
3703 } while (0)
3704@@ -249,6 +253,7 @@ union offset_union {
3705 #define __put16_unaligned_check(ins,val,addr) \
3706 do { \
3707 unsigned int err = 0, v = val, a = addr; \
3708+ pax_open_userland(); \
3709 __asm__( FIRST_BYTE_16 \
3710 ARM( "1: "ins" %1, [%2], #1\n" ) \
3711 THUMB( "1: "ins" %1, [%2]\n" ) \
3712@@ -268,6 +273,7 @@ union offset_union {
3713 " .popsection\n" \
3714 : "=r" (err), "=&r" (v), "=&r" (a) \
3715 : "0" (err), "1" (v), "2" (a)); \
3716+ pax_close_userland(); \
3717 if (err) \
3718 goto fault; \
3719 } while (0)
3720@@ -281,6 +287,7 @@ union offset_union {
3721 #define __put32_unaligned_check(ins,val,addr) \
3722 do { \
3723 unsigned int err = 0, v = val, a = addr; \
3724+ pax_open_userland(); \
3725 __asm__( FIRST_BYTE_32 \
3726 ARM( "1: "ins" %1, [%2], #1\n" ) \
3727 THUMB( "1: "ins" %1, [%2]\n" ) \
3728@@ -310,6 +317,7 @@ union offset_union {
3729 " .popsection\n" \
3730 : "=r" (err), "=&r" (v), "=&r" (a) \
3731 : "0" (err), "1" (v), "2" (a)); \
3732+ pax_close_userland(); \
3733 if (err) \
3734 goto fault; \
3735 } while (0)
3736diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3737index 4a05444..d21968c 100644
3738--- a/arch/arm/mm/context.c
3739+++ b/arch/arm/mm/context.c
3740@@ -43,7 +43,7 @@
3741 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3742
3743 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3744-static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3745+static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3746 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3747
3748 static DEFINE_PER_CPU(atomic64_t, active_asids);
3749@@ -183,7 +183,7 @@ static int is_reserved_asid(u64 asid)
3750 static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3751 {
3752 u64 asid = atomic64_read(&mm->context.id);
3753- u64 generation = atomic64_read(&asid_generation);
3754+ u64 generation = atomic64_read_unchecked(&asid_generation);
3755
3756 if (asid != 0 && is_reserved_asid(asid)) {
3757 /*
3758@@ -201,7 +201,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3759 */
3760 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3761 if (asid == NUM_USER_ASIDS) {
3762- generation = atomic64_add_return(ASID_FIRST_VERSION,
3763+ generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3764 &asid_generation);
3765 flush_context(cpu);
3766 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3767@@ -230,14 +230,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3768 cpu_set_reserved_ttbr0();
3769
3770 asid = atomic64_read(&mm->context.id);
3771- if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3772+ if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3773 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3774 goto switch_mm_fastpath;
3775
3776 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
3777 /* Check that our ASID belongs to the current generation. */
3778 asid = atomic64_read(&mm->context.id);
3779- if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
3780+ if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
3781 asid = new_context(mm, cpu);
3782 atomic64_set(&mm->context.id, asid);
3783 }
3784diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3785index c97f794..6461880 100644
3786--- a/arch/arm/mm/fault.c
3787+++ b/arch/arm/mm/fault.c
3788@@ -25,6 +25,7 @@
3789 #include <asm/system_misc.h>
3790 #include <asm/system_info.h>
3791 #include <asm/tlbflush.h>
3792+#include <asm/sections.h>
3793
3794 #include "fault.h"
3795
3796@@ -138,6 +139,20 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3797 if (fixup_exception(regs))
3798 return;
3799
3800+#ifdef CONFIG_PAX_KERNEXEC
3801+ if ((fsr & FSR_WRITE) &&
3802+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3803+ (MODULES_VADDR <= addr && addr < MODULES_END)))
3804+ {
3805+ if (current->signal->curr_ip)
3806+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3807+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3808+ else
3809+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3810+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3811+ }
3812+#endif
3813+
3814 /*
3815 * No handler, we'll have to terminate things with extreme prejudice.
3816 */
3817@@ -174,6 +189,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3818 }
3819 #endif
3820
3821+#ifdef CONFIG_PAX_PAGEEXEC
3822+ if (fsr & FSR_LNX_PF) {
3823+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3824+ do_group_exit(SIGKILL);
3825+ }
3826+#endif
3827+
3828 tsk->thread.address = addr;
3829 tsk->thread.error_code = fsr;
3830 tsk->thread.trap_no = 14;
3831@@ -398,6 +420,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3832 }
3833 #endif /* CONFIG_MMU */
3834
3835+#ifdef CONFIG_PAX_PAGEEXEC
3836+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3837+{
3838+ long i;
3839+
3840+ printk(KERN_ERR "PAX: bytes at PC: ");
3841+ for (i = 0; i < 20; i++) {
3842+ unsigned char c;
3843+ if (get_user(c, (__force unsigned char __user *)pc+i))
3844+ printk(KERN_CONT "?? ");
3845+ else
3846+ printk(KERN_CONT "%02x ", c);
3847+ }
3848+ printk("\n");
3849+
3850+ printk(KERN_ERR "PAX: bytes at SP-4: ");
3851+ for (i = -1; i < 20; i++) {
3852+ unsigned long c;
3853+ if (get_user(c, (__force unsigned long __user *)sp+i))
3854+ printk(KERN_CONT "???????? ");
3855+ else
3856+ printk(KERN_CONT "%08lx ", c);
3857+ }
3858+ printk("\n");
3859+}
3860+#endif
3861+
3862 /*
3863 * First Level Translation Fault Handler
3864 *
3865@@ -545,9 +594,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3866 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3867 struct siginfo info;
3868
3869+#ifdef CONFIG_PAX_MEMORY_UDEREF
3870+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3871+ if (current->signal->curr_ip)
3872+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3873+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3874+ else
3875+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3876+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3877+ goto die;
3878+ }
3879+#endif
3880+
3881 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3882 return;
3883
3884+die:
3885 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3886 inf->name, fsr, addr);
3887
3888@@ -571,15 +633,92 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
3889 ifsr_info[nr].name = name;
3890 }
3891
3892+asmlinkage int sys_sigreturn(struct pt_regs *regs);
3893+asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
3894+
3895 asmlinkage void __exception
3896 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3897 {
3898 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3899 struct siginfo info;
3900+ unsigned long pc = instruction_pointer(regs);
3901+
3902+ if (user_mode(regs)) {
3903+ unsigned long sigpage = current->mm->context.sigpage;
3904+
3905+ if (sigpage <= pc && pc < sigpage + 7*4) {
3906+ if (pc < sigpage + 3*4)
3907+ sys_sigreturn(regs);
3908+ else
3909+ sys_rt_sigreturn(regs);
3910+ return;
3911+ }
3912+ if (pc == 0xffff0f60UL) {
3913+ /*
3914+ * PaX: __kuser_cmpxchg64 emulation
3915+ */
3916+ // TODO
3917+ //regs->ARM_pc = regs->ARM_lr;
3918+ //return;
3919+ }
3920+ if (pc == 0xffff0fa0UL) {
3921+ /*
3922+ * PaX: __kuser_memory_barrier emulation
3923+ */
3924+ // dmb(); implied by the exception
3925+ regs->ARM_pc = regs->ARM_lr;
3926+ return;
3927+ }
3928+ if (pc == 0xffff0fc0UL) {
3929+ /*
3930+ * PaX: __kuser_cmpxchg emulation
3931+ */
3932+ // TODO
3933+ //regs->ARM_pc = regs->ARM_lr;
3934+ //return;
3935+ }
3936+ if (pc == 0xffff0fe0UL) {
3937+ /*
3938+ * PaX: __kuser_get_tls emulation
3939+ */
3940+ regs->ARM_r0 = current_thread_info()->tp_value[0];
3941+ regs->ARM_pc = regs->ARM_lr;
3942+ return;
3943+ }
3944+ }
3945+
3946+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3947+ else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
3948+ if (current->signal->curr_ip)
3949+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3950+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3951+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
3952+ else
3953+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
3954+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3955+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
3956+ goto die;
3957+ }
3958+#endif
3959+
3960+#ifdef CONFIG_PAX_REFCOUNT
3961+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
3962+ unsigned int bkpt;
3963+
3964+ if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
3965+ current->thread.error_code = ifsr;
3966+ current->thread.trap_no = 0;
3967+ pax_report_refcount_overflow(regs);
3968+ fixup_exception(regs);
3969+ return;
3970+ }
3971+ }
3972+#endif
3973
3974 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
3975 return;
3976
3977+die:
3978 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
3979 inf->name, ifsr, addr);
3980
3981diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
3982index cf08bdf..772656c 100644
3983--- a/arch/arm/mm/fault.h
3984+++ b/arch/arm/mm/fault.h
3985@@ -3,6 +3,7 @@
3986
3987 /*
3988 * Fault status register encodings. We steal bit 31 for our own purposes.
3989+ * Set when the FSR value is from an instruction fault.
3990 */
3991 #define FSR_LNX_PF (1 << 31)
3992 #define FSR_WRITE (1 << 11)
3993@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
3994 }
3995 #endif
3996
3997+/* valid for LPAE and !LPAE */
3998+static inline int is_xn_fault(unsigned int fsr)
3999+{
4000+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
4001+}
4002+
4003+static inline int is_domain_fault(unsigned int fsr)
4004+{
4005+ return ((fsr_fs(fsr) & 0xD) == 0x9);
4006+}
4007+
4008 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4009 unsigned long search_exception_table(unsigned long addr);
4010
4011diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4012index 15225d8..25e2e3c 100644
4013--- a/arch/arm/mm/init.c
4014+++ b/arch/arm/mm/init.c
4015@@ -30,6 +30,8 @@
4016 #include <asm/setup.h>
4017 #include <asm/tlb.h>
4018 #include <asm/fixmap.h>
4019+#include <asm/system_info.h>
4020+#include <asm/cp15.h>
4021
4022 #include <asm/mach/arch.h>
4023 #include <asm/mach/map.h>
4024@@ -683,7 +685,46 @@ void free_initmem(void)
4025 {
4026 #ifdef CONFIG_HAVE_TCM
4027 extern char __tcm_start, __tcm_end;
4028+#endif
4029
4030+#ifdef CONFIG_PAX_KERNEXEC
4031+ unsigned long addr;
4032+ pgd_t *pgd;
4033+ pud_t *pud;
4034+ pmd_t *pmd;
4035+ int cpu_arch = cpu_architecture();
4036+ unsigned int cr = get_cr();
4037+
4038+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4039+ /* make pages tables, etc before .text NX */
4040+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4041+ pgd = pgd_offset_k(addr);
4042+ pud = pud_offset(pgd, addr);
4043+ pmd = pmd_offset(pud, addr);
4044+ __section_update(pmd, addr, PMD_SECT_XN);
4045+ }
4046+ /* make init NX */
4047+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4048+ pgd = pgd_offset_k(addr);
4049+ pud = pud_offset(pgd, addr);
4050+ pmd = pmd_offset(pud, addr);
4051+ __section_update(pmd, addr, PMD_SECT_XN);
4052+ }
4053+ /* make kernel code/rodata RX */
4054+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4055+ pgd = pgd_offset_k(addr);
4056+ pud = pud_offset(pgd, addr);
4057+ pmd = pmd_offset(pud, addr);
4058+#ifdef CONFIG_ARM_LPAE
4059+ __section_update(pmd, addr, PMD_SECT_RDONLY);
4060+#else
4061+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4062+#endif
4063+ }
4064+ }
4065+#endif
4066+
4067+#ifdef CONFIG_HAVE_TCM
4068 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4069 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4070 #endif
4071diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4072index f123d6e..04bf569 100644
4073--- a/arch/arm/mm/ioremap.c
4074+++ b/arch/arm/mm/ioremap.c
4075@@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4076 unsigned int mtype;
4077
4078 if (cached)
4079- mtype = MT_MEMORY;
4080+ mtype = MT_MEMORY_RX;
4081 else
4082- mtype = MT_MEMORY_NONCACHED;
4083+ mtype = MT_MEMORY_NONCACHED_RX;
4084
4085 return __arm_ioremap_caller(phys_addr, size, mtype,
4086 __builtin_return_address(0));
4087diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4088index 0c63562..7128a90 100644
4089--- a/arch/arm/mm/mmap.c
4090+++ b/arch/arm/mm/mmap.c
4091@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4092 struct vm_area_struct *vma;
4093 int do_align = 0;
4094 int aliasing = cache_is_vipt_aliasing();
4095+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4096 struct vm_unmapped_area_info info;
4097
4098 /*
4099@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4100 if (len > TASK_SIZE)
4101 return -ENOMEM;
4102
4103+#ifdef CONFIG_PAX_RANDMMAP
4104+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4105+#endif
4106+
4107 if (addr) {
4108 if (do_align)
4109 addr = COLOUR_ALIGN(addr, pgoff);
4110@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4111 addr = PAGE_ALIGN(addr);
4112
4113 vma = find_vma(mm, addr);
4114- if (TASK_SIZE - len >= addr &&
4115- (!vma || addr + len <= vma->vm_start))
4116+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4117 return addr;
4118 }
4119
4120@@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4121 info.high_limit = TASK_SIZE;
4122 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4123 info.align_offset = pgoff << PAGE_SHIFT;
4124+ info.threadstack_offset = offset;
4125 return vm_unmapped_area(&info);
4126 }
4127
4128@@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4129 unsigned long addr = addr0;
4130 int do_align = 0;
4131 int aliasing = cache_is_vipt_aliasing();
4132+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4133 struct vm_unmapped_area_info info;
4134
4135 /*
4136@@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4137 return addr;
4138 }
4139
4140+#ifdef CONFIG_PAX_RANDMMAP
4141+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4142+#endif
4143+
4144 /* requesting a specific address */
4145 if (addr) {
4146 if (do_align)
4147@@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4148 else
4149 addr = PAGE_ALIGN(addr);
4150 vma = find_vma(mm, addr);
4151- if (TASK_SIZE - len >= addr &&
4152- (!vma || addr + len <= vma->vm_start))
4153+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4154 return addr;
4155 }
4156
4157@@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4158 info.high_limit = mm->mmap_base;
4159 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4160 info.align_offset = pgoff << PAGE_SHIFT;
4161+ info.threadstack_offset = offset;
4162 addr = vm_unmapped_area(&info);
4163
4164 /*
4165@@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4166 {
4167 unsigned long random_factor = 0UL;
4168
4169+#ifdef CONFIG_PAX_RANDMMAP
4170+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4171+#endif
4172+
4173 /* 8 bits of randomness in 20 address space bits */
4174 if ((current->flags & PF_RANDOMIZE) &&
4175 !(current->personality & ADDR_NO_RANDOMIZE))
4176@@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4177
4178 if (mmap_is_legacy()) {
4179 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4180+
4181+#ifdef CONFIG_PAX_RANDMMAP
4182+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4183+ mm->mmap_base += mm->delta_mmap;
4184+#endif
4185+
4186 mm->get_unmapped_area = arch_get_unmapped_area;
4187 } else {
4188 mm->mmap_base = mmap_base(random_factor);
4189+
4190+#ifdef CONFIG_PAX_RANDMMAP
4191+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4192+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4193+#endif
4194+
4195 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4196 }
4197 }
4198diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4199index 53cdbd3..670f177 100644
4200--- a/arch/arm/mm/mmu.c
4201+++ b/arch/arm/mm/mmu.c
4202@@ -36,6 +36,22 @@
4203 #include "mm.h"
4204 #include "tcm.h"
4205
4206+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4207+void modify_domain(unsigned int dom, unsigned int type)
4208+{
4209+ struct thread_info *thread = current_thread_info();
4210+ unsigned int domain = thread->cpu_domain;
4211+ /*
4212+ * DOMAIN_MANAGER might be defined to some other value,
4213+ * use the arch-defined constant
4214+ */
4215+ domain &= ~domain_val(dom, 3);
4216+ thread->cpu_domain = domain | domain_val(dom, type);
4217+ set_domain(thread->cpu_domain);
4218+}
4219+EXPORT_SYMBOL(modify_domain);
4220+#endif
4221+
4222 /*
4223 * empty_zero_page is a special page that is used for
4224 * zero-initialized data and COW.
4225@@ -228,10 +244,18 @@ __setup("noalign", noalign_setup);
4226
4227 #endif /* ifdef CONFIG_CPU_CP15 / else */
4228
4229-#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
4230+#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY
4231 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4232
4233-static struct mem_type mem_types[] = {
4234+#ifdef CONFIG_PAX_KERNEXEC
4235+#define L_PTE_KERNEXEC L_PTE_RDONLY
4236+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4237+#else
4238+#define L_PTE_KERNEXEC L_PTE_DIRTY
4239+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4240+#endif
4241+
4242+static struct mem_type mem_types[] __read_only = {
4243 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4244 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4245 L_PTE_SHARED,
4246@@ -260,16 +284,16 @@ static struct mem_type mem_types[] = {
4247 [MT_UNCACHED] = {
4248 .prot_pte = PROT_PTE_DEVICE,
4249 .prot_l1 = PMD_TYPE_TABLE,
4250- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4251+ .prot_sect = PROT_SECT_DEVICE,
4252 .domain = DOMAIN_IO,
4253 },
4254 [MT_CACHECLEAN] = {
4255- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4256+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4257 .domain = DOMAIN_KERNEL,
4258 },
4259 #ifndef CONFIG_ARM_LPAE
4260 [MT_MINICLEAN] = {
4261- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4262+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_RDONLY,
4263 .domain = DOMAIN_KERNEL,
4264 },
4265 #endif
4266@@ -277,36 +301,54 @@ static struct mem_type mem_types[] = {
4267 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4268 L_PTE_RDONLY,
4269 .prot_l1 = PMD_TYPE_TABLE,
4270- .domain = DOMAIN_USER,
4271+ .domain = DOMAIN_VECTORS,
4272 },
4273 [MT_HIGH_VECTORS] = {
4274 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4275 L_PTE_USER | L_PTE_RDONLY,
4276 .prot_l1 = PMD_TYPE_TABLE,
4277- .domain = DOMAIN_USER,
4278+ .domain = DOMAIN_VECTORS,
4279 },
4280- [MT_MEMORY] = {
4281+ [MT_MEMORY_RWX] = {
4282 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4283 .prot_l1 = PMD_TYPE_TABLE,
4284 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4285 .domain = DOMAIN_KERNEL,
4286 },
4287+ [MT_MEMORY_RW] = {
4288+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4289+ .prot_l1 = PMD_TYPE_TABLE,
4290+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4291+ .domain = DOMAIN_KERNEL,
4292+ },
4293+ [MT_MEMORY_RX] = {
4294+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4295+ .prot_l1 = PMD_TYPE_TABLE,
4296+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4297+ .domain = DOMAIN_KERNEL,
4298+ },
4299 [MT_ROM] = {
4300- .prot_sect = PMD_TYPE_SECT,
4301+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4302 .domain = DOMAIN_KERNEL,
4303 },
4304- [MT_MEMORY_NONCACHED] = {
4305+ [MT_MEMORY_NONCACHED_RW] = {
4306 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4307 L_PTE_MT_BUFFERABLE,
4308 .prot_l1 = PMD_TYPE_TABLE,
4309 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4310 .domain = DOMAIN_KERNEL,
4311 },
4312+ [MT_MEMORY_NONCACHED_RX] = {
4313+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4314+ L_PTE_MT_BUFFERABLE,
4315+ .prot_l1 = PMD_TYPE_TABLE,
4316+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4317+ .domain = DOMAIN_KERNEL,
4318+ },
4319 [MT_MEMORY_DTCM] = {
4320- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4321- L_PTE_XN,
4322+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4323 .prot_l1 = PMD_TYPE_TABLE,
4324- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4325+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4326 .domain = DOMAIN_KERNEL,
4327 },
4328 [MT_MEMORY_ITCM] = {
4329@@ -316,10 +358,10 @@ static struct mem_type mem_types[] = {
4330 },
4331 [MT_MEMORY_SO] = {
4332 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4333- L_PTE_MT_UNCACHED | L_PTE_XN,
4334+ L_PTE_MT_UNCACHED,
4335 .prot_l1 = PMD_TYPE_TABLE,
4336 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
4337- PMD_SECT_UNCACHED | PMD_SECT_XN,
4338+ PMD_SECT_UNCACHED,
4339 .domain = DOMAIN_KERNEL,
4340 },
4341 [MT_MEMORY_DMA_READY] = {
4342@@ -405,9 +447,35 @@ static void __init build_mem_type_table(void)
4343 * to prevent speculative instruction fetches.
4344 */
4345 mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
4346+ mem_types[MT_DEVICE].prot_pte |= L_PTE_XN;
4347 mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
4348+ mem_types[MT_DEVICE_NONSHARED].prot_pte |= L_PTE_XN;
4349 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
4350+ mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_XN;
4351 mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
4352+ mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_XN;
4353+
4354+ /* Mark other regions on ARMv6+ as execute-never */
4355+
4356+#ifdef CONFIG_PAX_KERNEXEC
4357+ mem_types[MT_UNCACHED].prot_sect |= PMD_SECT_XN;
4358+ mem_types[MT_UNCACHED].prot_pte |= L_PTE_XN;
4359+ mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_XN;
4360+ mem_types[MT_CACHECLEAN].prot_pte |= L_PTE_XN;
4361+#ifndef CONFIG_ARM_LPAE
4362+ mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_XN;
4363+ mem_types[MT_MINICLEAN].prot_pte |= L_PTE_XN;
4364+#endif
4365+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
4366+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_XN;
4367+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_XN;
4368+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= PMD_SECT_XN;
4369+ mem_types[MT_MEMORY_DTCM].prot_sect |= PMD_SECT_XN;
4370+ mem_types[MT_MEMORY_DTCM].prot_pte |= L_PTE_XN;
4371+#endif
4372+
4373+ mem_types[MT_MEMORY_SO].prot_sect |= PMD_SECT_XN;
4374+ mem_types[MT_MEMORY_SO].prot_pte |= L_PTE_XN;
4375 }
4376 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4377 /*
4378@@ -468,6 +536,9 @@ static void __init build_mem_type_table(void)
4379 * from SVC mode and no access from userspace.
4380 */
4381 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4382+#ifdef CONFIG_PAX_KERNEXEC
4383+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4384+#endif
4385 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4386 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4387 #endif
4388@@ -485,11 +556,17 @@ static void __init build_mem_type_table(void)
4389 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4390 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4391 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4392- mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
4393- mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
4394+ mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4395+ mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4396+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4397+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4398+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4399+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4400 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4401- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
4402- mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
4403+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_S;
4404+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= L_PTE_SHARED;
4405+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_S;
4406+ mem_types[MT_MEMORY_NONCACHED_RX].prot_pte |= L_PTE_SHARED;
4407 }
4408 }
4409
4410@@ -500,15 +577,20 @@ static void __init build_mem_type_table(void)
4411 if (cpu_arch >= CPU_ARCH_ARMv6) {
4412 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4413 /* Non-cacheable Normal is XCB = 001 */
4414- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4415+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4416+ PMD_SECT_BUFFERED;
4417+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4418 PMD_SECT_BUFFERED;
4419 } else {
4420 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4421- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4422+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4423+ PMD_SECT_TEX(1);
4424+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4425 PMD_SECT_TEX(1);
4426 }
4427 } else {
4428- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4429+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_BUFFERABLE;
4430+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_BUFFERABLE;
4431 }
4432
4433 #ifdef CONFIG_ARM_LPAE
4434@@ -524,6 +606,8 @@ static void __init build_mem_type_table(void)
4435 vecs_pgprot |= PTE_EXT_AF;
4436 #endif
4437
4438+ user_pgprot |= __supported_pte_mask;
4439+
4440 for (i = 0; i < 16; i++) {
4441 pteval_t v = pgprot_val(protection_map[i]);
4442 protection_map[i] = __pgprot(v | user_pgprot);
4443@@ -541,10 +625,15 @@ static void __init build_mem_type_table(void)
4444
4445 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4446 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4447- mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
4448- mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
4449+ mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4450+ mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4451+ mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4452+ mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4453+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4454+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4455 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4456- mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
4457+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= ecc_mask;
4458+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= ecc_mask;
4459 mem_types[MT_ROM].prot_sect |= cp->pmd;
4460
4461 switch (cp->pmd) {
4462@@ -1186,18 +1275,15 @@ void __init arm_mm_memblock_reserve(void)
4463 * called function. This means you can't use any function or debugging
4464 * method which may touch any device, otherwise the kernel _will_ crash.
4465 */
4466+
4467+static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4468+
4469 static void __init devicemaps_init(struct machine_desc *mdesc)
4470 {
4471 struct map_desc map;
4472 unsigned long addr;
4473- void *vectors;
4474
4475- /*
4476- * Allocate the vector page early.
4477- */
4478- vectors = early_alloc(PAGE_SIZE * 2);
4479-
4480- early_trap_init(vectors);
4481+ early_trap_init(&vectors);
4482
4483 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4484 pmd_clear(pmd_off_k(addr));
4485@@ -1237,7 +1323,7 @@ static void __init devicemaps_init(struct machine_desc *mdesc)
4486 * location (0xffff0000). If we aren't using high-vectors, also
4487 * create a mapping at the low-vectors virtual address.
4488 */
4489- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4490+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4491 map.virtual = 0xffff0000;
4492 map.length = PAGE_SIZE;
4493 #ifdef CONFIG_KUSER_HELPERS
4494@@ -1309,8 +1395,39 @@ static void __init map_lowmem(void)
4495 map.pfn = __phys_to_pfn(start);
4496 map.virtual = __phys_to_virt(start);
4497 map.length = end - start;
4498- map.type = MT_MEMORY;
4499
4500+#ifdef CONFIG_PAX_KERNEXEC
4501+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4502+ struct map_desc kernel;
4503+ struct map_desc initmap;
4504+
4505+ /* when freeing initmem we will make this RW */
4506+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4507+ initmap.virtual = (unsigned long)__init_begin;
4508+ initmap.length = _sdata - __init_begin;
4509+ initmap.type = MT_MEMORY_RWX;
4510+ create_mapping(&initmap);
4511+
4512+ /* when freeing initmem we will make this RX */
4513+ kernel.pfn = __phys_to_pfn(__pa(_stext));
4514+ kernel.virtual = (unsigned long)_stext;
4515+ kernel.length = __init_begin - _stext;
4516+ kernel.type = MT_MEMORY_RWX;
4517+ create_mapping(&kernel);
4518+
4519+ if (map.virtual < (unsigned long)_stext) {
4520+ map.length = (unsigned long)_stext - map.virtual;
4521+ map.type = MT_MEMORY_RWX;
4522+ create_mapping(&map);
4523+ }
4524+
4525+ map.pfn = __phys_to_pfn(__pa(_sdata));
4526+ map.virtual = (unsigned long)_sdata;
4527+ map.length = end - __pa(_sdata);
4528+ }
4529+#endif
4530+
4531+ map.type = MT_MEMORY_RW;
4532 create_mapping(&map);
4533 }
4534 }
4535diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4536index a5bc92d..0bb4730 100644
4537--- a/arch/arm/plat-omap/sram.c
4538+++ b/arch/arm/plat-omap/sram.c
4539@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4540 * Looks like we need to preserve some bootloader code at the
4541 * beginning of SRAM for jumping to flash for reboot to work...
4542 */
4543+ pax_open_kernel();
4544 memset_io(omap_sram_base + omap_sram_skip, 0,
4545 omap_sram_size - omap_sram_skip);
4546+ pax_close_kernel();
4547 }
4548diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4549index ce6d763..cfea917 100644
4550--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4551+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4552@@ -47,7 +47,7 @@ struct samsung_dma_ops {
4553 int (*started)(unsigned ch);
4554 int (*flush)(unsigned ch);
4555 int (*stop)(unsigned ch);
4556-};
4557+} __no_const;
4558
4559 extern void *samsung_dmadev_get_ops(void);
4560 extern void *s3c_dma_get_ops(void);
4561diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4562index c3a58a1..78fbf54 100644
4563--- a/arch/avr32/include/asm/cache.h
4564+++ b/arch/avr32/include/asm/cache.h
4565@@ -1,8 +1,10 @@
4566 #ifndef __ASM_AVR32_CACHE_H
4567 #define __ASM_AVR32_CACHE_H
4568
4569+#include <linux/const.h>
4570+
4571 #define L1_CACHE_SHIFT 5
4572-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4573+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4574
4575 /*
4576 * Memory returned by kmalloc() may be used for DMA, so we must make
4577diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4578index d232888..87c8df1 100644
4579--- a/arch/avr32/include/asm/elf.h
4580+++ b/arch/avr32/include/asm/elf.h
4581@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4582 the loader. We need to make sure that it is out of the way of the program
4583 that it will "exec", and that there is sufficient room for the brk. */
4584
4585-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4586+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4587
4588+#ifdef CONFIG_PAX_ASLR
4589+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4590+
4591+#define PAX_DELTA_MMAP_LEN 15
4592+#define PAX_DELTA_STACK_LEN 15
4593+#endif
4594
4595 /* This yields a mask that user programs can use to figure out what
4596 instruction set this CPU supports. This could be done in user space,
4597diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4598index 479330b..53717a8 100644
4599--- a/arch/avr32/include/asm/kmap_types.h
4600+++ b/arch/avr32/include/asm/kmap_types.h
4601@@ -2,9 +2,9 @@
4602 #define __ASM_AVR32_KMAP_TYPES_H
4603
4604 #ifdef CONFIG_DEBUG_HIGHMEM
4605-# define KM_TYPE_NR 29
4606+# define KM_TYPE_NR 30
4607 #else
4608-# define KM_TYPE_NR 14
4609+# define KM_TYPE_NR 15
4610 #endif
4611
4612 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4613diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4614index b2f2d2d..d1c85cb 100644
4615--- a/arch/avr32/mm/fault.c
4616+++ b/arch/avr32/mm/fault.c
4617@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4618
4619 int exception_trace = 1;
4620
4621+#ifdef CONFIG_PAX_PAGEEXEC
4622+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4623+{
4624+ unsigned long i;
4625+
4626+ printk(KERN_ERR "PAX: bytes at PC: ");
4627+ for (i = 0; i < 20; i++) {
4628+ unsigned char c;
4629+ if (get_user(c, (unsigned char *)pc+i))
4630+ printk(KERN_CONT "???????? ");
4631+ else
4632+ printk(KERN_CONT "%02x ", c);
4633+ }
4634+ printk("\n");
4635+}
4636+#endif
4637+
4638 /*
4639 * This routine handles page faults. It determines the address and the
4640 * problem, and then passes it off to one of the appropriate routines.
4641@@ -174,6 +191,16 @@ bad_area:
4642 up_read(&mm->mmap_sem);
4643
4644 if (user_mode(regs)) {
4645+
4646+#ifdef CONFIG_PAX_PAGEEXEC
4647+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4648+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4649+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4650+ do_group_exit(SIGKILL);
4651+ }
4652+ }
4653+#endif
4654+
4655 if (exception_trace && printk_ratelimit())
4656 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4657 "sp %08lx ecr %lu\n",
4658diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4659index 568885a..f8008df 100644
4660--- a/arch/blackfin/include/asm/cache.h
4661+++ b/arch/blackfin/include/asm/cache.h
4662@@ -7,6 +7,7 @@
4663 #ifndef __ARCH_BLACKFIN_CACHE_H
4664 #define __ARCH_BLACKFIN_CACHE_H
4665
4666+#include <linux/const.h>
4667 #include <linux/linkage.h> /* for asmlinkage */
4668
4669 /*
4670@@ -14,7 +15,7 @@
4671 * Blackfin loads 32 bytes for cache
4672 */
4673 #define L1_CACHE_SHIFT 5
4674-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4675+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4676 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4677
4678 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4679diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4680index aea2718..3639a60 100644
4681--- a/arch/cris/include/arch-v10/arch/cache.h
4682+++ b/arch/cris/include/arch-v10/arch/cache.h
4683@@ -1,8 +1,9 @@
4684 #ifndef _ASM_ARCH_CACHE_H
4685 #define _ASM_ARCH_CACHE_H
4686
4687+#include <linux/const.h>
4688 /* Etrax 100LX have 32-byte cache-lines. */
4689-#define L1_CACHE_BYTES 32
4690 #define L1_CACHE_SHIFT 5
4691+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4692
4693 #endif /* _ASM_ARCH_CACHE_H */
4694diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4695index 7caf25d..ee65ac5 100644
4696--- a/arch/cris/include/arch-v32/arch/cache.h
4697+++ b/arch/cris/include/arch-v32/arch/cache.h
4698@@ -1,11 +1,12 @@
4699 #ifndef _ASM_CRIS_ARCH_CACHE_H
4700 #define _ASM_CRIS_ARCH_CACHE_H
4701
4702+#include <linux/const.h>
4703 #include <arch/hwregs/dma.h>
4704
4705 /* A cache-line is 32 bytes. */
4706-#define L1_CACHE_BYTES 32
4707 #define L1_CACHE_SHIFT 5
4708+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4709
4710 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4711
4712diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4713index b86329d..6709906 100644
4714--- a/arch/frv/include/asm/atomic.h
4715+++ b/arch/frv/include/asm/atomic.h
4716@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4717 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4718 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4719
4720+#define atomic64_read_unchecked(v) atomic64_read(v)
4721+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4722+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4723+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4724+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4725+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4726+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4727+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4728+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4729+
4730 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4731 {
4732 int c, old;
4733diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4734index 2797163..c2a401d 100644
4735--- a/arch/frv/include/asm/cache.h
4736+++ b/arch/frv/include/asm/cache.h
4737@@ -12,10 +12,11 @@
4738 #ifndef __ASM_CACHE_H
4739 #define __ASM_CACHE_H
4740
4741+#include <linux/const.h>
4742
4743 /* bytes per L1 cache line */
4744 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4745-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4746+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4747
4748 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4749 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4750diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4751index 43901f2..0d8b865 100644
4752--- a/arch/frv/include/asm/kmap_types.h
4753+++ b/arch/frv/include/asm/kmap_types.h
4754@@ -2,6 +2,6 @@
4755 #ifndef _ASM_KMAP_TYPES_H
4756 #define _ASM_KMAP_TYPES_H
4757
4758-#define KM_TYPE_NR 17
4759+#define KM_TYPE_NR 18
4760
4761 #endif
4762diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4763index 836f147..4cf23f5 100644
4764--- a/arch/frv/mm/elf-fdpic.c
4765+++ b/arch/frv/mm/elf-fdpic.c
4766@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4767 {
4768 struct vm_area_struct *vma;
4769 struct vm_unmapped_area_info info;
4770+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4771
4772 if (len > TASK_SIZE)
4773 return -ENOMEM;
4774@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4775 if (addr) {
4776 addr = PAGE_ALIGN(addr);
4777 vma = find_vma(current->mm, addr);
4778- if (TASK_SIZE - len >= addr &&
4779- (!vma || addr + len <= vma->vm_start))
4780+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4781 goto success;
4782 }
4783
4784@@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4785 info.high_limit = (current->mm->start_stack - 0x00200000);
4786 info.align_mask = 0;
4787 info.align_offset = 0;
4788+ info.threadstack_offset = offset;
4789 addr = vm_unmapped_area(&info);
4790 if (!(addr & ~PAGE_MASK))
4791 goto success;
4792diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4793index f4ca594..adc72fd6 100644
4794--- a/arch/hexagon/include/asm/cache.h
4795+++ b/arch/hexagon/include/asm/cache.h
4796@@ -21,9 +21,11 @@
4797 #ifndef __ASM_CACHE_H
4798 #define __ASM_CACHE_H
4799
4800+#include <linux/const.h>
4801+
4802 /* Bytes per L1 cache line */
4803-#define L1_CACHE_SHIFT (5)
4804-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4805+#define L1_CACHE_SHIFT 5
4806+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4807
4808 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4809 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4810diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4811index 6e6fe18..a6ae668 100644
4812--- a/arch/ia64/include/asm/atomic.h
4813+++ b/arch/ia64/include/asm/atomic.h
4814@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4815 #define atomic64_inc(v) atomic64_add(1, (v))
4816 #define atomic64_dec(v) atomic64_sub(1, (v))
4817
4818+#define atomic64_read_unchecked(v) atomic64_read(v)
4819+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4820+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4821+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4822+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4823+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4824+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4825+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4826+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4827+
4828 /* Atomic operations are already serializing */
4829 #define smp_mb__before_atomic_dec() barrier()
4830 #define smp_mb__after_atomic_dec() barrier()
4831diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4832index 988254a..e1ee885 100644
4833--- a/arch/ia64/include/asm/cache.h
4834+++ b/arch/ia64/include/asm/cache.h
4835@@ -1,6 +1,7 @@
4836 #ifndef _ASM_IA64_CACHE_H
4837 #define _ASM_IA64_CACHE_H
4838
4839+#include <linux/const.h>
4840
4841 /*
4842 * Copyright (C) 1998-2000 Hewlett-Packard Co
4843@@ -9,7 +10,7 @@
4844
4845 /* Bytes per L1 (data) cache line. */
4846 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4847-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4848+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4849
4850 #ifdef CONFIG_SMP
4851 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4852diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4853index 5a83c5c..4d7f553 100644
4854--- a/arch/ia64/include/asm/elf.h
4855+++ b/arch/ia64/include/asm/elf.h
4856@@ -42,6 +42,13 @@
4857 */
4858 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
4859
4860+#ifdef CONFIG_PAX_ASLR
4861+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
4862+
4863+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4864+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4865+#endif
4866+
4867 #define PT_IA_64_UNWIND 0x70000001
4868
4869 /* IA-64 relocations: */
4870diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
4871index 96a8d92..617a1cf 100644
4872--- a/arch/ia64/include/asm/pgalloc.h
4873+++ b/arch/ia64/include/asm/pgalloc.h
4874@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4875 pgd_val(*pgd_entry) = __pa(pud);
4876 }
4877
4878+static inline void
4879+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4880+{
4881+ pgd_populate(mm, pgd_entry, pud);
4882+}
4883+
4884 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4885 {
4886 return quicklist_alloc(0, GFP_KERNEL, NULL);
4887@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4888 pud_val(*pud_entry) = __pa(pmd);
4889 }
4890
4891+static inline void
4892+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4893+{
4894+ pud_populate(mm, pud_entry, pmd);
4895+}
4896+
4897 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
4898 {
4899 return quicklist_alloc(0, GFP_KERNEL, NULL);
4900diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
4901index 7935115..c0eca6a 100644
4902--- a/arch/ia64/include/asm/pgtable.h
4903+++ b/arch/ia64/include/asm/pgtable.h
4904@@ -12,7 +12,7 @@
4905 * David Mosberger-Tang <davidm@hpl.hp.com>
4906 */
4907
4908-
4909+#include <linux/const.h>
4910 #include <asm/mman.h>
4911 #include <asm/page.h>
4912 #include <asm/processor.h>
4913@@ -142,6 +142,17 @@
4914 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4915 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4916 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
4917+
4918+#ifdef CONFIG_PAX_PAGEEXEC
4919+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
4920+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4921+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4922+#else
4923+# define PAGE_SHARED_NOEXEC PAGE_SHARED
4924+# define PAGE_READONLY_NOEXEC PAGE_READONLY
4925+# define PAGE_COPY_NOEXEC PAGE_COPY
4926+#endif
4927+
4928 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
4929 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
4930 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
4931diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
4932index 54ff557..70c88b7 100644
4933--- a/arch/ia64/include/asm/spinlock.h
4934+++ b/arch/ia64/include/asm/spinlock.h
4935@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
4936 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
4937
4938 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
4939- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
4940+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
4941 }
4942
4943 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
4944diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
4945index 449c8c0..18965fb 100644
4946--- a/arch/ia64/include/asm/uaccess.h
4947+++ b/arch/ia64/include/asm/uaccess.h
4948@@ -240,12 +240,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
4949 static inline unsigned long
4950 __copy_to_user (void __user *to, const void *from, unsigned long count)
4951 {
4952+ if (count > INT_MAX)
4953+ return count;
4954+
4955+ if (!__builtin_constant_p(count))
4956+ check_object_size(from, count, true);
4957+
4958 return __copy_user(to, (__force void __user *) from, count);
4959 }
4960
4961 static inline unsigned long
4962 __copy_from_user (void *to, const void __user *from, unsigned long count)
4963 {
4964+ if (count > INT_MAX)
4965+ return count;
4966+
4967+ if (!__builtin_constant_p(count))
4968+ check_object_size(to, count, false);
4969+
4970 return __copy_user((__force void __user *) to, from, count);
4971 }
4972
4973@@ -255,10 +267,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4974 ({ \
4975 void __user *__cu_to = (to); \
4976 const void *__cu_from = (from); \
4977- long __cu_len = (n); \
4978+ unsigned long __cu_len = (n); \
4979 \
4980- if (__access_ok(__cu_to, __cu_len, get_fs())) \
4981+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
4982+ if (!__builtin_constant_p(n)) \
4983+ check_object_size(__cu_from, __cu_len, true); \
4984 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
4985+ } \
4986 __cu_len; \
4987 })
4988
4989@@ -266,11 +281,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4990 ({ \
4991 void *__cu_to = (to); \
4992 const void __user *__cu_from = (from); \
4993- long __cu_len = (n); \
4994+ unsigned long __cu_len = (n); \
4995 \
4996 __chk_user_ptr(__cu_from); \
4997- if (__access_ok(__cu_from, __cu_len, get_fs())) \
4998+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
4999+ if (!__builtin_constant_p(n)) \
5000+ check_object_size(__cu_to, __cu_len, false); \
5001 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5002+ } \
5003 __cu_len; \
5004 })
5005
5006diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5007index 24603be..948052d 100644
5008--- a/arch/ia64/kernel/module.c
5009+++ b/arch/ia64/kernel/module.c
5010@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5011 void
5012 module_free (struct module *mod, void *module_region)
5013 {
5014- if (mod && mod->arch.init_unw_table &&
5015- module_region == mod->module_init) {
5016+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5017 unw_remove_unwind_table(mod->arch.init_unw_table);
5018 mod->arch.init_unw_table = NULL;
5019 }
5020@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5021 }
5022
5023 static inline int
5024+in_init_rx (const struct module *mod, uint64_t addr)
5025+{
5026+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5027+}
5028+
5029+static inline int
5030+in_init_rw (const struct module *mod, uint64_t addr)
5031+{
5032+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5033+}
5034+
5035+static inline int
5036 in_init (const struct module *mod, uint64_t addr)
5037 {
5038- return addr - (uint64_t) mod->module_init < mod->init_size;
5039+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5040+}
5041+
5042+static inline int
5043+in_core_rx (const struct module *mod, uint64_t addr)
5044+{
5045+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5046+}
5047+
5048+static inline int
5049+in_core_rw (const struct module *mod, uint64_t addr)
5050+{
5051+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5052 }
5053
5054 static inline int
5055 in_core (const struct module *mod, uint64_t addr)
5056 {
5057- return addr - (uint64_t) mod->module_core < mod->core_size;
5058+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5059 }
5060
5061 static inline int
5062@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5063 break;
5064
5065 case RV_BDREL:
5066- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5067+ if (in_init_rx(mod, val))
5068+ val -= (uint64_t) mod->module_init_rx;
5069+ else if (in_init_rw(mod, val))
5070+ val -= (uint64_t) mod->module_init_rw;
5071+ else if (in_core_rx(mod, val))
5072+ val -= (uint64_t) mod->module_core_rx;
5073+ else if (in_core_rw(mod, val))
5074+ val -= (uint64_t) mod->module_core_rw;
5075 break;
5076
5077 case RV_LTV:
5078@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5079 * addresses have been selected...
5080 */
5081 uint64_t gp;
5082- if (mod->core_size > MAX_LTOFF)
5083+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5084 /*
5085 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5086 * at the end of the module.
5087 */
5088- gp = mod->core_size - MAX_LTOFF / 2;
5089+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5090 else
5091- gp = mod->core_size / 2;
5092- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5093+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5094+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5095 mod->arch.gp = gp;
5096 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5097 }
5098diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5099index ab33328..f39506c 100644
5100--- a/arch/ia64/kernel/palinfo.c
5101+++ b/arch/ia64/kernel/palinfo.c
5102@@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5103 return NOTIFY_OK;
5104 }
5105
5106-static struct notifier_block __refdata palinfo_cpu_notifier =
5107+static struct notifier_block palinfo_cpu_notifier =
5108 {
5109 .notifier_call = palinfo_cpu_callback,
5110 .priority = 0,
5111diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5112index 41e33f8..65180b2 100644
5113--- a/arch/ia64/kernel/sys_ia64.c
5114+++ b/arch/ia64/kernel/sys_ia64.c
5115@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5116 unsigned long align_mask = 0;
5117 struct mm_struct *mm = current->mm;
5118 struct vm_unmapped_area_info info;
5119+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5120
5121 if (len > RGN_MAP_LIMIT)
5122 return -ENOMEM;
5123@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5124 if (REGION_NUMBER(addr) == RGN_HPAGE)
5125 addr = 0;
5126 #endif
5127+
5128+#ifdef CONFIG_PAX_RANDMMAP
5129+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5130+ addr = mm->free_area_cache;
5131+ else
5132+#endif
5133+
5134 if (!addr)
5135 addr = TASK_UNMAPPED_BASE;
5136
5137@@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5138 info.high_limit = TASK_SIZE;
5139 info.align_mask = align_mask;
5140 info.align_offset = 0;
5141+ info.threadstack_offset = offset;
5142 return vm_unmapped_area(&info);
5143 }
5144
5145diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5146index 0ccb28f..8992469 100644
5147--- a/arch/ia64/kernel/vmlinux.lds.S
5148+++ b/arch/ia64/kernel/vmlinux.lds.S
5149@@ -198,7 +198,7 @@ SECTIONS {
5150 /* Per-cpu data: */
5151 . = ALIGN(PERCPU_PAGE_SIZE);
5152 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5153- __phys_per_cpu_start = __per_cpu_load;
5154+ __phys_per_cpu_start = per_cpu_load;
5155 /*
5156 * ensure percpu data fits
5157 * into percpu page size
5158diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5159index 6cf0341..d352594 100644
5160--- a/arch/ia64/mm/fault.c
5161+++ b/arch/ia64/mm/fault.c
5162@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5163 return pte_present(pte);
5164 }
5165
5166+#ifdef CONFIG_PAX_PAGEEXEC
5167+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5168+{
5169+ unsigned long i;
5170+
5171+ printk(KERN_ERR "PAX: bytes at PC: ");
5172+ for (i = 0; i < 8; i++) {
5173+ unsigned int c;
5174+ if (get_user(c, (unsigned int *)pc+i))
5175+ printk(KERN_CONT "???????? ");
5176+ else
5177+ printk(KERN_CONT "%08x ", c);
5178+ }
5179+ printk("\n");
5180+}
5181+#endif
5182+
5183 # define VM_READ_BIT 0
5184 # define VM_WRITE_BIT 1
5185 # define VM_EXEC_BIT 2
5186@@ -149,8 +166,21 @@ retry:
5187 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5188 goto bad_area;
5189
5190- if ((vma->vm_flags & mask) != mask)
5191+ if ((vma->vm_flags & mask) != mask) {
5192+
5193+#ifdef CONFIG_PAX_PAGEEXEC
5194+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5195+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5196+ goto bad_area;
5197+
5198+ up_read(&mm->mmap_sem);
5199+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5200+ do_group_exit(SIGKILL);
5201+ }
5202+#endif
5203+
5204 goto bad_area;
5205+ }
5206
5207 /*
5208 * If for any reason at all we couldn't handle the fault, make
5209diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5210index 76069c1..c2aa816 100644
5211--- a/arch/ia64/mm/hugetlbpage.c
5212+++ b/arch/ia64/mm/hugetlbpage.c
5213@@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5214 unsigned long pgoff, unsigned long flags)
5215 {
5216 struct vm_unmapped_area_info info;
5217+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5218
5219 if (len > RGN_MAP_LIMIT)
5220 return -ENOMEM;
5221@@ -172,6 +173,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5222 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5223 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5224 info.align_offset = 0;
5225+ info.threadstack_offset = offset;
5226 return vm_unmapped_area(&info);
5227 }
5228
5229diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5230index b6f7f43..c04320d 100644
5231--- a/arch/ia64/mm/init.c
5232+++ b/arch/ia64/mm/init.c
5233@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5234 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5235 vma->vm_end = vma->vm_start + PAGE_SIZE;
5236 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5237+
5238+#ifdef CONFIG_PAX_PAGEEXEC
5239+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5240+ vma->vm_flags &= ~VM_EXEC;
5241+
5242+#ifdef CONFIG_PAX_MPROTECT
5243+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
5244+ vma->vm_flags &= ~VM_MAYEXEC;
5245+#endif
5246+
5247+ }
5248+#endif
5249+
5250 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5251 down_write(&current->mm->mmap_sem);
5252 if (insert_vm_struct(current->mm, vma)) {
5253diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5254index 40b3ee9..8c2c112 100644
5255--- a/arch/m32r/include/asm/cache.h
5256+++ b/arch/m32r/include/asm/cache.h
5257@@ -1,8 +1,10 @@
5258 #ifndef _ASM_M32R_CACHE_H
5259 #define _ASM_M32R_CACHE_H
5260
5261+#include <linux/const.h>
5262+
5263 /* L1 cache line size */
5264 #define L1_CACHE_SHIFT 4
5265-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5266+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5267
5268 #endif /* _ASM_M32R_CACHE_H */
5269diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5270index 82abd15..d95ae5d 100644
5271--- a/arch/m32r/lib/usercopy.c
5272+++ b/arch/m32r/lib/usercopy.c
5273@@ -14,6 +14,9 @@
5274 unsigned long
5275 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5276 {
5277+ if ((long)n < 0)
5278+ return n;
5279+
5280 prefetch(from);
5281 if (access_ok(VERIFY_WRITE, to, n))
5282 __copy_user(to,from,n);
5283@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5284 unsigned long
5285 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5286 {
5287+ if ((long)n < 0)
5288+ return n;
5289+
5290 prefetchw(to);
5291 if (access_ok(VERIFY_READ, from, n))
5292 __copy_user_zeroing(to,from,n);
5293diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5294index 0395c51..5f26031 100644
5295--- a/arch/m68k/include/asm/cache.h
5296+++ b/arch/m68k/include/asm/cache.h
5297@@ -4,9 +4,11 @@
5298 #ifndef __ARCH_M68K_CACHE_H
5299 #define __ARCH_M68K_CACHE_H
5300
5301+#include <linux/const.h>
5302+
5303 /* bytes per L1 cache line */
5304 #define L1_CACHE_SHIFT 4
5305-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5306+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5307
5308 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5309
5310diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5311index 3c52fa6..11b2ad8 100644
5312--- a/arch/metag/mm/hugetlbpage.c
5313+++ b/arch/metag/mm/hugetlbpage.c
5314@@ -200,6 +200,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5315 info.high_limit = TASK_SIZE;
5316 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5317 info.align_offset = 0;
5318+ info.threadstack_offset = 0;
5319 return vm_unmapped_area(&info);
5320 }
5321
5322diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5323index 4efe96a..60e8699 100644
5324--- a/arch/microblaze/include/asm/cache.h
5325+++ b/arch/microblaze/include/asm/cache.h
5326@@ -13,11 +13,12 @@
5327 #ifndef _ASM_MICROBLAZE_CACHE_H
5328 #define _ASM_MICROBLAZE_CACHE_H
5329
5330+#include <linux/const.h>
5331 #include <asm/registers.h>
5332
5333 #define L1_CACHE_SHIFT 5
5334 /* word-granular cache in microblaze */
5335-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5336+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5337
5338 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5339
5340diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5341index 08b6079..8b554d2 100644
5342--- a/arch/mips/include/asm/atomic.h
5343+++ b/arch/mips/include/asm/atomic.h
5344@@ -21,15 +21,39 @@
5345 #include <asm/cmpxchg.h>
5346 #include <asm/war.h>
5347
5348+#ifdef CONFIG_GENERIC_ATOMIC64
5349+#include <asm-generic/atomic64.h>
5350+#endif
5351+
5352 #define ATOMIC_INIT(i) { (i) }
5353
5354+#ifdef CONFIG_64BIT
5355+#define _ASM_EXTABLE(from, to) \
5356+" .section __ex_table,\"a\"\n" \
5357+" .dword " #from ", " #to"\n" \
5358+" .previous\n"
5359+#else
5360+#define _ASM_EXTABLE(from, to) \
5361+" .section __ex_table,\"a\"\n" \
5362+" .word " #from ", " #to"\n" \
5363+" .previous\n"
5364+#endif
5365+
5366 /*
5367 * atomic_read - read atomic variable
5368 * @v: pointer of type atomic_t
5369 *
5370 * Atomically reads the value of @v.
5371 */
5372-#define atomic_read(v) (*(volatile int *)&(v)->counter)
5373+static inline int atomic_read(const atomic_t *v)
5374+{
5375+ return (*(volatile const int *) &v->counter);
5376+}
5377+
5378+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5379+{
5380+ return (*(volatile const int *) &v->counter);
5381+}
5382
5383 /*
5384 * atomic_set - set atomic variable
5385@@ -38,7 +62,15 @@
5386 *
5387 * Atomically sets the value of @v to @i.
5388 */
5389-#define atomic_set(v, i) ((v)->counter = (i))
5390+static inline void atomic_set(atomic_t *v, int i)
5391+{
5392+ v->counter = i;
5393+}
5394+
5395+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5396+{
5397+ v->counter = i;
5398+}
5399
5400 /*
5401 * atomic_add - add integer to atomic variable
5402@@ -47,7 +79,67 @@
5403 *
5404 * Atomically adds @i to @v.
5405 */
5406-static __inline__ void atomic_add(int i, atomic_t * v)
5407+static __inline__ void atomic_add(int i, atomic_t *v)
5408+{
5409+ int temp;
5410+
5411+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5412+ __asm__ __volatile__(
5413+ " .set mips3 \n"
5414+ "1: ll %0, %1 # atomic_add \n"
5415+#ifdef CONFIG_PAX_REFCOUNT
5416+ /* Exception on overflow. */
5417+ "2: add %0, %2 \n"
5418+#else
5419+ " addu %0, %2 \n"
5420+#endif
5421+ " sc %0, %1 \n"
5422+ " beqzl %0, 1b \n"
5423+#ifdef CONFIG_PAX_REFCOUNT
5424+ "3: \n"
5425+ _ASM_EXTABLE(2b, 3b)
5426+#endif
5427+ " .set mips0 \n"
5428+ : "=&r" (temp), "+m" (v->counter)
5429+ : "Ir" (i));
5430+ } else if (kernel_uses_llsc) {
5431+ __asm__ __volatile__(
5432+ " .set mips3 \n"
5433+ "1: ll %0, %1 # atomic_add \n"
5434+#ifdef CONFIG_PAX_REFCOUNT
5435+ /* Exception on overflow. */
5436+ "2: add %0, %2 \n"
5437+#else
5438+ " addu %0, %2 \n"
5439+#endif
5440+ " sc %0, %1 \n"
5441+ " beqz %0, 1b \n"
5442+#ifdef CONFIG_PAX_REFCOUNT
5443+ "3: \n"
5444+ _ASM_EXTABLE(2b, 3b)
5445+#endif
5446+ " .set mips0 \n"
5447+ : "=&r" (temp), "+m" (v->counter)
5448+ : "Ir" (i));
5449+ } else {
5450+ unsigned long flags;
5451+
5452+ raw_local_irq_save(flags);
5453+ __asm__ __volatile__(
5454+#ifdef CONFIG_PAX_REFCOUNT
5455+ /* Exception on overflow. */
5456+ "1: add %0, %1 \n"
5457+ "2: \n"
5458+ _ASM_EXTABLE(1b, 2b)
5459+#else
5460+ " addu %0, %1 \n"
5461+#endif
5462+ : "+r" (v->counter) : "Ir" (i));
5463+ raw_local_irq_restore(flags);
5464+ }
5465+}
5466+
5467+static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
5468 {
5469 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5470 int temp;
5471@@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
5472 *
5473 * Atomically subtracts @i from @v.
5474 */
5475-static __inline__ void atomic_sub(int i, atomic_t * v)
5476+static __inline__ void atomic_sub(int i, atomic_t *v)
5477+{
5478+ int temp;
5479+
5480+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5481+ __asm__ __volatile__(
5482+ " .set mips3 \n"
5483+ "1: ll %0, %1 # atomic64_sub \n"
5484+#ifdef CONFIG_PAX_REFCOUNT
5485+ /* Exception on overflow. */
5486+ "2: sub %0, %2 \n"
5487+#else
5488+ " subu %0, %2 \n"
5489+#endif
5490+ " sc %0, %1 \n"
5491+ " beqzl %0, 1b \n"
5492+#ifdef CONFIG_PAX_REFCOUNT
5493+ "3: \n"
5494+ _ASM_EXTABLE(2b, 3b)
5495+#endif
5496+ " .set mips0 \n"
5497+ : "=&r" (temp), "+m" (v->counter)
5498+ : "Ir" (i));
5499+ } else if (kernel_uses_llsc) {
5500+ __asm__ __volatile__(
5501+ " .set mips3 \n"
5502+ "1: ll %0, %1 # atomic64_sub \n"
5503+#ifdef CONFIG_PAX_REFCOUNT
5504+ /* Exception on overflow. */
5505+ "2: sub %0, %2 \n"
5506+#else
5507+ " subu %0, %2 \n"
5508+#endif
5509+ " sc %0, %1 \n"
5510+ " beqz %0, 1b \n"
5511+#ifdef CONFIG_PAX_REFCOUNT
5512+ "3: \n"
5513+ _ASM_EXTABLE(2b, 3b)
5514+#endif
5515+ " .set mips0 \n"
5516+ : "=&r" (temp), "+m" (v->counter)
5517+ : "Ir" (i));
5518+ } else {
5519+ unsigned long flags;
5520+
5521+ raw_local_irq_save(flags);
5522+ __asm__ __volatile__(
5523+#ifdef CONFIG_PAX_REFCOUNT
5524+ /* Exception on overflow. */
5525+ "1: sub %0, %1 \n"
5526+ "2: \n"
5527+ _ASM_EXTABLE(1b, 2b)
5528+#else
5529+ " subu %0, %1 \n"
5530+#endif
5531+ : "+r" (v->counter) : "Ir" (i));
5532+ raw_local_irq_restore(flags);
5533+ }
5534+}
5535+
5536+static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
5537 {
5538 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5539 int temp;
5540@@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
5541 /*
5542 * Same as above, but return the result value
5543 */
5544-static __inline__ int atomic_add_return(int i, atomic_t * v)
5545+static __inline__ int atomic_add_return(int i, atomic_t *v)
5546+{
5547+ int result;
5548+ int temp;
5549+
5550+ smp_mb__before_llsc();
5551+
5552+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5553+ __asm__ __volatile__(
5554+ " .set mips3 \n"
5555+ "1: ll %1, %2 # atomic_add_return \n"
5556+#ifdef CONFIG_PAX_REFCOUNT
5557+ "2: add %0, %1, %3 \n"
5558+#else
5559+ " addu %0, %1, %3 \n"
5560+#endif
5561+ " sc %0, %2 \n"
5562+ " beqzl %0, 1b \n"
5563+#ifdef CONFIG_PAX_REFCOUNT
5564+ " b 4f \n"
5565+ " .set noreorder \n"
5566+ "3: b 5f \n"
5567+ " move %0, %1 \n"
5568+ " .set reorder \n"
5569+ _ASM_EXTABLE(2b, 3b)
5570+#endif
5571+ "4: addu %0, %1, %3 \n"
5572+#ifdef CONFIG_PAX_REFCOUNT
5573+ "5: \n"
5574+#endif
5575+ " .set mips0 \n"
5576+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5577+ : "Ir" (i));
5578+ } else if (kernel_uses_llsc) {
5579+ __asm__ __volatile__(
5580+ " .set mips3 \n"
5581+ "1: ll %1, %2 # atomic_add_return \n"
5582+#ifdef CONFIG_PAX_REFCOUNT
5583+ "2: add %0, %1, %3 \n"
5584+#else
5585+ " addu %0, %1, %3 \n"
5586+#endif
5587+ " sc %0, %2 \n"
5588+ " bnez %0, 4f \n"
5589+ " b 1b \n"
5590+#ifdef CONFIG_PAX_REFCOUNT
5591+ " .set noreorder \n"
5592+ "3: b 5f \n"
5593+ " move %0, %1 \n"
5594+ " .set reorder \n"
5595+ _ASM_EXTABLE(2b, 3b)
5596+#endif
5597+ "4: addu %0, %1, %3 \n"
5598+#ifdef CONFIG_PAX_REFCOUNT
5599+ "5: \n"
5600+#endif
5601+ " .set mips0 \n"
5602+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5603+ : "Ir" (i));
5604+ } else {
5605+ unsigned long flags;
5606+
5607+ raw_local_irq_save(flags);
5608+ __asm__ __volatile__(
5609+ " lw %0, %1 \n"
5610+#ifdef CONFIG_PAX_REFCOUNT
5611+ /* Exception on overflow. */
5612+ "1: add %0, %2 \n"
5613+#else
5614+ " addu %0, %2 \n"
5615+#endif
5616+ " sw %0, %1 \n"
5617+#ifdef CONFIG_PAX_REFCOUNT
5618+ /* Note: Dest reg is not modified on overflow */
5619+ "2: \n"
5620+ _ASM_EXTABLE(1b, 2b)
5621+#endif
5622+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5623+ raw_local_irq_restore(flags);
5624+ }
5625+
5626+ smp_llsc_mb();
5627+
5628+ return result;
5629+}
5630+
5631+static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5632 {
5633 int result;
5634
5635@@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
5636 return result;
5637 }
5638
5639-static __inline__ int atomic_sub_return(int i, atomic_t * v)
5640+static __inline__ int atomic_sub_return(int i, atomic_t *v)
5641+{
5642+ int result;
5643+ int temp;
5644+
5645+ smp_mb__before_llsc();
5646+
5647+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5648+ __asm__ __volatile__(
5649+ " .set mips3 \n"
5650+ "1: ll %1, %2 # atomic_sub_return \n"
5651+#ifdef CONFIG_PAX_REFCOUNT
5652+ "2: sub %0, %1, %3 \n"
5653+#else
5654+ " subu %0, %1, %3 \n"
5655+#endif
5656+ " sc %0, %2 \n"
5657+ " beqzl %0, 1b \n"
5658+#ifdef CONFIG_PAX_REFCOUNT
5659+ " b 4f \n"
5660+ " .set noreorder \n"
5661+ "3: b 5f \n"
5662+ " move %0, %1 \n"
5663+ " .set reorder \n"
5664+ _ASM_EXTABLE(2b, 3b)
5665+#endif
5666+ "4: subu %0, %1, %3 \n"
5667+#ifdef CONFIG_PAX_REFCOUNT
5668+ "5: \n"
5669+#endif
5670+ " .set mips0 \n"
5671+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
5672+ : "Ir" (i), "m" (v->counter)
5673+ : "memory");
5674+ } else if (kernel_uses_llsc) {
5675+ __asm__ __volatile__(
5676+ " .set mips3 \n"
5677+ "1: ll %1, %2 # atomic_sub_return \n"
5678+#ifdef CONFIG_PAX_REFCOUNT
5679+ "2: sub %0, %1, %3 \n"
5680+#else
5681+ " subu %0, %1, %3 \n"
5682+#endif
5683+ " sc %0, %2 \n"
5684+ " bnez %0, 4f \n"
5685+ " b 1b \n"
5686+#ifdef CONFIG_PAX_REFCOUNT
5687+ " .set noreorder \n"
5688+ "3: b 5f \n"
5689+ " move %0, %1 \n"
5690+ " .set reorder \n"
5691+ _ASM_EXTABLE(2b, 3b)
5692+#endif
5693+ "4: subu %0, %1, %3 \n"
5694+#ifdef CONFIG_PAX_REFCOUNT
5695+ "5: \n"
5696+#endif
5697+ " .set mips0 \n"
5698+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5699+ : "Ir" (i));
5700+ } else {
5701+ unsigned long flags;
5702+
5703+ raw_local_irq_save(flags);
5704+ __asm__ __volatile__(
5705+ " lw %0, %1 \n"
5706+#ifdef CONFIG_PAX_REFCOUNT
5707+ /* Exception on overflow. */
5708+ "1: sub %0, %2 \n"
5709+#else
5710+ " subu %0, %2 \n"
5711+#endif
5712+ " sw %0, %1 \n"
5713+#ifdef CONFIG_PAX_REFCOUNT
5714+ /* Note: Dest reg is not modified on overflow */
5715+ "2: \n"
5716+ _ASM_EXTABLE(1b, 2b)
5717+#endif
5718+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5719+ raw_local_irq_restore(flags);
5720+ }
5721+
5722+ smp_llsc_mb();
5723+
5724+ return result;
5725+}
5726+static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
5727 {
5728 int result;
5729
5730@@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
5731 * Atomically test @v and subtract @i if @v is greater or equal than @i.
5732 * The function returns the old value of @v minus @i.
5733 */
5734-static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5735+static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
5736 {
5737 int result;
5738
5739@@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5740 return result;
5741 }
5742
5743-#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5744-#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
5745+static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
5746+{
5747+ return cmpxchg(&v->counter, old, new);
5748+}
5749+
5750+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
5751+ int new)
5752+{
5753+ return cmpxchg(&(v->counter), old, new);
5754+}
5755+
5756+static inline int atomic_xchg(atomic_t *v, int new)
5757+{
5758+ return xchg(&v->counter, new);
5759+}
5760+
5761+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5762+{
5763+ return xchg(&(v->counter), new);
5764+}
5765
5766 /**
5767 * __atomic_add_unless - add unless the number is a given value
5768@@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5769
5770 #define atomic_dec_return(v) atomic_sub_return(1, (v))
5771 #define atomic_inc_return(v) atomic_add_return(1, (v))
5772+static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5773+{
5774+ return atomic_add_return_unchecked(1, v);
5775+}
5776
5777 /*
5778 * atomic_sub_and_test - subtract value from variable and test result
5779@@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5780 * other cases.
5781 */
5782 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5783+static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5784+{
5785+ return atomic_add_return_unchecked(1, v) == 0;
5786+}
5787
5788 /*
5789 * atomic_dec_and_test - decrement by 1 and test
5790@@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5791 * Atomically increments @v by 1.
5792 */
5793 #define atomic_inc(v) atomic_add(1, (v))
5794+static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
5795+{
5796+ atomic_add_unchecked(1, v);
5797+}
5798
5799 /*
5800 * atomic_dec - decrement and test
5801@@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5802 * Atomically decrements @v by 1.
5803 */
5804 #define atomic_dec(v) atomic_sub(1, (v))
5805+static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
5806+{
5807+ atomic_sub_unchecked(1, v);
5808+}
5809
5810 /*
5811 * atomic_add_negative - add and test if negative
5812@@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5813 * @v: pointer of type atomic64_t
5814 *
5815 */
5816-#define atomic64_read(v) (*(volatile long *)&(v)->counter)
5817+static inline long atomic64_read(const atomic64_t *v)
5818+{
5819+ return (*(volatile const long *) &v->counter);
5820+}
5821+
5822+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5823+{
5824+ return (*(volatile const long *) &v->counter);
5825+}
5826
5827 /*
5828 * atomic64_set - set atomic variable
5829 * @v: pointer of type atomic64_t
5830 * @i: required value
5831 */
5832-#define atomic64_set(v, i) ((v)->counter = (i))
5833+static inline void atomic64_set(atomic64_t *v, long i)
5834+{
5835+ v->counter = i;
5836+}
5837+
5838+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5839+{
5840+ v->counter = i;
5841+}
5842
5843 /*
5844 * atomic64_add - add integer to atomic variable
5845@@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5846 *
5847 * Atomically adds @i to @v.
5848 */
5849-static __inline__ void atomic64_add(long i, atomic64_t * v)
5850+static __inline__ void atomic64_add(long i, atomic64_t *v)
5851+{
5852+ long temp;
5853+
5854+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5855+ __asm__ __volatile__(
5856+ " .set mips3 \n"
5857+ "1: lld %0, %1 # atomic64_add \n"
5858+#ifdef CONFIG_PAX_REFCOUNT
5859+ /* Exception on overflow. */
5860+ "2: dadd %0, %2 \n"
5861+#else
5862+ " daddu %0, %2 \n"
5863+#endif
5864+ " scd %0, %1 \n"
5865+ " beqzl %0, 1b \n"
5866+#ifdef CONFIG_PAX_REFCOUNT
5867+ "3: \n"
5868+ _ASM_EXTABLE(2b, 3b)
5869+#endif
5870+ " .set mips0 \n"
5871+ : "=&r" (temp), "+m" (v->counter)
5872+ : "Ir" (i));
5873+ } else if (kernel_uses_llsc) {
5874+ __asm__ __volatile__(
5875+ " .set mips3 \n"
5876+ "1: lld %0, %1 # atomic64_add \n"
5877+#ifdef CONFIG_PAX_REFCOUNT
5878+ /* Exception on overflow. */
5879+ "2: dadd %0, %2 \n"
5880+#else
5881+ " daddu %0, %2 \n"
5882+#endif
5883+ " scd %0, %1 \n"
5884+ " beqz %0, 1b \n"
5885+#ifdef CONFIG_PAX_REFCOUNT
5886+ "3: \n"
5887+ _ASM_EXTABLE(2b, 3b)
5888+#endif
5889+ " .set mips0 \n"
5890+ : "=&r" (temp), "+m" (v->counter)
5891+ : "Ir" (i));
5892+ } else {
5893+ unsigned long flags;
5894+
5895+ raw_local_irq_save(flags);
5896+ __asm__ __volatile__(
5897+#ifdef CONFIG_PAX_REFCOUNT
5898+ /* Exception on overflow. */
5899+ "1: dadd %0, %1 \n"
5900+ "2: \n"
5901+ _ASM_EXTABLE(1b, 2b)
5902+#else
5903+ " daddu %0, %1 \n"
5904+#endif
5905+ : "+r" (v->counter) : "Ir" (i));
5906+ raw_local_irq_restore(flags);
5907+ }
5908+}
5909+static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
5910 {
5911 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5912 long temp;
5913@@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
5914 *
5915 * Atomically subtracts @i from @v.
5916 */
5917-static __inline__ void atomic64_sub(long i, atomic64_t * v)
5918+static __inline__ void atomic64_sub(long i, atomic64_t *v)
5919+{
5920+ long temp;
5921+
5922+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5923+ __asm__ __volatile__(
5924+ " .set mips3 \n"
5925+ "1: lld %0, %1 # atomic64_sub \n"
5926+#ifdef CONFIG_PAX_REFCOUNT
5927+ /* Exception on overflow. */
5928+ "2: dsub %0, %2 \n"
5929+#else
5930+ " dsubu %0, %2 \n"
5931+#endif
5932+ " scd %0, %1 \n"
5933+ " beqzl %0, 1b \n"
5934+#ifdef CONFIG_PAX_REFCOUNT
5935+ "3: \n"
5936+ _ASM_EXTABLE(2b, 3b)
5937+#endif
5938+ " .set mips0 \n"
5939+ : "=&r" (temp), "+m" (v->counter)
5940+ : "Ir" (i));
5941+ } else if (kernel_uses_llsc) {
5942+ __asm__ __volatile__(
5943+ " .set mips3 \n"
5944+ "1: lld %0, %1 # atomic64_sub \n"
5945+#ifdef CONFIG_PAX_REFCOUNT
5946+ /* Exception on overflow. */
5947+ "2: dsub %0, %2 \n"
5948+#else
5949+ " dsubu %0, %2 \n"
5950+#endif
5951+ " scd %0, %1 \n"
5952+ " beqz %0, 1b \n"
5953+#ifdef CONFIG_PAX_REFCOUNT
5954+ "3: \n"
5955+ _ASM_EXTABLE(2b, 3b)
5956+#endif
5957+ " .set mips0 \n"
5958+ : "=&r" (temp), "+m" (v->counter)
5959+ : "Ir" (i));
5960+ } else {
5961+ unsigned long flags;
5962+
5963+ raw_local_irq_save(flags);
5964+ __asm__ __volatile__(
5965+#ifdef CONFIG_PAX_REFCOUNT
5966+ /* Exception on overflow. */
5967+ "1: dsub %0, %1 \n"
5968+ "2: \n"
5969+ _ASM_EXTABLE(1b, 2b)
5970+#else
5971+ " dsubu %0, %1 \n"
5972+#endif
5973+ : "+r" (v->counter) : "Ir" (i));
5974+ raw_local_irq_restore(flags);
5975+ }
5976+}
5977+
5978+static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
5979 {
5980 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5981 long temp;
5982@@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
5983 /*
5984 * Same as above, but return the result value
5985 */
5986-static __inline__ long atomic64_add_return(long i, atomic64_t * v)
5987+static __inline__ long atomic64_add_return(long i, atomic64_t *v)
5988+{
5989+ long result;
5990+ long temp;
5991+
5992+ smp_mb__before_llsc();
5993+
5994+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5995+ __asm__ __volatile__(
5996+ " .set mips3 \n"
5997+ "1: lld %1, %2 # atomic64_add_return \n"
5998+#ifdef CONFIG_PAX_REFCOUNT
5999+ "2: dadd %0, %1, %3 \n"
6000+#else
6001+ " daddu %0, %1, %3 \n"
6002+#endif
6003+ " scd %0, %2 \n"
6004+ " beqzl %0, 1b \n"
6005+#ifdef CONFIG_PAX_REFCOUNT
6006+ " b 4f \n"
6007+ " .set noreorder \n"
6008+ "3: b 5f \n"
6009+ " move %0, %1 \n"
6010+ " .set reorder \n"
6011+ _ASM_EXTABLE(2b, 3b)
6012+#endif
6013+ "4: daddu %0, %1, %3 \n"
6014+#ifdef CONFIG_PAX_REFCOUNT
6015+ "5: \n"
6016+#endif
6017+ " .set mips0 \n"
6018+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6019+ : "Ir" (i));
6020+ } else if (kernel_uses_llsc) {
6021+ __asm__ __volatile__(
6022+ " .set mips3 \n"
6023+ "1: lld %1, %2 # atomic64_add_return \n"
6024+#ifdef CONFIG_PAX_REFCOUNT
6025+ "2: dadd %0, %1, %3 \n"
6026+#else
6027+ " daddu %0, %1, %3 \n"
6028+#endif
6029+ " scd %0, %2 \n"
6030+ " bnez %0, 4f \n"
6031+ " b 1b \n"
6032+#ifdef CONFIG_PAX_REFCOUNT
6033+ " .set noreorder \n"
6034+ "3: b 5f \n"
6035+ " move %0, %1 \n"
6036+ " .set reorder \n"
6037+ _ASM_EXTABLE(2b, 3b)
6038+#endif
6039+ "4: daddu %0, %1, %3 \n"
6040+#ifdef CONFIG_PAX_REFCOUNT
6041+ "5: \n"
6042+#endif
6043+ " .set mips0 \n"
6044+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6045+ : "Ir" (i), "m" (v->counter)
6046+ : "memory");
6047+ } else {
6048+ unsigned long flags;
6049+
6050+ raw_local_irq_save(flags);
6051+ __asm__ __volatile__(
6052+ " ld %0, %1 \n"
6053+#ifdef CONFIG_PAX_REFCOUNT
6054+ /* Exception on overflow. */
6055+ "1: dadd %0, %2 \n"
6056+#else
6057+ " daddu %0, %2 \n"
6058+#endif
6059+ " sd %0, %1 \n"
6060+#ifdef CONFIG_PAX_REFCOUNT
6061+ /* Note: Dest reg is not modified on overflow */
6062+ "2: \n"
6063+ _ASM_EXTABLE(1b, 2b)
6064+#endif
6065+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6066+ raw_local_irq_restore(flags);
6067+ }
6068+
6069+ smp_llsc_mb();
6070+
6071+ return result;
6072+}
6073+static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6074 {
6075 long result;
6076
6077@@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6078 return result;
6079 }
6080
6081-static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6082+static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6083+{
6084+ long result;
6085+ long temp;
6086+
6087+ smp_mb__before_llsc();
6088+
6089+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6090+ long temp;
6091+
6092+ __asm__ __volatile__(
6093+ " .set mips3 \n"
6094+ "1: lld %1, %2 # atomic64_sub_return \n"
6095+#ifdef CONFIG_PAX_REFCOUNT
6096+ "2: dsub %0, %1, %3 \n"
6097+#else
6098+ " dsubu %0, %1, %3 \n"
6099+#endif
6100+ " scd %0, %2 \n"
6101+ " beqzl %0, 1b \n"
6102+#ifdef CONFIG_PAX_REFCOUNT
6103+ " b 4f \n"
6104+ " .set noreorder \n"
6105+ "3: b 5f \n"
6106+ " move %0, %1 \n"
6107+ " .set reorder \n"
6108+ _ASM_EXTABLE(2b, 3b)
6109+#endif
6110+ "4: dsubu %0, %1, %3 \n"
6111+#ifdef CONFIG_PAX_REFCOUNT
6112+ "5: \n"
6113+#endif
6114+ " .set mips0 \n"
6115+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6116+ : "Ir" (i), "m" (v->counter)
6117+ : "memory");
6118+ } else if (kernel_uses_llsc) {
6119+ __asm__ __volatile__(
6120+ " .set mips3 \n"
6121+ "1: lld %1, %2 # atomic64_sub_return \n"
6122+#ifdef CONFIG_PAX_REFCOUNT
6123+ "2: dsub %0, %1, %3 \n"
6124+#else
6125+ " dsubu %0, %1, %3 \n"
6126+#endif
6127+ " scd %0, %2 \n"
6128+ " bnez %0, 4f \n"
6129+ " b 1b \n"
6130+#ifdef CONFIG_PAX_REFCOUNT
6131+ " .set noreorder \n"
6132+ "3: b 5f \n"
6133+ " move %0, %1 \n"
6134+ " .set reorder \n"
6135+ _ASM_EXTABLE(2b, 3b)
6136+#endif
6137+ "4: dsubu %0, %1, %3 \n"
6138+#ifdef CONFIG_PAX_REFCOUNT
6139+ "5: \n"
6140+#endif
6141+ " .set mips0 \n"
6142+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6143+ : "Ir" (i), "m" (v->counter)
6144+ : "memory");
6145+ } else {
6146+ unsigned long flags;
6147+
6148+ raw_local_irq_save(flags);
6149+ __asm__ __volatile__(
6150+ " ld %0, %1 \n"
6151+#ifdef CONFIG_PAX_REFCOUNT
6152+ /* Exception on overflow. */
6153+ "1: dsub %0, %2 \n"
6154+#else
6155+ " dsubu %0, %2 \n"
6156+#endif
6157+ " sd %0, %1 \n"
6158+#ifdef CONFIG_PAX_REFCOUNT
6159+ /* Note: Dest reg is not modified on overflow */
6160+ "2: \n"
6161+ _ASM_EXTABLE(1b, 2b)
6162+#endif
6163+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6164+ raw_local_irq_restore(flags);
6165+ }
6166+
6167+ smp_llsc_mb();
6168+
6169+ return result;
6170+}
6171+
6172+static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6173 {
6174 long result;
6175
6176@@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6177 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6178 * The function returns the old value of @v minus @i.
6179 */
6180-static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6181+static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6182 {
6183 long result;
6184
6185@@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6186 return result;
6187 }
6188
6189-#define atomic64_cmpxchg(v, o, n) \
6190- ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6191-#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6192+static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6193+{
6194+ return cmpxchg(&v->counter, old, new);
6195+}
6196+
6197+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6198+ long new)
6199+{
6200+ return cmpxchg(&(v->counter), old, new);
6201+}
6202+
6203+static inline long atomic64_xchg(atomic64_t *v, long new)
6204+{
6205+ return xchg(&v->counter, new);
6206+}
6207+
6208+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6209+{
6210+ return xchg(&(v->counter), new);
6211+}
6212
6213 /**
6214 * atomic64_add_unless - add unless the number is a given value
6215@@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6216
6217 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6218 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6219+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6220
6221 /*
6222 * atomic64_sub_and_test - subtract value from variable and test result
6223@@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6224 * other cases.
6225 */
6226 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6227+#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6228
6229 /*
6230 * atomic64_dec_and_test - decrement by 1 and test
6231@@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6232 * Atomically increments @v by 1.
6233 */
6234 #define atomic64_inc(v) atomic64_add(1, (v))
6235+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6236
6237 /*
6238 * atomic64_dec - decrement and test
6239@@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6240 * Atomically decrements @v by 1.
6241 */
6242 #define atomic64_dec(v) atomic64_sub(1, (v))
6243+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6244
6245 /*
6246 * atomic64_add_negative - add and test if negative
6247diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6248index b4db69f..8f3b093 100644
6249--- a/arch/mips/include/asm/cache.h
6250+++ b/arch/mips/include/asm/cache.h
6251@@ -9,10 +9,11 @@
6252 #ifndef _ASM_CACHE_H
6253 #define _ASM_CACHE_H
6254
6255+#include <linux/const.h>
6256 #include <kmalloc.h>
6257
6258 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6259-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6260+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6261
6262 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6263 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6264diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6265index cf3ae24..238d22f 100644
6266--- a/arch/mips/include/asm/elf.h
6267+++ b/arch/mips/include/asm/elf.h
6268@@ -372,13 +372,16 @@ extern const char *__elf_platform;
6269 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6270 #endif
6271
6272+#ifdef CONFIG_PAX_ASLR
6273+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6274+
6275+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6276+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6277+#endif
6278+
6279 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6280 struct linux_binprm;
6281 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6282 int uses_interp);
6283
6284-struct mm_struct;
6285-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6286-#define arch_randomize_brk arch_randomize_brk
6287-
6288 #endif /* _ASM_ELF_H */
6289diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6290index c1f6afa..38cc6e9 100644
6291--- a/arch/mips/include/asm/exec.h
6292+++ b/arch/mips/include/asm/exec.h
6293@@ -12,6 +12,6 @@
6294 #ifndef _ASM_EXEC_H
6295 #define _ASM_EXEC_H
6296
6297-extern unsigned long arch_align_stack(unsigned long sp);
6298+#define arch_align_stack(x) ((x) & ~0xfUL)
6299
6300 #endif /* _ASM_EXEC_H */
6301diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6302index d44622c..64990d2 100644
6303--- a/arch/mips/include/asm/local.h
6304+++ b/arch/mips/include/asm/local.h
6305@@ -12,15 +12,25 @@ typedef struct
6306 atomic_long_t a;
6307 } local_t;
6308
6309+typedef struct {
6310+ atomic_long_unchecked_t a;
6311+} local_unchecked_t;
6312+
6313 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6314
6315 #define local_read(l) atomic_long_read(&(l)->a)
6316+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6317 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6318+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6319
6320 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6321+#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6322 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6323+#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6324 #define local_inc(l) atomic_long_inc(&(l)->a)
6325+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6326 #define local_dec(l) atomic_long_dec(&(l)->a)
6327+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6328
6329 /*
6330 * Same as above, but return the result value
6331@@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6332 return result;
6333 }
6334
6335+static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6336+{
6337+ unsigned long result;
6338+
6339+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6340+ unsigned long temp;
6341+
6342+ __asm__ __volatile__(
6343+ " .set mips3 \n"
6344+ "1:" __LL "%1, %2 # local_add_return \n"
6345+ " addu %0, %1, %3 \n"
6346+ __SC "%0, %2 \n"
6347+ " beqzl %0, 1b \n"
6348+ " addu %0, %1, %3 \n"
6349+ " .set mips0 \n"
6350+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6351+ : "Ir" (i), "m" (l->a.counter)
6352+ : "memory");
6353+ } else if (kernel_uses_llsc) {
6354+ unsigned long temp;
6355+
6356+ __asm__ __volatile__(
6357+ " .set mips3 \n"
6358+ "1:" __LL "%1, %2 # local_add_return \n"
6359+ " addu %0, %1, %3 \n"
6360+ __SC "%0, %2 \n"
6361+ " beqz %0, 1b \n"
6362+ " addu %0, %1, %3 \n"
6363+ " .set mips0 \n"
6364+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6365+ : "Ir" (i), "m" (l->a.counter)
6366+ : "memory");
6367+ } else {
6368+ unsigned long flags;
6369+
6370+ local_irq_save(flags);
6371+ result = l->a.counter;
6372+ result += i;
6373+ l->a.counter = result;
6374+ local_irq_restore(flags);
6375+ }
6376+
6377+ return result;
6378+}
6379+
6380 static __inline__ long local_sub_return(long i, local_t * l)
6381 {
6382 unsigned long result;
6383@@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6384
6385 #define local_cmpxchg(l, o, n) \
6386 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6387+#define local_cmpxchg_unchecked(l, o, n) \
6388+ ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6389 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6390
6391 /**
6392diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6393index f6be474..12ad554 100644
6394--- a/arch/mips/include/asm/page.h
6395+++ b/arch/mips/include/asm/page.h
6396@@ -95,7 +95,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6397 #ifdef CONFIG_CPU_MIPS32
6398 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6399 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6400- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6401+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6402 #else
6403 typedef struct { unsigned long long pte; } pte_t;
6404 #define pte_val(x) ((x).pte)
6405diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6406index 881d18b..cea38bc 100644
6407--- a/arch/mips/include/asm/pgalloc.h
6408+++ b/arch/mips/include/asm/pgalloc.h
6409@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6410 {
6411 set_pud(pud, __pud((unsigned long)pmd));
6412 }
6413+
6414+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6415+{
6416+ pud_populate(mm, pud, pmd);
6417+}
6418 #endif
6419
6420 /*
6421diff --git a/arch/mips/include/asm/smtc_proc.h b/arch/mips/include/asm/smtc_proc.h
6422index 25da651..ae2a259 100644
6423--- a/arch/mips/include/asm/smtc_proc.h
6424+++ b/arch/mips/include/asm/smtc_proc.h
6425@@ -18,6 +18,6 @@ extern struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6426
6427 /* Count of number of recoveries of "stolen" FPU access rights on 34K */
6428
6429-extern atomic_t smtc_fpu_recoveries;
6430+extern atomic_unchecked_t smtc_fpu_recoveries;
6431
6432 #endif /* __ASM_SMTC_PROC_H */
6433diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6434index 61215a3..213ee0e 100644
6435--- a/arch/mips/include/asm/thread_info.h
6436+++ b/arch/mips/include/asm/thread_info.h
6437@@ -116,6 +116,8 @@ static inline struct thread_info *current_thread_info(void)
6438 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
6439 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
6440 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
6441+/* li takes a 32bit immediate */
6442+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
6443 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
6444
6445 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6446@@ -132,20 +134,18 @@ static inline struct thread_info *current_thread_info(void)
6447 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
6448 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
6449 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
6450+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6451
6452-#define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6453- _TIF_SYSCALL_AUDIT)
6454+#define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
6455
6456 /* work to do in syscall_trace_leave() */
6457-#define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6458- _TIF_SYSCALL_AUDIT)
6459+#define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
6460
6461 /* work to do on interrupt/exception return */
6462 #define _TIF_WORK_MASK \
6463 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
6464 /* work to do on any return to u-space */
6465-#define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6466- _TIF_WORK_SYSCALL_EXIT)
6467+#define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
6468
6469 #endif /* __KERNEL__ */
6470
6471diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6472index 1188e00..41cf144 100644
6473--- a/arch/mips/kernel/binfmt_elfn32.c
6474+++ b/arch/mips/kernel/binfmt_elfn32.c
6475@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6476 #undef ELF_ET_DYN_BASE
6477 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6478
6479+#ifdef CONFIG_PAX_ASLR
6480+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6481+
6482+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6483+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6484+#endif
6485+
6486 #include <asm/processor.h>
6487 #include <linux/module.h>
6488 #include <linux/elfcore.h>
6489diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6490index 202e581..689ca79 100644
6491--- a/arch/mips/kernel/binfmt_elfo32.c
6492+++ b/arch/mips/kernel/binfmt_elfo32.c
6493@@ -56,6 +56,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6494 #undef ELF_ET_DYN_BASE
6495 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6496
6497+#ifdef CONFIG_PAX_ASLR
6498+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6499+
6500+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6501+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6502+#endif
6503+
6504 #include <asm/processor.h>
6505
6506 /*
6507diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6508index d1fea7a..45602ea 100644
6509--- a/arch/mips/kernel/irq.c
6510+++ b/arch/mips/kernel/irq.c
6511@@ -77,17 +77,17 @@ void ack_bad_irq(unsigned int irq)
6512 printk("unexpected IRQ # %d\n", irq);
6513 }
6514
6515-atomic_t irq_err_count;
6516+atomic_unchecked_t irq_err_count;
6517
6518 int arch_show_interrupts(struct seq_file *p, int prec)
6519 {
6520- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6521+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6522 return 0;
6523 }
6524
6525 asmlinkage void spurious_interrupt(void)
6526 {
6527- atomic_inc(&irq_err_count);
6528+ atomic_inc_unchecked(&irq_err_count);
6529 }
6530
6531 void __init init_IRQ(void)
6532diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6533index ddc7610..8c58f17 100644
6534--- a/arch/mips/kernel/process.c
6535+++ b/arch/mips/kernel/process.c
6536@@ -566,15 +566,3 @@ unsigned long get_wchan(struct task_struct *task)
6537 out:
6538 return pc;
6539 }
6540-
6541-/*
6542- * Don't forget that the stack pointer must be aligned on a 8 bytes
6543- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6544- */
6545-unsigned long arch_align_stack(unsigned long sp)
6546-{
6547- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6548- sp -= get_random_int() & ~PAGE_MASK;
6549-
6550- return sp & ALMASK;
6551-}
6552diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6553index 8ae1ebe..1bcbf47 100644
6554--- a/arch/mips/kernel/ptrace.c
6555+++ b/arch/mips/kernel/ptrace.c
6556@@ -529,6 +529,10 @@ static inline int audit_arch(void)
6557 return arch;
6558 }
6559
6560+#ifdef CONFIG_GRKERNSEC_SETXID
6561+extern void gr_delayed_cred_worker(void);
6562+#endif
6563+
6564 /*
6565 * Notification of system call entry/exit
6566 * - triggered by current->work.syscall_trace
6567@@ -540,6 +544,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
6568 /* do the secure computing check first */
6569 secure_computing_strict(regs->regs[2]);
6570
6571+#ifdef CONFIG_GRKERNSEC_SETXID
6572+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6573+ gr_delayed_cred_worker();
6574+#endif
6575+
6576 if (!(current->ptrace & PT_PTRACED))
6577 goto out;
6578
6579diff --git a/arch/mips/kernel/smtc-proc.c b/arch/mips/kernel/smtc-proc.c
6580index c10aa84..9ec2e60 100644
6581--- a/arch/mips/kernel/smtc-proc.c
6582+++ b/arch/mips/kernel/smtc-proc.c
6583@@ -31,7 +31,7 @@ unsigned long selfipis[NR_CPUS];
6584
6585 struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6586
6587-atomic_t smtc_fpu_recoveries;
6588+atomic_unchecked_t smtc_fpu_recoveries;
6589
6590 static int smtc_proc_show(struct seq_file *m, void *v)
6591 {
6592@@ -48,7 +48,7 @@ static int smtc_proc_show(struct seq_file *m, void *v)
6593 for(i = 0; i < NR_CPUS; i++)
6594 seq_printf(m, "%d: %ld\n", i, smtc_cpu_stats[i].selfipis);
6595 seq_printf(m, "%d Recoveries of \"stolen\" FPU\n",
6596- atomic_read(&smtc_fpu_recoveries));
6597+ atomic_read_unchecked(&smtc_fpu_recoveries));
6598 return 0;
6599 }
6600
6601@@ -73,7 +73,7 @@ void init_smtc_stats(void)
6602 smtc_cpu_stats[i].selfipis = 0;
6603 }
6604
6605- atomic_set(&smtc_fpu_recoveries, 0);
6606+ atomic_set_unchecked(&smtc_fpu_recoveries, 0);
6607
6608 proc_create("smtc", 0444, NULL, &smtc_proc_fops);
6609 }
6610diff --git a/arch/mips/kernel/smtc.c b/arch/mips/kernel/smtc.c
6611index dfc1b91..11a2c07 100644
6612--- a/arch/mips/kernel/smtc.c
6613+++ b/arch/mips/kernel/smtc.c
6614@@ -1359,7 +1359,7 @@ void smtc_soft_dump(void)
6615 }
6616 smtc_ipi_qdump();
6617 printk("%d Recoveries of \"stolen\" FPU\n",
6618- atomic_read(&smtc_fpu_recoveries));
6619+ atomic_read_unchecked(&smtc_fpu_recoveries));
6620 }
6621
6622
6623diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
6624index 84536bf..79caa4d 100644
6625--- a/arch/mips/kernel/sync-r4k.c
6626+++ b/arch/mips/kernel/sync-r4k.c
6627@@ -21,8 +21,8 @@
6628 #include <asm/mipsregs.h>
6629
6630 static atomic_t count_start_flag = ATOMIC_INIT(0);
6631-static atomic_t count_count_start = ATOMIC_INIT(0);
6632-static atomic_t count_count_stop = ATOMIC_INIT(0);
6633+static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
6634+static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
6635 static atomic_t count_reference = ATOMIC_INIT(0);
6636
6637 #define COUNTON 100
6638@@ -69,13 +69,13 @@ void synchronise_count_master(int cpu)
6639
6640 for (i = 0; i < NR_LOOPS; i++) {
6641 /* slaves loop on '!= 2' */
6642- while (atomic_read(&count_count_start) != 1)
6643+ while (atomic_read_unchecked(&count_count_start) != 1)
6644 mb();
6645- atomic_set(&count_count_stop, 0);
6646+ atomic_set_unchecked(&count_count_stop, 0);
6647 smp_wmb();
6648
6649 /* this lets the slaves write their count register */
6650- atomic_inc(&count_count_start);
6651+ atomic_inc_unchecked(&count_count_start);
6652
6653 /*
6654 * Everyone initialises count in the last loop:
6655@@ -86,11 +86,11 @@ void synchronise_count_master(int cpu)
6656 /*
6657 * Wait for all slaves to leave the synchronization point:
6658 */
6659- while (atomic_read(&count_count_stop) != 1)
6660+ while (atomic_read_unchecked(&count_count_stop) != 1)
6661 mb();
6662- atomic_set(&count_count_start, 0);
6663+ atomic_set_unchecked(&count_count_start, 0);
6664 smp_wmb();
6665- atomic_inc(&count_count_stop);
6666+ atomic_inc_unchecked(&count_count_stop);
6667 }
6668 /* Arrange for an interrupt in a short while */
6669 write_c0_compare(read_c0_count() + COUNTON);
6670@@ -131,8 +131,8 @@ void synchronise_count_slave(int cpu)
6671 initcount = atomic_read(&count_reference);
6672
6673 for (i = 0; i < NR_LOOPS; i++) {
6674- atomic_inc(&count_count_start);
6675- while (atomic_read(&count_count_start) != 2)
6676+ atomic_inc_unchecked(&count_count_start);
6677+ while (atomic_read_unchecked(&count_count_start) != 2)
6678 mb();
6679
6680 /*
6681@@ -141,8 +141,8 @@ void synchronise_count_slave(int cpu)
6682 if (i == NR_LOOPS-1)
6683 write_c0_count(initcount);
6684
6685- atomic_inc(&count_count_stop);
6686- while (atomic_read(&count_count_stop) != 2)
6687+ atomic_inc_unchecked(&count_count_stop);
6688+ while (atomic_read_unchecked(&count_count_stop) != 2)
6689 mb();
6690 }
6691 /* Arrange for an interrupt in a short while */
6692diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
6693index aec3408..74d79d3 100644
6694--- a/arch/mips/kernel/traps.c
6695+++ b/arch/mips/kernel/traps.c
6696@@ -683,7 +683,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
6697 siginfo_t info;
6698
6699 prev_state = exception_enter();
6700- die_if_kernel("Integer overflow", regs);
6701+ if (unlikely(!user_mode(regs))) {
6702+
6703+#ifdef CONFIG_PAX_REFCOUNT
6704+ if (fixup_exception(regs)) {
6705+ pax_report_refcount_overflow(regs);
6706+ exception_exit(prev_state);
6707+ return;
6708+ }
6709+#endif
6710+
6711+ die("Integer overflow", regs);
6712+ }
6713
6714 info.si_code = FPE_INTOVF;
6715 info.si_signo = SIGFPE;
6716diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
6717index 85df1cd..4f0a4de 100644
6718--- a/arch/mips/mm/fault.c
6719+++ b/arch/mips/mm/fault.c
6720@@ -28,6 +28,23 @@
6721 #include <asm/highmem.h> /* For VMALLOC_END */
6722 #include <linux/kdebug.h>
6723
6724+#ifdef CONFIG_PAX_PAGEEXEC
6725+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6726+{
6727+ unsigned long i;
6728+
6729+ printk(KERN_ERR "PAX: bytes at PC: ");
6730+ for (i = 0; i < 5; i++) {
6731+ unsigned int c;
6732+ if (get_user(c, (unsigned int *)pc+i))
6733+ printk(KERN_CONT "???????? ");
6734+ else
6735+ printk(KERN_CONT "%08x ", c);
6736+ }
6737+ printk("\n");
6738+}
6739+#endif
6740+
6741 /*
6742 * This routine handles page faults. It determines the address,
6743 * and the problem, and then passes it off to one of the appropriate
6744@@ -197,6 +214,14 @@ bad_area:
6745 bad_area_nosemaphore:
6746 /* User mode accesses just cause a SIGSEGV */
6747 if (user_mode(regs)) {
6748+
6749+#ifdef CONFIG_PAX_PAGEEXEC
6750+ if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
6751+ pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
6752+ do_group_exit(SIGKILL);
6753+ }
6754+#endif
6755+
6756 tsk->thread.cp0_badvaddr = address;
6757 tsk->thread.error_code = write;
6758 #if 0
6759diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
6760index f1baadd..8537544 100644
6761--- a/arch/mips/mm/mmap.c
6762+++ b/arch/mips/mm/mmap.c
6763@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6764 struct vm_area_struct *vma;
6765 unsigned long addr = addr0;
6766 int do_color_align;
6767+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6768 struct vm_unmapped_area_info info;
6769
6770 if (unlikely(len > TASK_SIZE))
6771@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6772 do_color_align = 1;
6773
6774 /* requesting a specific address */
6775+
6776+#ifdef CONFIG_PAX_RANDMMAP
6777+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
6778+#endif
6779+
6780 if (addr) {
6781 if (do_color_align)
6782 addr = COLOUR_ALIGN(addr, pgoff);
6783@@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6784 addr = PAGE_ALIGN(addr);
6785
6786 vma = find_vma(mm, addr);
6787- if (TASK_SIZE - len >= addr &&
6788- (!vma || addr + len <= vma->vm_start))
6789+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
6790 return addr;
6791 }
6792
6793 info.length = len;
6794 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
6795 info.align_offset = pgoff << PAGE_SHIFT;
6796+ info.threadstack_offset = offset;
6797
6798 if (dir == DOWN) {
6799 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
6800@@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6801 {
6802 unsigned long random_factor = 0UL;
6803
6804+#ifdef CONFIG_PAX_RANDMMAP
6805+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6806+#endif
6807+
6808 if (current->flags & PF_RANDOMIZE) {
6809 random_factor = get_random_int();
6810 random_factor = random_factor << PAGE_SHIFT;
6811@@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6812
6813 if (mmap_is_legacy()) {
6814 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
6815+
6816+#ifdef CONFIG_PAX_RANDMMAP
6817+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6818+ mm->mmap_base += mm->delta_mmap;
6819+#endif
6820+
6821 mm->get_unmapped_area = arch_get_unmapped_area;
6822 } else {
6823 mm->mmap_base = mmap_base(random_factor);
6824+
6825+#ifdef CONFIG_PAX_RANDMMAP
6826+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6827+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6828+#endif
6829+
6830 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6831 }
6832 }
6833
6834-static inline unsigned long brk_rnd(void)
6835-{
6836- unsigned long rnd = get_random_int();
6837-
6838- rnd = rnd << PAGE_SHIFT;
6839- /* 8MB for 32bit, 256MB for 64bit */
6840- if (TASK_IS_32BIT_ADDR)
6841- rnd = rnd & 0x7ffffful;
6842- else
6843- rnd = rnd & 0xffffffful;
6844-
6845- return rnd;
6846-}
6847-
6848-unsigned long arch_randomize_brk(struct mm_struct *mm)
6849-{
6850- unsigned long base = mm->brk;
6851- unsigned long ret;
6852-
6853- ret = PAGE_ALIGN(base + brk_rnd());
6854-
6855- if (ret < mm->brk)
6856- return mm->brk;
6857-
6858- return ret;
6859-}
6860-
6861 int __virt_addr_valid(const volatile void *kaddr)
6862 {
6863 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
6864diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
6865index a2358b4..7cead4f 100644
6866--- a/arch/mips/sgi-ip27/ip27-nmi.c
6867+++ b/arch/mips/sgi-ip27/ip27-nmi.c
6868@@ -187,9 +187,9 @@ void
6869 cont_nmi_dump(void)
6870 {
6871 #ifndef REAL_NMI_SIGNAL
6872- static atomic_t nmied_cpus = ATOMIC_INIT(0);
6873+ static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
6874
6875- atomic_inc(&nmied_cpus);
6876+ atomic_inc_unchecked(&nmied_cpus);
6877 #endif
6878 /*
6879 * Only allow 1 cpu to proceed
6880@@ -233,7 +233,7 @@ cont_nmi_dump(void)
6881 udelay(10000);
6882 }
6883 #else
6884- while (atomic_read(&nmied_cpus) != num_online_cpus());
6885+ while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
6886 #endif
6887
6888 /*
6889diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
6890index 967d144..db12197 100644
6891--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
6892+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
6893@@ -11,12 +11,14 @@
6894 #ifndef _ASM_PROC_CACHE_H
6895 #define _ASM_PROC_CACHE_H
6896
6897+#include <linux/const.h>
6898+
6899 /* L1 cache */
6900
6901 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
6902 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
6903-#define L1_CACHE_BYTES 16 /* bytes per entry */
6904 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
6905+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
6906 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
6907
6908 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
6909diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
6910index bcb5df2..84fabd2 100644
6911--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
6912+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
6913@@ -16,13 +16,15 @@
6914 #ifndef _ASM_PROC_CACHE_H
6915 #define _ASM_PROC_CACHE_H
6916
6917+#include <linux/const.h>
6918+
6919 /*
6920 * L1 cache
6921 */
6922 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
6923 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
6924-#define L1_CACHE_BYTES 32 /* bytes per entry */
6925 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
6926+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
6927 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
6928
6929 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
6930diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
6931index 4ce7a01..449202a 100644
6932--- a/arch/openrisc/include/asm/cache.h
6933+++ b/arch/openrisc/include/asm/cache.h
6934@@ -19,11 +19,13 @@
6935 #ifndef __ASM_OPENRISC_CACHE_H
6936 #define __ASM_OPENRISC_CACHE_H
6937
6938+#include <linux/const.h>
6939+
6940 /* FIXME: How can we replace these with values from the CPU...
6941 * they shouldn't be hard-coded!
6942 */
6943
6944-#define L1_CACHE_BYTES 16
6945 #define L1_CACHE_SHIFT 4
6946+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6947
6948 #endif /* __ASM_OPENRISC_CACHE_H */
6949diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
6950index 472886c..00e7df9 100644
6951--- a/arch/parisc/include/asm/atomic.h
6952+++ b/arch/parisc/include/asm/atomic.h
6953@@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
6954 return dec;
6955 }
6956
6957+#define atomic64_read_unchecked(v) atomic64_read(v)
6958+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
6959+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
6960+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
6961+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
6962+#define atomic64_inc_unchecked(v) atomic64_inc(v)
6963+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
6964+#define atomic64_dec_unchecked(v) atomic64_dec(v)
6965+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
6966+
6967 #endif /* !CONFIG_64BIT */
6968
6969
6970diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
6971index 47f11c7..3420df2 100644
6972--- a/arch/parisc/include/asm/cache.h
6973+++ b/arch/parisc/include/asm/cache.h
6974@@ -5,6 +5,7 @@
6975 #ifndef __ARCH_PARISC_CACHE_H
6976 #define __ARCH_PARISC_CACHE_H
6977
6978+#include <linux/const.h>
6979
6980 /*
6981 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
6982@@ -15,13 +16,13 @@
6983 * just ruin performance.
6984 */
6985 #ifdef CONFIG_PA20
6986-#define L1_CACHE_BYTES 64
6987 #define L1_CACHE_SHIFT 6
6988 #else
6989-#define L1_CACHE_BYTES 32
6990 #define L1_CACHE_SHIFT 5
6991 #endif
6992
6993+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6994+
6995 #ifndef __ASSEMBLY__
6996
6997 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6998diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
6999index ad2b503..bdf1651 100644
7000--- a/arch/parisc/include/asm/elf.h
7001+++ b/arch/parisc/include/asm/elf.h
7002@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7003
7004 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7005
7006+#ifdef CONFIG_PAX_ASLR
7007+#define PAX_ELF_ET_DYN_BASE 0x10000UL
7008+
7009+#define PAX_DELTA_MMAP_LEN 16
7010+#define PAX_DELTA_STACK_LEN 16
7011+#endif
7012+
7013 /* This yields a mask that user programs can use to figure out what
7014 instruction set this CPU supports. This could be done in user space,
7015 but it's not easy, and we've already done it here. */
7016diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7017index fc987a1..6e068ef 100644
7018--- a/arch/parisc/include/asm/pgalloc.h
7019+++ b/arch/parisc/include/asm/pgalloc.h
7020@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7021 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7022 }
7023
7024+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7025+{
7026+ pgd_populate(mm, pgd, pmd);
7027+}
7028+
7029 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7030 {
7031 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7032@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7033 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7034 #define pmd_free(mm, x) do { } while (0)
7035 #define pgd_populate(mm, pmd, pte) BUG()
7036+#define pgd_populate_kernel(mm, pmd, pte) BUG()
7037
7038 #endif
7039
7040diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7041index 34899b5..02dd060 100644
7042--- a/arch/parisc/include/asm/pgtable.h
7043+++ b/arch/parisc/include/asm/pgtable.h
7044@@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7045 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7046 #define PAGE_COPY PAGE_EXECREAD
7047 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7048+
7049+#ifdef CONFIG_PAX_PAGEEXEC
7050+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7051+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7052+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7053+#else
7054+# define PAGE_SHARED_NOEXEC PAGE_SHARED
7055+# define PAGE_COPY_NOEXEC PAGE_COPY
7056+# define PAGE_READONLY_NOEXEC PAGE_READONLY
7057+#endif
7058+
7059 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7060 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7061 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7062diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7063index e0a8235..ce2f1e1 100644
7064--- a/arch/parisc/include/asm/uaccess.h
7065+++ b/arch/parisc/include/asm/uaccess.h
7066@@ -245,10 +245,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7067 const void __user *from,
7068 unsigned long n)
7069 {
7070- int sz = __compiletime_object_size(to);
7071+ size_t sz = __compiletime_object_size(to);
7072 int ret = -EFAULT;
7073
7074- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7075+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7076 ret = __copy_from_user(to, from, n);
7077 else
7078 copy_from_user_overflow();
7079diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7080index 2a625fb..9908930 100644
7081--- a/arch/parisc/kernel/module.c
7082+++ b/arch/parisc/kernel/module.c
7083@@ -98,16 +98,38 @@
7084
7085 /* three functions to determine where in the module core
7086 * or init pieces the location is */
7087+static inline int in_init_rx(struct module *me, void *loc)
7088+{
7089+ return (loc >= me->module_init_rx &&
7090+ loc < (me->module_init_rx + me->init_size_rx));
7091+}
7092+
7093+static inline int in_init_rw(struct module *me, void *loc)
7094+{
7095+ return (loc >= me->module_init_rw &&
7096+ loc < (me->module_init_rw + me->init_size_rw));
7097+}
7098+
7099 static inline int in_init(struct module *me, void *loc)
7100 {
7101- return (loc >= me->module_init &&
7102- loc <= (me->module_init + me->init_size));
7103+ return in_init_rx(me, loc) || in_init_rw(me, loc);
7104+}
7105+
7106+static inline int in_core_rx(struct module *me, void *loc)
7107+{
7108+ return (loc >= me->module_core_rx &&
7109+ loc < (me->module_core_rx + me->core_size_rx));
7110+}
7111+
7112+static inline int in_core_rw(struct module *me, void *loc)
7113+{
7114+ return (loc >= me->module_core_rw &&
7115+ loc < (me->module_core_rw + me->core_size_rw));
7116 }
7117
7118 static inline int in_core(struct module *me, void *loc)
7119 {
7120- return (loc >= me->module_core &&
7121- loc <= (me->module_core + me->core_size));
7122+ return in_core_rx(me, loc) || in_core_rw(me, loc);
7123 }
7124
7125 static inline int in_local(struct module *me, void *loc)
7126@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7127 }
7128
7129 /* align things a bit */
7130- me->core_size = ALIGN(me->core_size, 16);
7131- me->arch.got_offset = me->core_size;
7132- me->core_size += gots * sizeof(struct got_entry);
7133+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7134+ me->arch.got_offset = me->core_size_rw;
7135+ me->core_size_rw += gots * sizeof(struct got_entry);
7136
7137- me->core_size = ALIGN(me->core_size, 16);
7138- me->arch.fdesc_offset = me->core_size;
7139- me->core_size += fdescs * sizeof(Elf_Fdesc);
7140+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7141+ me->arch.fdesc_offset = me->core_size_rw;
7142+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7143
7144 me->arch.got_max = gots;
7145 me->arch.fdesc_max = fdescs;
7146@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7147
7148 BUG_ON(value == 0);
7149
7150- got = me->module_core + me->arch.got_offset;
7151+ got = me->module_core_rw + me->arch.got_offset;
7152 for (i = 0; got[i].addr; i++)
7153 if (got[i].addr == value)
7154 goto out;
7155@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7156 #ifdef CONFIG_64BIT
7157 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7158 {
7159- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7160+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7161
7162 if (!value) {
7163 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7164@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7165
7166 /* Create new one */
7167 fdesc->addr = value;
7168- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7169+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7170 return (Elf_Addr)fdesc;
7171 }
7172 #endif /* CONFIG_64BIT */
7173@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7174
7175 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7176 end = table + sechdrs[me->arch.unwind_section].sh_size;
7177- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7178+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7179
7180 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7181 me->arch.unwind_section, table, end, gp);
7182diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7183index 5dfd248..64914ac 100644
7184--- a/arch/parisc/kernel/sys_parisc.c
7185+++ b/arch/parisc/kernel/sys_parisc.c
7186@@ -33,9 +33,11 @@
7187 #include <linux/utsname.h>
7188 #include <linux/personality.h>
7189
7190-static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7191+static unsigned long get_unshared_area(struct file *filp, unsigned long addr, unsigned long len,
7192+ unsigned long flags)
7193 {
7194 struct vm_unmapped_area_info info;
7195+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7196
7197 info.flags = 0;
7198 info.length = len;
7199@@ -43,6 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7200 info.high_limit = TASK_SIZE;
7201 info.align_mask = 0;
7202 info.align_offset = 0;
7203+ info.threadstack_offset = offset;
7204 return vm_unmapped_area(&info);
7205 }
7206
7207@@ -61,10 +64,11 @@ static int get_offset(struct address_space *mapping)
7208 return (unsigned long) mapping >> 8;
7209 }
7210
7211-static unsigned long get_shared_area(struct address_space *mapping,
7212- unsigned long addr, unsigned long len, unsigned long pgoff)
7213+static unsigned long get_shared_area(struct file *filp, struct address_space *mapping,
7214+ unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
7215 {
7216 struct vm_unmapped_area_info info;
7217+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7218
7219 info.flags = 0;
7220 info.length = len;
7221@@ -72,6 +76,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
7222 info.high_limit = TASK_SIZE;
7223 info.align_mask = PAGE_MASK & (SHMLBA - 1);
7224 info.align_offset = (get_offset(mapping) + pgoff) << PAGE_SHIFT;
7225+ info.threadstack_offset = offset;
7226 return vm_unmapped_area(&info);
7227 }
7228
7229@@ -86,15 +91,22 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7230 return -EINVAL;
7231 return addr;
7232 }
7233- if (!addr)
7234+ if (!addr) {
7235 addr = TASK_UNMAPPED_BASE;
7236
7237+#ifdef CONFIG_PAX_RANDMMAP
7238+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
7239+ addr += current->mm->delta_mmap;
7240+#endif
7241+
7242+ }
7243+
7244 if (filp) {
7245- addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
7246+ addr = get_shared_area(filp, filp->f_mapping, addr, len, pgoff, flags);
7247 } else if(flags & MAP_SHARED) {
7248- addr = get_shared_area(NULL, addr, len, pgoff);
7249+ addr = get_shared_area(filp, NULL, addr, len, pgoff, flags);
7250 } else {
7251- addr = get_unshared_area(addr, len);
7252+ addr = get_unshared_area(filp, addr, len, flags);
7253 }
7254 return addr;
7255 }
7256diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7257index b3f87a3..5d5d03d 100644
7258--- a/arch/parisc/kernel/traps.c
7259+++ b/arch/parisc/kernel/traps.c
7260@@ -727,9 +727,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7261
7262 down_read(&current->mm->mmap_sem);
7263 vma = find_vma(current->mm,regs->iaoq[0]);
7264- if (vma && (regs->iaoq[0] >= vma->vm_start)
7265- && (vma->vm_flags & VM_EXEC)) {
7266-
7267+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7268 fault_address = regs->iaoq[0];
7269 fault_space = regs->iasq[0];
7270
7271diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7272index f247a34..dc0f219 100644
7273--- a/arch/parisc/mm/fault.c
7274+++ b/arch/parisc/mm/fault.c
7275@@ -15,6 +15,7 @@
7276 #include <linux/sched.h>
7277 #include <linux/interrupt.h>
7278 #include <linux/module.h>
7279+#include <linux/unistd.h>
7280
7281 #include <asm/uaccess.h>
7282 #include <asm/traps.h>
7283@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
7284 static unsigned long
7285 parisc_acctyp(unsigned long code, unsigned int inst)
7286 {
7287- if (code == 6 || code == 16)
7288+ if (code == 6 || code == 7 || code == 16)
7289 return VM_EXEC;
7290
7291 switch (inst & 0xf0000000) {
7292@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7293 }
7294 #endif
7295
7296+#ifdef CONFIG_PAX_PAGEEXEC
7297+/*
7298+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7299+ *
7300+ * returns 1 when task should be killed
7301+ * 2 when rt_sigreturn trampoline was detected
7302+ * 3 when unpatched PLT trampoline was detected
7303+ */
7304+static int pax_handle_fetch_fault(struct pt_regs *regs)
7305+{
7306+
7307+#ifdef CONFIG_PAX_EMUPLT
7308+ int err;
7309+
7310+ do { /* PaX: unpatched PLT emulation */
7311+ unsigned int bl, depwi;
7312+
7313+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7314+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7315+
7316+ if (err)
7317+ break;
7318+
7319+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7320+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7321+
7322+ err = get_user(ldw, (unsigned int *)addr);
7323+ err |= get_user(bv, (unsigned int *)(addr+4));
7324+ err |= get_user(ldw2, (unsigned int *)(addr+8));
7325+
7326+ if (err)
7327+ break;
7328+
7329+ if (ldw == 0x0E801096U &&
7330+ bv == 0xEAC0C000U &&
7331+ ldw2 == 0x0E881095U)
7332+ {
7333+ unsigned int resolver, map;
7334+
7335+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7336+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7337+ if (err)
7338+ break;
7339+
7340+ regs->gr[20] = instruction_pointer(regs)+8;
7341+ regs->gr[21] = map;
7342+ regs->gr[22] = resolver;
7343+ regs->iaoq[0] = resolver | 3UL;
7344+ regs->iaoq[1] = regs->iaoq[0] + 4;
7345+ return 3;
7346+ }
7347+ }
7348+ } while (0);
7349+#endif
7350+
7351+#ifdef CONFIG_PAX_EMUTRAMP
7352+
7353+#ifndef CONFIG_PAX_EMUSIGRT
7354+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7355+ return 1;
7356+#endif
7357+
7358+ do { /* PaX: rt_sigreturn emulation */
7359+ unsigned int ldi1, ldi2, bel, nop;
7360+
7361+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7362+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7363+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7364+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7365+
7366+ if (err)
7367+ break;
7368+
7369+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7370+ ldi2 == 0x3414015AU &&
7371+ bel == 0xE4008200U &&
7372+ nop == 0x08000240U)
7373+ {
7374+ regs->gr[25] = (ldi1 & 2) >> 1;
7375+ regs->gr[20] = __NR_rt_sigreturn;
7376+ regs->gr[31] = regs->iaoq[1] + 16;
7377+ regs->sr[0] = regs->iasq[1];
7378+ regs->iaoq[0] = 0x100UL;
7379+ regs->iaoq[1] = regs->iaoq[0] + 4;
7380+ regs->iasq[0] = regs->sr[2];
7381+ regs->iasq[1] = regs->sr[2];
7382+ return 2;
7383+ }
7384+ } while (0);
7385+#endif
7386+
7387+ return 1;
7388+}
7389+
7390+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7391+{
7392+ unsigned long i;
7393+
7394+ printk(KERN_ERR "PAX: bytes at PC: ");
7395+ for (i = 0; i < 5; i++) {
7396+ unsigned int c;
7397+ if (get_user(c, (unsigned int *)pc+i))
7398+ printk(KERN_CONT "???????? ");
7399+ else
7400+ printk(KERN_CONT "%08x ", c);
7401+ }
7402+ printk("\n");
7403+}
7404+#endif
7405+
7406 int fixup_exception(struct pt_regs *regs)
7407 {
7408 const struct exception_table_entry *fix;
7409@@ -194,8 +305,33 @@ good_area:
7410
7411 acc_type = parisc_acctyp(code,regs->iir);
7412
7413- if ((vma->vm_flags & acc_type) != acc_type)
7414+ if ((vma->vm_flags & acc_type) != acc_type) {
7415+
7416+#ifdef CONFIG_PAX_PAGEEXEC
7417+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7418+ (address & ~3UL) == instruction_pointer(regs))
7419+ {
7420+ up_read(&mm->mmap_sem);
7421+ switch (pax_handle_fetch_fault(regs)) {
7422+
7423+#ifdef CONFIG_PAX_EMUPLT
7424+ case 3:
7425+ return;
7426+#endif
7427+
7428+#ifdef CONFIG_PAX_EMUTRAMP
7429+ case 2:
7430+ return;
7431+#endif
7432+
7433+ }
7434+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
7435+ do_group_exit(SIGKILL);
7436+ }
7437+#endif
7438+
7439 goto bad_area;
7440+ }
7441
7442 /*
7443 * If for any reason at all we couldn't handle the fault, make
7444diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
7445index e3b1d41..8e81edf 100644
7446--- a/arch/powerpc/include/asm/atomic.h
7447+++ b/arch/powerpc/include/asm/atomic.h
7448@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
7449 return t1;
7450 }
7451
7452+#define atomic64_read_unchecked(v) atomic64_read(v)
7453+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7454+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7455+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7456+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7457+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7458+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7459+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7460+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7461+
7462 #endif /* __powerpc64__ */
7463
7464 #endif /* __KERNEL__ */
7465diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
7466index 9e495c9..b6878e5 100644
7467--- a/arch/powerpc/include/asm/cache.h
7468+++ b/arch/powerpc/include/asm/cache.h
7469@@ -3,6 +3,7 @@
7470
7471 #ifdef __KERNEL__
7472
7473+#include <linux/const.h>
7474
7475 /* bytes per L1 cache line */
7476 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
7477@@ -22,7 +23,7 @@
7478 #define L1_CACHE_SHIFT 7
7479 #endif
7480
7481-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7482+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7483
7484 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7485
7486diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
7487index cc0655a..13eac2e 100644
7488--- a/arch/powerpc/include/asm/elf.h
7489+++ b/arch/powerpc/include/asm/elf.h
7490@@ -28,8 +28,19 @@
7491 the loader. We need to make sure that it is out of the way of the program
7492 that it will "exec", and that there is sufficient room for the brk. */
7493
7494-extern unsigned long randomize_et_dyn(unsigned long base);
7495-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
7496+#define ELF_ET_DYN_BASE (0x20000000)
7497+
7498+#ifdef CONFIG_PAX_ASLR
7499+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
7500+
7501+#ifdef __powerpc64__
7502+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
7503+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
7504+#else
7505+#define PAX_DELTA_MMAP_LEN 15
7506+#define PAX_DELTA_STACK_LEN 15
7507+#endif
7508+#endif
7509
7510 /*
7511 * Our registers are always unsigned longs, whether we're a 32 bit
7512@@ -123,10 +134,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
7513 (0x7ff >> (PAGE_SHIFT - 12)) : \
7514 (0x3ffff >> (PAGE_SHIFT - 12)))
7515
7516-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7517-#define arch_randomize_brk arch_randomize_brk
7518-
7519-
7520 #ifdef CONFIG_SPU_BASE
7521 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
7522 #define NT_SPU 1
7523diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
7524index 8196e9c..d83a9f3 100644
7525--- a/arch/powerpc/include/asm/exec.h
7526+++ b/arch/powerpc/include/asm/exec.h
7527@@ -4,6 +4,6 @@
7528 #ifndef _ASM_POWERPC_EXEC_H
7529 #define _ASM_POWERPC_EXEC_H
7530
7531-extern unsigned long arch_align_stack(unsigned long sp);
7532+#define arch_align_stack(x) ((x) & ~0xfUL)
7533
7534 #endif /* _ASM_POWERPC_EXEC_H */
7535diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
7536index 5acabbd..7ea14fa 100644
7537--- a/arch/powerpc/include/asm/kmap_types.h
7538+++ b/arch/powerpc/include/asm/kmap_types.h
7539@@ -10,7 +10,7 @@
7540 * 2 of the License, or (at your option) any later version.
7541 */
7542
7543-#define KM_TYPE_NR 16
7544+#define KM_TYPE_NR 17
7545
7546 #endif /* __KERNEL__ */
7547 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
7548diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
7549index 8565c25..2865190 100644
7550--- a/arch/powerpc/include/asm/mman.h
7551+++ b/arch/powerpc/include/asm/mman.h
7552@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
7553 }
7554 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
7555
7556-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
7557+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
7558 {
7559 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
7560 }
7561diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
7562index b9f4262..dcf04f7 100644
7563--- a/arch/powerpc/include/asm/page.h
7564+++ b/arch/powerpc/include/asm/page.h
7565@@ -230,8 +230,9 @@ extern long long virt_phys_offset;
7566 * and needs to be executable. This means the whole heap ends
7567 * up being executable.
7568 */
7569-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
7570- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7571+#define VM_DATA_DEFAULT_FLAGS32 \
7572+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
7573+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7574
7575 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
7576 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7577@@ -259,6 +260,9 @@ extern long long virt_phys_offset;
7578 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
7579 #endif
7580
7581+#define ktla_ktva(addr) (addr)
7582+#define ktva_ktla(addr) (addr)
7583+
7584 #ifndef CONFIG_PPC_BOOK3S_64
7585 /*
7586 * Use the top bit of the higher-level page table entries to indicate whether
7587diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
7588index 88693ce..ac6f9ab 100644
7589--- a/arch/powerpc/include/asm/page_64.h
7590+++ b/arch/powerpc/include/asm/page_64.h
7591@@ -153,15 +153,18 @@ do { \
7592 * stack by default, so in the absence of a PT_GNU_STACK program header
7593 * we turn execute permission off.
7594 */
7595-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
7596- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7597+#define VM_STACK_DEFAULT_FLAGS32 \
7598+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
7599+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7600
7601 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
7602 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7603
7604+#ifndef CONFIG_PAX_PAGEEXEC
7605 #define VM_STACK_DEFAULT_FLAGS \
7606 (is_32bit_task() ? \
7607 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
7608+#endif
7609
7610 #include <asm-generic/getorder.h>
7611
7612diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
7613index f65e27b..23ffb5b 100644
7614--- a/arch/powerpc/include/asm/pgalloc-64.h
7615+++ b/arch/powerpc/include/asm/pgalloc-64.h
7616@@ -53,6 +53,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
7617 #ifndef CONFIG_PPC_64K_PAGES
7618
7619 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
7620+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
7621
7622 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
7623 {
7624@@ -70,6 +71,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
7625 pud_set(pud, (unsigned long)pmd);
7626 }
7627
7628+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
7629+{
7630+ pud_populate(mm, pud, pmd);
7631+}
7632+
7633 #define pmd_populate(mm, pmd, pte_page) \
7634 pmd_populate_kernel(mm, pmd, page_address(pte_page))
7635 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
7636@@ -171,6 +177,7 @@ extern void __tlb_remove_table(void *_table);
7637 #endif
7638
7639 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
7640+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7641
7642 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
7643 pte_t *pte)
7644diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
7645index 7d6eacf..14c0240 100644
7646--- a/arch/powerpc/include/asm/pgtable.h
7647+++ b/arch/powerpc/include/asm/pgtable.h
7648@@ -2,6 +2,7 @@
7649 #define _ASM_POWERPC_PGTABLE_H
7650 #ifdef __KERNEL__
7651
7652+#include <linux/const.h>
7653 #ifndef __ASSEMBLY__
7654 #include <asm/processor.h> /* For TASK_SIZE */
7655 #include <asm/mmu.h>
7656diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
7657index 4aad413..85d86bf 100644
7658--- a/arch/powerpc/include/asm/pte-hash32.h
7659+++ b/arch/powerpc/include/asm/pte-hash32.h
7660@@ -21,6 +21,7 @@
7661 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
7662 #define _PAGE_USER 0x004 /* usermode access allowed */
7663 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
7664+#define _PAGE_EXEC _PAGE_GUARDED
7665 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
7666 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
7667 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
7668diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
7669index 99222e2..f629aef 100644
7670--- a/arch/powerpc/include/asm/reg.h
7671+++ b/arch/powerpc/include/asm/reg.h
7672@@ -234,6 +234,7 @@
7673 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
7674 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
7675 #define DSISR_NOHPTE 0x40000000 /* no translation found */
7676+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
7677 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
7678 #define DSISR_ISSTORE 0x02000000 /* access was a store */
7679 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
7680diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
7681index 48cfc85..891382f 100644
7682--- a/arch/powerpc/include/asm/smp.h
7683+++ b/arch/powerpc/include/asm/smp.h
7684@@ -50,7 +50,7 @@ struct smp_ops_t {
7685 int (*cpu_disable)(void);
7686 void (*cpu_die)(unsigned int nr);
7687 int (*cpu_bootable)(unsigned int nr);
7688-};
7689+} __no_const;
7690
7691 extern void smp_send_debugger_break(void);
7692 extern void start_secondary_resume(void);
7693diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
7694index ba7b197..d292e26 100644
7695--- a/arch/powerpc/include/asm/thread_info.h
7696+++ b/arch/powerpc/include/asm/thread_info.h
7697@@ -93,7 +93,6 @@ static inline struct thread_info *current_thread_info(void)
7698 #define TIF_POLLING_NRFLAG 3 /* true if poll_idle() is polling
7699 TIF_NEED_RESCHED */
7700 #define TIF_32BIT 4 /* 32 bit binary */
7701-#define TIF_PERFMON_WORK 5 /* work for pfm_handle_work() */
7702 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
7703 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
7704 #define TIF_SINGLESTEP 8 /* singlestepping active */
7705@@ -107,6 +106,9 @@ static inline struct thread_info *current_thread_info(void)
7706 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
7707 for stack store? */
7708 #define TIF_MEMDIE 17 /* is terminating due to OOM killer */
7709+#define TIF_PERFMON_WORK 18 /* work for pfm_handle_work() */
7710+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
7711+#define TIF_GRSEC_SETXID 5 /* update credentials on syscall entry/exit */
7712
7713 /* as above, but as bit values */
7714 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
7715@@ -126,9 +128,10 @@ static inline struct thread_info *current_thread_info(void)
7716 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
7717 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
7718 #define _TIF_NOHZ (1<<TIF_NOHZ)
7719+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
7720 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
7721 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
7722- _TIF_NOHZ)
7723+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
7724
7725 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
7726 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
7727diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
7728index 9485b43..4718d50 100644
7729--- a/arch/powerpc/include/asm/uaccess.h
7730+++ b/arch/powerpc/include/asm/uaccess.h
7731@@ -318,52 +318,6 @@ do { \
7732 extern unsigned long __copy_tofrom_user(void __user *to,
7733 const void __user *from, unsigned long size);
7734
7735-#ifndef __powerpc64__
7736-
7737-static inline unsigned long copy_from_user(void *to,
7738- const void __user *from, unsigned long n)
7739-{
7740- unsigned long over;
7741-
7742- if (access_ok(VERIFY_READ, from, n))
7743- return __copy_tofrom_user((__force void __user *)to, from, n);
7744- if ((unsigned long)from < TASK_SIZE) {
7745- over = (unsigned long)from + n - TASK_SIZE;
7746- return __copy_tofrom_user((__force void __user *)to, from,
7747- n - over) + over;
7748- }
7749- return n;
7750-}
7751-
7752-static inline unsigned long copy_to_user(void __user *to,
7753- const void *from, unsigned long n)
7754-{
7755- unsigned long over;
7756-
7757- if (access_ok(VERIFY_WRITE, to, n))
7758- return __copy_tofrom_user(to, (__force void __user *)from, n);
7759- if ((unsigned long)to < TASK_SIZE) {
7760- over = (unsigned long)to + n - TASK_SIZE;
7761- return __copy_tofrom_user(to, (__force void __user *)from,
7762- n - over) + over;
7763- }
7764- return n;
7765-}
7766-
7767-#else /* __powerpc64__ */
7768-
7769-#define __copy_in_user(to, from, size) \
7770- __copy_tofrom_user((to), (from), (size))
7771-
7772-extern unsigned long copy_from_user(void *to, const void __user *from,
7773- unsigned long n);
7774-extern unsigned long copy_to_user(void __user *to, const void *from,
7775- unsigned long n);
7776-extern unsigned long copy_in_user(void __user *to, const void __user *from,
7777- unsigned long n);
7778-
7779-#endif /* __powerpc64__ */
7780-
7781 static inline unsigned long __copy_from_user_inatomic(void *to,
7782 const void __user *from, unsigned long n)
7783 {
7784@@ -387,6 +341,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
7785 if (ret == 0)
7786 return 0;
7787 }
7788+
7789+ if (!__builtin_constant_p(n))
7790+ check_object_size(to, n, false);
7791+
7792 return __copy_tofrom_user((__force void __user *)to, from, n);
7793 }
7794
7795@@ -413,6 +371,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
7796 if (ret == 0)
7797 return 0;
7798 }
7799+
7800+ if (!__builtin_constant_p(n))
7801+ check_object_size(from, n, true);
7802+
7803 return __copy_tofrom_user(to, (__force const void __user *)from, n);
7804 }
7805
7806@@ -430,6 +392,92 @@ static inline unsigned long __copy_to_user(void __user *to,
7807 return __copy_to_user_inatomic(to, from, size);
7808 }
7809
7810+#ifndef __powerpc64__
7811+
7812+static inline unsigned long __must_check copy_from_user(void *to,
7813+ const void __user *from, unsigned long n)
7814+{
7815+ unsigned long over;
7816+
7817+ if ((long)n < 0)
7818+ return n;
7819+
7820+ if (access_ok(VERIFY_READ, from, n)) {
7821+ if (!__builtin_constant_p(n))
7822+ check_object_size(to, n, false);
7823+ return __copy_tofrom_user((__force void __user *)to, from, n);
7824+ }
7825+ if ((unsigned long)from < TASK_SIZE) {
7826+ over = (unsigned long)from + n - TASK_SIZE;
7827+ if (!__builtin_constant_p(n - over))
7828+ check_object_size(to, n - over, false);
7829+ return __copy_tofrom_user((__force void __user *)to, from,
7830+ n - over) + over;
7831+ }
7832+ return n;
7833+}
7834+
7835+static inline unsigned long __must_check copy_to_user(void __user *to,
7836+ const void *from, unsigned long n)
7837+{
7838+ unsigned long over;
7839+
7840+ if ((long)n < 0)
7841+ return n;
7842+
7843+ if (access_ok(VERIFY_WRITE, to, n)) {
7844+ if (!__builtin_constant_p(n))
7845+ check_object_size(from, n, true);
7846+ return __copy_tofrom_user(to, (__force void __user *)from, n);
7847+ }
7848+ if ((unsigned long)to < TASK_SIZE) {
7849+ over = (unsigned long)to + n - TASK_SIZE;
7850+ if (!__builtin_constant_p(n))
7851+ check_object_size(from, n - over, true);
7852+ return __copy_tofrom_user(to, (__force void __user *)from,
7853+ n - over) + over;
7854+ }
7855+ return n;
7856+}
7857+
7858+#else /* __powerpc64__ */
7859+
7860+#define __copy_in_user(to, from, size) \
7861+ __copy_tofrom_user((to), (from), (size))
7862+
7863+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
7864+{
7865+ if ((long)n < 0 || n > INT_MAX)
7866+ return n;
7867+
7868+ if (!__builtin_constant_p(n))
7869+ check_object_size(to, n, false);
7870+
7871+ if (likely(access_ok(VERIFY_READ, from, n)))
7872+ n = __copy_from_user(to, from, n);
7873+ else
7874+ memset(to, 0, n);
7875+ return n;
7876+}
7877+
7878+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
7879+{
7880+ if ((long)n < 0 || n > INT_MAX)
7881+ return n;
7882+
7883+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
7884+ if (!__builtin_constant_p(n))
7885+ check_object_size(from, n, true);
7886+ n = __copy_to_user(to, from, n);
7887+ }
7888+ return n;
7889+}
7890+
7891+extern unsigned long copy_in_user(void __user *to, const void __user *from,
7892+ unsigned long n);
7893+
7894+#endif /* __powerpc64__ */
7895+
7896 extern unsigned long __clear_user(void __user *addr, unsigned long size);
7897
7898 static inline unsigned long clear_user(void __user *addr, unsigned long size)
7899diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
7900index 645170a..6cf0271 100644
7901--- a/arch/powerpc/kernel/exceptions-64e.S
7902+++ b/arch/powerpc/kernel/exceptions-64e.S
7903@@ -757,6 +757,7 @@ storage_fault_common:
7904 std r14,_DAR(r1)
7905 std r15,_DSISR(r1)
7906 addi r3,r1,STACK_FRAME_OVERHEAD
7907+ bl .save_nvgprs
7908 mr r4,r14
7909 mr r5,r15
7910 ld r14,PACA_EXGEN+EX_R14(r13)
7911@@ -765,8 +766,7 @@ storage_fault_common:
7912 cmpdi r3,0
7913 bne- 1f
7914 b .ret_from_except_lite
7915-1: bl .save_nvgprs
7916- mr r5,r3
7917+1: mr r5,r3
7918 addi r3,r1,STACK_FRAME_OVERHEAD
7919 ld r4,_DAR(r1)
7920 bl .bad_page_fault
7921diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
7922index 902ca3c..e942155 100644
7923--- a/arch/powerpc/kernel/exceptions-64s.S
7924+++ b/arch/powerpc/kernel/exceptions-64s.S
7925@@ -1357,10 +1357,10 @@ handle_page_fault:
7926 11: ld r4,_DAR(r1)
7927 ld r5,_DSISR(r1)
7928 addi r3,r1,STACK_FRAME_OVERHEAD
7929+ bl .save_nvgprs
7930 bl .do_page_fault
7931 cmpdi r3,0
7932 beq+ 12f
7933- bl .save_nvgprs
7934 mr r5,r3
7935 addi r3,r1,STACK_FRAME_OVERHEAD
7936 lwz r4,_DAR(r1)
7937diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
7938index 2e3200c..72095ce 100644
7939--- a/arch/powerpc/kernel/module_32.c
7940+++ b/arch/powerpc/kernel/module_32.c
7941@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
7942 me->arch.core_plt_section = i;
7943 }
7944 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
7945- printk("Module doesn't contain .plt or .init.plt sections.\n");
7946+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
7947 return -ENOEXEC;
7948 }
7949
7950@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
7951
7952 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
7953 /* Init, or core PLT? */
7954- if (location >= mod->module_core
7955- && location < mod->module_core + mod->core_size)
7956+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
7957+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
7958 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
7959- else
7960+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
7961+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
7962 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
7963+ else {
7964+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
7965+ return ~0UL;
7966+ }
7967
7968 /* Find this entry, or if that fails, the next avail. entry */
7969 while (entry->jump[0]) {
7970diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
7971index 8083be2..10aa352 100644
7972--- a/arch/powerpc/kernel/process.c
7973+++ b/arch/powerpc/kernel/process.c
7974@@ -884,8 +884,8 @@ void show_regs(struct pt_regs * regs)
7975 * Lookup NIP late so we have the best change of getting the
7976 * above info out without failing
7977 */
7978- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
7979- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
7980+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
7981+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
7982 #endif
7983 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
7984 printk("PACATMSCRATCH [%llx]\n", get_paca()->tm_scratch);
7985@@ -1349,10 +1349,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
7986 newsp = stack[0];
7987 ip = stack[STACK_FRAME_LR_SAVE];
7988 if (!firstframe || ip != lr) {
7989- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
7990+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
7991 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
7992 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
7993- printk(" (%pS)",
7994+ printk(" (%pA)",
7995 (void *)current->ret_stack[curr_frame].ret);
7996 curr_frame--;
7997 }
7998@@ -1372,7 +1372,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
7999 struct pt_regs *regs = (struct pt_regs *)
8000 (sp + STACK_FRAME_OVERHEAD);
8001 lr = regs->link;
8002- printk("--- Exception: %lx at %pS\n LR = %pS\n",
8003+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
8004 regs->trap, (void *)regs->nip, (void *)lr);
8005 firstframe = 1;
8006 }
8007@@ -1408,58 +1408,3 @@ void notrace __ppc64_runlatch_off(void)
8008 mtspr(SPRN_CTRLT, ctrl);
8009 }
8010 #endif /* CONFIG_PPC64 */
8011-
8012-unsigned long arch_align_stack(unsigned long sp)
8013-{
8014- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8015- sp -= get_random_int() & ~PAGE_MASK;
8016- return sp & ~0xf;
8017-}
8018-
8019-static inline unsigned long brk_rnd(void)
8020-{
8021- unsigned long rnd = 0;
8022-
8023- /* 8MB for 32bit, 1GB for 64bit */
8024- if (is_32bit_task())
8025- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
8026- else
8027- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
8028-
8029- return rnd << PAGE_SHIFT;
8030-}
8031-
8032-unsigned long arch_randomize_brk(struct mm_struct *mm)
8033-{
8034- unsigned long base = mm->brk;
8035- unsigned long ret;
8036-
8037-#ifdef CONFIG_PPC_STD_MMU_64
8038- /*
8039- * If we are using 1TB segments and we are allowed to randomise
8040- * the heap, we can put it above 1TB so it is backed by a 1TB
8041- * segment. Otherwise the heap will be in the bottom 1TB
8042- * which always uses 256MB segments and this may result in a
8043- * performance penalty.
8044- */
8045- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
8046- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
8047-#endif
8048-
8049- ret = PAGE_ALIGN(base + brk_rnd());
8050-
8051- if (ret < mm->brk)
8052- return mm->brk;
8053-
8054- return ret;
8055-}
8056-
8057-unsigned long randomize_et_dyn(unsigned long base)
8058-{
8059- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8060-
8061- if (ret < base)
8062- return base;
8063-
8064- return ret;
8065-}
8066diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
8067index 9a0d24c..e7fbedf 100644
8068--- a/arch/powerpc/kernel/ptrace.c
8069+++ b/arch/powerpc/kernel/ptrace.c
8070@@ -1761,6 +1761,10 @@ long arch_ptrace(struct task_struct *child, long request,
8071 return ret;
8072 }
8073
8074+#ifdef CONFIG_GRKERNSEC_SETXID
8075+extern void gr_delayed_cred_worker(void);
8076+#endif
8077+
8078 /*
8079 * We must return the syscall number to actually look up in the table.
8080 * This can be -1L to skip running any syscall at all.
8081@@ -1773,6 +1777,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
8082
8083 secure_computing_strict(regs->gpr[0]);
8084
8085+#ifdef CONFIG_GRKERNSEC_SETXID
8086+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8087+ gr_delayed_cred_worker();
8088+#endif
8089+
8090 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
8091 tracehook_report_syscall_entry(regs))
8092 /*
8093@@ -1807,6 +1816,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
8094 {
8095 int step;
8096
8097+#ifdef CONFIG_GRKERNSEC_SETXID
8098+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8099+ gr_delayed_cred_worker();
8100+#endif
8101+
8102 audit_syscall_exit(regs);
8103
8104 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8105diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
8106index 0f83122..c0aca6a 100644
8107--- a/arch/powerpc/kernel/signal_32.c
8108+++ b/arch/powerpc/kernel/signal_32.c
8109@@ -987,7 +987,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
8110 /* Save user registers on the stack */
8111 frame = &rt_sf->uc.uc_mcontext;
8112 addr = frame;
8113- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
8114+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8115 sigret = 0;
8116 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
8117 } else {
8118diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
8119index 887e99d..310bc11 100644
8120--- a/arch/powerpc/kernel/signal_64.c
8121+++ b/arch/powerpc/kernel/signal_64.c
8122@@ -751,7 +751,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
8123 #endif
8124
8125 /* Set up to return from userspace. */
8126- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
8127+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8128 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
8129 } else {
8130 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
8131diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
8132index e435bc0..41c2964 100644
8133--- a/arch/powerpc/kernel/traps.c
8134+++ b/arch/powerpc/kernel/traps.c
8135@@ -141,6 +141,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
8136 return flags;
8137 }
8138
8139+extern void gr_handle_kernel_exploit(void);
8140+
8141 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8142 int signr)
8143 {
8144@@ -190,6 +192,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8145 panic("Fatal exception in interrupt");
8146 if (panic_on_oops)
8147 panic("Fatal exception");
8148+
8149+ gr_handle_kernel_exploit();
8150+
8151 do_exit(signr);
8152 }
8153
8154diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
8155index 1d9c926..25f4741 100644
8156--- a/arch/powerpc/kernel/vdso.c
8157+++ b/arch/powerpc/kernel/vdso.c
8158@@ -34,6 +34,7 @@
8159 #include <asm/firmware.h>
8160 #include <asm/vdso.h>
8161 #include <asm/vdso_datapage.h>
8162+#include <asm/mman.h>
8163
8164 #include "setup.h"
8165
8166@@ -222,7 +223,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8167 vdso_base = VDSO32_MBASE;
8168 #endif
8169
8170- current->mm->context.vdso_base = 0;
8171+ current->mm->context.vdso_base = ~0UL;
8172
8173 /* vDSO has a problem and was disabled, just don't "enable" it for the
8174 * process
8175@@ -242,7 +243,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8176 vdso_base = get_unmapped_area(NULL, vdso_base,
8177 (vdso_pages << PAGE_SHIFT) +
8178 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
8179- 0, 0);
8180+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
8181 if (IS_ERR_VALUE(vdso_base)) {
8182 rc = vdso_base;
8183 goto fail_mmapsem;
8184diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
8185index 5eea6f3..5d10396 100644
8186--- a/arch/powerpc/lib/usercopy_64.c
8187+++ b/arch/powerpc/lib/usercopy_64.c
8188@@ -9,22 +9,6 @@
8189 #include <linux/module.h>
8190 #include <asm/uaccess.h>
8191
8192-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8193-{
8194- if (likely(access_ok(VERIFY_READ, from, n)))
8195- n = __copy_from_user(to, from, n);
8196- else
8197- memset(to, 0, n);
8198- return n;
8199-}
8200-
8201-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8202-{
8203- if (likely(access_ok(VERIFY_WRITE, to, n)))
8204- n = __copy_to_user(to, from, n);
8205- return n;
8206-}
8207-
8208 unsigned long copy_in_user(void __user *to, const void __user *from,
8209 unsigned long n)
8210 {
8211@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
8212 return n;
8213 }
8214
8215-EXPORT_SYMBOL(copy_from_user);
8216-EXPORT_SYMBOL(copy_to_user);
8217 EXPORT_SYMBOL(copy_in_user);
8218
8219diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
8220index 8726779..a33c512 100644
8221--- a/arch/powerpc/mm/fault.c
8222+++ b/arch/powerpc/mm/fault.c
8223@@ -33,6 +33,10 @@
8224 #include <linux/magic.h>
8225 #include <linux/ratelimit.h>
8226 #include <linux/context_tracking.h>
8227+#include <linux/slab.h>
8228+#include <linux/pagemap.h>
8229+#include <linux/compiler.h>
8230+#include <linux/unistd.h>
8231
8232 #include <asm/firmware.h>
8233 #include <asm/page.h>
8234@@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
8235 }
8236 #endif
8237
8238+#ifdef CONFIG_PAX_PAGEEXEC
8239+/*
8240+ * PaX: decide what to do with offenders (regs->nip = fault address)
8241+ *
8242+ * returns 1 when task should be killed
8243+ */
8244+static int pax_handle_fetch_fault(struct pt_regs *regs)
8245+{
8246+ return 1;
8247+}
8248+
8249+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8250+{
8251+ unsigned long i;
8252+
8253+ printk(KERN_ERR "PAX: bytes at PC: ");
8254+ for (i = 0; i < 5; i++) {
8255+ unsigned int c;
8256+ if (get_user(c, (unsigned int __user *)pc+i))
8257+ printk(KERN_CONT "???????? ");
8258+ else
8259+ printk(KERN_CONT "%08x ", c);
8260+ }
8261+ printk("\n");
8262+}
8263+#endif
8264+
8265 /*
8266 * Check whether the instruction at regs->nip is a store using
8267 * an update addressing form which will update r1.
8268@@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
8269 * indicate errors in DSISR but can validly be set in SRR1.
8270 */
8271 if (trap == 0x400)
8272- error_code &= 0x48200000;
8273+ error_code &= 0x58200000;
8274 else
8275 is_write = error_code & DSISR_ISSTORE;
8276 #else
8277@@ -371,7 +402,7 @@ good_area:
8278 * "undefined". Of those that can be set, this is the only
8279 * one which seems bad.
8280 */
8281- if (error_code & 0x10000000)
8282+ if (error_code & DSISR_GUARDED)
8283 /* Guarded storage error. */
8284 goto bad_area;
8285 #endif /* CONFIG_8xx */
8286@@ -386,7 +417,7 @@ good_area:
8287 * processors use the same I/D cache coherency mechanism
8288 * as embedded.
8289 */
8290- if (error_code & DSISR_PROTFAULT)
8291+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
8292 goto bad_area;
8293 #endif /* CONFIG_PPC_STD_MMU */
8294
8295@@ -471,6 +502,23 @@ bad_area:
8296 bad_area_nosemaphore:
8297 /* User mode accesses cause a SIGSEGV */
8298 if (user_mode(regs)) {
8299+
8300+#ifdef CONFIG_PAX_PAGEEXEC
8301+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
8302+#ifdef CONFIG_PPC_STD_MMU
8303+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
8304+#else
8305+ if (is_exec && regs->nip == address) {
8306+#endif
8307+ switch (pax_handle_fetch_fault(regs)) {
8308+ }
8309+
8310+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
8311+ do_group_exit(SIGKILL);
8312+ }
8313+ }
8314+#endif
8315+
8316 _exception(SIGSEGV, regs, code, address);
8317 goto bail;
8318 }
8319diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
8320index cb8bdbe..d770680 100644
8321--- a/arch/powerpc/mm/mmap.c
8322+++ b/arch/powerpc/mm/mmap.c
8323@@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
8324 {
8325 unsigned long rnd = 0;
8326
8327+#ifdef CONFIG_PAX_RANDMMAP
8328+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8329+#endif
8330+
8331 if (current->flags & PF_RANDOMIZE) {
8332 /* 8MB for 32bit, 1GB for 64bit */
8333 if (is_32bit_task())
8334@@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8335 */
8336 if (mmap_is_legacy()) {
8337 mm->mmap_base = TASK_UNMAPPED_BASE;
8338+
8339+#ifdef CONFIG_PAX_RANDMMAP
8340+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8341+ mm->mmap_base += mm->delta_mmap;
8342+#endif
8343+
8344 mm->get_unmapped_area = arch_get_unmapped_area;
8345 } else {
8346 mm->mmap_base = mmap_base();
8347+
8348+#ifdef CONFIG_PAX_RANDMMAP
8349+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8350+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8351+#endif
8352+
8353 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8354 }
8355 }
8356diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
8357index 3e99c14..f00953c 100644
8358--- a/arch/powerpc/mm/slice.c
8359+++ b/arch/powerpc/mm/slice.c
8360@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
8361 if ((mm->task_size - len) < addr)
8362 return 0;
8363 vma = find_vma(mm, addr);
8364- return (!vma || (addr + len) <= vma->vm_start);
8365+ return check_heap_stack_gap(vma, addr, len, 0);
8366 }
8367
8368 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
8369@@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
8370 info.align_offset = 0;
8371
8372 addr = TASK_UNMAPPED_BASE;
8373+
8374+#ifdef CONFIG_PAX_RANDMMAP
8375+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8376+ addr += mm->delta_mmap;
8377+#endif
8378+
8379 while (addr < TASK_SIZE) {
8380 info.low_limit = addr;
8381 if (!slice_scan_available(addr, available, 1, &addr))
8382@@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
8383 if (fixed && addr > (mm->task_size - len))
8384 return -EINVAL;
8385
8386+#ifdef CONFIG_PAX_RANDMMAP
8387+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
8388+ addr = 0;
8389+#endif
8390+
8391 /* If hint, make sure it matches our alignment restrictions */
8392 if (!fixed && addr) {
8393 addr = _ALIGN_UP(addr, 1ul << pshift);
8394diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
8395index 9098692..3d54cd1 100644
8396--- a/arch/powerpc/platforms/cell/spufs/file.c
8397+++ b/arch/powerpc/platforms/cell/spufs/file.c
8398@@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
8399 return VM_FAULT_NOPAGE;
8400 }
8401
8402-static int spufs_mem_mmap_access(struct vm_area_struct *vma,
8403+static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
8404 unsigned long address,
8405- void *buf, int len, int write)
8406+ void *buf, size_t len, int write)
8407 {
8408 struct spu_context *ctx = vma->vm_file->private_data;
8409 unsigned long offset = address - vma->vm_start;
8410diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
8411index c797832..ce575c8 100644
8412--- a/arch/s390/include/asm/atomic.h
8413+++ b/arch/s390/include/asm/atomic.h
8414@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
8415 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
8416 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8417
8418+#define atomic64_read_unchecked(v) atomic64_read(v)
8419+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
8420+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
8421+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
8422+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
8423+#define atomic64_inc_unchecked(v) atomic64_inc(v)
8424+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
8425+#define atomic64_dec_unchecked(v) atomic64_dec(v)
8426+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8427+
8428 #define smp_mb__before_atomic_dec() smp_mb()
8429 #define smp_mb__after_atomic_dec() smp_mb()
8430 #define smp_mb__before_atomic_inc() smp_mb()
8431diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
8432index 4d7ccac..d03d0ad 100644
8433--- a/arch/s390/include/asm/cache.h
8434+++ b/arch/s390/include/asm/cache.h
8435@@ -9,8 +9,10 @@
8436 #ifndef __ARCH_S390_CACHE_H
8437 #define __ARCH_S390_CACHE_H
8438
8439-#define L1_CACHE_BYTES 256
8440+#include <linux/const.h>
8441+
8442 #define L1_CACHE_SHIFT 8
8443+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8444 #define NET_SKB_PAD 32
8445
8446 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
8447diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
8448index 78f4f87..598ce39 100644
8449--- a/arch/s390/include/asm/elf.h
8450+++ b/arch/s390/include/asm/elf.h
8451@@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
8452 the loader. We need to make sure that it is out of the way of the program
8453 that it will "exec", and that there is sufficient room for the brk. */
8454
8455-extern unsigned long randomize_et_dyn(unsigned long base);
8456-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
8457+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
8458+
8459+#ifdef CONFIG_PAX_ASLR
8460+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
8461+
8462+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
8463+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
8464+#endif
8465
8466 /* This yields a mask that user programs can use to figure out what
8467 instruction set this CPU supports. */
8468@@ -222,9 +228,6 @@ struct linux_binprm;
8469 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
8470 int arch_setup_additional_pages(struct linux_binprm *, int);
8471
8472-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8473-#define arch_randomize_brk arch_randomize_brk
8474-
8475 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
8476
8477 #endif
8478diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
8479index c4a93d6..4d2a9b4 100644
8480--- a/arch/s390/include/asm/exec.h
8481+++ b/arch/s390/include/asm/exec.h
8482@@ -7,6 +7,6 @@
8483 #ifndef __ASM_EXEC_H
8484 #define __ASM_EXEC_H
8485
8486-extern unsigned long arch_align_stack(unsigned long sp);
8487+#define arch_align_stack(x) ((x) & ~0xfUL)
8488
8489 #endif /* __ASM_EXEC_H */
8490diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
8491index 9c33ed4..e40cbef 100644
8492--- a/arch/s390/include/asm/uaccess.h
8493+++ b/arch/s390/include/asm/uaccess.h
8494@@ -252,6 +252,10 @@ static inline unsigned long __must_check
8495 copy_to_user(void __user *to, const void *from, unsigned long n)
8496 {
8497 might_fault();
8498+
8499+ if ((long)n < 0)
8500+ return n;
8501+
8502 return __copy_to_user(to, from, n);
8503 }
8504
8505@@ -275,6 +279,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
8506 static inline unsigned long __must_check
8507 __copy_from_user(void *to, const void __user *from, unsigned long n)
8508 {
8509+ if ((long)n < 0)
8510+ return n;
8511+
8512 if (__builtin_constant_p(n) && (n <= 256))
8513 return uaccess.copy_from_user_small(n, from, to);
8514 else
8515@@ -306,10 +313,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
8516 static inline unsigned long __must_check
8517 copy_from_user(void *to, const void __user *from, unsigned long n)
8518 {
8519- unsigned int sz = __compiletime_object_size(to);
8520+ size_t sz = __compiletime_object_size(to);
8521
8522 might_fault();
8523- if (unlikely(sz != -1 && sz < n)) {
8524+
8525+ if ((long)n < 0)
8526+ return n;
8527+
8528+ if (unlikely(sz != (size_t)-1 && sz < n)) {
8529 copy_from_user_overflow();
8530 return n;
8531 }
8532diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
8533index 7845e15..59c4353 100644
8534--- a/arch/s390/kernel/module.c
8535+++ b/arch/s390/kernel/module.c
8536@@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
8537
8538 /* Increase core size by size of got & plt and set start
8539 offsets for got and plt. */
8540- me->core_size = ALIGN(me->core_size, 4);
8541- me->arch.got_offset = me->core_size;
8542- me->core_size += me->arch.got_size;
8543- me->arch.plt_offset = me->core_size;
8544- me->core_size += me->arch.plt_size;
8545+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
8546+ me->arch.got_offset = me->core_size_rw;
8547+ me->core_size_rw += me->arch.got_size;
8548+ me->arch.plt_offset = me->core_size_rx;
8549+ me->core_size_rx += me->arch.plt_size;
8550 return 0;
8551 }
8552
8553@@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8554 if (info->got_initialized == 0) {
8555 Elf_Addr *gotent;
8556
8557- gotent = me->module_core + me->arch.got_offset +
8558+ gotent = me->module_core_rw + me->arch.got_offset +
8559 info->got_offset;
8560 *gotent = val;
8561 info->got_initialized = 1;
8562@@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8563 rc = apply_rela_bits(loc, val, 0, 64, 0);
8564 else if (r_type == R_390_GOTENT ||
8565 r_type == R_390_GOTPLTENT) {
8566- val += (Elf_Addr) me->module_core - loc;
8567+ val += (Elf_Addr) me->module_core_rw - loc;
8568 rc = apply_rela_bits(loc, val, 1, 32, 1);
8569 }
8570 break;
8571@@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8572 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
8573 if (info->plt_initialized == 0) {
8574 unsigned int *ip;
8575- ip = me->module_core + me->arch.plt_offset +
8576+ ip = me->module_core_rx + me->arch.plt_offset +
8577 info->plt_offset;
8578 #ifndef CONFIG_64BIT
8579 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
8580@@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8581 val - loc + 0xffffUL < 0x1ffffeUL) ||
8582 (r_type == R_390_PLT32DBL &&
8583 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
8584- val = (Elf_Addr) me->module_core +
8585+ val = (Elf_Addr) me->module_core_rx +
8586 me->arch.plt_offset +
8587 info->plt_offset;
8588 val += rela->r_addend - loc;
8589@@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8590 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
8591 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
8592 val = val + rela->r_addend -
8593- ((Elf_Addr) me->module_core + me->arch.got_offset);
8594+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
8595 if (r_type == R_390_GOTOFF16)
8596 rc = apply_rela_bits(loc, val, 0, 16, 0);
8597 else if (r_type == R_390_GOTOFF32)
8598@@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8599 break;
8600 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
8601 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
8602- val = (Elf_Addr) me->module_core + me->arch.got_offset +
8603+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
8604 rela->r_addend - loc;
8605 if (r_type == R_390_GOTPC)
8606 rc = apply_rela_bits(loc, val, 1, 32, 0);
8607diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
8608index 2bc3edd..ab9d598 100644
8609--- a/arch/s390/kernel/process.c
8610+++ b/arch/s390/kernel/process.c
8611@@ -236,39 +236,3 @@ unsigned long get_wchan(struct task_struct *p)
8612 }
8613 return 0;
8614 }
8615-
8616-unsigned long arch_align_stack(unsigned long sp)
8617-{
8618- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8619- sp -= get_random_int() & ~PAGE_MASK;
8620- return sp & ~0xf;
8621-}
8622-
8623-static inline unsigned long brk_rnd(void)
8624-{
8625- /* 8MB for 32bit, 1GB for 64bit */
8626- if (is_32bit_task())
8627- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
8628- else
8629- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
8630-}
8631-
8632-unsigned long arch_randomize_brk(struct mm_struct *mm)
8633-{
8634- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
8635-
8636- if (ret < mm->brk)
8637- return mm->brk;
8638- return ret;
8639-}
8640-
8641-unsigned long randomize_et_dyn(unsigned long base)
8642-{
8643- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8644-
8645- if (!(current->flags & PF_RANDOMIZE))
8646- return base;
8647- if (ret < base)
8648- return base;
8649- return ret;
8650-}
8651diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
8652index 4002329..99b67cb 100644
8653--- a/arch/s390/mm/mmap.c
8654+++ b/arch/s390/mm/mmap.c
8655@@ -90,9 +90,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8656 */
8657 if (mmap_is_legacy()) {
8658 mm->mmap_base = TASK_UNMAPPED_BASE;
8659+
8660+#ifdef CONFIG_PAX_RANDMMAP
8661+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8662+ mm->mmap_base += mm->delta_mmap;
8663+#endif
8664+
8665 mm->get_unmapped_area = arch_get_unmapped_area;
8666 } else {
8667 mm->mmap_base = mmap_base();
8668+
8669+#ifdef CONFIG_PAX_RANDMMAP
8670+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8671+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8672+#endif
8673+
8674 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8675 }
8676 }
8677@@ -173,9 +185,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8678 */
8679 if (mmap_is_legacy()) {
8680 mm->mmap_base = TASK_UNMAPPED_BASE;
8681+
8682+#ifdef CONFIG_PAX_RANDMMAP
8683+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8684+ mm->mmap_base += mm->delta_mmap;
8685+#endif
8686+
8687 mm->get_unmapped_area = s390_get_unmapped_area;
8688 } else {
8689 mm->mmap_base = mmap_base();
8690+
8691+#ifdef CONFIG_PAX_RANDMMAP
8692+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8693+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8694+#endif
8695+
8696 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
8697 }
8698 }
8699diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
8700index ae3d59f..f65f075 100644
8701--- a/arch/score/include/asm/cache.h
8702+++ b/arch/score/include/asm/cache.h
8703@@ -1,7 +1,9 @@
8704 #ifndef _ASM_SCORE_CACHE_H
8705 #define _ASM_SCORE_CACHE_H
8706
8707+#include <linux/const.h>
8708+
8709 #define L1_CACHE_SHIFT 4
8710-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8711+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8712
8713 #endif /* _ASM_SCORE_CACHE_H */
8714diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
8715index f9f3cd5..58ff438 100644
8716--- a/arch/score/include/asm/exec.h
8717+++ b/arch/score/include/asm/exec.h
8718@@ -1,6 +1,6 @@
8719 #ifndef _ASM_SCORE_EXEC_H
8720 #define _ASM_SCORE_EXEC_H
8721
8722-extern unsigned long arch_align_stack(unsigned long sp);
8723+#define arch_align_stack(x) (x)
8724
8725 #endif /* _ASM_SCORE_EXEC_H */
8726diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
8727index f4c6d02..e9355c3 100644
8728--- a/arch/score/kernel/process.c
8729+++ b/arch/score/kernel/process.c
8730@@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
8731
8732 return task_pt_regs(task)->cp0_epc;
8733 }
8734-
8735-unsigned long arch_align_stack(unsigned long sp)
8736-{
8737- return sp;
8738-}
8739diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
8740index ef9e555..331bd29 100644
8741--- a/arch/sh/include/asm/cache.h
8742+++ b/arch/sh/include/asm/cache.h
8743@@ -9,10 +9,11 @@
8744 #define __ASM_SH_CACHE_H
8745 #ifdef __KERNEL__
8746
8747+#include <linux/const.h>
8748 #include <linux/init.h>
8749 #include <cpu/cache.h>
8750
8751-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8752+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8753
8754 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
8755
8756diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
8757index 6777177..cb5e44f 100644
8758--- a/arch/sh/mm/mmap.c
8759+++ b/arch/sh/mm/mmap.c
8760@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8761 struct mm_struct *mm = current->mm;
8762 struct vm_area_struct *vma;
8763 int do_colour_align;
8764+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8765 struct vm_unmapped_area_info info;
8766
8767 if (flags & MAP_FIXED) {
8768@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8769 if (filp || (flags & MAP_SHARED))
8770 do_colour_align = 1;
8771
8772+#ifdef CONFIG_PAX_RANDMMAP
8773+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8774+#endif
8775+
8776 if (addr) {
8777 if (do_colour_align)
8778 addr = COLOUR_ALIGN(addr, pgoff);
8779@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8780 addr = PAGE_ALIGN(addr);
8781
8782 vma = find_vma(mm, addr);
8783- if (TASK_SIZE - len >= addr &&
8784- (!vma || addr + len <= vma->vm_start))
8785+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8786 return addr;
8787 }
8788
8789 info.flags = 0;
8790 info.length = len;
8791- info.low_limit = TASK_UNMAPPED_BASE;
8792+ info.low_limit = mm->mmap_base;
8793 info.high_limit = TASK_SIZE;
8794 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
8795 info.align_offset = pgoff << PAGE_SHIFT;
8796@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8797 struct mm_struct *mm = current->mm;
8798 unsigned long addr = addr0;
8799 int do_colour_align;
8800+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8801 struct vm_unmapped_area_info info;
8802
8803 if (flags & MAP_FIXED) {
8804@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8805 if (filp || (flags & MAP_SHARED))
8806 do_colour_align = 1;
8807
8808+#ifdef CONFIG_PAX_RANDMMAP
8809+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8810+#endif
8811+
8812 /* requesting a specific address */
8813 if (addr) {
8814 if (do_colour_align)
8815@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8816 addr = PAGE_ALIGN(addr);
8817
8818 vma = find_vma(mm, addr);
8819- if (TASK_SIZE - len >= addr &&
8820- (!vma || addr + len <= vma->vm_start))
8821+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8822 return addr;
8823 }
8824
8825@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8826 VM_BUG_ON(addr != -ENOMEM);
8827 info.flags = 0;
8828 info.low_limit = TASK_UNMAPPED_BASE;
8829+
8830+#ifdef CONFIG_PAX_RANDMMAP
8831+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8832+ info.low_limit += mm->delta_mmap;
8833+#endif
8834+
8835 info.high_limit = TASK_SIZE;
8836 addr = vm_unmapped_area(&info);
8837 }
8838diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
8839index be56a24..443328f 100644
8840--- a/arch/sparc/include/asm/atomic_64.h
8841+++ b/arch/sparc/include/asm/atomic_64.h
8842@@ -14,18 +14,40 @@
8843 #define ATOMIC64_INIT(i) { (i) }
8844
8845 #define atomic_read(v) (*(volatile int *)&(v)->counter)
8846+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
8847+{
8848+ return v->counter;
8849+}
8850 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
8851+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
8852+{
8853+ return v->counter;
8854+}
8855
8856 #define atomic_set(v, i) (((v)->counter) = i)
8857+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
8858+{
8859+ v->counter = i;
8860+}
8861 #define atomic64_set(v, i) (((v)->counter) = i)
8862+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
8863+{
8864+ v->counter = i;
8865+}
8866
8867 extern void atomic_add(int, atomic_t *);
8868+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
8869 extern void atomic64_add(long, atomic64_t *);
8870+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
8871 extern void atomic_sub(int, atomic_t *);
8872+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
8873 extern void atomic64_sub(long, atomic64_t *);
8874+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
8875
8876 extern int atomic_add_ret(int, atomic_t *);
8877+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
8878 extern long atomic64_add_ret(long, atomic64_t *);
8879+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
8880 extern int atomic_sub_ret(int, atomic_t *);
8881 extern long atomic64_sub_ret(long, atomic64_t *);
8882
8883@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
8884 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
8885
8886 #define atomic_inc_return(v) atomic_add_ret(1, v)
8887+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
8888+{
8889+ return atomic_add_ret_unchecked(1, v);
8890+}
8891 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
8892+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
8893+{
8894+ return atomic64_add_ret_unchecked(1, v);
8895+}
8896
8897 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
8898 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
8899
8900 #define atomic_add_return(i, v) atomic_add_ret(i, v)
8901+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
8902+{
8903+ return atomic_add_ret_unchecked(i, v);
8904+}
8905 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
8906+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
8907+{
8908+ return atomic64_add_ret_unchecked(i, v);
8909+}
8910
8911 /*
8912 * atomic_inc_and_test - increment and test
8913@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
8914 * other cases.
8915 */
8916 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
8917+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
8918+{
8919+ return atomic_inc_return_unchecked(v) == 0;
8920+}
8921 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
8922
8923 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
8924@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
8925 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
8926
8927 #define atomic_inc(v) atomic_add(1, v)
8928+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
8929+{
8930+ atomic_add_unchecked(1, v);
8931+}
8932 #define atomic64_inc(v) atomic64_add(1, v)
8933+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
8934+{
8935+ atomic64_add_unchecked(1, v);
8936+}
8937
8938 #define atomic_dec(v) atomic_sub(1, v)
8939+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
8940+{
8941+ atomic_sub_unchecked(1, v);
8942+}
8943 #define atomic64_dec(v) atomic64_sub(1, v)
8944+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
8945+{
8946+ atomic64_sub_unchecked(1, v);
8947+}
8948
8949 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
8950 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
8951
8952 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
8953+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
8954+{
8955+ return cmpxchg(&v->counter, old, new);
8956+}
8957 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
8958+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
8959+{
8960+ return xchg(&v->counter, new);
8961+}
8962
8963 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
8964 {
8965- int c, old;
8966+ int c, old, new;
8967 c = atomic_read(v);
8968 for (;;) {
8969- if (unlikely(c == (u)))
8970+ if (unlikely(c == u))
8971 break;
8972- old = atomic_cmpxchg((v), c, c + (a));
8973+
8974+ asm volatile("addcc %2, %0, %0\n"
8975+
8976+#ifdef CONFIG_PAX_REFCOUNT
8977+ "tvs %%icc, 6\n"
8978+#endif
8979+
8980+ : "=r" (new)
8981+ : "0" (c), "ir" (a)
8982+ : "cc");
8983+
8984+ old = atomic_cmpxchg(v, c, new);
8985 if (likely(old == c))
8986 break;
8987 c = old;
8988@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
8989 #define atomic64_cmpxchg(v, o, n) \
8990 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
8991 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
8992+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
8993+{
8994+ return xchg(&v->counter, new);
8995+}
8996
8997 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
8998 {
8999- long c, old;
9000+ long c, old, new;
9001 c = atomic64_read(v);
9002 for (;;) {
9003- if (unlikely(c == (u)))
9004+ if (unlikely(c == u))
9005 break;
9006- old = atomic64_cmpxchg((v), c, c + (a));
9007+
9008+ asm volatile("addcc %2, %0, %0\n"
9009+
9010+#ifdef CONFIG_PAX_REFCOUNT
9011+ "tvs %%xcc, 6\n"
9012+#endif
9013+
9014+ : "=r" (new)
9015+ : "0" (c), "ir" (a)
9016+ : "cc");
9017+
9018+ old = atomic64_cmpxchg(v, c, new);
9019 if (likely(old == c))
9020 break;
9021 c = old;
9022 }
9023- return c != (u);
9024+ return c != u;
9025 }
9026
9027 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9028diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
9029index 5bb6991..5c2132e 100644
9030--- a/arch/sparc/include/asm/cache.h
9031+++ b/arch/sparc/include/asm/cache.h
9032@@ -7,10 +7,12 @@
9033 #ifndef _SPARC_CACHE_H
9034 #define _SPARC_CACHE_H
9035
9036+#include <linux/const.h>
9037+
9038 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
9039
9040 #define L1_CACHE_SHIFT 5
9041-#define L1_CACHE_BYTES 32
9042+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9043
9044 #ifdef CONFIG_SPARC32
9045 #define SMP_CACHE_BYTES_SHIFT 5
9046diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
9047index a24e41f..47677ff 100644
9048--- a/arch/sparc/include/asm/elf_32.h
9049+++ b/arch/sparc/include/asm/elf_32.h
9050@@ -114,6 +114,13 @@ typedef struct {
9051
9052 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
9053
9054+#ifdef CONFIG_PAX_ASLR
9055+#define PAX_ELF_ET_DYN_BASE 0x10000UL
9056+
9057+#define PAX_DELTA_MMAP_LEN 16
9058+#define PAX_DELTA_STACK_LEN 16
9059+#endif
9060+
9061 /* This yields a mask that user programs can use to figure out what
9062 instruction set this cpu supports. This can NOT be done in userspace
9063 on Sparc. */
9064diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
9065index 370ca1e..d4f4a98 100644
9066--- a/arch/sparc/include/asm/elf_64.h
9067+++ b/arch/sparc/include/asm/elf_64.h
9068@@ -189,6 +189,13 @@ typedef struct {
9069 #define ELF_ET_DYN_BASE 0x0000010000000000UL
9070 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
9071
9072+#ifdef CONFIG_PAX_ASLR
9073+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
9074+
9075+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
9076+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
9077+#endif
9078+
9079 extern unsigned long sparc64_elf_hwcap;
9080 #define ELF_HWCAP sparc64_elf_hwcap
9081
9082diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
9083index 9b1c36d..209298b 100644
9084--- a/arch/sparc/include/asm/pgalloc_32.h
9085+++ b/arch/sparc/include/asm/pgalloc_32.h
9086@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
9087 }
9088
9089 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
9090+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
9091
9092 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
9093 unsigned long address)
9094diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
9095index bcfe063..b333142 100644
9096--- a/arch/sparc/include/asm/pgalloc_64.h
9097+++ b/arch/sparc/include/asm/pgalloc_64.h
9098@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9099 }
9100
9101 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
9102+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
9103
9104 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
9105 {
9106diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
9107index 502f632..da1917f 100644
9108--- a/arch/sparc/include/asm/pgtable_32.h
9109+++ b/arch/sparc/include/asm/pgtable_32.h
9110@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
9111 #define PAGE_SHARED SRMMU_PAGE_SHARED
9112 #define PAGE_COPY SRMMU_PAGE_COPY
9113 #define PAGE_READONLY SRMMU_PAGE_RDONLY
9114+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
9115+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
9116+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
9117 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
9118
9119 /* Top-level page directory - dummy used by init-mm.
9120@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
9121
9122 /* xwr */
9123 #define __P000 PAGE_NONE
9124-#define __P001 PAGE_READONLY
9125-#define __P010 PAGE_COPY
9126-#define __P011 PAGE_COPY
9127+#define __P001 PAGE_READONLY_NOEXEC
9128+#define __P010 PAGE_COPY_NOEXEC
9129+#define __P011 PAGE_COPY_NOEXEC
9130 #define __P100 PAGE_READONLY
9131 #define __P101 PAGE_READONLY
9132 #define __P110 PAGE_COPY
9133 #define __P111 PAGE_COPY
9134
9135 #define __S000 PAGE_NONE
9136-#define __S001 PAGE_READONLY
9137-#define __S010 PAGE_SHARED
9138-#define __S011 PAGE_SHARED
9139+#define __S001 PAGE_READONLY_NOEXEC
9140+#define __S010 PAGE_SHARED_NOEXEC
9141+#define __S011 PAGE_SHARED_NOEXEC
9142 #define __S100 PAGE_READONLY
9143 #define __S101 PAGE_READONLY
9144 #define __S110 PAGE_SHARED
9145diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
9146index 79da178..c2eede8 100644
9147--- a/arch/sparc/include/asm/pgtsrmmu.h
9148+++ b/arch/sparc/include/asm/pgtsrmmu.h
9149@@ -115,6 +115,11 @@
9150 SRMMU_EXEC | SRMMU_REF)
9151 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
9152 SRMMU_EXEC | SRMMU_REF)
9153+
9154+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
9155+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9156+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9157+
9158 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
9159 SRMMU_DIRTY | SRMMU_REF)
9160
9161diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
9162index 9689176..63c18ea 100644
9163--- a/arch/sparc/include/asm/spinlock_64.h
9164+++ b/arch/sparc/include/asm/spinlock_64.h
9165@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
9166
9167 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
9168
9169-static void inline arch_read_lock(arch_rwlock_t *lock)
9170+static inline void arch_read_lock(arch_rwlock_t *lock)
9171 {
9172 unsigned long tmp1, tmp2;
9173
9174 __asm__ __volatile__ (
9175 "1: ldsw [%2], %0\n"
9176 " brlz,pn %0, 2f\n"
9177-"4: add %0, 1, %1\n"
9178+"4: addcc %0, 1, %1\n"
9179+
9180+#ifdef CONFIG_PAX_REFCOUNT
9181+" tvs %%icc, 6\n"
9182+#endif
9183+
9184 " cas [%2], %0, %1\n"
9185 " cmp %0, %1\n"
9186 " bne,pn %%icc, 1b\n"
9187@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
9188 " .previous"
9189 : "=&r" (tmp1), "=&r" (tmp2)
9190 : "r" (lock)
9191- : "memory");
9192+ : "memory", "cc");
9193 }
9194
9195-static int inline arch_read_trylock(arch_rwlock_t *lock)
9196+static inline int arch_read_trylock(arch_rwlock_t *lock)
9197 {
9198 int tmp1, tmp2;
9199
9200@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9201 "1: ldsw [%2], %0\n"
9202 " brlz,a,pn %0, 2f\n"
9203 " mov 0, %0\n"
9204-" add %0, 1, %1\n"
9205+" addcc %0, 1, %1\n"
9206+
9207+#ifdef CONFIG_PAX_REFCOUNT
9208+" tvs %%icc, 6\n"
9209+#endif
9210+
9211 " cas [%2], %0, %1\n"
9212 " cmp %0, %1\n"
9213 " bne,pn %%icc, 1b\n"
9214@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9215 return tmp1;
9216 }
9217
9218-static void inline arch_read_unlock(arch_rwlock_t *lock)
9219+static inline void arch_read_unlock(arch_rwlock_t *lock)
9220 {
9221 unsigned long tmp1, tmp2;
9222
9223 __asm__ __volatile__(
9224 "1: lduw [%2], %0\n"
9225-" sub %0, 1, %1\n"
9226+" subcc %0, 1, %1\n"
9227+
9228+#ifdef CONFIG_PAX_REFCOUNT
9229+" tvs %%icc, 6\n"
9230+#endif
9231+
9232 " cas [%2], %0, %1\n"
9233 " cmp %0, %1\n"
9234 " bne,pn %%xcc, 1b\n"
9235@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
9236 : "memory");
9237 }
9238
9239-static void inline arch_write_lock(arch_rwlock_t *lock)
9240+static inline void arch_write_lock(arch_rwlock_t *lock)
9241 {
9242 unsigned long mask, tmp1, tmp2;
9243
9244@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
9245 : "memory");
9246 }
9247
9248-static void inline arch_write_unlock(arch_rwlock_t *lock)
9249+static inline void arch_write_unlock(arch_rwlock_t *lock)
9250 {
9251 __asm__ __volatile__(
9252 " stw %%g0, [%0]"
9253@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
9254 : "memory");
9255 }
9256
9257-static int inline arch_write_trylock(arch_rwlock_t *lock)
9258+static inline int arch_write_trylock(arch_rwlock_t *lock)
9259 {
9260 unsigned long mask, tmp1, tmp2, result;
9261
9262diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
9263index dd38075..e7cac83 100644
9264--- a/arch/sparc/include/asm/thread_info_32.h
9265+++ b/arch/sparc/include/asm/thread_info_32.h
9266@@ -49,6 +49,8 @@ struct thread_info {
9267 unsigned long w_saved;
9268
9269 struct restart_block restart_block;
9270+
9271+ unsigned long lowest_stack;
9272 };
9273
9274 /*
9275diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
9276index d5e5042..9bfee76 100644
9277--- a/arch/sparc/include/asm/thread_info_64.h
9278+++ b/arch/sparc/include/asm/thread_info_64.h
9279@@ -63,6 +63,8 @@ struct thread_info {
9280 struct pt_regs *kern_una_regs;
9281 unsigned int kern_una_insn;
9282
9283+ unsigned long lowest_stack;
9284+
9285 unsigned long fpregs[0] __attribute__ ((aligned(64)));
9286 };
9287
9288@@ -192,10 +194,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
9289 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
9290 /* flag bit 6 is available */
9291 #define TIF_32BIT 7 /* 32-bit binary */
9292-/* flag bit 8 is available */
9293+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
9294 #define TIF_SECCOMP 9 /* secure computing */
9295 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
9296 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
9297+
9298 /* NOTE: Thread flags >= 12 should be ones we have no interest
9299 * in using in assembly, else we can't use the mask as
9300 * an immediate value in instructions such as andcc.
9301@@ -214,12 +217,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
9302 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
9303 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
9304 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
9305+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
9306
9307 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
9308 _TIF_DO_NOTIFY_RESUME_MASK | \
9309 _TIF_NEED_RESCHED)
9310 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
9311
9312+#define _TIF_WORK_SYSCALL \
9313+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
9314+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
9315+
9316+
9317 /*
9318 * Thread-synchronous status.
9319 *
9320diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
9321index 0167d26..767bb0c 100644
9322--- a/arch/sparc/include/asm/uaccess.h
9323+++ b/arch/sparc/include/asm/uaccess.h
9324@@ -1,5 +1,6 @@
9325 #ifndef ___ASM_SPARC_UACCESS_H
9326 #define ___ASM_SPARC_UACCESS_H
9327+
9328 #if defined(__sparc__) && defined(__arch64__)
9329 #include <asm/uaccess_64.h>
9330 #else
9331diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
9332index 53a28dd..50c38c3 100644
9333--- a/arch/sparc/include/asm/uaccess_32.h
9334+++ b/arch/sparc/include/asm/uaccess_32.h
9335@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
9336
9337 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9338 {
9339- if (n && __access_ok((unsigned long) to, n))
9340+ if ((long)n < 0)
9341+ return n;
9342+
9343+ if (n && __access_ok((unsigned long) to, n)) {
9344+ if (!__builtin_constant_p(n))
9345+ check_object_size(from, n, true);
9346 return __copy_user(to, (__force void __user *) from, n);
9347- else
9348+ } else
9349 return n;
9350 }
9351
9352 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
9353 {
9354+ if ((long)n < 0)
9355+ return n;
9356+
9357+ if (!__builtin_constant_p(n))
9358+ check_object_size(from, n, true);
9359+
9360 return __copy_user(to, (__force void __user *) from, n);
9361 }
9362
9363 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9364 {
9365- if (n && __access_ok((unsigned long) from, n))
9366+ if ((long)n < 0)
9367+ return n;
9368+
9369+ if (n && __access_ok((unsigned long) from, n)) {
9370+ if (!__builtin_constant_p(n))
9371+ check_object_size(to, n, false);
9372 return __copy_user((__force void __user *) to, from, n);
9373- else
9374+ } else
9375 return n;
9376 }
9377
9378 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
9379 {
9380+ if ((long)n < 0)
9381+ return n;
9382+
9383 return __copy_user((__force void __user *) to, from, n);
9384 }
9385
9386diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
9387index e562d3c..191f176 100644
9388--- a/arch/sparc/include/asm/uaccess_64.h
9389+++ b/arch/sparc/include/asm/uaccess_64.h
9390@@ -10,6 +10,7 @@
9391 #include <linux/compiler.h>
9392 #include <linux/string.h>
9393 #include <linux/thread_info.h>
9394+#include <linux/kernel.h>
9395 #include <asm/asi.h>
9396 #include <asm/spitfire.h>
9397 #include <asm-generic/uaccess-unaligned.h>
9398@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
9399 static inline unsigned long __must_check
9400 copy_from_user(void *to, const void __user *from, unsigned long size)
9401 {
9402- unsigned long ret = ___copy_from_user(to, from, size);
9403+ unsigned long ret;
9404
9405+ if ((long)size < 0 || size > INT_MAX)
9406+ return size;
9407+
9408+ if (!__builtin_constant_p(size))
9409+ check_object_size(to, size, false);
9410+
9411+ ret = ___copy_from_user(to, from, size);
9412 if (unlikely(ret))
9413 ret = copy_from_user_fixup(to, from, size);
9414
9415@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
9416 static inline unsigned long __must_check
9417 copy_to_user(void __user *to, const void *from, unsigned long size)
9418 {
9419- unsigned long ret = ___copy_to_user(to, from, size);
9420+ unsigned long ret;
9421
9422+ if ((long)size < 0 || size > INT_MAX)
9423+ return size;
9424+
9425+ if (!__builtin_constant_p(size))
9426+ check_object_size(from, size, true);
9427+
9428+ ret = ___copy_to_user(to, from, size);
9429 if (unlikely(ret))
9430 ret = copy_to_user_fixup(to, from, size);
9431 return ret;
9432diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
9433index d432fb2..6056af1 100644
9434--- a/arch/sparc/kernel/Makefile
9435+++ b/arch/sparc/kernel/Makefile
9436@@ -3,7 +3,7 @@
9437 #
9438
9439 asflags-y := -ansi
9440-ccflags-y := -Werror
9441+#ccflags-y := -Werror
9442
9443 extra-y := head_$(BITS).o
9444
9445diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
9446index fdd819d..5af08c8 100644
9447--- a/arch/sparc/kernel/process_32.c
9448+++ b/arch/sparc/kernel/process_32.c
9449@@ -116,14 +116,14 @@ void show_regs(struct pt_regs *r)
9450
9451 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
9452 r->psr, r->pc, r->npc, r->y, print_tainted());
9453- printk("PC: <%pS>\n", (void *) r->pc);
9454+ printk("PC: <%pA>\n", (void *) r->pc);
9455 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9456 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
9457 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
9458 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9459 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
9460 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
9461- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
9462+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
9463
9464 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9465 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
9466@@ -160,7 +160,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
9467 rw = (struct reg_window32 *) fp;
9468 pc = rw->ins[7];
9469 printk("[%08lx : ", pc);
9470- printk("%pS ] ", (void *) pc);
9471+ printk("%pA ] ", (void *) pc);
9472 fp = rw->ins[6];
9473 } while (++count < 16);
9474 printk("\n");
9475diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
9476index baebab2..9cd13b1 100644
9477--- a/arch/sparc/kernel/process_64.c
9478+++ b/arch/sparc/kernel/process_64.c
9479@@ -158,7 +158,7 @@ static void show_regwindow(struct pt_regs *regs)
9480 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
9481 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
9482 if (regs->tstate & TSTATE_PRIV)
9483- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
9484+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
9485 }
9486
9487 void show_regs(struct pt_regs *regs)
9488@@ -167,7 +167,7 @@ void show_regs(struct pt_regs *regs)
9489
9490 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
9491 regs->tpc, regs->tnpc, regs->y, print_tainted());
9492- printk("TPC: <%pS>\n", (void *) regs->tpc);
9493+ printk("TPC: <%pA>\n", (void *) regs->tpc);
9494 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
9495 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
9496 regs->u_regs[3]);
9497@@ -180,7 +180,7 @@ void show_regs(struct pt_regs *regs)
9498 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
9499 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
9500 regs->u_regs[15]);
9501- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
9502+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
9503 show_regwindow(regs);
9504 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
9505 }
9506@@ -269,7 +269,7 @@ void arch_trigger_all_cpu_backtrace(void)
9507 ((tp && tp->task) ? tp->task->pid : -1));
9508
9509 if (gp->tstate & TSTATE_PRIV) {
9510- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
9511+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
9512 (void *) gp->tpc,
9513 (void *) gp->o7,
9514 (void *) gp->i7,
9515diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
9516index 79cc0d1..ec62734 100644
9517--- a/arch/sparc/kernel/prom_common.c
9518+++ b/arch/sparc/kernel/prom_common.c
9519@@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
9520
9521 unsigned int prom_early_allocated __initdata;
9522
9523-static struct of_pdt_ops prom_sparc_ops __initdata = {
9524+static struct of_pdt_ops prom_sparc_ops __initconst = {
9525 .nextprop = prom_common_nextprop,
9526 .getproplen = prom_getproplen,
9527 .getproperty = prom_getproperty,
9528diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
9529index 7ff45e4..a58f271 100644
9530--- a/arch/sparc/kernel/ptrace_64.c
9531+++ b/arch/sparc/kernel/ptrace_64.c
9532@@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
9533 return ret;
9534 }
9535
9536+#ifdef CONFIG_GRKERNSEC_SETXID
9537+extern void gr_delayed_cred_worker(void);
9538+#endif
9539+
9540 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9541 {
9542 int ret = 0;
9543@@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9544 /* do the secure computing check first */
9545 secure_computing_strict(regs->u_regs[UREG_G1]);
9546
9547+#ifdef CONFIG_GRKERNSEC_SETXID
9548+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9549+ gr_delayed_cred_worker();
9550+#endif
9551+
9552 if (test_thread_flag(TIF_SYSCALL_TRACE))
9553 ret = tracehook_report_syscall_entry(regs);
9554
9555@@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9556
9557 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
9558 {
9559+#ifdef CONFIG_GRKERNSEC_SETXID
9560+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9561+ gr_delayed_cred_worker();
9562+#endif
9563+
9564 audit_syscall_exit(regs);
9565
9566 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
9567diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
9568index e142545..fd29654 100644
9569--- a/arch/sparc/kernel/smp_64.c
9570+++ b/arch/sparc/kernel/smp_64.c
9571@@ -869,8 +869,8 @@ extern unsigned long xcall_flush_dcache_page_cheetah;
9572 extern unsigned long xcall_flush_dcache_page_spitfire;
9573
9574 #ifdef CONFIG_DEBUG_DCFLUSH
9575-extern atomic_t dcpage_flushes;
9576-extern atomic_t dcpage_flushes_xcall;
9577+extern atomic_unchecked_t dcpage_flushes;
9578+extern atomic_unchecked_t dcpage_flushes_xcall;
9579 #endif
9580
9581 static inline void __local_flush_dcache_page(struct page *page)
9582@@ -894,7 +894,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
9583 return;
9584
9585 #ifdef CONFIG_DEBUG_DCFLUSH
9586- atomic_inc(&dcpage_flushes);
9587+ atomic_inc_unchecked(&dcpage_flushes);
9588 #endif
9589
9590 this_cpu = get_cpu();
9591@@ -918,7 +918,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
9592 xcall_deliver(data0, __pa(pg_addr),
9593 (u64) pg_addr, cpumask_of(cpu));
9594 #ifdef CONFIG_DEBUG_DCFLUSH
9595- atomic_inc(&dcpage_flushes_xcall);
9596+ atomic_inc_unchecked(&dcpage_flushes_xcall);
9597 #endif
9598 }
9599 }
9600@@ -937,7 +937,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
9601 preempt_disable();
9602
9603 #ifdef CONFIG_DEBUG_DCFLUSH
9604- atomic_inc(&dcpage_flushes);
9605+ atomic_inc_unchecked(&dcpage_flushes);
9606 #endif
9607 data0 = 0;
9608 pg_addr = page_address(page);
9609@@ -954,7 +954,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
9610 xcall_deliver(data0, __pa(pg_addr),
9611 (u64) pg_addr, cpu_online_mask);
9612 #ifdef CONFIG_DEBUG_DCFLUSH
9613- atomic_inc(&dcpage_flushes_xcall);
9614+ atomic_inc_unchecked(&dcpage_flushes_xcall);
9615 #endif
9616 }
9617 __local_flush_dcache_page(page);
9618diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
9619index 3a8d184..49498a8 100644
9620--- a/arch/sparc/kernel/sys_sparc_32.c
9621+++ b/arch/sparc/kernel/sys_sparc_32.c
9622@@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9623 if (len > TASK_SIZE - PAGE_SIZE)
9624 return -ENOMEM;
9625 if (!addr)
9626- addr = TASK_UNMAPPED_BASE;
9627+ addr = current->mm->mmap_base;
9628
9629 info.flags = 0;
9630 info.length = len;
9631diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
9632index 51561b8..8256764 100644
9633--- a/arch/sparc/kernel/sys_sparc_64.c
9634+++ b/arch/sparc/kernel/sys_sparc_64.c
9635@@ -90,13 +90,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9636 struct vm_area_struct * vma;
9637 unsigned long task_size = TASK_SIZE;
9638 int do_color_align;
9639+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9640 struct vm_unmapped_area_info info;
9641
9642 if (flags & MAP_FIXED) {
9643 /* We do not accept a shared mapping if it would violate
9644 * cache aliasing constraints.
9645 */
9646- if ((flags & MAP_SHARED) &&
9647+ if ((filp || (flags & MAP_SHARED)) &&
9648 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
9649 return -EINVAL;
9650 return addr;
9651@@ -111,6 +112,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9652 if (filp || (flags & MAP_SHARED))
9653 do_color_align = 1;
9654
9655+#ifdef CONFIG_PAX_RANDMMAP
9656+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9657+#endif
9658+
9659 if (addr) {
9660 if (do_color_align)
9661 addr = COLOR_ALIGN(addr, pgoff);
9662@@ -118,22 +123,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9663 addr = PAGE_ALIGN(addr);
9664
9665 vma = find_vma(mm, addr);
9666- if (task_size - len >= addr &&
9667- (!vma || addr + len <= vma->vm_start))
9668+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9669 return addr;
9670 }
9671
9672 info.flags = 0;
9673 info.length = len;
9674- info.low_limit = TASK_UNMAPPED_BASE;
9675+ info.low_limit = mm->mmap_base;
9676 info.high_limit = min(task_size, VA_EXCLUDE_START);
9677 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
9678 info.align_offset = pgoff << PAGE_SHIFT;
9679+ info.threadstack_offset = offset;
9680 addr = vm_unmapped_area(&info);
9681
9682 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
9683 VM_BUG_ON(addr != -ENOMEM);
9684 info.low_limit = VA_EXCLUDE_END;
9685+
9686+#ifdef CONFIG_PAX_RANDMMAP
9687+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9688+ info.low_limit += mm->delta_mmap;
9689+#endif
9690+
9691 info.high_limit = task_size;
9692 addr = vm_unmapped_area(&info);
9693 }
9694@@ -151,6 +162,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9695 unsigned long task_size = STACK_TOP32;
9696 unsigned long addr = addr0;
9697 int do_color_align;
9698+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9699 struct vm_unmapped_area_info info;
9700
9701 /* This should only ever run for 32-bit processes. */
9702@@ -160,7 +172,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9703 /* We do not accept a shared mapping if it would violate
9704 * cache aliasing constraints.
9705 */
9706- if ((flags & MAP_SHARED) &&
9707+ if ((filp || (flags & MAP_SHARED)) &&
9708 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
9709 return -EINVAL;
9710 return addr;
9711@@ -173,6 +185,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9712 if (filp || (flags & MAP_SHARED))
9713 do_color_align = 1;
9714
9715+#ifdef CONFIG_PAX_RANDMMAP
9716+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9717+#endif
9718+
9719 /* requesting a specific address */
9720 if (addr) {
9721 if (do_color_align)
9722@@ -181,8 +197,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9723 addr = PAGE_ALIGN(addr);
9724
9725 vma = find_vma(mm, addr);
9726- if (task_size - len >= addr &&
9727- (!vma || addr + len <= vma->vm_start))
9728+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9729 return addr;
9730 }
9731
9732@@ -192,6 +207,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9733 info.high_limit = mm->mmap_base;
9734 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
9735 info.align_offset = pgoff << PAGE_SHIFT;
9736+ info.threadstack_offset = offset;
9737 addr = vm_unmapped_area(&info);
9738
9739 /*
9740@@ -204,6 +220,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9741 VM_BUG_ON(addr != -ENOMEM);
9742 info.flags = 0;
9743 info.low_limit = TASK_UNMAPPED_BASE;
9744+
9745+#ifdef CONFIG_PAX_RANDMMAP
9746+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9747+ info.low_limit += mm->delta_mmap;
9748+#endif
9749+
9750 info.high_limit = STACK_TOP32;
9751 addr = vm_unmapped_area(&info);
9752 }
9753@@ -260,10 +282,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
9754 EXPORT_SYMBOL(get_fb_unmapped_area);
9755
9756 /* Essentially the same as PowerPC. */
9757-static unsigned long mmap_rnd(void)
9758+static unsigned long mmap_rnd(struct mm_struct *mm)
9759 {
9760 unsigned long rnd = 0UL;
9761
9762+#ifdef CONFIG_PAX_RANDMMAP
9763+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9764+#endif
9765+
9766 if (current->flags & PF_RANDOMIZE) {
9767 unsigned long val = get_random_int();
9768 if (test_thread_flag(TIF_32BIT))
9769@@ -276,7 +302,7 @@ static unsigned long mmap_rnd(void)
9770
9771 void arch_pick_mmap_layout(struct mm_struct *mm)
9772 {
9773- unsigned long random_factor = mmap_rnd();
9774+ unsigned long random_factor = mmap_rnd(mm);
9775 unsigned long gap;
9776
9777 /*
9778@@ -289,6 +315,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9779 gap == RLIM_INFINITY ||
9780 sysctl_legacy_va_layout) {
9781 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
9782+
9783+#ifdef CONFIG_PAX_RANDMMAP
9784+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9785+ mm->mmap_base += mm->delta_mmap;
9786+#endif
9787+
9788 mm->get_unmapped_area = arch_get_unmapped_area;
9789 } else {
9790 /* We know it's 32-bit */
9791@@ -300,6 +332,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9792 gap = (task_size / 6 * 5);
9793
9794 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
9795+
9796+#ifdef CONFIG_PAX_RANDMMAP
9797+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9798+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9799+#endif
9800+
9801 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9802 }
9803 }
9804diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
9805index 73ec8a7..4611979 100644
9806--- a/arch/sparc/kernel/syscalls.S
9807+++ b/arch/sparc/kernel/syscalls.S
9808@@ -52,7 +52,7 @@ sys32_rt_sigreturn:
9809 #endif
9810 .align 32
9811 1: ldx [%g6 + TI_FLAGS], %l5
9812- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9813+ andcc %l5, _TIF_WORK_SYSCALL, %g0
9814 be,pt %icc, rtrap
9815 nop
9816 call syscall_trace_leave
9817@@ -184,7 +184,7 @@ linux_sparc_syscall32:
9818
9819 srl %i3, 0, %o3 ! IEU0
9820 srl %i2, 0, %o2 ! IEU0 Group
9821- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9822+ andcc %l0, _TIF_WORK_SYSCALL, %g0
9823 bne,pn %icc, linux_syscall_trace32 ! CTI
9824 mov %i0, %l5 ! IEU1
9825 5: call %l7 ! CTI Group brk forced
9826@@ -207,7 +207,7 @@ linux_sparc_syscall:
9827
9828 mov %i3, %o3 ! IEU1
9829 mov %i4, %o4 ! IEU0 Group
9830- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9831+ andcc %l0, _TIF_WORK_SYSCALL, %g0
9832 bne,pn %icc, linux_syscall_trace ! CTI Group
9833 mov %i0, %l5 ! IEU0
9834 2: call %l7 ! CTI Group brk forced
9835@@ -223,7 +223,7 @@ ret_sys_call:
9836
9837 cmp %o0, -ERESTART_RESTARTBLOCK
9838 bgeu,pn %xcc, 1f
9839- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9840+ andcc %l0, _TIF_WORK_SYSCALL, %g0
9841 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
9842
9843 2:
9844diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
9845index 6629829..036032d 100644
9846--- a/arch/sparc/kernel/traps_32.c
9847+++ b/arch/sparc/kernel/traps_32.c
9848@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
9849 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
9850 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
9851
9852+extern void gr_handle_kernel_exploit(void);
9853+
9854 void die_if_kernel(char *str, struct pt_regs *regs)
9855 {
9856 static int die_counter;
9857@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
9858 count++ < 30 &&
9859 (((unsigned long) rw) >= PAGE_OFFSET) &&
9860 !(((unsigned long) rw) & 0x7)) {
9861- printk("Caller[%08lx]: %pS\n", rw->ins[7],
9862+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
9863 (void *) rw->ins[7]);
9864 rw = (struct reg_window32 *)rw->ins[6];
9865 }
9866 }
9867 printk("Instruction DUMP:");
9868 instruction_dump ((unsigned long *) regs->pc);
9869- if(regs->psr & PSR_PS)
9870+ if(regs->psr & PSR_PS) {
9871+ gr_handle_kernel_exploit();
9872 do_exit(SIGKILL);
9873+ }
9874 do_exit(SIGSEGV);
9875 }
9876
9877diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
9878index b3f833a..f485f80 100644
9879--- a/arch/sparc/kernel/traps_64.c
9880+++ b/arch/sparc/kernel/traps_64.c
9881@@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
9882 i + 1,
9883 p->trapstack[i].tstate, p->trapstack[i].tpc,
9884 p->trapstack[i].tnpc, p->trapstack[i].tt);
9885- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
9886+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
9887 }
9888 }
9889
9890@@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
9891
9892 lvl -= 0x100;
9893 if (regs->tstate & TSTATE_PRIV) {
9894+
9895+#ifdef CONFIG_PAX_REFCOUNT
9896+ if (lvl == 6)
9897+ pax_report_refcount_overflow(regs);
9898+#endif
9899+
9900 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
9901 die_if_kernel(buffer, regs);
9902 }
9903@@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
9904 void bad_trap_tl1(struct pt_regs *regs, long lvl)
9905 {
9906 char buffer[32];
9907-
9908+
9909 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
9910 0, lvl, SIGTRAP) == NOTIFY_STOP)
9911 return;
9912
9913+#ifdef CONFIG_PAX_REFCOUNT
9914+ if (lvl == 6)
9915+ pax_report_refcount_overflow(regs);
9916+#endif
9917+
9918 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
9919
9920 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
9921@@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
9922 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
9923 printk("%s" "ERROR(%d): ",
9924 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
9925- printk("TPC<%pS>\n", (void *) regs->tpc);
9926+ printk("TPC<%pA>\n", (void *) regs->tpc);
9927 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
9928 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
9929 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
9930@@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
9931 smp_processor_id(),
9932 (type & 0x1) ? 'I' : 'D',
9933 regs->tpc);
9934- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
9935+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
9936 panic("Irrecoverable Cheetah+ parity error.");
9937 }
9938
9939@@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
9940 smp_processor_id(),
9941 (type & 0x1) ? 'I' : 'D',
9942 regs->tpc);
9943- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
9944+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
9945 }
9946
9947 struct sun4v_error_entry {
9948@@ -1830,8 +1841,8 @@ struct sun4v_error_entry {
9949 /*0x38*/u64 reserved_5;
9950 };
9951
9952-static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
9953-static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
9954+static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
9955+static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
9956
9957 static const char *sun4v_err_type_to_str(u8 type)
9958 {
9959@@ -1923,7 +1934,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
9960 }
9961
9962 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
9963- int cpu, const char *pfx, atomic_t *ocnt)
9964+ int cpu, const char *pfx, atomic_unchecked_t *ocnt)
9965 {
9966 u64 *raw_ptr = (u64 *) ent;
9967 u32 attrs;
9968@@ -1981,8 +1992,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
9969
9970 show_regs(regs);
9971
9972- if ((cnt = atomic_read(ocnt)) != 0) {
9973- atomic_set(ocnt, 0);
9974+ if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
9975+ atomic_set_unchecked(ocnt, 0);
9976 wmb();
9977 printk("%s: Queue overflowed %d times.\n",
9978 pfx, cnt);
9979@@ -2036,7 +2047,7 @@ void sun4v_resum_error(struct pt_regs *regs, unsigned long offset)
9980 */
9981 void sun4v_resum_overflow(struct pt_regs *regs)
9982 {
9983- atomic_inc(&sun4v_resum_oflow_cnt);
9984+ atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
9985 }
9986
9987 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
9988@@ -2089,7 +2100,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
9989 /* XXX Actually even this can make not that much sense. Perhaps
9990 * XXX we should just pull the plug and panic directly from here?
9991 */
9992- atomic_inc(&sun4v_nonresum_oflow_cnt);
9993+ atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
9994 }
9995
9996 unsigned long sun4v_err_itlb_vaddr;
9997@@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
9998
9999 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
10000 regs->tpc, tl);
10001- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
10002+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
10003 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10004- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
10005+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
10006 (void *) regs->u_regs[UREG_I7]);
10007 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
10008 "pte[%lx] error[%lx]\n",
10009@@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
10010
10011 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
10012 regs->tpc, tl);
10013- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
10014+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
10015 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10016- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
10017+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
10018 (void *) regs->u_regs[UREG_I7]);
10019 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
10020 "pte[%lx] error[%lx]\n",
10021@@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10022 fp = (unsigned long)sf->fp + STACK_BIAS;
10023 }
10024
10025- printk(" [%016lx] %pS\n", pc, (void *) pc);
10026+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10027 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
10028 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
10029 int index = tsk->curr_ret_stack;
10030 if (tsk->ret_stack && index >= graph) {
10031 pc = tsk->ret_stack[index - graph].ret;
10032- printk(" [%016lx] %pS\n", pc, (void *) pc);
10033+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10034 graph++;
10035 }
10036 }
10037@@ -2360,6 +2371,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
10038 return (struct reg_window *) (fp + STACK_BIAS);
10039 }
10040
10041+extern void gr_handle_kernel_exploit(void);
10042+
10043 void die_if_kernel(char *str, struct pt_regs *regs)
10044 {
10045 static int die_counter;
10046@@ -2388,7 +2401,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10047 while (rw &&
10048 count++ < 30 &&
10049 kstack_valid(tp, (unsigned long) rw)) {
10050- printk("Caller[%016lx]: %pS\n", rw->ins[7],
10051+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
10052 (void *) rw->ins[7]);
10053
10054 rw = kernel_stack_up(rw);
10055@@ -2401,8 +2414,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10056 }
10057 user_instruction_dump ((unsigned int __user *) regs->tpc);
10058 }
10059- if (regs->tstate & TSTATE_PRIV)
10060+ if (regs->tstate & TSTATE_PRIV) {
10061+ gr_handle_kernel_exploit();
10062 do_exit(SIGKILL);
10063+ }
10064 do_exit(SIGSEGV);
10065 }
10066 EXPORT_SYMBOL(die_if_kernel);
10067diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
10068index 8201c25e..072a2a7 100644
10069--- a/arch/sparc/kernel/unaligned_64.c
10070+++ b/arch/sparc/kernel/unaligned_64.c
10071@@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
10072 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
10073
10074 if (__ratelimit(&ratelimit)) {
10075- printk("Kernel unaligned access at TPC[%lx] %pS\n",
10076+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
10077 regs->tpc, (void *) regs->tpc);
10078 }
10079 }
10080diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
10081index dbe119b..089c7c1 100644
10082--- a/arch/sparc/lib/Makefile
10083+++ b/arch/sparc/lib/Makefile
10084@@ -2,7 +2,7 @@
10085 #
10086
10087 asflags-y := -ansi -DST_DIV0=0x02
10088-ccflags-y := -Werror
10089+#ccflags-y := -Werror
10090
10091 lib-$(CONFIG_SPARC32) += ashrdi3.o
10092 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
10093diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
10094index 85c233d..68500e0 100644
10095--- a/arch/sparc/lib/atomic_64.S
10096+++ b/arch/sparc/lib/atomic_64.S
10097@@ -17,7 +17,12 @@
10098 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10099 BACKOFF_SETUP(%o2)
10100 1: lduw [%o1], %g1
10101- add %g1, %o0, %g7
10102+ addcc %g1, %o0, %g7
10103+
10104+#ifdef CONFIG_PAX_REFCOUNT
10105+ tvs %icc, 6
10106+#endif
10107+
10108 cas [%o1], %g1, %g7
10109 cmp %g1, %g7
10110 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10111@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10112 2: BACKOFF_SPIN(%o2, %o3, 1b)
10113 ENDPROC(atomic_add)
10114
10115+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10116+ BACKOFF_SETUP(%o2)
10117+1: lduw [%o1], %g1
10118+ add %g1, %o0, %g7
10119+ cas [%o1], %g1, %g7
10120+ cmp %g1, %g7
10121+ bne,pn %icc, 2f
10122+ nop
10123+ retl
10124+ nop
10125+2: BACKOFF_SPIN(%o2, %o3, 1b)
10126+ENDPROC(atomic_add_unchecked)
10127+
10128 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10129 BACKOFF_SETUP(%o2)
10130 1: lduw [%o1], %g1
10131- sub %g1, %o0, %g7
10132+ subcc %g1, %o0, %g7
10133+
10134+#ifdef CONFIG_PAX_REFCOUNT
10135+ tvs %icc, 6
10136+#endif
10137+
10138 cas [%o1], %g1, %g7
10139 cmp %g1, %g7
10140 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10141@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10142 2: BACKOFF_SPIN(%o2, %o3, 1b)
10143 ENDPROC(atomic_sub)
10144
10145+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10146+ BACKOFF_SETUP(%o2)
10147+1: lduw [%o1], %g1
10148+ sub %g1, %o0, %g7
10149+ cas [%o1], %g1, %g7
10150+ cmp %g1, %g7
10151+ bne,pn %icc, 2f
10152+ nop
10153+ retl
10154+ nop
10155+2: BACKOFF_SPIN(%o2, %o3, 1b)
10156+ENDPROC(atomic_sub_unchecked)
10157+
10158 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10159 BACKOFF_SETUP(%o2)
10160 1: lduw [%o1], %g1
10161- add %g1, %o0, %g7
10162+ addcc %g1, %o0, %g7
10163+
10164+#ifdef CONFIG_PAX_REFCOUNT
10165+ tvs %icc, 6
10166+#endif
10167+
10168 cas [%o1], %g1, %g7
10169 cmp %g1, %g7
10170 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10171@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10172 2: BACKOFF_SPIN(%o2, %o3, 1b)
10173 ENDPROC(atomic_add_ret)
10174
10175+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10176+ BACKOFF_SETUP(%o2)
10177+1: lduw [%o1], %g1
10178+ addcc %g1, %o0, %g7
10179+ cas [%o1], %g1, %g7
10180+ cmp %g1, %g7
10181+ bne,pn %icc, 2f
10182+ add %g7, %o0, %g7
10183+ sra %g7, 0, %o0
10184+ retl
10185+ nop
10186+2: BACKOFF_SPIN(%o2, %o3, 1b)
10187+ENDPROC(atomic_add_ret_unchecked)
10188+
10189 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10190 BACKOFF_SETUP(%o2)
10191 1: lduw [%o1], %g1
10192- sub %g1, %o0, %g7
10193+ subcc %g1, %o0, %g7
10194+
10195+#ifdef CONFIG_PAX_REFCOUNT
10196+ tvs %icc, 6
10197+#endif
10198+
10199 cas [%o1], %g1, %g7
10200 cmp %g1, %g7
10201 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10202@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
10203 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10204 BACKOFF_SETUP(%o2)
10205 1: ldx [%o1], %g1
10206- add %g1, %o0, %g7
10207+ addcc %g1, %o0, %g7
10208+
10209+#ifdef CONFIG_PAX_REFCOUNT
10210+ tvs %xcc, 6
10211+#endif
10212+
10213 casx [%o1], %g1, %g7
10214 cmp %g1, %g7
10215 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10216@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10217 2: BACKOFF_SPIN(%o2, %o3, 1b)
10218 ENDPROC(atomic64_add)
10219
10220+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10221+ BACKOFF_SETUP(%o2)
10222+1: ldx [%o1], %g1
10223+ addcc %g1, %o0, %g7
10224+ casx [%o1], %g1, %g7
10225+ cmp %g1, %g7
10226+ bne,pn %xcc, 2f
10227+ nop
10228+ retl
10229+ nop
10230+2: BACKOFF_SPIN(%o2, %o3, 1b)
10231+ENDPROC(atomic64_add_unchecked)
10232+
10233 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10234 BACKOFF_SETUP(%o2)
10235 1: ldx [%o1], %g1
10236- sub %g1, %o0, %g7
10237+ subcc %g1, %o0, %g7
10238+
10239+#ifdef CONFIG_PAX_REFCOUNT
10240+ tvs %xcc, 6
10241+#endif
10242+
10243 casx [%o1], %g1, %g7
10244 cmp %g1, %g7
10245 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10246@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10247 2: BACKOFF_SPIN(%o2, %o3, 1b)
10248 ENDPROC(atomic64_sub)
10249
10250+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10251+ BACKOFF_SETUP(%o2)
10252+1: ldx [%o1], %g1
10253+ subcc %g1, %o0, %g7
10254+ casx [%o1], %g1, %g7
10255+ cmp %g1, %g7
10256+ bne,pn %xcc, 2f
10257+ nop
10258+ retl
10259+ nop
10260+2: BACKOFF_SPIN(%o2, %o3, 1b)
10261+ENDPROC(atomic64_sub_unchecked)
10262+
10263 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10264 BACKOFF_SETUP(%o2)
10265 1: ldx [%o1], %g1
10266- add %g1, %o0, %g7
10267+ addcc %g1, %o0, %g7
10268+
10269+#ifdef CONFIG_PAX_REFCOUNT
10270+ tvs %xcc, 6
10271+#endif
10272+
10273 casx [%o1], %g1, %g7
10274 cmp %g1, %g7
10275 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10276@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10277 2: BACKOFF_SPIN(%o2, %o3, 1b)
10278 ENDPROC(atomic64_add_ret)
10279
10280+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10281+ BACKOFF_SETUP(%o2)
10282+1: ldx [%o1], %g1
10283+ addcc %g1, %o0, %g7
10284+ casx [%o1], %g1, %g7
10285+ cmp %g1, %g7
10286+ bne,pn %xcc, 2f
10287+ add %g7, %o0, %g7
10288+ mov %g7, %o0
10289+ retl
10290+ nop
10291+2: BACKOFF_SPIN(%o2, %o3, 1b)
10292+ENDPROC(atomic64_add_ret_unchecked)
10293+
10294 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10295 BACKOFF_SETUP(%o2)
10296 1: ldx [%o1], %g1
10297- sub %g1, %o0, %g7
10298+ subcc %g1, %o0, %g7
10299+
10300+#ifdef CONFIG_PAX_REFCOUNT
10301+ tvs %xcc, 6
10302+#endif
10303+
10304 casx [%o1], %g1, %g7
10305 cmp %g1, %g7
10306 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10307diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
10308index 323335b..ed85ea2 100644
10309--- a/arch/sparc/lib/ksyms.c
10310+++ b/arch/sparc/lib/ksyms.c
10311@@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
10312
10313 /* Atomic counter implementation. */
10314 EXPORT_SYMBOL(atomic_add);
10315+EXPORT_SYMBOL(atomic_add_unchecked);
10316 EXPORT_SYMBOL(atomic_add_ret);
10317+EXPORT_SYMBOL(atomic_add_ret_unchecked);
10318 EXPORT_SYMBOL(atomic_sub);
10319+EXPORT_SYMBOL(atomic_sub_unchecked);
10320 EXPORT_SYMBOL(atomic_sub_ret);
10321 EXPORT_SYMBOL(atomic64_add);
10322+EXPORT_SYMBOL(atomic64_add_unchecked);
10323 EXPORT_SYMBOL(atomic64_add_ret);
10324+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
10325 EXPORT_SYMBOL(atomic64_sub);
10326+EXPORT_SYMBOL(atomic64_sub_unchecked);
10327 EXPORT_SYMBOL(atomic64_sub_ret);
10328 EXPORT_SYMBOL(atomic64_dec_if_positive);
10329
10330diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
10331index 30c3ecc..736f015 100644
10332--- a/arch/sparc/mm/Makefile
10333+++ b/arch/sparc/mm/Makefile
10334@@ -2,7 +2,7 @@
10335 #
10336
10337 asflags-y := -ansi
10338-ccflags-y := -Werror
10339+#ccflags-y := -Werror
10340
10341 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
10342 obj-y += fault_$(BITS).o
10343diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
10344index e98bfda..ea8d221 100644
10345--- a/arch/sparc/mm/fault_32.c
10346+++ b/arch/sparc/mm/fault_32.c
10347@@ -21,6 +21,9 @@
10348 #include <linux/perf_event.h>
10349 #include <linux/interrupt.h>
10350 #include <linux/kdebug.h>
10351+#include <linux/slab.h>
10352+#include <linux/pagemap.h>
10353+#include <linux/compiler.h>
10354
10355 #include <asm/page.h>
10356 #include <asm/pgtable.h>
10357@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
10358 return safe_compute_effective_address(regs, insn);
10359 }
10360
10361+#ifdef CONFIG_PAX_PAGEEXEC
10362+#ifdef CONFIG_PAX_DLRESOLVE
10363+static void pax_emuplt_close(struct vm_area_struct *vma)
10364+{
10365+ vma->vm_mm->call_dl_resolve = 0UL;
10366+}
10367+
10368+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10369+{
10370+ unsigned int *kaddr;
10371+
10372+ vmf->page = alloc_page(GFP_HIGHUSER);
10373+ if (!vmf->page)
10374+ return VM_FAULT_OOM;
10375+
10376+ kaddr = kmap(vmf->page);
10377+ memset(kaddr, 0, PAGE_SIZE);
10378+ kaddr[0] = 0x9DE3BFA8U; /* save */
10379+ flush_dcache_page(vmf->page);
10380+ kunmap(vmf->page);
10381+ return VM_FAULT_MAJOR;
10382+}
10383+
10384+static const struct vm_operations_struct pax_vm_ops = {
10385+ .close = pax_emuplt_close,
10386+ .fault = pax_emuplt_fault
10387+};
10388+
10389+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
10390+{
10391+ int ret;
10392+
10393+ INIT_LIST_HEAD(&vma->anon_vma_chain);
10394+ vma->vm_mm = current->mm;
10395+ vma->vm_start = addr;
10396+ vma->vm_end = addr + PAGE_SIZE;
10397+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
10398+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
10399+ vma->vm_ops = &pax_vm_ops;
10400+
10401+ ret = insert_vm_struct(current->mm, vma);
10402+ if (ret)
10403+ return ret;
10404+
10405+ ++current->mm->total_vm;
10406+ return 0;
10407+}
10408+#endif
10409+
10410+/*
10411+ * PaX: decide what to do with offenders (regs->pc = fault address)
10412+ *
10413+ * returns 1 when task should be killed
10414+ * 2 when patched PLT trampoline was detected
10415+ * 3 when unpatched PLT trampoline was detected
10416+ */
10417+static int pax_handle_fetch_fault(struct pt_regs *regs)
10418+{
10419+
10420+#ifdef CONFIG_PAX_EMUPLT
10421+ int err;
10422+
10423+ do { /* PaX: patched PLT emulation #1 */
10424+ unsigned int sethi1, sethi2, jmpl;
10425+
10426+ err = get_user(sethi1, (unsigned int *)regs->pc);
10427+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
10428+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
10429+
10430+ if (err)
10431+ break;
10432+
10433+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
10434+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
10435+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
10436+ {
10437+ unsigned int addr;
10438+
10439+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
10440+ addr = regs->u_regs[UREG_G1];
10441+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10442+ regs->pc = addr;
10443+ regs->npc = addr+4;
10444+ return 2;
10445+ }
10446+ } while (0);
10447+
10448+ do { /* PaX: patched PLT emulation #2 */
10449+ unsigned int ba;
10450+
10451+ err = get_user(ba, (unsigned int *)regs->pc);
10452+
10453+ if (err)
10454+ break;
10455+
10456+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
10457+ unsigned int addr;
10458+
10459+ if ((ba & 0xFFC00000U) == 0x30800000U)
10460+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
10461+ else
10462+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10463+ regs->pc = addr;
10464+ regs->npc = addr+4;
10465+ return 2;
10466+ }
10467+ } while (0);
10468+
10469+ do { /* PaX: patched PLT emulation #3 */
10470+ unsigned int sethi, bajmpl, nop;
10471+
10472+ err = get_user(sethi, (unsigned int *)regs->pc);
10473+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
10474+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
10475+
10476+ if (err)
10477+ break;
10478+
10479+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10480+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
10481+ nop == 0x01000000U)
10482+ {
10483+ unsigned int addr;
10484+
10485+ addr = (sethi & 0x003FFFFFU) << 10;
10486+ regs->u_regs[UREG_G1] = addr;
10487+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
10488+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10489+ else
10490+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10491+ regs->pc = addr;
10492+ regs->npc = addr+4;
10493+ return 2;
10494+ }
10495+ } while (0);
10496+
10497+ do { /* PaX: unpatched PLT emulation step 1 */
10498+ unsigned int sethi, ba, nop;
10499+
10500+ err = get_user(sethi, (unsigned int *)regs->pc);
10501+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
10502+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
10503+
10504+ if (err)
10505+ break;
10506+
10507+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10508+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
10509+ nop == 0x01000000U)
10510+ {
10511+ unsigned int addr, save, call;
10512+
10513+ if ((ba & 0xFFC00000U) == 0x30800000U)
10514+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
10515+ else
10516+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10517+
10518+ err = get_user(save, (unsigned int *)addr);
10519+ err |= get_user(call, (unsigned int *)(addr+4));
10520+ err |= get_user(nop, (unsigned int *)(addr+8));
10521+ if (err)
10522+ break;
10523+
10524+#ifdef CONFIG_PAX_DLRESOLVE
10525+ if (save == 0x9DE3BFA8U &&
10526+ (call & 0xC0000000U) == 0x40000000U &&
10527+ nop == 0x01000000U)
10528+ {
10529+ struct vm_area_struct *vma;
10530+ unsigned long call_dl_resolve;
10531+
10532+ down_read(&current->mm->mmap_sem);
10533+ call_dl_resolve = current->mm->call_dl_resolve;
10534+ up_read(&current->mm->mmap_sem);
10535+ if (likely(call_dl_resolve))
10536+ goto emulate;
10537+
10538+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
10539+
10540+ down_write(&current->mm->mmap_sem);
10541+ if (current->mm->call_dl_resolve) {
10542+ call_dl_resolve = current->mm->call_dl_resolve;
10543+ up_write(&current->mm->mmap_sem);
10544+ if (vma)
10545+ kmem_cache_free(vm_area_cachep, vma);
10546+ goto emulate;
10547+ }
10548+
10549+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
10550+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
10551+ up_write(&current->mm->mmap_sem);
10552+ if (vma)
10553+ kmem_cache_free(vm_area_cachep, vma);
10554+ return 1;
10555+ }
10556+
10557+ if (pax_insert_vma(vma, call_dl_resolve)) {
10558+ up_write(&current->mm->mmap_sem);
10559+ kmem_cache_free(vm_area_cachep, vma);
10560+ return 1;
10561+ }
10562+
10563+ current->mm->call_dl_resolve = call_dl_resolve;
10564+ up_write(&current->mm->mmap_sem);
10565+
10566+emulate:
10567+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10568+ regs->pc = call_dl_resolve;
10569+ regs->npc = addr+4;
10570+ return 3;
10571+ }
10572+#endif
10573+
10574+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
10575+ if ((save & 0xFFC00000U) == 0x05000000U &&
10576+ (call & 0xFFFFE000U) == 0x85C0A000U &&
10577+ nop == 0x01000000U)
10578+ {
10579+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10580+ regs->u_regs[UREG_G2] = addr + 4;
10581+ addr = (save & 0x003FFFFFU) << 10;
10582+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10583+ regs->pc = addr;
10584+ regs->npc = addr+4;
10585+ return 3;
10586+ }
10587+ }
10588+ } while (0);
10589+
10590+ do { /* PaX: unpatched PLT emulation step 2 */
10591+ unsigned int save, call, nop;
10592+
10593+ err = get_user(save, (unsigned int *)(regs->pc-4));
10594+ err |= get_user(call, (unsigned int *)regs->pc);
10595+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
10596+ if (err)
10597+ break;
10598+
10599+ if (save == 0x9DE3BFA8U &&
10600+ (call & 0xC0000000U) == 0x40000000U &&
10601+ nop == 0x01000000U)
10602+ {
10603+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
10604+
10605+ regs->u_regs[UREG_RETPC] = regs->pc;
10606+ regs->pc = dl_resolve;
10607+ regs->npc = dl_resolve+4;
10608+ return 3;
10609+ }
10610+ } while (0);
10611+#endif
10612+
10613+ return 1;
10614+}
10615+
10616+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
10617+{
10618+ unsigned long i;
10619+
10620+ printk(KERN_ERR "PAX: bytes at PC: ");
10621+ for (i = 0; i < 8; i++) {
10622+ unsigned int c;
10623+ if (get_user(c, (unsigned int *)pc+i))
10624+ printk(KERN_CONT "???????? ");
10625+ else
10626+ printk(KERN_CONT "%08x ", c);
10627+ }
10628+ printk("\n");
10629+}
10630+#endif
10631+
10632 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
10633 int text_fault)
10634 {
10635@@ -230,6 +504,24 @@ good_area:
10636 if (!(vma->vm_flags & VM_WRITE))
10637 goto bad_area;
10638 } else {
10639+
10640+#ifdef CONFIG_PAX_PAGEEXEC
10641+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
10642+ up_read(&mm->mmap_sem);
10643+ switch (pax_handle_fetch_fault(regs)) {
10644+
10645+#ifdef CONFIG_PAX_EMUPLT
10646+ case 2:
10647+ case 3:
10648+ return;
10649+#endif
10650+
10651+ }
10652+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
10653+ do_group_exit(SIGKILL);
10654+ }
10655+#endif
10656+
10657 /* Allow reads even for write-only mappings */
10658 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
10659 goto bad_area;
10660diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
10661index 5062ff3..e0b75f3 100644
10662--- a/arch/sparc/mm/fault_64.c
10663+++ b/arch/sparc/mm/fault_64.c
10664@@ -21,6 +21,9 @@
10665 #include <linux/kprobes.h>
10666 #include <linux/kdebug.h>
10667 #include <linux/percpu.h>
10668+#include <linux/slab.h>
10669+#include <linux/pagemap.h>
10670+#include <linux/compiler.h>
10671
10672 #include <asm/page.h>
10673 #include <asm/pgtable.h>
10674@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
10675 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
10676 regs->tpc);
10677 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
10678- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
10679+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
10680 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
10681 dump_stack();
10682 unhandled_fault(regs->tpc, current, regs);
10683@@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
10684 show_regs(regs);
10685 }
10686
10687+#ifdef CONFIG_PAX_PAGEEXEC
10688+#ifdef CONFIG_PAX_DLRESOLVE
10689+static void pax_emuplt_close(struct vm_area_struct *vma)
10690+{
10691+ vma->vm_mm->call_dl_resolve = 0UL;
10692+}
10693+
10694+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10695+{
10696+ unsigned int *kaddr;
10697+
10698+ vmf->page = alloc_page(GFP_HIGHUSER);
10699+ if (!vmf->page)
10700+ return VM_FAULT_OOM;
10701+
10702+ kaddr = kmap(vmf->page);
10703+ memset(kaddr, 0, PAGE_SIZE);
10704+ kaddr[0] = 0x9DE3BFA8U; /* save */
10705+ flush_dcache_page(vmf->page);
10706+ kunmap(vmf->page);
10707+ return VM_FAULT_MAJOR;
10708+}
10709+
10710+static const struct vm_operations_struct pax_vm_ops = {
10711+ .close = pax_emuplt_close,
10712+ .fault = pax_emuplt_fault
10713+};
10714+
10715+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
10716+{
10717+ int ret;
10718+
10719+ INIT_LIST_HEAD(&vma->anon_vma_chain);
10720+ vma->vm_mm = current->mm;
10721+ vma->vm_start = addr;
10722+ vma->vm_end = addr + PAGE_SIZE;
10723+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
10724+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
10725+ vma->vm_ops = &pax_vm_ops;
10726+
10727+ ret = insert_vm_struct(current->mm, vma);
10728+ if (ret)
10729+ return ret;
10730+
10731+ ++current->mm->total_vm;
10732+ return 0;
10733+}
10734+#endif
10735+
10736+/*
10737+ * PaX: decide what to do with offenders (regs->tpc = fault address)
10738+ *
10739+ * returns 1 when task should be killed
10740+ * 2 when patched PLT trampoline was detected
10741+ * 3 when unpatched PLT trampoline was detected
10742+ */
10743+static int pax_handle_fetch_fault(struct pt_regs *regs)
10744+{
10745+
10746+#ifdef CONFIG_PAX_EMUPLT
10747+ int err;
10748+
10749+ do { /* PaX: patched PLT emulation #1 */
10750+ unsigned int sethi1, sethi2, jmpl;
10751+
10752+ err = get_user(sethi1, (unsigned int *)regs->tpc);
10753+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
10754+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
10755+
10756+ if (err)
10757+ break;
10758+
10759+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
10760+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
10761+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
10762+ {
10763+ unsigned long addr;
10764+
10765+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
10766+ addr = regs->u_regs[UREG_G1];
10767+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
10768+
10769+ if (test_thread_flag(TIF_32BIT))
10770+ addr &= 0xFFFFFFFFUL;
10771+
10772+ regs->tpc = addr;
10773+ regs->tnpc = addr+4;
10774+ return 2;
10775+ }
10776+ } while (0);
10777+
10778+ do { /* PaX: patched PLT emulation #2 */
10779+ unsigned int ba;
10780+
10781+ err = get_user(ba, (unsigned int *)regs->tpc);
10782+
10783+ if (err)
10784+ break;
10785+
10786+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
10787+ unsigned long addr;
10788+
10789+ if ((ba & 0xFFC00000U) == 0x30800000U)
10790+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
10791+ else
10792+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10793+
10794+ if (test_thread_flag(TIF_32BIT))
10795+ addr &= 0xFFFFFFFFUL;
10796+
10797+ regs->tpc = addr;
10798+ regs->tnpc = addr+4;
10799+ return 2;
10800+ }
10801+ } while (0);
10802+
10803+ do { /* PaX: patched PLT emulation #3 */
10804+ unsigned int sethi, bajmpl, nop;
10805+
10806+ err = get_user(sethi, (unsigned int *)regs->tpc);
10807+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
10808+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
10809+
10810+ if (err)
10811+ break;
10812+
10813+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10814+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
10815+ nop == 0x01000000U)
10816+ {
10817+ unsigned long addr;
10818+
10819+ addr = (sethi & 0x003FFFFFU) << 10;
10820+ regs->u_regs[UREG_G1] = addr;
10821+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
10822+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
10823+ else
10824+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10825+
10826+ if (test_thread_flag(TIF_32BIT))
10827+ addr &= 0xFFFFFFFFUL;
10828+
10829+ regs->tpc = addr;
10830+ regs->tnpc = addr+4;
10831+ return 2;
10832+ }
10833+ } while (0);
10834+
10835+ do { /* PaX: patched PLT emulation #4 */
10836+ unsigned int sethi, mov1, call, mov2;
10837+
10838+ err = get_user(sethi, (unsigned int *)regs->tpc);
10839+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
10840+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
10841+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
10842+
10843+ if (err)
10844+ break;
10845+
10846+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10847+ mov1 == 0x8210000FU &&
10848+ (call & 0xC0000000U) == 0x40000000U &&
10849+ mov2 == 0x9E100001U)
10850+ {
10851+ unsigned long addr;
10852+
10853+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
10854+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
10855+
10856+ if (test_thread_flag(TIF_32BIT))
10857+ addr &= 0xFFFFFFFFUL;
10858+
10859+ regs->tpc = addr;
10860+ regs->tnpc = addr+4;
10861+ return 2;
10862+ }
10863+ } while (0);
10864+
10865+ do { /* PaX: patched PLT emulation #5 */
10866+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
10867+
10868+ err = get_user(sethi, (unsigned int *)regs->tpc);
10869+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
10870+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
10871+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
10872+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
10873+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
10874+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
10875+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
10876+
10877+ if (err)
10878+ break;
10879+
10880+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10881+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
10882+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
10883+ (or1 & 0xFFFFE000U) == 0x82106000U &&
10884+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
10885+ sllx == 0x83287020U &&
10886+ jmpl == 0x81C04005U &&
10887+ nop == 0x01000000U)
10888+ {
10889+ unsigned long addr;
10890+
10891+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
10892+ regs->u_regs[UREG_G1] <<= 32;
10893+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
10894+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
10895+ regs->tpc = addr;
10896+ regs->tnpc = addr+4;
10897+ return 2;
10898+ }
10899+ } while (0);
10900+
10901+ do { /* PaX: patched PLT emulation #6 */
10902+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
10903+
10904+ err = get_user(sethi, (unsigned int *)regs->tpc);
10905+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
10906+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
10907+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
10908+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
10909+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
10910+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
10911+
10912+ if (err)
10913+ break;
10914+
10915+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10916+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
10917+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
10918+ sllx == 0x83287020U &&
10919+ (or & 0xFFFFE000U) == 0x8A116000U &&
10920+ jmpl == 0x81C04005U &&
10921+ nop == 0x01000000U)
10922+ {
10923+ unsigned long addr;
10924+
10925+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
10926+ regs->u_regs[UREG_G1] <<= 32;
10927+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
10928+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
10929+ regs->tpc = addr;
10930+ regs->tnpc = addr+4;
10931+ return 2;
10932+ }
10933+ } while (0);
10934+
10935+ do { /* PaX: unpatched PLT emulation step 1 */
10936+ unsigned int sethi, ba, nop;
10937+
10938+ err = get_user(sethi, (unsigned int *)regs->tpc);
10939+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
10940+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
10941+
10942+ if (err)
10943+ break;
10944+
10945+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10946+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
10947+ nop == 0x01000000U)
10948+ {
10949+ unsigned long addr;
10950+ unsigned int save, call;
10951+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
10952+
10953+ if ((ba & 0xFFC00000U) == 0x30800000U)
10954+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
10955+ else
10956+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10957+
10958+ if (test_thread_flag(TIF_32BIT))
10959+ addr &= 0xFFFFFFFFUL;
10960+
10961+ err = get_user(save, (unsigned int *)addr);
10962+ err |= get_user(call, (unsigned int *)(addr+4));
10963+ err |= get_user(nop, (unsigned int *)(addr+8));
10964+ if (err)
10965+ break;
10966+
10967+#ifdef CONFIG_PAX_DLRESOLVE
10968+ if (save == 0x9DE3BFA8U &&
10969+ (call & 0xC0000000U) == 0x40000000U &&
10970+ nop == 0x01000000U)
10971+ {
10972+ struct vm_area_struct *vma;
10973+ unsigned long call_dl_resolve;
10974+
10975+ down_read(&current->mm->mmap_sem);
10976+ call_dl_resolve = current->mm->call_dl_resolve;
10977+ up_read(&current->mm->mmap_sem);
10978+ if (likely(call_dl_resolve))
10979+ goto emulate;
10980+
10981+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
10982+
10983+ down_write(&current->mm->mmap_sem);
10984+ if (current->mm->call_dl_resolve) {
10985+ call_dl_resolve = current->mm->call_dl_resolve;
10986+ up_write(&current->mm->mmap_sem);
10987+ if (vma)
10988+ kmem_cache_free(vm_area_cachep, vma);
10989+ goto emulate;
10990+ }
10991+
10992+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
10993+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
10994+ up_write(&current->mm->mmap_sem);
10995+ if (vma)
10996+ kmem_cache_free(vm_area_cachep, vma);
10997+ return 1;
10998+ }
10999+
11000+ if (pax_insert_vma(vma, call_dl_resolve)) {
11001+ up_write(&current->mm->mmap_sem);
11002+ kmem_cache_free(vm_area_cachep, vma);
11003+ return 1;
11004+ }
11005+
11006+ current->mm->call_dl_resolve = call_dl_resolve;
11007+ up_write(&current->mm->mmap_sem);
11008+
11009+emulate:
11010+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11011+ regs->tpc = call_dl_resolve;
11012+ regs->tnpc = addr+4;
11013+ return 3;
11014+ }
11015+#endif
11016+
11017+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11018+ if ((save & 0xFFC00000U) == 0x05000000U &&
11019+ (call & 0xFFFFE000U) == 0x85C0A000U &&
11020+ nop == 0x01000000U)
11021+ {
11022+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11023+ regs->u_regs[UREG_G2] = addr + 4;
11024+ addr = (save & 0x003FFFFFU) << 10;
11025+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11026+
11027+ if (test_thread_flag(TIF_32BIT))
11028+ addr &= 0xFFFFFFFFUL;
11029+
11030+ regs->tpc = addr;
11031+ regs->tnpc = addr+4;
11032+ return 3;
11033+ }
11034+
11035+ /* PaX: 64-bit PLT stub */
11036+ err = get_user(sethi1, (unsigned int *)addr);
11037+ err |= get_user(sethi2, (unsigned int *)(addr+4));
11038+ err |= get_user(or1, (unsigned int *)(addr+8));
11039+ err |= get_user(or2, (unsigned int *)(addr+12));
11040+ err |= get_user(sllx, (unsigned int *)(addr+16));
11041+ err |= get_user(add, (unsigned int *)(addr+20));
11042+ err |= get_user(jmpl, (unsigned int *)(addr+24));
11043+ err |= get_user(nop, (unsigned int *)(addr+28));
11044+ if (err)
11045+ break;
11046+
11047+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
11048+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11049+ (or1 & 0xFFFFE000U) == 0x88112000U &&
11050+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
11051+ sllx == 0x89293020U &&
11052+ add == 0x8A010005U &&
11053+ jmpl == 0x89C14000U &&
11054+ nop == 0x01000000U)
11055+ {
11056+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11057+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11058+ regs->u_regs[UREG_G4] <<= 32;
11059+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11060+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
11061+ regs->u_regs[UREG_G4] = addr + 24;
11062+ addr = regs->u_regs[UREG_G5];
11063+ regs->tpc = addr;
11064+ regs->tnpc = addr+4;
11065+ return 3;
11066+ }
11067+ }
11068+ } while (0);
11069+
11070+#ifdef CONFIG_PAX_DLRESOLVE
11071+ do { /* PaX: unpatched PLT emulation step 2 */
11072+ unsigned int save, call, nop;
11073+
11074+ err = get_user(save, (unsigned int *)(regs->tpc-4));
11075+ err |= get_user(call, (unsigned int *)regs->tpc);
11076+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
11077+ if (err)
11078+ break;
11079+
11080+ if (save == 0x9DE3BFA8U &&
11081+ (call & 0xC0000000U) == 0x40000000U &&
11082+ nop == 0x01000000U)
11083+ {
11084+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11085+
11086+ if (test_thread_flag(TIF_32BIT))
11087+ dl_resolve &= 0xFFFFFFFFUL;
11088+
11089+ regs->u_regs[UREG_RETPC] = regs->tpc;
11090+ regs->tpc = dl_resolve;
11091+ regs->tnpc = dl_resolve+4;
11092+ return 3;
11093+ }
11094+ } while (0);
11095+#endif
11096+
11097+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
11098+ unsigned int sethi, ba, nop;
11099+
11100+ err = get_user(sethi, (unsigned int *)regs->tpc);
11101+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11102+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11103+
11104+ if (err)
11105+ break;
11106+
11107+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11108+ (ba & 0xFFF00000U) == 0x30600000U &&
11109+ nop == 0x01000000U)
11110+ {
11111+ unsigned long addr;
11112+
11113+ addr = (sethi & 0x003FFFFFU) << 10;
11114+ regs->u_regs[UREG_G1] = addr;
11115+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11116+
11117+ if (test_thread_flag(TIF_32BIT))
11118+ addr &= 0xFFFFFFFFUL;
11119+
11120+ regs->tpc = addr;
11121+ regs->tnpc = addr+4;
11122+ return 2;
11123+ }
11124+ } while (0);
11125+
11126+#endif
11127+
11128+ return 1;
11129+}
11130+
11131+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11132+{
11133+ unsigned long i;
11134+
11135+ printk(KERN_ERR "PAX: bytes at PC: ");
11136+ for (i = 0; i < 8; i++) {
11137+ unsigned int c;
11138+ if (get_user(c, (unsigned int *)pc+i))
11139+ printk(KERN_CONT "???????? ");
11140+ else
11141+ printk(KERN_CONT "%08x ", c);
11142+ }
11143+ printk("\n");
11144+}
11145+#endif
11146+
11147 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
11148 {
11149 struct mm_struct *mm = current->mm;
11150@@ -341,6 +804,29 @@ retry:
11151 if (!vma)
11152 goto bad_area;
11153
11154+#ifdef CONFIG_PAX_PAGEEXEC
11155+ /* PaX: detect ITLB misses on non-exec pages */
11156+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
11157+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
11158+ {
11159+ if (address != regs->tpc)
11160+ goto good_area;
11161+
11162+ up_read(&mm->mmap_sem);
11163+ switch (pax_handle_fetch_fault(regs)) {
11164+
11165+#ifdef CONFIG_PAX_EMUPLT
11166+ case 2:
11167+ case 3:
11168+ return;
11169+#endif
11170+
11171+ }
11172+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
11173+ do_group_exit(SIGKILL);
11174+ }
11175+#endif
11176+
11177 /* Pure DTLB misses do not tell us whether the fault causing
11178 * load/store/atomic was a write or not, it only says that there
11179 * was no match. So in such a case we (carefully) read the
11180diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
11181index d2b5944..d878f3c 100644
11182--- a/arch/sparc/mm/hugetlbpage.c
11183+++ b/arch/sparc/mm/hugetlbpage.c
11184@@ -28,7 +28,8 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11185 unsigned long addr,
11186 unsigned long len,
11187 unsigned long pgoff,
11188- unsigned long flags)
11189+ unsigned long flags,
11190+ unsigned long offset)
11191 {
11192 unsigned long task_size = TASK_SIZE;
11193 struct vm_unmapped_area_info info;
11194@@ -38,15 +39,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11195
11196 info.flags = 0;
11197 info.length = len;
11198- info.low_limit = TASK_UNMAPPED_BASE;
11199+ info.low_limit = mm->mmap_base;
11200 info.high_limit = min(task_size, VA_EXCLUDE_START);
11201 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11202 info.align_offset = 0;
11203+ info.threadstack_offset = offset;
11204 addr = vm_unmapped_area(&info);
11205
11206 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
11207 VM_BUG_ON(addr != -ENOMEM);
11208 info.low_limit = VA_EXCLUDE_END;
11209+
11210+#ifdef CONFIG_PAX_RANDMMAP
11211+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11212+ info.low_limit += mm->delta_mmap;
11213+#endif
11214+
11215 info.high_limit = task_size;
11216 addr = vm_unmapped_area(&info);
11217 }
11218@@ -58,7 +66,8 @@ static unsigned long
11219 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11220 const unsigned long len,
11221 const unsigned long pgoff,
11222- const unsigned long flags)
11223+ const unsigned long flags,
11224+ const unsigned long offset)
11225 {
11226 struct mm_struct *mm = current->mm;
11227 unsigned long addr = addr0;
11228@@ -73,6 +82,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11229 info.high_limit = mm->mmap_base;
11230 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11231 info.align_offset = 0;
11232+ info.threadstack_offset = offset;
11233 addr = vm_unmapped_area(&info);
11234
11235 /*
11236@@ -85,6 +95,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11237 VM_BUG_ON(addr != -ENOMEM);
11238 info.flags = 0;
11239 info.low_limit = TASK_UNMAPPED_BASE;
11240+
11241+#ifdef CONFIG_PAX_RANDMMAP
11242+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11243+ info.low_limit += mm->delta_mmap;
11244+#endif
11245+
11246 info.high_limit = STACK_TOP32;
11247 addr = vm_unmapped_area(&info);
11248 }
11249@@ -99,6 +115,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11250 struct mm_struct *mm = current->mm;
11251 struct vm_area_struct *vma;
11252 unsigned long task_size = TASK_SIZE;
11253+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
11254
11255 if (test_thread_flag(TIF_32BIT))
11256 task_size = STACK_TOP32;
11257@@ -114,19 +131,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11258 return addr;
11259 }
11260
11261+#ifdef CONFIG_PAX_RANDMMAP
11262+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11263+#endif
11264+
11265 if (addr) {
11266 addr = ALIGN(addr, HPAGE_SIZE);
11267 vma = find_vma(mm, addr);
11268- if (task_size - len >= addr &&
11269- (!vma || addr + len <= vma->vm_start))
11270+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
11271 return addr;
11272 }
11273 if (mm->get_unmapped_area == arch_get_unmapped_area)
11274 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
11275- pgoff, flags);
11276+ pgoff, flags, offset);
11277 else
11278 return hugetlb_get_unmapped_area_topdown(file, addr, len,
11279- pgoff, flags);
11280+ pgoff, flags, offset);
11281 }
11282
11283 pte_t *huge_pte_alloc(struct mm_struct *mm,
11284diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
11285index ed82eda..0d80e77 100644
11286--- a/arch/sparc/mm/init_64.c
11287+++ b/arch/sparc/mm/init_64.c
11288@@ -188,9 +188,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
11289 int num_kernel_image_mappings;
11290
11291 #ifdef CONFIG_DEBUG_DCFLUSH
11292-atomic_t dcpage_flushes = ATOMIC_INIT(0);
11293+atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
11294 #ifdef CONFIG_SMP
11295-atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11296+atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11297 #endif
11298 #endif
11299
11300@@ -198,7 +198,7 @@ inline void flush_dcache_page_impl(struct page *page)
11301 {
11302 BUG_ON(tlb_type == hypervisor);
11303 #ifdef CONFIG_DEBUG_DCFLUSH
11304- atomic_inc(&dcpage_flushes);
11305+ atomic_inc_unchecked(&dcpage_flushes);
11306 #endif
11307
11308 #ifdef DCACHE_ALIASING_POSSIBLE
11309@@ -466,10 +466,10 @@ void mmu_info(struct seq_file *m)
11310
11311 #ifdef CONFIG_DEBUG_DCFLUSH
11312 seq_printf(m, "DCPageFlushes\t: %d\n",
11313- atomic_read(&dcpage_flushes));
11314+ atomic_read_unchecked(&dcpage_flushes));
11315 #ifdef CONFIG_SMP
11316 seq_printf(m, "DCPageFlushesXC\t: %d\n",
11317- atomic_read(&dcpage_flushes_xcall));
11318+ atomic_read_unchecked(&dcpage_flushes_xcall));
11319 #endif /* CONFIG_SMP */
11320 #endif /* CONFIG_DEBUG_DCFLUSH */
11321 }
11322diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
11323index f4500c6..889656c 100644
11324--- a/arch/tile/include/asm/atomic_64.h
11325+++ b/arch/tile/include/asm/atomic_64.h
11326@@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
11327
11328 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
11329
11330+#define atomic64_read_unchecked(v) atomic64_read(v)
11331+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
11332+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
11333+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
11334+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
11335+#define atomic64_inc_unchecked(v) atomic64_inc(v)
11336+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
11337+#define atomic64_dec_unchecked(v) atomic64_dec(v)
11338+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
11339+
11340 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
11341 #define smp_mb__before_atomic_dec() smp_mb()
11342 #define smp_mb__after_atomic_dec() smp_mb()
11343diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
11344index a9a5299..0fce79e 100644
11345--- a/arch/tile/include/asm/cache.h
11346+++ b/arch/tile/include/asm/cache.h
11347@@ -15,11 +15,12 @@
11348 #ifndef _ASM_TILE_CACHE_H
11349 #define _ASM_TILE_CACHE_H
11350
11351+#include <linux/const.h>
11352 #include <arch/chip.h>
11353
11354 /* bytes per L1 data cache line */
11355 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
11356-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11357+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11358
11359 /* bytes per L2 cache line */
11360 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
11361diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
11362index e4d44bd..99927a3 100644
11363--- a/arch/tile/include/asm/uaccess.h
11364+++ b/arch/tile/include/asm/uaccess.h
11365@@ -408,9 +408,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
11366 const void __user *from,
11367 unsigned long n)
11368 {
11369- int sz = __compiletime_object_size(to);
11370+ size_t sz = __compiletime_object_size(to);
11371
11372- if (likely(sz == -1 || sz >= n))
11373+ if (likely(sz == (size_t)-1 || sz >= n))
11374 n = _copy_from_user(to, from, n);
11375 else
11376 copy_from_user_overflow();
11377diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
11378index 650ccff..45fe2d6 100644
11379--- a/arch/tile/mm/hugetlbpage.c
11380+++ b/arch/tile/mm/hugetlbpage.c
11381@@ -239,6 +239,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
11382 info.high_limit = TASK_SIZE;
11383 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
11384 info.align_offset = 0;
11385+ info.threadstack_offset = 0;
11386 return vm_unmapped_area(&info);
11387 }
11388
11389@@ -256,6 +257,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
11390 info.high_limit = current->mm->mmap_base;
11391 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
11392 info.align_offset = 0;
11393+ info.threadstack_offset = 0;
11394 addr = vm_unmapped_area(&info);
11395
11396 /*
11397diff --git a/arch/um/Makefile b/arch/um/Makefile
11398index 133f7de..1d6f2f1 100644
11399--- a/arch/um/Makefile
11400+++ b/arch/um/Makefile
11401@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
11402 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
11403 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
11404
11405+ifdef CONSTIFY_PLUGIN
11406+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11407+endif
11408+
11409 #This will adjust *FLAGS accordingly to the platform.
11410 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
11411
11412diff --git a/arch/um/defconfig b/arch/um/defconfig
11413index 08107a7..ab22afe 100644
11414--- a/arch/um/defconfig
11415+++ b/arch/um/defconfig
11416@@ -51,7 +51,6 @@ CONFIG_X86_CMPXCHG=y
11417 CONFIG_X86_L1_CACHE_SHIFT=5
11418 CONFIG_X86_XADD=y
11419 CONFIG_X86_PPRO_FENCE=y
11420-CONFIG_X86_WP_WORKS_OK=y
11421 CONFIG_X86_INVLPG=y
11422 CONFIG_X86_BSWAP=y
11423 CONFIG_X86_POPAD_OK=y
11424diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
11425index 19e1bdd..3665b77 100644
11426--- a/arch/um/include/asm/cache.h
11427+++ b/arch/um/include/asm/cache.h
11428@@ -1,6 +1,7 @@
11429 #ifndef __UM_CACHE_H
11430 #define __UM_CACHE_H
11431
11432+#include <linux/const.h>
11433
11434 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
11435 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
11436@@ -12,6 +13,6 @@
11437 # define L1_CACHE_SHIFT 5
11438 #endif
11439
11440-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11441+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11442
11443 #endif
11444diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
11445index 2e0a6b1..a64d0f5 100644
11446--- a/arch/um/include/asm/kmap_types.h
11447+++ b/arch/um/include/asm/kmap_types.h
11448@@ -8,6 +8,6 @@
11449
11450 /* No more #include "asm/arch/kmap_types.h" ! */
11451
11452-#define KM_TYPE_NR 14
11453+#define KM_TYPE_NR 15
11454
11455 #endif
11456diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
11457index 5ff53d9..5850cdf 100644
11458--- a/arch/um/include/asm/page.h
11459+++ b/arch/um/include/asm/page.h
11460@@ -14,6 +14,9 @@
11461 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
11462 #define PAGE_MASK (~(PAGE_SIZE-1))
11463
11464+#define ktla_ktva(addr) (addr)
11465+#define ktva_ktla(addr) (addr)
11466+
11467 #ifndef __ASSEMBLY__
11468
11469 struct page;
11470diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
11471index 0032f92..cd151e0 100644
11472--- a/arch/um/include/asm/pgtable-3level.h
11473+++ b/arch/um/include/asm/pgtable-3level.h
11474@@ -58,6 +58,7 @@
11475 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
11476 #define pud_populate(mm, pud, pmd) \
11477 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
11478+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
11479
11480 #ifdef CONFIG_64BIT
11481 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
11482diff --git a/arch/um/kernel/exitcode.c b/arch/um/kernel/exitcode.c
11483index 829df49..41ebbfe 100644
11484--- a/arch/um/kernel/exitcode.c
11485+++ b/arch/um/kernel/exitcode.c
11486@@ -40,9 +40,11 @@ static ssize_t exitcode_proc_write(struct file *file,
11487 const char __user *buffer, size_t count, loff_t *pos)
11488 {
11489 char *end, buf[sizeof("nnnnn\0")];
11490+ size_t size;
11491 int tmp;
11492
11493- if (copy_from_user(buf, buffer, count))
11494+ size = min(count, sizeof(buf));
11495+ if (copy_from_user(buf, buffer, size))
11496 return -EFAULT;
11497
11498 tmp = simple_strtol(buf, &end, 0);
11499diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
11500index bbcef52..6a2a483 100644
11501--- a/arch/um/kernel/process.c
11502+++ b/arch/um/kernel/process.c
11503@@ -367,22 +367,6 @@ int singlestepping(void * t)
11504 return 2;
11505 }
11506
11507-/*
11508- * Only x86 and x86_64 have an arch_align_stack().
11509- * All other arches have "#define arch_align_stack(x) (x)"
11510- * in their asm/system.h
11511- * As this is included in UML from asm-um/system-generic.h,
11512- * we can use it to behave as the subarch does.
11513- */
11514-#ifndef arch_align_stack
11515-unsigned long arch_align_stack(unsigned long sp)
11516-{
11517- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
11518- sp -= get_random_int() % 8192;
11519- return sp & ~0xf;
11520-}
11521-#endif
11522-
11523 unsigned long get_wchan(struct task_struct *p)
11524 {
11525 unsigned long stack_page, sp, ip;
11526diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
11527index ad8f795..2c7eec6 100644
11528--- a/arch/unicore32/include/asm/cache.h
11529+++ b/arch/unicore32/include/asm/cache.h
11530@@ -12,8 +12,10 @@
11531 #ifndef __UNICORE_CACHE_H__
11532 #define __UNICORE_CACHE_H__
11533
11534-#define L1_CACHE_SHIFT (5)
11535-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11536+#include <linux/const.h>
11537+
11538+#define L1_CACHE_SHIFT 5
11539+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11540
11541 /*
11542 * Memory returned by kmalloc() may be used for DMA, so we must make
11543diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
11544index b32ebf9..5704f98 100644
11545--- a/arch/x86/Kconfig
11546+++ b/arch/x86/Kconfig
11547@@ -248,7 +248,7 @@ config X86_HT
11548
11549 config X86_32_LAZY_GS
11550 def_bool y
11551- depends on X86_32 && !CC_STACKPROTECTOR
11552+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
11553
11554 config ARCH_HWEIGHT_CFLAGS
11555 string
11556@@ -1088,6 +1088,7 @@ config MICROCODE_EARLY
11557
11558 config X86_MSR
11559 tristate "/dev/cpu/*/msr - Model-specific register support"
11560+ depends on !GRKERNSEC_KMEM
11561 ---help---
11562 This device gives privileged processes access to the x86
11563 Model-Specific Registers (MSRs). It is a character device with
11564@@ -1111,7 +1112,7 @@ choice
11565
11566 config NOHIGHMEM
11567 bool "off"
11568- depends on !X86_NUMAQ
11569+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
11570 ---help---
11571 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
11572 However, the address space of 32-bit x86 processors is only 4
11573@@ -1148,7 +1149,7 @@ config NOHIGHMEM
11574
11575 config HIGHMEM4G
11576 bool "4GB"
11577- depends on !X86_NUMAQ
11578+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
11579 ---help---
11580 Select this if you have a 32-bit processor and between 1 and 4
11581 gigabytes of physical RAM.
11582@@ -1201,7 +1202,7 @@ config PAGE_OFFSET
11583 hex
11584 default 0xB0000000 if VMSPLIT_3G_OPT
11585 default 0x80000000 if VMSPLIT_2G
11586- default 0x78000000 if VMSPLIT_2G_OPT
11587+ default 0x70000000 if VMSPLIT_2G_OPT
11588 default 0x40000000 if VMSPLIT_1G
11589 default 0xC0000000
11590 depends on X86_32
11591@@ -1599,6 +1600,7 @@ config SECCOMP
11592
11593 config CC_STACKPROTECTOR
11594 bool "Enable -fstack-protector buffer overflow detection"
11595+ depends on X86_64 || !PAX_MEMORY_UDEREF
11596 ---help---
11597 This option turns on the -fstack-protector GCC feature. This
11598 feature puts, at the beginning of functions, a canary value on
11599@@ -1718,6 +1720,8 @@ config X86_NEED_RELOCS
11600 config PHYSICAL_ALIGN
11601 hex "Alignment value to which kernel should be aligned" if X86_32
11602 default "0x1000000"
11603+ range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
11604+ range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
11605 range 0x2000 0x1000000
11606 ---help---
11607 This value puts the alignment restrictions on physical address
11608@@ -1793,9 +1797,10 @@ config DEBUG_HOTPLUG_CPU0
11609 If unsure, say N.
11610
11611 config COMPAT_VDSO
11612- def_bool y
11613+ def_bool n
11614 prompt "Compat VDSO support"
11615 depends on X86_32 || IA32_EMULATION
11616+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
11617 ---help---
11618 Map the 32-bit VDSO to the predictable old-style address too.
11619
11620diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
11621index c026cca..14657ae 100644
11622--- a/arch/x86/Kconfig.cpu
11623+++ b/arch/x86/Kconfig.cpu
11624@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
11625
11626 config X86_F00F_BUG
11627 def_bool y
11628- depends on M586MMX || M586TSC || M586 || M486
11629+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
11630
11631 config X86_INVD_BUG
11632 def_bool y
11633@@ -327,7 +327,7 @@ config X86_INVD_BUG
11634
11635 config X86_ALIGNMENT_16
11636 def_bool y
11637- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
11638+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
11639
11640 config X86_INTEL_USERCOPY
11641 def_bool y
11642@@ -373,7 +373,7 @@ config X86_CMPXCHG64
11643 # generates cmov.
11644 config X86_CMOV
11645 def_bool y
11646- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
11647+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
11648
11649 config X86_MINIMUM_CPU_FAMILY
11650 int
11651diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
11652index 78d91af..8ceb94b 100644
11653--- a/arch/x86/Kconfig.debug
11654+++ b/arch/x86/Kconfig.debug
11655@@ -74,7 +74,7 @@ config X86_PTDUMP
11656 config DEBUG_RODATA
11657 bool "Write protect kernel read-only data structures"
11658 default y
11659- depends on DEBUG_KERNEL
11660+ depends on DEBUG_KERNEL && BROKEN
11661 ---help---
11662 Mark the kernel read-only data as write-protected in the pagetables,
11663 in order to catch accidental (and incorrect) writes to such const
11664@@ -92,7 +92,7 @@ config DEBUG_RODATA_TEST
11665
11666 config DEBUG_SET_MODULE_RONX
11667 bool "Set loadable kernel module data as NX and text as RO"
11668- depends on MODULES
11669+ depends on MODULES && BROKEN
11670 ---help---
11671 This option helps catch unintended modifications to loadable
11672 kernel module's text and read-only data. It also prevents execution
11673diff --git a/arch/x86/Makefile b/arch/x86/Makefile
11674index 07639c6..6f2c901 100644
11675--- a/arch/x86/Makefile
11676+++ b/arch/x86/Makefile
11677@@ -54,6 +54,7 @@ else
11678 UTS_MACHINE := x86_64
11679 CHECKFLAGS += -D__x86_64__ -m64
11680
11681+ biarch := $(call cc-option,-m64)
11682 KBUILD_AFLAGS += -m64
11683 KBUILD_CFLAGS += -m64
11684
11685@@ -241,3 +242,12 @@ define archhelp
11686 echo ' FDINITRD=file initrd for the booted kernel'
11687 echo ' kvmconfig - Enable additional options for guest kernel support'
11688 endef
11689+
11690+define OLD_LD
11691+
11692+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
11693+*** Please upgrade your binutils to 2.18 or newer
11694+endef
11695+
11696+archprepare:
11697+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
11698diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
11699index 379814b..add62ce 100644
11700--- a/arch/x86/boot/Makefile
11701+++ b/arch/x86/boot/Makefile
11702@@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
11703 $(call cc-option, -fno-stack-protector) \
11704 $(call cc-option, -mpreferred-stack-boundary=2)
11705 KBUILD_CFLAGS += $(call cc-option, -m32)
11706+ifdef CONSTIFY_PLUGIN
11707+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11708+endif
11709 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
11710 GCOV_PROFILE := n
11711
11712diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
11713index 878e4b9..20537ab 100644
11714--- a/arch/x86/boot/bitops.h
11715+++ b/arch/x86/boot/bitops.h
11716@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
11717 u8 v;
11718 const u32 *p = (const u32 *)addr;
11719
11720- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
11721+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
11722 return v;
11723 }
11724
11725@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
11726
11727 static inline void set_bit(int nr, void *addr)
11728 {
11729- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
11730+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
11731 }
11732
11733 #endif /* BOOT_BITOPS_H */
11734diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
11735index 5b75319..331a4ca 100644
11736--- a/arch/x86/boot/boot.h
11737+++ b/arch/x86/boot/boot.h
11738@@ -85,7 +85,7 @@ static inline void io_delay(void)
11739 static inline u16 ds(void)
11740 {
11741 u16 seg;
11742- asm("movw %%ds,%0" : "=rm" (seg));
11743+ asm volatile("movw %%ds,%0" : "=rm" (seg));
11744 return seg;
11745 }
11746
11747@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
11748 static inline int memcmp(const void *s1, const void *s2, size_t len)
11749 {
11750 u8 diff;
11751- asm("repe; cmpsb; setnz %0"
11752+ asm volatile("repe; cmpsb; setnz %0"
11753 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
11754 return diff;
11755 }
11756diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
11757index dcd90df..c830d7d 100644
11758--- a/arch/x86/boot/compressed/Makefile
11759+++ b/arch/x86/boot/compressed/Makefile
11760@@ -15,6 +15,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
11761 KBUILD_CFLAGS += $(cflags-y)
11762 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
11763 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
11764+ifdef CONSTIFY_PLUGIN
11765+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11766+endif
11767
11768 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
11769 GCOV_PROFILE := n
11770diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
11771index b7388a4..03844ec 100644
11772--- a/arch/x86/boot/compressed/eboot.c
11773+++ b/arch/x86/boot/compressed/eboot.c
11774@@ -150,7 +150,6 @@ again:
11775 *addr = max_addr;
11776 }
11777
11778-free_pool:
11779 efi_call_phys1(sys_table->boottime->free_pool, map);
11780
11781 fail:
11782@@ -214,7 +213,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
11783 if (i == map_size / desc_size)
11784 status = EFI_NOT_FOUND;
11785
11786-free_pool:
11787 efi_call_phys1(sys_table->boottime->free_pool, map);
11788 fail:
11789 return status;
11790diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
11791index a53440e..c3dbf1e 100644
11792--- a/arch/x86/boot/compressed/efi_stub_32.S
11793+++ b/arch/x86/boot/compressed/efi_stub_32.S
11794@@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
11795 * parameter 2, ..., param n. To make things easy, we save the return
11796 * address of efi_call_phys in a global variable.
11797 */
11798- popl %ecx
11799- movl %ecx, saved_return_addr(%edx)
11800- /* get the function pointer into ECX*/
11801- popl %ecx
11802- movl %ecx, efi_rt_function_ptr(%edx)
11803+ popl saved_return_addr(%edx)
11804+ popl efi_rt_function_ptr(%edx)
11805
11806 /*
11807 * 3. Call the physical function.
11808 */
11809- call *%ecx
11810+ call *efi_rt_function_ptr(%edx)
11811
11812 /*
11813 * 4. Balance the stack. And because EAX contain the return value,
11814@@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
11815 1: popl %edx
11816 subl $1b, %edx
11817
11818- movl efi_rt_function_ptr(%edx), %ecx
11819- pushl %ecx
11820+ pushl efi_rt_function_ptr(%edx)
11821
11822 /*
11823 * 10. Push the saved return address onto the stack and return.
11824 */
11825- movl saved_return_addr(%edx), %ecx
11826- pushl %ecx
11827- ret
11828+ jmpl *saved_return_addr(%edx)
11829 ENDPROC(efi_call_phys)
11830 .previous
11831
11832diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
11833index 1e3184f..0d11e2e 100644
11834--- a/arch/x86/boot/compressed/head_32.S
11835+++ b/arch/x86/boot/compressed/head_32.S
11836@@ -118,7 +118,7 @@ preferred_addr:
11837 notl %eax
11838 andl %eax, %ebx
11839 #else
11840- movl $LOAD_PHYSICAL_ADDR, %ebx
11841+ movl $____LOAD_PHYSICAL_ADDR, %ebx
11842 #endif
11843
11844 /* Target address to relocate to for decompression */
11845@@ -204,7 +204,7 @@ relocated:
11846 * and where it was actually loaded.
11847 */
11848 movl %ebp, %ebx
11849- subl $LOAD_PHYSICAL_ADDR, %ebx
11850+ subl $____LOAD_PHYSICAL_ADDR, %ebx
11851 jz 2f /* Nothing to be done if loaded at compiled addr. */
11852 /*
11853 * Process relocations.
11854@@ -212,8 +212,7 @@ relocated:
11855
11856 1: subl $4, %edi
11857 movl (%edi), %ecx
11858- testl %ecx, %ecx
11859- jz 2f
11860+ jecxz 2f
11861 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
11862 jmp 1b
11863 2:
11864diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
11865index 06e71c2..88a98264 100644
11866--- a/arch/x86/boot/compressed/head_64.S
11867+++ b/arch/x86/boot/compressed/head_64.S
11868@@ -95,7 +95,7 @@ ENTRY(startup_32)
11869 notl %eax
11870 andl %eax, %ebx
11871 #else
11872- movl $LOAD_PHYSICAL_ADDR, %ebx
11873+ movl $____LOAD_PHYSICAL_ADDR, %ebx
11874 #endif
11875
11876 /* Target address to relocate to for decompression */
11877@@ -270,7 +270,7 @@ preferred_addr:
11878 notq %rax
11879 andq %rax, %rbp
11880 #else
11881- movq $LOAD_PHYSICAL_ADDR, %rbp
11882+ movq $____LOAD_PHYSICAL_ADDR, %rbp
11883 #endif
11884
11885 /* Target address to relocate to for decompression */
11886@@ -361,8 +361,8 @@ gdt:
11887 .long gdt
11888 .word 0
11889 .quad 0x0000000000000000 /* NULL descriptor */
11890- .quad 0x00af9a000000ffff /* __KERNEL_CS */
11891- .quad 0x00cf92000000ffff /* __KERNEL_DS */
11892+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
11893+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
11894 .quad 0x0080890000000000 /* TS descriptor */
11895 .quad 0x0000000000000000 /* TS continued */
11896 gdt_end:
11897diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
11898index 0319c88..7c1931f 100644
11899--- a/arch/x86/boot/compressed/misc.c
11900+++ b/arch/x86/boot/compressed/misc.c
11901@@ -307,7 +307,7 @@ static void parse_elf(void *output)
11902 case PT_LOAD:
11903 #ifdef CONFIG_RELOCATABLE
11904 dest = output;
11905- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
11906+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
11907 #else
11908 dest = (void *)(phdr->p_paddr);
11909 #endif
11910@@ -358,7 +358,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
11911 error("Destination address too large");
11912 #endif
11913 #ifndef CONFIG_RELOCATABLE
11914- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
11915+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
11916 error("Wrong destination address");
11917 #endif
11918
11919diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
11920index 4d3ff03..e4972ff 100644
11921--- a/arch/x86/boot/cpucheck.c
11922+++ b/arch/x86/boot/cpucheck.c
11923@@ -74,7 +74,7 @@ static int has_fpu(void)
11924 u16 fcw = -1, fsw = -1;
11925 u32 cr0;
11926
11927- asm("movl %%cr0,%0" : "=r" (cr0));
11928+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
11929 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
11930 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
11931 asm volatile("movl %0,%%cr0" : : "r" (cr0));
11932@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
11933 {
11934 u32 f0, f1;
11935
11936- asm("pushfl ; "
11937+ asm volatile("pushfl ; "
11938 "pushfl ; "
11939 "popl %0 ; "
11940 "movl %0,%1 ; "
11941@@ -115,7 +115,7 @@ static void get_flags(void)
11942 set_bit(X86_FEATURE_FPU, cpu.flags);
11943
11944 if (has_eflag(X86_EFLAGS_ID)) {
11945- asm("cpuid"
11946+ asm volatile("cpuid"
11947 : "=a" (max_intel_level),
11948 "=b" (cpu_vendor[0]),
11949 "=d" (cpu_vendor[1]),
11950@@ -124,7 +124,7 @@ static void get_flags(void)
11951
11952 if (max_intel_level >= 0x00000001 &&
11953 max_intel_level <= 0x0000ffff) {
11954- asm("cpuid"
11955+ asm volatile("cpuid"
11956 : "=a" (tfms),
11957 "=c" (cpu.flags[4]),
11958 "=d" (cpu.flags[0])
11959@@ -136,7 +136,7 @@ static void get_flags(void)
11960 cpu.model += ((tfms >> 16) & 0xf) << 4;
11961 }
11962
11963- asm("cpuid"
11964+ asm volatile("cpuid"
11965 : "=a" (max_amd_level)
11966 : "a" (0x80000000)
11967 : "ebx", "ecx", "edx");
11968@@ -144,7 +144,7 @@ static void get_flags(void)
11969 if (max_amd_level >= 0x80000001 &&
11970 max_amd_level <= 0x8000ffff) {
11971 u32 eax = 0x80000001;
11972- asm("cpuid"
11973+ asm volatile("cpuid"
11974 : "+a" (eax),
11975 "=c" (cpu.flags[6]),
11976 "=d" (cpu.flags[1])
11977@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
11978 u32 ecx = MSR_K7_HWCR;
11979 u32 eax, edx;
11980
11981- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11982+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11983 eax &= ~(1 << 15);
11984- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11985+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11986
11987 get_flags(); /* Make sure it really did something */
11988 err = check_flags();
11989@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
11990 u32 ecx = MSR_VIA_FCR;
11991 u32 eax, edx;
11992
11993- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11994+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11995 eax |= (1<<1)|(1<<7);
11996- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11997+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11998
11999 set_bit(X86_FEATURE_CX8, cpu.flags);
12000 err = check_flags();
12001@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12002 u32 eax, edx;
12003 u32 level = 1;
12004
12005- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12006- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12007- asm("cpuid"
12008+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12009+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12010+ asm volatile("cpuid"
12011 : "+a" (level), "=d" (cpu.flags[0])
12012 : : "ecx", "ebx");
12013- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12014+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12015
12016 err = check_flags();
12017 }
12018diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
12019index 9ec06a1..2c25e79 100644
12020--- a/arch/x86/boot/header.S
12021+++ b/arch/x86/boot/header.S
12022@@ -409,10 +409,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
12023 # single linked list of
12024 # struct setup_data
12025
12026-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
12027+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12028
12029 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
12030+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12031+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
12032+#else
12033 #define VO_INIT_SIZE (VO__end - VO__text)
12034+#endif
12035 #if ZO_INIT_SIZE > VO_INIT_SIZE
12036 #define INIT_SIZE ZO_INIT_SIZE
12037 #else
12038diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
12039index db75d07..8e6d0af 100644
12040--- a/arch/x86/boot/memory.c
12041+++ b/arch/x86/boot/memory.c
12042@@ -19,7 +19,7 @@
12043
12044 static int detect_memory_e820(void)
12045 {
12046- int count = 0;
12047+ unsigned int count = 0;
12048 struct biosregs ireg, oreg;
12049 struct e820entry *desc = boot_params.e820_map;
12050 static struct e820entry buf; /* static so it is zeroed */
12051diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
12052index 11e8c6e..fdbb1ed 100644
12053--- a/arch/x86/boot/video-vesa.c
12054+++ b/arch/x86/boot/video-vesa.c
12055@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
12056
12057 boot_params.screen_info.vesapm_seg = oreg.es;
12058 boot_params.screen_info.vesapm_off = oreg.di;
12059+ boot_params.screen_info.vesapm_size = oreg.cx;
12060 }
12061
12062 /*
12063diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
12064index 43eda28..5ab5fdb 100644
12065--- a/arch/x86/boot/video.c
12066+++ b/arch/x86/boot/video.c
12067@@ -96,7 +96,7 @@ static void store_mode_params(void)
12068 static unsigned int get_entry(void)
12069 {
12070 char entry_buf[4];
12071- int i, len = 0;
12072+ unsigned int i, len = 0;
12073 int key;
12074 unsigned int v;
12075
12076diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
12077index 9105655..5e37f27 100644
12078--- a/arch/x86/crypto/aes-x86_64-asm_64.S
12079+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
12080@@ -8,6 +8,8 @@
12081 * including this sentence is retained in full.
12082 */
12083
12084+#include <asm/alternative-asm.h>
12085+
12086 .extern crypto_ft_tab
12087 .extern crypto_it_tab
12088 .extern crypto_fl_tab
12089@@ -70,6 +72,8 @@
12090 je B192; \
12091 leaq 32(r9),r9;
12092
12093+#define ret pax_force_retaddr 0, 1; ret
12094+
12095 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
12096 movq r1,r2; \
12097 movq r3,r4; \
12098diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
12099index 477e9d7..3ab339f 100644
12100--- a/arch/x86/crypto/aesni-intel_asm.S
12101+++ b/arch/x86/crypto/aesni-intel_asm.S
12102@@ -31,6 +31,7 @@
12103
12104 #include <linux/linkage.h>
12105 #include <asm/inst.h>
12106+#include <asm/alternative-asm.h>
12107
12108 #ifdef __x86_64__
12109 .data
12110@@ -1441,6 +1442,7 @@ _return_T_done_decrypt:
12111 pop %r14
12112 pop %r13
12113 pop %r12
12114+ pax_force_retaddr 0, 1
12115 ret
12116 ENDPROC(aesni_gcm_dec)
12117
12118@@ -1705,6 +1707,7 @@ _return_T_done_encrypt:
12119 pop %r14
12120 pop %r13
12121 pop %r12
12122+ pax_force_retaddr 0, 1
12123 ret
12124 ENDPROC(aesni_gcm_enc)
12125
12126@@ -1722,6 +1725,7 @@ _key_expansion_256a:
12127 pxor %xmm1, %xmm0
12128 movaps %xmm0, (TKEYP)
12129 add $0x10, TKEYP
12130+ pax_force_retaddr_bts
12131 ret
12132 ENDPROC(_key_expansion_128)
12133 ENDPROC(_key_expansion_256a)
12134@@ -1748,6 +1752,7 @@ _key_expansion_192a:
12135 shufps $0b01001110, %xmm2, %xmm1
12136 movaps %xmm1, 0x10(TKEYP)
12137 add $0x20, TKEYP
12138+ pax_force_retaddr_bts
12139 ret
12140 ENDPROC(_key_expansion_192a)
12141
12142@@ -1768,6 +1773,7 @@ _key_expansion_192b:
12143
12144 movaps %xmm0, (TKEYP)
12145 add $0x10, TKEYP
12146+ pax_force_retaddr_bts
12147 ret
12148 ENDPROC(_key_expansion_192b)
12149
12150@@ -1781,6 +1787,7 @@ _key_expansion_256b:
12151 pxor %xmm1, %xmm2
12152 movaps %xmm2, (TKEYP)
12153 add $0x10, TKEYP
12154+ pax_force_retaddr_bts
12155 ret
12156 ENDPROC(_key_expansion_256b)
12157
12158@@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
12159 #ifndef __x86_64__
12160 popl KEYP
12161 #endif
12162+ pax_force_retaddr 0, 1
12163 ret
12164 ENDPROC(aesni_set_key)
12165
12166@@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
12167 popl KLEN
12168 popl KEYP
12169 #endif
12170+ pax_force_retaddr 0, 1
12171 ret
12172 ENDPROC(aesni_enc)
12173
12174@@ -1974,6 +1983,7 @@ _aesni_enc1:
12175 AESENC KEY STATE
12176 movaps 0x70(TKEYP), KEY
12177 AESENCLAST KEY STATE
12178+ pax_force_retaddr_bts
12179 ret
12180 ENDPROC(_aesni_enc1)
12181
12182@@ -2083,6 +2093,7 @@ _aesni_enc4:
12183 AESENCLAST KEY STATE2
12184 AESENCLAST KEY STATE3
12185 AESENCLAST KEY STATE4
12186+ pax_force_retaddr_bts
12187 ret
12188 ENDPROC(_aesni_enc4)
12189
12190@@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
12191 popl KLEN
12192 popl KEYP
12193 #endif
12194+ pax_force_retaddr 0, 1
12195 ret
12196 ENDPROC(aesni_dec)
12197
12198@@ -2164,6 +2176,7 @@ _aesni_dec1:
12199 AESDEC KEY STATE
12200 movaps 0x70(TKEYP), KEY
12201 AESDECLAST KEY STATE
12202+ pax_force_retaddr_bts
12203 ret
12204 ENDPROC(_aesni_dec1)
12205
12206@@ -2273,6 +2286,7 @@ _aesni_dec4:
12207 AESDECLAST KEY STATE2
12208 AESDECLAST KEY STATE3
12209 AESDECLAST KEY STATE4
12210+ pax_force_retaddr_bts
12211 ret
12212 ENDPROC(_aesni_dec4)
12213
12214@@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
12215 popl KEYP
12216 popl LEN
12217 #endif
12218+ pax_force_retaddr 0, 1
12219 ret
12220 ENDPROC(aesni_ecb_enc)
12221
12222@@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
12223 popl KEYP
12224 popl LEN
12225 #endif
12226+ pax_force_retaddr 0, 1
12227 ret
12228 ENDPROC(aesni_ecb_dec)
12229
12230@@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
12231 popl LEN
12232 popl IVP
12233 #endif
12234+ pax_force_retaddr 0, 1
12235 ret
12236 ENDPROC(aesni_cbc_enc)
12237
12238@@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
12239 popl LEN
12240 popl IVP
12241 #endif
12242+ pax_force_retaddr 0, 1
12243 ret
12244 ENDPROC(aesni_cbc_dec)
12245
12246@@ -2550,6 +2568,7 @@ _aesni_inc_init:
12247 mov $1, TCTR_LOW
12248 MOVQ_R64_XMM TCTR_LOW INC
12249 MOVQ_R64_XMM CTR TCTR_LOW
12250+ pax_force_retaddr_bts
12251 ret
12252 ENDPROC(_aesni_inc_init)
12253
12254@@ -2579,6 +2598,7 @@ _aesni_inc:
12255 .Linc_low:
12256 movaps CTR, IV
12257 PSHUFB_XMM BSWAP_MASK IV
12258+ pax_force_retaddr_bts
12259 ret
12260 ENDPROC(_aesni_inc)
12261
12262@@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
12263 .Lctr_enc_ret:
12264 movups IV, (IVP)
12265 .Lctr_enc_just_ret:
12266+ pax_force_retaddr 0, 1
12267 ret
12268 ENDPROC(aesni_ctr_enc)
12269
12270@@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
12271 pxor INC, STATE4
12272 movdqu STATE4, 0x70(OUTP)
12273
12274+ pax_force_retaddr 0, 1
12275 ret
12276 ENDPROC(aesni_xts_crypt8)
12277
12278diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
12279index 246c670..4d1ed00 100644
12280--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
12281+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
12282@@ -21,6 +21,7 @@
12283 */
12284
12285 #include <linux/linkage.h>
12286+#include <asm/alternative-asm.h>
12287
12288 .file "blowfish-x86_64-asm.S"
12289 .text
12290@@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
12291 jnz .L__enc_xor;
12292
12293 write_block();
12294+ pax_force_retaddr 0, 1
12295 ret;
12296 .L__enc_xor:
12297 xor_block();
12298+ pax_force_retaddr 0, 1
12299 ret;
12300 ENDPROC(__blowfish_enc_blk)
12301
12302@@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
12303
12304 movq %r11, %rbp;
12305
12306+ pax_force_retaddr 0, 1
12307 ret;
12308 ENDPROC(blowfish_dec_blk)
12309
12310@@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
12311
12312 popq %rbx;
12313 popq %rbp;
12314+ pax_force_retaddr 0, 1
12315 ret;
12316
12317 .L__enc_xor4:
12318@@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
12319
12320 popq %rbx;
12321 popq %rbp;
12322+ pax_force_retaddr 0, 1
12323 ret;
12324 ENDPROC(__blowfish_enc_blk_4way)
12325
12326@@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
12327 popq %rbx;
12328 popq %rbp;
12329
12330+ pax_force_retaddr 0, 1
12331 ret;
12332 ENDPROC(blowfish_dec_blk_4way)
12333diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12334index ce71f92..2dd5b1e 100644
12335--- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12336+++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12337@@ -16,6 +16,7 @@
12338 */
12339
12340 #include <linux/linkage.h>
12341+#include <asm/alternative-asm.h>
12342
12343 #define CAMELLIA_TABLE_BYTE_LEN 272
12344
12345@@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
12346 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
12347 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
12348 %rcx, (%r9));
12349+ pax_force_retaddr_bts
12350 ret;
12351 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
12352
12353@@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
12354 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
12355 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
12356 %rax, (%r9));
12357+ pax_force_retaddr_bts
12358 ret;
12359 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
12360
12361@@ -780,6 +783,7 @@ __camellia_enc_blk16:
12362 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
12363 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
12364
12365+ pax_force_retaddr_bts
12366 ret;
12367
12368 .align 8
12369@@ -865,6 +869,7 @@ __camellia_dec_blk16:
12370 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
12371 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
12372
12373+ pax_force_retaddr_bts
12374 ret;
12375
12376 .align 8
12377@@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
12378 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12379 %xmm8, %rsi);
12380
12381+ pax_force_retaddr 0, 1
12382 ret;
12383 ENDPROC(camellia_ecb_enc_16way)
12384
12385@@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
12386 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12387 %xmm8, %rsi);
12388
12389+ pax_force_retaddr 0, 1
12390 ret;
12391 ENDPROC(camellia_ecb_dec_16way)
12392
12393@@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
12394 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12395 %xmm8, %rsi);
12396
12397+ pax_force_retaddr 0, 1
12398 ret;
12399 ENDPROC(camellia_cbc_dec_16way)
12400
12401@@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
12402 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12403 %xmm8, %rsi);
12404
12405+ pax_force_retaddr 0, 1
12406 ret;
12407 ENDPROC(camellia_ctr_16way)
12408
12409@@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
12410 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12411 %xmm8, %rsi);
12412
12413+ pax_force_retaddr 0, 1
12414 ret;
12415 ENDPROC(camellia_xts_crypt_16way)
12416
12417diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12418index 0e0b886..8fc756a 100644
12419--- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12420+++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12421@@ -11,6 +11,7 @@
12422 */
12423
12424 #include <linux/linkage.h>
12425+#include <asm/alternative-asm.h>
12426
12427 #define CAMELLIA_TABLE_BYTE_LEN 272
12428
12429@@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
12430 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
12431 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
12432 %rcx, (%r9));
12433+ pax_force_retaddr_bts
12434 ret;
12435 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
12436
12437@@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
12438 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
12439 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
12440 %rax, (%r9));
12441+ pax_force_retaddr_bts
12442 ret;
12443 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
12444
12445@@ -820,6 +823,7 @@ __camellia_enc_blk32:
12446 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
12447 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
12448
12449+ pax_force_retaddr_bts
12450 ret;
12451
12452 .align 8
12453@@ -905,6 +909,7 @@ __camellia_dec_blk32:
12454 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
12455 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
12456
12457+ pax_force_retaddr_bts
12458 ret;
12459
12460 .align 8
12461@@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
12462
12463 vzeroupper;
12464
12465+ pax_force_retaddr 0, 1
12466 ret;
12467 ENDPROC(camellia_ecb_enc_32way)
12468
12469@@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
12470
12471 vzeroupper;
12472
12473+ pax_force_retaddr 0, 1
12474 ret;
12475 ENDPROC(camellia_ecb_dec_32way)
12476
12477@@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
12478
12479 vzeroupper;
12480
12481+ pax_force_retaddr 0, 1
12482 ret;
12483 ENDPROC(camellia_cbc_dec_32way)
12484
12485@@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
12486
12487 vzeroupper;
12488
12489+ pax_force_retaddr 0, 1
12490 ret;
12491 ENDPROC(camellia_ctr_32way)
12492
12493@@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
12494
12495 vzeroupper;
12496
12497+ pax_force_retaddr 0, 1
12498 ret;
12499 ENDPROC(camellia_xts_crypt_32way)
12500
12501diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
12502index 310319c..ce174a4 100644
12503--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
12504+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
12505@@ -21,6 +21,7 @@
12506 */
12507
12508 #include <linux/linkage.h>
12509+#include <asm/alternative-asm.h>
12510
12511 .file "camellia-x86_64-asm_64.S"
12512 .text
12513@@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
12514 enc_outunpack(mov, RT1);
12515
12516 movq RRBP, %rbp;
12517+ pax_force_retaddr 0, 1
12518 ret;
12519
12520 .L__enc_xor:
12521 enc_outunpack(xor, RT1);
12522
12523 movq RRBP, %rbp;
12524+ pax_force_retaddr 0, 1
12525 ret;
12526 ENDPROC(__camellia_enc_blk)
12527
12528@@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
12529 dec_outunpack();
12530
12531 movq RRBP, %rbp;
12532+ pax_force_retaddr 0, 1
12533 ret;
12534 ENDPROC(camellia_dec_blk)
12535
12536@@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
12537
12538 movq RRBP, %rbp;
12539 popq %rbx;
12540+ pax_force_retaddr 0, 1
12541 ret;
12542
12543 .L__enc2_xor:
12544@@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
12545
12546 movq RRBP, %rbp;
12547 popq %rbx;
12548+ pax_force_retaddr 0, 1
12549 ret;
12550 ENDPROC(__camellia_enc_blk_2way)
12551
12552@@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
12553
12554 movq RRBP, %rbp;
12555 movq RXOR, %rbx;
12556+ pax_force_retaddr 0, 1
12557 ret;
12558 ENDPROC(camellia_dec_blk_2way)
12559diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12560index c35fd5d..c1ee236 100644
12561--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12562+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12563@@ -24,6 +24,7 @@
12564 */
12565
12566 #include <linux/linkage.h>
12567+#include <asm/alternative-asm.h>
12568
12569 .file "cast5-avx-x86_64-asm_64.S"
12570
12571@@ -281,6 +282,7 @@ __cast5_enc_blk16:
12572 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
12573 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
12574
12575+ pax_force_retaddr 0, 1
12576 ret;
12577 ENDPROC(__cast5_enc_blk16)
12578
12579@@ -352,6 +354,7 @@ __cast5_dec_blk16:
12580 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
12581 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
12582
12583+ pax_force_retaddr 0, 1
12584 ret;
12585
12586 .L__skip_dec:
12587@@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
12588 vmovdqu RR4, (6*4*4)(%r11);
12589 vmovdqu RL4, (7*4*4)(%r11);
12590
12591+ pax_force_retaddr
12592 ret;
12593 ENDPROC(cast5_ecb_enc_16way)
12594
12595@@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
12596 vmovdqu RR4, (6*4*4)(%r11);
12597 vmovdqu RL4, (7*4*4)(%r11);
12598
12599+ pax_force_retaddr
12600 ret;
12601 ENDPROC(cast5_ecb_dec_16way)
12602
12603@@ -469,6 +474,7 @@ ENTRY(cast5_cbc_dec_16way)
12604
12605 popq %r12;
12606
12607+ pax_force_retaddr
12608 ret;
12609 ENDPROC(cast5_cbc_dec_16way)
12610
12611@@ -542,5 +548,6 @@ ENTRY(cast5_ctr_16way)
12612
12613 popq %r12;
12614
12615+ pax_force_retaddr
12616 ret;
12617 ENDPROC(cast5_ctr_16way)
12618diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
12619index e3531f8..18ded3a 100644
12620--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
12621+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
12622@@ -24,6 +24,7 @@
12623 */
12624
12625 #include <linux/linkage.h>
12626+#include <asm/alternative-asm.h>
12627 #include "glue_helper-asm-avx.S"
12628
12629 .file "cast6-avx-x86_64-asm_64.S"
12630@@ -295,6 +296,7 @@ __cast6_enc_blk8:
12631 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
12632 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
12633
12634+ pax_force_retaddr 0, 1
12635 ret;
12636 ENDPROC(__cast6_enc_blk8)
12637
12638@@ -340,6 +342,7 @@ __cast6_dec_blk8:
12639 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
12640 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
12641
12642+ pax_force_retaddr 0, 1
12643 ret;
12644 ENDPROC(__cast6_dec_blk8)
12645
12646@@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
12647
12648 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12649
12650+ pax_force_retaddr
12651 ret;
12652 ENDPROC(cast6_ecb_enc_8way)
12653
12654@@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
12655
12656 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12657
12658+ pax_force_retaddr
12659 ret;
12660 ENDPROC(cast6_ecb_dec_8way)
12661
12662@@ -399,6 +404,7 @@ ENTRY(cast6_cbc_dec_8way)
12663
12664 popq %r12;
12665
12666+ pax_force_retaddr
12667 ret;
12668 ENDPROC(cast6_cbc_dec_8way)
12669
12670@@ -424,6 +430,7 @@ ENTRY(cast6_ctr_8way)
12671
12672 popq %r12;
12673
12674+ pax_force_retaddr
12675 ret;
12676 ENDPROC(cast6_ctr_8way)
12677
12678@@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
12679 /* dst <= regs xor IVs(in dst) */
12680 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12681
12682+ pax_force_retaddr
12683 ret;
12684 ENDPROC(cast6_xts_enc_8way)
12685
12686@@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
12687 /* dst <= regs xor IVs(in dst) */
12688 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12689
12690+ pax_force_retaddr
12691 ret;
12692 ENDPROC(cast6_xts_dec_8way)
12693diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
12694index dbc4339..3d868c5 100644
12695--- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
12696+++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
12697@@ -45,6 +45,7 @@
12698
12699 #include <asm/inst.h>
12700 #include <linux/linkage.h>
12701+#include <asm/alternative-asm.h>
12702
12703 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
12704
12705@@ -312,6 +313,7 @@ do_return:
12706 popq %rsi
12707 popq %rdi
12708 popq %rbx
12709+ pax_force_retaddr 0, 1
12710 ret
12711
12712 ################################################################
12713diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
12714index 586f41a..d02851e 100644
12715--- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
12716+++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
12717@@ -18,6 +18,7 @@
12718
12719 #include <linux/linkage.h>
12720 #include <asm/inst.h>
12721+#include <asm/alternative-asm.h>
12722
12723 .data
12724
12725@@ -93,6 +94,7 @@ __clmul_gf128mul_ble:
12726 psrlq $1, T2
12727 pxor T2, T1
12728 pxor T1, DATA
12729+ pax_force_retaddr
12730 ret
12731 ENDPROC(__clmul_gf128mul_ble)
12732
12733@@ -105,6 +107,7 @@ ENTRY(clmul_ghash_mul)
12734 call __clmul_gf128mul_ble
12735 PSHUFB_XMM BSWAP DATA
12736 movups DATA, (%rdi)
12737+ pax_force_retaddr
12738 ret
12739 ENDPROC(clmul_ghash_mul)
12740
12741@@ -132,6 +135,7 @@ ENTRY(clmul_ghash_update)
12742 PSHUFB_XMM BSWAP DATA
12743 movups DATA, (%rdi)
12744 .Lupdate_just_ret:
12745+ pax_force_retaddr
12746 ret
12747 ENDPROC(clmul_ghash_update)
12748
12749@@ -157,5 +161,6 @@ ENTRY(clmul_ghash_setkey)
12750 pand .Lpoly, %xmm1
12751 pxor %xmm1, %xmm0
12752 movups %xmm0, (%rdi)
12753+ pax_force_retaddr
12754 ret
12755 ENDPROC(clmul_ghash_setkey)
12756diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
12757index 9279e0b..9270820 100644
12758--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
12759+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
12760@@ -1,4 +1,5 @@
12761 #include <linux/linkage.h>
12762+#include <asm/alternative-asm.h>
12763
12764 # enter salsa20_encrypt_bytes
12765 ENTRY(salsa20_encrypt_bytes)
12766@@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
12767 add %r11,%rsp
12768 mov %rdi,%rax
12769 mov %rsi,%rdx
12770+ pax_force_retaddr 0, 1
12771 ret
12772 # bytesatleast65:
12773 ._bytesatleast65:
12774@@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
12775 add %r11,%rsp
12776 mov %rdi,%rax
12777 mov %rsi,%rdx
12778+ pax_force_retaddr
12779 ret
12780 ENDPROC(salsa20_keysetup)
12781
12782@@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
12783 add %r11,%rsp
12784 mov %rdi,%rax
12785 mov %rsi,%rdx
12786+ pax_force_retaddr
12787 ret
12788 ENDPROC(salsa20_ivsetup)
12789diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
12790index 2f202f4..d9164d6 100644
12791--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
12792+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
12793@@ -24,6 +24,7 @@
12794 */
12795
12796 #include <linux/linkage.h>
12797+#include <asm/alternative-asm.h>
12798 #include "glue_helper-asm-avx.S"
12799
12800 .file "serpent-avx-x86_64-asm_64.S"
12801@@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
12802 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
12803 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
12804
12805+ pax_force_retaddr
12806 ret;
12807 ENDPROC(__serpent_enc_blk8_avx)
12808
12809@@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
12810 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
12811 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
12812
12813+ pax_force_retaddr
12814 ret;
12815 ENDPROC(__serpent_dec_blk8_avx)
12816
12817@@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
12818
12819 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12820
12821+ pax_force_retaddr
12822 ret;
12823 ENDPROC(serpent_ecb_enc_8way_avx)
12824
12825@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
12826
12827 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
12828
12829+ pax_force_retaddr
12830 ret;
12831 ENDPROC(serpent_ecb_dec_8way_avx)
12832
12833@@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
12834
12835 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
12836
12837+ pax_force_retaddr
12838 ret;
12839 ENDPROC(serpent_cbc_dec_8way_avx)
12840
12841@@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
12842
12843 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12844
12845+ pax_force_retaddr
12846 ret;
12847 ENDPROC(serpent_ctr_8way_avx)
12848
12849@@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
12850 /* dst <= regs xor IVs(in dst) */
12851 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12852
12853+ pax_force_retaddr
12854 ret;
12855 ENDPROC(serpent_xts_enc_8way_avx)
12856
12857@@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
12858 /* dst <= regs xor IVs(in dst) */
12859 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
12860
12861+ pax_force_retaddr
12862 ret;
12863 ENDPROC(serpent_xts_dec_8way_avx)
12864diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
12865index b222085..abd483c 100644
12866--- a/arch/x86/crypto/serpent-avx2-asm_64.S
12867+++ b/arch/x86/crypto/serpent-avx2-asm_64.S
12868@@ -15,6 +15,7 @@
12869 */
12870
12871 #include <linux/linkage.h>
12872+#include <asm/alternative-asm.h>
12873 #include "glue_helper-asm-avx2.S"
12874
12875 .file "serpent-avx2-asm_64.S"
12876@@ -610,6 +611,7 @@ __serpent_enc_blk16:
12877 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
12878 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
12879
12880+ pax_force_retaddr
12881 ret;
12882 ENDPROC(__serpent_enc_blk16)
12883
12884@@ -664,6 +666,7 @@ __serpent_dec_blk16:
12885 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
12886 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
12887
12888+ pax_force_retaddr
12889 ret;
12890 ENDPROC(__serpent_dec_blk16)
12891
12892@@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
12893
12894 vzeroupper;
12895
12896+ pax_force_retaddr
12897 ret;
12898 ENDPROC(serpent_ecb_enc_16way)
12899
12900@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
12901
12902 vzeroupper;
12903
12904+ pax_force_retaddr
12905 ret;
12906 ENDPROC(serpent_ecb_dec_16way)
12907
12908@@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
12909
12910 vzeroupper;
12911
12912+ pax_force_retaddr
12913 ret;
12914 ENDPROC(serpent_cbc_dec_16way)
12915
12916@@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
12917
12918 vzeroupper;
12919
12920+ pax_force_retaddr
12921 ret;
12922 ENDPROC(serpent_ctr_16way)
12923
12924@@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
12925
12926 vzeroupper;
12927
12928+ pax_force_retaddr
12929 ret;
12930 ENDPROC(serpent_xts_enc_16way)
12931
12932@@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
12933
12934 vzeroupper;
12935
12936+ pax_force_retaddr
12937 ret;
12938 ENDPROC(serpent_xts_dec_16way)
12939diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
12940index acc066c..1559cc4 100644
12941--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
12942+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
12943@@ -25,6 +25,7 @@
12944 */
12945
12946 #include <linux/linkage.h>
12947+#include <asm/alternative-asm.h>
12948
12949 .file "serpent-sse2-x86_64-asm_64.S"
12950 .text
12951@@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
12952 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
12953 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
12954
12955+ pax_force_retaddr
12956 ret;
12957
12958 .L__enc_xor8:
12959 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
12960 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
12961
12962+ pax_force_retaddr
12963 ret;
12964 ENDPROC(__serpent_enc_blk_8way)
12965
12966@@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
12967 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
12968 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
12969
12970+ pax_force_retaddr
12971 ret;
12972 ENDPROC(serpent_dec_blk_8way)
12973diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
12974index a410950..3356d42 100644
12975--- a/arch/x86/crypto/sha1_ssse3_asm.S
12976+++ b/arch/x86/crypto/sha1_ssse3_asm.S
12977@@ -29,6 +29,7 @@
12978 */
12979
12980 #include <linux/linkage.h>
12981+#include <asm/alternative-asm.h>
12982
12983 #define CTX %rdi // arg1
12984 #define BUF %rsi // arg2
12985@@ -104,6 +105,7 @@
12986 pop %r12
12987 pop %rbp
12988 pop %rbx
12989+ pax_force_retaddr 0, 1
12990 ret
12991
12992 ENDPROC(\name)
12993diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
12994index 642f156..4ab07b9 100644
12995--- a/arch/x86/crypto/sha256-avx-asm.S
12996+++ b/arch/x86/crypto/sha256-avx-asm.S
12997@@ -49,6 +49,7 @@
12998
12999 #ifdef CONFIG_AS_AVX
13000 #include <linux/linkage.h>
13001+#include <asm/alternative-asm.h>
13002
13003 ## assume buffers not aligned
13004 #define VMOVDQ vmovdqu
13005@@ -460,6 +461,7 @@ done_hash:
13006 popq %r13
13007 popq %rbp
13008 popq %rbx
13009+ pax_force_retaddr 0, 1
13010 ret
13011 ENDPROC(sha256_transform_avx)
13012
13013diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
13014index 9e86944..2e7f95a 100644
13015--- a/arch/x86/crypto/sha256-avx2-asm.S
13016+++ b/arch/x86/crypto/sha256-avx2-asm.S
13017@@ -50,6 +50,7 @@
13018
13019 #ifdef CONFIG_AS_AVX2
13020 #include <linux/linkage.h>
13021+#include <asm/alternative-asm.h>
13022
13023 ## assume buffers not aligned
13024 #define VMOVDQ vmovdqu
13025@@ -720,6 +721,7 @@ done_hash:
13026 popq %r12
13027 popq %rbp
13028 popq %rbx
13029+ pax_force_retaddr 0, 1
13030 ret
13031 ENDPROC(sha256_transform_rorx)
13032
13033diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
13034index f833b74..c36ed14 100644
13035--- a/arch/x86/crypto/sha256-ssse3-asm.S
13036+++ b/arch/x86/crypto/sha256-ssse3-asm.S
13037@@ -47,6 +47,7 @@
13038 ########################################################################
13039
13040 #include <linux/linkage.h>
13041+#include <asm/alternative-asm.h>
13042
13043 ## assume buffers not aligned
13044 #define MOVDQ movdqu
13045@@ -471,6 +472,7 @@ done_hash:
13046 popq %rbp
13047 popq %rbx
13048
13049+ pax_force_retaddr 0, 1
13050 ret
13051 ENDPROC(sha256_transform_ssse3)
13052
13053diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
13054index 974dde9..4533d34 100644
13055--- a/arch/x86/crypto/sha512-avx-asm.S
13056+++ b/arch/x86/crypto/sha512-avx-asm.S
13057@@ -49,6 +49,7 @@
13058
13059 #ifdef CONFIG_AS_AVX
13060 #include <linux/linkage.h>
13061+#include <asm/alternative-asm.h>
13062
13063 .text
13064
13065@@ -364,6 +365,7 @@ updateblock:
13066 mov frame_RSPSAVE(%rsp), %rsp
13067
13068 nowork:
13069+ pax_force_retaddr 0, 1
13070 ret
13071 ENDPROC(sha512_transform_avx)
13072
13073diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
13074index 568b961..061ef1d 100644
13075--- a/arch/x86/crypto/sha512-avx2-asm.S
13076+++ b/arch/x86/crypto/sha512-avx2-asm.S
13077@@ -51,6 +51,7 @@
13078
13079 #ifdef CONFIG_AS_AVX2
13080 #include <linux/linkage.h>
13081+#include <asm/alternative-asm.h>
13082
13083 .text
13084
13085@@ -678,6 +679,7 @@ done_hash:
13086
13087 # Restore Stack Pointer
13088 mov frame_RSPSAVE(%rsp), %rsp
13089+ pax_force_retaddr 0, 1
13090 ret
13091 ENDPROC(sha512_transform_rorx)
13092
13093diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
13094index fb56855..e23914f 100644
13095--- a/arch/x86/crypto/sha512-ssse3-asm.S
13096+++ b/arch/x86/crypto/sha512-ssse3-asm.S
13097@@ -48,6 +48,7 @@
13098 ########################################################################
13099
13100 #include <linux/linkage.h>
13101+#include <asm/alternative-asm.h>
13102
13103 .text
13104
13105@@ -363,6 +364,7 @@ updateblock:
13106 mov frame_RSPSAVE(%rsp), %rsp
13107
13108 nowork:
13109+ pax_force_retaddr 0, 1
13110 ret
13111 ENDPROC(sha512_transform_ssse3)
13112
13113diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13114index 0505813..63b1d00 100644
13115--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13116+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13117@@ -24,6 +24,7 @@
13118 */
13119
13120 #include <linux/linkage.h>
13121+#include <asm/alternative-asm.h>
13122 #include "glue_helper-asm-avx.S"
13123
13124 .file "twofish-avx-x86_64-asm_64.S"
13125@@ -284,6 +285,7 @@ __twofish_enc_blk8:
13126 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
13127 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
13128
13129+ pax_force_retaddr 0, 1
13130 ret;
13131 ENDPROC(__twofish_enc_blk8)
13132
13133@@ -324,6 +326,7 @@ __twofish_dec_blk8:
13134 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
13135 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
13136
13137+ pax_force_retaddr 0, 1
13138 ret;
13139 ENDPROC(__twofish_dec_blk8)
13140
13141@@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
13142
13143 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13144
13145+ pax_force_retaddr 0, 1
13146 ret;
13147 ENDPROC(twofish_ecb_enc_8way)
13148
13149@@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
13150
13151 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13152
13153+ pax_force_retaddr 0, 1
13154 ret;
13155 ENDPROC(twofish_ecb_dec_8way)
13156
13157@@ -383,6 +388,7 @@ ENTRY(twofish_cbc_dec_8way)
13158
13159 popq %r12;
13160
13161+ pax_force_retaddr 0, 1
13162 ret;
13163 ENDPROC(twofish_cbc_dec_8way)
13164
13165@@ -408,6 +414,7 @@ ENTRY(twofish_ctr_8way)
13166
13167 popq %r12;
13168
13169+ pax_force_retaddr 0, 1
13170 ret;
13171 ENDPROC(twofish_ctr_8way)
13172
13173@@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
13174 /* dst <= regs xor IVs(in dst) */
13175 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13176
13177+ pax_force_retaddr 0, 1
13178 ret;
13179 ENDPROC(twofish_xts_enc_8way)
13180
13181@@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
13182 /* dst <= regs xor IVs(in dst) */
13183 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13184
13185+ pax_force_retaddr 0, 1
13186 ret;
13187 ENDPROC(twofish_xts_dec_8way)
13188diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13189index 1c3b7ce..b365c5e 100644
13190--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13191+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13192@@ -21,6 +21,7 @@
13193 */
13194
13195 #include <linux/linkage.h>
13196+#include <asm/alternative-asm.h>
13197
13198 .file "twofish-x86_64-asm-3way.S"
13199 .text
13200@@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
13201 popq %r13;
13202 popq %r14;
13203 popq %r15;
13204+ pax_force_retaddr 0, 1
13205 ret;
13206
13207 .L__enc_xor3:
13208@@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
13209 popq %r13;
13210 popq %r14;
13211 popq %r15;
13212+ pax_force_retaddr 0, 1
13213 ret;
13214 ENDPROC(__twofish_enc_blk_3way)
13215
13216@@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
13217 popq %r13;
13218 popq %r14;
13219 popq %r15;
13220+ pax_force_retaddr 0, 1
13221 ret;
13222 ENDPROC(twofish_dec_blk_3way)
13223diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
13224index a039d21..29e7615 100644
13225--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
13226+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
13227@@ -22,6 +22,7 @@
13228
13229 #include <linux/linkage.h>
13230 #include <asm/asm-offsets.h>
13231+#include <asm/alternative-asm.h>
13232
13233 #define a_offset 0
13234 #define b_offset 4
13235@@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
13236
13237 popq R1
13238 movq $1,%rax
13239+ pax_force_retaddr 0, 1
13240 ret
13241 ENDPROC(twofish_enc_blk)
13242
13243@@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
13244
13245 popq R1
13246 movq $1,%rax
13247+ pax_force_retaddr 0, 1
13248 ret
13249 ENDPROC(twofish_dec_blk)
13250diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
13251index bae3aba..c1788c1 100644
13252--- a/arch/x86/ia32/ia32_aout.c
13253+++ b/arch/x86/ia32/ia32_aout.c
13254@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
13255 unsigned long dump_start, dump_size;
13256 struct user32 dump;
13257
13258+ memset(&dump, 0, sizeof(dump));
13259+
13260 fs = get_fs();
13261 set_fs(KERNEL_DS);
13262 has_dumped = 1;
13263diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
13264index 665a730..8e7a67a 100644
13265--- a/arch/x86/ia32/ia32_signal.c
13266+++ b/arch/x86/ia32/ia32_signal.c
13267@@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
13268 sp -= frame_size;
13269 /* Align the stack pointer according to the i386 ABI,
13270 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
13271- sp = ((sp + 4) & -16ul) - 4;
13272+ sp = ((sp - 12) & -16ul) - 4;
13273 return (void __user *) sp;
13274 }
13275
13276@@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
13277 * These are actually not used anymore, but left because some
13278 * gdb versions depend on them as a marker.
13279 */
13280- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
13281+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
13282 } put_user_catch(err);
13283
13284 if (err)
13285@@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
13286 0xb8,
13287 __NR_ia32_rt_sigreturn,
13288 0x80cd,
13289- 0,
13290+ 0
13291 };
13292
13293 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
13294@@ -461,16 +461,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
13295
13296 if (ksig->ka.sa.sa_flags & SA_RESTORER)
13297 restorer = ksig->ka.sa.sa_restorer;
13298+ else if (current->mm->context.vdso)
13299+ /* Return stub is in 32bit vsyscall page */
13300+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
13301 else
13302- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
13303- rt_sigreturn);
13304+ restorer = &frame->retcode;
13305 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
13306
13307 /*
13308 * Not actually used anymore, but left because some gdb
13309 * versions need it.
13310 */
13311- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
13312+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
13313 } put_user_catch(err);
13314
13315 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
13316diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
13317index 474dc1b..9297c58 100644
13318--- a/arch/x86/ia32/ia32entry.S
13319+++ b/arch/x86/ia32/ia32entry.S
13320@@ -15,8 +15,10 @@
13321 #include <asm/irqflags.h>
13322 #include <asm/asm.h>
13323 #include <asm/smap.h>
13324+#include <asm/pgtable.h>
13325 #include <linux/linkage.h>
13326 #include <linux/err.h>
13327+#include <asm/alternative-asm.h>
13328
13329 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
13330 #include <linux/elf-em.h>
13331@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
13332 ENDPROC(native_irq_enable_sysexit)
13333 #endif
13334
13335+ .macro pax_enter_kernel_user
13336+ pax_set_fptr_mask
13337+#ifdef CONFIG_PAX_MEMORY_UDEREF
13338+ call pax_enter_kernel_user
13339+#endif
13340+ .endm
13341+
13342+ .macro pax_exit_kernel_user
13343+#ifdef CONFIG_PAX_MEMORY_UDEREF
13344+ call pax_exit_kernel_user
13345+#endif
13346+#ifdef CONFIG_PAX_RANDKSTACK
13347+ pushq %rax
13348+ pushq %r11
13349+ call pax_randomize_kstack
13350+ popq %r11
13351+ popq %rax
13352+#endif
13353+ .endm
13354+
13355+ .macro pax_erase_kstack
13356+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13357+ call pax_erase_kstack
13358+#endif
13359+ .endm
13360+
13361 /*
13362 * 32bit SYSENTER instruction entry.
13363 *
13364@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
13365 CFI_REGISTER rsp,rbp
13366 SWAPGS_UNSAFE_STACK
13367 movq PER_CPU_VAR(kernel_stack), %rsp
13368- addq $(KERNEL_STACK_OFFSET),%rsp
13369- /*
13370- * No need to follow this irqs on/off section: the syscall
13371- * disabled irqs, here we enable it straight after entry:
13372- */
13373- ENABLE_INTERRUPTS(CLBR_NONE)
13374 movl %ebp,%ebp /* zero extension */
13375 pushq_cfi $__USER32_DS
13376 /*CFI_REL_OFFSET ss,0*/
13377@@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
13378 CFI_REL_OFFSET rsp,0
13379 pushfq_cfi
13380 /*CFI_REL_OFFSET rflags,0*/
13381- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
13382- CFI_REGISTER rip,r10
13383+ orl $X86_EFLAGS_IF,(%rsp)
13384+ GET_THREAD_INFO(%r11)
13385+ movl TI_sysenter_return(%r11), %r11d
13386+ CFI_REGISTER rip,r11
13387 pushq_cfi $__USER32_CS
13388 /*CFI_REL_OFFSET cs,0*/
13389 movl %eax, %eax
13390- pushq_cfi %r10
13391+ pushq_cfi %r11
13392 CFI_REL_OFFSET rip,0
13393 pushq_cfi %rax
13394 cld
13395 SAVE_ARGS 0,1,0
13396+ pax_enter_kernel_user
13397+
13398+#ifdef CONFIG_PAX_RANDKSTACK
13399+ pax_erase_kstack
13400+#endif
13401+
13402+ /*
13403+ * No need to follow this irqs on/off section: the syscall
13404+ * disabled irqs, here we enable it straight after entry:
13405+ */
13406+ ENABLE_INTERRUPTS(CLBR_NONE)
13407 /* no need to do an access_ok check here because rbp has been
13408 32bit zero extended */
13409+
13410+#ifdef CONFIG_PAX_MEMORY_UDEREF
13411+ addq pax_user_shadow_base,%rbp
13412+ ASM_PAX_OPEN_USERLAND
13413+#endif
13414+
13415 ASM_STAC
13416 1: movl (%rbp),%ebp
13417 _ASM_EXTABLE(1b,ia32_badarg)
13418 ASM_CLAC
13419- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13420- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13421+
13422+#ifdef CONFIG_PAX_MEMORY_UDEREF
13423+ ASM_PAX_CLOSE_USERLAND
13424+#endif
13425+
13426+ GET_THREAD_INFO(%r11)
13427+ orl $TS_COMPAT,TI_status(%r11)
13428+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
13429 CFI_REMEMBER_STATE
13430 jnz sysenter_tracesys
13431 cmpq $(IA32_NR_syscalls-1),%rax
13432@@ -162,12 +209,15 @@ sysenter_do_call:
13433 sysenter_dispatch:
13434 call *ia32_sys_call_table(,%rax,8)
13435 movq %rax,RAX-ARGOFFSET(%rsp)
13436+ GET_THREAD_INFO(%r11)
13437 DISABLE_INTERRUPTS(CLBR_NONE)
13438 TRACE_IRQS_OFF
13439- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13440+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
13441 jnz sysexit_audit
13442 sysexit_from_sys_call:
13443- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13444+ pax_exit_kernel_user
13445+ pax_erase_kstack
13446+ andl $~TS_COMPAT,TI_status(%r11)
13447 /* clear IF, that popfq doesn't enable interrupts early */
13448 andl $~0x200,EFLAGS-R11(%rsp)
13449 movl RIP-R11(%rsp),%edx /* User %eip */
13450@@ -193,6 +243,9 @@ sysexit_from_sys_call:
13451 movl %eax,%esi /* 2nd arg: syscall number */
13452 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
13453 call __audit_syscall_entry
13454+
13455+ pax_erase_kstack
13456+
13457 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
13458 cmpq $(IA32_NR_syscalls-1),%rax
13459 ja ia32_badsys
13460@@ -204,7 +257,7 @@ sysexit_from_sys_call:
13461 .endm
13462
13463 .macro auditsys_exit exit
13464- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13465+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
13466 jnz ia32_ret_from_sys_call
13467 TRACE_IRQS_ON
13468 ENABLE_INTERRUPTS(CLBR_NONE)
13469@@ -215,11 +268,12 @@ sysexit_from_sys_call:
13470 1: setbe %al /* 1 if error, 0 if not */
13471 movzbl %al,%edi /* zero-extend that into %edi */
13472 call __audit_syscall_exit
13473+ GET_THREAD_INFO(%r11)
13474 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
13475 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
13476 DISABLE_INTERRUPTS(CLBR_NONE)
13477 TRACE_IRQS_OFF
13478- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13479+ testl %edi,TI_flags(%r11)
13480 jz \exit
13481 CLEAR_RREGS -ARGOFFSET
13482 jmp int_with_check
13483@@ -237,7 +291,7 @@ sysexit_audit:
13484
13485 sysenter_tracesys:
13486 #ifdef CONFIG_AUDITSYSCALL
13487- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13488+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
13489 jz sysenter_auditsys
13490 #endif
13491 SAVE_REST
13492@@ -249,6 +303,9 @@ sysenter_tracesys:
13493 RESTORE_REST
13494 cmpq $(IA32_NR_syscalls-1),%rax
13495 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
13496+
13497+ pax_erase_kstack
13498+
13499 jmp sysenter_do_call
13500 CFI_ENDPROC
13501 ENDPROC(ia32_sysenter_target)
13502@@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
13503 ENTRY(ia32_cstar_target)
13504 CFI_STARTPROC32 simple
13505 CFI_SIGNAL_FRAME
13506- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
13507+ CFI_DEF_CFA rsp,0
13508 CFI_REGISTER rip,rcx
13509 /*CFI_REGISTER rflags,r11*/
13510 SWAPGS_UNSAFE_STACK
13511 movl %esp,%r8d
13512 CFI_REGISTER rsp,r8
13513 movq PER_CPU_VAR(kernel_stack),%rsp
13514+ SAVE_ARGS 8*6,0,0
13515+ pax_enter_kernel_user
13516+
13517+#ifdef CONFIG_PAX_RANDKSTACK
13518+ pax_erase_kstack
13519+#endif
13520+
13521 /*
13522 * No need to follow this irqs on/off section: the syscall
13523 * disabled irqs and here we enable it straight after entry:
13524 */
13525 ENABLE_INTERRUPTS(CLBR_NONE)
13526- SAVE_ARGS 8,0,0
13527 movl %eax,%eax /* zero extension */
13528 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
13529 movq %rcx,RIP-ARGOFFSET(%rsp)
13530@@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
13531 /* no need to do an access_ok check here because r8 has been
13532 32bit zero extended */
13533 /* hardware stack frame is complete now */
13534+
13535+#ifdef CONFIG_PAX_MEMORY_UDEREF
13536+ ASM_PAX_OPEN_USERLAND
13537+ movq pax_user_shadow_base,%r8
13538+ addq RSP-ARGOFFSET(%rsp),%r8
13539+#endif
13540+
13541 ASM_STAC
13542 1: movl (%r8),%r9d
13543 _ASM_EXTABLE(1b,ia32_badarg)
13544 ASM_CLAC
13545- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13546- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13547+
13548+#ifdef CONFIG_PAX_MEMORY_UDEREF
13549+ ASM_PAX_CLOSE_USERLAND
13550+#endif
13551+
13552+ GET_THREAD_INFO(%r11)
13553+ orl $TS_COMPAT,TI_status(%r11)
13554+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
13555 CFI_REMEMBER_STATE
13556 jnz cstar_tracesys
13557 cmpq $IA32_NR_syscalls-1,%rax
13558@@ -319,12 +395,15 @@ cstar_do_call:
13559 cstar_dispatch:
13560 call *ia32_sys_call_table(,%rax,8)
13561 movq %rax,RAX-ARGOFFSET(%rsp)
13562+ GET_THREAD_INFO(%r11)
13563 DISABLE_INTERRUPTS(CLBR_NONE)
13564 TRACE_IRQS_OFF
13565- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13566+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
13567 jnz sysretl_audit
13568 sysretl_from_sys_call:
13569- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13570+ pax_exit_kernel_user
13571+ pax_erase_kstack
13572+ andl $~TS_COMPAT,TI_status(%r11)
13573 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
13574 movl RIP-ARGOFFSET(%rsp),%ecx
13575 CFI_REGISTER rip,rcx
13576@@ -352,7 +431,7 @@ sysretl_audit:
13577
13578 cstar_tracesys:
13579 #ifdef CONFIG_AUDITSYSCALL
13580- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13581+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
13582 jz cstar_auditsys
13583 #endif
13584 xchgl %r9d,%ebp
13585@@ -366,11 +445,19 @@ cstar_tracesys:
13586 xchgl %ebp,%r9d
13587 cmpq $(IA32_NR_syscalls-1),%rax
13588 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
13589+
13590+ pax_erase_kstack
13591+
13592 jmp cstar_do_call
13593 END(ia32_cstar_target)
13594
13595 ia32_badarg:
13596 ASM_CLAC
13597+
13598+#ifdef CONFIG_PAX_MEMORY_UDEREF
13599+ ASM_PAX_CLOSE_USERLAND
13600+#endif
13601+
13602 movq $-EFAULT,%rax
13603 jmp ia32_sysret
13604 CFI_ENDPROC
13605@@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
13606 CFI_REL_OFFSET rip,RIP-RIP
13607 PARAVIRT_ADJUST_EXCEPTION_FRAME
13608 SWAPGS
13609- /*
13610- * No need to follow this irqs on/off section: the syscall
13611- * disabled irqs and here we enable it straight after entry:
13612- */
13613- ENABLE_INTERRUPTS(CLBR_NONE)
13614 movl %eax,%eax
13615 pushq_cfi %rax
13616 cld
13617 /* note the registers are not zero extended to the sf.
13618 this could be a problem. */
13619 SAVE_ARGS 0,1,0
13620- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13621- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13622+ pax_enter_kernel_user
13623+
13624+#ifdef CONFIG_PAX_RANDKSTACK
13625+ pax_erase_kstack
13626+#endif
13627+
13628+ /*
13629+ * No need to follow this irqs on/off section: the syscall
13630+ * disabled irqs and here we enable it straight after entry:
13631+ */
13632+ ENABLE_INTERRUPTS(CLBR_NONE)
13633+ GET_THREAD_INFO(%r11)
13634+ orl $TS_COMPAT,TI_status(%r11)
13635+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
13636 jnz ia32_tracesys
13637 cmpq $(IA32_NR_syscalls-1),%rax
13638 ja ia32_badsys
13639@@ -442,6 +536,9 @@ ia32_tracesys:
13640 RESTORE_REST
13641 cmpq $(IA32_NR_syscalls-1),%rax
13642 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
13643+
13644+ pax_erase_kstack
13645+
13646 jmp ia32_do_call
13647 END(ia32_syscall)
13648
13649diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
13650index 8e0ceec..af13504 100644
13651--- a/arch/x86/ia32/sys_ia32.c
13652+++ b/arch/x86/ia32/sys_ia32.c
13653@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
13654 */
13655 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
13656 {
13657- typeof(ubuf->st_uid) uid = 0;
13658- typeof(ubuf->st_gid) gid = 0;
13659+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
13660+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
13661 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
13662 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
13663 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
13664diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
13665index 372231c..a5aa1a1 100644
13666--- a/arch/x86/include/asm/alternative-asm.h
13667+++ b/arch/x86/include/asm/alternative-asm.h
13668@@ -18,6 +18,45 @@
13669 .endm
13670 #endif
13671
13672+#ifdef KERNEXEC_PLUGIN
13673+ .macro pax_force_retaddr_bts rip=0
13674+ btsq $63,\rip(%rsp)
13675+ .endm
13676+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
13677+ .macro pax_force_retaddr rip=0, reload=0
13678+ btsq $63,\rip(%rsp)
13679+ .endm
13680+ .macro pax_force_fptr ptr
13681+ btsq $63,\ptr
13682+ .endm
13683+ .macro pax_set_fptr_mask
13684+ .endm
13685+#endif
13686+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
13687+ .macro pax_force_retaddr rip=0, reload=0
13688+ .if \reload
13689+ pax_set_fptr_mask
13690+ .endif
13691+ orq %r10,\rip(%rsp)
13692+ .endm
13693+ .macro pax_force_fptr ptr
13694+ orq %r10,\ptr
13695+ .endm
13696+ .macro pax_set_fptr_mask
13697+ movabs $0x8000000000000000,%r10
13698+ .endm
13699+#endif
13700+#else
13701+ .macro pax_force_retaddr rip=0, reload=0
13702+ .endm
13703+ .macro pax_force_fptr ptr
13704+ .endm
13705+ .macro pax_force_retaddr_bts rip=0
13706+ .endm
13707+ .macro pax_set_fptr_mask
13708+ .endm
13709+#endif
13710+
13711 .macro altinstruction_entry orig alt feature orig_len alt_len
13712 .long \orig - .
13713 .long \alt - .
13714diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
13715index 58ed6d9..f1cbe58 100644
13716--- a/arch/x86/include/asm/alternative.h
13717+++ b/arch/x86/include/asm/alternative.h
13718@@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
13719 ".pushsection .discard,\"aw\",@progbits\n" \
13720 DISCARD_ENTRY(1) \
13721 ".popsection\n" \
13722- ".pushsection .altinstr_replacement, \"ax\"\n" \
13723+ ".pushsection .altinstr_replacement, \"a\"\n" \
13724 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
13725 ".popsection"
13726
13727@@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
13728 DISCARD_ENTRY(1) \
13729 DISCARD_ENTRY(2) \
13730 ".popsection\n" \
13731- ".pushsection .altinstr_replacement, \"ax\"\n" \
13732+ ".pushsection .altinstr_replacement, \"a\"\n" \
13733 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
13734 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
13735 ".popsection"
13736diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
13737index f8119b5..7209d5b 100644
13738--- a/arch/x86/include/asm/apic.h
13739+++ b/arch/x86/include/asm/apic.h
13740@@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
13741
13742 #ifdef CONFIG_X86_LOCAL_APIC
13743
13744-extern unsigned int apic_verbosity;
13745+extern int apic_verbosity;
13746 extern int local_apic_timer_c2_ok;
13747
13748 extern int disable_apic;
13749diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
13750index 20370c6..a2eb9b0 100644
13751--- a/arch/x86/include/asm/apm.h
13752+++ b/arch/x86/include/asm/apm.h
13753@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
13754 __asm__ __volatile__(APM_DO_ZERO_SEGS
13755 "pushl %%edi\n\t"
13756 "pushl %%ebp\n\t"
13757- "lcall *%%cs:apm_bios_entry\n\t"
13758+ "lcall *%%ss:apm_bios_entry\n\t"
13759 "setc %%al\n\t"
13760 "popl %%ebp\n\t"
13761 "popl %%edi\n\t"
13762@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
13763 __asm__ __volatile__(APM_DO_ZERO_SEGS
13764 "pushl %%edi\n\t"
13765 "pushl %%ebp\n\t"
13766- "lcall *%%cs:apm_bios_entry\n\t"
13767+ "lcall *%%ss:apm_bios_entry\n\t"
13768 "setc %%bl\n\t"
13769 "popl %%ebp\n\t"
13770 "popl %%edi\n\t"
13771diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
13772index 722aa3b..3a0bb27 100644
13773--- a/arch/x86/include/asm/atomic.h
13774+++ b/arch/x86/include/asm/atomic.h
13775@@ -22,7 +22,18 @@
13776 */
13777 static inline int atomic_read(const atomic_t *v)
13778 {
13779- return (*(volatile int *)&(v)->counter);
13780+ return (*(volatile const int *)&(v)->counter);
13781+}
13782+
13783+/**
13784+ * atomic_read_unchecked - read atomic variable
13785+ * @v: pointer of type atomic_unchecked_t
13786+ *
13787+ * Atomically reads the value of @v.
13788+ */
13789+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
13790+{
13791+ return (*(volatile const int *)&(v)->counter);
13792 }
13793
13794 /**
13795@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
13796 }
13797
13798 /**
13799+ * atomic_set_unchecked - set atomic variable
13800+ * @v: pointer of type atomic_unchecked_t
13801+ * @i: required value
13802+ *
13803+ * Atomically sets the value of @v to @i.
13804+ */
13805+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
13806+{
13807+ v->counter = i;
13808+}
13809+
13810+/**
13811 * atomic_add - add integer to atomic variable
13812 * @i: integer value to add
13813 * @v: pointer of type atomic_t
13814@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
13815 */
13816 static inline void atomic_add(int i, atomic_t *v)
13817 {
13818- asm volatile(LOCK_PREFIX "addl %1,%0"
13819+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
13820+
13821+#ifdef CONFIG_PAX_REFCOUNT
13822+ "jno 0f\n"
13823+ LOCK_PREFIX "subl %1,%0\n"
13824+ "int $4\n0:\n"
13825+ _ASM_EXTABLE(0b, 0b)
13826+#endif
13827+
13828+ : "+m" (v->counter)
13829+ : "ir" (i));
13830+}
13831+
13832+/**
13833+ * atomic_add_unchecked - add integer to atomic variable
13834+ * @i: integer value to add
13835+ * @v: pointer of type atomic_unchecked_t
13836+ *
13837+ * Atomically adds @i to @v.
13838+ */
13839+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
13840+{
13841+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
13842 : "+m" (v->counter)
13843 : "ir" (i));
13844 }
13845@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
13846 */
13847 static inline void atomic_sub(int i, atomic_t *v)
13848 {
13849- asm volatile(LOCK_PREFIX "subl %1,%0"
13850+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
13851+
13852+#ifdef CONFIG_PAX_REFCOUNT
13853+ "jno 0f\n"
13854+ LOCK_PREFIX "addl %1,%0\n"
13855+ "int $4\n0:\n"
13856+ _ASM_EXTABLE(0b, 0b)
13857+#endif
13858+
13859+ : "+m" (v->counter)
13860+ : "ir" (i));
13861+}
13862+
13863+/**
13864+ * atomic_sub_unchecked - subtract integer from atomic variable
13865+ * @i: integer value to subtract
13866+ * @v: pointer of type atomic_unchecked_t
13867+ *
13868+ * Atomically subtracts @i from @v.
13869+ */
13870+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
13871+{
13872+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
13873 : "+m" (v->counter)
13874 : "ir" (i));
13875 }
13876@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
13877 {
13878 unsigned char c;
13879
13880- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
13881+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
13882+
13883+#ifdef CONFIG_PAX_REFCOUNT
13884+ "jno 0f\n"
13885+ LOCK_PREFIX "addl %2,%0\n"
13886+ "int $4\n0:\n"
13887+ _ASM_EXTABLE(0b, 0b)
13888+#endif
13889+
13890+ "sete %1\n"
13891 : "+m" (v->counter), "=qm" (c)
13892 : "ir" (i) : "memory");
13893 return c;
13894@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
13895 */
13896 static inline void atomic_inc(atomic_t *v)
13897 {
13898- asm volatile(LOCK_PREFIX "incl %0"
13899+ asm volatile(LOCK_PREFIX "incl %0\n"
13900+
13901+#ifdef CONFIG_PAX_REFCOUNT
13902+ "jno 0f\n"
13903+ LOCK_PREFIX "decl %0\n"
13904+ "int $4\n0:\n"
13905+ _ASM_EXTABLE(0b, 0b)
13906+#endif
13907+
13908+ : "+m" (v->counter));
13909+}
13910+
13911+/**
13912+ * atomic_inc_unchecked - increment atomic variable
13913+ * @v: pointer of type atomic_unchecked_t
13914+ *
13915+ * Atomically increments @v by 1.
13916+ */
13917+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
13918+{
13919+ asm volatile(LOCK_PREFIX "incl %0\n"
13920 : "+m" (v->counter));
13921 }
13922
13923@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
13924 */
13925 static inline void atomic_dec(atomic_t *v)
13926 {
13927- asm volatile(LOCK_PREFIX "decl %0"
13928+ asm volatile(LOCK_PREFIX "decl %0\n"
13929+
13930+#ifdef CONFIG_PAX_REFCOUNT
13931+ "jno 0f\n"
13932+ LOCK_PREFIX "incl %0\n"
13933+ "int $4\n0:\n"
13934+ _ASM_EXTABLE(0b, 0b)
13935+#endif
13936+
13937+ : "+m" (v->counter));
13938+}
13939+
13940+/**
13941+ * atomic_dec_unchecked - decrement atomic variable
13942+ * @v: pointer of type atomic_unchecked_t
13943+ *
13944+ * Atomically decrements @v by 1.
13945+ */
13946+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
13947+{
13948+ asm volatile(LOCK_PREFIX "decl %0\n"
13949 : "+m" (v->counter));
13950 }
13951
13952@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
13953 {
13954 unsigned char c;
13955
13956- asm volatile(LOCK_PREFIX "decl %0; sete %1"
13957+ asm volatile(LOCK_PREFIX "decl %0\n"
13958+
13959+#ifdef CONFIG_PAX_REFCOUNT
13960+ "jno 0f\n"
13961+ LOCK_PREFIX "incl %0\n"
13962+ "int $4\n0:\n"
13963+ _ASM_EXTABLE(0b, 0b)
13964+#endif
13965+
13966+ "sete %1\n"
13967 : "+m" (v->counter), "=qm" (c)
13968 : : "memory");
13969 return c != 0;
13970@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
13971 {
13972 unsigned char c;
13973
13974- asm volatile(LOCK_PREFIX "incl %0; sete %1"
13975+ asm volatile(LOCK_PREFIX "incl %0\n"
13976+
13977+#ifdef CONFIG_PAX_REFCOUNT
13978+ "jno 0f\n"
13979+ LOCK_PREFIX "decl %0\n"
13980+ "int $4\n0:\n"
13981+ _ASM_EXTABLE(0b, 0b)
13982+#endif
13983+
13984+ "sete %1\n"
13985+ : "+m" (v->counter), "=qm" (c)
13986+ : : "memory");
13987+ return c != 0;
13988+}
13989+
13990+/**
13991+ * atomic_inc_and_test_unchecked - increment and test
13992+ * @v: pointer of type atomic_unchecked_t
13993+ *
13994+ * Atomically increments @v by 1
13995+ * and returns true if the result is zero, or false for all
13996+ * other cases.
13997+ */
13998+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
13999+{
14000+ unsigned char c;
14001+
14002+ asm volatile(LOCK_PREFIX "incl %0\n"
14003+ "sete %1\n"
14004 : "+m" (v->counter), "=qm" (c)
14005 : : "memory");
14006 return c != 0;
14007@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
14008 {
14009 unsigned char c;
14010
14011- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
14012+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
14013+
14014+#ifdef CONFIG_PAX_REFCOUNT
14015+ "jno 0f\n"
14016+ LOCK_PREFIX "subl %2,%0\n"
14017+ "int $4\n0:\n"
14018+ _ASM_EXTABLE(0b, 0b)
14019+#endif
14020+
14021+ "sets %1\n"
14022 : "+m" (v->counter), "=qm" (c)
14023 : "ir" (i) : "memory");
14024 return c;
14025@@ -172,6 +334,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
14026 */
14027 static inline int atomic_add_return(int i, atomic_t *v)
14028 {
14029+ return i + xadd_check_overflow(&v->counter, i);
14030+}
14031+
14032+/**
14033+ * atomic_add_return_unchecked - add integer and return
14034+ * @i: integer value to add
14035+ * @v: pointer of type atomic_unchecked_t
14036+ *
14037+ * Atomically adds @i to @v and returns @i + @v
14038+ */
14039+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
14040+{
14041 return i + xadd(&v->counter, i);
14042 }
14043
14044@@ -188,6 +362,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
14045 }
14046
14047 #define atomic_inc_return(v) (atomic_add_return(1, v))
14048+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
14049+{
14050+ return atomic_add_return_unchecked(1, v);
14051+}
14052 #define atomic_dec_return(v) (atomic_sub_return(1, v))
14053
14054 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
14055@@ -195,11 +373,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
14056 return cmpxchg(&v->counter, old, new);
14057 }
14058
14059+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
14060+{
14061+ return cmpxchg(&v->counter, old, new);
14062+}
14063+
14064 static inline int atomic_xchg(atomic_t *v, int new)
14065 {
14066 return xchg(&v->counter, new);
14067 }
14068
14069+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
14070+{
14071+ return xchg(&v->counter, new);
14072+}
14073+
14074 /**
14075 * __atomic_add_unless - add unless the number is already a given value
14076 * @v: pointer of type atomic_t
14077@@ -211,12 +399,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
14078 */
14079 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
14080 {
14081- int c, old;
14082+ int c, old, new;
14083 c = atomic_read(v);
14084 for (;;) {
14085- if (unlikely(c == (u)))
14086+ if (unlikely(c == u))
14087 break;
14088- old = atomic_cmpxchg((v), c, c + (a));
14089+
14090+ asm volatile("addl %2,%0\n"
14091+
14092+#ifdef CONFIG_PAX_REFCOUNT
14093+ "jno 0f\n"
14094+ "subl %2,%0\n"
14095+ "int $4\n0:\n"
14096+ _ASM_EXTABLE(0b, 0b)
14097+#endif
14098+
14099+ : "=r" (new)
14100+ : "0" (c), "ir" (a));
14101+
14102+ old = atomic_cmpxchg(v, c, new);
14103 if (likely(old == c))
14104 break;
14105 c = old;
14106@@ -225,6 +426,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
14107 }
14108
14109 /**
14110+ * atomic_inc_not_zero_hint - increment if not null
14111+ * @v: pointer of type atomic_t
14112+ * @hint: probable value of the atomic before the increment
14113+ *
14114+ * This version of atomic_inc_not_zero() gives a hint of probable
14115+ * value of the atomic. This helps processor to not read the memory
14116+ * before doing the atomic read/modify/write cycle, lowering
14117+ * number of bus transactions on some arches.
14118+ *
14119+ * Returns: 0 if increment was not done, 1 otherwise.
14120+ */
14121+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
14122+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
14123+{
14124+ int val, c = hint, new;
14125+
14126+ /* sanity test, should be removed by compiler if hint is a constant */
14127+ if (!hint)
14128+ return __atomic_add_unless(v, 1, 0);
14129+
14130+ do {
14131+ asm volatile("incl %0\n"
14132+
14133+#ifdef CONFIG_PAX_REFCOUNT
14134+ "jno 0f\n"
14135+ "decl %0\n"
14136+ "int $4\n0:\n"
14137+ _ASM_EXTABLE(0b, 0b)
14138+#endif
14139+
14140+ : "=r" (new)
14141+ : "0" (c));
14142+
14143+ val = atomic_cmpxchg(v, c, new);
14144+ if (val == c)
14145+ return 1;
14146+ c = val;
14147+ } while (c);
14148+
14149+ return 0;
14150+}
14151+
14152+/**
14153 * atomic_inc_short - increment of a short integer
14154 * @v: pointer to type int
14155 *
14156@@ -253,14 +497,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
14157 #endif
14158
14159 /* These are x86-specific, used by some header files */
14160-#define atomic_clear_mask(mask, addr) \
14161- asm volatile(LOCK_PREFIX "andl %0,%1" \
14162- : : "r" (~(mask)), "m" (*(addr)) : "memory")
14163+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
14164+{
14165+ asm volatile(LOCK_PREFIX "andl %1,%0"
14166+ : "+m" (v->counter)
14167+ : "r" (~(mask))
14168+ : "memory");
14169+}
14170
14171-#define atomic_set_mask(mask, addr) \
14172- asm volatile(LOCK_PREFIX "orl %0,%1" \
14173- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
14174- : "memory")
14175+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
14176+{
14177+ asm volatile(LOCK_PREFIX "andl %1,%0"
14178+ : "+m" (v->counter)
14179+ : "r" (~(mask))
14180+ : "memory");
14181+}
14182+
14183+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
14184+{
14185+ asm volatile(LOCK_PREFIX "orl %1,%0"
14186+ : "+m" (v->counter)
14187+ : "r" (mask)
14188+ : "memory");
14189+}
14190+
14191+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
14192+{
14193+ asm volatile(LOCK_PREFIX "orl %1,%0"
14194+ : "+m" (v->counter)
14195+ : "r" (mask)
14196+ : "memory");
14197+}
14198
14199 /* Atomic operations are already serializing on x86 */
14200 #define smp_mb__before_atomic_dec() barrier()
14201diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
14202index b154de7..aadebd8 100644
14203--- a/arch/x86/include/asm/atomic64_32.h
14204+++ b/arch/x86/include/asm/atomic64_32.h
14205@@ -12,6 +12,14 @@ typedef struct {
14206 u64 __aligned(8) counter;
14207 } atomic64_t;
14208
14209+#ifdef CONFIG_PAX_REFCOUNT
14210+typedef struct {
14211+ u64 __aligned(8) counter;
14212+} atomic64_unchecked_t;
14213+#else
14214+typedef atomic64_t atomic64_unchecked_t;
14215+#endif
14216+
14217 #define ATOMIC64_INIT(val) { (val) }
14218
14219 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
14220@@ -37,21 +45,31 @@ typedef struct {
14221 ATOMIC64_DECL_ONE(sym##_386)
14222
14223 ATOMIC64_DECL_ONE(add_386);
14224+ATOMIC64_DECL_ONE(add_unchecked_386);
14225 ATOMIC64_DECL_ONE(sub_386);
14226+ATOMIC64_DECL_ONE(sub_unchecked_386);
14227 ATOMIC64_DECL_ONE(inc_386);
14228+ATOMIC64_DECL_ONE(inc_unchecked_386);
14229 ATOMIC64_DECL_ONE(dec_386);
14230+ATOMIC64_DECL_ONE(dec_unchecked_386);
14231 #endif
14232
14233 #define alternative_atomic64(f, out, in...) \
14234 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
14235
14236 ATOMIC64_DECL(read);
14237+ATOMIC64_DECL(read_unchecked);
14238 ATOMIC64_DECL(set);
14239+ATOMIC64_DECL(set_unchecked);
14240 ATOMIC64_DECL(xchg);
14241 ATOMIC64_DECL(add_return);
14242+ATOMIC64_DECL(add_return_unchecked);
14243 ATOMIC64_DECL(sub_return);
14244+ATOMIC64_DECL(sub_return_unchecked);
14245 ATOMIC64_DECL(inc_return);
14246+ATOMIC64_DECL(inc_return_unchecked);
14247 ATOMIC64_DECL(dec_return);
14248+ATOMIC64_DECL(dec_return_unchecked);
14249 ATOMIC64_DECL(dec_if_positive);
14250 ATOMIC64_DECL(inc_not_zero);
14251 ATOMIC64_DECL(add_unless);
14252@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
14253 }
14254
14255 /**
14256+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
14257+ * @p: pointer to type atomic64_unchecked_t
14258+ * @o: expected value
14259+ * @n: new value
14260+ *
14261+ * Atomically sets @v to @n if it was equal to @o and returns
14262+ * the old value.
14263+ */
14264+
14265+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
14266+{
14267+ return cmpxchg64(&v->counter, o, n);
14268+}
14269+
14270+/**
14271 * atomic64_xchg - xchg atomic64 variable
14272 * @v: pointer to type atomic64_t
14273 * @n: value to assign
14274@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
14275 }
14276
14277 /**
14278+ * atomic64_set_unchecked - set atomic64 variable
14279+ * @v: pointer to type atomic64_unchecked_t
14280+ * @n: value to assign
14281+ *
14282+ * Atomically sets the value of @v to @n.
14283+ */
14284+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
14285+{
14286+ unsigned high = (unsigned)(i >> 32);
14287+ unsigned low = (unsigned)i;
14288+ alternative_atomic64(set, /* no output */,
14289+ "S" (v), "b" (low), "c" (high)
14290+ : "eax", "edx", "memory");
14291+}
14292+
14293+/**
14294 * atomic64_read - read atomic64 variable
14295 * @v: pointer to type atomic64_t
14296 *
14297@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
14298 }
14299
14300 /**
14301+ * atomic64_read_unchecked - read atomic64 variable
14302+ * @v: pointer to type atomic64_unchecked_t
14303+ *
14304+ * Atomically reads the value of @v and returns it.
14305+ */
14306+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
14307+{
14308+ long long r;
14309+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
14310+ return r;
14311+ }
14312+
14313+/**
14314 * atomic64_add_return - add and return
14315 * @i: integer value to add
14316 * @v: pointer to type atomic64_t
14317@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
14318 return i;
14319 }
14320
14321+/**
14322+ * atomic64_add_return_unchecked - add and return
14323+ * @i: integer value to add
14324+ * @v: pointer to type atomic64_unchecked_t
14325+ *
14326+ * Atomically adds @i to @v and returns @i + *@v
14327+ */
14328+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
14329+{
14330+ alternative_atomic64(add_return_unchecked,
14331+ ASM_OUTPUT2("+A" (i), "+c" (v)),
14332+ ASM_NO_INPUT_CLOBBER("memory"));
14333+ return i;
14334+}
14335+
14336 /*
14337 * Other variants with different arithmetic operators:
14338 */
14339@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
14340 return a;
14341 }
14342
14343+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
14344+{
14345+ long long a;
14346+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
14347+ "S" (v) : "memory", "ecx");
14348+ return a;
14349+}
14350+
14351 static inline long long atomic64_dec_return(atomic64_t *v)
14352 {
14353 long long a;
14354@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
14355 }
14356
14357 /**
14358+ * atomic64_add_unchecked - add integer to atomic64 variable
14359+ * @i: integer value to add
14360+ * @v: pointer to type atomic64_unchecked_t
14361+ *
14362+ * Atomically adds @i to @v.
14363+ */
14364+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
14365+{
14366+ __alternative_atomic64(add_unchecked, add_return_unchecked,
14367+ ASM_OUTPUT2("+A" (i), "+c" (v)),
14368+ ASM_NO_INPUT_CLOBBER("memory"));
14369+ return i;
14370+}
14371+
14372+/**
14373 * atomic64_sub - subtract the atomic64 variable
14374 * @i: integer value to subtract
14375 * @v: pointer to type atomic64_t
14376diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
14377index 0e1cbfc..5623683 100644
14378--- a/arch/x86/include/asm/atomic64_64.h
14379+++ b/arch/x86/include/asm/atomic64_64.h
14380@@ -18,7 +18,19 @@
14381 */
14382 static inline long atomic64_read(const atomic64_t *v)
14383 {
14384- return (*(volatile long *)&(v)->counter);
14385+ return (*(volatile const long *)&(v)->counter);
14386+}
14387+
14388+/**
14389+ * atomic64_read_unchecked - read atomic64 variable
14390+ * @v: pointer of type atomic64_unchecked_t
14391+ *
14392+ * Atomically reads the value of @v.
14393+ * Doesn't imply a read memory barrier.
14394+ */
14395+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
14396+{
14397+ return (*(volatile const long *)&(v)->counter);
14398 }
14399
14400 /**
14401@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
14402 }
14403
14404 /**
14405+ * atomic64_set_unchecked - set atomic64 variable
14406+ * @v: pointer to type atomic64_unchecked_t
14407+ * @i: required value
14408+ *
14409+ * Atomically sets the value of @v to @i.
14410+ */
14411+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
14412+{
14413+ v->counter = i;
14414+}
14415+
14416+/**
14417 * atomic64_add - add integer to atomic64 variable
14418 * @i: integer value to add
14419 * @v: pointer to type atomic64_t
14420@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
14421 */
14422 static inline void atomic64_add(long i, atomic64_t *v)
14423 {
14424+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
14425+
14426+#ifdef CONFIG_PAX_REFCOUNT
14427+ "jno 0f\n"
14428+ LOCK_PREFIX "subq %1,%0\n"
14429+ "int $4\n0:\n"
14430+ _ASM_EXTABLE(0b, 0b)
14431+#endif
14432+
14433+ : "=m" (v->counter)
14434+ : "er" (i), "m" (v->counter));
14435+}
14436+
14437+/**
14438+ * atomic64_add_unchecked - add integer to atomic64 variable
14439+ * @i: integer value to add
14440+ * @v: pointer to type atomic64_unchecked_t
14441+ *
14442+ * Atomically adds @i to @v.
14443+ */
14444+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
14445+{
14446 asm volatile(LOCK_PREFIX "addq %1,%0"
14447 : "=m" (v->counter)
14448 : "er" (i), "m" (v->counter));
14449@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
14450 */
14451 static inline void atomic64_sub(long i, atomic64_t *v)
14452 {
14453- asm volatile(LOCK_PREFIX "subq %1,%0"
14454+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
14455+
14456+#ifdef CONFIG_PAX_REFCOUNT
14457+ "jno 0f\n"
14458+ LOCK_PREFIX "addq %1,%0\n"
14459+ "int $4\n0:\n"
14460+ _ASM_EXTABLE(0b, 0b)
14461+#endif
14462+
14463+ : "=m" (v->counter)
14464+ : "er" (i), "m" (v->counter));
14465+}
14466+
14467+/**
14468+ * atomic64_sub_unchecked - subtract the atomic64 variable
14469+ * @i: integer value to subtract
14470+ * @v: pointer to type atomic64_unchecked_t
14471+ *
14472+ * Atomically subtracts @i from @v.
14473+ */
14474+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
14475+{
14476+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
14477 : "=m" (v->counter)
14478 : "er" (i), "m" (v->counter));
14479 }
14480@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
14481 {
14482 unsigned char c;
14483
14484- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
14485+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
14486+
14487+#ifdef CONFIG_PAX_REFCOUNT
14488+ "jno 0f\n"
14489+ LOCK_PREFIX "addq %2,%0\n"
14490+ "int $4\n0:\n"
14491+ _ASM_EXTABLE(0b, 0b)
14492+#endif
14493+
14494+ "sete %1\n"
14495 : "=m" (v->counter), "=qm" (c)
14496 : "er" (i), "m" (v->counter) : "memory");
14497 return c;
14498@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
14499 */
14500 static inline void atomic64_inc(atomic64_t *v)
14501 {
14502+ asm volatile(LOCK_PREFIX "incq %0\n"
14503+
14504+#ifdef CONFIG_PAX_REFCOUNT
14505+ "jno 0f\n"
14506+ LOCK_PREFIX "decq %0\n"
14507+ "int $4\n0:\n"
14508+ _ASM_EXTABLE(0b, 0b)
14509+#endif
14510+
14511+ : "=m" (v->counter)
14512+ : "m" (v->counter));
14513+}
14514+
14515+/**
14516+ * atomic64_inc_unchecked - increment atomic64 variable
14517+ * @v: pointer to type atomic64_unchecked_t
14518+ *
14519+ * Atomically increments @v by 1.
14520+ */
14521+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
14522+{
14523 asm volatile(LOCK_PREFIX "incq %0"
14524 : "=m" (v->counter)
14525 : "m" (v->counter));
14526@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
14527 */
14528 static inline void atomic64_dec(atomic64_t *v)
14529 {
14530- asm volatile(LOCK_PREFIX "decq %0"
14531+ asm volatile(LOCK_PREFIX "decq %0\n"
14532+
14533+#ifdef CONFIG_PAX_REFCOUNT
14534+ "jno 0f\n"
14535+ LOCK_PREFIX "incq %0\n"
14536+ "int $4\n0:\n"
14537+ _ASM_EXTABLE(0b, 0b)
14538+#endif
14539+
14540+ : "=m" (v->counter)
14541+ : "m" (v->counter));
14542+}
14543+
14544+/**
14545+ * atomic64_dec_unchecked - decrement atomic64 variable
14546+ * @v: pointer to type atomic64_t
14547+ *
14548+ * Atomically decrements @v by 1.
14549+ */
14550+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
14551+{
14552+ asm volatile(LOCK_PREFIX "decq %0\n"
14553 : "=m" (v->counter)
14554 : "m" (v->counter));
14555 }
14556@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
14557 {
14558 unsigned char c;
14559
14560- asm volatile(LOCK_PREFIX "decq %0; sete %1"
14561+ asm volatile(LOCK_PREFIX "decq %0\n"
14562+
14563+#ifdef CONFIG_PAX_REFCOUNT
14564+ "jno 0f\n"
14565+ LOCK_PREFIX "incq %0\n"
14566+ "int $4\n0:\n"
14567+ _ASM_EXTABLE(0b, 0b)
14568+#endif
14569+
14570+ "sete %1\n"
14571 : "=m" (v->counter), "=qm" (c)
14572 : "m" (v->counter) : "memory");
14573 return c != 0;
14574@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
14575 {
14576 unsigned char c;
14577
14578- asm volatile(LOCK_PREFIX "incq %0; sete %1"
14579+ asm volatile(LOCK_PREFIX "incq %0\n"
14580+
14581+#ifdef CONFIG_PAX_REFCOUNT
14582+ "jno 0f\n"
14583+ LOCK_PREFIX "decq %0\n"
14584+ "int $4\n0:\n"
14585+ _ASM_EXTABLE(0b, 0b)
14586+#endif
14587+
14588+ "sete %1\n"
14589 : "=m" (v->counter), "=qm" (c)
14590 : "m" (v->counter) : "memory");
14591 return c != 0;
14592@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
14593 {
14594 unsigned char c;
14595
14596- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
14597+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
14598+
14599+#ifdef CONFIG_PAX_REFCOUNT
14600+ "jno 0f\n"
14601+ LOCK_PREFIX "subq %2,%0\n"
14602+ "int $4\n0:\n"
14603+ _ASM_EXTABLE(0b, 0b)
14604+#endif
14605+
14606+ "sets %1\n"
14607 : "=m" (v->counter), "=qm" (c)
14608 : "er" (i), "m" (v->counter) : "memory");
14609 return c;
14610@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
14611 */
14612 static inline long atomic64_add_return(long i, atomic64_t *v)
14613 {
14614+ return i + xadd_check_overflow(&v->counter, i);
14615+}
14616+
14617+/**
14618+ * atomic64_add_return_unchecked - add and return
14619+ * @i: integer value to add
14620+ * @v: pointer to type atomic64_unchecked_t
14621+ *
14622+ * Atomically adds @i to @v and returns @i + @v
14623+ */
14624+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
14625+{
14626 return i + xadd(&v->counter, i);
14627 }
14628
14629@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
14630 }
14631
14632 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
14633+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
14634+{
14635+ return atomic64_add_return_unchecked(1, v);
14636+}
14637 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
14638
14639 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
14640@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
14641 return cmpxchg(&v->counter, old, new);
14642 }
14643
14644+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
14645+{
14646+ return cmpxchg(&v->counter, old, new);
14647+}
14648+
14649 static inline long atomic64_xchg(atomic64_t *v, long new)
14650 {
14651 return xchg(&v->counter, new);
14652@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
14653 */
14654 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
14655 {
14656- long c, old;
14657+ long c, old, new;
14658 c = atomic64_read(v);
14659 for (;;) {
14660- if (unlikely(c == (u)))
14661+ if (unlikely(c == u))
14662 break;
14663- old = atomic64_cmpxchg((v), c, c + (a));
14664+
14665+ asm volatile("add %2,%0\n"
14666+
14667+#ifdef CONFIG_PAX_REFCOUNT
14668+ "jno 0f\n"
14669+ "sub %2,%0\n"
14670+ "int $4\n0:\n"
14671+ _ASM_EXTABLE(0b, 0b)
14672+#endif
14673+
14674+ : "=r" (new)
14675+ : "0" (c), "ir" (a));
14676+
14677+ old = atomic64_cmpxchg(v, c, new);
14678 if (likely(old == c))
14679 break;
14680 c = old;
14681 }
14682- return c != (u);
14683+ return c != u;
14684 }
14685
14686 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
14687diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
14688index 6dfd019..28e188d 100644
14689--- a/arch/x86/include/asm/bitops.h
14690+++ b/arch/x86/include/asm/bitops.h
14691@@ -40,7 +40,7 @@
14692 * a mask operation on a byte.
14693 */
14694 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
14695-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
14696+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
14697 #define CONST_MASK(nr) (1 << ((nr) & 7))
14698
14699 /**
14700@@ -486,7 +486,7 @@ static inline int fls(int x)
14701 * at position 64.
14702 */
14703 #ifdef CONFIG_X86_64
14704-static __always_inline int fls64(__u64 x)
14705+static __always_inline long fls64(__u64 x)
14706 {
14707 int bitpos = -1;
14708 /*
14709diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
14710index 4fa687a..60f2d39 100644
14711--- a/arch/x86/include/asm/boot.h
14712+++ b/arch/x86/include/asm/boot.h
14713@@ -6,10 +6,15 @@
14714 #include <uapi/asm/boot.h>
14715
14716 /* Physical address where kernel should be loaded. */
14717-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
14718+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
14719 + (CONFIG_PHYSICAL_ALIGN - 1)) \
14720 & ~(CONFIG_PHYSICAL_ALIGN - 1))
14721
14722+#ifndef __ASSEMBLY__
14723+extern unsigned char __LOAD_PHYSICAL_ADDR[];
14724+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
14725+#endif
14726+
14727 /* Minimum kernel alignment, as a power of two */
14728 #ifdef CONFIG_X86_64
14729 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
14730diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
14731index 48f99f1..d78ebf9 100644
14732--- a/arch/x86/include/asm/cache.h
14733+++ b/arch/x86/include/asm/cache.h
14734@@ -5,12 +5,13 @@
14735
14736 /* L1 cache line size */
14737 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
14738-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
14739+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
14740
14741 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
14742+#define __read_only __attribute__((__section__(".data..read_only")))
14743
14744 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
14745-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
14746+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
14747
14748 #ifdef CONFIG_X86_VSMP
14749 #ifdef CONFIG_SMP
14750diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
14751index 9863ee3..4a1f8e1 100644
14752--- a/arch/x86/include/asm/cacheflush.h
14753+++ b/arch/x86/include/asm/cacheflush.h
14754@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
14755 unsigned long pg_flags = pg->flags & _PGMT_MASK;
14756
14757 if (pg_flags == _PGMT_DEFAULT)
14758- return -1;
14759+ return ~0UL;
14760 else if (pg_flags == _PGMT_WC)
14761 return _PAGE_CACHE_WC;
14762 else if (pg_flags == _PGMT_UC_MINUS)
14763diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
14764index f50de69..2b0a458 100644
14765--- a/arch/x86/include/asm/checksum_32.h
14766+++ b/arch/x86/include/asm/checksum_32.h
14767@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
14768 int len, __wsum sum,
14769 int *src_err_ptr, int *dst_err_ptr);
14770
14771+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
14772+ int len, __wsum sum,
14773+ int *src_err_ptr, int *dst_err_ptr);
14774+
14775+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
14776+ int len, __wsum sum,
14777+ int *src_err_ptr, int *dst_err_ptr);
14778+
14779 /*
14780 * Note: when you get a NULL pointer exception here this means someone
14781 * passed in an incorrect kernel address to one of these functions.
14782@@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
14783
14784 might_sleep();
14785 stac();
14786- ret = csum_partial_copy_generic((__force void *)src, dst,
14787+ ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
14788 len, sum, err_ptr, NULL);
14789 clac();
14790
14791@@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
14792 might_sleep();
14793 if (access_ok(VERIFY_WRITE, dst, len)) {
14794 stac();
14795- ret = csum_partial_copy_generic(src, (__force void *)dst,
14796+ ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
14797 len, sum, NULL, err_ptr);
14798 clac();
14799 return ret;
14800diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
14801index d47786a..ce1b05d 100644
14802--- a/arch/x86/include/asm/cmpxchg.h
14803+++ b/arch/x86/include/asm/cmpxchg.h
14804@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
14805 __compiletime_error("Bad argument size for cmpxchg");
14806 extern void __xadd_wrong_size(void)
14807 __compiletime_error("Bad argument size for xadd");
14808+extern void __xadd_check_overflow_wrong_size(void)
14809+ __compiletime_error("Bad argument size for xadd_check_overflow");
14810 extern void __add_wrong_size(void)
14811 __compiletime_error("Bad argument size for add");
14812+extern void __add_check_overflow_wrong_size(void)
14813+ __compiletime_error("Bad argument size for add_check_overflow");
14814
14815 /*
14816 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
14817@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
14818 __ret; \
14819 })
14820
14821+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
14822+ ({ \
14823+ __typeof__ (*(ptr)) __ret = (arg); \
14824+ switch (sizeof(*(ptr))) { \
14825+ case __X86_CASE_L: \
14826+ asm volatile (lock #op "l %0, %1\n" \
14827+ "jno 0f\n" \
14828+ "mov %0,%1\n" \
14829+ "int $4\n0:\n" \
14830+ _ASM_EXTABLE(0b, 0b) \
14831+ : "+r" (__ret), "+m" (*(ptr)) \
14832+ : : "memory", "cc"); \
14833+ break; \
14834+ case __X86_CASE_Q: \
14835+ asm volatile (lock #op "q %q0, %1\n" \
14836+ "jno 0f\n" \
14837+ "mov %0,%1\n" \
14838+ "int $4\n0:\n" \
14839+ _ASM_EXTABLE(0b, 0b) \
14840+ : "+r" (__ret), "+m" (*(ptr)) \
14841+ : : "memory", "cc"); \
14842+ break; \
14843+ default: \
14844+ __ ## op ## _check_overflow_wrong_size(); \
14845+ } \
14846+ __ret; \
14847+ })
14848+
14849 /*
14850 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
14851 * Since this is generally used to protect other memory information, we
14852@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
14853 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
14854 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
14855
14856+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
14857+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
14858+
14859 #define __add(ptr, inc, lock) \
14860 ({ \
14861 __typeof__ (*(ptr)) __ret = (inc); \
14862diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
14863index 59c6c40..5e0b22c 100644
14864--- a/arch/x86/include/asm/compat.h
14865+++ b/arch/x86/include/asm/compat.h
14866@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
14867 typedef u32 compat_uint_t;
14868 typedef u32 compat_ulong_t;
14869 typedef u64 __attribute__((aligned(4))) compat_u64;
14870-typedef u32 compat_uptr_t;
14871+typedef u32 __user compat_uptr_t;
14872
14873 struct compat_timespec {
14874 compat_time_t tv_sec;
14875diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
14876index 7290585..717e89e 100644
14877--- a/arch/x86/include/asm/cpufeature.h
14878+++ b/arch/x86/include/asm/cpufeature.h
14879@@ -203,7 +203,7 @@
14880 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
14881 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
14882 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
14883-
14884+#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
14885
14886 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
14887 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
14888@@ -211,7 +211,7 @@
14889 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
14890 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
14891 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
14892-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
14893+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
14894 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
14895 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
14896 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
14897@@ -353,6 +353,7 @@ extern const char * const x86_power_flags[32];
14898 #undef cpu_has_centaur_mcr
14899 #define cpu_has_centaur_mcr 0
14900
14901+#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
14902 #endif /* CONFIG_X86_64 */
14903
14904 #if __GNUC__ >= 4
14905@@ -403,7 +404,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
14906
14907 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
14908 t_warn:
14909- warn_pre_alternatives();
14910+ if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
14911+ warn_pre_alternatives();
14912 return false;
14913 #endif
14914 #else /* GCC_VERSION >= 40500 */
14915@@ -421,7 +423,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
14916 ".section .discard,\"aw\",@progbits\n"
14917 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
14918 ".previous\n"
14919- ".section .altinstr_replacement,\"ax\"\n"
14920+ ".section .altinstr_replacement,\"a\"\n"
14921 "3: movb $1,%0\n"
14922 "4:\n"
14923 ".previous\n"
14924@@ -457,7 +459,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
14925 " .byte 2b - 1b\n" /* src len */
14926 " .byte 4f - 3f\n" /* repl len */
14927 ".previous\n"
14928- ".section .altinstr_replacement,\"ax\"\n"
14929+ ".section .altinstr_replacement,\"a\"\n"
14930 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
14931 "4:\n"
14932 ".previous\n"
14933@@ -490,7 +492,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
14934 ".section .discard,\"aw\",@progbits\n"
14935 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
14936 ".previous\n"
14937- ".section .altinstr_replacement,\"ax\"\n"
14938+ ".section .altinstr_replacement,\"a\"\n"
14939 "3: movb $0,%0\n"
14940 "4:\n"
14941 ".previous\n"
14942@@ -504,7 +506,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
14943 ".section .discard,\"aw\",@progbits\n"
14944 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
14945 ".previous\n"
14946- ".section .altinstr_replacement,\"ax\"\n"
14947+ ".section .altinstr_replacement,\"a\"\n"
14948 "5: movb $1,%0\n"
14949 "6:\n"
14950 ".previous\n"
14951diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
14952index b90e5df..b462c91 100644
14953--- a/arch/x86/include/asm/desc.h
14954+++ b/arch/x86/include/asm/desc.h
14955@@ -4,6 +4,7 @@
14956 #include <asm/desc_defs.h>
14957 #include <asm/ldt.h>
14958 #include <asm/mmu.h>
14959+#include <asm/pgtable.h>
14960
14961 #include <linux/smp.h>
14962 #include <linux/percpu.h>
14963@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
14964
14965 desc->type = (info->read_exec_only ^ 1) << 1;
14966 desc->type |= info->contents << 2;
14967+ desc->type |= info->seg_not_present ^ 1;
14968
14969 desc->s = 1;
14970 desc->dpl = 0x3;
14971@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
14972 }
14973
14974 extern struct desc_ptr idt_descr;
14975-extern gate_desc idt_table[];
14976-extern struct desc_ptr debug_idt_descr;
14977-extern gate_desc debug_idt_table[];
14978-
14979-struct gdt_page {
14980- struct desc_struct gdt[GDT_ENTRIES];
14981-} __attribute__((aligned(PAGE_SIZE)));
14982-
14983-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
14984+extern gate_desc idt_table[IDT_ENTRIES];
14985+extern const struct desc_ptr debug_idt_descr;
14986+extern gate_desc debug_idt_table[IDT_ENTRIES];
14987
14988+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
14989 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
14990 {
14991- return per_cpu(gdt_page, cpu).gdt;
14992+ return cpu_gdt_table[cpu];
14993 }
14994
14995 #ifdef CONFIG_X86_64
14996@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
14997 unsigned long base, unsigned dpl, unsigned flags,
14998 unsigned short seg)
14999 {
15000- gate->a = (seg << 16) | (base & 0xffff);
15001- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
15002+ gate->gate.offset_low = base;
15003+ gate->gate.seg = seg;
15004+ gate->gate.reserved = 0;
15005+ gate->gate.type = type;
15006+ gate->gate.s = 0;
15007+ gate->gate.dpl = dpl;
15008+ gate->gate.p = 1;
15009+ gate->gate.offset_high = base >> 16;
15010 }
15011
15012 #endif
15013@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
15014
15015 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
15016 {
15017+ pax_open_kernel();
15018 memcpy(&idt[entry], gate, sizeof(*gate));
15019+ pax_close_kernel();
15020 }
15021
15022 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
15023 {
15024+ pax_open_kernel();
15025 memcpy(&ldt[entry], desc, 8);
15026+ pax_close_kernel();
15027 }
15028
15029 static inline void
15030@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
15031 default: size = sizeof(*gdt); break;
15032 }
15033
15034+ pax_open_kernel();
15035 memcpy(&gdt[entry], desc, size);
15036+ pax_close_kernel();
15037 }
15038
15039 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
15040@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
15041
15042 static inline void native_load_tr_desc(void)
15043 {
15044+ pax_open_kernel();
15045 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
15046+ pax_close_kernel();
15047 }
15048
15049 static inline void native_load_gdt(const struct desc_ptr *dtr)
15050@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
15051 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
15052 unsigned int i;
15053
15054+ pax_open_kernel();
15055 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
15056 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
15057+ pax_close_kernel();
15058 }
15059
15060 #define _LDT_empty(info) \
15061@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
15062 preempt_enable();
15063 }
15064
15065-static inline unsigned long get_desc_base(const struct desc_struct *desc)
15066+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
15067 {
15068 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
15069 }
15070@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
15071 }
15072
15073 #ifdef CONFIG_X86_64
15074-static inline void set_nmi_gate(int gate, void *addr)
15075+static inline void set_nmi_gate(int gate, const void *addr)
15076 {
15077 gate_desc s;
15078
15079@@ -321,8 +334,8 @@ static inline void set_nmi_gate(int gate, void *addr)
15080 #endif
15081
15082 #ifdef CONFIG_TRACING
15083-extern struct desc_ptr trace_idt_descr;
15084-extern gate_desc trace_idt_table[];
15085+extern const struct desc_ptr trace_idt_descr;
15086+extern gate_desc trace_idt_table[IDT_ENTRIES];
15087 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
15088 {
15089 write_idt_entry(trace_idt_table, entry, gate);
15090@@ -333,7 +346,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
15091 }
15092 #endif
15093
15094-static inline void _set_gate(int gate, unsigned type, void *addr,
15095+static inline void _set_gate(int gate, unsigned type, const void *addr,
15096 unsigned dpl, unsigned ist, unsigned seg)
15097 {
15098 gate_desc s;
15099@@ -353,7 +366,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
15100 * Pentium F0 0F bugfix can have resulted in the mapped
15101 * IDT being write-protected.
15102 */
15103-static inline void set_intr_gate(unsigned int n, void *addr)
15104+static inline void set_intr_gate(unsigned int n, const void *addr)
15105 {
15106 BUG_ON((unsigned)n > 0xFF);
15107 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
15108@@ -410,19 +423,19 @@ static inline void __alloc_intr_gate(unsigned int n, void *addr)
15109 /*
15110 * This routine sets up an interrupt gate at directory privilege level 3.
15111 */
15112-static inline void set_system_intr_gate(unsigned int n, void *addr)
15113+static inline void set_system_intr_gate(unsigned int n, const void *addr)
15114 {
15115 BUG_ON((unsigned)n > 0xFF);
15116 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
15117 }
15118
15119-static inline void set_system_trap_gate(unsigned int n, void *addr)
15120+static inline void set_system_trap_gate(unsigned int n, const void *addr)
15121 {
15122 BUG_ON((unsigned)n > 0xFF);
15123 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
15124 }
15125
15126-static inline void set_trap_gate(unsigned int n, void *addr)
15127+static inline void set_trap_gate(unsigned int n, const void *addr)
15128 {
15129 BUG_ON((unsigned)n > 0xFF);
15130 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
15131@@ -431,16 +444,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
15132 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
15133 {
15134 BUG_ON((unsigned)n > 0xFF);
15135- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
15136+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
15137 }
15138
15139-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
15140+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
15141 {
15142 BUG_ON((unsigned)n > 0xFF);
15143 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
15144 }
15145
15146-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
15147+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
15148 {
15149 BUG_ON((unsigned)n > 0xFF);
15150 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
15151@@ -512,4 +525,17 @@ static inline void load_current_idt(void)
15152 else
15153 load_idt((const struct desc_ptr *)&idt_descr);
15154 }
15155+
15156+#ifdef CONFIG_X86_32
15157+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
15158+{
15159+ struct desc_struct d;
15160+
15161+ if (likely(limit))
15162+ limit = (limit - 1UL) >> PAGE_SHIFT;
15163+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
15164+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
15165+}
15166+#endif
15167+
15168 #endif /* _ASM_X86_DESC_H */
15169diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
15170index 278441f..b95a174 100644
15171--- a/arch/x86/include/asm/desc_defs.h
15172+++ b/arch/x86/include/asm/desc_defs.h
15173@@ -31,6 +31,12 @@ struct desc_struct {
15174 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
15175 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
15176 };
15177+ struct {
15178+ u16 offset_low;
15179+ u16 seg;
15180+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
15181+ unsigned offset_high: 16;
15182+ } gate;
15183 };
15184 } __attribute__((packed));
15185
15186diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
15187index ced283a..ffe04cc 100644
15188--- a/arch/x86/include/asm/div64.h
15189+++ b/arch/x86/include/asm/div64.h
15190@@ -39,7 +39,7 @@
15191 __mod; \
15192 })
15193
15194-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
15195+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
15196 {
15197 union {
15198 u64 v64;
15199diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
15200index 9c999c1..3860cb8 100644
15201--- a/arch/x86/include/asm/elf.h
15202+++ b/arch/x86/include/asm/elf.h
15203@@ -243,7 +243,25 @@ extern int force_personality32;
15204 the loader. We need to make sure that it is out of the way of the program
15205 that it will "exec", and that there is sufficient room for the brk. */
15206
15207+#ifdef CONFIG_PAX_SEGMEXEC
15208+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
15209+#else
15210 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
15211+#endif
15212+
15213+#ifdef CONFIG_PAX_ASLR
15214+#ifdef CONFIG_X86_32
15215+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
15216+
15217+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
15218+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
15219+#else
15220+#define PAX_ELF_ET_DYN_BASE 0x400000UL
15221+
15222+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
15223+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
15224+#endif
15225+#endif
15226
15227 /* This yields a mask that user programs can use to figure out what
15228 instruction set this CPU supports. This could be done in user space,
15229@@ -296,16 +314,12 @@ do { \
15230
15231 #define ARCH_DLINFO \
15232 do { \
15233- if (vdso_enabled) \
15234- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
15235- (unsigned long)current->mm->context.vdso); \
15236+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
15237 } while (0)
15238
15239 #define ARCH_DLINFO_X32 \
15240 do { \
15241- if (vdso_enabled) \
15242- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
15243- (unsigned long)current->mm->context.vdso); \
15244+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
15245 } while (0)
15246
15247 #define AT_SYSINFO 32
15248@@ -320,7 +334,7 @@ else \
15249
15250 #endif /* !CONFIG_X86_32 */
15251
15252-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
15253+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
15254
15255 #define VDSO_ENTRY \
15256 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
15257@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
15258 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
15259 #define compat_arch_setup_additional_pages syscall32_setup_pages
15260
15261-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
15262-#define arch_randomize_brk arch_randomize_brk
15263-
15264 /*
15265 * True on X86_32 or when emulating IA32 on X86_64
15266 */
15267diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
15268index 77a99ac..39ff7f5 100644
15269--- a/arch/x86/include/asm/emergency-restart.h
15270+++ b/arch/x86/include/asm/emergency-restart.h
15271@@ -1,6 +1,6 @@
15272 #ifndef _ASM_X86_EMERGENCY_RESTART_H
15273 #define _ASM_X86_EMERGENCY_RESTART_H
15274
15275-extern void machine_emergency_restart(void);
15276+extern void machine_emergency_restart(void) __noreturn;
15277
15278 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
15279diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
15280index 4d0bda7..221da4d 100644
15281--- a/arch/x86/include/asm/fpu-internal.h
15282+++ b/arch/x86/include/asm/fpu-internal.h
15283@@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
15284 #define user_insn(insn, output, input...) \
15285 ({ \
15286 int err; \
15287+ pax_open_userland(); \
15288 asm volatile(ASM_STAC "\n" \
15289- "1:" #insn "\n\t" \
15290+ "1:" \
15291+ __copyuser_seg \
15292+ #insn "\n\t" \
15293 "2: " ASM_CLAC "\n" \
15294 ".section .fixup,\"ax\"\n" \
15295 "3: movl $-1,%[err]\n" \
15296@@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
15297 _ASM_EXTABLE(1b, 3b) \
15298 : [err] "=r" (err), output \
15299 : "0"(0), input); \
15300+ pax_close_userland(); \
15301 err; \
15302 })
15303
15304@@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
15305 "emms\n\t" /* clear stack tags */
15306 "fildl %P[addr]", /* set F?P to defined value */
15307 X86_FEATURE_FXSAVE_LEAK,
15308- [addr] "m" (tsk->thread.fpu.has_fpu));
15309+ [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
15310
15311 return fpu_restore_checking(&tsk->thread.fpu);
15312 }
15313diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
15314index be27ba1..04a8801 100644
15315--- a/arch/x86/include/asm/futex.h
15316+++ b/arch/x86/include/asm/futex.h
15317@@ -12,6 +12,7 @@
15318 #include <asm/smap.h>
15319
15320 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
15321+ typecheck(u32 __user *, uaddr); \
15322 asm volatile("\t" ASM_STAC "\n" \
15323 "1:\t" insn "\n" \
15324 "2:\t" ASM_CLAC "\n" \
15325@@ -20,15 +21,16 @@
15326 "\tjmp\t2b\n" \
15327 "\t.previous\n" \
15328 _ASM_EXTABLE(1b, 3b) \
15329- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
15330+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
15331 : "i" (-EFAULT), "0" (oparg), "1" (0))
15332
15333 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
15334+ typecheck(u32 __user *, uaddr); \
15335 asm volatile("\t" ASM_STAC "\n" \
15336 "1:\tmovl %2, %0\n" \
15337 "\tmovl\t%0, %3\n" \
15338 "\t" insn "\n" \
15339- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
15340+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
15341 "\tjnz\t1b\n" \
15342 "3:\t" ASM_CLAC "\n" \
15343 "\t.section .fixup,\"ax\"\n" \
15344@@ -38,7 +40,7 @@
15345 _ASM_EXTABLE(1b, 4b) \
15346 _ASM_EXTABLE(2b, 4b) \
15347 : "=&a" (oldval), "=&r" (ret), \
15348- "+m" (*uaddr), "=&r" (tem) \
15349+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
15350 : "r" (oparg), "i" (-EFAULT), "1" (0))
15351
15352 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
15353@@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
15354
15355 pagefault_disable();
15356
15357+ pax_open_userland();
15358 switch (op) {
15359 case FUTEX_OP_SET:
15360- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
15361+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
15362 break;
15363 case FUTEX_OP_ADD:
15364- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
15365+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
15366 uaddr, oparg);
15367 break;
15368 case FUTEX_OP_OR:
15369@@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
15370 default:
15371 ret = -ENOSYS;
15372 }
15373+ pax_close_userland();
15374
15375 pagefault_enable();
15376
15377@@ -115,18 +119,20 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
15378 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
15379 return -EFAULT;
15380
15381+ pax_open_userland();
15382 asm volatile("\t" ASM_STAC "\n"
15383- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
15384+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
15385 "2:\t" ASM_CLAC "\n"
15386 "\t.section .fixup, \"ax\"\n"
15387 "3:\tmov %3, %0\n"
15388 "\tjmp 2b\n"
15389 "\t.previous\n"
15390 _ASM_EXTABLE(1b, 3b)
15391- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
15392+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
15393 : "i" (-EFAULT), "r" (newval), "1" (oldval)
15394 : "memory"
15395 );
15396+ pax_close_userland();
15397
15398 *uval = oldval;
15399 return ret;
15400diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
15401index e4ac559..c1c0c87 100644
15402--- a/arch/x86/include/asm/hw_irq.h
15403+++ b/arch/x86/include/asm/hw_irq.h
15404@@ -165,8 +165,8 @@ extern void setup_ioapic_dest(void);
15405 extern void enable_IO_APIC(void);
15406
15407 /* Statistics */
15408-extern atomic_t irq_err_count;
15409-extern atomic_t irq_mis_count;
15410+extern atomic_unchecked_t irq_err_count;
15411+extern atomic_unchecked_t irq_mis_count;
15412
15413 /* EISA */
15414 extern void eisa_set_level_irq(unsigned int irq);
15415diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
15416index a203659..9889f1c 100644
15417--- a/arch/x86/include/asm/i8259.h
15418+++ b/arch/x86/include/asm/i8259.h
15419@@ -62,7 +62,7 @@ struct legacy_pic {
15420 void (*init)(int auto_eoi);
15421 int (*irq_pending)(unsigned int irq);
15422 void (*make_irq)(unsigned int irq);
15423-};
15424+} __do_const;
15425
15426 extern struct legacy_pic *legacy_pic;
15427 extern struct legacy_pic null_legacy_pic;
15428diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
15429index 34f69cb..6d95446 100644
15430--- a/arch/x86/include/asm/io.h
15431+++ b/arch/x86/include/asm/io.h
15432@@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
15433 "m" (*(volatile type __force *)addr) barrier); }
15434
15435 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
15436-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
15437-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
15438+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
15439+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
15440
15441 build_mmio_read(__readb, "b", unsigned char, "=q", )
15442-build_mmio_read(__readw, "w", unsigned short, "=r", )
15443-build_mmio_read(__readl, "l", unsigned int, "=r", )
15444+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
15445+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
15446
15447 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
15448 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
15449@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
15450 return ioremap_nocache(offset, size);
15451 }
15452
15453-extern void iounmap(volatile void __iomem *addr);
15454+extern void iounmap(const volatile void __iomem *addr);
15455
15456 extern void set_iounmap_nonlazy(void);
15457
15458@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
15459
15460 #include <linux/vmalloc.h>
15461
15462+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
15463+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
15464+{
15465+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
15466+}
15467+
15468+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
15469+{
15470+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
15471+}
15472+
15473 /*
15474 * Convert a virtual cached pointer to an uncached pointer
15475 */
15476diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
15477index bba3cf8..06bc8da 100644
15478--- a/arch/x86/include/asm/irqflags.h
15479+++ b/arch/x86/include/asm/irqflags.h
15480@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
15481 sti; \
15482 sysexit
15483
15484+#define GET_CR0_INTO_RDI mov %cr0, %rdi
15485+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
15486+#define GET_CR3_INTO_RDI mov %cr3, %rdi
15487+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
15488+
15489 #else
15490 #define INTERRUPT_RETURN iret
15491 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
15492diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
15493index 5a6d287..f815789 100644
15494--- a/arch/x86/include/asm/kprobes.h
15495+++ b/arch/x86/include/asm/kprobes.h
15496@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
15497 #define RELATIVEJUMP_SIZE 5
15498 #define RELATIVECALL_OPCODE 0xe8
15499 #define RELATIVE_ADDR_SIZE 4
15500-#define MAX_STACK_SIZE 64
15501-#define MIN_STACK_SIZE(ADDR) \
15502- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
15503- THREAD_SIZE - (unsigned long)(ADDR))) \
15504- ? (MAX_STACK_SIZE) \
15505- : (((unsigned long)current_thread_info()) + \
15506- THREAD_SIZE - (unsigned long)(ADDR)))
15507+#define MAX_STACK_SIZE 64UL
15508+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
15509
15510 #define flush_insn_slot(p) do { } while (0)
15511
15512diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
15513index 2d89e39..baee879 100644
15514--- a/arch/x86/include/asm/local.h
15515+++ b/arch/x86/include/asm/local.h
15516@@ -10,33 +10,97 @@ typedef struct {
15517 atomic_long_t a;
15518 } local_t;
15519
15520+typedef struct {
15521+ atomic_long_unchecked_t a;
15522+} local_unchecked_t;
15523+
15524 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
15525
15526 #define local_read(l) atomic_long_read(&(l)->a)
15527+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
15528 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
15529+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
15530
15531 static inline void local_inc(local_t *l)
15532 {
15533- asm volatile(_ASM_INC "%0"
15534+ asm volatile(_ASM_INC "%0\n"
15535+
15536+#ifdef CONFIG_PAX_REFCOUNT
15537+ "jno 0f\n"
15538+ _ASM_DEC "%0\n"
15539+ "int $4\n0:\n"
15540+ _ASM_EXTABLE(0b, 0b)
15541+#endif
15542+
15543+ : "+m" (l->a.counter));
15544+}
15545+
15546+static inline void local_inc_unchecked(local_unchecked_t *l)
15547+{
15548+ asm volatile(_ASM_INC "%0\n"
15549 : "+m" (l->a.counter));
15550 }
15551
15552 static inline void local_dec(local_t *l)
15553 {
15554- asm volatile(_ASM_DEC "%0"
15555+ asm volatile(_ASM_DEC "%0\n"
15556+
15557+#ifdef CONFIG_PAX_REFCOUNT
15558+ "jno 0f\n"
15559+ _ASM_INC "%0\n"
15560+ "int $4\n0:\n"
15561+ _ASM_EXTABLE(0b, 0b)
15562+#endif
15563+
15564+ : "+m" (l->a.counter));
15565+}
15566+
15567+static inline void local_dec_unchecked(local_unchecked_t *l)
15568+{
15569+ asm volatile(_ASM_DEC "%0\n"
15570 : "+m" (l->a.counter));
15571 }
15572
15573 static inline void local_add(long i, local_t *l)
15574 {
15575- asm volatile(_ASM_ADD "%1,%0"
15576+ asm volatile(_ASM_ADD "%1,%0\n"
15577+
15578+#ifdef CONFIG_PAX_REFCOUNT
15579+ "jno 0f\n"
15580+ _ASM_SUB "%1,%0\n"
15581+ "int $4\n0:\n"
15582+ _ASM_EXTABLE(0b, 0b)
15583+#endif
15584+
15585+ : "+m" (l->a.counter)
15586+ : "ir" (i));
15587+}
15588+
15589+static inline void local_add_unchecked(long i, local_unchecked_t *l)
15590+{
15591+ asm volatile(_ASM_ADD "%1,%0\n"
15592 : "+m" (l->a.counter)
15593 : "ir" (i));
15594 }
15595
15596 static inline void local_sub(long i, local_t *l)
15597 {
15598- asm volatile(_ASM_SUB "%1,%0"
15599+ asm volatile(_ASM_SUB "%1,%0\n"
15600+
15601+#ifdef CONFIG_PAX_REFCOUNT
15602+ "jno 0f\n"
15603+ _ASM_ADD "%1,%0\n"
15604+ "int $4\n0:\n"
15605+ _ASM_EXTABLE(0b, 0b)
15606+#endif
15607+
15608+ : "+m" (l->a.counter)
15609+ : "ir" (i));
15610+}
15611+
15612+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
15613+{
15614+ asm volatile(_ASM_SUB "%1,%0\n"
15615 : "+m" (l->a.counter)
15616 : "ir" (i));
15617 }
15618@@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
15619 {
15620 unsigned char c;
15621
15622- asm volatile(_ASM_SUB "%2,%0; sete %1"
15623+ asm volatile(_ASM_SUB "%2,%0\n"
15624+
15625+#ifdef CONFIG_PAX_REFCOUNT
15626+ "jno 0f\n"
15627+ _ASM_ADD "%2,%0\n"
15628+ "int $4\n0:\n"
15629+ _ASM_EXTABLE(0b, 0b)
15630+#endif
15631+
15632+ "sete %1\n"
15633 : "+m" (l->a.counter), "=qm" (c)
15634 : "ir" (i) : "memory");
15635 return c;
15636@@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
15637 {
15638 unsigned char c;
15639
15640- asm volatile(_ASM_DEC "%0; sete %1"
15641+ asm volatile(_ASM_DEC "%0\n"
15642+
15643+#ifdef CONFIG_PAX_REFCOUNT
15644+ "jno 0f\n"
15645+ _ASM_INC "%0\n"
15646+ "int $4\n0:\n"
15647+ _ASM_EXTABLE(0b, 0b)
15648+#endif
15649+
15650+ "sete %1\n"
15651 : "+m" (l->a.counter), "=qm" (c)
15652 : : "memory");
15653 return c != 0;
15654@@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
15655 {
15656 unsigned char c;
15657
15658- asm volatile(_ASM_INC "%0; sete %1"
15659+ asm volatile(_ASM_INC "%0\n"
15660+
15661+#ifdef CONFIG_PAX_REFCOUNT
15662+ "jno 0f\n"
15663+ _ASM_DEC "%0\n"
15664+ "int $4\n0:\n"
15665+ _ASM_EXTABLE(0b, 0b)
15666+#endif
15667+
15668+ "sete %1\n"
15669 : "+m" (l->a.counter), "=qm" (c)
15670 : : "memory");
15671 return c != 0;
15672@@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
15673 {
15674 unsigned char c;
15675
15676- asm volatile(_ASM_ADD "%2,%0; sets %1"
15677+ asm volatile(_ASM_ADD "%2,%0\n"
15678+
15679+#ifdef CONFIG_PAX_REFCOUNT
15680+ "jno 0f\n"
15681+ _ASM_SUB "%2,%0\n"
15682+ "int $4\n0:\n"
15683+ _ASM_EXTABLE(0b, 0b)
15684+#endif
15685+
15686+ "sets %1\n"
15687 : "+m" (l->a.counter), "=qm" (c)
15688 : "ir" (i) : "memory");
15689 return c;
15690@@ -125,6 +225,30 @@ static inline int local_add_negative(long i, local_t *l)
15691 static inline long local_add_return(long i, local_t *l)
15692 {
15693 long __i = i;
15694+ asm volatile(_ASM_XADD "%0, %1\n"
15695+
15696+#ifdef CONFIG_PAX_REFCOUNT
15697+ "jno 0f\n"
15698+ _ASM_MOV "%0,%1\n"
15699+ "int $4\n0:\n"
15700+ _ASM_EXTABLE(0b, 0b)
15701+#endif
15702+
15703+ : "+r" (i), "+m" (l->a.counter)
15704+ : : "memory");
15705+ return i + __i;
15706+}
15707+
15708+/**
15709+ * local_add_return_unchecked - add and return
15710+ * @i: integer value to add
15711+ * @l: pointer to type local_unchecked_t
15712+ *
15713+ * Atomically adds @i to @l and returns @i + @l
15714+ */
15715+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
15716+{
15717+ long __i = i;
15718 asm volatile(_ASM_XADD "%0, %1;"
15719 : "+r" (i), "+m" (l->a.counter)
15720 : : "memory");
15721@@ -141,6 +265,8 @@ static inline long local_sub_return(long i, local_t *l)
15722
15723 #define local_cmpxchg(l, o, n) \
15724 (cmpxchg_local(&((l)->a.counter), (o), (n)))
15725+#define local_cmpxchg_unchecked(l, o, n) \
15726+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
15727 /* Always has a lock prefix */
15728 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
15729
15730diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
15731new file mode 100644
15732index 0000000..2bfd3ba
15733--- /dev/null
15734+++ b/arch/x86/include/asm/mman.h
15735@@ -0,0 +1,15 @@
15736+#ifndef _X86_MMAN_H
15737+#define _X86_MMAN_H
15738+
15739+#include <uapi/asm/mman.h>
15740+
15741+#ifdef __KERNEL__
15742+#ifndef __ASSEMBLY__
15743+#ifdef CONFIG_X86_32
15744+#define arch_mmap_check i386_mmap_check
15745+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
15746+#endif
15747+#endif
15748+#endif
15749+
15750+#endif /* X86_MMAN_H */
15751diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
15752index 5f55e69..e20bfb1 100644
15753--- a/arch/x86/include/asm/mmu.h
15754+++ b/arch/x86/include/asm/mmu.h
15755@@ -9,7 +9,7 @@
15756 * we put the segment information here.
15757 */
15758 typedef struct {
15759- void *ldt;
15760+ struct desc_struct *ldt;
15761 int size;
15762
15763 #ifdef CONFIG_X86_64
15764@@ -18,7 +18,19 @@ typedef struct {
15765 #endif
15766
15767 struct mutex lock;
15768- void *vdso;
15769+ unsigned long vdso;
15770+
15771+#ifdef CONFIG_X86_32
15772+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
15773+ unsigned long user_cs_base;
15774+ unsigned long user_cs_limit;
15775+
15776+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
15777+ cpumask_t cpu_user_cs_mask;
15778+#endif
15779+
15780+#endif
15781+#endif
15782 } mm_context_t;
15783
15784 #ifdef CONFIG_SMP
15785diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
15786index be12c53..2124e35 100644
15787--- a/arch/x86/include/asm/mmu_context.h
15788+++ b/arch/x86/include/asm/mmu_context.h
15789@@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
15790
15791 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
15792 {
15793+
15794+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15795+ if (!(static_cpu_has(X86_FEATURE_PCID))) {
15796+ unsigned int i;
15797+ pgd_t *pgd;
15798+
15799+ pax_open_kernel();
15800+ pgd = get_cpu_pgd(smp_processor_id(), kernel);
15801+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
15802+ set_pgd_batched(pgd+i, native_make_pgd(0));
15803+ pax_close_kernel();
15804+ }
15805+#endif
15806+
15807 #ifdef CONFIG_SMP
15808 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
15809 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
15810@@ -34,16 +48,55 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
15811 struct task_struct *tsk)
15812 {
15813 unsigned cpu = smp_processor_id();
15814+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
15815+ int tlbstate = TLBSTATE_OK;
15816+#endif
15817
15818 if (likely(prev != next)) {
15819 #ifdef CONFIG_SMP
15820+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
15821+ tlbstate = this_cpu_read(cpu_tlbstate.state);
15822+#endif
15823 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
15824 this_cpu_write(cpu_tlbstate.active_mm, next);
15825 #endif
15826 cpumask_set_cpu(cpu, mm_cpumask(next));
15827
15828 /* Re-load page tables */
15829+#ifdef CONFIG_PAX_PER_CPU_PGD
15830+ pax_open_kernel();
15831+
15832+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15833+ if (static_cpu_has(X86_FEATURE_PCID))
15834+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
15835+ else
15836+#endif
15837+
15838+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
15839+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
15840+ pax_close_kernel();
15841+ BUG_ON((__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL) != (read_cr3() & __PHYSICAL_MASK) && (__pa(get_cpu_pgd(cpu, user)) | PCID_USER) != (read_cr3() & __PHYSICAL_MASK));
15842+
15843+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15844+ if (static_cpu_has(X86_FEATURE_PCID)) {
15845+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
15846+ u64 descriptor[2];
15847+ descriptor[0] = PCID_USER;
15848+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
15849+ } else {
15850+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
15851+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
15852+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
15853+ else
15854+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
15855+ }
15856+ } else
15857+#endif
15858+
15859+ load_cr3(get_cpu_pgd(cpu, kernel));
15860+#else
15861 load_cr3(next->pgd);
15862+#endif
15863
15864 /* Stop flush ipis for the previous mm */
15865 cpumask_clear_cpu(cpu, mm_cpumask(prev));
15866@@ -51,9 +104,63 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
15867 /* Load the LDT, if the LDT is different: */
15868 if (unlikely(prev->context.ldt != next->context.ldt))
15869 load_LDT_nolock(&next->context);
15870+
15871+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
15872+ if (!(__supported_pte_mask & _PAGE_NX)) {
15873+ smp_mb__before_clear_bit();
15874+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
15875+ smp_mb__after_clear_bit();
15876+ cpu_set(cpu, next->context.cpu_user_cs_mask);
15877+ }
15878+#endif
15879+
15880+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
15881+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
15882+ prev->context.user_cs_limit != next->context.user_cs_limit))
15883+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
15884+#ifdef CONFIG_SMP
15885+ else if (unlikely(tlbstate != TLBSTATE_OK))
15886+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
15887+#endif
15888+#endif
15889+
15890 }
15891+ else {
15892+
15893+#ifdef CONFIG_PAX_PER_CPU_PGD
15894+ pax_open_kernel();
15895+
15896+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15897+ if (static_cpu_has(X86_FEATURE_PCID))
15898+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
15899+ else
15900+#endif
15901+
15902+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
15903+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
15904+ pax_close_kernel();
15905+ 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));
15906+
15907+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15908+ if (static_cpu_has(X86_FEATURE_PCID)) {
15909+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
15910+ u64 descriptor[2];
15911+ descriptor[0] = PCID_USER;
15912+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
15913+ } else {
15914+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
15915+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
15916+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
15917+ else
15918+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
15919+ }
15920+ } else
15921+#endif
15922+
15923+ load_cr3(get_cpu_pgd(cpu, kernel));
15924+#endif
15925+
15926 #ifdef CONFIG_SMP
15927- else {
15928 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
15929 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
15930
15931@@ -70,11 +177,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
15932 * tlb flush IPI delivery. We must reload CR3
15933 * to make sure to use no freed page tables.
15934 */
15935+
15936+#ifndef CONFIG_PAX_PER_CPU_PGD
15937 load_cr3(next->pgd);
15938+#endif
15939+
15940 load_LDT_nolock(&next->context);
15941+
15942+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
15943+ if (!(__supported_pte_mask & _PAGE_NX))
15944+ cpu_set(cpu, next->context.cpu_user_cs_mask);
15945+#endif
15946+
15947+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
15948+#ifdef CONFIG_PAX_PAGEEXEC
15949+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
15950+#endif
15951+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
15952+#endif
15953+
15954 }
15955+#endif
15956 }
15957-#endif
15958 }
15959
15960 #define activate_mm(prev, next) \
15961diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
15962index e3b7819..b257c64 100644
15963--- a/arch/x86/include/asm/module.h
15964+++ b/arch/x86/include/asm/module.h
15965@@ -5,6 +5,7 @@
15966
15967 #ifdef CONFIG_X86_64
15968 /* X86_64 does not define MODULE_PROC_FAMILY */
15969+#define MODULE_PROC_FAMILY ""
15970 #elif defined CONFIG_M486
15971 #define MODULE_PROC_FAMILY "486 "
15972 #elif defined CONFIG_M586
15973@@ -57,8 +58,20 @@
15974 #error unknown processor family
15975 #endif
15976
15977-#ifdef CONFIG_X86_32
15978-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
15979+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
15980+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
15981+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
15982+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
15983+#else
15984+#define MODULE_PAX_KERNEXEC ""
15985 #endif
15986
15987+#ifdef CONFIG_PAX_MEMORY_UDEREF
15988+#define MODULE_PAX_UDEREF "UDEREF "
15989+#else
15990+#define MODULE_PAX_UDEREF ""
15991+#endif
15992+
15993+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
15994+
15995 #endif /* _ASM_X86_MODULE_H */
15996diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
15997index 86f9301..b365cda 100644
15998--- a/arch/x86/include/asm/nmi.h
15999+++ b/arch/x86/include/asm/nmi.h
16000@@ -40,11 +40,11 @@ struct nmiaction {
16001 nmi_handler_t handler;
16002 unsigned long flags;
16003 const char *name;
16004-};
16005+} __do_const;
16006
16007 #define register_nmi_handler(t, fn, fg, n, init...) \
16008 ({ \
16009- static struct nmiaction init fn##_na = { \
16010+ static const struct nmiaction init fn##_na = { \
16011 .handler = (fn), \
16012 .name = (n), \
16013 .flags = (fg), \
16014@@ -52,7 +52,7 @@ struct nmiaction {
16015 __register_nmi_handler((t), &fn##_na); \
16016 })
16017
16018-int __register_nmi_handler(unsigned int, struct nmiaction *);
16019+int __register_nmi_handler(unsigned int, const struct nmiaction *);
16020
16021 void unregister_nmi_handler(unsigned int, const char *);
16022
16023diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
16024index c878924..21f4889 100644
16025--- a/arch/x86/include/asm/page.h
16026+++ b/arch/x86/include/asm/page.h
16027@@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
16028 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
16029
16030 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
16031+#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
16032
16033 #define __boot_va(x) __va(x)
16034 #define __boot_pa(x) __pa(x)
16035diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
16036index 0f1ddee..e2fc3d1 100644
16037--- a/arch/x86/include/asm/page_64.h
16038+++ b/arch/x86/include/asm/page_64.h
16039@@ -7,9 +7,9 @@
16040
16041 /* duplicated to the one in bootmem.h */
16042 extern unsigned long max_pfn;
16043-extern unsigned long phys_base;
16044+extern const unsigned long phys_base;
16045
16046-static inline unsigned long __phys_addr_nodebug(unsigned long x)
16047+static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
16048 {
16049 unsigned long y = x - __START_KERNEL_map;
16050
16051diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
16052index cfdc9ee..3f7b5d6 100644
16053--- a/arch/x86/include/asm/paravirt.h
16054+++ b/arch/x86/include/asm/paravirt.h
16055@@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
16056 return (pmd_t) { ret };
16057 }
16058
16059-static inline pmdval_t pmd_val(pmd_t pmd)
16060+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
16061 {
16062 pmdval_t ret;
16063
16064@@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
16065 val);
16066 }
16067
16068+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
16069+{
16070+ pgdval_t val = native_pgd_val(pgd);
16071+
16072+ if (sizeof(pgdval_t) > sizeof(long))
16073+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
16074+ val, (u64)val >> 32);
16075+ else
16076+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
16077+ val);
16078+}
16079+
16080 static inline void pgd_clear(pgd_t *pgdp)
16081 {
16082 set_pgd(pgdp, __pgd(0));
16083@@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
16084 pv_mmu_ops.set_fixmap(idx, phys, flags);
16085 }
16086
16087+#ifdef CONFIG_PAX_KERNEXEC
16088+static inline unsigned long pax_open_kernel(void)
16089+{
16090+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
16091+}
16092+
16093+static inline unsigned long pax_close_kernel(void)
16094+{
16095+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
16096+}
16097+#else
16098+static inline unsigned long pax_open_kernel(void) { return 0; }
16099+static inline unsigned long pax_close_kernel(void) { return 0; }
16100+#endif
16101+
16102 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
16103
16104 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
16105@@ -926,7 +953,7 @@ extern void default_banner(void);
16106
16107 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
16108 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
16109-#define PARA_INDIRECT(addr) *%cs:addr
16110+#define PARA_INDIRECT(addr) *%ss:addr
16111 #endif
16112
16113 #define INTERRUPT_RETURN \
16114@@ -1001,6 +1028,21 @@ extern void default_banner(void);
16115 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
16116 CLBR_NONE, \
16117 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
16118+
16119+#define GET_CR0_INTO_RDI \
16120+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
16121+ mov %rax,%rdi
16122+
16123+#define SET_RDI_INTO_CR0 \
16124+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
16125+
16126+#define GET_CR3_INTO_RDI \
16127+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
16128+ mov %rax,%rdi
16129+
16130+#define SET_RDI_INTO_CR3 \
16131+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
16132+
16133 #endif /* CONFIG_X86_32 */
16134
16135 #endif /* __ASSEMBLY__ */
16136diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
16137index 0db1fca..52310cc 100644
16138--- a/arch/x86/include/asm/paravirt_types.h
16139+++ b/arch/x86/include/asm/paravirt_types.h
16140@@ -84,7 +84,7 @@ struct pv_init_ops {
16141 */
16142 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
16143 unsigned long addr, unsigned len);
16144-};
16145+} __no_const;
16146
16147
16148 struct pv_lazy_ops {
16149@@ -98,7 +98,7 @@ struct pv_time_ops {
16150 unsigned long long (*sched_clock)(void);
16151 unsigned long long (*steal_clock)(int cpu);
16152 unsigned long (*get_tsc_khz)(void);
16153-};
16154+} __no_const;
16155
16156 struct pv_cpu_ops {
16157 /* hooks for various privileged instructions */
16158@@ -192,7 +192,7 @@ struct pv_cpu_ops {
16159
16160 void (*start_context_switch)(struct task_struct *prev);
16161 void (*end_context_switch)(struct task_struct *next);
16162-};
16163+} __no_const;
16164
16165 struct pv_irq_ops {
16166 /*
16167@@ -223,7 +223,7 @@ struct pv_apic_ops {
16168 unsigned long start_eip,
16169 unsigned long start_esp);
16170 #endif
16171-};
16172+} __no_const;
16173
16174 struct pv_mmu_ops {
16175 unsigned long (*read_cr2)(void);
16176@@ -313,6 +313,7 @@ struct pv_mmu_ops {
16177 struct paravirt_callee_save make_pud;
16178
16179 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
16180+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
16181 #endif /* PAGETABLE_LEVELS == 4 */
16182 #endif /* PAGETABLE_LEVELS >= 3 */
16183
16184@@ -324,6 +325,12 @@ struct pv_mmu_ops {
16185 an mfn. We can tell which is which from the index. */
16186 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
16187 phys_addr_t phys, pgprot_t flags);
16188+
16189+#ifdef CONFIG_PAX_KERNEXEC
16190+ unsigned long (*pax_open_kernel)(void);
16191+ unsigned long (*pax_close_kernel)(void);
16192+#endif
16193+
16194 };
16195
16196 struct arch_spinlock;
16197@@ -334,7 +341,7 @@ struct pv_lock_ops {
16198 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
16199 int (*spin_trylock)(struct arch_spinlock *lock);
16200 void (*spin_unlock)(struct arch_spinlock *lock);
16201-};
16202+} __no_const;
16203
16204 /* This contains all the paravirt structures: we get a convenient
16205 * number for each function using the offset which we use to indicate
16206diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
16207index b4389a4..7024269 100644
16208--- a/arch/x86/include/asm/pgalloc.h
16209+++ b/arch/x86/include/asm/pgalloc.h
16210@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
16211 pmd_t *pmd, pte_t *pte)
16212 {
16213 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
16214+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
16215+}
16216+
16217+static inline void pmd_populate_user(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) | _PAGE_TABLE));
16222 }
16223
16224@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
16225
16226 #ifdef CONFIG_X86_PAE
16227 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
16228+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
16229+{
16230+ pud_populate(mm, pudp, pmd);
16231+}
16232 #else /* !CONFIG_X86_PAE */
16233 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
16234 {
16235 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
16236 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
16237 }
16238+
16239+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
16240+{
16241+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
16242+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
16243+}
16244 #endif /* CONFIG_X86_PAE */
16245
16246 #if PAGETABLE_LEVELS > 3
16247@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
16248 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
16249 }
16250
16251+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
16252+{
16253+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
16254+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
16255+}
16256+
16257 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
16258 {
16259 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
16260diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
16261index 3bf2dd0..23d2a9f 100644
16262--- a/arch/x86/include/asm/pgtable-2level.h
16263+++ b/arch/x86/include/asm/pgtable-2level.h
16264@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
16265
16266 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
16267 {
16268+ pax_open_kernel();
16269 *pmdp = pmd;
16270+ pax_close_kernel();
16271 }
16272
16273 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
16274diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
16275index 81bb91b..9392125 100644
16276--- a/arch/x86/include/asm/pgtable-3level.h
16277+++ b/arch/x86/include/asm/pgtable-3level.h
16278@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
16279
16280 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
16281 {
16282+ pax_open_kernel();
16283 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
16284+ pax_close_kernel();
16285 }
16286
16287 static inline void native_set_pud(pud_t *pudp, pud_t pud)
16288 {
16289+ pax_open_kernel();
16290 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
16291+ pax_close_kernel();
16292 }
16293
16294 /*
16295diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
16296index 1c00631..845f898 100644
16297--- a/arch/x86/include/asm/pgtable.h
16298+++ b/arch/x86/include/asm/pgtable.h
16299@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
16300
16301 #ifndef __PAGETABLE_PUD_FOLDED
16302 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
16303+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
16304 #define pgd_clear(pgd) native_pgd_clear(pgd)
16305 #endif
16306
16307@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
16308
16309 #define arch_end_context_switch(prev) do {} while(0)
16310
16311+#define pax_open_kernel() native_pax_open_kernel()
16312+#define pax_close_kernel() native_pax_close_kernel()
16313 #endif /* CONFIG_PARAVIRT */
16314
16315+#define __HAVE_ARCH_PAX_OPEN_KERNEL
16316+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
16317+
16318+#ifdef CONFIG_PAX_KERNEXEC
16319+static inline unsigned long native_pax_open_kernel(void)
16320+{
16321+ unsigned long cr0;
16322+
16323+ preempt_disable();
16324+ barrier();
16325+ cr0 = read_cr0() ^ X86_CR0_WP;
16326+ BUG_ON(cr0 & X86_CR0_WP);
16327+ write_cr0(cr0);
16328+ return cr0 ^ X86_CR0_WP;
16329+}
16330+
16331+static inline unsigned long native_pax_close_kernel(void)
16332+{
16333+ unsigned long cr0;
16334+
16335+ cr0 = read_cr0() ^ X86_CR0_WP;
16336+ BUG_ON(!(cr0 & X86_CR0_WP));
16337+ write_cr0(cr0);
16338+ barrier();
16339+ preempt_enable_no_resched();
16340+ return cr0 ^ X86_CR0_WP;
16341+}
16342+#else
16343+static inline unsigned long native_pax_open_kernel(void) { return 0; }
16344+static inline unsigned long native_pax_close_kernel(void) { return 0; }
16345+#endif
16346+
16347 /*
16348 * The following only work if pte_present() is true.
16349 * Undefined behaviour if not..
16350 */
16351+static inline int pte_user(pte_t pte)
16352+{
16353+ return pte_val(pte) & _PAGE_USER;
16354+}
16355+
16356 static inline int pte_dirty(pte_t pte)
16357 {
16358 return pte_flags(pte) & _PAGE_DIRTY;
16359@@ -147,6 +187,11 @@ static inline unsigned long pud_pfn(pud_t pud)
16360 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
16361 }
16362
16363+static inline unsigned long pgd_pfn(pgd_t pgd)
16364+{
16365+ return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
16366+}
16367+
16368 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
16369
16370 static inline int pmd_large(pmd_t pte)
16371@@ -200,9 +245,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
16372 return pte_clear_flags(pte, _PAGE_RW);
16373 }
16374
16375+static inline pte_t pte_mkread(pte_t pte)
16376+{
16377+ return __pte(pte_val(pte) | _PAGE_USER);
16378+}
16379+
16380 static inline pte_t pte_mkexec(pte_t pte)
16381 {
16382- return pte_clear_flags(pte, _PAGE_NX);
16383+#ifdef CONFIG_X86_PAE
16384+ if (__supported_pte_mask & _PAGE_NX)
16385+ return pte_clear_flags(pte, _PAGE_NX);
16386+ else
16387+#endif
16388+ return pte_set_flags(pte, _PAGE_USER);
16389+}
16390+
16391+static inline pte_t pte_exprotect(pte_t pte)
16392+{
16393+#ifdef CONFIG_X86_PAE
16394+ if (__supported_pte_mask & _PAGE_NX)
16395+ return pte_set_flags(pte, _PAGE_NX);
16396+ else
16397+#endif
16398+ return pte_clear_flags(pte, _PAGE_USER);
16399 }
16400
16401 static inline pte_t pte_mkdirty(pte_t pte)
16402@@ -444,6 +509,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
16403 #endif
16404
16405 #ifndef __ASSEMBLY__
16406+
16407+#ifdef CONFIG_PAX_PER_CPU_PGD
16408+extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
16409+enum cpu_pgd_type {kernel = 0, user = 1};
16410+static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
16411+{
16412+ return cpu_pgd[cpu][type];
16413+}
16414+#endif
16415+
16416 #include <linux/mm_types.h>
16417 #include <linux/log2.h>
16418
16419@@ -576,7 +651,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
16420 * Currently stuck as a macro due to indirect forward reference to
16421 * linux/mmzone.h's __section_mem_map_addr() definition:
16422 */
16423-#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
16424+#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
16425
16426 /* Find an entry in the second-level page table.. */
16427 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
16428@@ -616,7 +691,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
16429 * Currently stuck as a macro due to indirect forward reference to
16430 * linux/mmzone.h's __section_mem_map_addr() definition:
16431 */
16432-#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
16433+#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
16434
16435 /* to find an entry in a page-table-directory. */
16436 static inline unsigned long pud_index(unsigned long address)
16437@@ -631,7 +706,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
16438
16439 static inline int pgd_bad(pgd_t pgd)
16440 {
16441- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
16442+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
16443 }
16444
16445 static inline int pgd_none(pgd_t pgd)
16446@@ -654,7 +729,12 @@ static inline int pgd_none(pgd_t pgd)
16447 * pgd_offset() returns a (pgd_t *)
16448 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
16449 */
16450-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
16451+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
16452+
16453+#ifdef CONFIG_PAX_PER_CPU_PGD
16454+#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
16455+#endif
16456+
16457 /*
16458 * a shortcut which implies the use of the kernel's pgd, instead
16459 * of a process's
16460@@ -665,6 +745,23 @@ static inline int pgd_none(pgd_t pgd)
16461 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
16462 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
16463
16464+#ifdef CONFIG_X86_32
16465+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
16466+#else
16467+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
16468+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
16469+
16470+#ifdef CONFIG_PAX_MEMORY_UDEREF
16471+#ifdef __ASSEMBLY__
16472+#define pax_user_shadow_base pax_user_shadow_base(%rip)
16473+#else
16474+extern unsigned long pax_user_shadow_base;
16475+extern pgdval_t clone_pgd_mask;
16476+#endif
16477+#endif
16478+
16479+#endif
16480+
16481 #ifndef __ASSEMBLY__
16482
16483 extern int direct_gbpages;
16484@@ -831,11 +928,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
16485 * dst and src can be on the same page, but the range must not overlap,
16486 * and must not cross a page boundary.
16487 */
16488-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
16489+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
16490 {
16491- memcpy(dst, src, count * sizeof(pgd_t));
16492+ pax_open_kernel();
16493+ while (count--)
16494+ *dst++ = *src++;
16495+ pax_close_kernel();
16496 }
16497
16498+#ifdef CONFIG_PAX_PER_CPU_PGD
16499+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
16500+#endif
16501+
16502+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16503+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
16504+#else
16505+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
16506+#endif
16507+
16508 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
16509 static inline int page_level_shift(enum pg_level level)
16510 {
16511diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
16512index 9ee3221..b979c6b 100644
16513--- a/arch/x86/include/asm/pgtable_32.h
16514+++ b/arch/x86/include/asm/pgtable_32.h
16515@@ -25,9 +25,6 @@
16516 struct mm_struct;
16517 struct vm_area_struct;
16518
16519-extern pgd_t swapper_pg_dir[1024];
16520-extern pgd_t initial_page_table[1024];
16521-
16522 static inline void pgtable_cache_init(void) { }
16523 static inline void check_pgt_cache(void) { }
16524 void paging_init(void);
16525@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
16526 # include <asm/pgtable-2level.h>
16527 #endif
16528
16529+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
16530+extern pgd_t initial_page_table[PTRS_PER_PGD];
16531+#ifdef CONFIG_X86_PAE
16532+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
16533+#endif
16534+
16535 #if defined(CONFIG_HIGHPTE)
16536 #define pte_offset_map(dir, address) \
16537 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
16538@@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
16539 /* Clear a kernel PTE and flush it from the TLB */
16540 #define kpte_clear_flush(ptep, vaddr) \
16541 do { \
16542+ pax_open_kernel(); \
16543 pte_clear(&init_mm, (vaddr), (ptep)); \
16544+ pax_close_kernel(); \
16545 __flush_tlb_one((vaddr)); \
16546 } while (0)
16547
16548 #endif /* !__ASSEMBLY__ */
16549
16550+#define HAVE_ARCH_UNMAPPED_AREA
16551+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
16552+
16553 /*
16554 * kern_addr_valid() is (1) for FLATMEM and (0) for
16555 * SPARSEMEM and DISCONTIGMEM
16556diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
16557index ed5903b..c7fe163 100644
16558--- a/arch/x86/include/asm/pgtable_32_types.h
16559+++ b/arch/x86/include/asm/pgtable_32_types.h
16560@@ -8,7 +8,7 @@
16561 */
16562 #ifdef CONFIG_X86_PAE
16563 # include <asm/pgtable-3level_types.h>
16564-# define PMD_SIZE (1UL << PMD_SHIFT)
16565+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
16566 # define PMD_MASK (~(PMD_SIZE - 1))
16567 #else
16568 # include <asm/pgtable-2level_types.h>
16569@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
16570 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
16571 #endif
16572
16573+#ifdef CONFIG_PAX_KERNEXEC
16574+#ifndef __ASSEMBLY__
16575+extern unsigned char MODULES_EXEC_VADDR[];
16576+extern unsigned char MODULES_EXEC_END[];
16577+#endif
16578+#include <asm/boot.h>
16579+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
16580+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
16581+#else
16582+#define ktla_ktva(addr) (addr)
16583+#define ktva_ktla(addr) (addr)
16584+#endif
16585+
16586 #define MODULES_VADDR VMALLOC_START
16587 #define MODULES_END VMALLOC_END
16588 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
16589diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
16590index e22c1db..23a625a 100644
16591--- a/arch/x86/include/asm/pgtable_64.h
16592+++ b/arch/x86/include/asm/pgtable_64.h
16593@@ -16,10 +16,14 @@
16594
16595 extern pud_t level3_kernel_pgt[512];
16596 extern pud_t level3_ident_pgt[512];
16597+extern pud_t level3_vmalloc_start_pgt[512];
16598+extern pud_t level3_vmalloc_end_pgt[512];
16599+extern pud_t level3_vmemmap_pgt[512];
16600+extern pud_t level2_vmemmap_pgt[512];
16601 extern pmd_t level2_kernel_pgt[512];
16602 extern pmd_t level2_fixmap_pgt[512];
16603-extern pmd_t level2_ident_pgt[512];
16604-extern pgd_t init_level4_pgt[];
16605+extern pmd_t level2_ident_pgt[512*2];
16606+extern pgd_t init_level4_pgt[512];
16607
16608 #define swapper_pg_dir init_level4_pgt
16609
16610@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
16611
16612 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
16613 {
16614+ pax_open_kernel();
16615 *pmdp = pmd;
16616+ pax_close_kernel();
16617 }
16618
16619 static inline void native_pmd_clear(pmd_t *pmd)
16620@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
16621
16622 static inline void native_set_pud(pud_t *pudp, pud_t pud)
16623 {
16624+ pax_open_kernel();
16625 *pudp = pud;
16626+ pax_close_kernel();
16627 }
16628
16629 static inline void native_pud_clear(pud_t *pud)
16630@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
16631
16632 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
16633 {
16634+ pax_open_kernel();
16635+ *pgdp = pgd;
16636+ pax_close_kernel();
16637+}
16638+
16639+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
16640+{
16641 *pgdp = pgd;
16642 }
16643
16644diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
16645index 2d88344..4679fc3 100644
16646--- a/arch/x86/include/asm/pgtable_64_types.h
16647+++ b/arch/x86/include/asm/pgtable_64_types.h
16648@@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
16649 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
16650 #define MODULES_END _AC(0xffffffffff000000, UL)
16651 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
16652+#define MODULES_EXEC_VADDR MODULES_VADDR
16653+#define MODULES_EXEC_END MODULES_END
16654+
16655+#define ktla_ktva(addr) (addr)
16656+#define ktva_ktla(addr) (addr)
16657
16658 #define EARLY_DYNAMIC_PAGE_TABLES 64
16659
16660diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
16661index f4843e0..a2526f8 100644
16662--- a/arch/x86/include/asm/pgtable_types.h
16663+++ b/arch/x86/include/asm/pgtable_types.h
16664@@ -16,13 +16,12 @@
16665 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
16666 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
16667 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
16668-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
16669+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
16670 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
16671 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
16672 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
16673-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
16674-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
16675-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
16676+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
16677+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
16678 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
16679
16680 /* If _PAGE_BIT_PRESENT is clear, we use these: */
16681@@ -40,7 +39,6 @@
16682 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
16683 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
16684 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
16685-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
16686 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
16687 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
16688 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
16689@@ -84,8 +82,10 @@
16690
16691 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
16692 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
16693-#else
16694+#elif defined(CONFIG_KMEMCHECK)
16695 #define _PAGE_NX (_AT(pteval_t, 0))
16696+#else
16697+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
16698 #endif
16699
16700 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
16701@@ -143,6 +143,9 @@
16702 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
16703 _PAGE_ACCESSED)
16704
16705+#define PAGE_READONLY_NOEXEC PAGE_READONLY
16706+#define PAGE_SHARED_NOEXEC PAGE_SHARED
16707+
16708 #define __PAGE_KERNEL_EXEC \
16709 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
16710 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
16711@@ -153,7 +156,7 @@
16712 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
16713 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
16714 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
16715-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
16716+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
16717 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
16718 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
16719 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
16720@@ -215,8 +218,8 @@
16721 * bits are combined, this will alow user to access the high address mapped
16722 * VDSO in the presence of CONFIG_COMPAT_VDSO
16723 */
16724-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
16725-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
16726+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
16727+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
16728 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
16729 #endif
16730
16731@@ -254,7 +257,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
16732 {
16733 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
16734 }
16735+#endif
16736
16737+#if PAGETABLE_LEVELS == 3
16738+#include <asm-generic/pgtable-nopud.h>
16739+#endif
16740+
16741+#if PAGETABLE_LEVELS == 2
16742+#include <asm-generic/pgtable-nopmd.h>
16743+#endif
16744+
16745+#ifndef __ASSEMBLY__
16746 #if PAGETABLE_LEVELS > 3
16747 typedef struct { pudval_t pud; } pud_t;
16748
16749@@ -268,8 +281,6 @@ static inline pudval_t native_pud_val(pud_t pud)
16750 return pud.pud;
16751 }
16752 #else
16753-#include <asm-generic/pgtable-nopud.h>
16754-
16755 static inline pudval_t native_pud_val(pud_t pud)
16756 {
16757 return native_pgd_val(pud.pgd);
16758@@ -289,8 +300,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
16759 return pmd.pmd;
16760 }
16761 #else
16762-#include <asm-generic/pgtable-nopmd.h>
16763-
16764 static inline pmdval_t native_pmd_val(pmd_t pmd)
16765 {
16766 return native_pgd_val(pmd.pud.pgd);
16767@@ -330,7 +339,6 @@ typedef struct page *pgtable_t;
16768
16769 extern pteval_t __supported_pte_mask;
16770 extern void set_nx(void);
16771-extern int nx_enabled;
16772
16773 #define pgprot_writecombine pgprot_writecombine
16774 extern pgprot_t pgprot_writecombine(pgprot_t prot);
16775diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
16776index 24cf5ae..4d9fa2d 100644
16777--- a/arch/x86/include/asm/processor.h
16778+++ b/arch/x86/include/asm/processor.h
16779@@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
16780 : "memory");
16781 }
16782
16783+/* invpcid (%rdx),%rax */
16784+#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
16785+
16786+#define INVPCID_SINGLE_ADDRESS 0UL
16787+#define INVPCID_SINGLE_CONTEXT 1UL
16788+#define INVPCID_ALL_GLOBAL 2UL
16789+#define INVPCID_ALL_MONGLOBAL 3UL
16790+
16791+#define PCID_KERNEL 0UL
16792+#define PCID_USER 1UL
16793+#define PCID_NOFLUSH (1UL << 63)
16794+
16795 static inline void load_cr3(pgd_t *pgdir)
16796 {
16797- write_cr3(__pa(pgdir));
16798+ write_cr3(__pa(pgdir) | PCID_KERNEL);
16799 }
16800
16801 #ifdef CONFIG_X86_32
16802@@ -283,7 +295,7 @@ struct tss_struct {
16803
16804 } ____cacheline_aligned;
16805
16806-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
16807+extern struct tss_struct init_tss[NR_CPUS];
16808
16809 /*
16810 * Save the original ist values for checking stack pointers during debugging
16811@@ -453,6 +465,7 @@ struct thread_struct {
16812 unsigned short ds;
16813 unsigned short fsindex;
16814 unsigned short gsindex;
16815+ unsigned short ss;
16816 #endif
16817 #ifdef CONFIG_X86_32
16818 unsigned long ip;
16819@@ -553,29 +566,8 @@ static inline void load_sp0(struct tss_struct *tss,
16820 extern unsigned long mmu_cr4_features;
16821 extern u32 *trampoline_cr4_features;
16822
16823-static inline void set_in_cr4(unsigned long mask)
16824-{
16825- unsigned long cr4;
16826-
16827- mmu_cr4_features |= mask;
16828- if (trampoline_cr4_features)
16829- *trampoline_cr4_features = mmu_cr4_features;
16830- cr4 = read_cr4();
16831- cr4 |= mask;
16832- write_cr4(cr4);
16833-}
16834-
16835-static inline void clear_in_cr4(unsigned long mask)
16836-{
16837- unsigned long cr4;
16838-
16839- mmu_cr4_features &= ~mask;
16840- if (trampoline_cr4_features)
16841- *trampoline_cr4_features = mmu_cr4_features;
16842- cr4 = read_cr4();
16843- cr4 &= ~mask;
16844- write_cr4(cr4);
16845-}
16846+extern void set_in_cr4(unsigned long mask);
16847+extern void clear_in_cr4(unsigned long mask);
16848
16849 typedef struct {
16850 unsigned long seg;
16851@@ -824,11 +816,18 @@ static inline void spin_lock_prefetch(const void *x)
16852 */
16853 #define TASK_SIZE PAGE_OFFSET
16854 #define TASK_SIZE_MAX TASK_SIZE
16855+
16856+#ifdef CONFIG_PAX_SEGMEXEC
16857+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
16858+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
16859+#else
16860 #define STACK_TOP TASK_SIZE
16861-#define STACK_TOP_MAX STACK_TOP
16862+#endif
16863+
16864+#define STACK_TOP_MAX TASK_SIZE
16865
16866 #define INIT_THREAD { \
16867- .sp0 = sizeof(init_stack) + (long)&init_stack, \
16868+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
16869 .vm86_info = NULL, \
16870 .sysenter_cs = __KERNEL_CS, \
16871 .io_bitmap_ptr = NULL, \
16872@@ -842,7 +841,7 @@ static inline void spin_lock_prefetch(const void *x)
16873 */
16874 #define INIT_TSS { \
16875 .x86_tss = { \
16876- .sp0 = sizeof(init_stack) + (long)&init_stack, \
16877+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
16878 .ss0 = __KERNEL_DS, \
16879 .ss1 = __KERNEL_CS, \
16880 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
16881@@ -853,11 +852,7 @@ static inline void spin_lock_prefetch(const void *x)
16882 extern unsigned long thread_saved_pc(struct task_struct *tsk);
16883
16884 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
16885-#define KSTK_TOP(info) \
16886-({ \
16887- unsigned long *__ptr = (unsigned long *)(info); \
16888- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
16889-})
16890+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
16891
16892 /*
16893 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
16894@@ -872,7 +867,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
16895 #define task_pt_regs(task) \
16896 ({ \
16897 struct pt_regs *__regs__; \
16898- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
16899+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
16900 __regs__ - 1; \
16901 })
16902
16903@@ -882,13 +877,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
16904 /*
16905 * User space process size. 47bits minus one guard page.
16906 */
16907-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
16908+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
16909
16910 /* This decides where the kernel will search for a free chunk of vm
16911 * space during mmap's.
16912 */
16913 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
16914- 0xc0000000 : 0xFFFFe000)
16915+ 0xc0000000 : 0xFFFFf000)
16916
16917 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
16918 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
16919@@ -899,11 +894,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
16920 #define STACK_TOP_MAX TASK_SIZE_MAX
16921
16922 #define INIT_THREAD { \
16923- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
16924+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
16925 }
16926
16927 #define INIT_TSS { \
16928- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
16929+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
16930 }
16931
16932 /*
16933@@ -931,6 +926,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
16934 */
16935 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
16936
16937+#ifdef CONFIG_PAX_SEGMEXEC
16938+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
16939+#endif
16940+
16941 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
16942
16943 /* Get/set a process' ability to use the timestamp counter instruction */
16944@@ -943,7 +942,8 @@ extern int set_tsc_mode(unsigned int val);
16945 extern u16 amd_get_nb_id(int cpu);
16946
16947 struct aperfmperf {
16948- u64 aperf, mperf;
16949+ u64 aperf __intentional_overflow(0);
16950+ u64 mperf __intentional_overflow(0);
16951 };
16952
16953 static inline void get_aperfmperf(struct aperfmperf *am)
16954@@ -971,7 +971,7 @@ unsigned long calc_aperfmperf_ratio(struct aperfmperf *old,
16955 return ratio;
16956 }
16957
16958-extern unsigned long arch_align_stack(unsigned long sp);
16959+#define arch_align_stack(x) ((x) & ~0xfUL)
16960 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
16961
16962 void default_idle(void);
16963@@ -981,6 +981,6 @@ bool xen_set_default_idle(void);
16964 #define xen_set_default_idle 0
16965 #endif
16966
16967-void stop_this_cpu(void *dummy);
16968+void stop_this_cpu(void *dummy) __noreturn;
16969 void df_debug(struct pt_regs *regs, long error_code);
16970 #endif /* _ASM_X86_PROCESSOR_H */
16971diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
16972index 942a086..6c26446 100644
16973--- a/arch/x86/include/asm/ptrace.h
16974+++ b/arch/x86/include/asm/ptrace.h
16975@@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
16976 }
16977
16978 /*
16979- * user_mode_vm(regs) determines whether a register set came from user mode.
16980+ * user_mode(regs) determines whether a register set came from user mode.
16981 * This is true if V8086 mode was enabled OR if the register set was from
16982 * protected mode with RPL-3 CS value. This tricky test checks that with
16983 * one comparison. Many places in the kernel can bypass this full check
16984- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
16985+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
16986+ * be used.
16987 */
16988-static inline int user_mode(struct pt_regs *regs)
16989+static inline int user_mode_novm(struct pt_regs *regs)
16990 {
16991 #ifdef CONFIG_X86_32
16992 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
16993 #else
16994- return !!(regs->cs & 3);
16995+ return !!(regs->cs & SEGMENT_RPL_MASK);
16996 #endif
16997 }
16998
16999-static inline int user_mode_vm(struct pt_regs *regs)
17000+static inline int user_mode(struct pt_regs *regs)
17001 {
17002 #ifdef CONFIG_X86_32
17003 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
17004 USER_RPL;
17005 #else
17006- return user_mode(regs);
17007+ return user_mode_novm(regs);
17008 #endif
17009 }
17010
17011@@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
17012 #ifdef CONFIG_X86_64
17013 static inline bool user_64bit_mode(struct pt_regs *regs)
17014 {
17015+ unsigned long cs = regs->cs & 0xffff;
17016 #ifndef CONFIG_PARAVIRT
17017 /*
17018 * On non-paravirt systems, this is the only long mode CPL 3
17019 * selector. We do not allow long mode selectors in the LDT.
17020 */
17021- return regs->cs == __USER_CS;
17022+ return cs == __USER_CS;
17023 #else
17024 /* Headers are too twisted for this to go in paravirt.h. */
17025- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
17026+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
17027 #endif
17028 }
17029
17030@@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
17031 * Traps from the kernel do not save sp and ss.
17032 * Use the helper function to retrieve sp.
17033 */
17034- if (offset == offsetof(struct pt_regs, sp) &&
17035- regs->cs == __KERNEL_CS)
17036- return kernel_stack_pointer(regs);
17037+ if (offset == offsetof(struct pt_regs, sp)) {
17038+ unsigned long cs = regs->cs & 0xffff;
17039+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
17040+ return kernel_stack_pointer(regs);
17041+ }
17042 #endif
17043 return *(unsigned long *)((unsigned long)regs + offset);
17044 }
17045diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
17046index 9c6b890..5305f53 100644
17047--- a/arch/x86/include/asm/realmode.h
17048+++ b/arch/x86/include/asm/realmode.h
17049@@ -22,16 +22,14 @@ struct real_mode_header {
17050 #endif
17051 /* APM/BIOS reboot */
17052 u32 machine_real_restart_asm;
17053-#ifdef CONFIG_X86_64
17054 u32 machine_real_restart_seg;
17055-#endif
17056 };
17057
17058 /* This must match data at trampoline_32/64.S */
17059 struct trampoline_header {
17060 #ifdef CONFIG_X86_32
17061 u32 start;
17062- u16 gdt_pad;
17063+ u16 boot_cs;
17064 u16 gdt_limit;
17065 u32 gdt_base;
17066 #else
17067diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
17068index a82c4f1..ac45053 100644
17069--- a/arch/x86/include/asm/reboot.h
17070+++ b/arch/x86/include/asm/reboot.h
17071@@ -6,13 +6,13 @@
17072 struct pt_regs;
17073
17074 struct machine_ops {
17075- void (*restart)(char *cmd);
17076- void (*halt)(void);
17077- void (*power_off)(void);
17078+ void (* __noreturn restart)(char *cmd);
17079+ void (* __noreturn halt)(void);
17080+ void (* __noreturn power_off)(void);
17081 void (*shutdown)(void);
17082 void (*crash_shutdown)(struct pt_regs *);
17083- void (*emergency_restart)(void);
17084-};
17085+ void (* __noreturn emergency_restart)(void);
17086+} __no_const;
17087
17088 extern struct machine_ops machine_ops;
17089
17090diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
17091index cad82c9..2e5c5c1 100644
17092--- a/arch/x86/include/asm/rwsem.h
17093+++ b/arch/x86/include/asm/rwsem.h
17094@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
17095 {
17096 asm volatile("# beginning down_read\n\t"
17097 LOCK_PREFIX _ASM_INC "(%1)\n\t"
17098+
17099+#ifdef CONFIG_PAX_REFCOUNT
17100+ "jno 0f\n"
17101+ LOCK_PREFIX _ASM_DEC "(%1)\n"
17102+ "int $4\n0:\n"
17103+ _ASM_EXTABLE(0b, 0b)
17104+#endif
17105+
17106 /* adds 0x00000001 */
17107 " jns 1f\n"
17108 " call call_rwsem_down_read_failed\n"
17109@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
17110 "1:\n\t"
17111 " mov %1,%2\n\t"
17112 " add %3,%2\n\t"
17113+
17114+#ifdef CONFIG_PAX_REFCOUNT
17115+ "jno 0f\n"
17116+ "sub %3,%2\n"
17117+ "int $4\n0:\n"
17118+ _ASM_EXTABLE(0b, 0b)
17119+#endif
17120+
17121 " jle 2f\n\t"
17122 LOCK_PREFIX " cmpxchg %2,%0\n\t"
17123 " jnz 1b\n\t"
17124@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
17125 long tmp;
17126 asm volatile("# beginning down_write\n\t"
17127 LOCK_PREFIX " xadd %1,(%2)\n\t"
17128+
17129+#ifdef CONFIG_PAX_REFCOUNT
17130+ "jno 0f\n"
17131+ "mov %1,(%2)\n"
17132+ "int $4\n0:\n"
17133+ _ASM_EXTABLE(0b, 0b)
17134+#endif
17135+
17136 /* adds 0xffff0001, returns the old value */
17137 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
17138 /* was the active mask 0 before? */
17139@@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
17140 long tmp;
17141 asm volatile("# beginning __up_read\n\t"
17142 LOCK_PREFIX " xadd %1,(%2)\n\t"
17143+
17144+#ifdef CONFIG_PAX_REFCOUNT
17145+ "jno 0f\n"
17146+ "mov %1,(%2)\n"
17147+ "int $4\n0:\n"
17148+ _ASM_EXTABLE(0b, 0b)
17149+#endif
17150+
17151 /* subtracts 1, returns the old value */
17152 " jns 1f\n\t"
17153 " call call_rwsem_wake\n" /* expects old value in %edx */
17154@@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
17155 long tmp;
17156 asm volatile("# beginning __up_write\n\t"
17157 LOCK_PREFIX " xadd %1,(%2)\n\t"
17158+
17159+#ifdef CONFIG_PAX_REFCOUNT
17160+ "jno 0f\n"
17161+ "mov %1,(%2)\n"
17162+ "int $4\n0:\n"
17163+ _ASM_EXTABLE(0b, 0b)
17164+#endif
17165+
17166 /* subtracts 0xffff0001, returns the old value */
17167 " jns 1f\n\t"
17168 " call call_rwsem_wake\n" /* expects old value in %edx */
17169@@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
17170 {
17171 asm volatile("# beginning __downgrade_write\n\t"
17172 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
17173+
17174+#ifdef CONFIG_PAX_REFCOUNT
17175+ "jno 0f\n"
17176+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
17177+ "int $4\n0:\n"
17178+ _ASM_EXTABLE(0b, 0b)
17179+#endif
17180+
17181 /*
17182 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
17183 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
17184@@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
17185 */
17186 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
17187 {
17188- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
17189+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
17190+
17191+#ifdef CONFIG_PAX_REFCOUNT
17192+ "jno 0f\n"
17193+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
17194+ "int $4\n0:\n"
17195+ _ASM_EXTABLE(0b, 0b)
17196+#endif
17197+
17198 : "+m" (sem->count)
17199 : "er" (delta));
17200 }
17201@@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
17202 */
17203 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
17204 {
17205- return delta + xadd(&sem->count, delta);
17206+ return delta + xadd_check_overflow(&sem->count, delta);
17207 }
17208
17209 #endif /* __KERNEL__ */
17210diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
17211index c48a950..bc40804 100644
17212--- a/arch/x86/include/asm/segment.h
17213+++ b/arch/x86/include/asm/segment.h
17214@@ -64,10 +64,15 @@
17215 * 26 - ESPFIX small SS
17216 * 27 - per-cpu [ offset to per-cpu data area ]
17217 * 28 - stack_canary-20 [ for stack protector ]
17218- * 29 - unused
17219- * 30 - unused
17220+ * 29 - PCI BIOS CS
17221+ * 30 - PCI BIOS DS
17222 * 31 - TSS for double fault handler
17223 */
17224+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
17225+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
17226+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
17227+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
17228+
17229 #define GDT_ENTRY_TLS_MIN 6
17230 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
17231
17232@@ -79,6 +84,8 @@
17233
17234 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
17235
17236+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
17237+
17238 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
17239
17240 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
17241@@ -104,6 +111,12 @@
17242 #define __KERNEL_STACK_CANARY 0
17243 #endif
17244
17245+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
17246+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
17247+
17248+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
17249+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
17250+
17251 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
17252
17253 /*
17254@@ -141,7 +154,7 @@
17255 */
17256
17257 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
17258-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
17259+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
17260
17261
17262 #else
17263@@ -165,6 +178,8 @@
17264 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
17265 #define __USER32_DS __USER_DS
17266
17267+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
17268+
17269 #define GDT_ENTRY_TSS 8 /* needs two entries */
17270 #define GDT_ENTRY_LDT 10 /* needs two entries */
17271 #define GDT_ENTRY_TLS_MIN 12
17272@@ -173,6 +188,8 @@
17273 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
17274 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
17275
17276+#define GDT_ENTRY_UDEREF_KERNEL_DS 16
17277+
17278 /* TLS indexes for 64bit - hardcoded in arch_prctl */
17279 #define FS_TLS 0
17280 #define GS_TLS 1
17281@@ -180,12 +197,14 @@
17282 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
17283 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
17284
17285-#define GDT_ENTRIES 16
17286+#define GDT_ENTRIES 17
17287
17288 #endif
17289
17290 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
17291+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
17292 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
17293+#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
17294 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
17295 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
17296 #ifndef CONFIG_PARAVIRT
17297@@ -265,7 +284,7 @@ static inline unsigned long get_limit(unsigned long segment)
17298 {
17299 unsigned long __limit;
17300 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
17301- return __limit + 1;
17302+ return __limit;
17303 }
17304
17305 #endif /* !__ASSEMBLY__ */
17306diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
17307index 8d3120f..352b440 100644
17308--- a/arch/x86/include/asm/smap.h
17309+++ b/arch/x86/include/asm/smap.h
17310@@ -25,11 +25,40 @@
17311
17312 #include <asm/alternative-asm.h>
17313
17314+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17315+#define ASM_PAX_OPEN_USERLAND \
17316+ 661: jmp 663f; \
17317+ .pushsection .altinstr_replacement, "a" ; \
17318+ 662: pushq %rax; nop; \
17319+ .popsection ; \
17320+ .pushsection .altinstructions, "a" ; \
17321+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
17322+ .popsection ; \
17323+ call __pax_open_userland; \
17324+ popq %rax; \
17325+ 663:
17326+
17327+#define ASM_PAX_CLOSE_USERLAND \
17328+ 661: jmp 663f; \
17329+ .pushsection .altinstr_replacement, "a" ; \
17330+ 662: pushq %rax; nop; \
17331+ .popsection; \
17332+ .pushsection .altinstructions, "a" ; \
17333+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
17334+ .popsection; \
17335+ call __pax_close_userland; \
17336+ popq %rax; \
17337+ 663:
17338+#else
17339+#define ASM_PAX_OPEN_USERLAND
17340+#define ASM_PAX_CLOSE_USERLAND
17341+#endif
17342+
17343 #ifdef CONFIG_X86_SMAP
17344
17345 #define ASM_CLAC \
17346 661: ASM_NOP3 ; \
17347- .pushsection .altinstr_replacement, "ax" ; \
17348+ .pushsection .altinstr_replacement, "a" ; \
17349 662: __ASM_CLAC ; \
17350 .popsection ; \
17351 .pushsection .altinstructions, "a" ; \
17352@@ -38,7 +67,7 @@
17353
17354 #define ASM_STAC \
17355 661: ASM_NOP3 ; \
17356- .pushsection .altinstr_replacement, "ax" ; \
17357+ .pushsection .altinstr_replacement, "a" ; \
17358 662: __ASM_STAC ; \
17359 .popsection ; \
17360 .pushsection .altinstructions, "a" ; \
17361@@ -56,6 +85,37 @@
17362
17363 #include <asm/alternative.h>
17364
17365+#define __HAVE_ARCH_PAX_OPEN_USERLAND
17366+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
17367+
17368+extern void __pax_open_userland(void);
17369+static __always_inline unsigned long pax_open_userland(void)
17370+{
17371+
17372+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17373+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
17374+ :
17375+ : [open] "i" (__pax_open_userland)
17376+ : "memory", "rax");
17377+#endif
17378+
17379+ return 0;
17380+}
17381+
17382+extern void __pax_close_userland(void);
17383+static __always_inline unsigned long pax_close_userland(void)
17384+{
17385+
17386+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17387+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
17388+ :
17389+ : [close] "i" (__pax_close_userland)
17390+ : "memory", "rax");
17391+#endif
17392+
17393+ return 0;
17394+}
17395+
17396 #ifdef CONFIG_X86_SMAP
17397
17398 static __always_inline void clac(void)
17399diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
17400index 4137890..03fa172 100644
17401--- a/arch/x86/include/asm/smp.h
17402+++ b/arch/x86/include/asm/smp.h
17403@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
17404 /* cpus sharing the last level cache: */
17405 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
17406 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
17407-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
17408+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
17409
17410 static inline struct cpumask *cpu_sibling_mask(int cpu)
17411 {
17412@@ -79,7 +79,7 @@ struct smp_ops {
17413
17414 void (*send_call_func_ipi)(const struct cpumask *mask);
17415 void (*send_call_func_single_ipi)(int cpu);
17416-};
17417+} __no_const;
17418
17419 /* Globals due to paravirt */
17420 extern void set_cpu_sibling_map(int cpu);
17421@@ -191,14 +191,8 @@ extern unsigned disabled_cpus;
17422 extern int safe_smp_processor_id(void);
17423
17424 #elif defined(CONFIG_X86_64_SMP)
17425-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
17426-
17427-#define stack_smp_processor_id() \
17428-({ \
17429- struct thread_info *ti; \
17430- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
17431- ti->cpu; \
17432-})
17433+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
17434+#define stack_smp_processor_id() raw_smp_processor_id()
17435 #define safe_smp_processor_id() smp_processor_id()
17436
17437 #endif
17438diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
17439index e3ddd7d..3611fce 100644
17440--- a/arch/x86/include/asm/spinlock.h
17441+++ b/arch/x86/include/asm/spinlock.h
17442@@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
17443 static inline void arch_read_lock(arch_rwlock_t *rw)
17444 {
17445 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
17446+
17447+#ifdef CONFIG_PAX_REFCOUNT
17448+ "jno 0f\n"
17449+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
17450+ "int $4\n0:\n"
17451+ _ASM_EXTABLE(0b, 0b)
17452+#endif
17453+
17454 "jns 1f\n"
17455 "call __read_lock_failed\n\t"
17456 "1:\n"
17457@@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
17458 static inline void arch_write_lock(arch_rwlock_t *rw)
17459 {
17460 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
17461+
17462+#ifdef CONFIG_PAX_REFCOUNT
17463+ "jno 0f\n"
17464+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
17465+ "int $4\n0:\n"
17466+ _ASM_EXTABLE(0b, 0b)
17467+#endif
17468+
17469 "jz 1f\n"
17470 "call __write_lock_failed\n\t"
17471 "1:\n"
17472@@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
17473
17474 static inline void arch_read_unlock(arch_rwlock_t *rw)
17475 {
17476- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
17477+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
17478+
17479+#ifdef CONFIG_PAX_REFCOUNT
17480+ "jno 0f\n"
17481+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
17482+ "int $4\n0:\n"
17483+ _ASM_EXTABLE(0b, 0b)
17484+#endif
17485+
17486 :"+m" (rw->lock) : : "memory");
17487 }
17488
17489 static inline void arch_write_unlock(arch_rwlock_t *rw)
17490 {
17491- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
17492+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
17493+
17494+#ifdef CONFIG_PAX_REFCOUNT
17495+ "jno 0f\n"
17496+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
17497+ "int $4\n0:\n"
17498+ _ASM_EXTABLE(0b, 0b)
17499+#endif
17500+
17501 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
17502 }
17503
17504diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
17505index 6a99859..03cb807 100644
17506--- a/arch/x86/include/asm/stackprotector.h
17507+++ b/arch/x86/include/asm/stackprotector.h
17508@@ -47,7 +47,7 @@
17509 * head_32 for boot CPU and setup_per_cpu_areas() for others.
17510 */
17511 #define GDT_STACK_CANARY_INIT \
17512- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
17513+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
17514
17515 /*
17516 * Initialize the stackprotector canary value.
17517@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
17518
17519 static inline void load_stack_canary_segment(void)
17520 {
17521-#ifdef CONFIG_X86_32
17522+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
17523 asm volatile ("mov %0, %%gs" : : "r" (0));
17524 #endif
17525 }
17526diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
17527index 70bbe39..4ae2bd4 100644
17528--- a/arch/x86/include/asm/stacktrace.h
17529+++ b/arch/x86/include/asm/stacktrace.h
17530@@ -11,28 +11,20 @@
17531
17532 extern int kstack_depth_to_print;
17533
17534-struct thread_info;
17535+struct task_struct;
17536 struct stacktrace_ops;
17537
17538-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
17539- unsigned long *stack,
17540- unsigned long bp,
17541- const struct stacktrace_ops *ops,
17542- void *data,
17543- unsigned long *end,
17544- int *graph);
17545+typedef unsigned long walk_stack_t(struct task_struct *task,
17546+ void *stack_start,
17547+ unsigned long *stack,
17548+ unsigned long bp,
17549+ const struct stacktrace_ops *ops,
17550+ void *data,
17551+ unsigned long *end,
17552+ int *graph);
17553
17554-extern unsigned long
17555-print_context_stack(struct thread_info *tinfo,
17556- unsigned long *stack, unsigned long bp,
17557- const struct stacktrace_ops *ops, void *data,
17558- unsigned long *end, int *graph);
17559-
17560-extern unsigned long
17561-print_context_stack_bp(struct thread_info *tinfo,
17562- unsigned long *stack, unsigned long bp,
17563- const struct stacktrace_ops *ops, void *data,
17564- unsigned long *end, int *graph);
17565+extern walk_stack_t print_context_stack;
17566+extern walk_stack_t print_context_stack_bp;
17567
17568 /* Generic stack tracer with callbacks */
17569
17570@@ -40,7 +32,7 @@ struct stacktrace_ops {
17571 void (*address)(void *data, unsigned long address, int reliable);
17572 /* On negative return stop dumping */
17573 int (*stack)(void *data, char *name);
17574- walk_stack_t walk_stack;
17575+ walk_stack_t *walk_stack;
17576 };
17577
17578 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
17579diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
17580index 4ec45b3..a4f0a8a 100644
17581--- a/arch/x86/include/asm/switch_to.h
17582+++ b/arch/x86/include/asm/switch_to.h
17583@@ -108,7 +108,7 @@ do { \
17584 "call __switch_to\n\t" \
17585 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
17586 __switch_canary \
17587- "movq %P[thread_info](%%rsi),%%r8\n\t" \
17588+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
17589 "movq %%rax,%%rdi\n\t" \
17590 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
17591 "jnz ret_from_fork\n\t" \
17592@@ -119,7 +119,7 @@ do { \
17593 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
17594 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
17595 [_tif_fork] "i" (_TIF_FORK), \
17596- [thread_info] "i" (offsetof(struct task_struct, stack)), \
17597+ [thread_info] "m" (current_tinfo), \
17598 [current_task] "m" (current_task) \
17599 __switch_canary_iparam \
17600 : "memory", "cc" __EXTRA_CLOBBER)
17601diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
17602index 2781119..618b59b 100644
17603--- a/arch/x86/include/asm/thread_info.h
17604+++ b/arch/x86/include/asm/thread_info.h
17605@@ -10,6 +10,7 @@
17606 #include <linux/compiler.h>
17607 #include <asm/page.h>
17608 #include <asm/types.h>
17609+#include <asm/percpu.h>
17610
17611 /*
17612 * low level task data that entry.S needs immediate access to
17613@@ -23,7 +24,6 @@ struct exec_domain;
17614 #include <linux/atomic.h>
17615
17616 struct thread_info {
17617- struct task_struct *task; /* main task structure */
17618 struct exec_domain *exec_domain; /* execution domain */
17619 __u32 flags; /* low level flags */
17620 __u32 status; /* thread synchronous flags */
17621@@ -33,19 +33,13 @@ struct thread_info {
17622 mm_segment_t addr_limit;
17623 struct restart_block restart_block;
17624 void __user *sysenter_return;
17625-#ifdef CONFIG_X86_32
17626- unsigned long previous_esp; /* ESP of the previous stack in
17627- case of nested (IRQ) stacks
17628- */
17629- __u8 supervisor_stack[0];
17630-#endif
17631+ unsigned long lowest_stack;
17632 unsigned int sig_on_uaccess_error:1;
17633 unsigned int uaccess_err:1; /* uaccess failed */
17634 };
17635
17636-#define INIT_THREAD_INFO(tsk) \
17637+#define INIT_THREAD_INFO \
17638 { \
17639- .task = &tsk, \
17640 .exec_domain = &default_exec_domain, \
17641 .flags = 0, \
17642 .cpu = 0, \
17643@@ -56,7 +50,7 @@ struct thread_info {
17644 }, \
17645 }
17646
17647-#define init_thread_info (init_thread_union.thread_info)
17648+#define init_thread_info (init_thread_union.stack)
17649 #define init_stack (init_thread_union.stack)
17650
17651 #else /* !__ASSEMBLY__ */
17652@@ -96,6 +90,7 @@ struct thread_info {
17653 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
17654 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
17655 #define TIF_X32 30 /* 32-bit native x86-64 binary */
17656+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
17657
17658 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
17659 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
17660@@ -119,17 +114,18 @@ struct thread_info {
17661 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
17662 #define _TIF_ADDR32 (1 << TIF_ADDR32)
17663 #define _TIF_X32 (1 << TIF_X32)
17664+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
17665
17666 /* work to do in syscall_trace_enter() */
17667 #define _TIF_WORK_SYSCALL_ENTRY \
17668 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
17669 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
17670- _TIF_NOHZ)
17671+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
17672
17673 /* work to do in syscall_trace_leave() */
17674 #define _TIF_WORK_SYSCALL_EXIT \
17675 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
17676- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
17677+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
17678
17679 /* work to do on interrupt/exception return */
17680 #define _TIF_WORK_MASK \
17681@@ -140,7 +136,7 @@ struct thread_info {
17682 /* work to do on any return to user space */
17683 #define _TIF_ALLWORK_MASK \
17684 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
17685- _TIF_NOHZ)
17686+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
17687
17688 /* Only used for 64 bit */
17689 #define _TIF_DO_NOTIFY_MASK \
17690@@ -156,45 +152,40 @@ struct thread_info {
17691
17692 #define PREEMPT_ACTIVE 0x10000000
17693
17694-#ifdef CONFIG_X86_32
17695-
17696-#define STACK_WARN (THREAD_SIZE/8)
17697-/*
17698- * macros/functions for gaining access to the thread information structure
17699- *
17700- * preempt_count needs to be 1 initially, until the scheduler is functional.
17701- */
17702-#ifndef __ASSEMBLY__
17703-
17704-
17705-/* how to get the current stack pointer from C */
17706-register unsigned long current_stack_pointer asm("esp") __used;
17707-
17708-/* how to get the thread information struct from C */
17709-static inline struct thread_info *current_thread_info(void)
17710-{
17711- return (struct thread_info *)
17712- (current_stack_pointer & ~(THREAD_SIZE - 1));
17713-}
17714-
17715-#else /* !__ASSEMBLY__ */
17716-
17717+#ifdef __ASSEMBLY__
17718 /* how to get the thread information struct from ASM */
17719 #define GET_THREAD_INFO(reg) \
17720- movl $-THREAD_SIZE, reg; \
17721- andl %esp, reg
17722+ mov PER_CPU_VAR(current_tinfo), reg
17723
17724 /* use this one if reg already contains %esp */
17725-#define GET_THREAD_INFO_WITH_ESP(reg) \
17726- andl $-THREAD_SIZE, reg
17727+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
17728+#else
17729+/* how to get the thread information struct from C */
17730+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
17731+
17732+static __always_inline struct thread_info *current_thread_info(void)
17733+{
17734+ return this_cpu_read_stable(current_tinfo);
17735+}
17736+#endif
17737+
17738+#ifdef CONFIG_X86_32
17739+
17740+#define STACK_WARN (THREAD_SIZE/8)
17741+/*
17742+ * macros/functions for gaining access to the thread information structure
17743+ *
17744+ * preempt_count needs to be 1 initially, until the scheduler is functional.
17745+ */
17746+#ifndef __ASSEMBLY__
17747+
17748+/* how to get the current stack pointer from C */
17749+register unsigned long current_stack_pointer asm("esp") __used;
17750
17751 #endif
17752
17753 #else /* X86_32 */
17754
17755-#include <asm/percpu.h>
17756-#define KERNEL_STACK_OFFSET (5*8)
17757-
17758 /*
17759 * macros/functions for gaining access to the thread information structure
17760 * preempt_count needs to be 1 initially, until the scheduler is functional.
17761@@ -202,27 +193,8 @@ static inline struct thread_info *current_thread_info(void)
17762 #ifndef __ASSEMBLY__
17763 DECLARE_PER_CPU(unsigned long, kernel_stack);
17764
17765-static inline struct thread_info *current_thread_info(void)
17766-{
17767- struct thread_info *ti;
17768- ti = (void *)(this_cpu_read_stable(kernel_stack) +
17769- KERNEL_STACK_OFFSET - THREAD_SIZE);
17770- return ti;
17771-}
17772-
17773-#else /* !__ASSEMBLY__ */
17774-
17775-/* how to get the thread information struct from ASM */
17776-#define GET_THREAD_INFO(reg) \
17777- movq PER_CPU_VAR(kernel_stack),reg ; \
17778- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
17779-
17780-/*
17781- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
17782- * a certain register (to be used in assembler memory operands).
17783- */
17784-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
17785-
17786+/* how to get the current stack pointer from C */
17787+register unsigned long current_stack_pointer asm("rsp") __used;
17788 #endif
17789
17790 #endif /* !X86_32 */
17791@@ -281,5 +253,12 @@ static inline bool is_ia32_task(void)
17792 extern void arch_task_cache_init(void);
17793 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
17794 extern void arch_release_task_struct(struct task_struct *tsk);
17795+
17796+#define __HAVE_THREAD_FUNCTIONS
17797+#define task_thread_info(task) (&(task)->tinfo)
17798+#define task_stack_page(task) ((task)->stack)
17799+#define setup_thread_stack(p, org) do {} while (0)
17800+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
17801+
17802 #endif
17803 #endif /* _ASM_X86_THREAD_INFO_H */
17804diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
17805index cf51200..63ff068 100644
17806--- a/arch/x86/include/asm/tlbflush.h
17807+++ b/arch/x86/include/asm/tlbflush.h
17808@@ -17,18 +17,44 @@
17809
17810 static inline void __native_flush_tlb(void)
17811 {
17812+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17813+ u64 descriptor[2];
17814+
17815+ descriptor[0] = PCID_KERNEL;
17816+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
17817+ return;
17818+ }
17819+
17820+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17821+ if (static_cpu_has(X86_FEATURE_PCID)) {
17822+ unsigned int cpu = raw_get_cpu();
17823+
17824+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17825+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17826+ raw_put_cpu_no_resched();
17827+ return;
17828+ }
17829+#endif
17830+
17831 native_write_cr3(native_read_cr3());
17832 }
17833
17834 static inline void __native_flush_tlb_global_irq_disabled(void)
17835 {
17836- unsigned long cr4;
17837+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17838+ u64 descriptor[2];
17839
17840- cr4 = native_read_cr4();
17841- /* clear PGE */
17842- native_write_cr4(cr4 & ~X86_CR4_PGE);
17843- /* write old PGE again and flush TLBs */
17844- native_write_cr4(cr4);
17845+ descriptor[0] = PCID_KERNEL;
17846+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
17847+ } else {
17848+ unsigned long cr4;
17849+
17850+ cr4 = native_read_cr4();
17851+ /* clear PGE */
17852+ native_write_cr4(cr4 & ~X86_CR4_PGE);
17853+ /* write old PGE again and flush TLBs */
17854+ native_write_cr4(cr4);
17855+ }
17856 }
17857
17858 static inline void __native_flush_tlb_global(void)
17859@@ -49,6 +75,42 @@ static inline void __native_flush_tlb_global(void)
17860
17861 static inline void __native_flush_tlb_single(unsigned long addr)
17862 {
17863+
17864+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17865+ u64 descriptor[2];
17866+
17867+ descriptor[0] = PCID_KERNEL;
17868+ descriptor[1] = addr;
17869+
17870+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17871+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
17872+ if (addr < TASK_SIZE_MAX)
17873+ descriptor[1] += pax_user_shadow_base;
17874+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
17875+ }
17876+
17877+ descriptor[0] = PCID_USER;
17878+ descriptor[1] = addr;
17879+#endif
17880+
17881+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
17882+ return;
17883+ }
17884+
17885+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17886+ if (static_cpu_has(X86_FEATURE_PCID)) {
17887+ unsigned int cpu = raw_get_cpu();
17888+
17889+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
17890+ asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
17891+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17892+ raw_put_cpu_no_resched();
17893+
17894+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
17895+ addr += pax_user_shadow_base;
17896+ }
17897+#endif
17898+
17899 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
17900 }
17901
17902diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
17903index 5ee2687..74590b9 100644
17904--- a/arch/x86/include/asm/uaccess.h
17905+++ b/arch/x86/include/asm/uaccess.h
17906@@ -7,6 +7,7 @@
17907 #include <linux/compiler.h>
17908 #include <linux/thread_info.h>
17909 #include <linux/string.h>
17910+#include <linux/sched.h>
17911 #include <asm/asm.h>
17912 #include <asm/page.h>
17913 #include <asm/smap.h>
17914@@ -29,7 +30,12 @@
17915
17916 #define get_ds() (KERNEL_DS)
17917 #define get_fs() (current_thread_info()->addr_limit)
17918+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
17919+void __set_fs(mm_segment_t x);
17920+void set_fs(mm_segment_t x);
17921+#else
17922 #define set_fs(x) (current_thread_info()->addr_limit = (x))
17923+#endif
17924
17925 #define segment_eq(a, b) ((a).seg == (b).seg)
17926
17927@@ -77,8 +83,33 @@
17928 * checks that the pointer is in the user space range - after calling
17929 * this function, memory access functions may still return -EFAULT.
17930 */
17931-#define access_ok(type, addr, size) \
17932- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
17933+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
17934+#define access_ok(type, addr, size) \
17935+({ \
17936+ long __size = size; \
17937+ unsigned long __addr = (unsigned long)addr; \
17938+ unsigned long __addr_ao = __addr & PAGE_MASK; \
17939+ unsigned long __end_ao = __addr + __size - 1; \
17940+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
17941+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
17942+ while(__addr_ao <= __end_ao) { \
17943+ char __c_ao; \
17944+ __addr_ao += PAGE_SIZE; \
17945+ if (__size > PAGE_SIZE) \
17946+ cond_resched(); \
17947+ if (__get_user(__c_ao, (char __user *)__addr)) \
17948+ break; \
17949+ if (type != VERIFY_WRITE) { \
17950+ __addr = __addr_ao; \
17951+ continue; \
17952+ } \
17953+ if (__put_user(__c_ao, (char __user *)__addr)) \
17954+ break; \
17955+ __addr = __addr_ao; \
17956+ } \
17957+ } \
17958+ __ret_ao; \
17959+})
17960
17961 /*
17962 * The exception table consists of pairs of addresses relative to the
17963@@ -165,10 +196,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
17964 register __inttype(*(ptr)) __val_gu asm("%edx"); \
17965 __chk_user_ptr(ptr); \
17966 might_fault(); \
17967+ pax_open_userland(); \
17968 asm volatile("call __get_user_%P3" \
17969 : "=a" (__ret_gu), "=r" (__val_gu) \
17970 : "0" (ptr), "i" (sizeof(*(ptr)))); \
17971 (x) = (__typeof__(*(ptr))) __val_gu; \
17972+ pax_close_userland(); \
17973 __ret_gu; \
17974 })
17975
17976@@ -176,13 +209,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
17977 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
17978 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
17979
17980-
17981+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
17982+#define __copyuser_seg "gs;"
17983+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
17984+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
17985+#else
17986+#define __copyuser_seg
17987+#define __COPYUSER_SET_ES
17988+#define __COPYUSER_RESTORE_ES
17989+#endif
17990
17991 #ifdef CONFIG_X86_32
17992 #define __put_user_asm_u64(x, addr, err, errret) \
17993 asm volatile(ASM_STAC "\n" \
17994- "1: movl %%eax,0(%2)\n" \
17995- "2: movl %%edx,4(%2)\n" \
17996+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
17997+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
17998 "3: " ASM_CLAC "\n" \
17999 ".section .fixup,\"ax\"\n" \
18000 "4: movl %3,%0\n" \
18001@@ -195,8 +236,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
18002
18003 #define __put_user_asm_ex_u64(x, addr) \
18004 asm volatile(ASM_STAC "\n" \
18005- "1: movl %%eax,0(%1)\n" \
18006- "2: movl %%edx,4(%1)\n" \
18007+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
18008+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
18009 "3: " ASM_CLAC "\n" \
18010 _ASM_EXTABLE_EX(1b, 2b) \
18011 _ASM_EXTABLE_EX(2b, 3b) \
18012@@ -246,7 +287,8 @@ extern void __put_user_8(void);
18013 __typeof__(*(ptr)) __pu_val; \
18014 __chk_user_ptr(ptr); \
18015 might_fault(); \
18016- __pu_val = x; \
18017+ __pu_val = (x); \
18018+ pax_open_userland(); \
18019 switch (sizeof(*(ptr))) { \
18020 case 1: \
18021 __put_user_x(1, __pu_val, ptr, __ret_pu); \
18022@@ -264,6 +306,7 @@ extern void __put_user_8(void);
18023 __put_user_x(X, __pu_val, ptr, __ret_pu); \
18024 break; \
18025 } \
18026+ pax_close_userland(); \
18027 __ret_pu; \
18028 })
18029
18030@@ -344,8 +387,10 @@ do { \
18031 } while (0)
18032
18033 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
18034+do { \
18035+ pax_open_userland(); \
18036 asm volatile(ASM_STAC "\n" \
18037- "1: mov"itype" %2,%"rtype"1\n" \
18038+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
18039 "2: " ASM_CLAC "\n" \
18040 ".section .fixup,\"ax\"\n" \
18041 "3: mov %3,%0\n" \
18042@@ -353,8 +398,10 @@ do { \
18043 " jmp 2b\n" \
18044 ".previous\n" \
18045 _ASM_EXTABLE(1b, 3b) \
18046- : "=r" (err), ltype(x) \
18047- : "m" (__m(addr)), "i" (errret), "0" (err))
18048+ : "=r" (err), ltype (x) \
18049+ : "m" (__m(addr)), "i" (errret), "0" (err)); \
18050+ pax_close_userland(); \
18051+} while (0)
18052
18053 #define __get_user_size_ex(x, ptr, size) \
18054 do { \
18055@@ -378,7 +425,7 @@ do { \
18056 } while (0)
18057
18058 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
18059- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
18060+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
18061 "2:\n" \
18062 _ASM_EXTABLE_EX(1b, 2b) \
18063 : ltype(x) : "m" (__m(addr)))
18064@@ -395,13 +442,24 @@ do { \
18065 int __gu_err; \
18066 unsigned long __gu_val; \
18067 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
18068- (x) = (__force __typeof__(*(ptr)))__gu_val; \
18069+ (x) = (__typeof__(*(ptr)))__gu_val; \
18070 __gu_err; \
18071 })
18072
18073 /* FIXME: this hack is definitely wrong -AK */
18074 struct __large_struct { unsigned long buf[100]; };
18075-#define __m(x) (*(struct __large_struct __user *)(x))
18076+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18077+#define ____m(x) \
18078+({ \
18079+ unsigned long ____x = (unsigned long)(x); \
18080+ if (____x < pax_user_shadow_base) \
18081+ ____x += pax_user_shadow_base; \
18082+ (typeof(x))____x; \
18083+})
18084+#else
18085+#define ____m(x) (x)
18086+#endif
18087+#define __m(x) (*(struct __large_struct __user *)____m(x))
18088
18089 /*
18090 * Tell gcc we read from memory instead of writing: this is because
18091@@ -409,8 +467,10 @@ struct __large_struct { unsigned long buf[100]; };
18092 * aliasing issues.
18093 */
18094 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
18095+do { \
18096+ pax_open_userland(); \
18097 asm volatile(ASM_STAC "\n" \
18098- "1: mov"itype" %"rtype"1,%2\n" \
18099+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
18100 "2: " ASM_CLAC "\n" \
18101 ".section .fixup,\"ax\"\n" \
18102 "3: mov %3,%0\n" \
18103@@ -418,10 +478,12 @@ struct __large_struct { unsigned long buf[100]; };
18104 ".previous\n" \
18105 _ASM_EXTABLE(1b, 3b) \
18106 : "=r"(err) \
18107- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
18108+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
18109+ pax_close_userland(); \
18110+} while (0)
18111
18112 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
18113- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
18114+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
18115 "2:\n" \
18116 _ASM_EXTABLE_EX(1b, 2b) \
18117 : : ltype(x), "m" (__m(addr)))
18118@@ -431,11 +493,13 @@ struct __large_struct { unsigned long buf[100]; };
18119 */
18120 #define uaccess_try do { \
18121 current_thread_info()->uaccess_err = 0; \
18122+ pax_open_userland(); \
18123 stac(); \
18124 barrier();
18125
18126 #define uaccess_catch(err) \
18127 clac(); \
18128+ pax_close_userland(); \
18129 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
18130 } while (0)
18131
18132@@ -460,8 +524,12 @@ struct __large_struct { unsigned long buf[100]; };
18133 * On error, the variable @x is set to zero.
18134 */
18135
18136+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18137+#define __get_user(x, ptr) get_user((x), (ptr))
18138+#else
18139 #define __get_user(x, ptr) \
18140 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
18141+#endif
18142
18143 /**
18144 * __put_user: - Write a simple value into user space, with less checking.
18145@@ -483,8 +551,12 @@ struct __large_struct { unsigned long buf[100]; };
18146 * Returns zero on success, or -EFAULT on error.
18147 */
18148
18149+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18150+#define __put_user(x, ptr) put_user((x), (ptr))
18151+#else
18152 #define __put_user(x, ptr) \
18153 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
18154+#endif
18155
18156 #define __get_user_unaligned __get_user
18157 #define __put_user_unaligned __put_user
18158@@ -502,7 +574,7 @@ struct __large_struct { unsigned long buf[100]; };
18159 #define get_user_ex(x, ptr) do { \
18160 unsigned long __gue_val; \
18161 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
18162- (x) = (__force __typeof__(*(ptr)))__gue_val; \
18163+ (x) = (__typeof__(*(ptr)))__gue_val; \
18164 } while (0)
18165
18166 #define put_user_try uaccess_try
18167@@ -519,8 +591,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
18168 extern __must_check long strlen_user(const char __user *str);
18169 extern __must_check long strnlen_user(const char __user *str, long n);
18170
18171-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
18172-unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
18173+unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
18174+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
18175
18176 /*
18177 * movsl can be slow when source and dest are not both 8-byte aligned
18178diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
18179index 7f760a9..04b1c65 100644
18180--- a/arch/x86/include/asm/uaccess_32.h
18181+++ b/arch/x86/include/asm/uaccess_32.h
18182@@ -11,15 +11,15 @@
18183 #include <asm/page.h>
18184
18185 unsigned long __must_check __copy_to_user_ll
18186- (void __user *to, const void *from, unsigned long n);
18187+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
18188 unsigned long __must_check __copy_from_user_ll
18189- (void *to, const void __user *from, unsigned long n);
18190+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
18191 unsigned long __must_check __copy_from_user_ll_nozero
18192- (void *to, const void __user *from, unsigned long n);
18193+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
18194 unsigned long __must_check __copy_from_user_ll_nocache
18195- (void *to, const void __user *from, unsigned long n);
18196+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
18197 unsigned long __must_check __copy_from_user_ll_nocache_nozero
18198- (void *to, const void __user *from, unsigned long n);
18199+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
18200
18201 /**
18202 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
18203@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
18204 static __always_inline unsigned long __must_check
18205 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
18206 {
18207+ if ((long)n < 0)
18208+ return n;
18209+
18210+ check_object_size(from, n, true);
18211+
18212 if (__builtin_constant_p(n)) {
18213 unsigned long ret;
18214
18215@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
18216 __copy_to_user(void __user *to, const void *from, unsigned long n)
18217 {
18218 might_fault();
18219+
18220 return __copy_to_user_inatomic(to, from, n);
18221 }
18222
18223 static __always_inline unsigned long
18224 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
18225 {
18226+ if ((long)n < 0)
18227+ return n;
18228+
18229 /* Avoid zeroing the tail if the copy fails..
18230 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
18231 * but as the zeroing behaviour is only significant when n is not
18232@@ -137,6 +146,12 @@ static __always_inline unsigned long
18233 __copy_from_user(void *to, const void __user *from, unsigned long n)
18234 {
18235 might_fault();
18236+
18237+ if ((long)n < 0)
18238+ return n;
18239+
18240+ check_object_size(to, n, false);
18241+
18242 if (__builtin_constant_p(n)) {
18243 unsigned long ret;
18244
18245@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
18246 const void __user *from, unsigned long n)
18247 {
18248 might_fault();
18249+
18250+ if ((long)n < 0)
18251+ return n;
18252+
18253 if (__builtin_constant_p(n)) {
18254 unsigned long ret;
18255
18256@@ -181,15 +200,19 @@ static __always_inline unsigned long
18257 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
18258 unsigned long n)
18259 {
18260- return __copy_from_user_ll_nocache_nozero(to, from, n);
18261+ if ((long)n < 0)
18262+ return n;
18263+
18264+ return __copy_from_user_ll_nocache_nozero(to, from, n);
18265 }
18266
18267-unsigned long __must_check copy_to_user(void __user *to,
18268- const void *from, unsigned long n);
18269-unsigned long __must_check _copy_from_user(void *to,
18270- const void __user *from,
18271- unsigned long n);
18272-
18273+extern void copy_to_user_overflow(void)
18274+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18275+ __compiletime_error("copy_to_user() buffer size is not provably correct")
18276+#else
18277+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
18278+#endif
18279+;
18280
18281 extern void copy_from_user_overflow(void)
18282 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18283@@ -199,17 +222,60 @@ extern void copy_from_user_overflow(void)
18284 #endif
18285 ;
18286
18287-static inline unsigned long __must_check copy_from_user(void *to,
18288- const void __user *from,
18289- unsigned long n)
18290+/**
18291+ * copy_to_user: - Copy a block of data into user space.
18292+ * @to: Destination address, in user space.
18293+ * @from: Source address, in kernel space.
18294+ * @n: Number of bytes to copy.
18295+ *
18296+ * Context: User context only. This function may sleep.
18297+ *
18298+ * Copy data from kernel space to user space.
18299+ *
18300+ * Returns number of bytes that could not be copied.
18301+ * On success, this will be zero.
18302+ */
18303+static inline unsigned long __must_check
18304+copy_to_user(void __user *to, const void *from, unsigned long n)
18305 {
18306- int sz = __compiletime_object_size(to);
18307+ size_t sz = __compiletime_object_size(from);
18308
18309- if (likely(sz == -1 || sz >= n))
18310- n = _copy_from_user(to, from, n);
18311- else
18312+ if (unlikely(sz != (size_t)-1 && sz < n))
18313+ copy_to_user_overflow();
18314+ else if (access_ok(VERIFY_WRITE, to, n))
18315+ n = __copy_to_user(to, from, n);
18316+ return n;
18317+}
18318+
18319+/**
18320+ * copy_from_user: - Copy a block of data from user space.
18321+ * @to: Destination address, in kernel space.
18322+ * @from: Source address, in user space.
18323+ * @n: Number of bytes to copy.
18324+ *
18325+ * Context: User context only. This function may sleep.
18326+ *
18327+ * Copy data from user space to kernel space.
18328+ *
18329+ * Returns number of bytes that could not be copied.
18330+ * On success, this will be zero.
18331+ *
18332+ * If some data could not be copied, this function will pad the copied
18333+ * data to the requested size using zero bytes.
18334+ */
18335+static inline unsigned long __must_check
18336+copy_from_user(void *to, const void __user *from, unsigned long n)
18337+{
18338+ size_t sz = __compiletime_object_size(to);
18339+
18340+ check_object_size(to, n, false);
18341+
18342+ if (unlikely(sz != (size_t)-1 && sz < n))
18343 copy_from_user_overflow();
18344-
18345+ else if (access_ok(VERIFY_READ, from, n))
18346+ n = __copy_from_user(to, from, n);
18347+ else if ((long)n > 0)
18348+ memset(to, 0, n);
18349 return n;
18350 }
18351
18352diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
18353index 4f7923d..d3526c1 100644
18354--- a/arch/x86/include/asm/uaccess_64.h
18355+++ b/arch/x86/include/asm/uaccess_64.h
18356@@ -10,6 +10,9 @@
18357 #include <asm/alternative.h>
18358 #include <asm/cpufeature.h>
18359 #include <asm/page.h>
18360+#include <asm/pgtable.h>
18361+
18362+#define set_fs(x) (current_thread_info()->addr_limit = (x))
18363
18364 /*
18365 * Copy To/From Userspace
18366@@ -17,14 +20,14 @@
18367
18368 /* Handles exceptions in both to and from, but doesn't do access_ok */
18369 __must_check unsigned long
18370-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
18371+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
18372 __must_check unsigned long
18373-copy_user_generic_string(void *to, const void *from, unsigned len);
18374+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
18375 __must_check unsigned long
18376-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
18377+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
18378
18379-static __always_inline __must_check unsigned long
18380-copy_user_generic(void *to, const void *from, unsigned len)
18381+static __always_inline __must_check __size_overflow(3) unsigned long
18382+copy_user_generic(void *to, const void *from, unsigned long len)
18383 {
18384 unsigned ret;
18385
18386@@ -45,138 +48,200 @@ copy_user_generic(void *to, const void *from, unsigned len)
18387 return ret;
18388 }
18389
18390+static __always_inline __must_check unsigned long
18391+__copy_to_user(void __user *to, const void *from, unsigned long len);
18392+static __always_inline __must_check unsigned long
18393+__copy_from_user(void *to, const void __user *from, unsigned long len);
18394 __must_check unsigned long
18395-_copy_to_user(void __user *to, const void *from, unsigned len);
18396-__must_check unsigned long
18397-_copy_from_user(void *to, const void __user *from, unsigned len);
18398-__must_check unsigned long
18399-copy_in_user(void __user *to, const void __user *from, unsigned len);
18400+copy_in_user(void __user *to, const void __user *from, unsigned long len);
18401+
18402+extern void copy_to_user_overflow(void)
18403+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18404+ __compiletime_error("copy_to_user() buffer size is not provably correct")
18405+#else
18406+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
18407+#endif
18408+;
18409+
18410+extern void copy_from_user_overflow(void)
18411+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18412+ __compiletime_error("copy_from_user() buffer size is not provably correct")
18413+#else
18414+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
18415+#endif
18416+;
18417
18418 static inline unsigned long __must_check copy_from_user(void *to,
18419 const void __user *from,
18420 unsigned long n)
18421 {
18422- int sz = __compiletime_object_size(to);
18423-
18424 might_fault();
18425- if (likely(sz == -1 || sz >= n))
18426- n = _copy_from_user(to, from, n);
18427-#ifdef CONFIG_DEBUG_VM
18428- else
18429- WARN(1, "Buffer overflow detected!\n");
18430-#endif
18431+
18432+ check_object_size(to, n, false);
18433+
18434+ if (access_ok(VERIFY_READ, from, n))
18435+ n = __copy_from_user(to, from, n);
18436+ else if (n < INT_MAX)
18437+ memset(to, 0, n);
18438 return n;
18439 }
18440
18441 static __always_inline __must_check
18442-int copy_to_user(void __user *dst, const void *src, unsigned size)
18443+int copy_to_user(void __user *dst, const void *src, unsigned long size)
18444 {
18445 might_fault();
18446
18447- return _copy_to_user(dst, src, size);
18448+ if (access_ok(VERIFY_WRITE, dst, size))
18449+ size = __copy_to_user(dst, src, size);
18450+ return size;
18451 }
18452
18453 static __always_inline __must_check
18454-int __copy_from_user(void *dst, const void __user *src, unsigned size)
18455+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
18456 {
18457- int ret = 0;
18458+ size_t sz = __compiletime_object_size(dst);
18459+ unsigned ret = 0;
18460
18461 might_fault();
18462+
18463+ if (size > INT_MAX)
18464+ return size;
18465+
18466+ check_object_size(dst, size, false);
18467+
18468+#ifdef CONFIG_PAX_MEMORY_UDEREF
18469+ if (!__access_ok(VERIFY_READ, src, size))
18470+ return size;
18471+#endif
18472+
18473+ if (unlikely(sz != (size_t)-1 && sz < size)) {
18474+ copy_from_user_overflow();
18475+ return size;
18476+ }
18477+
18478 if (!__builtin_constant_p(size))
18479- return copy_user_generic(dst, (__force void *)src, size);
18480+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
18481 switch (size) {
18482- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
18483+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
18484 ret, "b", "b", "=q", 1);
18485 return ret;
18486- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
18487+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
18488 ret, "w", "w", "=r", 2);
18489 return ret;
18490- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
18491+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
18492 ret, "l", "k", "=r", 4);
18493 return ret;
18494- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
18495+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
18496 ret, "q", "", "=r", 8);
18497 return ret;
18498 case 10:
18499- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
18500+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
18501 ret, "q", "", "=r", 10);
18502 if (unlikely(ret))
18503 return ret;
18504 __get_user_asm(*(u16 *)(8 + (char *)dst),
18505- (u16 __user *)(8 + (char __user *)src),
18506+ (const u16 __user *)(8 + (const char __user *)src),
18507 ret, "w", "w", "=r", 2);
18508 return ret;
18509 case 16:
18510- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
18511+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
18512 ret, "q", "", "=r", 16);
18513 if (unlikely(ret))
18514 return ret;
18515 __get_user_asm(*(u64 *)(8 + (char *)dst),
18516- (u64 __user *)(8 + (char __user *)src),
18517+ (const u64 __user *)(8 + (const char __user *)src),
18518 ret, "q", "", "=r", 8);
18519 return ret;
18520 default:
18521- return copy_user_generic(dst, (__force void *)src, size);
18522+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
18523 }
18524 }
18525
18526 static __always_inline __must_check
18527-int __copy_to_user(void __user *dst, const void *src, unsigned size)
18528+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
18529 {
18530- int ret = 0;
18531+ size_t sz = __compiletime_object_size(src);
18532+ unsigned ret = 0;
18533
18534 might_fault();
18535+
18536+ if (size > INT_MAX)
18537+ return size;
18538+
18539+ check_object_size(src, size, true);
18540+
18541+#ifdef CONFIG_PAX_MEMORY_UDEREF
18542+ if (!__access_ok(VERIFY_WRITE, dst, size))
18543+ return size;
18544+#endif
18545+
18546+ if (unlikely(sz != (size_t)-1 && sz < size)) {
18547+ copy_to_user_overflow();
18548+ return size;
18549+ }
18550+
18551 if (!__builtin_constant_p(size))
18552- return copy_user_generic((__force void *)dst, src, size);
18553+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
18554 switch (size) {
18555- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
18556+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
18557 ret, "b", "b", "iq", 1);
18558 return ret;
18559- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
18560+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
18561 ret, "w", "w", "ir", 2);
18562 return ret;
18563- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
18564+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
18565 ret, "l", "k", "ir", 4);
18566 return ret;
18567- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
18568+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
18569 ret, "q", "", "er", 8);
18570 return ret;
18571 case 10:
18572- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
18573+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
18574 ret, "q", "", "er", 10);
18575 if (unlikely(ret))
18576 return ret;
18577 asm("":::"memory");
18578- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
18579+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
18580 ret, "w", "w", "ir", 2);
18581 return ret;
18582 case 16:
18583- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
18584+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
18585 ret, "q", "", "er", 16);
18586 if (unlikely(ret))
18587 return ret;
18588 asm("":::"memory");
18589- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
18590+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
18591 ret, "q", "", "er", 8);
18592 return ret;
18593 default:
18594- return copy_user_generic((__force void *)dst, src, size);
18595+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
18596 }
18597 }
18598
18599 static __always_inline __must_check
18600-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18601+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
18602 {
18603- int ret = 0;
18604+ unsigned ret = 0;
18605
18606 might_fault();
18607+
18608+ if (size > INT_MAX)
18609+ return size;
18610+
18611+#ifdef CONFIG_PAX_MEMORY_UDEREF
18612+ if (!__access_ok(VERIFY_READ, src, size))
18613+ return size;
18614+ if (!__access_ok(VERIFY_WRITE, dst, size))
18615+ return size;
18616+#endif
18617+
18618 if (!__builtin_constant_p(size))
18619- return copy_user_generic((__force void *)dst,
18620- (__force void *)src, size);
18621+ return copy_user_generic((__force_kernel void *)____m(dst),
18622+ (__force_kernel const void *)____m(src), size);
18623 switch (size) {
18624 case 1: {
18625 u8 tmp;
18626- __get_user_asm(tmp, (u8 __user *)src,
18627+ __get_user_asm(tmp, (const u8 __user *)src,
18628 ret, "b", "b", "=q", 1);
18629 if (likely(!ret))
18630 __put_user_asm(tmp, (u8 __user *)dst,
18631@@ -185,7 +250,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18632 }
18633 case 2: {
18634 u16 tmp;
18635- __get_user_asm(tmp, (u16 __user *)src,
18636+ __get_user_asm(tmp, (const u16 __user *)src,
18637 ret, "w", "w", "=r", 2);
18638 if (likely(!ret))
18639 __put_user_asm(tmp, (u16 __user *)dst,
18640@@ -195,7 +260,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18641
18642 case 4: {
18643 u32 tmp;
18644- __get_user_asm(tmp, (u32 __user *)src,
18645+ __get_user_asm(tmp, (const u32 __user *)src,
18646 ret, "l", "k", "=r", 4);
18647 if (likely(!ret))
18648 __put_user_asm(tmp, (u32 __user *)dst,
18649@@ -204,7 +269,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18650 }
18651 case 8: {
18652 u64 tmp;
18653- __get_user_asm(tmp, (u64 __user *)src,
18654+ __get_user_asm(tmp, (const u64 __user *)src,
18655 ret, "q", "", "=r", 8);
18656 if (likely(!ret))
18657 __put_user_asm(tmp, (u64 __user *)dst,
18658@@ -212,41 +277,74 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18659 return ret;
18660 }
18661 default:
18662- return copy_user_generic((__force void *)dst,
18663- (__force void *)src, size);
18664+ return copy_user_generic((__force_kernel void *)____m(dst),
18665+ (__force_kernel const void *)____m(src), size);
18666 }
18667 }
18668
18669-static __must_check __always_inline int
18670-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
18671+static __must_check __always_inline unsigned long
18672+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
18673 {
18674- return copy_user_generic(dst, (__force const void *)src, size);
18675+ if (size > INT_MAX)
18676+ return size;
18677+
18678+#ifdef CONFIG_PAX_MEMORY_UDEREF
18679+ if (!__access_ok(VERIFY_READ, src, size))
18680+ return size;
18681+#endif
18682+
18683+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
18684 }
18685
18686-static __must_check __always_inline int
18687-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
18688+static __must_check __always_inline unsigned long
18689+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
18690 {
18691- return copy_user_generic((__force void *)dst, src, size);
18692+ if (size > INT_MAX)
18693+ return size;
18694+
18695+#ifdef CONFIG_PAX_MEMORY_UDEREF
18696+ if (!__access_ok(VERIFY_WRITE, dst, size))
18697+ return size;
18698+#endif
18699+
18700+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
18701 }
18702
18703-extern long __copy_user_nocache(void *dst, const void __user *src,
18704- unsigned size, int zerorest);
18705+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
18706+ unsigned long size, int zerorest) __size_overflow(3);
18707
18708-static inline int
18709-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
18710+static inline unsigned long
18711+__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
18712 {
18713 might_fault();
18714+
18715+ if (size > INT_MAX)
18716+ return size;
18717+
18718+#ifdef CONFIG_PAX_MEMORY_UDEREF
18719+ if (!__access_ok(VERIFY_READ, src, size))
18720+ return size;
18721+#endif
18722+
18723 return __copy_user_nocache(dst, src, size, 1);
18724 }
18725
18726-static inline int
18727+static inline unsigned long
18728 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
18729- unsigned size)
18730+ unsigned long size)
18731 {
18732+ if (size > INT_MAX)
18733+ return size;
18734+
18735+#ifdef CONFIG_PAX_MEMORY_UDEREF
18736+ if (!__access_ok(VERIFY_READ, src, size))
18737+ return size;
18738+#endif
18739+
18740 return __copy_user_nocache(dst, src, size, 0);
18741 }
18742
18743 unsigned long
18744-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
18745+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
18746
18747 #endif /* _ASM_X86_UACCESS_64_H */
18748diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
18749index 5b238981..77fdd78 100644
18750--- a/arch/x86/include/asm/word-at-a-time.h
18751+++ b/arch/x86/include/asm/word-at-a-time.h
18752@@ -11,7 +11,7 @@
18753 * and shift, for example.
18754 */
18755 struct word_at_a_time {
18756- const unsigned long one_bits, high_bits;
18757+ unsigned long one_bits, high_bits;
18758 };
18759
18760 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
18761diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
18762index 828a156..650e625 100644
18763--- a/arch/x86/include/asm/x86_init.h
18764+++ b/arch/x86/include/asm/x86_init.h
18765@@ -129,7 +129,7 @@ struct x86_init_ops {
18766 struct x86_init_timers timers;
18767 struct x86_init_iommu iommu;
18768 struct x86_init_pci pci;
18769-};
18770+} __no_const;
18771
18772 /**
18773 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
18774@@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
18775 void (*setup_percpu_clockev)(void);
18776 void (*early_percpu_clock_init)(void);
18777 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
18778-};
18779+} __no_const;
18780
18781 struct timespec;
18782
18783@@ -168,7 +168,7 @@ struct x86_platform_ops {
18784 void (*save_sched_clock_state)(void);
18785 void (*restore_sched_clock_state)(void);
18786 void (*apic_post_init)(void);
18787-};
18788+} __no_const;
18789
18790 struct pci_dev;
18791 struct msi_msg;
18792@@ -182,7 +182,7 @@ struct x86_msi_ops {
18793 void (*teardown_msi_irqs)(struct pci_dev *dev);
18794 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
18795 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
18796-};
18797+} __no_const;
18798
18799 struct IO_APIC_route_entry;
18800 struct io_apic_irq_attr;
18801@@ -203,7 +203,7 @@ struct x86_io_apic_ops {
18802 unsigned int destination, int vector,
18803 struct io_apic_irq_attr *attr);
18804 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
18805-};
18806+} __no_const;
18807
18808 extern struct x86_init_ops x86_init;
18809 extern struct x86_cpuinit_ops x86_cpuinit;
18810diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
18811index 0415cda..3b22adc 100644
18812--- a/arch/x86/include/asm/xsave.h
18813+++ b/arch/x86/include/asm/xsave.h
18814@@ -70,8 +70,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
18815 if (unlikely(err))
18816 return -EFAULT;
18817
18818+ pax_open_userland();
18819 __asm__ __volatile__(ASM_STAC "\n"
18820- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
18821+ "1:"
18822+ __copyuser_seg
18823+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
18824 "2: " ASM_CLAC "\n"
18825 ".section .fixup,\"ax\"\n"
18826 "3: movl $-1,%[err]\n"
18827@@ -81,18 +84,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
18828 : [err] "=r" (err)
18829 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
18830 : "memory");
18831+ pax_close_userland();
18832 return err;
18833 }
18834
18835 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
18836 {
18837 int err;
18838- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
18839+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
18840 u32 lmask = mask;
18841 u32 hmask = mask >> 32;
18842
18843+ pax_open_userland();
18844 __asm__ __volatile__(ASM_STAC "\n"
18845- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
18846+ "1:"
18847+ __copyuser_seg
18848+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
18849 "2: " ASM_CLAC "\n"
18850 ".section .fixup,\"ax\"\n"
18851 "3: movl $-1,%[err]\n"
18852@@ -102,6 +109,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
18853 : [err] "=r" (err)
18854 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
18855 : "memory"); /* memory required? */
18856+ pax_close_userland();
18857 return err;
18858 }
18859
18860diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
18861index bbae024..e1528f9 100644
18862--- a/arch/x86/include/uapi/asm/e820.h
18863+++ b/arch/x86/include/uapi/asm/e820.h
18864@@ -63,7 +63,7 @@ struct e820map {
18865 #define ISA_START_ADDRESS 0xa0000
18866 #define ISA_END_ADDRESS 0x100000
18867
18868-#define BIOS_BEGIN 0x000a0000
18869+#define BIOS_BEGIN 0x000c0000
18870 #define BIOS_END 0x00100000
18871
18872 #define BIOS_ROM_BASE 0xffe00000
18873diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
18874index 88d99ea..9fc7e17 100644
18875--- a/arch/x86/kernel/Makefile
18876+++ b/arch/x86/kernel/Makefile
18877@@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
18878 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
18879 obj-$(CONFIG_IRQ_WORK) += irq_work.o
18880 obj-y += probe_roms.o
18881-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
18882+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
18883 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
18884 obj-y += syscall_$(BITS).o
18885 obj-$(CONFIG_X86_64) += vsyscall_64.o
18886diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
18887index 2627a81..cd8325e 100644
18888--- a/arch/x86/kernel/acpi/boot.c
18889+++ b/arch/x86/kernel/acpi/boot.c
18890@@ -1368,7 +1368,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
18891 * If your system is blacklisted here, but you find that acpi=force
18892 * works for you, please contact linux-acpi@vger.kernel.org
18893 */
18894-static struct dmi_system_id __initdata acpi_dmi_table[] = {
18895+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
18896 /*
18897 * Boxes that need ACPI disabled
18898 */
18899@@ -1443,7 +1443,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
18900 };
18901
18902 /* second table for DMI checks that should run after early-quirks */
18903-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
18904+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
18905 /*
18906 * HP laptops which use a DSDT reporting as HP/SB400/10000,
18907 * which includes some code which overrides all temperature
18908diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
18909index 3312010..a65ca7b 100644
18910--- a/arch/x86/kernel/acpi/sleep.c
18911+++ b/arch/x86/kernel/acpi/sleep.c
18912@@ -88,8 +88,12 @@ int x86_acpi_suspend_lowlevel(void)
18913 #else /* CONFIG_64BIT */
18914 #ifdef CONFIG_SMP
18915 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
18916+
18917+ pax_open_kernel();
18918 early_gdt_descr.address =
18919 (unsigned long)get_cpu_gdt_table(smp_processor_id());
18920+ pax_close_kernel();
18921+
18922 initial_gs = per_cpu_offset(smp_processor_id());
18923 #endif
18924 initial_code = (unsigned long)wakeup_long64;
18925diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
18926index d1daa66..59fecba 100644
18927--- a/arch/x86/kernel/acpi/wakeup_32.S
18928+++ b/arch/x86/kernel/acpi/wakeup_32.S
18929@@ -29,13 +29,11 @@ wakeup_pmode_return:
18930 # and restore the stack ... but you need gdt for this to work
18931 movl saved_context_esp, %esp
18932
18933- movl %cs:saved_magic, %eax
18934- cmpl $0x12345678, %eax
18935+ cmpl $0x12345678, saved_magic
18936 jne bogus_magic
18937
18938 # jump to place where we left off
18939- movl saved_eip, %eax
18940- jmp *%eax
18941+ jmp *(saved_eip)
18942
18943 bogus_magic:
18944 jmp bogus_magic
18945diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
18946index c15cf9a..0e63558 100644
18947--- a/arch/x86/kernel/alternative.c
18948+++ b/arch/x86/kernel/alternative.c
18949@@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
18950 */
18951 for (a = start; a < end; a++) {
18952 instr = (u8 *)&a->instr_offset + a->instr_offset;
18953+
18954+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18955+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18956+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
18957+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18958+#endif
18959+
18960 replacement = (u8 *)&a->repl_offset + a->repl_offset;
18961 BUG_ON(a->replacementlen > a->instrlen);
18962 BUG_ON(a->instrlen > sizeof(insnbuf));
18963@@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
18964 for (poff = start; poff < end; poff++) {
18965 u8 *ptr = (u8 *)poff + *poff;
18966
18967+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18968+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18969+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
18970+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18971+#endif
18972+
18973 if (!*poff || ptr < text || ptr >= text_end)
18974 continue;
18975 /* turn DS segment override prefix into lock prefix */
18976- if (*ptr == 0x3e)
18977+ if (*ktla_ktva(ptr) == 0x3e)
18978 text_poke(ptr, ((unsigned char []){0xf0}), 1);
18979 }
18980 mutex_unlock(&text_mutex);
18981@@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
18982 for (poff = start; poff < end; poff++) {
18983 u8 *ptr = (u8 *)poff + *poff;
18984
18985+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18986+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18987+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
18988+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18989+#endif
18990+
18991 if (!*poff || ptr < text || ptr >= text_end)
18992 continue;
18993 /* turn lock prefix into DS segment override prefix */
18994- if (*ptr == 0xf0)
18995+ if (*ktla_ktva(ptr) == 0xf0)
18996 text_poke(ptr, ((unsigned char []){0x3E}), 1);
18997 }
18998 mutex_unlock(&text_mutex);
18999@@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
19000
19001 BUG_ON(p->len > MAX_PATCH_LEN);
19002 /* prep the buffer with the original instructions */
19003- memcpy(insnbuf, p->instr, p->len);
19004+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
19005 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
19006 (unsigned long)p->instr, p->len);
19007
19008@@ -515,7 +534,7 @@ void __init alternative_instructions(void)
19009 if (!uniproc_patched || num_possible_cpus() == 1)
19010 free_init_pages("SMP alternatives",
19011 (unsigned long)__smp_locks,
19012- (unsigned long)__smp_locks_end);
19013+ PAGE_ALIGN((unsigned long)__smp_locks_end));
19014 #endif
19015
19016 apply_paravirt(__parainstructions, __parainstructions_end);
19017@@ -535,13 +554,17 @@ void __init alternative_instructions(void)
19018 * instructions. And on the local CPU you need to be protected again NMI or MCE
19019 * handlers seeing an inconsistent instruction while you patch.
19020 */
19021-void *__init_or_module text_poke_early(void *addr, const void *opcode,
19022+void *__kprobes text_poke_early(void *addr, const void *opcode,
19023 size_t len)
19024 {
19025 unsigned long flags;
19026 local_irq_save(flags);
19027- memcpy(addr, opcode, len);
19028+
19029+ pax_open_kernel();
19030+ memcpy(ktla_ktva(addr), opcode, len);
19031 sync_core();
19032+ pax_close_kernel();
19033+
19034 local_irq_restore(flags);
19035 /* Could also do a CLFLUSH here to speed up CPU recovery; but
19036 that causes hangs on some VIA CPUs. */
19037@@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
19038 */
19039 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
19040 {
19041- unsigned long flags;
19042- char *vaddr;
19043+ unsigned char *vaddr = ktla_ktva(addr);
19044 struct page *pages[2];
19045- int i;
19046+ size_t i;
19047
19048 if (!core_kernel_text((unsigned long)addr)) {
19049- pages[0] = vmalloc_to_page(addr);
19050- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
19051+ pages[0] = vmalloc_to_page(vaddr);
19052+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
19053 } else {
19054- pages[0] = virt_to_page(addr);
19055+ pages[0] = virt_to_page(vaddr);
19056 WARN_ON(!PageReserved(pages[0]));
19057- pages[1] = virt_to_page(addr + PAGE_SIZE);
19058+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
19059 }
19060 BUG_ON(!pages[0]);
19061- local_irq_save(flags);
19062- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
19063- if (pages[1])
19064- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
19065- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
19066- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
19067- clear_fixmap(FIX_TEXT_POKE0);
19068- if (pages[1])
19069- clear_fixmap(FIX_TEXT_POKE1);
19070- local_flush_tlb();
19071- sync_core();
19072- /* Could also do a CLFLUSH here to speed up CPU recovery; but
19073- that causes hangs on some VIA CPUs. */
19074+ text_poke_early(addr, opcode, len);
19075 for (i = 0; i < len; i++)
19076- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
19077- local_irq_restore(flags);
19078+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
19079 return addr;
19080 }
19081
19082diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
19083index eca89c5..d566b78 100644
19084--- a/arch/x86/kernel/apic/apic.c
19085+++ b/arch/x86/kernel/apic/apic.c
19086@@ -190,7 +190,7 @@ int first_system_vector = 0xfe;
19087 /*
19088 * Debug level, exported for io_apic.c
19089 */
19090-unsigned int apic_verbosity;
19091+int apic_verbosity;
19092
19093 int pic_mode;
19094
19095@@ -1985,7 +1985,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
19096 apic_write(APIC_ESR, 0);
19097 v1 = apic_read(APIC_ESR);
19098 ack_APIC_irq();
19099- atomic_inc(&irq_err_count);
19100+ atomic_inc_unchecked(&irq_err_count);
19101
19102 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
19103 smp_processor_id(), v0 , v1);
19104diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
19105index 00c77cf..2dc6a2d 100644
19106--- a/arch/x86/kernel/apic/apic_flat_64.c
19107+++ b/arch/x86/kernel/apic/apic_flat_64.c
19108@@ -157,7 +157,7 @@ static int flat_probe(void)
19109 return 1;
19110 }
19111
19112-static struct apic apic_flat = {
19113+static struct apic apic_flat __read_only = {
19114 .name = "flat",
19115 .probe = flat_probe,
19116 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
19117@@ -271,7 +271,7 @@ static int physflat_probe(void)
19118 return 0;
19119 }
19120
19121-static struct apic apic_physflat = {
19122+static struct apic apic_physflat __read_only = {
19123
19124 .name = "physical flat",
19125 .probe = physflat_probe,
19126diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
19127index e145f28..2752888 100644
19128--- a/arch/x86/kernel/apic/apic_noop.c
19129+++ b/arch/x86/kernel/apic/apic_noop.c
19130@@ -119,7 +119,7 @@ static void noop_apic_write(u32 reg, u32 v)
19131 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
19132 }
19133
19134-struct apic apic_noop = {
19135+struct apic apic_noop __read_only = {
19136 .name = "noop",
19137 .probe = noop_probe,
19138 .acpi_madt_oem_check = NULL,
19139diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
19140index d50e364..543bee3 100644
19141--- a/arch/x86/kernel/apic/bigsmp_32.c
19142+++ b/arch/x86/kernel/apic/bigsmp_32.c
19143@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
19144 return dmi_bigsmp;
19145 }
19146
19147-static struct apic apic_bigsmp = {
19148+static struct apic apic_bigsmp __read_only = {
19149
19150 .name = "bigsmp",
19151 .probe = probe_bigsmp,
19152diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
19153index c552247..587a316 100644
19154--- a/arch/x86/kernel/apic/es7000_32.c
19155+++ b/arch/x86/kernel/apic/es7000_32.c
19156@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
19157 return ret && es7000_apic_is_cluster();
19158 }
19159
19160-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
19161-static struct apic __refdata apic_es7000_cluster = {
19162+static struct apic apic_es7000_cluster __read_only = {
19163
19164 .name = "es7000",
19165 .probe = probe_es7000,
19166@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
19167 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
19168 };
19169
19170-static struct apic __refdata apic_es7000 = {
19171+static struct apic apic_es7000 __read_only = {
19172
19173 .name = "es7000",
19174 .probe = probe_es7000,
19175diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
19176index 9ed796c..e930fe4 100644
19177--- a/arch/x86/kernel/apic/io_apic.c
19178+++ b/arch/x86/kernel/apic/io_apic.c
19179@@ -1060,7 +1060,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
19180 }
19181 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
19182
19183-void lock_vector_lock(void)
19184+void lock_vector_lock(void) __acquires(vector_lock)
19185 {
19186 /* Used to the online set of cpus does not change
19187 * during assign_irq_vector.
19188@@ -1068,7 +1068,7 @@ void lock_vector_lock(void)
19189 raw_spin_lock(&vector_lock);
19190 }
19191
19192-void unlock_vector_lock(void)
19193+void unlock_vector_lock(void) __releases(vector_lock)
19194 {
19195 raw_spin_unlock(&vector_lock);
19196 }
19197@@ -2362,7 +2362,7 @@ static void ack_apic_edge(struct irq_data *data)
19198 ack_APIC_irq();
19199 }
19200
19201-atomic_t irq_mis_count;
19202+atomic_unchecked_t irq_mis_count;
19203
19204 #ifdef CONFIG_GENERIC_PENDING_IRQ
19205 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
19206@@ -2503,7 +2503,7 @@ static void ack_apic_level(struct irq_data *data)
19207 * at the cpu.
19208 */
19209 if (!(v & (1 << (i & 0x1f)))) {
19210- atomic_inc(&irq_mis_count);
19211+ atomic_inc_unchecked(&irq_mis_count);
19212
19213 eoi_ioapic_irq(irq, cfg);
19214 }
19215diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
19216index 1e42e8f..daacf44 100644
19217--- a/arch/x86/kernel/apic/numaq_32.c
19218+++ b/arch/x86/kernel/apic/numaq_32.c
19219@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
19220 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
19221 }
19222
19223-/* Use __refdata to keep false positive warning calm. */
19224-static struct apic __refdata apic_numaq = {
19225+static struct apic apic_numaq __read_only = {
19226
19227 .name = "NUMAQ",
19228 .probe = probe_numaq,
19229diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
19230index eb35ef9..f184a21 100644
19231--- a/arch/x86/kernel/apic/probe_32.c
19232+++ b/arch/x86/kernel/apic/probe_32.c
19233@@ -72,7 +72,7 @@ static int probe_default(void)
19234 return 1;
19235 }
19236
19237-static struct apic apic_default = {
19238+static struct apic apic_default __read_only = {
19239
19240 .name = "default",
19241 .probe = probe_default,
19242diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
19243index 77c95c0..434f8a4 100644
19244--- a/arch/x86/kernel/apic/summit_32.c
19245+++ b/arch/x86/kernel/apic/summit_32.c
19246@@ -486,7 +486,7 @@ void setup_summit(void)
19247 }
19248 #endif
19249
19250-static struct apic apic_summit = {
19251+static struct apic apic_summit __read_only = {
19252
19253 .name = "summit",
19254 .probe = probe_summit,
19255diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
19256index 140e29d..d88bc95 100644
19257--- a/arch/x86/kernel/apic/x2apic_cluster.c
19258+++ b/arch/x86/kernel/apic/x2apic_cluster.c
19259@@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
19260 return notifier_from_errno(err);
19261 }
19262
19263-static struct notifier_block __refdata x2apic_cpu_notifier = {
19264+static struct notifier_block x2apic_cpu_notifier = {
19265 .notifier_call = update_clusterinfo,
19266 };
19267
19268@@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
19269 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
19270 }
19271
19272-static struct apic apic_x2apic_cluster = {
19273+static struct apic apic_x2apic_cluster __read_only = {
19274
19275 .name = "cluster x2apic",
19276 .probe = x2apic_cluster_probe,
19277diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
19278index 562a76d..a003c0f 100644
19279--- a/arch/x86/kernel/apic/x2apic_phys.c
19280+++ b/arch/x86/kernel/apic/x2apic_phys.c
19281@@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
19282 return apic == &apic_x2apic_phys;
19283 }
19284
19285-static struct apic apic_x2apic_phys = {
19286+static struct apic apic_x2apic_phys __read_only = {
19287
19288 .name = "physical x2apic",
19289 .probe = x2apic_phys_probe,
19290diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
19291index 1191ac1..2335fa4 100644
19292--- a/arch/x86/kernel/apic/x2apic_uv_x.c
19293+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
19294@@ -357,7 +357,7 @@ static int uv_probe(void)
19295 return apic == &apic_x2apic_uv_x;
19296 }
19297
19298-static struct apic __refdata apic_x2apic_uv_x = {
19299+static struct apic apic_x2apic_uv_x __read_only = {
19300
19301 .name = "UV large system",
19302 .probe = uv_probe,
19303diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
19304index 53a4e27..038760a 100644
19305--- a/arch/x86/kernel/apm_32.c
19306+++ b/arch/x86/kernel/apm_32.c
19307@@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
19308 * This is for buggy BIOS's that refer to (real mode) segment 0x40
19309 * even though they are called in protected mode.
19310 */
19311-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
19312+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
19313 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
19314
19315 static const char driver_version[] = "1.16ac"; /* no spaces */
19316@@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
19317 BUG_ON(cpu != 0);
19318 gdt = get_cpu_gdt_table(cpu);
19319 save_desc_40 = gdt[0x40 / 8];
19320+
19321+ pax_open_kernel();
19322 gdt[0x40 / 8] = bad_bios_desc;
19323+ pax_close_kernel();
19324
19325 apm_irq_save(flags);
19326 APM_DO_SAVE_SEGS;
19327@@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
19328 &call->esi);
19329 APM_DO_RESTORE_SEGS;
19330 apm_irq_restore(flags);
19331+
19332+ pax_open_kernel();
19333 gdt[0x40 / 8] = save_desc_40;
19334+ pax_close_kernel();
19335+
19336 put_cpu();
19337
19338 return call->eax & 0xff;
19339@@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
19340 BUG_ON(cpu != 0);
19341 gdt = get_cpu_gdt_table(cpu);
19342 save_desc_40 = gdt[0x40 / 8];
19343+
19344+ pax_open_kernel();
19345 gdt[0x40 / 8] = bad_bios_desc;
19346+ pax_close_kernel();
19347
19348 apm_irq_save(flags);
19349 APM_DO_SAVE_SEGS;
19350@@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
19351 &call->eax);
19352 APM_DO_RESTORE_SEGS;
19353 apm_irq_restore(flags);
19354+
19355+ pax_open_kernel();
19356 gdt[0x40 / 8] = save_desc_40;
19357+ pax_close_kernel();
19358+
19359 put_cpu();
19360 return error;
19361 }
19362@@ -2362,12 +2376,15 @@ static int __init apm_init(void)
19363 * code to that CPU.
19364 */
19365 gdt = get_cpu_gdt_table(0);
19366+
19367+ pax_open_kernel();
19368 set_desc_base(&gdt[APM_CS >> 3],
19369 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
19370 set_desc_base(&gdt[APM_CS_16 >> 3],
19371 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
19372 set_desc_base(&gdt[APM_DS >> 3],
19373 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
19374+ pax_close_kernel();
19375
19376 proc_create("apm", 0, NULL, &apm_file_ops);
19377
19378diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
19379index 2861082..6d4718e 100644
19380--- a/arch/x86/kernel/asm-offsets.c
19381+++ b/arch/x86/kernel/asm-offsets.c
19382@@ -33,6 +33,8 @@ void common(void) {
19383 OFFSET(TI_status, thread_info, status);
19384 OFFSET(TI_addr_limit, thread_info, addr_limit);
19385 OFFSET(TI_preempt_count, thread_info, preempt_count);
19386+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
19387+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
19388
19389 BLANK();
19390 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
19391@@ -53,8 +55,26 @@ void common(void) {
19392 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
19393 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
19394 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
19395+
19396+#ifdef CONFIG_PAX_KERNEXEC
19397+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
19398 #endif
19399
19400+#ifdef CONFIG_PAX_MEMORY_UDEREF
19401+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
19402+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
19403+#ifdef CONFIG_X86_64
19404+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
19405+#endif
19406+#endif
19407+
19408+#endif
19409+
19410+ BLANK();
19411+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
19412+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
19413+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
19414+
19415 #ifdef CONFIG_XEN
19416 BLANK();
19417 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
19418diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
19419index e7c798b..2b2019b 100644
19420--- a/arch/x86/kernel/asm-offsets_64.c
19421+++ b/arch/x86/kernel/asm-offsets_64.c
19422@@ -77,6 +77,7 @@ int main(void)
19423 BLANK();
19424 #undef ENTRY
19425
19426+ DEFINE(TSS_size, sizeof(struct tss_struct));
19427 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
19428 BLANK();
19429
19430diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
19431index 47b56a7..efc2bc6 100644
19432--- a/arch/x86/kernel/cpu/Makefile
19433+++ b/arch/x86/kernel/cpu/Makefile
19434@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
19435 CFLAGS_REMOVE_perf_event.o = -pg
19436 endif
19437
19438-# Make sure load_percpu_segment has no stackprotector
19439-nostackp := $(call cc-option, -fno-stack-protector)
19440-CFLAGS_common.o := $(nostackp)
19441-
19442 obj-y := intel_cacheinfo.o scattered.o topology.o
19443 obj-y += proc.o capflags.o powerflags.o common.o
19444 obj-y += rdrand.o
19445diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
19446index 08a0890..e557865 100644
19447--- a/arch/x86/kernel/cpu/amd.c
19448+++ b/arch/x86/kernel/cpu/amd.c
19449@@ -743,7 +743,7 @@ static void init_amd(struct cpuinfo_x86 *c)
19450 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
19451 {
19452 /* AMD errata T13 (order #21922) */
19453- if ((c->x86 == 6)) {
19454+ if (c->x86 == 6) {
19455 /* Duron Rev A0 */
19456 if (c->x86_model == 3 && c->x86_mask == 0)
19457 size = 64;
19458diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
19459index 25eb274..3a92d93 100644
19460--- a/arch/x86/kernel/cpu/common.c
19461+++ b/arch/x86/kernel/cpu/common.c
19462@@ -88,60 +88,6 @@ static const struct cpu_dev default_cpu = {
19463
19464 static const struct cpu_dev *this_cpu = &default_cpu;
19465
19466-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
19467-#ifdef CONFIG_X86_64
19468- /*
19469- * We need valid kernel segments for data and code in long mode too
19470- * IRET will check the segment types kkeil 2000/10/28
19471- * Also sysret mandates a special GDT layout
19472- *
19473- * TLS descriptors are currently at a different place compared to i386.
19474- * Hopefully nobody expects them at a fixed place (Wine?)
19475- */
19476- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
19477- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
19478- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
19479- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
19480- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
19481- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
19482-#else
19483- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
19484- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
19485- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
19486- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
19487- /*
19488- * Segments used for calling PnP BIOS have byte granularity.
19489- * They code segments and data segments have fixed 64k limits,
19490- * the transfer segment sizes are set at run time.
19491- */
19492- /* 32-bit code */
19493- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
19494- /* 16-bit code */
19495- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
19496- /* 16-bit data */
19497- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
19498- /* 16-bit data */
19499- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
19500- /* 16-bit data */
19501- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
19502- /*
19503- * The APM segments have byte granularity and their bases
19504- * are set at run time. All have 64k limits.
19505- */
19506- /* 32-bit code */
19507- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
19508- /* 16-bit code */
19509- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
19510- /* data */
19511- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
19512-
19513- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
19514- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
19515- GDT_STACK_CANARY_INIT
19516-#endif
19517-} };
19518-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
19519-
19520 static int __init x86_xsave_setup(char *s)
19521 {
19522 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
19523@@ -288,6 +234,57 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
19524 set_in_cr4(X86_CR4_SMAP);
19525 }
19526
19527+#ifdef CONFIG_X86_64
19528+static __init int setup_disable_pcid(char *arg)
19529+{
19530+ setup_clear_cpu_cap(X86_FEATURE_PCID);
19531+
19532+#ifdef CONFIG_PAX_MEMORY_UDEREF
19533+ if (clone_pgd_mask != ~(pgdval_t)0UL)
19534+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
19535+#endif
19536+
19537+ return 1;
19538+}
19539+__setup("nopcid", setup_disable_pcid);
19540+
19541+static void setup_pcid(struct cpuinfo_x86 *c)
19542+{
19543+ if (!cpu_has(c, X86_FEATURE_PCID)) {
19544+
19545+#ifdef CONFIG_PAX_MEMORY_UDEREF
19546+ if (clone_pgd_mask != ~(pgdval_t)0UL) {
19547+ pax_open_kernel();
19548+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
19549+ pax_close_kernel();
19550+ printk("PAX: slow and weak UDEREF enabled\n");
19551+ } else
19552+ printk("PAX: UDEREF disabled\n");
19553+#endif
19554+
19555+ return;
19556+ }
19557+
19558+ printk("PAX: PCID detected\n");
19559+ set_in_cr4(X86_CR4_PCIDE);
19560+
19561+#ifdef CONFIG_PAX_MEMORY_UDEREF
19562+ pax_open_kernel();
19563+ clone_pgd_mask = ~(pgdval_t)0UL;
19564+ pax_close_kernel();
19565+ if (pax_user_shadow_base)
19566+ printk("PAX: weak UDEREF enabled\n");
19567+ else {
19568+ set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
19569+ printk("PAX: strong UDEREF enabled\n");
19570+ }
19571+#endif
19572+
19573+ if (cpu_has(c, X86_FEATURE_INVPCID))
19574+ printk("PAX: INVPCID detected\n");
19575+}
19576+#endif
19577+
19578 /*
19579 * Some CPU features depend on higher CPUID levels, which may not always
19580 * be available due to CPUID level capping or broken virtualization
19581@@ -386,7 +383,7 @@ void switch_to_new_gdt(int cpu)
19582 {
19583 struct desc_ptr gdt_descr;
19584
19585- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
19586+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19587 gdt_descr.size = GDT_SIZE - 1;
19588 load_gdt(&gdt_descr);
19589 /* Reload the per-cpu base */
19590@@ -875,6 +872,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
19591 setup_smep(c);
19592 setup_smap(c);
19593
19594+#ifdef CONFIG_X86_64
19595+ setup_pcid(c);
19596+#endif
19597+
19598 /*
19599 * The vendor-specific functions might have changed features.
19600 * Now we do "generic changes."
19601@@ -883,6 +884,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
19602 /* Filter out anything that depends on CPUID levels we don't have */
19603 filter_cpuid_features(c, true);
19604
19605+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
19606+ setup_clear_cpu_cap(X86_FEATURE_SEP);
19607+#endif
19608+
19609 /* If the model name is still unset, do table lookup. */
19610 if (!c->x86_model_id[0]) {
19611 const char *p;
19612@@ -1070,10 +1075,12 @@ static __init int setup_disablecpuid(char *arg)
19613 }
19614 __setup("clearcpuid=", setup_disablecpuid);
19615
19616+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
19617+EXPORT_PER_CPU_SYMBOL(current_tinfo);
19618+
19619 #ifdef CONFIG_X86_64
19620-struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
19621-struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
19622- (unsigned long) debug_idt_table };
19623+struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
19624+const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
19625
19626 DEFINE_PER_CPU_FIRST(union irq_stack_union,
19627 irq_stack_union) __aligned(PAGE_SIZE);
19628@@ -1087,7 +1094,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
19629 EXPORT_PER_CPU_SYMBOL(current_task);
19630
19631 DEFINE_PER_CPU(unsigned long, kernel_stack) =
19632- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
19633+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
19634 EXPORT_PER_CPU_SYMBOL(kernel_stack);
19635
19636 DEFINE_PER_CPU(char *, irq_stack_ptr) =
19637@@ -1232,7 +1239,7 @@ void cpu_init(void)
19638 load_ucode_ap();
19639
19640 cpu = stack_smp_processor_id();
19641- t = &per_cpu(init_tss, cpu);
19642+ t = init_tss + cpu;
19643 oist = &per_cpu(orig_ist, cpu);
19644
19645 #ifdef CONFIG_NUMA
19646@@ -1267,7 +1274,6 @@ void cpu_init(void)
19647 wrmsrl(MSR_KERNEL_GS_BASE, 0);
19648 barrier();
19649
19650- x86_configure_nx();
19651 enable_x2apic();
19652
19653 /*
19654@@ -1319,7 +1325,7 @@ void cpu_init(void)
19655 {
19656 int cpu = smp_processor_id();
19657 struct task_struct *curr = current;
19658- struct tss_struct *t = &per_cpu(init_tss, cpu);
19659+ struct tss_struct *t = init_tss + cpu;
19660 struct thread_struct *thread = &curr->thread;
19661
19662 show_ucode_info_early();
19663diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
19664index 1414c90..1159406 100644
19665--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
19666+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
19667@@ -1014,6 +1014,22 @@ static struct attribute *default_attrs[] = {
19668 };
19669
19670 #ifdef CONFIG_AMD_NB
19671+static struct attribute *default_attrs_amd_nb[] = {
19672+ &type.attr,
19673+ &level.attr,
19674+ &coherency_line_size.attr,
19675+ &physical_line_partition.attr,
19676+ &ways_of_associativity.attr,
19677+ &number_of_sets.attr,
19678+ &size.attr,
19679+ &shared_cpu_map.attr,
19680+ &shared_cpu_list.attr,
19681+ NULL,
19682+ NULL,
19683+ NULL,
19684+ NULL
19685+};
19686+
19687 static struct attribute **amd_l3_attrs(void)
19688 {
19689 static struct attribute **attrs;
19690@@ -1024,18 +1040,7 @@ static struct attribute **amd_l3_attrs(void)
19691
19692 n = ARRAY_SIZE(default_attrs);
19693
19694- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
19695- n += 2;
19696-
19697- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
19698- n += 1;
19699-
19700- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
19701- if (attrs == NULL)
19702- return attrs = default_attrs;
19703-
19704- for (n = 0; default_attrs[n]; n++)
19705- attrs[n] = default_attrs[n];
19706+ attrs = default_attrs_amd_nb;
19707
19708 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
19709 attrs[n++] = &cache_disable_0.attr;
19710@@ -1086,6 +1091,13 @@ static struct kobj_type ktype_cache = {
19711 .default_attrs = default_attrs,
19712 };
19713
19714+#ifdef CONFIG_AMD_NB
19715+static struct kobj_type ktype_cache_amd_nb = {
19716+ .sysfs_ops = &sysfs_ops,
19717+ .default_attrs = default_attrs_amd_nb,
19718+};
19719+#endif
19720+
19721 static struct kobj_type ktype_percpu_entry = {
19722 .sysfs_ops = &sysfs_ops,
19723 };
19724@@ -1151,20 +1163,26 @@ static int cache_add_dev(struct device *dev)
19725 return retval;
19726 }
19727
19728+#ifdef CONFIG_AMD_NB
19729+ amd_l3_attrs();
19730+#endif
19731+
19732 for (i = 0; i < num_cache_leaves; i++) {
19733+ struct kobj_type *ktype;
19734+
19735 this_object = INDEX_KOBJECT_PTR(cpu, i);
19736 this_object->cpu = cpu;
19737 this_object->index = i;
19738
19739 this_leaf = CPUID4_INFO_IDX(cpu, i);
19740
19741- ktype_cache.default_attrs = default_attrs;
19742+ ktype = &ktype_cache;
19743 #ifdef CONFIG_AMD_NB
19744 if (this_leaf->base.nb)
19745- ktype_cache.default_attrs = amd_l3_attrs();
19746+ ktype = &ktype_cache_amd_nb;
19747 #endif
19748 retval = kobject_init_and_add(&(this_object->kobj),
19749- &ktype_cache,
19750+ ktype,
19751 per_cpu(ici_cache_kobject, cpu),
19752 "index%1lu", i);
19753 if (unlikely(retval)) {
19754diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
19755index 87a65c9..92fcce6 100644
19756--- a/arch/x86/kernel/cpu/mcheck/mce.c
19757+++ b/arch/x86/kernel/cpu/mcheck/mce.c
19758@@ -45,6 +45,7 @@
19759 #include <asm/processor.h>
19760 #include <asm/mce.h>
19761 #include <asm/msr.h>
19762+#include <asm/local.h>
19763
19764 #include "mce-internal.h"
19765
19766@@ -249,7 +250,7 @@ static void print_mce(struct mce *m)
19767 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
19768 m->cs, m->ip);
19769
19770- if (m->cs == __KERNEL_CS)
19771+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
19772 print_symbol("{%s}", m->ip);
19773 pr_cont("\n");
19774 }
19775@@ -282,10 +283,10 @@ static void print_mce(struct mce *m)
19776
19777 #define PANIC_TIMEOUT 5 /* 5 seconds */
19778
19779-static atomic_t mce_paniced;
19780+static atomic_unchecked_t mce_paniced;
19781
19782 static int fake_panic;
19783-static atomic_t mce_fake_paniced;
19784+static atomic_unchecked_t mce_fake_paniced;
19785
19786 /* Panic in progress. Enable interrupts and wait for final IPI */
19787 static void wait_for_panic(void)
19788@@ -309,7 +310,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
19789 /*
19790 * Make sure only one CPU runs in machine check panic
19791 */
19792- if (atomic_inc_return(&mce_paniced) > 1)
19793+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
19794 wait_for_panic();
19795 barrier();
19796
19797@@ -317,7 +318,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
19798 console_verbose();
19799 } else {
19800 /* Don't log too much for fake panic */
19801- if (atomic_inc_return(&mce_fake_paniced) > 1)
19802+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
19803 return;
19804 }
19805 /* First print corrected ones that are still unlogged */
19806@@ -356,7 +357,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
19807 if (!fake_panic) {
19808 if (panic_timeout == 0)
19809 panic_timeout = mca_cfg.panic_timeout;
19810- panic(msg);
19811+ panic("%s", msg);
19812 } else
19813 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
19814 }
19815@@ -686,7 +687,7 @@ static int mce_timed_out(u64 *t)
19816 * might have been modified by someone else.
19817 */
19818 rmb();
19819- if (atomic_read(&mce_paniced))
19820+ if (atomic_read_unchecked(&mce_paniced))
19821 wait_for_panic();
19822 if (!mca_cfg.monarch_timeout)
19823 goto out;
19824@@ -1657,7 +1658,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
19825 }
19826
19827 /* Call the installed machine check handler for this CPU setup. */
19828-void (*machine_check_vector)(struct pt_regs *, long error_code) =
19829+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
19830 unexpected_machine_check;
19831
19832 /*
19833@@ -1680,7 +1681,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
19834 return;
19835 }
19836
19837+ pax_open_kernel();
19838 machine_check_vector = do_machine_check;
19839+ pax_close_kernel();
19840
19841 __mcheck_cpu_init_generic();
19842 __mcheck_cpu_init_vendor(c);
19843@@ -1694,7 +1697,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
19844 */
19845
19846 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
19847-static int mce_chrdev_open_count; /* #times opened */
19848+static local_t mce_chrdev_open_count; /* #times opened */
19849 static int mce_chrdev_open_exclu; /* already open exclusive? */
19850
19851 static int mce_chrdev_open(struct inode *inode, struct file *file)
19852@@ -1702,7 +1705,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
19853 spin_lock(&mce_chrdev_state_lock);
19854
19855 if (mce_chrdev_open_exclu ||
19856- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
19857+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
19858 spin_unlock(&mce_chrdev_state_lock);
19859
19860 return -EBUSY;
19861@@ -1710,7 +1713,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
19862
19863 if (file->f_flags & O_EXCL)
19864 mce_chrdev_open_exclu = 1;
19865- mce_chrdev_open_count++;
19866+ local_inc(&mce_chrdev_open_count);
19867
19868 spin_unlock(&mce_chrdev_state_lock);
19869
19870@@ -1721,7 +1724,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
19871 {
19872 spin_lock(&mce_chrdev_state_lock);
19873
19874- mce_chrdev_open_count--;
19875+ local_dec(&mce_chrdev_open_count);
19876 mce_chrdev_open_exclu = 0;
19877
19878 spin_unlock(&mce_chrdev_state_lock);
19879@@ -2376,7 +2379,7 @@ static __init void mce_init_banks(void)
19880
19881 for (i = 0; i < mca_cfg.banks; i++) {
19882 struct mce_bank *b = &mce_banks[i];
19883- struct device_attribute *a = &b->attr;
19884+ device_attribute_no_const *a = &b->attr;
19885
19886 sysfs_attr_init(&a->attr);
19887 a->attr.name = b->attrname;
19888@@ -2444,7 +2447,7 @@ struct dentry *mce_get_debugfs_dir(void)
19889 static void mce_reset(void)
19890 {
19891 cpu_missing = 0;
19892- atomic_set(&mce_fake_paniced, 0);
19893+ atomic_set_unchecked(&mce_fake_paniced, 0);
19894 atomic_set(&mce_executing, 0);
19895 atomic_set(&mce_callin, 0);
19896 atomic_set(&global_nwo, 0);
19897diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
19898index 1c044b1..37a2a43 100644
19899--- a/arch/x86/kernel/cpu/mcheck/p5.c
19900+++ b/arch/x86/kernel/cpu/mcheck/p5.c
19901@@ -11,6 +11,7 @@
19902 #include <asm/processor.h>
19903 #include <asm/mce.h>
19904 #include <asm/msr.h>
19905+#include <asm/pgtable.h>
19906
19907 /* By default disabled */
19908 int mce_p5_enabled __read_mostly;
19909@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
19910 if (!cpu_has(c, X86_FEATURE_MCE))
19911 return;
19912
19913+ pax_open_kernel();
19914 machine_check_vector = pentium_machine_check;
19915+ pax_close_kernel();
19916 /* Make sure the vector pointer is visible before we enable MCEs: */
19917 wmb();
19918
19919diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
19920index e9a701a..35317d6 100644
19921--- a/arch/x86/kernel/cpu/mcheck/winchip.c
19922+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
19923@@ -10,6 +10,7 @@
19924 #include <asm/processor.h>
19925 #include <asm/mce.h>
19926 #include <asm/msr.h>
19927+#include <asm/pgtable.h>
19928
19929 /* Machine check handler for WinChip C6: */
19930 static void winchip_machine_check(struct pt_regs *regs, long error_code)
19931@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
19932 {
19933 u32 lo, hi;
19934
19935+ pax_open_kernel();
19936 machine_check_vector = winchip_machine_check;
19937+ pax_close_kernel();
19938 /* Make sure the vector pointer is visible before we enable MCEs: */
19939 wmb();
19940
19941diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
19942index f961de9..8a9d332 100644
19943--- a/arch/x86/kernel/cpu/mtrr/main.c
19944+++ b/arch/x86/kernel/cpu/mtrr/main.c
19945@@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
19946 u64 size_or_mask, size_and_mask;
19947 static bool mtrr_aps_delayed_init;
19948
19949-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
19950+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
19951
19952 const struct mtrr_ops *mtrr_if;
19953
19954diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
19955index df5e41f..816c719 100644
19956--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
19957+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
19958@@ -25,7 +25,7 @@ struct mtrr_ops {
19959 int (*validate_add_page)(unsigned long base, unsigned long size,
19960 unsigned int type);
19961 int (*have_wrcomb)(void);
19962-};
19963+} __do_const;
19964
19965 extern int generic_get_free_region(unsigned long base, unsigned long size,
19966 int replace_reg);
19967diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
19968index a7c7305..b9705ab 100644
19969--- a/arch/x86/kernel/cpu/perf_event.c
19970+++ b/arch/x86/kernel/cpu/perf_event.c
19971@@ -1348,7 +1348,7 @@ static void __init pmu_check_apic(void)
19972 pr_info("no hardware sampling interrupt available.\n");
19973 }
19974
19975-static struct attribute_group x86_pmu_format_group = {
19976+static attribute_group_no_const x86_pmu_format_group = {
19977 .name = "format",
19978 .attrs = NULL,
19979 };
19980@@ -1447,7 +1447,7 @@ static struct attribute *events_attr[] = {
19981 NULL,
19982 };
19983
19984-static struct attribute_group x86_pmu_events_group = {
19985+static attribute_group_no_const x86_pmu_events_group = {
19986 .name = "events",
19987 .attrs = events_attr,
19988 };
19989@@ -1957,7 +1957,7 @@ static unsigned long get_segment_base(unsigned int segment)
19990 if (idx > GDT_ENTRIES)
19991 return 0;
19992
19993- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
19994+ desc = get_cpu_gdt_table(smp_processor_id());
19995 }
19996
19997 return get_desc_base(desc + idx);
19998@@ -2047,7 +2047,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
19999 break;
20000
20001 perf_callchain_store(entry, frame.return_address);
20002- fp = frame.next_frame;
20003+ fp = (const void __force_user *)frame.next_frame;
20004 }
20005 }
20006
20007diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20008index 639d128..e92d7e5 100644
20009--- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20010+++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20011@@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
20012 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
20013 {
20014 struct attribute **attrs;
20015- struct attribute_group *attr_group;
20016+ attribute_group_no_const *attr_group;
20017 int i = 0, j;
20018
20019 while (amd_iommu_v2_event_descs[i].attr.attr.name)
20020diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
20021index a45d8d4..8abd32c 100644
20022--- a/arch/x86/kernel/cpu/perf_event_intel.c
20023+++ b/arch/x86/kernel/cpu/perf_event_intel.c
20024@@ -2099,10 +2099,10 @@ __init int intel_pmu_init(void)
20025 * v2 and above have a perf capabilities MSR
20026 */
20027 if (version > 1) {
20028- u64 capabilities;
20029+ u64 capabilities = x86_pmu.intel_cap.capabilities;
20030
20031- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
20032- x86_pmu.intel_cap.capabilities = capabilities;
20033+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
20034+ x86_pmu.intel_cap.capabilities = capabilities;
20035 }
20036
20037 intel_ds_init();
20038diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20039index 1fb6c72..f5fa2a3 100644
20040--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20041+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20042@@ -3095,7 +3095,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
20043 static int __init uncore_type_init(struct intel_uncore_type *type)
20044 {
20045 struct intel_uncore_pmu *pmus;
20046- struct attribute_group *attr_group;
20047+ attribute_group_no_const *attr_group;
20048 struct attribute **attrs;
20049 int i, j;
20050
20051diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20052index 47b3d00c..2cf1751 100644
20053--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20054+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20055@@ -488,7 +488,7 @@ struct intel_uncore_box {
20056 struct uncore_event_desc {
20057 struct kobj_attribute attr;
20058 const char *config;
20059-};
20060+} __do_const;
20061
20062 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
20063 { \
20064diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
20065index 7d9481c..99c7e4b 100644
20066--- a/arch/x86/kernel/cpuid.c
20067+++ b/arch/x86/kernel/cpuid.c
20068@@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
20069 return notifier_from_errno(err);
20070 }
20071
20072-static struct notifier_block __refdata cpuid_class_cpu_notifier =
20073+static struct notifier_block cpuid_class_cpu_notifier =
20074 {
20075 .notifier_call = cpuid_class_cpu_callback,
20076 };
20077diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
20078index 74467fe..18793d5 100644
20079--- a/arch/x86/kernel/crash.c
20080+++ b/arch/x86/kernel/crash.c
20081@@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
20082 {
20083 #ifdef CONFIG_X86_32
20084 struct pt_regs fixed_regs;
20085-#endif
20086
20087-#ifdef CONFIG_X86_32
20088- if (!user_mode_vm(regs)) {
20089+ if (!user_mode(regs)) {
20090 crash_fixup_ss_esp(&fixed_regs, regs);
20091 regs = &fixed_regs;
20092 }
20093diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
20094index afa64ad..dce67dd 100644
20095--- a/arch/x86/kernel/crash_dump_64.c
20096+++ b/arch/x86/kernel/crash_dump_64.c
20097@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
20098 return -ENOMEM;
20099
20100 if (userbuf) {
20101- if (copy_to_user(buf, vaddr + offset, csize)) {
20102+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
20103 iounmap(vaddr);
20104 return -EFAULT;
20105 }
20106diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
20107index 5d3fe8d..02e1429 100644
20108--- a/arch/x86/kernel/doublefault.c
20109+++ b/arch/x86/kernel/doublefault.c
20110@@ -13,7 +13,7 @@
20111
20112 #define DOUBLEFAULT_STACKSIZE (1024)
20113 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
20114-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
20115+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
20116
20117 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
20118
20119@@ -23,7 +23,7 @@ static void doublefault_fn(void)
20120 unsigned long gdt, tss;
20121
20122 native_store_gdt(&gdt_desc);
20123- gdt = gdt_desc.address;
20124+ gdt = (unsigned long)gdt_desc.address;
20125
20126 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
20127
20128@@ -60,10 +60,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
20129 /* 0x2 bit is always set */
20130 .flags = X86_EFLAGS_SF | 0x2,
20131 .sp = STACK_START,
20132- .es = __USER_DS,
20133+ .es = __KERNEL_DS,
20134 .cs = __KERNEL_CS,
20135 .ss = __KERNEL_DS,
20136- .ds = __USER_DS,
20137+ .ds = __KERNEL_DS,
20138 .fs = __KERNEL_PERCPU,
20139
20140 .__cr3 = __pa_nodebug(swapper_pg_dir),
20141diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
20142index deb6421..76bbc12 100644
20143--- a/arch/x86/kernel/dumpstack.c
20144+++ b/arch/x86/kernel/dumpstack.c
20145@@ -2,6 +2,9 @@
20146 * Copyright (C) 1991, 1992 Linus Torvalds
20147 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
20148 */
20149+#ifdef CONFIG_GRKERNSEC_HIDESYM
20150+#define __INCLUDED_BY_HIDESYM 1
20151+#endif
20152 #include <linux/kallsyms.h>
20153 #include <linux/kprobes.h>
20154 #include <linux/uaccess.h>
20155@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
20156 static void
20157 print_ftrace_graph_addr(unsigned long addr, void *data,
20158 const struct stacktrace_ops *ops,
20159- struct thread_info *tinfo, int *graph)
20160+ struct task_struct *task, int *graph)
20161 {
20162- struct task_struct *task;
20163 unsigned long ret_addr;
20164 int index;
20165
20166 if (addr != (unsigned long)return_to_handler)
20167 return;
20168
20169- task = tinfo->task;
20170 index = task->curr_ret_stack;
20171
20172 if (!task->ret_stack || index < *graph)
20173@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
20174 static inline void
20175 print_ftrace_graph_addr(unsigned long addr, void *data,
20176 const struct stacktrace_ops *ops,
20177- struct thread_info *tinfo, int *graph)
20178+ struct task_struct *task, int *graph)
20179 { }
20180 #endif
20181
20182@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
20183 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
20184 */
20185
20186-static inline int valid_stack_ptr(struct thread_info *tinfo,
20187- void *p, unsigned int size, void *end)
20188+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
20189 {
20190- void *t = tinfo;
20191 if (end) {
20192 if (p < end && p >= (end-THREAD_SIZE))
20193 return 1;
20194@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
20195 }
20196
20197 unsigned long
20198-print_context_stack(struct thread_info *tinfo,
20199+print_context_stack(struct task_struct *task, void *stack_start,
20200 unsigned long *stack, unsigned long bp,
20201 const struct stacktrace_ops *ops, void *data,
20202 unsigned long *end, int *graph)
20203 {
20204 struct stack_frame *frame = (struct stack_frame *)bp;
20205
20206- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
20207+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
20208 unsigned long addr;
20209
20210 addr = *stack;
20211@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
20212 } else {
20213 ops->address(data, addr, 0);
20214 }
20215- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
20216+ print_ftrace_graph_addr(addr, data, ops, task, graph);
20217 }
20218 stack++;
20219 }
20220@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
20221 EXPORT_SYMBOL_GPL(print_context_stack);
20222
20223 unsigned long
20224-print_context_stack_bp(struct thread_info *tinfo,
20225+print_context_stack_bp(struct task_struct *task, void *stack_start,
20226 unsigned long *stack, unsigned long bp,
20227 const struct stacktrace_ops *ops, void *data,
20228 unsigned long *end, int *graph)
20229@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
20230 struct stack_frame *frame = (struct stack_frame *)bp;
20231 unsigned long *ret_addr = &frame->return_address;
20232
20233- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
20234+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
20235 unsigned long addr = *ret_addr;
20236
20237 if (!__kernel_text_address(addr))
20238@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
20239 ops->address(data, addr, 1);
20240 frame = frame->next_frame;
20241 ret_addr = &frame->return_address;
20242- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
20243+ print_ftrace_graph_addr(addr, data, ops, task, graph);
20244 }
20245
20246 return (unsigned long)frame;
20247@@ -150,7 +149,7 @@ static int print_trace_stack(void *data, char *name)
20248 static void print_trace_address(void *data, unsigned long addr, int reliable)
20249 {
20250 touch_nmi_watchdog();
20251- printk(data);
20252+ printk("%s", (char *)data);
20253 printk_address(addr, reliable);
20254 }
20255
20256@@ -219,6 +218,8 @@ unsigned __kprobes long oops_begin(void)
20257 }
20258 EXPORT_SYMBOL_GPL(oops_begin);
20259
20260+extern void gr_handle_kernel_exploit(void);
20261+
20262 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
20263 {
20264 if (regs && kexec_should_crash(current))
20265@@ -240,7 +241,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
20266 panic("Fatal exception in interrupt");
20267 if (panic_on_oops)
20268 panic("Fatal exception");
20269- do_exit(signr);
20270+
20271+ gr_handle_kernel_exploit();
20272+
20273+ do_group_exit(signr);
20274 }
20275
20276 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
20277@@ -268,7 +272,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
20278 print_modules();
20279 show_regs(regs);
20280 #ifdef CONFIG_X86_32
20281- if (user_mode_vm(regs)) {
20282+ if (user_mode(regs)) {
20283 sp = regs->sp;
20284 ss = regs->ss & 0xffff;
20285 } else {
20286@@ -296,7 +300,7 @@ void die(const char *str, struct pt_regs *regs, long err)
20287 unsigned long flags = oops_begin();
20288 int sig = SIGSEGV;
20289
20290- if (!user_mode_vm(regs))
20291+ if (!user_mode(regs))
20292 report_bug(regs->ip, regs);
20293
20294 if (__die(str, regs, err))
20295diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
20296index f2a1770..540657f 100644
20297--- a/arch/x86/kernel/dumpstack_32.c
20298+++ b/arch/x86/kernel/dumpstack_32.c
20299@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20300 bp = stack_frame(task, regs);
20301
20302 for (;;) {
20303- struct thread_info *context;
20304+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
20305
20306- context = (struct thread_info *)
20307- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
20308- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
20309+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
20310
20311- stack = (unsigned long *)context->previous_esp;
20312- if (!stack)
20313+ if (stack_start == task_stack_page(task))
20314 break;
20315+ stack = *(unsigned long **)stack_start;
20316 if (ops->stack(data, "IRQ") < 0)
20317 break;
20318 touch_nmi_watchdog();
20319@@ -87,27 +85,28 @@ void show_regs(struct pt_regs *regs)
20320 int i;
20321
20322 show_regs_print_info(KERN_EMERG);
20323- __show_regs(regs, !user_mode_vm(regs));
20324+ __show_regs(regs, !user_mode(regs));
20325
20326 /*
20327 * When in-kernel, we also print out the stack and code at the
20328 * time of the fault..
20329 */
20330- if (!user_mode_vm(regs)) {
20331+ if (!user_mode(regs)) {
20332 unsigned int code_prologue = code_bytes * 43 / 64;
20333 unsigned int code_len = code_bytes;
20334 unsigned char c;
20335 u8 *ip;
20336+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
20337
20338 pr_emerg("Stack:\n");
20339 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
20340
20341 pr_emerg("Code:");
20342
20343- ip = (u8 *)regs->ip - code_prologue;
20344+ ip = (u8 *)regs->ip - code_prologue + cs_base;
20345 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
20346 /* try starting at IP */
20347- ip = (u8 *)regs->ip;
20348+ ip = (u8 *)regs->ip + cs_base;
20349 code_len = code_len - code_prologue + 1;
20350 }
20351 for (i = 0; i < code_len; i++, ip++) {
20352@@ -116,7 +115,7 @@ void show_regs(struct pt_regs *regs)
20353 pr_cont(" Bad EIP value.");
20354 break;
20355 }
20356- if (ip == (u8 *)regs->ip)
20357+ if (ip == (u8 *)regs->ip + cs_base)
20358 pr_cont(" <%02x>", c);
20359 else
20360 pr_cont(" %02x", c);
20361@@ -129,6 +128,7 @@ int is_valid_bugaddr(unsigned long ip)
20362 {
20363 unsigned short ud2;
20364
20365+ ip = ktla_ktva(ip);
20366 if (ip < PAGE_OFFSET)
20367 return 0;
20368 if (probe_kernel_address((unsigned short *)ip, ud2))
20369@@ -136,3 +136,15 @@ int is_valid_bugaddr(unsigned long ip)
20370
20371 return ud2 == 0x0b0f;
20372 }
20373+
20374+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20375+void pax_check_alloca(unsigned long size)
20376+{
20377+ unsigned long sp = (unsigned long)&sp, stack_left;
20378+
20379+ /* all kernel stacks are of the same size */
20380+ stack_left = sp & (THREAD_SIZE - 1);
20381+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20382+}
20383+EXPORT_SYMBOL(pax_check_alloca);
20384+#endif
20385diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
20386index addb207..99635fa 100644
20387--- a/arch/x86/kernel/dumpstack_64.c
20388+++ b/arch/x86/kernel/dumpstack_64.c
20389@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20390 unsigned long *irq_stack_end =
20391 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
20392 unsigned used = 0;
20393- struct thread_info *tinfo;
20394 int graph = 0;
20395 unsigned long dummy;
20396+ void *stack_start;
20397
20398 if (!task)
20399 task = current;
20400@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20401 * current stack address. If the stacks consist of nested
20402 * exceptions
20403 */
20404- tinfo = task_thread_info(task);
20405 for (;;) {
20406 char *id;
20407 unsigned long *estack_end;
20408+
20409 estack_end = in_exception_stack(cpu, (unsigned long)stack,
20410 &used, &id);
20411
20412@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20413 if (ops->stack(data, id) < 0)
20414 break;
20415
20416- bp = ops->walk_stack(tinfo, stack, bp, ops,
20417+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
20418 data, estack_end, &graph);
20419 ops->stack(data, "<EOE>");
20420 /*
20421@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20422 * second-to-last pointer (index -2 to end) in the
20423 * exception stack:
20424 */
20425+ if ((u16)estack_end[-1] != __KERNEL_DS)
20426+ goto out;
20427 stack = (unsigned long *) estack_end[-2];
20428 continue;
20429 }
20430@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20431 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
20432 if (ops->stack(data, "IRQ") < 0)
20433 break;
20434- bp = ops->walk_stack(tinfo, stack, bp,
20435+ bp = ops->walk_stack(task, irq_stack, stack, bp,
20436 ops, data, irq_stack_end, &graph);
20437 /*
20438 * We link to the next stack (which would be
20439@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20440 /*
20441 * This handles the process stack:
20442 */
20443- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
20444+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
20445+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
20446+out:
20447 put_cpu();
20448 }
20449 EXPORT_SYMBOL(dump_trace);
20450@@ -300,3 +304,50 @@ int is_valid_bugaddr(unsigned long ip)
20451
20452 return ud2 == 0x0b0f;
20453 }
20454+
20455+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20456+void pax_check_alloca(unsigned long size)
20457+{
20458+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
20459+ unsigned cpu, used;
20460+ char *id;
20461+
20462+ /* check the process stack first */
20463+ stack_start = (unsigned long)task_stack_page(current);
20464+ stack_end = stack_start + THREAD_SIZE;
20465+ if (likely(stack_start <= sp && sp < stack_end)) {
20466+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
20467+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20468+ return;
20469+ }
20470+
20471+ cpu = get_cpu();
20472+
20473+ /* check the irq stacks */
20474+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
20475+ stack_start = stack_end - IRQ_STACK_SIZE;
20476+ if (stack_start <= sp && sp < stack_end) {
20477+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
20478+ put_cpu();
20479+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20480+ return;
20481+ }
20482+
20483+ /* check the exception stacks */
20484+ used = 0;
20485+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
20486+ stack_start = stack_end - EXCEPTION_STKSZ;
20487+ if (stack_end && stack_start <= sp && sp < stack_end) {
20488+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
20489+ put_cpu();
20490+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20491+ return;
20492+ }
20493+
20494+ put_cpu();
20495+
20496+ /* unknown stack */
20497+ BUG();
20498+}
20499+EXPORT_SYMBOL(pax_check_alloca);
20500+#endif
20501diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
20502index 174da5f..5e55606 100644
20503--- a/arch/x86/kernel/e820.c
20504+++ b/arch/x86/kernel/e820.c
20505@@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
20506
20507 static void early_panic(char *msg)
20508 {
20509- early_printk(msg);
20510- panic(msg);
20511+ early_printk("%s", msg);
20512+ panic("%s", msg);
20513 }
20514
20515 static int userdef __initdata;
20516diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
20517index d15f575..d692043 100644
20518--- a/arch/x86/kernel/early_printk.c
20519+++ b/arch/x86/kernel/early_printk.c
20520@@ -7,6 +7,7 @@
20521 #include <linux/pci_regs.h>
20522 #include <linux/pci_ids.h>
20523 #include <linux/errno.h>
20524+#include <linux/sched.h>
20525 #include <asm/io.h>
20526 #include <asm/processor.h>
20527 #include <asm/fcntl.h>
20528diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
20529index 2cfbc3a..b756682 100644
20530--- a/arch/x86/kernel/entry_32.S
20531+++ b/arch/x86/kernel/entry_32.S
20532@@ -177,13 +177,153 @@
20533 /*CFI_REL_OFFSET gs, PT_GS*/
20534 .endm
20535 .macro SET_KERNEL_GS reg
20536+
20537+#ifdef CONFIG_CC_STACKPROTECTOR
20538 movl $(__KERNEL_STACK_CANARY), \reg
20539+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
20540+ movl $(__USER_DS), \reg
20541+#else
20542+ xorl \reg, \reg
20543+#endif
20544+
20545 movl \reg, %gs
20546 .endm
20547
20548 #endif /* CONFIG_X86_32_LAZY_GS */
20549
20550-.macro SAVE_ALL
20551+.macro pax_enter_kernel
20552+#ifdef CONFIG_PAX_KERNEXEC
20553+ call pax_enter_kernel
20554+#endif
20555+.endm
20556+
20557+.macro pax_exit_kernel
20558+#ifdef CONFIG_PAX_KERNEXEC
20559+ call pax_exit_kernel
20560+#endif
20561+.endm
20562+
20563+#ifdef CONFIG_PAX_KERNEXEC
20564+ENTRY(pax_enter_kernel)
20565+#ifdef CONFIG_PARAVIRT
20566+ pushl %eax
20567+ pushl %ecx
20568+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
20569+ mov %eax, %esi
20570+#else
20571+ mov %cr0, %esi
20572+#endif
20573+ bts $16, %esi
20574+ jnc 1f
20575+ mov %cs, %esi
20576+ cmp $__KERNEL_CS, %esi
20577+ jz 3f
20578+ ljmp $__KERNEL_CS, $3f
20579+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
20580+2:
20581+#ifdef CONFIG_PARAVIRT
20582+ mov %esi, %eax
20583+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
20584+#else
20585+ mov %esi, %cr0
20586+#endif
20587+3:
20588+#ifdef CONFIG_PARAVIRT
20589+ popl %ecx
20590+ popl %eax
20591+#endif
20592+ ret
20593+ENDPROC(pax_enter_kernel)
20594+
20595+ENTRY(pax_exit_kernel)
20596+#ifdef CONFIG_PARAVIRT
20597+ pushl %eax
20598+ pushl %ecx
20599+#endif
20600+ mov %cs, %esi
20601+ cmp $__KERNEXEC_KERNEL_CS, %esi
20602+ jnz 2f
20603+#ifdef CONFIG_PARAVIRT
20604+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
20605+ mov %eax, %esi
20606+#else
20607+ mov %cr0, %esi
20608+#endif
20609+ btr $16, %esi
20610+ ljmp $__KERNEL_CS, $1f
20611+1:
20612+#ifdef CONFIG_PARAVIRT
20613+ mov %esi, %eax
20614+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
20615+#else
20616+ mov %esi, %cr0
20617+#endif
20618+2:
20619+#ifdef CONFIG_PARAVIRT
20620+ popl %ecx
20621+ popl %eax
20622+#endif
20623+ ret
20624+ENDPROC(pax_exit_kernel)
20625+#endif
20626+
20627+ .macro pax_erase_kstack
20628+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20629+ call pax_erase_kstack
20630+#endif
20631+ .endm
20632+
20633+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20634+/*
20635+ * ebp: thread_info
20636+ */
20637+ENTRY(pax_erase_kstack)
20638+ pushl %edi
20639+ pushl %ecx
20640+ pushl %eax
20641+
20642+ mov TI_lowest_stack(%ebp), %edi
20643+ mov $-0xBEEF, %eax
20644+ std
20645+
20646+1: mov %edi, %ecx
20647+ and $THREAD_SIZE_asm - 1, %ecx
20648+ shr $2, %ecx
20649+ repne scasl
20650+ jecxz 2f
20651+
20652+ cmp $2*16, %ecx
20653+ jc 2f
20654+
20655+ mov $2*16, %ecx
20656+ repe scasl
20657+ jecxz 2f
20658+ jne 1b
20659+
20660+2: cld
20661+ mov %esp, %ecx
20662+ sub %edi, %ecx
20663+
20664+ cmp $THREAD_SIZE_asm, %ecx
20665+ jb 3f
20666+ ud2
20667+3:
20668+
20669+ shr $2, %ecx
20670+ rep stosl
20671+
20672+ mov TI_task_thread_sp0(%ebp), %edi
20673+ sub $128, %edi
20674+ mov %edi, TI_lowest_stack(%ebp)
20675+
20676+ popl %eax
20677+ popl %ecx
20678+ popl %edi
20679+ ret
20680+ENDPROC(pax_erase_kstack)
20681+#endif
20682+
20683+.macro __SAVE_ALL _DS
20684 cld
20685 PUSH_GS
20686 pushl_cfi %fs
20687@@ -206,7 +346,7 @@
20688 CFI_REL_OFFSET ecx, 0
20689 pushl_cfi %ebx
20690 CFI_REL_OFFSET ebx, 0
20691- movl $(__USER_DS), %edx
20692+ movl $\_DS, %edx
20693 movl %edx, %ds
20694 movl %edx, %es
20695 movl $(__KERNEL_PERCPU), %edx
20696@@ -214,6 +354,15 @@
20697 SET_KERNEL_GS %edx
20698 .endm
20699
20700+.macro SAVE_ALL
20701+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
20702+ __SAVE_ALL __KERNEL_DS
20703+ pax_enter_kernel
20704+#else
20705+ __SAVE_ALL __USER_DS
20706+#endif
20707+.endm
20708+
20709 .macro RESTORE_INT_REGS
20710 popl_cfi %ebx
20711 CFI_RESTORE ebx
20712@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
20713 popfl_cfi
20714 jmp syscall_exit
20715 CFI_ENDPROC
20716-END(ret_from_fork)
20717+ENDPROC(ret_from_fork)
20718
20719 ENTRY(ret_from_kernel_thread)
20720 CFI_STARTPROC
20721@@ -344,7 +493,15 @@ ret_from_intr:
20722 andl $SEGMENT_RPL_MASK, %eax
20723 #endif
20724 cmpl $USER_RPL, %eax
20725+
20726+#ifdef CONFIG_PAX_KERNEXEC
20727+ jae resume_userspace
20728+
20729+ pax_exit_kernel
20730+ jmp resume_kernel
20731+#else
20732 jb resume_kernel # not returning to v8086 or userspace
20733+#endif
20734
20735 ENTRY(resume_userspace)
20736 LOCKDEP_SYS_EXIT
20737@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
20738 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
20739 # int/exception return?
20740 jne work_pending
20741- jmp restore_all
20742-END(ret_from_exception)
20743+ jmp restore_all_pax
20744+ENDPROC(ret_from_exception)
20745
20746 #ifdef CONFIG_PREEMPT
20747 ENTRY(resume_kernel)
20748@@ -372,7 +529,7 @@ need_resched:
20749 jz restore_all
20750 call preempt_schedule_irq
20751 jmp need_resched
20752-END(resume_kernel)
20753+ENDPROC(resume_kernel)
20754 #endif
20755 CFI_ENDPROC
20756 /*
20757@@ -406,30 +563,45 @@ sysenter_past_esp:
20758 /*CFI_REL_OFFSET cs, 0*/
20759 /*
20760 * Push current_thread_info()->sysenter_return to the stack.
20761- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
20762- * pushed above; +8 corresponds to copy_thread's esp0 setting.
20763 */
20764- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
20765+ pushl_cfi $0
20766 CFI_REL_OFFSET eip, 0
20767
20768 pushl_cfi %eax
20769 SAVE_ALL
20770+ GET_THREAD_INFO(%ebp)
20771+ movl TI_sysenter_return(%ebp),%ebp
20772+ movl %ebp,PT_EIP(%esp)
20773 ENABLE_INTERRUPTS(CLBR_NONE)
20774
20775 /*
20776 * Load the potential sixth argument from user stack.
20777 * Careful about security.
20778 */
20779+ movl PT_OLDESP(%esp),%ebp
20780+
20781+#ifdef CONFIG_PAX_MEMORY_UDEREF
20782+ mov PT_OLDSS(%esp),%ds
20783+1: movl %ds:(%ebp),%ebp
20784+ push %ss
20785+ pop %ds
20786+#else
20787 cmpl $__PAGE_OFFSET-3,%ebp
20788 jae syscall_fault
20789 ASM_STAC
20790 1: movl (%ebp),%ebp
20791 ASM_CLAC
20792+#endif
20793+
20794 movl %ebp,PT_EBP(%esp)
20795 _ASM_EXTABLE(1b,syscall_fault)
20796
20797 GET_THREAD_INFO(%ebp)
20798
20799+#ifdef CONFIG_PAX_RANDKSTACK
20800+ pax_erase_kstack
20801+#endif
20802+
20803 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
20804 jnz sysenter_audit
20805 sysenter_do_call:
20806@@ -444,12 +616,24 @@ sysenter_do_call:
20807 testl $_TIF_ALLWORK_MASK, %ecx
20808 jne sysexit_audit
20809 sysenter_exit:
20810+
20811+#ifdef CONFIG_PAX_RANDKSTACK
20812+ pushl_cfi %eax
20813+ movl %esp, %eax
20814+ call pax_randomize_kstack
20815+ popl_cfi %eax
20816+#endif
20817+
20818+ pax_erase_kstack
20819+
20820 /* if something modifies registers it must also disable sysexit */
20821 movl PT_EIP(%esp), %edx
20822 movl PT_OLDESP(%esp), %ecx
20823 xorl %ebp,%ebp
20824 TRACE_IRQS_ON
20825 1: mov PT_FS(%esp), %fs
20826+2: mov PT_DS(%esp), %ds
20827+3: mov PT_ES(%esp), %es
20828 PTGS_TO_GS
20829 ENABLE_INTERRUPTS_SYSEXIT
20830
20831@@ -466,6 +650,9 @@ sysenter_audit:
20832 movl %eax,%edx /* 2nd arg: syscall number */
20833 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
20834 call __audit_syscall_entry
20835+
20836+ pax_erase_kstack
20837+
20838 pushl_cfi %ebx
20839 movl PT_EAX(%esp),%eax /* reload syscall number */
20840 jmp sysenter_do_call
20841@@ -491,10 +678,16 @@ sysexit_audit:
20842
20843 CFI_ENDPROC
20844 .pushsection .fixup,"ax"
20845-2: movl $0,PT_FS(%esp)
20846+4: movl $0,PT_FS(%esp)
20847+ jmp 1b
20848+5: movl $0,PT_DS(%esp)
20849+ jmp 1b
20850+6: movl $0,PT_ES(%esp)
20851 jmp 1b
20852 .popsection
20853- _ASM_EXTABLE(1b,2b)
20854+ _ASM_EXTABLE(1b,4b)
20855+ _ASM_EXTABLE(2b,5b)
20856+ _ASM_EXTABLE(3b,6b)
20857 PTGS_TO_GS_EX
20858 ENDPROC(ia32_sysenter_target)
20859
20860@@ -509,6 +702,11 @@ ENTRY(system_call)
20861 pushl_cfi %eax # save orig_eax
20862 SAVE_ALL
20863 GET_THREAD_INFO(%ebp)
20864+
20865+#ifdef CONFIG_PAX_RANDKSTACK
20866+ pax_erase_kstack
20867+#endif
20868+
20869 # system call tracing in operation / emulation
20870 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
20871 jnz syscall_trace_entry
20872@@ -527,6 +725,15 @@ syscall_exit:
20873 testl $_TIF_ALLWORK_MASK, %ecx # current->work
20874 jne syscall_exit_work
20875
20876+restore_all_pax:
20877+
20878+#ifdef CONFIG_PAX_RANDKSTACK
20879+ movl %esp, %eax
20880+ call pax_randomize_kstack
20881+#endif
20882+
20883+ pax_erase_kstack
20884+
20885 restore_all:
20886 TRACE_IRQS_IRET
20887 restore_all_notrace:
20888@@ -583,14 +790,34 @@ ldt_ss:
20889 * compensating for the offset by changing to the ESPFIX segment with
20890 * a base address that matches for the difference.
20891 */
20892-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
20893+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
20894 mov %esp, %edx /* load kernel esp */
20895 mov PT_OLDESP(%esp), %eax /* load userspace esp */
20896 mov %dx, %ax /* eax: new kernel esp */
20897 sub %eax, %edx /* offset (low word is 0) */
20898+#ifdef CONFIG_SMP
20899+ movl PER_CPU_VAR(cpu_number), %ebx
20900+ shll $PAGE_SHIFT_asm, %ebx
20901+ addl $cpu_gdt_table, %ebx
20902+#else
20903+ movl $cpu_gdt_table, %ebx
20904+#endif
20905 shr $16, %edx
20906- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
20907- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
20908+
20909+#ifdef CONFIG_PAX_KERNEXEC
20910+ mov %cr0, %esi
20911+ btr $16, %esi
20912+ mov %esi, %cr0
20913+#endif
20914+
20915+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
20916+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
20917+
20918+#ifdef CONFIG_PAX_KERNEXEC
20919+ bts $16, %esi
20920+ mov %esi, %cr0
20921+#endif
20922+
20923 pushl_cfi $__ESPFIX_SS
20924 pushl_cfi %eax /* new kernel esp */
20925 /* Disable interrupts, but do not irqtrace this section: we
20926@@ -619,20 +846,18 @@ work_resched:
20927 movl TI_flags(%ebp), %ecx
20928 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
20929 # than syscall tracing?
20930- jz restore_all
20931+ jz restore_all_pax
20932 testb $_TIF_NEED_RESCHED, %cl
20933 jnz work_resched
20934
20935 work_notifysig: # deal with pending signals and
20936 # notify-resume requests
20937+ movl %esp, %eax
20938 #ifdef CONFIG_VM86
20939 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
20940- movl %esp, %eax
20941 jne work_notifysig_v86 # returning to kernel-space or
20942 # vm86-space
20943 1:
20944-#else
20945- movl %esp, %eax
20946 #endif
20947 TRACE_IRQS_ON
20948 ENABLE_INTERRUPTS(CLBR_NONE)
20949@@ -653,7 +878,7 @@ work_notifysig_v86:
20950 movl %eax, %esp
20951 jmp 1b
20952 #endif
20953-END(work_pending)
20954+ENDPROC(work_pending)
20955
20956 # perform syscall exit tracing
20957 ALIGN
20958@@ -661,11 +886,14 @@ syscall_trace_entry:
20959 movl $-ENOSYS,PT_EAX(%esp)
20960 movl %esp, %eax
20961 call syscall_trace_enter
20962+
20963+ pax_erase_kstack
20964+
20965 /* What it returned is what we'll actually use. */
20966 cmpl $(NR_syscalls), %eax
20967 jnae syscall_call
20968 jmp syscall_exit
20969-END(syscall_trace_entry)
20970+ENDPROC(syscall_trace_entry)
20971
20972 # perform syscall exit tracing
20973 ALIGN
20974@@ -678,21 +906,25 @@ syscall_exit_work:
20975 movl %esp, %eax
20976 call syscall_trace_leave
20977 jmp resume_userspace
20978-END(syscall_exit_work)
20979+ENDPROC(syscall_exit_work)
20980 CFI_ENDPROC
20981
20982 RING0_INT_FRAME # can't unwind into user space anyway
20983 syscall_fault:
20984+#ifdef CONFIG_PAX_MEMORY_UDEREF
20985+ push %ss
20986+ pop %ds
20987+#endif
20988 ASM_CLAC
20989 GET_THREAD_INFO(%ebp)
20990 movl $-EFAULT,PT_EAX(%esp)
20991 jmp resume_userspace
20992-END(syscall_fault)
20993+ENDPROC(syscall_fault)
20994
20995 syscall_badsys:
20996 movl $-ENOSYS,PT_EAX(%esp)
20997 jmp resume_userspace
20998-END(syscall_badsys)
20999+ENDPROC(syscall_badsys)
21000 CFI_ENDPROC
21001 /*
21002 * End of kprobes section
21003@@ -708,8 +940,15 @@ END(syscall_badsys)
21004 * normal stack and adjusts ESP with the matching offset.
21005 */
21006 /* fixup the stack */
21007- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
21008- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
21009+#ifdef CONFIG_SMP
21010+ movl PER_CPU_VAR(cpu_number), %ebx
21011+ shll $PAGE_SHIFT_asm, %ebx
21012+ addl $cpu_gdt_table, %ebx
21013+#else
21014+ movl $cpu_gdt_table, %ebx
21015+#endif
21016+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
21017+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
21018 shl $16, %eax
21019 addl %esp, %eax /* the adjusted stack pointer */
21020 pushl_cfi $__KERNEL_DS
21021@@ -762,7 +1001,7 @@ vector=vector+1
21022 .endr
21023 2: jmp common_interrupt
21024 .endr
21025-END(irq_entries_start)
21026+ENDPROC(irq_entries_start)
21027
21028 .previous
21029 END(interrupt)
21030@@ -823,7 +1062,7 @@ ENTRY(coprocessor_error)
21031 pushl_cfi $do_coprocessor_error
21032 jmp error_code
21033 CFI_ENDPROC
21034-END(coprocessor_error)
21035+ENDPROC(coprocessor_error)
21036
21037 ENTRY(simd_coprocessor_error)
21038 RING0_INT_FRAME
21039@@ -836,7 +1075,7 @@ ENTRY(simd_coprocessor_error)
21040 .section .altinstructions,"a"
21041 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
21042 .previous
21043-.section .altinstr_replacement,"ax"
21044+.section .altinstr_replacement,"a"
21045 663: pushl $do_simd_coprocessor_error
21046 664:
21047 .previous
21048@@ -845,7 +1084,7 @@ ENTRY(simd_coprocessor_error)
21049 #endif
21050 jmp error_code
21051 CFI_ENDPROC
21052-END(simd_coprocessor_error)
21053+ENDPROC(simd_coprocessor_error)
21054
21055 ENTRY(device_not_available)
21056 RING0_INT_FRAME
21057@@ -854,18 +1093,18 @@ ENTRY(device_not_available)
21058 pushl_cfi $do_device_not_available
21059 jmp error_code
21060 CFI_ENDPROC
21061-END(device_not_available)
21062+ENDPROC(device_not_available)
21063
21064 #ifdef CONFIG_PARAVIRT
21065 ENTRY(native_iret)
21066 iret
21067 _ASM_EXTABLE(native_iret, iret_exc)
21068-END(native_iret)
21069+ENDPROC(native_iret)
21070
21071 ENTRY(native_irq_enable_sysexit)
21072 sti
21073 sysexit
21074-END(native_irq_enable_sysexit)
21075+ENDPROC(native_irq_enable_sysexit)
21076 #endif
21077
21078 ENTRY(overflow)
21079@@ -875,7 +1114,7 @@ ENTRY(overflow)
21080 pushl_cfi $do_overflow
21081 jmp error_code
21082 CFI_ENDPROC
21083-END(overflow)
21084+ENDPROC(overflow)
21085
21086 ENTRY(bounds)
21087 RING0_INT_FRAME
21088@@ -884,7 +1123,7 @@ ENTRY(bounds)
21089 pushl_cfi $do_bounds
21090 jmp error_code
21091 CFI_ENDPROC
21092-END(bounds)
21093+ENDPROC(bounds)
21094
21095 ENTRY(invalid_op)
21096 RING0_INT_FRAME
21097@@ -893,7 +1132,7 @@ ENTRY(invalid_op)
21098 pushl_cfi $do_invalid_op
21099 jmp error_code
21100 CFI_ENDPROC
21101-END(invalid_op)
21102+ENDPROC(invalid_op)
21103
21104 ENTRY(coprocessor_segment_overrun)
21105 RING0_INT_FRAME
21106@@ -902,7 +1141,7 @@ ENTRY(coprocessor_segment_overrun)
21107 pushl_cfi $do_coprocessor_segment_overrun
21108 jmp error_code
21109 CFI_ENDPROC
21110-END(coprocessor_segment_overrun)
21111+ENDPROC(coprocessor_segment_overrun)
21112
21113 ENTRY(invalid_TSS)
21114 RING0_EC_FRAME
21115@@ -910,7 +1149,7 @@ ENTRY(invalid_TSS)
21116 pushl_cfi $do_invalid_TSS
21117 jmp error_code
21118 CFI_ENDPROC
21119-END(invalid_TSS)
21120+ENDPROC(invalid_TSS)
21121
21122 ENTRY(segment_not_present)
21123 RING0_EC_FRAME
21124@@ -918,7 +1157,7 @@ ENTRY(segment_not_present)
21125 pushl_cfi $do_segment_not_present
21126 jmp error_code
21127 CFI_ENDPROC
21128-END(segment_not_present)
21129+ENDPROC(segment_not_present)
21130
21131 ENTRY(stack_segment)
21132 RING0_EC_FRAME
21133@@ -926,7 +1165,7 @@ ENTRY(stack_segment)
21134 pushl_cfi $do_stack_segment
21135 jmp error_code
21136 CFI_ENDPROC
21137-END(stack_segment)
21138+ENDPROC(stack_segment)
21139
21140 ENTRY(alignment_check)
21141 RING0_EC_FRAME
21142@@ -934,7 +1173,7 @@ ENTRY(alignment_check)
21143 pushl_cfi $do_alignment_check
21144 jmp error_code
21145 CFI_ENDPROC
21146-END(alignment_check)
21147+ENDPROC(alignment_check)
21148
21149 ENTRY(divide_error)
21150 RING0_INT_FRAME
21151@@ -943,7 +1182,7 @@ ENTRY(divide_error)
21152 pushl_cfi $do_divide_error
21153 jmp error_code
21154 CFI_ENDPROC
21155-END(divide_error)
21156+ENDPROC(divide_error)
21157
21158 #ifdef CONFIG_X86_MCE
21159 ENTRY(machine_check)
21160@@ -953,7 +1192,7 @@ ENTRY(machine_check)
21161 pushl_cfi machine_check_vector
21162 jmp error_code
21163 CFI_ENDPROC
21164-END(machine_check)
21165+ENDPROC(machine_check)
21166 #endif
21167
21168 ENTRY(spurious_interrupt_bug)
21169@@ -963,7 +1202,7 @@ ENTRY(spurious_interrupt_bug)
21170 pushl_cfi $do_spurious_interrupt_bug
21171 jmp error_code
21172 CFI_ENDPROC
21173-END(spurious_interrupt_bug)
21174+ENDPROC(spurious_interrupt_bug)
21175 /*
21176 * End of kprobes section
21177 */
21178@@ -1073,7 +1312,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
21179
21180 ENTRY(mcount)
21181 ret
21182-END(mcount)
21183+ENDPROC(mcount)
21184
21185 ENTRY(ftrace_caller)
21186 cmpl $0, function_trace_stop
21187@@ -1106,7 +1345,7 @@ ftrace_graph_call:
21188 .globl ftrace_stub
21189 ftrace_stub:
21190 ret
21191-END(ftrace_caller)
21192+ENDPROC(ftrace_caller)
21193
21194 ENTRY(ftrace_regs_caller)
21195 pushf /* push flags before compare (in cs location) */
21196@@ -1207,7 +1446,7 @@ trace:
21197 popl %ecx
21198 popl %eax
21199 jmp ftrace_stub
21200-END(mcount)
21201+ENDPROC(mcount)
21202 #endif /* CONFIG_DYNAMIC_FTRACE */
21203 #endif /* CONFIG_FUNCTION_TRACER */
21204
21205@@ -1225,7 +1464,7 @@ ENTRY(ftrace_graph_caller)
21206 popl %ecx
21207 popl %eax
21208 ret
21209-END(ftrace_graph_caller)
21210+ENDPROC(ftrace_graph_caller)
21211
21212 .globl return_to_handler
21213 return_to_handler:
21214@@ -1281,15 +1520,18 @@ error_code:
21215 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
21216 REG_TO_PTGS %ecx
21217 SET_KERNEL_GS %ecx
21218- movl $(__USER_DS), %ecx
21219+ movl $(__KERNEL_DS), %ecx
21220 movl %ecx, %ds
21221 movl %ecx, %es
21222+
21223+ pax_enter_kernel
21224+
21225 TRACE_IRQS_OFF
21226 movl %esp,%eax # pt_regs pointer
21227 call *%edi
21228 jmp ret_from_exception
21229 CFI_ENDPROC
21230-END(page_fault)
21231+ENDPROC(page_fault)
21232
21233 /*
21234 * Debug traps and NMI can happen at the one SYSENTER instruction
21235@@ -1332,7 +1574,7 @@ debug_stack_correct:
21236 call do_debug
21237 jmp ret_from_exception
21238 CFI_ENDPROC
21239-END(debug)
21240+ENDPROC(debug)
21241
21242 /*
21243 * NMI is doubly nasty. It can happen _while_ we're handling
21244@@ -1370,6 +1612,9 @@ nmi_stack_correct:
21245 xorl %edx,%edx # zero error code
21246 movl %esp,%eax # pt_regs pointer
21247 call do_nmi
21248+
21249+ pax_exit_kernel
21250+
21251 jmp restore_all_notrace
21252 CFI_ENDPROC
21253
21254@@ -1406,12 +1651,15 @@ nmi_espfix_stack:
21255 FIXUP_ESPFIX_STACK # %eax == %esp
21256 xorl %edx,%edx # zero error code
21257 call do_nmi
21258+
21259+ pax_exit_kernel
21260+
21261 RESTORE_REGS
21262 lss 12+4(%esp), %esp # back to espfix stack
21263 CFI_ADJUST_CFA_OFFSET -24
21264 jmp irq_return
21265 CFI_ENDPROC
21266-END(nmi)
21267+ENDPROC(nmi)
21268
21269 ENTRY(int3)
21270 RING0_INT_FRAME
21271@@ -1424,14 +1672,14 @@ ENTRY(int3)
21272 call do_int3
21273 jmp ret_from_exception
21274 CFI_ENDPROC
21275-END(int3)
21276+ENDPROC(int3)
21277
21278 ENTRY(general_protection)
21279 RING0_EC_FRAME
21280 pushl_cfi $do_general_protection
21281 jmp error_code
21282 CFI_ENDPROC
21283-END(general_protection)
21284+ENDPROC(general_protection)
21285
21286 #ifdef CONFIG_KVM_GUEST
21287 ENTRY(async_page_fault)
21288@@ -1440,7 +1688,7 @@ ENTRY(async_page_fault)
21289 pushl_cfi $do_async_page_fault
21290 jmp error_code
21291 CFI_ENDPROC
21292-END(async_page_fault)
21293+ENDPROC(async_page_fault)
21294 #endif
21295
21296 /*
21297diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
21298index 1b69951..8430a6d 100644
21299--- a/arch/x86/kernel/entry_64.S
21300+++ b/arch/x86/kernel/entry_64.S
21301@@ -59,6 +59,8 @@
21302 #include <asm/context_tracking.h>
21303 #include <asm/smap.h>
21304 #include <linux/err.h>
21305+#include <asm/pgtable.h>
21306+#include <asm/alternative-asm.h>
21307
21308 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
21309 #include <linux/elf-em.h>
21310@@ -80,8 +82,9 @@
21311 #ifdef CONFIG_DYNAMIC_FTRACE
21312
21313 ENTRY(function_hook)
21314+ pax_force_retaddr
21315 retq
21316-END(function_hook)
21317+ENDPROC(function_hook)
21318
21319 /* skip is set if stack has been adjusted */
21320 .macro ftrace_caller_setup skip=0
21321@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
21322 #endif
21323
21324 GLOBAL(ftrace_stub)
21325+ pax_force_retaddr
21326 retq
21327-END(ftrace_caller)
21328+ENDPROC(ftrace_caller)
21329
21330 ENTRY(ftrace_regs_caller)
21331 /* Save the current flags before compare (in SS location)*/
21332@@ -191,7 +195,7 @@ ftrace_restore_flags:
21333 popfq
21334 jmp ftrace_stub
21335
21336-END(ftrace_regs_caller)
21337+ENDPROC(ftrace_regs_caller)
21338
21339
21340 #else /* ! CONFIG_DYNAMIC_FTRACE */
21341@@ -212,6 +216,7 @@ ENTRY(function_hook)
21342 #endif
21343
21344 GLOBAL(ftrace_stub)
21345+ pax_force_retaddr
21346 retq
21347
21348 trace:
21349@@ -225,12 +230,13 @@ trace:
21350 #endif
21351 subq $MCOUNT_INSN_SIZE, %rdi
21352
21353+ pax_force_fptr ftrace_trace_function
21354 call *ftrace_trace_function
21355
21356 MCOUNT_RESTORE_FRAME
21357
21358 jmp ftrace_stub
21359-END(function_hook)
21360+ENDPROC(function_hook)
21361 #endif /* CONFIG_DYNAMIC_FTRACE */
21362 #endif /* CONFIG_FUNCTION_TRACER */
21363
21364@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
21365
21366 MCOUNT_RESTORE_FRAME
21367
21368+ pax_force_retaddr
21369 retq
21370-END(ftrace_graph_caller)
21371+ENDPROC(ftrace_graph_caller)
21372
21373 GLOBAL(return_to_handler)
21374 subq $24, %rsp
21375@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
21376 movq 8(%rsp), %rdx
21377 movq (%rsp), %rax
21378 addq $24, %rsp
21379+ pax_force_fptr %rdi
21380 jmp *%rdi
21381+ENDPROC(return_to_handler)
21382 #endif
21383
21384
21385@@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
21386 ENDPROC(native_usergs_sysret64)
21387 #endif /* CONFIG_PARAVIRT */
21388
21389+ .macro ljmpq sel, off
21390+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
21391+ .byte 0x48; ljmp *1234f(%rip)
21392+ .pushsection .rodata
21393+ .align 16
21394+ 1234: .quad \off; .word \sel
21395+ .popsection
21396+#else
21397+ pushq $\sel
21398+ pushq $\off
21399+ lretq
21400+#endif
21401+ .endm
21402+
21403+ .macro pax_enter_kernel
21404+ pax_set_fptr_mask
21405+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21406+ call pax_enter_kernel
21407+#endif
21408+ .endm
21409+
21410+ .macro pax_exit_kernel
21411+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21412+ call pax_exit_kernel
21413+#endif
21414+
21415+ .endm
21416+
21417+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21418+ENTRY(pax_enter_kernel)
21419+ pushq %rdi
21420+
21421+#ifdef CONFIG_PARAVIRT
21422+ PV_SAVE_REGS(CLBR_RDI)
21423+#endif
21424+
21425+#ifdef CONFIG_PAX_KERNEXEC
21426+ GET_CR0_INTO_RDI
21427+ bts $16,%rdi
21428+ jnc 3f
21429+ mov %cs,%edi
21430+ cmp $__KERNEL_CS,%edi
21431+ jnz 2f
21432+1:
21433+#endif
21434+
21435+#ifdef CONFIG_PAX_MEMORY_UDEREF
21436+ 661: jmp 111f
21437+ .pushsection .altinstr_replacement, "a"
21438+ 662: ASM_NOP2
21439+ .popsection
21440+ .pushsection .altinstructions, "a"
21441+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21442+ .popsection
21443+ GET_CR3_INTO_RDI
21444+ cmp $0,%dil
21445+ jnz 112f
21446+ mov $__KERNEL_DS,%edi
21447+ mov %edi,%ss
21448+ jmp 111f
21449+112: cmp $1,%dil
21450+ jz 113f
21451+ ud2
21452+113: sub $4097,%rdi
21453+ bts $63,%rdi
21454+ SET_RDI_INTO_CR3
21455+ mov $__UDEREF_KERNEL_DS,%edi
21456+ mov %edi,%ss
21457+111:
21458+#endif
21459+
21460+#ifdef CONFIG_PARAVIRT
21461+ PV_RESTORE_REGS(CLBR_RDI)
21462+#endif
21463+
21464+ popq %rdi
21465+ pax_force_retaddr
21466+ retq
21467+
21468+#ifdef CONFIG_PAX_KERNEXEC
21469+2: ljmpq __KERNEL_CS,1b
21470+3: ljmpq __KERNEXEC_KERNEL_CS,4f
21471+4: SET_RDI_INTO_CR0
21472+ jmp 1b
21473+#endif
21474+ENDPROC(pax_enter_kernel)
21475+
21476+ENTRY(pax_exit_kernel)
21477+ pushq %rdi
21478+
21479+#ifdef CONFIG_PARAVIRT
21480+ PV_SAVE_REGS(CLBR_RDI)
21481+#endif
21482+
21483+#ifdef CONFIG_PAX_KERNEXEC
21484+ mov %cs,%rdi
21485+ cmp $__KERNEXEC_KERNEL_CS,%edi
21486+ jz 2f
21487+ GET_CR0_INTO_RDI
21488+ bts $16,%rdi
21489+ jnc 4f
21490+1:
21491+#endif
21492+
21493+#ifdef CONFIG_PAX_MEMORY_UDEREF
21494+ 661: jmp 111f
21495+ .pushsection .altinstr_replacement, "a"
21496+ 662: ASM_NOP2
21497+ .popsection
21498+ .pushsection .altinstructions, "a"
21499+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21500+ .popsection
21501+ mov %ss,%edi
21502+ cmp $__UDEREF_KERNEL_DS,%edi
21503+ jnz 111f
21504+ GET_CR3_INTO_RDI
21505+ cmp $0,%dil
21506+ jz 112f
21507+ ud2
21508+112: add $4097,%rdi
21509+ bts $63,%rdi
21510+ SET_RDI_INTO_CR3
21511+ mov $__KERNEL_DS,%edi
21512+ mov %edi,%ss
21513+111:
21514+#endif
21515+
21516+#ifdef CONFIG_PARAVIRT
21517+ PV_RESTORE_REGS(CLBR_RDI);
21518+#endif
21519+
21520+ popq %rdi
21521+ pax_force_retaddr
21522+ retq
21523+
21524+#ifdef CONFIG_PAX_KERNEXEC
21525+2: GET_CR0_INTO_RDI
21526+ btr $16,%rdi
21527+ jnc 4f
21528+ ljmpq __KERNEL_CS,3f
21529+3: SET_RDI_INTO_CR0
21530+ jmp 1b
21531+4: ud2
21532+ jmp 4b
21533+#endif
21534+ENDPROC(pax_exit_kernel)
21535+#endif
21536+
21537+ .macro pax_enter_kernel_user
21538+ pax_set_fptr_mask
21539+#ifdef CONFIG_PAX_MEMORY_UDEREF
21540+ call pax_enter_kernel_user
21541+#endif
21542+ .endm
21543+
21544+ .macro pax_exit_kernel_user
21545+#ifdef CONFIG_PAX_MEMORY_UDEREF
21546+ call pax_exit_kernel_user
21547+#endif
21548+#ifdef CONFIG_PAX_RANDKSTACK
21549+ pushq %rax
21550+ pushq %r11
21551+ call pax_randomize_kstack
21552+ popq %r11
21553+ popq %rax
21554+#endif
21555+ .endm
21556+
21557+#ifdef CONFIG_PAX_MEMORY_UDEREF
21558+ENTRY(pax_enter_kernel_user)
21559+ pushq %rdi
21560+ pushq %rbx
21561+
21562+#ifdef CONFIG_PARAVIRT
21563+ PV_SAVE_REGS(CLBR_RDI)
21564+#endif
21565+
21566+ 661: jmp 111f
21567+ .pushsection .altinstr_replacement, "a"
21568+ 662: ASM_NOP2
21569+ .popsection
21570+ .pushsection .altinstructions, "a"
21571+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21572+ .popsection
21573+ GET_CR3_INTO_RDI
21574+ cmp $1,%dil
21575+ jnz 4f
21576+ sub $4097,%rdi
21577+ bts $63,%rdi
21578+ SET_RDI_INTO_CR3
21579+ jmp 3f
21580+111:
21581+
21582+ GET_CR3_INTO_RDI
21583+ mov %rdi,%rbx
21584+ add $__START_KERNEL_map,%rbx
21585+ sub phys_base(%rip),%rbx
21586+
21587+#ifdef CONFIG_PARAVIRT
21588+ cmpl $0, pv_info+PARAVIRT_enabled
21589+ jz 1f
21590+ pushq %rdi
21591+ i = 0
21592+ .rept USER_PGD_PTRS
21593+ mov i*8(%rbx),%rsi
21594+ mov $0,%sil
21595+ lea i*8(%rbx),%rdi
21596+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
21597+ i = i + 1
21598+ .endr
21599+ popq %rdi
21600+ jmp 2f
21601+1:
21602+#endif
21603+
21604+ i = 0
21605+ .rept USER_PGD_PTRS
21606+ movb $0,i*8(%rbx)
21607+ i = i + 1
21608+ .endr
21609+
21610+2: SET_RDI_INTO_CR3
21611+
21612+#ifdef CONFIG_PAX_KERNEXEC
21613+ GET_CR0_INTO_RDI
21614+ bts $16,%rdi
21615+ SET_RDI_INTO_CR0
21616+#endif
21617+
21618+3:
21619+
21620+#ifdef CONFIG_PARAVIRT
21621+ PV_RESTORE_REGS(CLBR_RDI)
21622+#endif
21623+
21624+ popq %rbx
21625+ popq %rdi
21626+ pax_force_retaddr
21627+ retq
21628+4: ud2
21629+ENDPROC(pax_enter_kernel_user)
21630+
21631+ENTRY(pax_exit_kernel_user)
21632+ pushq %rdi
21633+ pushq %rbx
21634+
21635+#ifdef CONFIG_PARAVIRT
21636+ PV_SAVE_REGS(CLBR_RDI)
21637+#endif
21638+
21639+ GET_CR3_INTO_RDI
21640+ 661: jmp 1f
21641+ .pushsection .altinstr_replacement, "a"
21642+ 662: ASM_NOP2
21643+ .popsection
21644+ .pushsection .altinstructions, "a"
21645+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21646+ .popsection
21647+ cmp $0,%dil
21648+ jnz 3f
21649+ add $4097,%rdi
21650+ bts $63,%rdi
21651+ SET_RDI_INTO_CR3
21652+ jmp 2f
21653+1:
21654+
21655+ mov %rdi,%rbx
21656+
21657+#ifdef CONFIG_PAX_KERNEXEC
21658+ GET_CR0_INTO_RDI
21659+ btr $16,%rdi
21660+ jnc 3f
21661+ SET_RDI_INTO_CR0
21662+#endif
21663+
21664+ add $__START_KERNEL_map,%rbx
21665+ sub phys_base(%rip),%rbx
21666+
21667+#ifdef CONFIG_PARAVIRT
21668+ cmpl $0, pv_info+PARAVIRT_enabled
21669+ jz 1f
21670+ i = 0
21671+ .rept USER_PGD_PTRS
21672+ mov i*8(%rbx),%rsi
21673+ mov $0x67,%sil
21674+ lea i*8(%rbx),%rdi
21675+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
21676+ i = i + 1
21677+ .endr
21678+ jmp 2f
21679+1:
21680+#endif
21681+
21682+ i = 0
21683+ .rept USER_PGD_PTRS
21684+ movb $0x67,i*8(%rbx)
21685+ i = i + 1
21686+ .endr
21687+2:
21688+
21689+#ifdef CONFIG_PARAVIRT
21690+ PV_RESTORE_REGS(CLBR_RDI)
21691+#endif
21692+
21693+ popq %rbx
21694+ popq %rdi
21695+ pax_force_retaddr
21696+ retq
21697+3: ud2
21698+ENDPROC(pax_exit_kernel_user)
21699+#endif
21700+
21701+ .macro pax_enter_kernel_nmi
21702+ pax_set_fptr_mask
21703+
21704+#ifdef CONFIG_PAX_KERNEXEC
21705+ GET_CR0_INTO_RDI
21706+ bts $16,%rdi
21707+ jc 110f
21708+ SET_RDI_INTO_CR0
21709+ or $2,%ebx
21710+110:
21711+#endif
21712+
21713+#ifdef CONFIG_PAX_MEMORY_UDEREF
21714+ 661: jmp 111f
21715+ .pushsection .altinstr_replacement, "a"
21716+ 662: ASM_NOP2
21717+ .popsection
21718+ .pushsection .altinstructions, "a"
21719+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21720+ .popsection
21721+ GET_CR3_INTO_RDI
21722+ cmp $0,%dil
21723+ jz 111f
21724+ sub $4097,%rdi
21725+ or $4,%ebx
21726+ bts $63,%rdi
21727+ SET_RDI_INTO_CR3
21728+ mov $__UDEREF_KERNEL_DS,%edi
21729+ mov %edi,%ss
21730+111:
21731+#endif
21732+ .endm
21733+
21734+ .macro pax_exit_kernel_nmi
21735+#ifdef CONFIG_PAX_KERNEXEC
21736+ btr $1,%ebx
21737+ jnc 110f
21738+ GET_CR0_INTO_RDI
21739+ btr $16,%rdi
21740+ SET_RDI_INTO_CR0
21741+110:
21742+#endif
21743+
21744+#ifdef CONFIG_PAX_MEMORY_UDEREF
21745+ btr $2,%ebx
21746+ jnc 111f
21747+ GET_CR3_INTO_RDI
21748+ add $4097,%rdi
21749+ bts $63,%rdi
21750+ SET_RDI_INTO_CR3
21751+ mov $__KERNEL_DS,%edi
21752+ mov %edi,%ss
21753+111:
21754+#endif
21755+ .endm
21756+
21757+ .macro pax_erase_kstack
21758+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21759+ call pax_erase_kstack
21760+#endif
21761+ .endm
21762+
21763+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21764+ENTRY(pax_erase_kstack)
21765+ pushq %rdi
21766+ pushq %rcx
21767+ pushq %rax
21768+ pushq %r11
21769+
21770+ GET_THREAD_INFO(%r11)
21771+ mov TI_lowest_stack(%r11), %rdi
21772+ mov $-0xBEEF, %rax
21773+ std
21774+
21775+1: mov %edi, %ecx
21776+ and $THREAD_SIZE_asm - 1, %ecx
21777+ shr $3, %ecx
21778+ repne scasq
21779+ jecxz 2f
21780+
21781+ cmp $2*8, %ecx
21782+ jc 2f
21783+
21784+ mov $2*8, %ecx
21785+ repe scasq
21786+ jecxz 2f
21787+ jne 1b
21788+
21789+2: cld
21790+ mov %esp, %ecx
21791+ sub %edi, %ecx
21792+
21793+ cmp $THREAD_SIZE_asm, %rcx
21794+ jb 3f
21795+ ud2
21796+3:
21797+
21798+ shr $3, %ecx
21799+ rep stosq
21800+
21801+ mov TI_task_thread_sp0(%r11), %rdi
21802+ sub $256, %rdi
21803+ mov %rdi, TI_lowest_stack(%r11)
21804+
21805+ popq %r11
21806+ popq %rax
21807+ popq %rcx
21808+ popq %rdi
21809+ pax_force_retaddr
21810+ ret
21811+ENDPROC(pax_erase_kstack)
21812+#endif
21813
21814 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
21815 #ifdef CONFIG_TRACE_IRQFLAGS
21816@@ -375,8 +808,8 @@ ENDPROC(native_usergs_sysret64)
21817 .endm
21818
21819 .macro UNFAKE_STACK_FRAME
21820- addq $8*6, %rsp
21821- CFI_ADJUST_CFA_OFFSET -(6*8)
21822+ addq $8*6 + ARG_SKIP, %rsp
21823+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
21824 .endm
21825
21826 /*
21827@@ -463,7 +896,7 @@ ENDPROC(native_usergs_sysret64)
21828 movq %rsp, %rsi
21829
21830 leaq -RBP(%rsp),%rdi /* arg1 for handler */
21831- testl $3, CS-RBP(%rsi)
21832+ testb $3, CS-RBP(%rsi)
21833 je 1f
21834 SWAPGS
21835 /*
21836@@ -498,9 +931,10 @@ ENTRY(save_rest)
21837 movq_cfi r15, R15+16
21838 movq %r11, 8(%rsp) /* return address */
21839 FIXUP_TOP_OF_STACK %r11, 16
21840+ pax_force_retaddr
21841 ret
21842 CFI_ENDPROC
21843-END(save_rest)
21844+ENDPROC(save_rest)
21845
21846 /* save complete stack frame */
21847 .pushsection .kprobes.text, "ax"
21848@@ -529,9 +963,10 @@ ENTRY(save_paranoid)
21849 js 1f /* negative -> in kernel */
21850 SWAPGS
21851 xorl %ebx,%ebx
21852-1: ret
21853+1: pax_force_retaddr_bts
21854+ ret
21855 CFI_ENDPROC
21856-END(save_paranoid)
21857+ENDPROC(save_paranoid)
21858 .popsection
21859
21860 /*
21861@@ -553,7 +988,7 @@ ENTRY(ret_from_fork)
21862
21863 RESTORE_REST
21864
21865- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
21866+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
21867 jz 1f
21868
21869 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
21870@@ -571,7 +1006,7 @@ ENTRY(ret_from_fork)
21871 RESTORE_REST
21872 jmp int_ret_from_sys_call
21873 CFI_ENDPROC
21874-END(ret_from_fork)
21875+ENDPROC(ret_from_fork)
21876
21877 /*
21878 * System call entry. Up to 6 arguments in registers are supported.
21879@@ -608,7 +1043,7 @@ END(ret_from_fork)
21880 ENTRY(system_call)
21881 CFI_STARTPROC simple
21882 CFI_SIGNAL_FRAME
21883- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
21884+ CFI_DEF_CFA rsp,0
21885 CFI_REGISTER rip,rcx
21886 /*CFI_REGISTER rflags,r11*/
21887 SWAPGS_UNSAFE_STACK
21888@@ -621,16 +1056,23 @@ GLOBAL(system_call_after_swapgs)
21889
21890 movq %rsp,PER_CPU_VAR(old_rsp)
21891 movq PER_CPU_VAR(kernel_stack),%rsp
21892+ SAVE_ARGS 8*6,0
21893+ pax_enter_kernel_user
21894+
21895+#ifdef CONFIG_PAX_RANDKSTACK
21896+ pax_erase_kstack
21897+#endif
21898+
21899 /*
21900 * No need to follow this irqs off/on section - it's straight
21901 * and short:
21902 */
21903 ENABLE_INTERRUPTS(CLBR_NONE)
21904- SAVE_ARGS 8,0
21905 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
21906 movq %rcx,RIP-ARGOFFSET(%rsp)
21907 CFI_REL_OFFSET rip,RIP-ARGOFFSET
21908- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
21909+ GET_THREAD_INFO(%rcx)
21910+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
21911 jnz tracesys
21912 system_call_fastpath:
21913 #if __SYSCALL_MASK == ~0
21914@@ -640,7 +1082,7 @@ system_call_fastpath:
21915 cmpl $__NR_syscall_max,%eax
21916 #endif
21917 ja badsys
21918- movq %r10,%rcx
21919+ movq R10-ARGOFFSET(%rsp),%rcx
21920 call *sys_call_table(,%rax,8) # XXX: rip relative
21921 movq %rax,RAX-ARGOFFSET(%rsp)
21922 /*
21923@@ -654,10 +1096,13 @@ sysret_check:
21924 LOCKDEP_SYS_EXIT
21925 DISABLE_INTERRUPTS(CLBR_NONE)
21926 TRACE_IRQS_OFF
21927- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
21928+ GET_THREAD_INFO(%rcx)
21929+ movl TI_flags(%rcx),%edx
21930 andl %edi,%edx
21931 jnz sysret_careful
21932 CFI_REMEMBER_STATE
21933+ pax_exit_kernel_user
21934+ pax_erase_kstack
21935 /*
21936 * sysretq will re-enable interrupts:
21937 */
21938@@ -709,14 +1154,18 @@ badsys:
21939 * jump back to the normal fast path.
21940 */
21941 auditsys:
21942- movq %r10,%r9 /* 6th arg: 4th syscall arg */
21943+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
21944 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
21945 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
21946 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
21947 movq %rax,%rsi /* 2nd arg: syscall number */
21948 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
21949 call __audit_syscall_entry
21950+
21951+ pax_erase_kstack
21952+
21953 LOAD_ARGS 0 /* reload call-clobbered registers */
21954+ pax_set_fptr_mask
21955 jmp system_call_fastpath
21956
21957 /*
21958@@ -737,7 +1186,7 @@ sysret_audit:
21959 /* Do syscall tracing */
21960 tracesys:
21961 #ifdef CONFIG_AUDITSYSCALL
21962- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
21963+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
21964 jz auditsys
21965 #endif
21966 SAVE_REST
21967@@ -745,12 +1194,16 @@ tracesys:
21968 FIXUP_TOP_OF_STACK %rdi
21969 movq %rsp,%rdi
21970 call syscall_trace_enter
21971+
21972+ pax_erase_kstack
21973+
21974 /*
21975 * Reload arg registers from stack in case ptrace changed them.
21976 * We don't reload %rax because syscall_trace_enter() returned
21977 * the value it wants us to use in the table lookup.
21978 */
21979 LOAD_ARGS ARGOFFSET, 1
21980+ pax_set_fptr_mask
21981 RESTORE_REST
21982 #if __SYSCALL_MASK == ~0
21983 cmpq $__NR_syscall_max,%rax
21984@@ -759,7 +1212,7 @@ tracesys:
21985 cmpl $__NR_syscall_max,%eax
21986 #endif
21987 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
21988- movq %r10,%rcx /* fixup for C */
21989+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
21990 call *sys_call_table(,%rax,8)
21991 movq %rax,RAX-ARGOFFSET(%rsp)
21992 /* Use IRET because user could have changed frame */
21993@@ -780,7 +1233,9 @@ GLOBAL(int_with_check)
21994 andl %edi,%edx
21995 jnz int_careful
21996 andl $~TS_COMPAT,TI_status(%rcx)
21997- jmp retint_swapgs
21998+ pax_exit_kernel_user
21999+ pax_erase_kstack
22000+ jmp retint_swapgs_pax
22001
22002 /* Either reschedule or signal or syscall exit tracking needed. */
22003 /* First do a reschedule test. */
22004@@ -826,7 +1281,7 @@ int_restore_rest:
22005 TRACE_IRQS_OFF
22006 jmp int_with_check
22007 CFI_ENDPROC
22008-END(system_call)
22009+ENDPROC(system_call)
22010
22011 .macro FORK_LIKE func
22012 ENTRY(stub_\func)
22013@@ -839,9 +1294,10 @@ ENTRY(stub_\func)
22014 DEFAULT_FRAME 0 8 /* offset 8: return address */
22015 call sys_\func
22016 RESTORE_TOP_OF_STACK %r11, 8
22017+ pax_force_retaddr
22018 ret $REST_SKIP /* pop extended registers */
22019 CFI_ENDPROC
22020-END(stub_\func)
22021+ENDPROC(stub_\func)
22022 .endm
22023
22024 .macro FIXED_FRAME label,func
22025@@ -851,9 +1307,10 @@ ENTRY(\label)
22026 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
22027 call \func
22028 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
22029+ pax_force_retaddr
22030 ret
22031 CFI_ENDPROC
22032-END(\label)
22033+ENDPROC(\label)
22034 .endm
22035
22036 FORK_LIKE clone
22037@@ -870,9 +1327,10 @@ ENTRY(ptregscall_common)
22038 movq_cfi_restore R12+8, r12
22039 movq_cfi_restore RBP+8, rbp
22040 movq_cfi_restore RBX+8, rbx
22041+ pax_force_retaddr
22042 ret $REST_SKIP /* pop extended registers */
22043 CFI_ENDPROC
22044-END(ptregscall_common)
22045+ENDPROC(ptregscall_common)
22046
22047 ENTRY(stub_execve)
22048 CFI_STARTPROC
22049@@ -885,7 +1343,7 @@ ENTRY(stub_execve)
22050 RESTORE_REST
22051 jmp int_ret_from_sys_call
22052 CFI_ENDPROC
22053-END(stub_execve)
22054+ENDPROC(stub_execve)
22055
22056 /*
22057 * sigreturn is special because it needs to restore all registers on return.
22058@@ -902,7 +1360,7 @@ ENTRY(stub_rt_sigreturn)
22059 RESTORE_REST
22060 jmp int_ret_from_sys_call
22061 CFI_ENDPROC
22062-END(stub_rt_sigreturn)
22063+ENDPROC(stub_rt_sigreturn)
22064
22065 #ifdef CONFIG_X86_X32_ABI
22066 ENTRY(stub_x32_rt_sigreturn)
22067@@ -916,7 +1374,7 @@ ENTRY(stub_x32_rt_sigreturn)
22068 RESTORE_REST
22069 jmp int_ret_from_sys_call
22070 CFI_ENDPROC
22071-END(stub_x32_rt_sigreturn)
22072+ENDPROC(stub_x32_rt_sigreturn)
22073
22074 ENTRY(stub_x32_execve)
22075 CFI_STARTPROC
22076@@ -930,7 +1388,7 @@ ENTRY(stub_x32_execve)
22077 RESTORE_REST
22078 jmp int_ret_from_sys_call
22079 CFI_ENDPROC
22080-END(stub_x32_execve)
22081+ENDPROC(stub_x32_execve)
22082
22083 #endif
22084
22085@@ -967,7 +1425,7 @@ vector=vector+1
22086 2: jmp common_interrupt
22087 .endr
22088 CFI_ENDPROC
22089-END(irq_entries_start)
22090+ENDPROC(irq_entries_start)
22091
22092 .previous
22093 END(interrupt)
22094@@ -987,6 +1445,16 @@ END(interrupt)
22095 subq $ORIG_RAX-RBP, %rsp
22096 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
22097 SAVE_ARGS_IRQ
22098+#ifdef CONFIG_PAX_MEMORY_UDEREF
22099+ testb $3, CS(%rdi)
22100+ jnz 1f
22101+ pax_enter_kernel
22102+ jmp 2f
22103+1: pax_enter_kernel_user
22104+2:
22105+#else
22106+ pax_enter_kernel
22107+#endif
22108 call \func
22109 .endm
22110
22111@@ -1019,7 +1487,7 @@ ret_from_intr:
22112
22113 exit_intr:
22114 GET_THREAD_INFO(%rcx)
22115- testl $3,CS-ARGOFFSET(%rsp)
22116+ testb $3,CS-ARGOFFSET(%rsp)
22117 je retint_kernel
22118
22119 /* Interrupt came from user space */
22120@@ -1041,12 +1509,16 @@ retint_swapgs: /* return to user-space */
22121 * The iretq could re-enable interrupts:
22122 */
22123 DISABLE_INTERRUPTS(CLBR_ANY)
22124+ pax_exit_kernel_user
22125+retint_swapgs_pax:
22126 TRACE_IRQS_IRETQ
22127 SWAPGS
22128 jmp restore_args
22129
22130 retint_restore_args: /* return to kernel space */
22131 DISABLE_INTERRUPTS(CLBR_ANY)
22132+ pax_exit_kernel
22133+ pax_force_retaddr (RIP-ARGOFFSET)
22134 /*
22135 * The iretq could re-enable interrupts:
22136 */
22137@@ -1129,7 +1601,7 @@ ENTRY(retint_kernel)
22138 #endif
22139
22140 CFI_ENDPROC
22141-END(common_interrupt)
22142+ENDPROC(common_interrupt)
22143 /*
22144 * End of kprobes section
22145 */
22146@@ -1147,7 +1619,7 @@ ENTRY(\sym)
22147 interrupt \do_sym
22148 jmp ret_from_intr
22149 CFI_ENDPROC
22150-END(\sym)
22151+ENDPROC(\sym)
22152 .endm
22153
22154 #ifdef CONFIG_TRACING
22155@@ -1230,12 +1702,22 @@ ENTRY(\sym)
22156 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22157 call error_entry
22158 DEFAULT_FRAME 0
22159+#ifdef CONFIG_PAX_MEMORY_UDEREF
22160+ testb $3, CS(%rsp)
22161+ jnz 1f
22162+ pax_enter_kernel
22163+ jmp 2f
22164+1: pax_enter_kernel_user
22165+2:
22166+#else
22167+ pax_enter_kernel
22168+#endif
22169 movq %rsp,%rdi /* pt_regs pointer */
22170 xorl %esi,%esi /* no error code */
22171 call \do_sym
22172 jmp error_exit /* %ebx: no swapgs flag */
22173 CFI_ENDPROC
22174-END(\sym)
22175+ENDPROC(\sym)
22176 .endm
22177
22178 .macro paranoidzeroentry sym do_sym
22179@@ -1248,15 +1730,25 @@ ENTRY(\sym)
22180 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22181 call save_paranoid
22182 TRACE_IRQS_OFF
22183+#ifdef CONFIG_PAX_MEMORY_UDEREF
22184+ testb $3, CS(%rsp)
22185+ jnz 1f
22186+ pax_enter_kernel
22187+ jmp 2f
22188+1: pax_enter_kernel_user
22189+2:
22190+#else
22191+ pax_enter_kernel
22192+#endif
22193 movq %rsp,%rdi /* pt_regs pointer */
22194 xorl %esi,%esi /* no error code */
22195 call \do_sym
22196 jmp paranoid_exit /* %ebx: no swapgs flag */
22197 CFI_ENDPROC
22198-END(\sym)
22199+ENDPROC(\sym)
22200 .endm
22201
22202-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
22203+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
22204 .macro paranoidzeroentry_ist sym do_sym ist
22205 ENTRY(\sym)
22206 INTR_FRAME
22207@@ -1267,14 +1759,30 @@ ENTRY(\sym)
22208 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22209 call save_paranoid
22210 TRACE_IRQS_OFF_DEBUG
22211+#ifdef CONFIG_PAX_MEMORY_UDEREF
22212+ testb $3, CS(%rsp)
22213+ jnz 1f
22214+ pax_enter_kernel
22215+ jmp 2f
22216+1: pax_enter_kernel_user
22217+2:
22218+#else
22219+ pax_enter_kernel
22220+#endif
22221 movq %rsp,%rdi /* pt_regs pointer */
22222 xorl %esi,%esi /* no error code */
22223+#ifdef CONFIG_SMP
22224+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
22225+ lea init_tss(%r12), %r12
22226+#else
22227+ lea init_tss(%rip), %r12
22228+#endif
22229 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
22230 call \do_sym
22231 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
22232 jmp paranoid_exit /* %ebx: no swapgs flag */
22233 CFI_ENDPROC
22234-END(\sym)
22235+ENDPROC(\sym)
22236 .endm
22237
22238 .macro errorentry sym do_sym
22239@@ -1286,13 +1794,23 @@ ENTRY(\sym)
22240 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22241 call error_entry
22242 DEFAULT_FRAME 0
22243+#ifdef CONFIG_PAX_MEMORY_UDEREF
22244+ testb $3, CS(%rsp)
22245+ jnz 1f
22246+ pax_enter_kernel
22247+ jmp 2f
22248+1: pax_enter_kernel_user
22249+2:
22250+#else
22251+ pax_enter_kernel
22252+#endif
22253 movq %rsp,%rdi /* pt_regs pointer */
22254 movq ORIG_RAX(%rsp),%rsi /* get error code */
22255 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
22256 call \do_sym
22257 jmp error_exit /* %ebx: no swapgs flag */
22258 CFI_ENDPROC
22259-END(\sym)
22260+ENDPROC(\sym)
22261 .endm
22262
22263 /* error code is on the stack already */
22264@@ -1306,13 +1824,23 @@ ENTRY(\sym)
22265 call save_paranoid
22266 DEFAULT_FRAME 0
22267 TRACE_IRQS_OFF
22268+#ifdef CONFIG_PAX_MEMORY_UDEREF
22269+ testb $3, CS(%rsp)
22270+ jnz 1f
22271+ pax_enter_kernel
22272+ jmp 2f
22273+1: pax_enter_kernel_user
22274+2:
22275+#else
22276+ pax_enter_kernel
22277+#endif
22278 movq %rsp,%rdi /* pt_regs pointer */
22279 movq ORIG_RAX(%rsp),%rsi /* get error code */
22280 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
22281 call \do_sym
22282 jmp paranoid_exit /* %ebx: no swapgs flag */
22283 CFI_ENDPROC
22284-END(\sym)
22285+ENDPROC(\sym)
22286 .endm
22287
22288 zeroentry divide_error do_divide_error
22289@@ -1342,9 +1870,10 @@ gs_change:
22290 2: mfence /* workaround */
22291 SWAPGS
22292 popfq_cfi
22293+ pax_force_retaddr
22294 ret
22295 CFI_ENDPROC
22296-END(native_load_gs_index)
22297+ENDPROC(native_load_gs_index)
22298
22299 _ASM_EXTABLE(gs_change,bad_gs)
22300 .section .fixup,"ax"
22301@@ -1372,9 +1901,10 @@ ENTRY(call_softirq)
22302 CFI_DEF_CFA_REGISTER rsp
22303 CFI_ADJUST_CFA_OFFSET -8
22304 decl PER_CPU_VAR(irq_count)
22305+ pax_force_retaddr
22306 ret
22307 CFI_ENDPROC
22308-END(call_softirq)
22309+ENDPROC(call_softirq)
22310
22311 #ifdef CONFIG_XEN
22312 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
22313@@ -1412,7 +1942,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
22314 decl PER_CPU_VAR(irq_count)
22315 jmp error_exit
22316 CFI_ENDPROC
22317-END(xen_do_hypervisor_callback)
22318+ENDPROC(xen_do_hypervisor_callback)
22319
22320 /*
22321 * Hypervisor uses this for application faults while it executes.
22322@@ -1471,7 +2001,7 @@ ENTRY(xen_failsafe_callback)
22323 SAVE_ALL
22324 jmp error_exit
22325 CFI_ENDPROC
22326-END(xen_failsafe_callback)
22327+ENDPROC(xen_failsafe_callback)
22328
22329 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
22330 xen_hvm_callback_vector xen_evtchn_do_upcall
22331@@ -1523,18 +2053,33 @@ ENTRY(paranoid_exit)
22332 DEFAULT_FRAME
22333 DISABLE_INTERRUPTS(CLBR_NONE)
22334 TRACE_IRQS_OFF_DEBUG
22335- testl %ebx,%ebx /* swapgs needed? */
22336+ testl $1,%ebx /* swapgs needed? */
22337 jnz paranoid_restore
22338- testl $3,CS(%rsp)
22339+ testb $3,CS(%rsp)
22340 jnz paranoid_userspace
22341+#ifdef CONFIG_PAX_MEMORY_UDEREF
22342+ pax_exit_kernel
22343+ TRACE_IRQS_IRETQ 0
22344+ SWAPGS_UNSAFE_STACK
22345+ RESTORE_ALL 8
22346+ pax_force_retaddr_bts
22347+ jmp irq_return
22348+#endif
22349 paranoid_swapgs:
22350+#ifdef CONFIG_PAX_MEMORY_UDEREF
22351+ pax_exit_kernel_user
22352+#else
22353+ pax_exit_kernel
22354+#endif
22355 TRACE_IRQS_IRETQ 0
22356 SWAPGS_UNSAFE_STACK
22357 RESTORE_ALL 8
22358 jmp irq_return
22359 paranoid_restore:
22360+ pax_exit_kernel
22361 TRACE_IRQS_IRETQ_DEBUG 0
22362 RESTORE_ALL 8
22363+ pax_force_retaddr_bts
22364 jmp irq_return
22365 paranoid_userspace:
22366 GET_THREAD_INFO(%rcx)
22367@@ -1563,7 +2108,7 @@ paranoid_schedule:
22368 TRACE_IRQS_OFF
22369 jmp paranoid_userspace
22370 CFI_ENDPROC
22371-END(paranoid_exit)
22372+ENDPROC(paranoid_exit)
22373
22374 /*
22375 * Exception entry point. This expects an error code/orig_rax on the stack.
22376@@ -1590,12 +2135,13 @@ ENTRY(error_entry)
22377 movq_cfi r14, R14+8
22378 movq_cfi r15, R15+8
22379 xorl %ebx,%ebx
22380- testl $3,CS+8(%rsp)
22381+ testb $3,CS+8(%rsp)
22382 je error_kernelspace
22383 error_swapgs:
22384 SWAPGS
22385 error_sti:
22386 TRACE_IRQS_OFF
22387+ pax_force_retaddr_bts
22388 ret
22389
22390 /*
22391@@ -1622,7 +2168,7 @@ bstep_iret:
22392 movq %rcx,RIP+8(%rsp)
22393 jmp error_swapgs
22394 CFI_ENDPROC
22395-END(error_entry)
22396+ENDPROC(error_entry)
22397
22398
22399 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
22400@@ -1633,7 +2179,7 @@ ENTRY(error_exit)
22401 DISABLE_INTERRUPTS(CLBR_NONE)
22402 TRACE_IRQS_OFF
22403 GET_THREAD_INFO(%rcx)
22404- testl %eax,%eax
22405+ testl $1,%eax
22406 jne retint_kernel
22407 LOCKDEP_SYS_EXIT_IRQ
22408 movl TI_flags(%rcx),%edx
22409@@ -1642,7 +2188,7 @@ ENTRY(error_exit)
22410 jnz retint_careful
22411 jmp retint_swapgs
22412 CFI_ENDPROC
22413-END(error_exit)
22414+ENDPROC(error_exit)
22415
22416 /*
22417 * Test if a given stack is an NMI stack or not.
22418@@ -1700,9 +2246,11 @@ ENTRY(nmi)
22419 * If %cs was not the kernel segment, then the NMI triggered in user
22420 * space, which means it is definitely not nested.
22421 */
22422+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
22423+ je 1f
22424 cmpl $__KERNEL_CS, 16(%rsp)
22425 jne first_nmi
22426-
22427+1:
22428 /*
22429 * Check the special variable on the stack to see if NMIs are
22430 * executing.
22431@@ -1736,8 +2284,7 @@ nested_nmi:
22432
22433 1:
22434 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
22435- leaq -1*8(%rsp), %rdx
22436- movq %rdx, %rsp
22437+ subq $8, %rsp
22438 CFI_ADJUST_CFA_OFFSET 1*8
22439 leaq -10*8(%rsp), %rdx
22440 pushq_cfi $__KERNEL_DS
22441@@ -1755,6 +2302,7 @@ nested_nmi_out:
22442 CFI_RESTORE rdx
22443
22444 /* No need to check faults here */
22445+# pax_force_retaddr_bts
22446 INTERRUPT_RETURN
22447
22448 CFI_RESTORE_STATE
22449@@ -1871,6 +2419,8 @@ end_repeat_nmi:
22450 */
22451 movq %cr2, %r12
22452
22453+ pax_enter_kernel_nmi
22454+
22455 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
22456 movq %rsp,%rdi
22457 movq $-1,%rsi
22458@@ -1883,26 +2433,31 @@ end_repeat_nmi:
22459 movq %r12, %cr2
22460 1:
22461
22462- testl %ebx,%ebx /* swapgs needed? */
22463+ testl $1,%ebx /* swapgs needed? */
22464 jnz nmi_restore
22465 nmi_swapgs:
22466 SWAPGS_UNSAFE_STACK
22467 nmi_restore:
22468+ pax_exit_kernel_nmi
22469 /* Pop the extra iret frame at once */
22470 RESTORE_ALL 6*8
22471+ testb $3, 8(%rsp)
22472+ jnz 1f
22473+ pax_force_retaddr_bts
22474+1:
22475
22476 /* Clear the NMI executing stack variable */
22477 movq $0, 5*8(%rsp)
22478 jmp irq_return
22479 CFI_ENDPROC
22480-END(nmi)
22481+ENDPROC(nmi)
22482
22483 ENTRY(ignore_sysret)
22484 CFI_STARTPROC
22485 mov $-ENOSYS,%eax
22486 sysret
22487 CFI_ENDPROC
22488-END(ignore_sysret)
22489+ENDPROC(ignore_sysret)
22490
22491 /*
22492 * End of kprobes section
22493diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
22494index 42a392a..fbbd930 100644
22495--- a/arch/x86/kernel/ftrace.c
22496+++ b/arch/x86/kernel/ftrace.c
22497@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
22498 {
22499 unsigned char replaced[MCOUNT_INSN_SIZE];
22500
22501+ ip = ktla_ktva(ip);
22502+
22503 /*
22504 * Note: Due to modules and __init, code can
22505 * disappear and change, we need to protect against faulting
22506@@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
22507 unsigned char old[MCOUNT_INSN_SIZE], *new;
22508 int ret;
22509
22510- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
22511+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
22512 new = ftrace_call_replace(ip, (unsigned long)func);
22513
22514 /* See comment above by declaration of modifying_ftrace_code */
22515@@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
22516 /* Also update the regs callback function */
22517 if (!ret) {
22518 ip = (unsigned long)(&ftrace_regs_call);
22519- memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
22520+ memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
22521 new = ftrace_call_replace(ip, (unsigned long)func);
22522 ret = ftrace_modify_code(ip, old, new);
22523 }
22524@@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
22525 * kernel identity mapping to modify code.
22526 */
22527 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
22528- ip = (unsigned long)__va(__pa_symbol(ip));
22529+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
22530
22531 return probe_kernel_write((void *)ip, val, size);
22532 }
22533@@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
22534 unsigned char replaced[MCOUNT_INSN_SIZE];
22535 unsigned char brk = BREAKPOINT_INSTRUCTION;
22536
22537- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
22538+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
22539 return -EFAULT;
22540
22541 /* Make sure it is what we expect it to be */
22542@@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
22543 return ret;
22544
22545 fail_update:
22546- probe_kernel_write((void *)ip, &old_code[0], 1);
22547+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
22548 goto out;
22549 }
22550
22551@@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
22552 {
22553 unsigned char code[MCOUNT_INSN_SIZE];
22554
22555+ ip = ktla_ktva(ip);
22556+
22557 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
22558 return -EFAULT;
22559
22560diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
22561index 55b6761..a6456fc 100644
22562--- a/arch/x86/kernel/head64.c
22563+++ b/arch/x86/kernel/head64.c
22564@@ -67,12 +67,12 @@ again:
22565 pgd = *pgd_p;
22566
22567 /*
22568- * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
22569- * critical -- __PAGE_OFFSET would point us back into the dynamic
22570+ * The use of __early_va rather than __va here is critical:
22571+ * __va would point us back into the dynamic
22572 * range and we might end up looping forever...
22573 */
22574 if (pgd)
22575- pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
22576+ pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
22577 else {
22578 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
22579 reset_early_page_tables();
22580@@ -82,13 +82,13 @@ again:
22581 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
22582 for (i = 0; i < PTRS_PER_PUD; i++)
22583 pud_p[i] = 0;
22584- *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
22585+ *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
22586 }
22587 pud_p += pud_index(address);
22588 pud = *pud_p;
22589
22590 if (pud)
22591- pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
22592+ pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
22593 else {
22594 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
22595 reset_early_page_tables();
22596@@ -98,7 +98,7 @@ again:
22597 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
22598 for (i = 0; i < PTRS_PER_PMD; i++)
22599 pmd_p[i] = 0;
22600- *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
22601+ *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
22602 }
22603 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
22604 pmd_p[pmd_index(address)] = pmd;
22605@@ -175,7 +175,6 @@ void __init x86_64_start_kernel(char * real_mode_data)
22606 if (console_loglevel == 10)
22607 early_printk("Kernel alive\n");
22608
22609- clear_page(init_level4_pgt);
22610 /* set init_level4_pgt kernel high mapping*/
22611 init_level4_pgt[511] = early_level4_pgt[511];
22612
22613diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
22614index 5dd87a8..d68b3f4 100644
22615--- a/arch/x86/kernel/head_32.S
22616+++ b/arch/x86/kernel/head_32.S
22617@@ -26,6 +26,12 @@
22618 /* Physical address */
22619 #define pa(X) ((X) - __PAGE_OFFSET)
22620
22621+#ifdef CONFIG_PAX_KERNEXEC
22622+#define ta(X) (X)
22623+#else
22624+#define ta(X) ((X) - __PAGE_OFFSET)
22625+#endif
22626+
22627 /*
22628 * References to members of the new_cpu_data structure.
22629 */
22630@@ -55,11 +61,7 @@
22631 * and small than max_low_pfn, otherwise will waste some page table entries
22632 */
22633
22634-#if PTRS_PER_PMD > 1
22635-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
22636-#else
22637-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
22638-#endif
22639+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
22640
22641 /* Number of possible pages in the lowmem region */
22642 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
22643@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
22644 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
22645
22646 /*
22647+ * Real beginning of normal "text" segment
22648+ */
22649+ENTRY(stext)
22650+ENTRY(_stext)
22651+
22652+/*
22653 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
22654 * %esi points to the real-mode code as a 32-bit pointer.
22655 * CS and DS must be 4 GB flat segments, but we don't depend on
22656@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
22657 * can.
22658 */
22659 __HEAD
22660+
22661+#ifdef CONFIG_PAX_KERNEXEC
22662+ jmp startup_32
22663+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
22664+.fill PAGE_SIZE-5,1,0xcc
22665+#endif
22666+
22667 ENTRY(startup_32)
22668 movl pa(stack_start),%ecx
22669
22670@@ -106,6 +121,59 @@ ENTRY(startup_32)
22671 2:
22672 leal -__PAGE_OFFSET(%ecx),%esp
22673
22674+#ifdef CONFIG_SMP
22675+ movl $pa(cpu_gdt_table),%edi
22676+ movl $__per_cpu_load,%eax
22677+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
22678+ rorl $16,%eax
22679+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
22680+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
22681+ movl $__per_cpu_end - 1,%eax
22682+ subl $__per_cpu_start,%eax
22683+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
22684+#endif
22685+
22686+#ifdef CONFIG_PAX_MEMORY_UDEREF
22687+ movl $NR_CPUS,%ecx
22688+ movl $pa(cpu_gdt_table),%edi
22689+1:
22690+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
22691+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
22692+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
22693+ addl $PAGE_SIZE_asm,%edi
22694+ loop 1b
22695+#endif
22696+
22697+#ifdef CONFIG_PAX_KERNEXEC
22698+ movl $pa(boot_gdt),%edi
22699+ movl $__LOAD_PHYSICAL_ADDR,%eax
22700+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
22701+ rorl $16,%eax
22702+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
22703+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
22704+ rorl $16,%eax
22705+
22706+ ljmp $(__BOOT_CS),$1f
22707+1:
22708+
22709+ movl $NR_CPUS,%ecx
22710+ movl $pa(cpu_gdt_table),%edi
22711+ addl $__PAGE_OFFSET,%eax
22712+1:
22713+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
22714+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
22715+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
22716+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
22717+ rorl $16,%eax
22718+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
22719+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
22720+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
22721+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
22722+ rorl $16,%eax
22723+ addl $PAGE_SIZE_asm,%edi
22724+ loop 1b
22725+#endif
22726+
22727 /*
22728 * Clear BSS first so that there are no surprises...
22729 */
22730@@ -201,8 +269,11 @@ ENTRY(startup_32)
22731 movl %eax, pa(max_pfn_mapped)
22732
22733 /* Do early initialization of the fixmap area */
22734- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
22735- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
22736+#ifdef CONFIG_COMPAT_VDSO
22737+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
22738+#else
22739+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
22740+#endif
22741 #else /* Not PAE */
22742
22743 page_pde_offset = (__PAGE_OFFSET >> 20);
22744@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
22745 movl %eax, pa(max_pfn_mapped)
22746
22747 /* Do early initialization of the fixmap area */
22748- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
22749- movl %eax,pa(initial_page_table+0xffc)
22750+#ifdef CONFIG_COMPAT_VDSO
22751+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
22752+#else
22753+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
22754+#endif
22755 #endif
22756
22757 #ifdef CONFIG_PARAVIRT
22758@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
22759 cmpl $num_subarch_entries, %eax
22760 jae bad_subarch
22761
22762- movl pa(subarch_entries)(,%eax,4), %eax
22763- subl $__PAGE_OFFSET, %eax
22764- jmp *%eax
22765+ jmp *pa(subarch_entries)(,%eax,4)
22766
22767 bad_subarch:
22768 WEAK(lguest_entry)
22769@@ -261,10 +333,10 @@ WEAK(xen_entry)
22770 __INITDATA
22771
22772 subarch_entries:
22773- .long default_entry /* normal x86/PC */
22774- .long lguest_entry /* lguest hypervisor */
22775- .long xen_entry /* Xen hypervisor */
22776- .long default_entry /* Moorestown MID */
22777+ .long ta(default_entry) /* normal x86/PC */
22778+ .long ta(lguest_entry) /* lguest hypervisor */
22779+ .long ta(xen_entry) /* Xen hypervisor */
22780+ .long ta(default_entry) /* Moorestown MID */
22781 num_subarch_entries = (. - subarch_entries) / 4
22782 .previous
22783 #else
22784@@ -354,6 +426,7 @@ default_entry:
22785 movl pa(mmu_cr4_features),%eax
22786 movl %eax,%cr4
22787
22788+#ifdef CONFIG_X86_PAE
22789 testb $X86_CR4_PAE, %al # check if PAE is enabled
22790 jz enable_paging
22791
22792@@ -382,6 +455,9 @@ default_entry:
22793 /* Make changes effective */
22794 wrmsr
22795
22796+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
22797+#endif
22798+
22799 enable_paging:
22800
22801 /*
22802@@ -449,14 +525,20 @@ is486:
22803 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
22804 movl %eax,%ss # after changing gdt.
22805
22806- movl $(__USER_DS),%eax # DS/ES contains default USER segment
22807+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
22808 movl %eax,%ds
22809 movl %eax,%es
22810
22811 movl $(__KERNEL_PERCPU), %eax
22812 movl %eax,%fs # set this cpu's percpu
22813
22814+#ifdef CONFIG_CC_STACKPROTECTOR
22815 movl $(__KERNEL_STACK_CANARY),%eax
22816+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
22817+ movl $(__USER_DS),%eax
22818+#else
22819+ xorl %eax,%eax
22820+#endif
22821 movl %eax,%gs
22822
22823 xorl %eax,%eax # Clear LDT
22824@@ -512,8 +594,11 @@ setup_once:
22825 * relocation. Manually set base address in stack canary
22826 * segment descriptor.
22827 */
22828- movl $gdt_page,%eax
22829+ movl $cpu_gdt_table,%eax
22830 movl $stack_canary,%ecx
22831+#ifdef CONFIG_SMP
22832+ addl $__per_cpu_load,%ecx
22833+#endif
22834 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
22835 shrl $16, %ecx
22836 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
22837@@ -544,7 +629,7 @@ ENDPROC(early_idt_handlers)
22838 /* This is global to keep gas from relaxing the jumps */
22839 ENTRY(early_idt_handler)
22840 cld
22841- cmpl $2,%ss:early_recursion_flag
22842+ cmpl $1,%ss:early_recursion_flag
22843 je hlt_loop
22844 incl %ss:early_recursion_flag
22845
22846@@ -582,8 +667,8 @@ ENTRY(early_idt_handler)
22847 pushl (20+6*4)(%esp) /* trapno */
22848 pushl $fault_msg
22849 call printk
22850-#endif
22851 call dump_stack
22852+#endif
22853 hlt_loop:
22854 hlt
22855 jmp hlt_loop
22856@@ -602,8 +687,11 @@ ENDPROC(early_idt_handler)
22857 /* This is the default interrupt "handler" :-) */
22858 ALIGN
22859 ignore_int:
22860- cld
22861 #ifdef CONFIG_PRINTK
22862+ cmpl $2,%ss:early_recursion_flag
22863+ je hlt_loop
22864+ incl %ss:early_recursion_flag
22865+ cld
22866 pushl %eax
22867 pushl %ecx
22868 pushl %edx
22869@@ -612,9 +700,6 @@ ignore_int:
22870 movl $(__KERNEL_DS),%eax
22871 movl %eax,%ds
22872 movl %eax,%es
22873- cmpl $2,early_recursion_flag
22874- je hlt_loop
22875- incl early_recursion_flag
22876 pushl 16(%esp)
22877 pushl 24(%esp)
22878 pushl 32(%esp)
22879@@ -648,29 +733,34 @@ ENTRY(setup_once_ref)
22880 /*
22881 * BSS section
22882 */
22883-__PAGE_ALIGNED_BSS
22884- .align PAGE_SIZE
22885 #ifdef CONFIG_X86_PAE
22886+.section .initial_pg_pmd,"a",@progbits
22887 initial_pg_pmd:
22888 .fill 1024*KPMDS,4,0
22889 #else
22890+.section .initial_page_table,"a",@progbits
22891 ENTRY(initial_page_table)
22892 .fill 1024,4,0
22893 #endif
22894+.section .initial_pg_fixmap,"a",@progbits
22895 initial_pg_fixmap:
22896 .fill 1024,4,0
22897+.section .empty_zero_page,"a",@progbits
22898 ENTRY(empty_zero_page)
22899 .fill 4096,1,0
22900+.section .swapper_pg_dir,"a",@progbits
22901 ENTRY(swapper_pg_dir)
22902+#ifdef CONFIG_X86_PAE
22903+ .fill 4,8,0
22904+#else
22905 .fill 1024,4,0
22906+#endif
22907
22908 /*
22909 * This starts the data section.
22910 */
22911 #ifdef CONFIG_X86_PAE
22912-__PAGE_ALIGNED_DATA
22913- /* Page-aligned for the benefit of paravirt? */
22914- .align PAGE_SIZE
22915+.section .initial_page_table,"a",@progbits
22916 ENTRY(initial_page_table)
22917 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
22918 # if KPMDS == 3
22919@@ -689,12 +779,20 @@ ENTRY(initial_page_table)
22920 # error "Kernel PMDs should be 1, 2 or 3"
22921 # endif
22922 .align PAGE_SIZE /* needs to be page-sized too */
22923+
22924+#ifdef CONFIG_PAX_PER_CPU_PGD
22925+ENTRY(cpu_pgd)
22926+ .rept 2*NR_CPUS
22927+ .fill 4,8,0
22928+ .endr
22929+#endif
22930+
22931 #endif
22932
22933 .data
22934 .balign 4
22935 ENTRY(stack_start)
22936- .long init_thread_union+THREAD_SIZE
22937+ .long init_thread_union+THREAD_SIZE-8
22938
22939 __INITRODATA
22940 int_msg:
22941@@ -722,7 +820,7 @@ fault_msg:
22942 * segment size, and 32-bit linear address value:
22943 */
22944
22945- .data
22946+.section .rodata,"a",@progbits
22947 .globl boot_gdt_descr
22948 .globl idt_descr
22949
22950@@ -731,7 +829,7 @@ fault_msg:
22951 .word 0 # 32 bit align gdt_desc.address
22952 boot_gdt_descr:
22953 .word __BOOT_DS+7
22954- .long boot_gdt - __PAGE_OFFSET
22955+ .long pa(boot_gdt)
22956
22957 .word 0 # 32-bit align idt_desc.address
22958 idt_descr:
22959@@ -742,7 +840,7 @@ idt_descr:
22960 .word 0 # 32 bit align gdt_desc.address
22961 ENTRY(early_gdt_descr)
22962 .word GDT_ENTRIES*8-1
22963- .long gdt_page /* Overwritten for secondary CPUs */
22964+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
22965
22966 /*
22967 * The boot_gdt must mirror the equivalent in setup.S and is
22968@@ -751,5 +849,65 @@ ENTRY(early_gdt_descr)
22969 .align L1_CACHE_BYTES
22970 ENTRY(boot_gdt)
22971 .fill GDT_ENTRY_BOOT_CS,8,0
22972- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
22973- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
22974+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
22975+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
22976+
22977+ .align PAGE_SIZE_asm
22978+ENTRY(cpu_gdt_table)
22979+ .rept NR_CPUS
22980+ .quad 0x0000000000000000 /* NULL descriptor */
22981+ .quad 0x0000000000000000 /* 0x0b reserved */
22982+ .quad 0x0000000000000000 /* 0x13 reserved */
22983+ .quad 0x0000000000000000 /* 0x1b reserved */
22984+
22985+#ifdef CONFIG_PAX_KERNEXEC
22986+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
22987+#else
22988+ .quad 0x0000000000000000 /* 0x20 unused */
22989+#endif
22990+
22991+ .quad 0x0000000000000000 /* 0x28 unused */
22992+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
22993+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
22994+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
22995+ .quad 0x0000000000000000 /* 0x4b reserved */
22996+ .quad 0x0000000000000000 /* 0x53 reserved */
22997+ .quad 0x0000000000000000 /* 0x5b reserved */
22998+
22999+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
23000+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
23001+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
23002+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
23003+
23004+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
23005+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
23006+
23007+ /*
23008+ * Segments used for calling PnP BIOS have byte granularity.
23009+ * The code segments and data segments have fixed 64k limits,
23010+ * the transfer segment sizes are set at run time.
23011+ */
23012+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
23013+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
23014+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
23015+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
23016+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
23017+
23018+ /*
23019+ * The APM segments have byte granularity and their bases
23020+ * are set at run time. All have 64k limits.
23021+ */
23022+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
23023+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
23024+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
23025+
23026+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
23027+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
23028+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
23029+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
23030+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
23031+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
23032+
23033+ /* Be sure this is zeroed to avoid false validations in Xen */
23034+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
23035+ .endr
23036diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
23037index e1aabdb..73dcad8 100644
23038--- a/arch/x86/kernel/head_64.S
23039+++ b/arch/x86/kernel/head_64.S
23040@@ -20,6 +20,8 @@
23041 #include <asm/processor-flags.h>
23042 #include <asm/percpu.h>
23043 #include <asm/nops.h>
23044+#include <asm/cpufeature.h>
23045+#include <asm/alternative-asm.h>
23046
23047 #ifdef CONFIG_PARAVIRT
23048 #include <asm/asm-offsets.h>
23049@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
23050 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
23051 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
23052 L3_START_KERNEL = pud_index(__START_KERNEL_map)
23053+L4_VMALLOC_START = pgd_index(VMALLOC_START)
23054+L3_VMALLOC_START = pud_index(VMALLOC_START)
23055+L4_VMALLOC_END = pgd_index(VMALLOC_END)
23056+L3_VMALLOC_END = pud_index(VMALLOC_END)
23057+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
23058+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
23059
23060 .text
23061 __HEAD
23062@@ -89,11 +97,23 @@ startup_64:
23063 * Fixup the physical addresses in the page table
23064 */
23065 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
23066+ addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
23067+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
23068+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
23069+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
23070+ addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
23071
23072- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
23073- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
23074+ addq %rbp, level3_ident_pgt + (0*8)(%rip)
23075+#ifndef CONFIG_XEN
23076+ addq %rbp, level3_ident_pgt + (1*8)(%rip)
23077+#endif
23078
23079- addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
23080+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
23081+
23082+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
23083+ addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
23084+
23085+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
23086
23087 /*
23088 * Set up the identity mapping for the switchover. These
23089@@ -177,8 +197,8 @@ ENTRY(secondary_startup_64)
23090 movq $(init_level4_pgt - __START_KERNEL_map), %rax
23091 1:
23092
23093- /* Enable PAE mode and PGE */
23094- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
23095+ /* Enable PAE mode and PSE/PGE */
23096+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
23097 movq %rcx, %cr4
23098
23099 /* Setup early boot stage 4 level pagetables. */
23100@@ -199,10 +219,18 @@ ENTRY(secondary_startup_64)
23101 movl $MSR_EFER, %ecx
23102 rdmsr
23103 btsl $_EFER_SCE, %eax /* Enable System Call */
23104- btl $20,%edi /* No Execute supported? */
23105+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
23106 jnc 1f
23107 btsl $_EFER_NX, %eax
23108 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
23109+ leaq init_level4_pgt(%rip), %rdi
23110+#ifndef CONFIG_EFI
23111+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
23112+#endif
23113+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
23114+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
23115+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
23116+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
23117 1: wrmsr /* Make changes effective */
23118
23119 /* Setup cr0 */
23120@@ -282,6 +310,7 @@ ENTRY(secondary_startup_64)
23121 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
23122 * address given in m16:64.
23123 */
23124+ pax_set_fptr_mask
23125 movq initial_code(%rip),%rax
23126 pushq $0 # fake return address to stop unwinder
23127 pushq $__KERNEL_CS # set correct cs
23128@@ -388,7 +417,7 @@ ENTRY(early_idt_handler)
23129 call dump_stack
23130 #ifdef CONFIG_KALLSYMS
23131 leaq early_idt_ripmsg(%rip),%rdi
23132- movq 40(%rsp),%rsi # %rip again
23133+ movq 88(%rsp),%rsi # %rip again
23134 call __print_symbol
23135 #endif
23136 #endif /* EARLY_PRINTK */
23137@@ -416,6 +445,7 @@ ENDPROC(early_idt_handler)
23138 early_recursion_flag:
23139 .long 0
23140
23141+ .section .rodata,"a",@progbits
23142 #ifdef CONFIG_EARLY_PRINTK
23143 early_idt_msg:
23144 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
23145@@ -443,29 +473,52 @@ NEXT_PAGE(early_level4_pgt)
23146 NEXT_PAGE(early_dynamic_pgts)
23147 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
23148
23149- .data
23150+ .section .rodata,"a",@progbits
23151
23152-#ifndef CONFIG_XEN
23153 NEXT_PAGE(init_level4_pgt)
23154- .fill 512,8,0
23155-#else
23156-NEXT_PAGE(init_level4_pgt)
23157- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
23158 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
23159 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
23160+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
23161+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
23162+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
23163+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
23164+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
23165+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
23166 .org init_level4_pgt + L4_START_KERNEL*8, 0
23167 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
23168 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
23169
23170+#ifdef CONFIG_PAX_PER_CPU_PGD
23171+NEXT_PAGE(cpu_pgd)
23172+ .rept 2*NR_CPUS
23173+ .fill 512,8,0
23174+ .endr
23175+#endif
23176+
23177 NEXT_PAGE(level3_ident_pgt)
23178 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
23179+#ifdef CONFIG_XEN
23180 .fill 511, 8, 0
23181+#else
23182+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
23183+ .fill 510,8,0
23184+#endif
23185+
23186+NEXT_PAGE(level3_vmalloc_start_pgt)
23187+ .fill 512,8,0
23188+
23189+NEXT_PAGE(level3_vmalloc_end_pgt)
23190+ .fill 512,8,0
23191+
23192+NEXT_PAGE(level3_vmemmap_pgt)
23193+ .fill L3_VMEMMAP_START,8,0
23194+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
23195+
23196 NEXT_PAGE(level2_ident_pgt)
23197- /* Since I easily can, map the first 1G.
23198+ /* Since I easily can, map the first 2G.
23199 * Don't set NX because code runs from these pages.
23200 */
23201- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
23202-#endif
23203+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
23204
23205 NEXT_PAGE(level3_kernel_pgt)
23206 .fill L3_START_KERNEL,8,0
23207@@ -473,6 +526,9 @@ NEXT_PAGE(level3_kernel_pgt)
23208 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
23209 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
23210
23211+NEXT_PAGE(level2_vmemmap_pgt)
23212+ .fill 512,8,0
23213+
23214 NEXT_PAGE(level2_kernel_pgt)
23215 /*
23216 * 512 MB kernel mapping. We spend a full page on this pagetable
23217@@ -488,30 +544,62 @@ NEXT_PAGE(level2_kernel_pgt)
23218 KERNEL_IMAGE_SIZE/PMD_SIZE)
23219
23220 NEXT_PAGE(level2_fixmap_pgt)
23221- .fill 506,8,0
23222- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
23223- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
23224- .fill 5,8,0
23225+ .fill 507,8,0
23226+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
23227+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
23228+ .fill 4,8,0
23229
23230-NEXT_PAGE(level1_fixmap_pgt)
23231+NEXT_PAGE(level1_vsyscall_pgt)
23232 .fill 512,8,0
23233
23234 #undef PMDS
23235
23236- .data
23237+ .align PAGE_SIZE
23238+ENTRY(cpu_gdt_table)
23239+ .rept NR_CPUS
23240+ .quad 0x0000000000000000 /* NULL descriptor */
23241+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
23242+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
23243+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
23244+ .quad 0x00cffb000000ffff /* __USER32_CS */
23245+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
23246+ .quad 0x00affb000000ffff /* __USER_CS */
23247+
23248+#ifdef CONFIG_PAX_KERNEXEC
23249+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
23250+#else
23251+ .quad 0x0 /* unused */
23252+#endif
23253+
23254+ .quad 0,0 /* TSS */
23255+ .quad 0,0 /* LDT */
23256+ .quad 0,0,0 /* three TLS descriptors */
23257+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
23258+ /* asm/segment.h:GDT_ENTRIES must match this */
23259+
23260+#ifdef CONFIG_PAX_MEMORY_UDEREF
23261+ .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
23262+#else
23263+ .quad 0x0 /* unused */
23264+#endif
23265+
23266+ /* zero the remaining page */
23267+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
23268+ .endr
23269+
23270 .align 16
23271 .globl early_gdt_descr
23272 early_gdt_descr:
23273 .word GDT_ENTRIES*8-1
23274 early_gdt_descr_base:
23275- .quad INIT_PER_CPU_VAR(gdt_page)
23276+ .quad cpu_gdt_table
23277
23278 ENTRY(phys_base)
23279 /* This must match the first entry in level2_kernel_pgt */
23280 .quad 0x0000000000000000
23281
23282 #include "../../x86/xen/xen-head.S"
23283-
23284- __PAGE_ALIGNED_BSS
23285+
23286+ .section .rodata,"a",@progbits
23287 NEXT_PAGE(empty_zero_page)
23288 .skip PAGE_SIZE
23289diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
23290index 0fa6912..b37438b 100644
23291--- a/arch/x86/kernel/i386_ksyms_32.c
23292+++ b/arch/x86/kernel/i386_ksyms_32.c
23293@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
23294 EXPORT_SYMBOL(cmpxchg8b_emu);
23295 #endif
23296
23297+EXPORT_SYMBOL_GPL(cpu_gdt_table);
23298+
23299 /* Networking helper routines. */
23300 EXPORT_SYMBOL(csum_partial_copy_generic);
23301+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
23302+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
23303
23304 EXPORT_SYMBOL(__get_user_1);
23305 EXPORT_SYMBOL(__get_user_2);
23306@@ -37,3 +41,11 @@ EXPORT_SYMBOL(strstr);
23307
23308 EXPORT_SYMBOL(csum_partial);
23309 EXPORT_SYMBOL(empty_zero_page);
23310+
23311+#ifdef CONFIG_PAX_KERNEXEC
23312+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
23313+#endif
23314+
23315+#ifdef CONFIG_PAX_PER_CPU_PGD
23316+EXPORT_SYMBOL(cpu_pgd);
23317+#endif
23318diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
23319index 5d576ab..1403a03 100644
23320--- a/arch/x86/kernel/i387.c
23321+++ b/arch/x86/kernel/i387.c
23322@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
23323 static inline bool interrupted_user_mode(void)
23324 {
23325 struct pt_regs *regs = get_irq_regs();
23326- return regs && user_mode_vm(regs);
23327+ return regs && user_mode(regs);
23328 }
23329
23330 /*
23331diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
23332index 9a5c460..84868423 100644
23333--- a/arch/x86/kernel/i8259.c
23334+++ b/arch/x86/kernel/i8259.c
23335@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
23336 static void make_8259A_irq(unsigned int irq)
23337 {
23338 disable_irq_nosync(irq);
23339- io_apic_irqs &= ~(1<<irq);
23340+ io_apic_irqs &= ~(1UL<<irq);
23341 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
23342 i8259A_chip.name);
23343 enable_irq(irq);
23344@@ -209,7 +209,7 @@ spurious_8259A_irq:
23345 "spurious 8259A interrupt: IRQ%d.\n", irq);
23346 spurious_irq_mask |= irqmask;
23347 }
23348- atomic_inc(&irq_err_count);
23349+ atomic_inc_unchecked(&irq_err_count);
23350 /*
23351 * Theoretically we do not have to handle this IRQ,
23352 * but in Linux this does not cause problems and is
23353@@ -333,14 +333,16 @@ static void init_8259A(int auto_eoi)
23354 /* (slave's support for AEOI in flat mode is to be investigated) */
23355 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
23356
23357+ pax_open_kernel();
23358 if (auto_eoi)
23359 /*
23360 * In AEOI mode we just have to mask the interrupt
23361 * when acking.
23362 */
23363- i8259A_chip.irq_mask_ack = disable_8259A_irq;
23364+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
23365 else
23366- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
23367+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
23368+ pax_close_kernel();
23369
23370 udelay(100); /* wait for 8259A to initialize */
23371
23372diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
23373index a979b5b..1d6db75 100644
23374--- a/arch/x86/kernel/io_delay.c
23375+++ b/arch/x86/kernel/io_delay.c
23376@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
23377 * Quirk table for systems that misbehave (lock up, etc.) if port
23378 * 0x80 is used:
23379 */
23380-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
23381+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
23382 {
23383 .callback = dmi_io_delay_0xed_port,
23384 .ident = "Compaq Presario V6000",
23385diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
23386index 4ddaf66..6292f4e 100644
23387--- a/arch/x86/kernel/ioport.c
23388+++ b/arch/x86/kernel/ioport.c
23389@@ -6,6 +6,7 @@
23390 #include <linux/sched.h>
23391 #include <linux/kernel.h>
23392 #include <linux/capability.h>
23393+#include <linux/security.h>
23394 #include <linux/errno.h>
23395 #include <linux/types.h>
23396 #include <linux/ioport.h>
23397@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
23398
23399 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
23400 return -EINVAL;
23401+#ifdef CONFIG_GRKERNSEC_IO
23402+ if (turn_on && grsec_disable_privio) {
23403+ gr_handle_ioperm();
23404+ return -EPERM;
23405+ }
23406+#endif
23407 if (turn_on && !capable(CAP_SYS_RAWIO))
23408 return -EPERM;
23409
23410@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
23411 * because the ->io_bitmap_max value must match the bitmap
23412 * contents:
23413 */
23414- tss = &per_cpu(init_tss, get_cpu());
23415+ tss = init_tss + get_cpu();
23416
23417 if (turn_on)
23418 bitmap_clear(t->io_bitmap_ptr, from, num);
23419@@ -103,6 +110,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
23420 return -EINVAL;
23421 /* Trying to gain more privileges? */
23422 if (level > old) {
23423+#ifdef CONFIG_GRKERNSEC_IO
23424+ if (grsec_disable_privio) {
23425+ gr_handle_iopl();
23426+ return -EPERM;
23427+ }
23428+#endif
23429 if (!capable(CAP_SYS_RAWIO))
23430 return -EPERM;
23431 }
23432diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
23433index 3a8185c..3c042ee 100644
23434--- a/arch/x86/kernel/irq.c
23435+++ b/arch/x86/kernel/irq.c
23436@@ -21,7 +21,7 @@
23437 #define CREATE_TRACE_POINTS
23438 #include <asm/trace/irq_vectors.h>
23439
23440-atomic_t irq_err_count;
23441+atomic_unchecked_t irq_err_count;
23442
23443 /* Function pointer for generic interrupt vector handling */
23444 void (*x86_platform_ipi_callback)(void) = NULL;
23445@@ -125,9 +125,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
23446 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
23447 seq_printf(p, " Machine check polls\n");
23448 #endif
23449- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
23450+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
23451 #if defined(CONFIG_X86_IO_APIC)
23452- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
23453+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
23454 #endif
23455 return 0;
23456 }
23457@@ -167,7 +167,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
23458
23459 u64 arch_irq_stat(void)
23460 {
23461- u64 sum = atomic_read(&irq_err_count);
23462+ u64 sum = atomic_read_unchecked(&irq_err_count);
23463 return sum;
23464 }
23465
23466diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
23467index 4186755..784efa0 100644
23468--- a/arch/x86/kernel/irq_32.c
23469+++ b/arch/x86/kernel/irq_32.c
23470@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
23471 __asm__ __volatile__("andl %%esp,%0" :
23472 "=r" (sp) : "0" (THREAD_SIZE - 1));
23473
23474- return sp < (sizeof(struct thread_info) + STACK_WARN);
23475+ return sp < STACK_WARN;
23476 }
23477
23478 static void print_stack_overflow(void)
23479@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
23480 * per-CPU IRQ handling contexts (thread information and stack)
23481 */
23482 union irq_ctx {
23483- struct thread_info tinfo;
23484- u32 stack[THREAD_SIZE/sizeof(u32)];
23485+ unsigned long previous_esp;
23486+ u32 stack[THREAD_SIZE/sizeof(u32)];
23487 } __attribute__((aligned(THREAD_SIZE)));
23488
23489 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
23490@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
23491 static inline int
23492 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23493 {
23494- union irq_ctx *curctx, *irqctx;
23495+ union irq_ctx *irqctx;
23496 u32 *isp, arg1, arg2;
23497
23498- curctx = (union irq_ctx *) current_thread_info();
23499 irqctx = __this_cpu_read(hardirq_ctx);
23500
23501 /*
23502@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23503 * handler) we can't do that and just have to keep using the
23504 * current stack (which is the irq stack already after all)
23505 */
23506- if (unlikely(curctx == irqctx))
23507+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
23508 return 0;
23509
23510 /* build the stack frame on the IRQ stack */
23511- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
23512- irqctx->tinfo.task = curctx->tinfo.task;
23513- irqctx->tinfo.previous_esp = current_stack_pointer;
23514+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
23515+ irqctx->previous_esp = current_stack_pointer;
23516
23517- /* Copy the preempt_count so that the [soft]irq checks work. */
23518- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
23519+#ifdef CONFIG_PAX_MEMORY_UDEREF
23520+ __set_fs(MAKE_MM_SEG(0));
23521+#endif
23522
23523 if (unlikely(overflow))
23524 call_on_stack(print_stack_overflow, isp);
23525@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23526 : "0" (irq), "1" (desc), "2" (isp),
23527 "D" (desc->handle_irq)
23528 : "memory", "cc", "ecx");
23529+
23530+#ifdef CONFIG_PAX_MEMORY_UDEREF
23531+ __set_fs(current_thread_info()->addr_limit);
23532+#endif
23533+
23534 return 1;
23535 }
23536
23537@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23538 */
23539 void irq_ctx_init(int cpu)
23540 {
23541- union irq_ctx *irqctx;
23542-
23543 if (per_cpu(hardirq_ctx, cpu))
23544 return;
23545
23546- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
23547- THREADINFO_GFP,
23548- THREAD_SIZE_ORDER));
23549- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
23550- irqctx->tinfo.cpu = cpu;
23551- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
23552- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
23553+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
23554+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
23555
23556- per_cpu(hardirq_ctx, cpu) = irqctx;
23557-
23558- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
23559- THREADINFO_GFP,
23560- THREAD_SIZE_ORDER));
23561- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
23562- irqctx->tinfo.cpu = cpu;
23563- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
23564-
23565- per_cpu(softirq_ctx, cpu) = irqctx;
23566+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
23567+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
23568
23569 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
23570 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
23571@@ -152,7 +141,6 @@ void irq_ctx_init(int cpu)
23572 asmlinkage void do_softirq(void)
23573 {
23574 unsigned long flags;
23575- struct thread_info *curctx;
23576 union irq_ctx *irqctx;
23577 u32 *isp;
23578
23579@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
23580 local_irq_save(flags);
23581
23582 if (local_softirq_pending()) {
23583- curctx = current_thread_info();
23584 irqctx = __this_cpu_read(softirq_ctx);
23585- irqctx->tinfo.task = curctx->task;
23586- irqctx->tinfo.previous_esp = current_stack_pointer;
23587+ irqctx->previous_esp = current_stack_pointer;
23588
23589 /* build the stack frame on the softirq stack */
23590- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
23591+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
23592+
23593+#ifdef CONFIG_PAX_MEMORY_UDEREF
23594+ __set_fs(MAKE_MM_SEG(0));
23595+#endif
23596
23597 call_on_stack(__do_softirq, isp);
23598+
23599+#ifdef CONFIG_PAX_MEMORY_UDEREF
23600+ __set_fs(current_thread_info()->addr_limit);
23601+#endif
23602+
23603 /*
23604 * Shouldn't happen, we returned above if in_interrupt():
23605 */
23606@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
23607 if (unlikely(!desc))
23608 return false;
23609
23610- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
23611+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
23612 if (unlikely(overflow))
23613 print_stack_overflow();
23614 desc->handle_irq(irq, desc);
23615diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
23616index d04d3ec..ea4b374 100644
23617--- a/arch/x86/kernel/irq_64.c
23618+++ b/arch/x86/kernel/irq_64.c
23619@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
23620 u64 estack_top, estack_bottom;
23621 u64 curbase = (u64)task_stack_page(current);
23622
23623- if (user_mode_vm(regs))
23624+ if (user_mode(regs))
23625 return;
23626
23627 if (regs->sp >= curbase + sizeof(struct thread_info) +
23628diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
23629index dc1404b..bbc43e7 100644
23630--- a/arch/x86/kernel/kdebugfs.c
23631+++ b/arch/x86/kernel/kdebugfs.c
23632@@ -27,7 +27,7 @@ struct setup_data_node {
23633 u32 len;
23634 };
23635
23636-static ssize_t setup_data_read(struct file *file, char __user *user_buf,
23637+static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
23638 size_t count, loff_t *ppos)
23639 {
23640 struct setup_data_node *node = file->private_data;
23641diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
23642index 836f832..a8bda67 100644
23643--- a/arch/x86/kernel/kgdb.c
23644+++ b/arch/x86/kernel/kgdb.c
23645@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
23646 #ifdef CONFIG_X86_32
23647 switch (regno) {
23648 case GDB_SS:
23649- if (!user_mode_vm(regs))
23650+ if (!user_mode(regs))
23651 *(unsigned long *)mem = __KERNEL_DS;
23652 break;
23653 case GDB_SP:
23654- if (!user_mode_vm(regs))
23655+ if (!user_mode(regs))
23656 *(unsigned long *)mem = kernel_stack_pointer(regs);
23657 break;
23658 case GDB_GS:
23659@@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
23660 bp->attr.bp_addr = breakinfo[breakno].addr;
23661 bp->attr.bp_len = breakinfo[breakno].len;
23662 bp->attr.bp_type = breakinfo[breakno].type;
23663- info->address = breakinfo[breakno].addr;
23664+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
23665+ info->address = ktla_ktva(breakinfo[breakno].addr);
23666+ else
23667+ info->address = breakinfo[breakno].addr;
23668 info->len = breakinfo[breakno].len;
23669 info->type = breakinfo[breakno].type;
23670 val = arch_install_hw_breakpoint(bp);
23671@@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
23672 case 'k':
23673 /* clear the trace bit */
23674 linux_regs->flags &= ~X86_EFLAGS_TF;
23675- atomic_set(&kgdb_cpu_doing_single_step, -1);
23676+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
23677
23678 /* set the trace bit if we're stepping */
23679 if (remcomInBuffer[0] == 's') {
23680 linux_regs->flags |= X86_EFLAGS_TF;
23681- atomic_set(&kgdb_cpu_doing_single_step,
23682+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
23683 raw_smp_processor_id());
23684 }
23685
23686@@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
23687
23688 switch (cmd) {
23689 case DIE_DEBUG:
23690- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
23691+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
23692 if (user_mode(regs))
23693 return single_step_cont(regs, args);
23694 break;
23695@@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
23696 #endif /* CONFIG_DEBUG_RODATA */
23697
23698 bpt->type = BP_BREAKPOINT;
23699- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
23700+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
23701 BREAK_INSTR_SIZE);
23702 if (err)
23703 return err;
23704- err = probe_kernel_write((char *)bpt->bpt_addr,
23705+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
23706 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
23707 #ifdef CONFIG_DEBUG_RODATA
23708 if (!err)
23709@@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
23710 return -EBUSY;
23711 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
23712 BREAK_INSTR_SIZE);
23713- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
23714+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
23715 if (err)
23716 return err;
23717 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
23718@@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
23719 if (mutex_is_locked(&text_mutex))
23720 goto knl_write;
23721 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
23722- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
23723+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
23724 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
23725 goto knl_write;
23726 return err;
23727 knl_write:
23728 #endif /* CONFIG_DEBUG_RODATA */
23729- return probe_kernel_write((char *)bpt->bpt_addr,
23730+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
23731 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
23732 }
23733
23734diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
23735index 211bce4..6e2580a 100644
23736--- a/arch/x86/kernel/kprobes/core.c
23737+++ b/arch/x86/kernel/kprobes/core.c
23738@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
23739 s32 raddr;
23740 } __packed *insn;
23741
23742- insn = (struct __arch_relative_insn *)from;
23743+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
23744+
23745+ pax_open_kernel();
23746 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
23747 insn->op = op;
23748+ pax_close_kernel();
23749 }
23750
23751 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
23752@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
23753 kprobe_opcode_t opcode;
23754 kprobe_opcode_t *orig_opcodes = opcodes;
23755
23756- if (search_exception_tables((unsigned long)opcodes))
23757+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
23758 return 0; /* Page fault may occur on this address. */
23759
23760 retry:
23761@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
23762 * for the first byte, we can recover the original instruction
23763 * from it and kp->opcode.
23764 */
23765- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
23766+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
23767 buf[0] = kp->opcode;
23768- return (unsigned long)buf;
23769+ return ktva_ktla((unsigned long)buf);
23770 }
23771
23772 /*
23773@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
23774 /* Another subsystem puts a breakpoint, failed to recover */
23775 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
23776 return 0;
23777+ pax_open_kernel();
23778 memcpy(dest, insn.kaddr, insn.length);
23779+ pax_close_kernel();
23780
23781 #ifdef CONFIG_X86_64
23782 if (insn_rip_relative(&insn)) {
23783@@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
23784 return 0;
23785 }
23786 disp = (u8 *) dest + insn_offset_displacement(&insn);
23787+ pax_open_kernel();
23788 *(s32 *) disp = (s32) newdisp;
23789+ pax_close_kernel();
23790 }
23791 #endif
23792 return insn.length;
23793@@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
23794 * nor set current_kprobe, because it doesn't use single
23795 * stepping.
23796 */
23797- regs->ip = (unsigned long)p->ainsn.insn;
23798+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
23799 preempt_enable_no_resched();
23800 return;
23801 }
23802@@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
23803 regs->flags &= ~X86_EFLAGS_IF;
23804 /* single step inline if the instruction is an int3 */
23805 if (p->opcode == BREAKPOINT_INSTRUCTION)
23806- regs->ip = (unsigned long)p->addr;
23807+ regs->ip = ktla_ktva((unsigned long)p->addr);
23808 else
23809- regs->ip = (unsigned long)p->ainsn.insn;
23810+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
23811 }
23812
23813 /*
23814@@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
23815 setup_singlestep(p, regs, kcb, 0);
23816 return 1;
23817 }
23818- } else if (*addr != BREAKPOINT_INSTRUCTION) {
23819+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
23820 /*
23821 * The breakpoint instruction was removed right
23822 * after we hit it. Another cpu has removed
23823@@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
23824 " movq %rax, 152(%rsp)\n"
23825 RESTORE_REGS_STRING
23826 " popfq\n"
23827+#ifdef KERNEXEC_PLUGIN
23828+ " btsq $63,(%rsp)\n"
23829+#endif
23830 #else
23831 " pushf\n"
23832 SAVE_REGS_STRING
23833@@ -779,7 +789,7 @@ static void __kprobes
23834 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
23835 {
23836 unsigned long *tos = stack_addr(regs);
23837- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
23838+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
23839 unsigned long orig_ip = (unsigned long)p->addr;
23840 kprobe_opcode_t *insn = p->ainsn.insn;
23841
23842@@ -961,7 +971,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
23843 struct die_args *args = data;
23844 int ret = NOTIFY_DONE;
23845
23846- if (args->regs && user_mode_vm(args->regs))
23847+ if (args->regs && user_mode(args->regs))
23848 return ret;
23849
23850 switch (val) {
23851diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
23852index 76dc6f0..66bdfc3 100644
23853--- a/arch/x86/kernel/kprobes/opt.c
23854+++ b/arch/x86/kernel/kprobes/opt.c
23855@@ -79,6 +79,7 @@ found:
23856 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
23857 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
23858 {
23859+ pax_open_kernel();
23860 #ifdef CONFIG_X86_64
23861 *addr++ = 0x48;
23862 *addr++ = 0xbf;
23863@@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
23864 *addr++ = 0xb8;
23865 #endif
23866 *(unsigned long *)addr = val;
23867+ pax_close_kernel();
23868 }
23869
23870 static void __used __kprobes kprobes_optinsn_template_holder(void)
23871@@ -338,7 +340,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
23872 * Verify if the address gap is in 2GB range, because this uses
23873 * a relative jump.
23874 */
23875- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
23876+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
23877 if (abs(rel) > 0x7fffffff)
23878 return -ERANGE;
23879
23880@@ -353,16 +355,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
23881 op->optinsn.size = ret;
23882
23883 /* Copy arch-dep-instance from template */
23884- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
23885+ pax_open_kernel();
23886+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
23887+ pax_close_kernel();
23888
23889 /* Set probe information */
23890 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
23891
23892 /* Set probe function call */
23893- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
23894+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
23895
23896 /* Set returning jmp instruction at the tail of out-of-line buffer */
23897- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
23898+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
23899 (u8 *)op->kp.addr + op->optinsn.size);
23900
23901 flush_icache_range((unsigned long) buf,
23902@@ -385,7 +389,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
23903 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
23904
23905 /* Backup instructions which will be replaced by jump address */
23906- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
23907+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
23908 RELATIVE_ADDR_SIZE);
23909
23910 insn_buf[0] = RELATIVEJUMP_OPCODE;
23911@@ -483,7 +487,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
23912 /* This kprobe is really able to run optimized path. */
23913 op = container_of(p, struct optimized_kprobe, kp);
23914 /* Detour through copied instructions */
23915- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
23916+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
23917 if (!reenter)
23918 reset_current_kprobe();
23919 preempt_enable_no_resched();
23920diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
23921index ebc9873..1b9724b 100644
23922--- a/arch/x86/kernel/ldt.c
23923+++ b/arch/x86/kernel/ldt.c
23924@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
23925 if (reload) {
23926 #ifdef CONFIG_SMP
23927 preempt_disable();
23928- load_LDT(pc);
23929+ load_LDT_nolock(pc);
23930 if (!cpumask_equal(mm_cpumask(current->mm),
23931 cpumask_of(smp_processor_id())))
23932 smp_call_function(flush_ldt, current->mm, 1);
23933 preempt_enable();
23934 #else
23935- load_LDT(pc);
23936+ load_LDT_nolock(pc);
23937 #endif
23938 }
23939 if (oldsize) {
23940@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
23941 return err;
23942
23943 for (i = 0; i < old->size; i++)
23944- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
23945+ write_ldt_entry(new->ldt, i, old->ldt + i);
23946 return 0;
23947 }
23948
23949@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
23950 retval = copy_ldt(&mm->context, &old_mm->context);
23951 mutex_unlock(&old_mm->context.lock);
23952 }
23953+
23954+ if (tsk == current) {
23955+ mm->context.vdso = 0;
23956+
23957+#ifdef CONFIG_X86_32
23958+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23959+ mm->context.user_cs_base = 0UL;
23960+ mm->context.user_cs_limit = ~0UL;
23961+
23962+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
23963+ cpus_clear(mm->context.cpu_user_cs_mask);
23964+#endif
23965+
23966+#endif
23967+#endif
23968+
23969+ }
23970+
23971 return retval;
23972 }
23973
23974@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
23975 }
23976 }
23977
23978+#ifdef CONFIG_PAX_SEGMEXEC
23979+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
23980+ error = -EINVAL;
23981+ goto out_unlock;
23982+ }
23983+#endif
23984+
23985 fill_ldt(&ldt, &ldt_info);
23986 if (oldmode)
23987 ldt.avl = 0;
23988diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
23989index 5b19e4d..6476a76 100644
23990--- a/arch/x86/kernel/machine_kexec_32.c
23991+++ b/arch/x86/kernel/machine_kexec_32.c
23992@@ -26,7 +26,7 @@
23993 #include <asm/cacheflush.h>
23994 #include <asm/debugreg.h>
23995
23996-static void set_idt(void *newidt, __u16 limit)
23997+static void set_idt(struct desc_struct *newidt, __u16 limit)
23998 {
23999 struct desc_ptr curidt;
24000
24001@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
24002 }
24003
24004
24005-static void set_gdt(void *newgdt, __u16 limit)
24006+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
24007 {
24008 struct desc_ptr curgdt;
24009
24010@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
24011 }
24012
24013 control_page = page_address(image->control_code_page);
24014- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
24015+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
24016
24017 relocate_kernel_ptr = control_page;
24018 page_list[PA_CONTROL_PAGE] = __pa(control_page);
24019diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
24020index 15c9876..0a43909 100644
24021--- a/arch/x86/kernel/microcode_core.c
24022+++ b/arch/x86/kernel/microcode_core.c
24023@@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
24024 return NOTIFY_OK;
24025 }
24026
24027-static struct notifier_block __refdata mc_cpu_notifier = {
24028+static struct notifier_block mc_cpu_notifier = {
24029 .notifier_call = mc_cpu_callback,
24030 };
24031
24032diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
24033index 5fb2ceb..3ae90bb 100644
24034--- a/arch/x86/kernel/microcode_intel.c
24035+++ b/arch/x86/kernel/microcode_intel.c
24036@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
24037
24038 static int get_ucode_user(void *to, const void *from, size_t n)
24039 {
24040- return copy_from_user(to, from, n);
24041+ return copy_from_user(to, (const void __force_user *)from, n);
24042 }
24043
24044 static enum ucode_state
24045 request_microcode_user(int cpu, const void __user *buf, size_t size)
24046 {
24047- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
24048+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
24049 }
24050
24051 static void microcode_fini_cpu(int cpu)
24052diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
24053index 216a4d7..228255a 100644
24054--- a/arch/x86/kernel/module.c
24055+++ b/arch/x86/kernel/module.c
24056@@ -43,15 +43,60 @@ do { \
24057 } while (0)
24058 #endif
24059
24060-void *module_alloc(unsigned long size)
24061+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
24062 {
24063- if (PAGE_ALIGN(size) > MODULES_LEN)
24064+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
24065 return NULL;
24066 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
24067- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
24068+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
24069 -1, __builtin_return_address(0));
24070 }
24071
24072+void *module_alloc(unsigned long size)
24073+{
24074+
24075+#ifdef CONFIG_PAX_KERNEXEC
24076+ return __module_alloc(size, PAGE_KERNEL);
24077+#else
24078+ return __module_alloc(size, PAGE_KERNEL_EXEC);
24079+#endif
24080+
24081+}
24082+
24083+#ifdef CONFIG_PAX_KERNEXEC
24084+#ifdef CONFIG_X86_32
24085+void *module_alloc_exec(unsigned long size)
24086+{
24087+ struct vm_struct *area;
24088+
24089+ if (size == 0)
24090+ return NULL;
24091+
24092+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
24093+ return area ? area->addr : NULL;
24094+}
24095+EXPORT_SYMBOL(module_alloc_exec);
24096+
24097+void module_free_exec(struct module *mod, void *module_region)
24098+{
24099+ vunmap(module_region);
24100+}
24101+EXPORT_SYMBOL(module_free_exec);
24102+#else
24103+void module_free_exec(struct module *mod, void *module_region)
24104+{
24105+ module_free(mod, module_region);
24106+}
24107+EXPORT_SYMBOL(module_free_exec);
24108+
24109+void *module_alloc_exec(unsigned long size)
24110+{
24111+ return __module_alloc(size, PAGE_KERNEL_RX);
24112+}
24113+EXPORT_SYMBOL(module_alloc_exec);
24114+#endif
24115+#endif
24116+
24117 #ifdef CONFIG_X86_32
24118 int apply_relocate(Elf32_Shdr *sechdrs,
24119 const char *strtab,
24120@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
24121 unsigned int i;
24122 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
24123 Elf32_Sym *sym;
24124- uint32_t *location;
24125+ uint32_t *plocation, location;
24126
24127 DEBUGP("Applying relocate section %u to %u\n",
24128 relsec, sechdrs[relsec].sh_info);
24129 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
24130 /* This is where to make the change */
24131- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
24132- + rel[i].r_offset;
24133+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
24134+ location = (uint32_t)plocation;
24135+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
24136+ plocation = ktla_ktva((void *)plocation);
24137 /* This is the symbol it is referring to. Note that all
24138 undefined symbols have been resolved. */
24139 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
24140@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
24141 switch (ELF32_R_TYPE(rel[i].r_info)) {
24142 case R_386_32:
24143 /* We add the value into the location given */
24144- *location += sym->st_value;
24145+ pax_open_kernel();
24146+ *plocation += sym->st_value;
24147+ pax_close_kernel();
24148 break;
24149 case R_386_PC32:
24150 /* Add the value, subtract its position */
24151- *location += sym->st_value - (uint32_t)location;
24152+ pax_open_kernel();
24153+ *plocation += sym->st_value - location;
24154+ pax_close_kernel();
24155 break;
24156 default:
24157 pr_err("%s: Unknown relocation: %u\n",
24158@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
24159 case R_X86_64_NONE:
24160 break;
24161 case R_X86_64_64:
24162+ pax_open_kernel();
24163 *(u64 *)loc = val;
24164+ pax_close_kernel();
24165 break;
24166 case R_X86_64_32:
24167+ pax_open_kernel();
24168 *(u32 *)loc = val;
24169+ pax_close_kernel();
24170 if (val != *(u32 *)loc)
24171 goto overflow;
24172 break;
24173 case R_X86_64_32S:
24174+ pax_open_kernel();
24175 *(s32 *)loc = val;
24176+ pax_close_kernel();
24177 if ((s64)val != *(s32 *)loc)
24178 goto overflow;
24179 break;
24180 case R_X86_64_PC32:
24181 val -= (u64)loc;
24182+ pax_open_kernel();
24183 *(u32 *)loc = val;
24184+ pax_close_kernel();
24185+
24186 #if 0
24187 if ((s64)val != *(s32 *)loc)
24188 goto overflow;
24189diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
24190index 88458fa..349f7a4 100644
24191--- a/arch/x86/kernel/msr.c
24192+++ b/arch/x86/kernel/msr.c
24193@@ -233,7 +233,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
24194 return notifier_from_errno(err);
24195 }
24196
24197-static struct notifier_block __refdata msr_class_cpu_notifier = {
24198+static struct notifier_block msr_class_cpu_notifier = {
24199 .notifier_call = msr_class_cpu_callback,
24200 };
24201
24202diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
24203index ba77ebc..65da999 100644
24204--- a/arch/x86/kernel/nmi.c
24205+++ b/arch/x86/kernel/nmi.c
24206@@ -138,7 +138,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
24207 return handled;
24208 }
24209
24210-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
24211+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
24212 {
24213 struct nmi_desc *desc = nmi_to_desc(type);
24214 unsigned long flags;
24215@@ -162,9 +162,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
24216 * event confuses some handlers (kdump uses this flag)
24217 */
24218 if (action->flags & NMI_FLAG_FIRST)
24219- list_add_rcu(&action->list, &desc->head);
24220+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
24221 else
24222- list_add_tail_rcu(&action->list, &desc->head);
24223+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
24224
24225 spin_unlock_irqrestore(&desc->lock, flags);
24226 return 0;
24227@@ -187,7 +187,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
24228 if (!strcmp(n->name, name)) {
24229 WARN(in_nmi(),
24230 "Trying to free NMI (%s) from NMI context!\n", n->name);
24231- list_del_rcu(&n->list);
24232+ pax_list_del_rcu((struct list_head *)&n->list);
24233 break;
24234 }
24235 }
24236@@ -512,6 +512,17 @@ static inline void nmi_nesting_postprocess(void)
24237 dotraplinkage notrace __kprobes void
24238 do_nmi(struct pt_regs *regs, long error_code)
24239 {
24240+
24241+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
24242+ if (!user_mode(regs)) {
24243+ unsigned long cs = regs->cs & 0xFFFF;
24244+ unsigned long ip = ktva_ktla(regs->ip);
24245+
24246+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
24247+ regs->ip = ip;
24248+ }
24249+#endif
24250+
24251 nmi_nesting_preprocess(regs);
24252
24253 nmi_enter();
24254diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
24255index 6d9582e..f746287 100644
24256--- a/arch/x86/kernel/nmi_selftest.c
24257+++ b/arch/x86/kernel/nmi_selftest.c
24258@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
24259 {
24260 /* trap all the unknown NMIs we may generate */
24261 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
24262- __initdata);
24263+ __initconst);
24264 }
24265
24266 static void __init cleanup_nmi_testsuite(void)
24267@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
24268 unsigned long timeout;
24269
24270 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
24271- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
24272+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
24273 nmi_fail = FAILURE;
24274 return;
24275 }
24276diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
24277index 676b8c7..870ba04 100644
24278--- a/arch/x86/kernel/paravirt-spinlocks.c
24279+++ b/arch/x86/kernel/paravirt-spinlocks.c
24280@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
24281 arch_spin_lock(lock);
24282 }
24283
24284-struct pv_lock_ops pv_lock_ops = {
24285+struct pv_lock_ops pv_lock_ops __read_only = {
24286 #ifdef CONFIG_SMP
24287 .spin_is_locked = __ticket_spin_is_locked,
24288 .spin_is_contended = __ticket_spin_is_contended,
24289diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
24290index cd6de64..27c6af0 100644
24291--- a/arch/x86/kernel/paravirt.c
24292+++ b/arch/x86/kernel/paravirt.c
24293@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
24294 {
24295 return x;
24296 }
24297+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
24298+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
24299+#endif
24300
24301 void __init default_banner(void)
24302 {
24303@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
24304 if (opfunc == NULL)
24305 /* If there's no function, patch it with a ud2a (BUG) */
24306 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
24307- else if (opfunc == _paravirt_nop)
24308+ else if (opfunc == (void *)_paravirt_nop)
24309 /* If the operation is a nop, then nop the callsite */
24310 ret = paravirt_patch_nop();
24311
24312 /* identity functions just return their single argument */
24313- else if (opfunc == _paravirt_ident_32)
24314+ else if (opfunc == (void *)_paravirt_ident_32)
24315 ret = paravirt_patch_ident_32(insnbuf, len);
24316- else if (opfunc == _paravirt_ident_64)
24317+ else if (opfunc == (void *)_paravirt_ident_64)
24318 ret = paravirt_patch_ident_64(insnbuf, len);
24319+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
24320+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
24321+ ret = paravirt_patch_ident_64(insnbuf, len);
24322+#endif
24323
24324 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
24325 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
24326@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
24327 if (insn_len > len || start == NULL)
24328 insn_len = len;
24329 else
24330- memcpy(insnbuf, start, insn_len);
24331+ memcpy(insnbuf, ktla_ktva(start), insn_len);
24332
24333 return insn_len;
24334 }
24335@@ -304,7 +311,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
24336 return this_cpu_read(paravirt_lazy_mode);
24337 }
24338
24339-struct pv_info pv_info = {
24340+struct pv_info pv_info __read_only = {
24341 .name = "bare hardware",
24342 .paravirt_enabled = 0,
24343 .kernel_rpl = 0,
24344@@ -315,16 +322,16 @@ struct pv_info pv_info = {
24345 #endif
24346 };
24347
24348-struct pv_init_ops pv_init_ops = {
24349+struct pv_init_ops pv_init_ops __read_only = {
24350 .patch = native_patch,
24351 };
24352
24353-struct pv_time_ops pv_time_ops = {
24354+struct pv_time_ops pv_time_ops __read_only = {
24355 .sched_clock = native_sched_clock,
24356 .steal_clock = native_steal_clock,
24357 };
24358
24359-struct pv_irq_ops pv_irq_ops = {
24360+struct pv_irq_ops pv_irq_ops __read_only = {
24361 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
24362 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
24363 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
24364@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
24365 #endif
24366 };
24367
24368-struct pv_cpu_ops pv_cpu_ops = {
24369+struct pv_cpu_ops pv_cpu_ops __read_only = {
24370 .cpuid = native_cpuid,
24371 .get_debugreg = native_get_debugreg,
24372 .set_debugreg = native_set_debugreg,
24373@@ -394,21 +401,26 @@ struct pv_cpu_ops pv_cpu_ops = {
24374 .end_context_switch = paravirt_nop,
24375 };
24376
24377-struct pv_apic_ops pv_apic_ops = {
24378+struct pv_apic_ops pv_apic_ops __read_only= {
24379 #ifdef CONFIG_X86_LOCAL_APIC
24380 .startup_ipi_hook = paravirt_nop,
24381 #endif
24382 };
24383
24384-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
24385+#ifdef CONFIG_X86_32
24386+#ifdef CONFIG_X86_PAE
24387+/* 64-bit pagetable entries */
24388+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
24389+#else
24390 /* 32-bit pagetable entries */
24391 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
24392+#endif
24393 #else
24394 /* 64-bit pagetable entries */
24395 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
24396 #endif
24397
24398-struct pv_mmu_ops pv_mmu_ops = {
24399+struct pv_mmu_ops pv_mmu_ops __read_only = {
24400
24401 .read_cr2 = native_read_cr2,
24402 .write_cr2 = native_write_cr2,
24403@@ -458,6 +470,7 @@ struct pv_mmu_ops pv_mmu_ops = {
24404 .make_pud = PTE_IDENT,
24405
24406 .set_pgd = native_set_pgd,
24407+ .set_pgd_batched = native_set_pgd_batched,
24408 #endif
24409 #endif /* PAGETABLE_LEVELS >= 3 */
24410
24411@@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
24412 },
24413
24414 .set_fixmap = native_set_fixmap,
24415+
24416+#ifdef CONFIG_PAX_KERNEXEC
24417+ .pax_open_kernel = native_pax_open_kernel,
24418+ .pax_close_kernel = native_pax_close_kernel,
24419+#endif
24420+
24421 };
24422
24423 EXPORT_SYMBOL_GPL(pv_time_ops);
24424diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
24425index 299d493..2ccb0ee 100644
24426--- a/arch/x86/kernel/pci-calgary_64.c
24427+++ b/arch/x86/kernel/pci-calgary_64.c
24428@@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
24429 tce_space = be64_to_cpu(readq(target));
24430 tce_space = tce_space & TAR_SW_BITS;
24431
24432- tce_space = tce_space & (~specified_table_size);
24433+ tce_space = tce_space & (~(unsigned long)specified_table_size);
24434 info->tce_space = (u64 *)__va(tce_space);
24435 }
24436 }
24437diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
24438index 35ccf75..7a15747 100644
24439--- a/arch/x86/kernel/pci-iommu_table.c
24440+++ b/arch/x86/kernel/pci-iommu_table.c
24441@@ -2,7 +2,7 @@
24442 #include <asm/iommu_table.h>
24443 #include <linux/string.h>
24444 #include <linux/kallsyms.h>
24445-
24446+#include <linux/sched.h>
24447
24448 #define DEBUG 1
24449
24450diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
24451index 6c483ba..d10ce2f 100644
24452--- a/arch/x86/kernel/pci-swiotlb.c
24453+++ b/arch/x86/kernel/pci-swiotlb.c
24454@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
24455 void *vaddr, dma_addr_t dma_addr,
24456 struct dma_attrs *attrs)
24457 {
24458- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
24459+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
24460 }
24461
24462 static struct dma_map_ops swiotlb_dma_ops = {
24463diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
24464index 83369e5..52b93f0 100644
24465--- a/arch/x86/kernel/process.c
24466+++ b/arch/x86/kernel/process.c
24467@@ -36,7 +36,8 @@
24468 * section. Since TSS's are completely CPU-local, we want them
24469 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
24470 */
24471-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
24472+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
24473+EXPORT_SYMBOL(init_tss);
24474
24475 #ifdef CONFIG_X86_64
24476 static DEFINE_PER_CPU(unsigned char, is_idle);
24477@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
24478 task_xstate_cachep =
24479 kmem_cache_create("task_xstate", xstate_size,
24480 __alignof__(union thread_xstate),
24481- SLAB_PANIC | SLAB_NOTRACK, NULL);
24482+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
24483 }
24484
24485 /*
24486@@ -105,7 +106,7 @@ void exit_thread(void)
24487 unsigned long *bp = t->io_bitmap_ptr;
24488
24489 if (bp) {
24490- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
24491+ struct tss_struct *tss = init_tss + get_cpu();
24492
24493 t->io_bitmap_ptr = NULL;
24494 clear_thread_flag(TIF_IO_BITMAP);
24495@@ -125,6 +126,9 @@ void flush_thread(void)
24496 {
24497 struct task_struct *tsk = current;
24498
24499+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
24500+ loadsegment(gs, 0);
24501+#endif
24502 flush_ptrace_hw_breakpoint(tsk);
24503 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
24504 drop_init_fpu(tsk);
24505@@ -271,7 +275,7 @@ static void __exit_idle(void)
24506 void exit_idle(void)
24507 {
24508 /* idle loop has pid 0 */
24509- if (current->pid)
24510+ if (task_pid_nr(current))
24511 return;
24512 __exit_idle();
24513 }
24514@@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
24515 return ret;
24516 }
24517 #endif
24518-void stop_this_cpu(void *dummy)
24519+__noreturn void stop_this_cpu(void *dummy)
24520 {
24521 local_irq_disable();
24522 /*
24523@@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
24524 }
24525 early_param("idle", idle_setup);
24526
24527-unsigned long arch_align_stack(unsigned long sp)
24528+#ifdef CONFIG_PAX_RANDKSTACK
24529+void pax_randomize_kstack(struct pt_regs *regs)
24530 {
24531- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
24532- sp -= get_random_int() % 8192;
24533- return sp & ~0xf;
24534-}
24535+ struct thread_struct *thread = &current->thread;
24536+ unsigned long time;
24537
24538-unsigned long arch_randomize_brk(struct mm_struct *mm)
24539-{
24540- unsigned long range_end = mm->brk + 0x02000000;
24541- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
24542-}
24543+ if (!randomize_va_space)
24544+ return;
24545+
24546+ if (v8086_mode(regs))
24547+ return;
24548
24549+ rdtscl(time);
24550+
24551+ /* P4 seems to return a 0 LSB, ignore it */
24552+#ifdef CONFIG_MPENTIUM4
24553+ time &= 0x3EUL;
24554+ time <<= 2;
24555+#elif defined(CONFIG_X86_64)
24556+ time &= 0xFUL;
24557+ time <<= 4;
24558+#else
24559+ time &= 0x1FUL;
24560+ time <<= 3;
24561+#endif
24562+
24563+ thread->sp0 ^= time;
24564+ load_sp0(init_tss + smp_processor_id(), thread);
24565+
24566+#ifdef CONFIG_X86_64
24567+ this_cpu_write(kernel_stack, thread->sp0);
24568+#endif
24569+}
24570+#endif
24571diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
24572index f8adefc..4bce3d6 100644
24573--- a/arch/x86/kernel/process_32.c
24574+++ b/arch/x86/kernel/process_32.c
24575@@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
24576 unsigned long thread_saved_pc(struct task_struct *tsk)
24577 {
24578 return ((unsigned long *)tsk->thread.sp)[3];
24579+//XXX return tsk->thread.eip;
24580 }
24581
24582 void __show_regs(struct pt_regs *regs, int all)
24583@@ -74,19 +75,18 @@ void __show_regs(struct pt_regs *regs, int all)
24584 unsigned long sp;
24585 unsigned short ss, gs;
24586
24587- if (user_mode_vm(regs)) {
24588+ if (user_mode(regs)) {
24589 sp = regs->sp;
24590 ss = regs->ss & 0xffff;
24591- gs = get_user_gs(regs);
24592 } else {
24593 sp = kernel_stack_pointer(regs);
24594 savesegment(ss, ss);
24595- savesegment(gs, gs);
24596 }
24597+ gs = get_user_gs(regs);
24598
24599 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
24600 (u16)regs->cs, regs->ip, regs->flags,
24601- smp_processor_id());
24602+ raw_smp_processor_id());
24603 print_symbol("EIP is at %s\n", regs->ip);
24604
24605 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
24606@@ -133,20 +133,21 @@ void release_thread(struct task_struct *dead_task)
24607 int copy_thread(unsigned long clone_flags, unsigned long sp,
24608 unsigned long arg, struct task_struct *p)
24609 {
24610- struct pt_regs *childregs = task_pt_regs(p);
24611+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
24612 struct task_struct *tsk;
24613 int err;
24614
24615 p->thread.sp = (unsigned long) childregs;
24616 p->thread.sp0 = (unsigned long) (childregs+1);
24617+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
24618
24619 if (unlikely(p->flags & PF_KTHREAD)) {
24620 /* kernel thread */
24621 memset(childregs, 0, sizeof(struct pt_regs));
24622 p->thread.ip = (unsigned long) ret_from_kernel_thread;
24623- task_user_gs(p) = __KERNEL_STACK_CANARY;
24624- childregs->ds = __USER_DS;
24625- childregs->es = __USER_DS;
24626+ savesegment(gs, childregs->gs);
24627+ childregs->ds = __KERNEL_DS;
24628+ childregs->es = __KERNEL_DS;
24629 childregs->fs = __KERNEL_PERCPU;
24630 childregs->bx = sp; /* function */
24631 childregs->bp = arg;
24632@@ -253,7 +254,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24633 struct thread_struct *prev = &prev_p->thread,
24634 *next = &next_p->thread;
24635 int cpu = smp_processor_id();
24636- struct tss_struct *tss = &per_cpu(init_tss, cpu);
24637+ struct tss_struct *tss = init_tss + cpu;
24638 fpu_switch_t fpu;
24639
24640 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
24641@@ -277,6 +278,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24642 */
24643 lazy_save_gs(prev->gs);
24644
24645+#ifdef CONFIG_PAX_MEMORY_UDEREF
24646+ __set_fs(task_thread_info(next_p)->addr_limit);
24647+#endif
24648+
24649 /*
24650 * Load the per-thread Thread-Local Storage descriptor.
24651 */
24652@@ -307,6 +312,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24653 */
24654 arch_end_context_switch(next_p);
24655
24656+ this_cpu_write(current_task, next_p);
24657+ this_cpu_write(current_tinfo, &next_p->tinfo);
24658+
24659 /*
24660 * Restore %gs if needed (which is common)
24661 */
24662@@ -315,8 +323,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24663
24664 switch_fpu_finish(next_p, fpu);
24665
24666- this_cpu_write(current_task, next_p);
24667-
24668 return prev_p;
24669 }
24670
24671@@ -346,4 +352,3 @@ unsigned long get_wchan(struct task_struct *p)
24672 } while (count++ < 16);
24673 return 0;
24674 }
24675-
24676diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
24677index 05646ba..0c2906d 100644
24678--- a/arch/x86/kernel/process_64.c
24679+++ b/arch/x86/kernel/process_64.c
24680@@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
24681 struct pt_regs *childregs;
24682 struct task_struct *me = current;
24683
24684- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
24685+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
24686 childregs = task_pt_regs(p);
24687 p->thread.sp = (unsigned long) childregs;
24688 p->thread.usersp = me->thread.usersp;
24689+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
24690 set_tsk_thread_flag(p, TIF_FORK);
24691 p->fpu_counter = 0;
24692 p->thread.io_bitmap_ptr = NULL;
24693@@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
24694 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
24695 savesegment(es, p->thread.es);
24696 savesegment(ds, p->thread.ds);
24697+ savesegment(ss, p->thread.ss);
24698+ BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
24699 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
24700
24701 if (unlikely(p->flags & PF_KTHREAD)) {
24702@@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24703 struct thread_struct *prev = &prev_p->thread;
24704 struct thread_struct *next = &next_p->thread;
24705 int cpu = smp_processor_id();
24706- struct tss_struct *tss = &per_cpu(init_tss, cpu);
24707+ struct tss_struct *tss = init_tss + cpu;
24708 unsigned fsindex, gsindex;
24709 fpu_switch_t fpu;
24710
24711@@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24712 if (unlikely(next->ds | prev->ds))
24713 loadsegment(ds, next->ds);
24714
24715+ savesegment(ss, prev->ss);
24716+ if (unlikely(next->ss != prev->ss))
24717+ loadsegment(ss, next->ss);
24718
24719 /* We must save %fs and %gs before load_TLS() because
24720 * %fs and %gs may be cleared by load_TLS().
24721@@ -362,10 +368,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24722 prev->usersp = this_cpu_read(old_rsp);
24723 this_cpu_write(old_rsp, next->usersp);
24724 this_cpu_write(current_task, next_p);
24725+ this_cpu_write(current_tinfo, &next_p->tinfo);
24726
24727- this_cpu_write(kernel_stack,
24728- (unsigned long)task_stack_page(next_p) +
24729- THREAD_SIZE - KERNEL_STACK_OFFSET);
24730+ this_cpu_write(kernel_stack, next->sp0);
24731
24732 /*
24733 * Now maybe reload the debug registers and handle I/O bitmaps
24734@@ -434,12 +439,11 @@ unsigned long get_wchan(struct task_struct *p)
24735 if (!p || p == current || p->state == TASK_RUNNING)
24736 return 0;
24737 stack = (unsigned long)task_stack_page(p);
24738- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
24739+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
24740 return 0;
24741 fp = *(u64 *)(p->thread.sp);
24742 do {
24743- if (fp < (unsigned long)stack ||
24744- fp >= (unsigned long)stack+THREAD_SIZE)
24745+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
24746 return 0;
24747 ip = *(u64 *)(fp+8);
24748 if (!in_sched_functions(ip))
24749diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
24750index 7461f50..1334029 100644
24751--- a/arch/x86/kernel/ptrace.c
24752+++ b/arch/x86/kernel/ptrace.c
24753@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
24754 {
24755 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
24756 unsigned long sp = (unsigned long)&regs->sp;
24757- struct thread_info *tinfo;
24758
24759- if (context == (sp & ~(THREAD_SIZE - 1)))
24760+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
24761 return sp;
24762
24763- tinfo = (struct thread_info *)context;
24764- if (tinfo->previous_esp)
24765- return tinfo->previous_esp;
24766+ sp = *(unsigned long *)context;
24767+ if (sp)
24768+ return sp;
24769
24770 return (unsigned long)regs;
24771 }
24772@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
24773 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
24774 {
24775 int i;
24776- int dr7 = 0;
24777+ unsigned long dr7 = 0;
24778 struct arch_hw_breakpoint *info;
24779
24780 for (i = 0; i < HBP_NUM; i++) {
24781@@ -822,7 +821,7 @@ long arch_ptrace(struct task_struct *child, long request,
24782 unsigned long addr, unsigned long data)
24783 {
24784 int ret;
24785- unsigned long __user *datap = (unsigned long __user *)data;
24786+ unsigned long __user *datap = (__force unsigned long __user *)data;
24787
24788 switch (request) {
24789 /* read the word at location addr in the USER area. */
24790@@ -907,14 +906,14 @@ long arch_ptrace(struct task_struct *child, long request,
24791 if ((int) addr < 0)
24792 return -EIO;
24793 ret = do_get_thread_area(child, addr,
24794- (struct user_desc __user *)data);
24795+ (__force struct user_desc __user *) data);
24796 break;
24797
24798 case PTRACE_SET_THREAD_AREA:
24799 if ((int) addr < 0)
24800 return -EIO;
24801 ret = do_set_thread_area(child, addr,
24802- (struct user_desc __user *)data, 0);
24803+ (__force struct user_desc __user *) data, 0);
24804 break;
24805 #endif
24806
24807@@ -1292,7 +1291,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
24808
24809 #ifdef CONFIG_X86_64
24810
24811-static struct user_regset x86_64_regsets[] __read_mostly = {
24812+static user_regset_no_const x86_64_regsets[] __read_only = {
24813 [REGSET_GENERAL] = {
24814 .core_note_type = NT_PRSTATUS,
24815 .n = sizeof(struct user_regs_struct) / sizeof(long),
24816@@ -1333,7 +1332,7 @@ static const struct user_regset_view user_x86_64_view = {
24817 #endif /* CONFIG_X86_64 */
24818
24819 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
24820-static struct user_regset x86_32_regsets[] __read_mostly = {
24821+static user_regset_no_const x86_32_regsets[] __read_only = {
24822 [REGSET_GENERAL] = {
24823 .core_note_type = NT_PRSTATUS,
24824 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
24825@@ -1386,7 +1385,7 @@ static const struct user_regset_view user_x86_32_view = {
24826 */
24827 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
24828
24829-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
24830+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
24831 {
24832 #ifdef CONFIG_X86_64
24833 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
24834@@ -1421,7 +1420,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
24835 memset(info, 0, sizeof(*info));
24836 info->si_signo = SIGTRAP;
24837 info->si_code = si_code;
24838- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
24839+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
24840 }
24841
24842 void user_single_step_siginfo(struct task_struct *tsk,
24843@@ -1450,6 +1449,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
24844 # define IS_IA32 0
24845 #endif
24846
24847+#ifdef CONFIG_GRKERNSEC_SETXID
24848+extern void gr_delayed_cred_worker(void);
24849+#endif
24850+
24851 /*
24852 * We must return the syscall number to actually look up in the table.
24853 * This can be -1L to skip running any syscall at all.
24854@@ -1460,6 +1463,11 @@ long syscall_trace_enter(struct pt_regs *regs)
24855
24856 user_exit();
24857
24858+#ifdef CONFIG_GRKERNSEC_SETXID
24859+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
24860+ gr_delayed_cred_worker();
24861+#endif
24862+
24863 /*
24864 * If we stepped into a sysenter/syscall insn, it trapped in
24865 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
24866@@ -1515,6 +1523,11 @@ void syscall_trace_leave(struct pt_regs *regs)
24867 */
24868 user_exit();
24869
24870+#ifdef CONFIG_GRKERNSEC_SETXID
24871+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
24872+ gr_delayed_cred_worker();
24873+#endif
24874+
24875 audit_syscall_exit(regs);
24876
24877 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
24878diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
24879index 2cb9470..ff1fd80 100644
24880--- a/arch/x86/kernel/pvclock.c
24881+++ b/arch/x86/kernel/pvclock.c
24882@@ -43,11 +43,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
24883 return pv_tsc_khz;
24884 }
24885
24886-static atomic64_t last_value = ATOMIC64_INIT(0);
24887+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
24888
24889 void pvclock_resume(void)
24890 {
24891- atomic64_set(&last_value, 0);
24892+ atomic64_set_unchecked(&last_value, 0);
24893 }
24894
24895 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
24896@@ -92,11 +92,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
24897 * updating at the same time, and one of them could be slightly behind,
24898 * making the assumption that last_value always go forward fail to hold.
24899 */
24900- last = atomic64_read(&last_value);
24901+ last = atomic64_read_unchecked(&last_value);
24902 do {
24903 if (ret < last)
24904 return last;
24905- last = atomic64_cmpxchg(&last_value, last, ret);
24906+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
24907 } while (unlikely(last != ret));
24908
24909 return ret;
24910diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
24911index 5f4ad27..9d96c99 100644
24912--- a/arch/x86/kernel/reboot.c
24913+++ b/arch/x86/kernel/reboot.c
24914@@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
24915
24916 void __noreturn machine_real_restart(unsigned int type)
24917 {
24918+
24919+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
24920+ struct desc_struct *gdt;
24921+#endif
24922+
24923 local_irq_disable();
24924
24925 /*
24926@@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
24927
24928 /* Jump to the identity-mapped low memory code */
24929 #ifdef CONFIG_X86_32
24930- asm volatile("jmpl *%0" : :
24931+
24932+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
24933+ gdt = get_cpu_gdt_table(smp_processor_id());
24934+ pax_open_kernel();
24935+#ifdef CONFIG_PAX_MEMORY_UDEREF
24936+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
24937+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
24938+ loadsegment(ds, __KERNEL_DS);
24939+ loadsegment(es, __KERNEL_DS);
24940+ loadsegment(ss, __KERNEL_DS);
24941+#endif
24942+#ifdef CONFIG_PAX_KERNEXEC
24943+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
24944+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
24945+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
24946+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
24947+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
24948+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
24949+#endif
24950+ pax_close_kernel();
24951+#endif
24952+
24953+ asm volatile("ljmpl *%0" : :
24954 "rm" (real_mode_header->machine_real_restart_asm),
24955 "a" (type));
24956 #else
24957@@ -458,7 +485,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
24958 * try to force a triple fault and then cycle between hitting the keyboard
24959 * controller and doing that
24960 */
24961-static void native_machine_emergency_restart(void)
24962+static void __noreturn native_machine_emergency_restart(void)
24963 {
24964 int i;
24965 int attempt = 0;
24966@@ -567,13 +594,13 @@ void native_machine_shutdown(void)
24967 #endif
24968 }
24969
24970-static void __machine_emergency_restart(int emergency)
24971+static void __noreturn __machine_emergency_restart(int emergency)
24972 {
24973 reboot_emergency = emergency;
24974 machine_ops.emergency_restart();
24975 }
24976
24977-static void native_machine_restart(char *__unused)
24978+static void __noreturn native_machine_restart(char *__unused)
24979 {
24980 pr_notice("machine restart\n");
24981
24982@@ -582,7 +609,7 @@ static void native_machine_restart(char *__unused)
24983 __machine_emergency_restart(0);
24984 }
24985
24986-static void native_machine_halt(void)
24987+static void __noreturn native_machine_halt(void)
24988 {
24989 /* Stop other cpus and apics */
24990 machine_shutdown();
24991@@ -592,7 +619,7 @@ static void native_machine_halt(void)
24992 stop_this_cpu(NULL);
24993 }
24994
24995-static void native_machine_power_off(void)
24996+static void __noreturn native_machine_power_off(void)
24997 {
24998 if (pm_power_off) {
24999 if (!reboot_force)
25000@@ -601,9 +628,10 @@ static void native_machine_power_off(void)
25001 }
25002 /* A fallback in case there is no PM info available */
25003 tboot_shutdown(TB_SHUTDOWN_HALT);
25004+ unreachable();
25005 }
25006
25007-struct machine_ops machine_ops = {
25008+struct machine_ops machine_ops __read_only = {
25009 .power_off = native_machine_power_off,
25010 .shutdown = native_machine_shutdown,
25011 .emergency_restart = native_machine_emergency_restart,
25012diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
25013index c8e41e9..64049ef 100644
25014--- a/arch/x86/kernel/reboot_fixups_32.c
25015+++ b/arch/x86/kernel/reboot_fixups_32.c
25016@@ -57,7 +57,7 @@ struct device_fixup {
25017 unsigned int vendor;
25018 unsigned int device;
25019 void (*reboot_fixup)(struct pci_dev *);
25020-};
25021+} __do_const;
25022
25023 /*
25024 * PCI ids solely used for fixups_table go here
25025diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
25026index 3fd2c69..16ef367 100644
25027--- a/arch/x86/kernel/relocate_kernel_64.S
25028+++ b/arch/x86/kernel/relocate_kernel_64.S
25029@@ -11,6 +11,7 @@
25030 #include <asm/kexec.h>
25031 #include <asm/processor-flags.h>
25032 #include <asm/pgtable_types.h>
25033+#include <asm/alternative-asm.h>
25034
25035 /*
25036 * Must be relocatable PIC code callable as a C function
25037@@ -96,8 +97,7 @@ relocate_kernel:
25038
25039 /* jump to identity mapped page */
25040 addq $(identity_mapped - relocate_kernel), %r8
25041- pushq %r8
25042- ret
25043+ jmp *%r8
25044
25045 identity_mapped:
25046 /* set return address to 0 if not preserving context */
25047@@ -167,6 +167,7 @@ identity_mapped:
25048 xorl %r14d, %r14d
25049 xorl %r15d, %r15d
25050
25051+ pax_force_retaddr 0, 1
25052 ret
25053
25054 1:
25055diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
25056index 234e1e3..1246d05 100644
25057--- a/arch/x86/kernel/setup.c
25058+++ b/arch/x86/kernel/setup.c
25059@@ -110,6 +110,7 @@
25060 #include <asm/mce.h>
25061 #include <asm/alternative.h>
25062 #include <asm/prom.h>
25063+#include <asm/boot.h>
25064
25065 /*
25066 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
25067@@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
25068 #endif
25069
25070
25071-#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
25072-unsigned long mmu_cr4_features;
25073+#ifdef CONFIG_X86_64
25074+unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
25075+#elif defined(CONFIG_X86_PAE)
25076+unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
25077 #else
25078-unsigned long mmu_cr4_features = X86_CR4_PAE;
25079+unsigned long mmu_cr4_features __read_only;
25080 #endif
25081
25082+void set_in_cr4(unsigned long mask)
25083+{
25084+ unsigned long cr4 = read_cr4();
25085+
25086+ if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
25087+ return;
25088+
25089+ pax_open_kernel();
25090+ mmu_cr4_features |= mask;
25091+ pax_close_kernel();
25092+
25093+ if (trampoline_cr4_features)
25094+ *trampoline_cr4_features = mmu_cr4_features;
25095+ cr4 |= mask;
25096+ write_cr4(cr4);
25097+}
25098+EXPORT_SYMBOL(set_in_cr4);
25099+
25100+void clear_in_cr4(unsigned long mask)
25101+{
25102+ unsigned long cr4 = read_cr4();
25103+
25104+ if (!(cr4 & mask) && cr4 == mmu_cr4_features)
25105+ return;
25106+
25107+ pax_open_kernel();
25108+ mmu_cr4_features &= ~mask;
25109+ pax_close_kernel();
25110+
25111+ if (trampoline_cr4_features)
25112+ *trampoline_cr4_features = mmu_cr4_features;
25113+ cr4 &= ~mask;
25114+ write_cr4(cr4);
25115+}
25116+EXPORT_SYMBOL(clear_in_cr4);
25117+
25118 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
25119 int bootloader_type, bootloader_version;
25120
25121@@ -442,7 +481,7 @@ static void __init parse_setup_data(void)
25122
25123 switch (data_type) {
25124 case SETUP_E820_EXT:
25125- parse_e820_ext(pa_data, data_len);
25126+ parse_e820_ext((struct setup_data __force_kernel *)pa_data, data_len);
25127 break;
25128 case SETUP_DTB:
25129 add_dtb(pa_data);
25130@@ -768,7 +807,7 @@ static void __init trim_bios_range(void)
25131 * area (640->1Mb) as ram even though it is not.
25132 * take them out.
25133 */
25134- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
25135+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
25136
25137 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
25138 }
25139@@ -776,7 +815,7 @@ static void __init trim_bios_range(void)
25140 /* called before trim_bios_range() to spare extra sanitize */
25141 static void __init e820_add_kernel_range(void)
25142 {
25143- u64 start = __pa_symbol(_text);
25144+ u64 start = __pa_symbol(ktla_ktva(_text));
25145 u64 size = __pa_symbol(_end) - start;
25146
25147 /*
25148@@ -838,8 +877,12 @@ static void __init trim_low_memory_range(void)
25149
25150 void __init setup_arch(char **cmdline_p)
25151 {
25152+#ifdef CONFIG_X86_32
25153+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
25154+#else
25155 memblock_reserve(__pa_symbol(_text),
25156 (unsigned long)__bss_stop - (unsigned long)_text);
25157+#endif
25158
25159 early_reserve_initrd();
25160
25161@@ -931,14 +974,14 @@ void __init setup_arch(char **cmdline_p)
25162
25163 if (!boot_params.hdr.root_flags)
25164 root_mountflags &= ~MS_RDONLY;
25165- init_mm.start_code = (unsigned long) _text;
25166- init_mm.end_code = (unsigned long) _etext;
25167+ init_mm.start_code = ktla_ktva((unsigned long) _text);
25168+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
25169 init_mm.end_data = (unsigned long) _edata;
25170 init_mm.brk = _brk_end;
25171
25172- code_resource.start = __pa_symbol(_text);
25173- code_resource.end = __pa_symbol(_etext)-1;
25174- data_resource.start = __pa_symbol(_etext);
25175+ code_resource.start = __pa_symbol(ktla_ktva(_text));
25176+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
25177+ data_resource.start = __pa_symbol(_sdata);
25178 data_resource.end = __pa_symbol(_edata)-1;
25179 bss_resource.start = __pa_symbol(__bss_start);
25180 bss_resource.end = __pa_symbol(__bss_stop)-1;
25181diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
25182index 5cdff03..80fa283 100644
25183--- a/arch/x86/kernel/setup_percpu.c
25184+++ b/arch/x86/kernel/setup_percpu.c
25185@@ -21,19 +21,17 @@
25186 #include <asm/cpu.h>
25187 #include <asm/stackprotector.h>
25188
25189-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
25190+#ifdef CONFIG_SMP
25191+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
25192 EXPORT_PER_CPU_SYMBOL(cpu_number);
25193+#endif
25194
25195-#ifdef CONFIG_X86_64
25196 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
25197-#else
25198-#define BOOT_PERCPU_OFFSET 0
25199-#endif
25200
25201 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
25202 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
25203
25204-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
25205+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
25206 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
25207 };
25208 EXPORT_SYMBOL(__per_cpu_offset);
25209@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
25210 {
25211 #ifdef CONFIG_NEED_MULTIPLE_NODES
25212 pg_data_t *last = NULL;
25213- unsigned int cpu;
25214+ int cpu;
25215
25216 for_each_possible_cpu(cpu) {
25217 int node = early_cpu_to_node(cpu);
25218@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
25219 {
25220 #ifdef CONFIG_X86_32
25221 struct desc_struct gdt;
25222+ unsigned long base = per_cpu_offset(cpu);
25223
25224- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
25225- 0x2 | DESCTYPE_S, 0x8);
25226- gdt.s = 1;
25227+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
25228+ 0x83 | DESCTYPE_S, 0xC);
25229 write_gdt_entry(get_cpu_gdt_table(cpu),
25230 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
25231 #endif
25232@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
25233 /* alrighty, percpu areas up and running */
25234 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
25235 for_each_possible_cpu(cpu) {
25236+#ifdef CONFIG_CC_STACKPROTECTOR
25237+#ifdef CONFIG_X86_32
25238+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
25239+#endif
25240+#endif
25241 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
25242 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
25243 per_cpu(cpu_number, cpu) = cpu;
25244@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
25245 */
25246 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
25247 #endif
25248+#ifdef CONFIG_CC_STACKPROTECTOR
25249+#ifdef CONFIG_X86_32
25250+ if (!cpu)
25251+ per_cpu(stack_canary.canary, cpu) = canary;
25252+#endif
25253+#endif
25254 /*
25255 * Up to this point, the boot CPU has been using .init.data
25256 * area. Reload any changed state for the boot CPU.
25257diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
25258index d859eea..44e17c4 100644
25259--- a/arch/x86/kernel/signal.c
25260+++ b/arch/x86/kernel/signal.c
25261@@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
25262 * Align the stack pointer according to the i386 ABI,
25263 * i.e. so that on function entry ((sp + 4) & 15) == 0.
25264 */
25265- sp = ((sp + 4) & -16ul) - 4;
25266+ sp = ((sp - 12) & -16ul) - 4;
25267 #else /* !CONFIG_X86_32 */
25268 sp = round_down(sp, 16) - 8;
25269 #endif
25270@@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
25271 }
25272
25273 if (current->mm->context.vdso)
25274- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
25275+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
25276 else
25277- restorer = &frame->retcode;
25278+ restorer = (void __user *)&frame->retcode;
25279 if (ksig->ka.sa.sa_flags & SA_RESTORER)
25280 restorer = ksig->ka.sa.sa_restorer;
25281
25282@@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
25283 * reasons and because gdb uses it as a signature to notice
25284 * signal handler stack frames.
25285 */
25286- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
25287+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
25288
25289 if (err)
25290 return -EFAULT;
25291@@ -361,7 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
25292 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
25293
25294 /* Set up to return from userspace. */
25295- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
25296+ if (current->mm->context.vdso)
25297+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
25298+ else
25299+ restorer = (void __user *)&frame->retcode;
25300 if (ksig->ka.sa.sa_flags & SA_RESTORER)
25301 restorer = ksig->ka.sa.sa_restorer;
25302 put_user_ex(restorer, &frame->pretcode);
25303@@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
25304 * reasons and because gdb uses it as a signature to notice
25305 * signal handler stack frames.
25306 */
25307- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
25308+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
25309 } put_user_catch(err);
25310
25311 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
25312@@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
25313 {
25314 int usig = signr_convert(ksig->sig);
25315 sigset_t *set = sigmask_to_save();
25316- compat_sigset_t *cset = (compat_sigset_t *) set;
25317+ sigset_t sigcopy;
25318+ compat_sigset_t *cset;
25319+
25320+ sigcopy = *set;
25321+
25322+ cset = (compat_sigset_t *) &sigcopy;
25323
25324 /* Set up the stack frame */
25325 if (is_ia32_frame()) {
25326@@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
25327 } else if (is_x32_frame()) {
25328 return x32_setup_rt_frame(ksig, cset, regs);
25329 } else {
25330- return __setup_rt_frame(ksig->sig, ksig, set, regs);
25331+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
25332 }
25333 }
25334
25335diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
25336index cdaa347..f5af55d 100644
25337--- a/arch/x86/kernel/smp.c
25338+++ b/arch/x86/kernel/smp.c
25339@@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
25340
25341 __setup("nonmi_ipi", nonmi_ipi_setup);
25342
25343-struct smp_ops smp_ops = {
25344+struct smp_ops smp_ops __read_only = {
25345 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
25346 .smp_prepare_cpus = native_smp_prepare_cpus,
25347 .smp_cpus_done = native_smp_cpus_done,
25348diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
25349index aecc98a..0244a53 100644
25350--- a/arch/x86/kernel/smpboot.c
25351+++ b/arch/x86/kernel/smpboot.c
25352@@ -251,14 +251,18 @@ static void notrace start_secondary(void *unused)
25353
25354 enable_start_cpu0 = 0;
25355
25356-#ifdef CONFIG_X86_32
25357- /* switch away from the initial page table */
25358- load_cr3(swapper_pg_dir);
25359- __flush_tlb_all();
25360-#endif
25361-
25362 /* otherwise gcc will move up smp_processor_id before the cpu_init */
25363 barrier();
25364+
25365+ /* switch away from the initial page table */
25366+#ifdef CONFIG_PAX_PER_CPU_PGD
25367+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
25368+ __flush_tlb_all();
25369+#elif defined(CONFIG_X86_32)
25370+ load_cr3(swapper_pg_dir);
25371+ __flush_tlb_all();
25372+#endif
25373+
25374 /*
25375 * Check TSC synchronization with the BP:
25376 */
25377@@ -748,6 +752,7 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
25378 idle->thread.sp = (unsigned long) (((struct pt_regs *)
25379 (THREAD_SIZE + task_stack_page(idle))) - 1);
25380 per_cpu(current_task, cpu) = idle;
25381+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
25382
25383 #ifdef CONFIG_X86_32
25384 /* Stack for startup_32 can be just as for start_secondary onwards */
25385@@ -755,11 +760,13 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
25386 #else
25387 clear_tsk_thread_flag(idle, TIF_FORK);
25388 initial_gs = per_cpu_offset(cpu);
25389- per_cpu(kernel_stack, cpu) =
25390- (unsigned long)task_stack_page(idle) -
25391- KERNEL_STACK_OFFSET + THREAD_SIZE;
25392+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
25393 #endif
25394+
25395+ pax_open_kernel();
25396 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
25397+ pax_close_kernel();
25398+
25399 initial_code = (unsigned long)start_secondary;
25400 stack_start = idle->thread.sp;
25401
25402@@ -908,6 +915,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
25403 /* the FPU context is blank, nobody can own it */
25404 __cpu_disable_lazy_restore(cpu);
25405
25406+#ifdef CONFIG_PAX_PER_CPU_PGD
25407+ clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
25408+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25409+ KERNEL_PGD_PTRS);
25410+ clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
25411+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25412+ KERNEL_PGD_PTRS);
25413+#endif
25414+
25415 err = do_boot_cpu(apicid, cpu, tidle);
25416 if (err) {
25417 pr_debug("do_boot_cpu failed %d\n", err);
25418diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
25419index 9b4d51d..5d28b58 100644
25420--- a/arch/x86/kernel/step.c
25421+++ b/arch/x86/kernel/step.c
25422@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
25423 struct desc_struct *desc;
25424 unsigned long base;
25425
25426- seg &= ~7UL;
25427+ seg >>= 3;
25428
25429 mutex_lock(&child->mm->context.lock);
25430- if (unlikely((seg >> 3) >= child->mm->context.size))
25431+ if (unlikely(seg >= child->mm->context.size))
25432 addr = -1L; /* bogus selector, access would fault */
25433 else {
25434 desc = child->mm->context.ldt + seg;
25435@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
25436 addr += base;
25437 }
25438 mutex_unlock(&child->mm->context.lock);
25439- }
25440+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
25441+ addr = ktla_ktva(addr);
25442
25443 return addr;
25444 }
25445@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
25446 unsigned char opcode[15];
25447 unsigned long addr = convert_ip_to_linear(child, regs);
25448
25449+ if (addr == -EINVAL)
25450+ return 0;
25451+
25452 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
25453 for (i = 0; i < copied; i++) {
25454 switch (opcode[i]) {
25455diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
25456new file mode 100644
25457index 0000000..5877189
25458--- /dev/null
25459+++ b/arch/x86/kernel/sys_i386_32.c
25460@@ -0,0 +1,189 @@
25461+/*
25462+ * This file contains various random system calls that
25463+ * have a non-standard calling sequence on the Linux/i386
25464+ * platform.
25465+ */
25466+
25467+#include <linux/errno.h>
25468+#include <linux/sched.h>
25469+#include <linux/mm.h>
25470+#include <linux/fs.h>
25471+#include <linux/smp.h>
25472+#include <linux/sem.h>
25473+#include <linux/msg.h>
25474+#include <linux/shm.h>
25475+#include <linux/stat.h>
25476+#include <linux/syscalls.h>
25477+#include <linux/mman.h>
25478+#include <linux/file.h>
25479+#include <linux/utsname.h>
25480+#include <linux/ipc.h>
25481+#include <linux/elf.h>
25482+
25483+#include <linux/uaccess.h>
25484+#include <linux/unistd.h>
25485+
25486+#include <asm/syscalls.h>
25487+
25488+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
25489+{
25490+ unsigned long pax_task_size = TASK_SIZE;
25491+
25492+#ifdef CONFIG_PAX_SEGMEXEC
25493+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
25494+ pax_task_size = SEGMEXEC_TASK_SIZE;
25495+#endif
25496+
25497+ if (flags & MAP_FIXED)
25498+ if (len > pax_task_size || addr > pax_task_size - len)
25499+ return -EINVAL;
25500+
25501+ return 0;
25502+}
25503+
25504+/*
25505+ * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
25506+ */
25507+static unsigned long get_align_mask(void)
25508+{
25509+ if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
25510+ return 0;
25511+
25512+ if (!(current->flags & PF_RANDOMIZE))
25513+ return 0;
25514+
25515+ return va_align.mask;
25516+}
25517+
25518+unsigned long
25519+arch_get_unmapped_area(struct file *filp, unsigned long addr,
25520+ unsigned long len, unsigned long pgoff, unsigned long flags)
25521+{
25522+ struct mm_struct *mm = current->mm;
25523+ struct vm_area_struct *vma;
25524+ unsigned long pax_task_size = TASK_SIZE;
25525+ struct vm_unmapped_area_info info;
25526+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25527+
25528+#ifdef CONFIG_PAX_SEGMEXEC
25529+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25530+ pax_task_size = SEGMEXEC_TASK_SIZE;
25531+#endif
25532+
25533+ pax_task_size -= PAGE_SIZE;
25534+
25535+ if (len > pax_task_size)
25536+ return -ENOMEM;
25537+
25538+ if (flags & MAP_FIXED)
25539+ return addr;
25540+
25541+#ifdef CONFIG_PAX_RANDMMAP
25542+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25543+#endif
25544+
25545+ if (addr) {
25546+ addr = PAGE_ALIGN(addr);
25547+ if (pax_task_size - len >= addr) {
25548+ vma = find_vma(mm, addr);
25549+ if (check_heap_stack_gap(vma, addr, len, offset))
25550+ return addr;
25551+ }
25552+ }
25553+
25554+ info.flags = 0;
25555+ info.length = len;
25556+ info.align_mask = filp ? get_align_mask() : 0;
25557+ info.align_offset = pgoff << PAGE_SHIFT;
25558+ info.threadstack_offset = offset;
25559+
25560+#ifdef CONFIG_PAX_PAGEEXEC
25561+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
25562+ info.low_limit = 0x00110000UL;
25563+ info.high_limit = mm->start_code;
25564+
25565+#ifdef CONFIG_PAX_RANDMMAP
25566+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25567+ info.low_limit += mm->delta_mmap & 0x03FFF000UL;
25568+#endif
25569+
25570+ if (info.low_limit < info.high_limit) {
25571+ addr = vm_unmapped_area(&info);
25572+ if (!IS_ERR_VALUE(addr))
25573+ return addr;
25574+ }
25575+ } else
25576+#endif
25577+
25578+ info.low_limit = mm->mmap_base;
25579+ info.high_limit = pax_task_size;
25580+
25581+ return vm_unmapped_area(&info);
25582+}
25583+
25584+unsigned long
25585+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25586+ const unsigned long len, const unsigned long pgoff,
25587+ const unsigned long flags)
25588+{
25589+ struct vm_area_struct *vma;
25590+ struct mm_struct *mm = current->mm;
25591+ unsigned long addr = addr0, pax_task_size = TASK_SIZE;
25592+ struct vm_unmapped_area_info info;
25593+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25594+
25595+#ifdef CONFIG_PAX_SEGMEXEC
25596+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25597+ pax_task_size = SEGMEXEC_TASK_SIZE;
25598+#endif
25599+
25600+ pax_task_size -= PAGE_SIZE;
25601+
25602+ /* requested length too big for entire address space */
25603+ if (len > pax_task_size)
25604+ return -ENOMEM;
25605+
25606+ if (flags & MAP_FIXED)
25607+ return addr;
25608+
25609+#ifdef CONFIG_PAX_PAGEEXEC
25610+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
25611+ goto bottomup;
25612+#endif
25613+
25614+#ifdef CONFIG_PAX_RANDMMAP
25615+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25616+#endif
25617+
25618+ /* requesting a specific address */
25619+ if (addr) {
25620+ addr = PAGE_ALIGN(addr);
25621+ if (pax_task_size - len >= addr) {
25622+ vma = find_vma(mm, addr);
25623+ if (check_heap_stack_gap(vma, addr, len, offset))
25624+ return addr;
25625+ }
25626+ }
25627+
25628+ info.flags = VM_UNMAPPED_AREA_TOPDOWN;
25629+ info.length = len;
25630+ info.low_limit = PAGE_SIZE;
25631+ info.high_limit = mm->mmap_base;
25632+ info.align_mask = filp ? get_align_mask() : 0;
25633+ info.align_offset = pgoff << PAGE_SHIFT;
25634+ info.threadstack_offset = offset;
25635+
25636+ addr = vm_unmapped_area(&info);
25637+ if (!(addr & ~PAGE_MASK))
25638+ return addr;
25639+ VM_BUG_ON(addr != -ENOMEM);
25640+
25641+bottomup:
25642+ /*
25643+ * A failed mmap() very likely causes application failure,
25644+ * so fall back to the bottom-up function here. This scenario
25645+ * can happen with large stack limits and large mmap()
25646+ * allocations.
25647+ */
25648+ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
25649+}
25650diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
25651index 30277e2..5664a29 100644
25652--- a/arch/x86/kernel/sys_x86_64.c
25653+++ b/arch/x86/kernel/sys_x86_64.c
25654@@ -81,8 +81,8 @@ out:
25655 return error;
25656 }
25657
25658-static void find_start_end(unsigned long flags, unsigned long *begin,
25659- unsigned long *end)
25660+static void find_start_end(struct mm_struct *mm, unsigned long flags,
25661+ unsigned long *begin, unsigned long *end)
25662 {
25663 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
25664 unsigned long new_begin;
25665@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
25666 *begin = new_begin;
25667 }
25668 } else {
25669- *begin = current->mm->mmap_legacy_base;
25670+ *begin = mm->mmap_legacy_base;
25671 *end = TASK_SIZE;
25672 }
25673 }
25674@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
25675 struct vm_area_struct *vma;
25676 struct vm_unmapped_area_info info;
25677 unsigned long begin, end;
25678+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25679
25680 if (flags & MAP_FIXED)
25681 return addr;
25682
25683- find_start_end(flags, &begin, &end);
25684+ find_start_end(mm, flags, &begin, &end);
25685
25686 if (len > end)
25687 return -ENOMEM;
25688
25689+#ifdef CONFIG_PAX_RANDMMAP
25690+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25691+#endif
25692+
25693 if (addr) {
25694 addr = PAGE_ALIGN(addr);
25695 vma = find_vma(mm, addr);
25696- if (end - len >= addr &&
25697- (!vma || addr + len <= vma->vm_start))
25698+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
25699 return addr;
25700 }
25701
25702@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
25703 info.high_limit = end;
25704 info.align_mask = filp ? get_align_mask() : 0;
25705 info.align_offset = pgoff << PAGE_SHIFT;
25706+ info.threadstack_offset = offset;
25707 return vm_unmapped_area(&info);
25708 }
25709
25710@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25711 struct mm_struct *mm = current->mm;
25712 unsigned long addr = addr0;
25713 struct vm_unmapped_area_info info;
25714+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25715
25716 /* requested length too big for entire address space */
25717 if (len > TASK_SIZE)
25718@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25719 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
25720 goto bottomup;
25721
25722+#ifdef CONFIG_PAX_RANDMMAP
25723+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25724+#endif
25725+
25726 /* requesting a specific address */
25727 if (addr) {
25728 addr = PAGE_ALIGN(addr);
25729 vma = find_vma(mm, addr);
25730- if (TASK_SIZE - len >= addr &&
25731- (!vma || addr + len <= vma->vm_start))
25732+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
25733 return addr;
25734 }
25735
25736@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25737 info.high_limit = mm->mmap_base;
25738 info.align_mask = filp ? get_align_mask() : 0;
25739 info.align_offset = pgoff << PAGE_SHIFT;
25740+ info.threadstack_offset = offset;
25741 addr = vm_unmapped_area(&info);
25742 if (!(addr & ~PAGE_MASK))
25743 return addr;
25744diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
25745index addf7b5..f960685 100644
25746--- a/arch/x86/kernel/tboot.c
25747+++ b/arch/x86/kernel/tboot.c
25748@@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
25749
25750 void tboot_shutdown(u32 shutdown_type)
25751 {
25752- void (*shutdown)(void);
25753+ void (* __noreturn shutdown)(void);
25754
25755 if (!tboot_enabled())
25756 return;
25757@@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
25758
25759 switch_to_tboot_pt();
25760
25761- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
25762+ shutdown = (void *)tboot->shutdown_entry;
25763 shutdown();
25764
25765 /* should not reach here */
25766@@ -301,7 +301,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
25767 return 0;
25768 }
25769
25770-static atomic_t ap_wfs_count;
25771+static atomic_unchecked_t ap_wfs_count;
25772
25773 static int tboot_wait_for_aps(int num_aps)
25774 {
25775@@ -325,9 +325,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
25776 {
25777 switch (action) {
25778 case CPU_DYING:
25779- atomic_inc(&ap_wfs_count);
25780+ atomic_inc_unchecked(&ap_wfs_count);
25781 if (num_online_cpus() == 1)
25782- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
25783+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
25784 return NOTIFY_BAD;
25785 break;
25786 }
25787@@ -413,7 +413,7 @@ static __init int tboot_late_init(void)
25788
25789 tboot_create_trampoline();
25790
25791- atomic_set(&ap_wfs_count, 0);
25792+ atomic_set_unchecked(&ap_wfs_count, 0);
25793 register_hotcpu_notifier(&tboot_cpu_notifier);
25794
25795 #ifdef CONFIG_DEBUG_FS
25796diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
25797index 24d3c91..d06b473 100644
25798--- a/arch/x86/kernel/time.c
25799+++ b/arch/x86/kernel/time.c
25800@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
25801 {
25802 unsigned long pc = instruction_pointer(regs);
25803
25804- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
25805+ if (!user_mode(regs) && in_lock_functions(pc)) {
25806 #ifdef CONFIG_FRAME_POINTER
25807- return *(unsigned long *)(regs->bp + sizeof(long));
25808+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
25809 #else
25810 unsigned long *sp =
25811 (unsigned long *)kernel_stack_pointer(regs);
25812@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
25813 * or above a saved flags. Eflags has bits 22-31 zero,
25814 * kernel addresses don't.
25815 */
25816+
25817+#ifdef CONFIG_PAX_KERNEXEC
25818+ return ktla_ktva(sp[0]);
25819+#else
25820 if (sp[0] >> 22)
25821 return sp[0];
25822 if (sp[1] >> 22)
25823 return sp[1];
25824 #endif
25825+
25826+#endif
25827 }
25828 return pc;
25829 }
25830diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
25831index f7fec09..9991981 100644
25832--- a/arch/x86/kernel/tls.c
25833+++ b/arch/x86/kernel/tls.c
25834@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
25835 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
25836 return -EINVAL;
25837
25838+#ifdef CONFIG_PAX_SEGMEXEC
25839+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
25840+ return -EINVAL;
25841+#endif
25842+
25843 set_tls_desc(p, idx, &info, 1);
25844
25845 return 0;
25846@@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
25847
25848 if (kbuf)
25849 info = kbuf;
25850- else if (__copy_from_user(infobuf, ubuf, count))
25851+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
25852 return -EFAULT;
25853 else
25854 info = infobuf;
25855diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
25856index 1c113db..287b42e 100644
25857--- a/arch/x86/kernel/tracepoint.c
25858+++ b/arch/x86/kernel/tracepoint.c
25859@@ -9,11 +9,11 @@
25860 #include <linux/atomic.h>
25861
25862 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
25863-struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
25864+const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
25865 (unsigned long) trace_idt_table };
25866
25867 /* No need to be aligned, but done to keep all IDTs defined the same way. */
25868-gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
25869+gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
25870
25871 static int trace_irq_vector_refcount;
25872 static DEFINE_MUTEX(irq_vector_mutex);
25873diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
25874index 1b23a1c..910de0d 100644
25875--- a/arch/x86/kernel/traps.c
25876+++ b/arch/x86/kernel/traps.c
25877@@ -65,7 +65,7 @@
25878 #include <asm/proto.h>
25879
25880 /* No need to be aligned, but done to keep all IDTs defined the same way. */
25881-gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
25882+gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
25883 #else
25884 #include <asm/processor-flags.h>
25885 #include <asm/setup.h>
25886@@ -74,7 +74,7 @@ asmlinkage int system_call(void);
25887 #endif
25888
25889 /* Must be page-aligned because the real IDT is used in a fixmap. */
25890-gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
25891+gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
25892
25893 DECLARE_BITMAP(used_vectors, NR_VECTORS);
25894 EXPORT_SYMBOL_GPL(used_vectors);
25895@@ -106,11 +106,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
25896 }
25897
25898 static int __kprobes
25899-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
25900+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
25901 struct pt_regs *regs, long error_code)
25902 {
25903 #ifdef CONFIG_X86_32
25904- if (regs->flags & X86_VM_MASK) {
25905+ if (v8086_mode(regs)) {
25906 /*
25907 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
25908 * On nmi (interrupt 2), do_trap should not be called.
25909@@ -123,12 +123,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
25910 return -1;
25911 }
25912 #endif
25913- if (!user_mode(regs)) {
25914+ if (!user_mode_novm(regs)) {
25915 if (!fixup_exception(regs)) {
25916 tsk->thread.error_code = error_code;
25917 tsk->thread.trap_nr = trapnr;
25918+
25919+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25920+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
25921+ str = "PAX: suspicious stack segment fault";
25922+#endif
25923+
25924 die(str, regs, error_code);
25925 }
25926+
25927+#ifdef CONFIG_PAX_REFCOUNT
25928+ if (trapnr == 4)
25929+ pax_report_refcount_overflow(regs);
25930+#endif
25931+
25932 return 0;
25933 }
25934
25935@@ -136,7 +148,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
25936 }
25937
25938 static void __kprobes
25939-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
25940+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
25941 long error_code, siginfo_t *info)
25942 {
25943 struct task_struct *tsk = current;
25944@@ -160,7 +172,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
25945 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
25946 printk_ratelimit()) {
25947 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
25948- tsk->comm, tsk->pid, str,
25949+ tsk->comm, task_pid_nr(tsk), str,
25950 regs->ip, regs->sp, error_code);
25951 print_vma_addr(" in ", regs->ip);
25952 pr_cont("\n");
25953@@ -276,7 +288,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
25954 conditional_sti(regs);
25955
25956 #ifdef CONFIG_X86_32
25957- if (regs->flags & X86_VM_MASK) {
25958+ if (v8086_mode(regs)) {
25959 local_irq_enable();
25960 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
25961 goto exit;
25962@@ -284,18 +296,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
25963 #endif
25964
25965 tsk = current;
25966- if (!user_mode(regs)) {
25967+ if (!user_mode_novm(regs)) {
25968 if (fixup_exception(regs))
25969 goto exit;
25970
25971 tsk->thread.error_code = error_code;
25972 tsk->thread.trap_nr = X86_TRAP_GP;
25973 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
25974- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
25975+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
25976+
25977+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25978+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
25979+ die("PAX: suspicious general protection fault", regs, error_code);
25980+ else
25981+#endif
25982+
25983 die("general protection fault", regs, error_code);
25984+ }
25985 goto exit;
25986 }
25987
25988+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
25989+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
25990+ struct mm_struct *mm = tsk->mm;
25991+ unsigned long limit;
25992+
25993+ down_write(&mm->mmap_sem);
25994+ limit = mm->context.user_cs_limit;
25995+ if (limit < TASK_SIZE) {
25996+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
25997+ up_write(&mm->mmap_sem);
25998+ return;
25999+ }
26000+ up_write(&mm->mmap_sem);
26001+ }
26002+#endif
26003+
26004 tsk->thread.error_code = error_code;
26005 tsk->thread.trap_nr = X86_TRAP_GP;
26006
26007@@ -453,7 +489,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
26008 /* It's safe to allow irq's after DR6 has been saved */
26009 preempt_conditional_sti(regs);
26010
26011- if (regs->flags & X86_VM_MASK) {
26012+ if (v8086_mode(regs)) {
26013 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
26014 X86_TRAP_DB);
26015 preempt_conditional_cli(regs);
26016@@ -468,7 +504,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
26017 * We already checked v86 mode above, so we can check for kernel mode
26018 * by just checking the CPL of CS.
26019 */
26020- if ((dr6 & DR_STEP) && !user_mode(regs)) {
26021+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
26022 tsk->thread.debugreg6 &= ~DR_STEP;
26023 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
26024 regs->flags &= ~X86_EFLAGS_TF;
26025@@ -500,7 +536,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
26026 return;
26027 conditional_sti(regs);
26028
26029- if (!user_mode_vm(regs))
26030+ if (!user_mode(regs))
26031 {
26032 if (!fixup_exception(regs)) {
26033 task->thread.error_code = error_code;
26034diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
26035index 2ed8459..7cf329f 100644
26036--- a/arch/x86/kernel/uprobes.c
26037+++ b/arch/x86/kernel/uprobes.c
26038@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
26039 int ret = NOTIFY_DONE;
26040
26041 /* We are only interested in userspace traps */
26042- if (regs && !user_mode_vm(regs))
26043+ if (regs && !user_mode(regs))
26044 return NOTIFY_DONE;
26045
26046 switch (val) {
26047@@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
26048
26049 if (ncopied != rasize) {
26050 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
26051- "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
26052+ "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
26053
26054 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
26055 }
26056diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
26057index b9242ba..50c5edd 100644
26058--- a/arch/x86/kernel/verify_cpu.S
26059+++ b/arch/x86/kernel/verify_cpu.S
26060@@ -20,6 +20,7 @@
26061 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
26062 * arch/x86/kernel/trampoline_64.S: secondary processor verification
26063 * arch/x86/kernel/head_32.S: processor startup
26064+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
26065 *
26066 * verify_cpu, returns the status of longmode and SSE in register %eax.
26067 * 0: Success 1: Failure
26068diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
26069index e8edcf5..27f9344 100644
26070--- a/arch/x86/kernel/vm86_32.c
26071+++ b/arch/x86/kernel/vm86_32.c
26072@@ -44,6 +44,7 @@
26073 #include <linux/ptrace.h>
26074 #include <linux/audit.h>
26075 #include <linux/stddef.h>
26076+#include <linux/grsecurity.h>
26077
26078 #include <asm/uaccess.h>
26079 #include <asm/io.h>
26080@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
26081 do_exit(SIGSEGV);
26082 }
26083
26084- tss = &per_cpu(init_tss, get_cpu());
26085+ tss = init_tss + get_cpu();
26086 current->thread.sp0 = current->thread.saved_sp0;
26087 current->thread.sysenter_cs = __KERNEL_CS;
26088 load_sp0(tss, &current->thread);
26089@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
26090
26091 if (tsk->thread.saved_sp0)
26092 return -EPERM;
26093+
26094+#ifdef CONFIG_GRKERNSEC_VM86
26095+ if (!capable(CAP_SYS_RAWIO)) {
26096+ gr_handle_vm86();
26097+ return -EPERM;
26098+ }
26099+#endif
26100+
26101 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
26102 offsetof(struct kernel_vm86_struct, vm86plus) -
26103 sizeof(info.regs));
26104@@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
26105 int tmp;
26106 struct vm86plus_struct __user *v86;
26107
26108+#ifdef CONFIG_GRKERNSEC_VM86
26109+ if (!capable(CAP_SYS_RAWIO)) {
26110+ gr_handle_vm86();
26111+ return -EPERM;
26112+ }
26113+#endif
26114+
26115 tsk = current;
26116 switch (cmd) {
26117 case VM86_REQUEST_IRQ:
26118@@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
26119 tsk->thread.saved_fs = info->regs32->fs;
26120 tsk->thread.saved_gs = get_user_gs(info->regs32);
26121
26122- tss = &per_cpu(init_tss, get_cpu());
26123+ tss = init_tss + get_cpu();
26124 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
26125 if (cpu_has_sep)
26126 tsk->thread.sysenter_cs = 0;
26127@@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
26128 goto cannot_handle;
26129 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
26130 goto cannot_handle;
26131- intr_ptr = (unsigned long __user *) (i << 2);
26132+ intr_ptr = (__force unsigned long __user *) (i << 2);
26133 if (get_user(segoffs, intr_ptr))
26134 goto cannot_handle;
26135 if ((segoffs >> 16) == BIOSSEG)
26136diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
26137index 10c4f30..65408b9 100644
26138--- a/arch/x86/kernel/vmlinux.lds.S
26139+++ b/arch/x86/kernel/vmlinux.lds.S
26140@@ -26,6 +26,13 @@
26141 #include <asm/page_types.h>
26142 #include <asm/cache.h>
26143 #include <asm/boot.h>
26144+#include <asm/segment.h>
26145+
26146+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26147+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
26148+#else
26149+#define __KERNEL_TEXT_OFFSET 0
26150+#endif
26151
26152 #undef i386 /* in case the preprocessor is a 32bit one */
26153
26154@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
26155
26156 PHDRS {
26157 text PT_LOAD FLAGS(5); /* R_E */
26158+#ifdef CONFIG_X86_32
26159+ module PT_LOAD FLAGS(5); /* R_E */
26160+#endif
26161+#ifdef CONFIG_XEN
26162+ rodata PT_LOAD FLAGS(5); /* R_E */
26163+#else
26164+ rodata PT_LOAD FLAGS(4); /* R__ */
26165+#endif
26166 data PT_LOAD FLAGS(6); /* RW_ */
26167-#ifdef CONFIG_X86_64
26168+ init.begin PT_LOAD FLAGS(6); /* RW_ */
26169 #ifdef CONFIG_SMP
26170 percpu PT_LOAD FLAGS(6); /* RW_ */
26171 #endif
26172+ text.init PT_LOAD FLAGS(5); /* R_E */
26173+ text.exit PT_LOAD FLAGS(5); /* R_E */
26174 init PT_LOAD FLAGS(7); /* RWE */
26175-#endif
26176 note PT_NOTE FLAGS(0); /* ___ */
26177 }
26178
26179 SECTIONS
26180 {
26181 #ifdef CONFIG_X86_32
26182- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
26183- phys_startup_32 = startup_32 - LOAD_OFFSET;
26184+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
26185 #else
26186- . = __START_KERNEL;
26187- phys_startup_64 = startup_64 - LOAD_OFFSET;
26188+ . = __START_KERNEL;
26189 #endif
26190
26191 /* Text and read-only data */
26192- .text : AT(ADDR(.text) - LOAD_OFFSET) {
26193- _text = .;
26194+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
26195 /* bootstrapping code */
26196+#ifdef CONFIG_X86_32
26197+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
26198+#else
26199+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
26200+#endif
26201+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
26202+ _text = .;
26203 HEAD_TEXT
26204 . = ALIGN(8);
26205 _stext = .;
26206@@ -104,13 +124,47 @@ SECTIONS
26207 IRQENTRY_TEXT
26208 *(.fixup)
26209 *(.gnu.warning)
26210- /* End of text section */
26211- _etext = .;
26212 } :text = 0x9090
26213
26214- NOTES :text :note
26215+ . += __KERNEL_TEXT_OFFSET;
26216
26217- EXCEPTION_TABLE(16) :text = 0x9090
26218+#ifdef CONFIG_X86_32
26219+ . = ALIGN(PAGE_SIZE);
26220+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
26221+
26222+#ifdef CONFIG_PAX_KERNEXEC
26223+ MODULES_EXEC_VADDR = .;
26224+ BYTE(0)
26225+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
26226+ . = ALIGN(HPAGE_SIZE) - 1;
26227+ MODULES_EXEC_END = .;
26228+#endif
26229+
26230+ } :module
26231+#endif
26232+
26233+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
26234+ /* End of text section */
26235+ BYTE(0)
26236+ _etext = . - __KERNEL_TEXT_OFFSET;
26237+ }
26238+
26239+#ifdef CONFIG_X86_32
26240+ . = ALIGN(PAGE_SIZE);
26241+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
26242+ . = ALIGN(PAGE_SIZE);
26243+ *(.empty_zero_page)
26244+ *(.initial_pg_fixmap)
26245+ *(.initial_pg_pmd)
26246+ *(.initial_page_table)
26247+ *(.swapper_pg_dir)
26248+ } :rodata
26249+#endif
26250+
26251+ . = ALIGN(PAGE_SIZE);
26252+ NOTES :rodata :note
26253+
26254+ EXCEPTION_TABLE(16) :rodata
26255
26256 #if defined(CONFIG_DEBUG_RODATA)
26257 /* .text should occupy whole number of pages */
26258@@ -122,16 +176,20 @@ SECTIONS
26259
26260 /* Data */
26261 .data : AT(ADDR(.data) - LOAD_OFFSET) {
26262+
26263+#ifdef CONFIG_PAX_KERNEXEC
26264+ . = ALIGN(HPAGE_SIZE);
26265+#else
26266+ . = ALIGN(PAGE_SIZE);
26267+#endif
26268+
26269 /* Start of data section */
26270 _sdata = .;
26271
26272 /* init_task */
26273 INIT_TASK_DATA(THREAD_SIZE)
26274
26275-#ifdef CONFIG_X86_32
26276- /* 32 bit has nosave before _edata */
26277 NOSAVE_DATA
26278-#endif
26279
26280 PAGE_ALIGNED_DATA(PAGE_SIZE)
26281
26282@@ -172,12 +230,19 @@ SECTIONS
26283 #endif /* CONFIG_X86_64 */
26284
26285 /* Init code and data - will be freed after init */
26286- . = ALIGN(PAGE_SIZE);
26287 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
26288+ BYTE(0)
26289+
26290+#ifdef CONFIG_PAX_KERNEXEC
26291+ . = ALIGN(HPAGE_SIZE);
26292+#else
26293+ . = ALIGN(PAGE_SIZE);
26294+#endif
26295+
26296 __init_begin = .; /* paired with __init_end */
26297- }
26298+ } :init.begin
26299
26300-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
26301+#ifdef CONFIG_SMP
26302 /*
26303 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
26304 * output PHDR, so the next output section - .init.text - should
26305@@ -186,12 +251,27 @@ SECTIONS
26306 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
26307 #endif
26308
26309- INIT_TEXT_SECTION(PAGE_SIZE)
26310-#ifdef CONFIG_X86_64
26311- :init
26312-#endif
26313+ . = ALIGN(PAGE_SIZE);
26314+ init_begin = .;
26315+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
26316+ VMLINUX_SYMBOL(_sinittext) = .;
26317+ INIT_TEXT
26318+ VMLINUX_SYMBOL(_einittext) = .;
26319+ . = ALIGN(PAGE_SIZE);
26320+ } :text.init
26321
26322- INIT_DATA_SECTION(16)
26323+ /*
26324+ * .exit.text is discard at runtime, not link time, to deal with
26325+ * references from .altinstructions and .eh_frame
26326+ */
26327+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
26328+ EXIT_TEXT
26329+ . = ALIGN(16);
26330+ } :text.exit
26331+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
26332+
26333+ . = ALIGN(PAGE_SIZE);
26334+ INIT_DATA_SECTION(16) :init
26335
26336 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
26337 __x86_cpu_dev_start = .;
26338@@ -253,19 +333,12 @@ SECTIONS
26339 }
26340
26341 . = ALIGN(8);
26342- /*
26343- * .exit.text is discard at runtime, not link time, to deal with
26344- * references from .altinstructions and .eh_frame
26345- */
26346- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
26347- EXIT_TEXT
26348- }
26349
26350 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
26351 EXIT_DATA
26352 }
26353
26354-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
26355+#ifndef CONFIG_SMP
26356 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
26357 #endif
26358
26359@@ -284,16 +357,10 @@ SECTIONS
26360 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
26361 __smp_locks = .;
26362 *(.smp_locks)
26363- . = ALIGN(PAGE_SIZE);
26364 __smp_locks_end = .;
26365+ . = ALIGN(PAGE_SIZE);
26366 }
26367
26368-#ifdef CONFIG_X86_64
26369- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
26370- NOSAVE_DATA
26371- }
26372-#endif
26373-
26374 /* BSS */
26375 . = ALIGN(PAGE_SIZE);
26376 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
26377@@ -309,6 +376,7 @@ SECTIONS
26378 __brk_base = .;
26379 . += 64 * 1024; /* 64k alignment slop space */
26380 *(.brk_reservation) /* areas brk users have reserved */
26381+ . = ALIGN(HPAGE_SIZE);
26382 __brk_limit = .;
26383 }
26384
26385@@ -335,13 +403,12 @@ SECTIONS
26386 * for the boot processor.
26387 */
26388 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
26389-INIT_PER_CPU(gdt_page);
26390 INIT_PER_CPU(irq_stack_union);
26391
26392 /*
26393 * Build-time check on the image size:
26394 */
26395-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
26396+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
26397 "kernel image bigger than KERNEL_IMAGE_SIZE");
26398
26399 #ifdef CONFIG_SMP
26400diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
26401index 1f96f93..d5c8f7a 100644
26402--- a/arch/x86/kernel/vsyscall_64.c
26403+++ b/arch/x86/kernel/vsyscall_64.c
26404@@ -56,15 +56,13 @@
26405 DEFINE_VVAR(int, vgetcpu_mode);
26406 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
26407
26408-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
26409+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
26410
26411 static int __init vsyscall_setup(char *str)
26412 {
26413 if (str) {
26414 if (!strcmp("emulate", str))
26415 vsyscall_mode = EMULATE;
26416- else if (!strcmp("native", str))
26417- vsyscall_mode = NATIVE;
26418 else if (!strcmp("none", str))
26419 vsyscall_mode = NONE;
26420 else
26421@@ -323,8 +321,7 @@ do_ret:
26422 return true;
26423
26424 sigsegv:
26425- force_sig(SIGSEGV, current);
26426- return true;
26427+ do_group_exit(SIGKILL);
26428 }
26429
26430 /*
26431@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
26432 extern char __vvar_page;
26433 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
26434
26435- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
26436- vsyscall_mode == NATIVE
26437- ? PAGE_KERNEL_VSYSCALL
26438- : PAGE_KERNEL_VVAR);
26439+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
26440 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
26441 (unsigned long)VSYSCALL_START);
26442
26443diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
26444index b014d94..e775258 100644
26445--- a/arch/x86/kernel/x8664_ksyms_64.c
26446+++ b/arch/x86/kernel/x8664_ksyms_64.c
26447@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
26448 EXPORT_SYMBOL(copy_user_generic_unrolled);
26449 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
26450 EXPORT_SYMBOL(__copy_user_nocache);
26451-EXPORT_SYMBOL(_copy_from_user);
26452-EXPORT_SYMBOL(_copy_to_user);
26453
26454 EXPORT_SYMBOL(copy_page);
26455 EXPORT_SYMBOL(clear_page);
26456@@ -66,3 +64,7 @@ EXPORT_SYMBOL(empty_zero_page);
26457 #ifndef CONFIG_PARAVIRT
26458 EXPORT_SYMBOL(native_load_gs_index);
26459 #endif
26460+
26461+#ifdef CONFIG_PAX_PER_CPU_PGD
26462+EXPORT_SYMBOL(cpu_pgd);
26463+#endif
26464diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
26465index 5f24c71..1dadf09 100644
26466--- a/arch/x86/kernel/x86_init.c
26467+++ b/arch/x86/kernel/x86_init.c
26468@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
26469 static void default_nmi_init(void) { };
26470 static int default_i8042_detect(void) { return 1; };
26471
26472-struct x86_platform_ops x86_platform = {
26473+struct x86_platform_ops x86_platform __read_only = {
26474 .calibrate_tsc = native_calibrate_tsc,
26475 .get_wallclock = mach_get_cmos_time,
26476 .set_wallclock = mach_set_rtc_mmss,
26477@@ -107,7 +107,7 @@ struct x86_platform_ops x86_platform = {
26478 };
26479
26480 EXPORT_SYMBOL_GPL(x86_platform);
26481-struct x86_msi_ops x86_msi = {
26482+struct x86_msi_ops x86_msi __read_only = {
26483 .setup_msi_irqs = native_setup_msi_irqs,
26484 .compose_msi_msg = native_compose_msi_msg,
26485 .teardown_msi_irq = native_teardown_msi_irq,
26486@@ -116,7 +116,7 @@ struct x86_msi_ops x86_msi = {
26487 .setup_hpet_msi = default_setup_hpet_msi,
26488 };
26489
26490-struct x86_io_apic_ops x86_io_apic_ops = {
26491+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
26492 .init = native_io_apic_init_mappings,
26493 .read = native_io_apic_read,
26494 .write = native_io_apic_write,
26495diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
26496index 422fd82..c3687ca 100644
26497--- a/arch/x86/kernel/xsave.c
26498+++ b/arch/x86/kernel/xsave.c
26499@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
26500 {
26501 int err;
26502
26503+ buf = (struct xsave_struct __user *)____m(buf);
26504 if (use_xsave())
26505 err = xsave_user(buf);
26506 else if (use_fxsr())
26507@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
26508 */
26509 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
26510 {
26511+ buf = (void __user *)____m(buf);
26512 if (use_xsave()) {
26513 if ((unsigned long)buf % 64 || fx_only) {
26514 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
26515diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
26516index a20ecb5..d0e2194 100644
26517--- a/arch/x86/kvm/cpuid.c
26518+++ b/arch/x86/kvm/cpuid.c
26519@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
26520 struct kvm_cpuid2 *cpuid,
26521 struct kvm_cpuid_entry2 __user *entries)
26522 {
26523- int r;
26524+ int r, i;
26525
26526 r = -E2BIG;
26527 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
26528 goto out;
26529 r = -EFAULT;
26530- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
26531- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
26532+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
26533 goto out;
26534+ for (i = 0; i < cpuid->nent; ++i) {
26535+ struct kvm_cpuid_entry2 cpuid_entry;
26536+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
26537+ goto out;
26538+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
26539+ }
26540 vcpu->arch.cpuid_nent = cpuid->nent;
26541 kvm_apic_set_version(vcpu);
26542 kvm_x86_ops->cpuid_update(vcpu);
26543@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
26544 struct kvm_cpuid2 *cpuid,
26545 struct kvm_cpuid_entry2 __user *entries)
26546 {
26547- int r;
26548+ int r, i;
26549
26550 r = -E2BIG;
26551 if (cpuid->nent < vcpu->arch.cpuid_nent)
26552 goto out;
26553 r = -EFAULT;
26554- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
26555- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
26556+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
26557 goto out;
26558+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
26559+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
26560+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
26561+ goto out;
26562+ }
26563 return 0;
26564
26565 out:
26566diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
26567index afc1124..3e431f2 100644
26568--- a/arch/x86/kvm/lapic.c
26569+++ b/arch/x86/kvm/lapic.c
26570@@ -55,7 +55,7 @@
26571 #define APIC_BUS_CYCLE_NS 1
26572
26573 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
26574-#define apic_debug(fmt, arg...)
26575+#define apic_debug(fmt, arg...) do {} while (0)
26576
26577 #define APIC_LVT_NUM 6
26578 /* 14 is the version for Xeon and Pentium 8.4.8*/
26579diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
26580index 7769699..c8aca4a7f 100644
26581--- a/arch/x86/kvm/paging_tmpl.h
26582+++ b/arch/x86/kvm/paging_tmpl.h
26583@@ -208,7 +208,7 @@ retry_walk:
26584 if (unlikely(kvm_is_error_hva(host_addr)))
26585 goto error;
26586
26587- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
26588+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
26589 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
26590 goto error;
26591 walker->ptep_user[walker->level - 1] = ptep_user;
26592diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
26593index c0bc803..6837a50 100644
26594--- a/arch/x86/kvm/svm.c
26595+++ b/arch/x86/kvm/svm.c
26596@@ -3501,7 +3501,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
26597 int cpu = raw_smp_processor_id();
26598
26599 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
26600+
26601+ pax_open_kernel();
26602 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
26603+ pax_close_kernel();
26604+
26605 load_TR_desc();
26606 }
26607
26608@@ -3902,6 +3906,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
26609 #endif
26610 #endif
26611
26612+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
26613+ __set_fs(current_thread_info()->addr_limit);
26614+#endif
26615+
26616 reload_tss(vcpu);
26617
26618 local_irq_disable();
26619diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
26620index 064d0be..f5f758e 100644
26621--- a/arch/x86/kvm/vmx.c
26622+++ b/arch/x86/kvm/vmx.c
26623@@ -1311,12 +1311,12 @@ static void vmcs_write64(unsigned long field, u64 value)
26624 #endif
26625 }
26626
26627-static void vmcs_clear_bits(unsigned long field, u32 mask)
26628+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
26629 {
26630 vmcs_writel(field, vmcs_readl(field) & ~mask);
26631 }
26632
26633-static void vmcs_set_bits(unsigned long field, u32 mask)
26634+static void vmcs_set_bits(unsigned long field, unsigned long mask)
26635 {
26636 vmcs_writel(field, vmcs_readl(field) | mask);
26637 }
26638@@ -1517,7 +1517,11 @@ static void reload_tss(void)
26639 struct desc_struct *descs;
26640
26641 descs = (void *)gdt->address;
26642+
26643+ pax_open_kernel();
26644 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
26645+ pax_close_kernel();
26646+
26647 load_TR_desc();
26648 }
26649
26650@@ -1741,6 +1745,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
26651 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
26652 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
26653
26654+#ifdef CONFIG_PAX_PER_CPU_PGD
26655+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
26656+#endif
26657+
26658 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
26659 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
26660 vmx->loaded_vmcs->cpu = cpu;
26661@@ -2940,8 +2948,11 @@ static __init int hardware_setup(void)
26662 if (!cpu_has_vmx_flexpriority())
26663 flexpriority_enabled = 0;
26664
26665- if (!cpu_has_vmx_tpr_shadow())
26666- kvm_x86_ops->update_cr8_intercept = NULL;
26667+ if (!cpu_has_vmx_tpr_shadow()) {
26668+ pax_open_kernel();
26669+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
26670+ pax_close_kernel();
26671+ }
26672
26673 if (enable_ept && !cpu_has_vmx_ept_2m_page())
26674 kvm_disable_largepages();
26675@@ -2952,13 +2963,15 @@ static __init int hardware_setup(void)
26676 if (!cpu_has_vmx_apicv())
26677 enable_apicv = 0;
26678
26679+ pax_open_kernel();
26680 if (enable_apicv)
26681- kvm_x86_ops->update_cr8_intercept = NULL;
26682+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
26683 else {
26684- kvm_x86_ops->hwapic_irr_update = NULL;
26685- kvm_x86_ops->deliver_posted_interrupt = NULL;
26686- kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
26687+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
26688+ *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
26689+ *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
26690 }
26691+ pax_close_kernel();
26692
26693 if (nested)
26694 nested_vmx_setup_ctls_msrs();
26695@@ -4081,7 +4094,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
26696
26697 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
26698 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
26699+
26700+#ifndef CONFIG_PAX_PER_CPU_PGD
26701 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
26702+#endif
26703
26704 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
26705 #ifdef CONFIG_X86_64
26706@@ -4103,7 +4119,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
26707 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
26708 vmx->host_idt_base = dt.address;
26709
26710- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
26711+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
26712
26713 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
26714 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
26715@@ -7039,6 +7055,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26716 "jmp 2f \n\t"
26717 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
26718 "2: "
26719+
26720+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26721+ "ljmp %[cs],$3f\n\t"
26722+ "3: "
26723+#endif
26724+
26725 /* Save guest registers, load host registers, keep flags */
26726 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
26727 "pop %0 \n\t"
26728@@ -7091,6 +7113,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26729 #endif
26730 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
26731 [wordsize]"i"(sizeof(ulong))
26732+
26733+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26734+ ,[cs]"i"(__KERNEL_CS)
26735+#endif
26736+
26737 : "cc", "memory"
26738 #ifdef CONFIG_X86_64
26739 , "rax", "rbx", "rdi", "rsi"
26740@@ -7104,7 +7131,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26741 if (debugctlmsr)
26742 update_debugctlmsr(debugctlmsr);
26743
26744-#ifndef CONFIG_X86_64
26745+#ifdef CONFIG_X86_32
26746 /*
26747 * The sysexit path does not restore ds/es, so we must set them to
26748 * a reasonable value ourselves.
26749@@ -7113,8 +7140,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26750 * may be executed in interrupt context, which saves and restore segments
26751 * around it, nullifying its effect.
26752 */
26753- loadsegment(ds, __USER_DS);
26754- loadsegment(es, __USER_DS);
26755+ loadsegment(ds, __KERNEL_DS);
26756+ loadsegment(es, __KERNEL_DS);
26757+ loadsegment(ss, __KERNEL_DS);
26758+
26759+#ifdef CONFIG_PAX_KERNEXEC
26760+ loadsegment(fs, __KERNEL_PERCPU);
26761+#endif
26762+
26763+#ifdef CONFIG_PAX_MEMORY_UDEREF
26764+ __set_fs(current_thread_info()->addr_limit);
26765+#endif
26766+
26767 #endif
26768
26769 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
26770diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
26771index d21bce5..fdae9f1 100644
26772--- a/arch/x86/kvm/x86.c
26773+++ b/arch/x86/kvm/x86.c
26774@@ -1766,8 +1766,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
26775 {
26776 struct kvm *kvm = vcpu->kvm;
26777 int lm = is_long_mode(vcpu);
26778- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
26779- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
26780+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
26781+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
26782 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
26783 : kvm->arch.xen_hvm_config.blob_size_32;
26784 u32 page_num = data & ~PAGE_MASK;
26785@@ -2650,6 +2650,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
26786 if (n < msr_list.nmsrs)
26787 goto out;
26788 r = -EFAULT;
26789+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
26790+ goto out;
26791 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
26792 num_msrs_to_save * sizeof(u32)))
26793 goto out;
26794@@ -5344,7 +5346,7 @@ static struct notifier_block pvclock_gtod_notifier = {
26795 };
26796 #endif
26797
26798-int kvm_arch_init(void *opaque)
26799+int kvm_arch_init(const void *opaque)
26800 {
26801 int r;
26802 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
26803diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
26804index 6a22c19..1763f04 100644
26805--- a/arch/x86/lguest/boot.c
26806+++ b/arch/x86/lguest/boot.c
26807@@ -1201,9 +1201,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
26808 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
26809 * Launcher to reboot us.
26810 */
26811-static void lguest_restart(char *reason)
26812+static __noreturn void lguest_restart(char *reason)
26813 {
26814 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
26815+ BUG();
26816 }
26817
26818 /*G:050
26819diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
26820index 00933d5..3a64af9 100644
26821--- a/arch/x86/lib/atomic64_386_32.S
26822+++ b/arch/x86/lib/atomic64_386_32.S
26823@@ -48,6 +48,10 @@ BEGIN(read)
26824 movl (v), %eax
26825 movl 4(v), %edx
26826 RET_ENDP
26827+BEGIN(read_unchecked)
26828+ movl (v), %eax
26829+ movl 4(v), %edx
26830+RET_ENDP
26831 #undef v
26832
26833 #define v %esi
26834@@ -55,6 +59,10 @@ BEGIN(set)
26835 movl %ebx, (v)
26836 movl %ecx, 4(v)
26837 RET_ENDP
26838+BEGIN(set_unchecked)
26839+ movl %ebx, (v)
26840+ movl %ecx, 4(v)
26841+RET_ENDP
26842 #undef v
26843
26844 #define v %esi
26845@@ -70,6 +78,20 @@ RET_ENDP
26846 BEGIN(add)
26847 addl %eax, (v)
26848 adcl %edx, 4(v)
26849+
26850+#ifdef CONFIG_PAX_REFCOUNT
26851+ jno 0f
26852+ subl %eax, (v)
26853+ sbbl %edx, 4(v)
26854+ int $4
26855+0:
26856+ _ASM_EXTABLE(0b, 0b)
26857+#endif
26858+
26859+RET_ENDP
26860+BEGIN(add_unchecked)
26861+ addl %eax, (v)
26862+ adcl %edx, 4(v)
26863 RET_ENDP
26864 #undef v
26865
26866@@ -77,6 +99,24 @@ RET_ENDP
26867 BEGIN(add_return)
26868 addl (v), %eax
26869 adcl 4(v), %edx
26870+
26871+#ifdef CONFIG_PAX_REFCOUNT
26872+ into
26873+1234:
26874+ _ASM_EXTABLE(1234b, 2f)
26875+#endif
26876+
26877+ movl %eax, (v)
26878+ movl %edx, 4(v)
26879+
26880+#ifdef CONFIG_PAX_REFCOUNT
26881+2:
26882+#endif
26883+
26884+RET_ENDP
26885+BEGIN(add_return_unchecked)
26886+ addl (v), %eax
26887+ adcl 4(v), %edx
26888 movl %eax, (v)
26889 movl %edx, 4(v)
26890 RET_ENDP
26891@@ -86,6 +126,20 @@ RET_ENDP
26892 BEGIN(sub)
26893 subl %eax, (v)
26894 sbbl %edx, 4(v)
26895+
26896+#ifdef CONFIG_PAX_REFCOUNT
26897+ jno 0f
26898+ addl %eax, (v)
26899+ adcl %edx, 4(v)
26900+ int $4
26901+0:
26902+ _ASM_EXTABLE(0b, 0b)
26903+#endif
26904+
26905+RET_ENDP
26906+BEGIN(sub_unchecked)
26907+ subl %eax, (v)
26908+ sbbl %edx, 4(v)
26909 RET_ENDP
26910 #undef v
26911
26912@@ -96,6 +150,27 @@ BEGIN(sub_return)
26913 sbbl $0, %edx
26914 addl (v), %eax
26915 adcl 4(v), %edx
26916+
26917+#ifdef CONFIG_PAX_REFCOUNT
26918+ into
26919+1234:
26920+ _ASM_EXTABLE(1234b, 2f)
26921+#endif
26922+
26923+ movl %eax, (v)
26924+ movl %edx, 4(v)
26925+
26926+#ifdef CONFIG_PAX_REFCOUNT
26927+2:
26928+#endif
26929+
26930+RET_ENDP
26931+BEGIN(sub_return_unchecked)
26932+ negl %edx
26933+ negl %eax
26934+ sbbl $0, %edx
26935+ addl (v), %eax
26936+ adcl 4(v), %edx
26937 movl %eax, (v)
26938 movl %edx, 4(v)
26939 RET_ENDP
26940@@ -105,6 +180,20 @@ RET_ENDP
26941 BEGIN(inc)
26942 addl $1, (v)
26943 adcl $0, 4(v)
26944+
26945+#ifdef CONFIG_PAX_REFCOUNT
26946+ jno 0f
26947+ subl $1, (v)
26948+ sbbl $0, 4(v)
26949+ int $4
26950+0:
26951+ _ASM_EXTABLE(0b, 0b)
26952+#endif
26953+
26954+RET_ENDP
26955+BEGIN(inc_unchecked)
26956+ addl $1, (v)
26957+ adcl $0, 4(v)
26958 RET_ENDP
26959 #undef v
26960
26961@@ -114,6 +203,26 @@ BEGIN(inc_return)
26962 movl 4(v), %edx
26963 addl $1, %eax
26964 adcl $0, %edx
26965+
26966+#ifdef CONFIG_PAX_REFCOUNT
26967+ into
26968+1234:
26969+ _ASM_EXTABLE(1234b, 2f)
26970+#endif
26971+
26972+ movl %eax, (v)
26973+ movl %edx, 4(v)
26974+
26975+#ifdef CONFIG_PAX_REFCOUNT
26976+2:
26977+#endif
26978+
26979+RET_ENDP
26980+BEGIN(inc_return_unchecked)
26981+ movl (v), %eax
26982+ movl 4(v), %edx
26983+ addl $1, %eax
26984+ adcl $0, %edx
26985 movl %eax, (v)
26986 movl %edx, 4(v)
26987 RET_ENDP
26988@@ -123,6 +232,20 @@ RET_ENDP
26989 BEGIN(dec)
26990 subl $1, (v)
26991 sbbl $0, 4(v)
26992+
26993+#ifdef CONFIG_PAX_REFCOUNT
26994+ jno 0f
26995+ addl $1, (v)
26996+ adcl $0, 4(v)
26997+ int $4
26998+0:
26999+ _ASM_EXTABLE(0b, 0b)
27000+#endif
27001+
27002+RET_ENDP
27003+BEGIN(dec_unchecked)
27004+ subl $1, (v)
27005+ sbbl $0, 4(v)
27006 RET_ENDP
27007 #undef v
27008
27009@@ -132,6 +255,26 @@ BEGIN(dec_return)
27010 movl 4(v), %edx
27011 subl $1, %eax
27012 sbbl $0, %edx
27013+
27014+#ifdef CONFIG_PAX_REFCOUNT
27015+ into
27016+1234:
27017+ _ASM_EXTABLE(1234b, 2f)
27018+#endif
27019+
27020+ movl %eax, (v)
27021+ movl %edx, 4(v)
27022+
27023+#ifdef CONFIG_PAX_REFCOUNT
27024+2:
27025+#endif
27026+
27027+RET_ENDP
27028+BEGIN(dec_return_unchecked)
27029+ movl (v), %eax
27030+ movl 4(v), %edx
27031+ subl $1, %eax
27032+ sbbl $0, %edx
27033 movl %eax, (v)
27034 movl %edx, 4(v)
27035 RET_ENDP
27036@@ -143,6 +286,13 @@ BEGIN(add_unless)
27037 adcl %edx, %edi
27038 addl (v), %eax
27039 adcl 4(v), %edx
27040+
27041+#ifdef CONFIG_PAX_REFCOUNT
27042+ into
27043+1234:
27044+ _ASM_EXTABLE(1234b, 2f)
27045+#endif
27046+
27047 cmpl %eax, %ecx
27048 je 3f
27049 1:
27050@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
27051 1:
27052 addl $1, %eax
27053 adcl $0, %edx
27054+
27055+#ifdef CONFIG_PAX_REFCOUNT
27056+ into
27057+1234:
27058+ _ASM_EXTABLE(1234b, 2f)
27059+#endif
27060+
27061 movl %eax, (v)
27062 movl %edx, 4(v)
27063 movl $1, %eax
27064@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
27065 movl 4(v), %edx
27066 subl $1, %eax
27067 sbbl $0, %edx
27068+
27069+#ifdef CONFIG_PAX_REFCOUNT
27070+ into
27071+1234:
27072+ _ASM_EXTABLE(1234b, 1f)
27073+#endif
27074+
27075 js 1f
27076 movl %eax, (v)
27077 movl %edx, 4(v)
27078diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
27079index f5cc9eb..51fa319 100644
27080--- a/arch/x86/lib/atomic64_cx8_32.S
27081+++ b/arch/x86/lib/atomic64_cx8_32.S
27082@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
27083 CFI_STARTPROC
27084
27085 read64 %ecx
27086+ pax_force_retaddr
27087 ret
27088 CFI_ENDPROC
27089 ENDPROC(atomic64_read_cx8)
27090
27091+ENTRY(atomic64_read_unchecked_cx8)
27092+ CFI_STARTPROC
27093+
27094+ read64 %ecx
27095+ pax_force_retaddr
27096+ ret
27097+ CFI_ENDPROC
27098+ENDPROC(atomic64_read_unchecked_cx8)
27099+
27100 ENTRY(atomic64_set_cx8)
27101 CFI_STARTPROC
27102
27103@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
27104 cmpxchg8b (%esi)
27105 jne 1b
27106
27107+ pax_force_retaddr
27108 ret
27109 CFI_ENDPROC
27110 ENDPROC(atomic64_set_cx8)
27111
27112+ENTRY(atomic64_set_unchecked_cx8)
27113+ CFI_STARTPROC
27114+
27115+1:
27116+/* we don't need LOCK_PREFIX since aligned 64-bit writes
27117+ * are atomic on 586 and newer */
27118+ cmpxchg8b (%esi)
27119+ jne 1b
27120+
27121+ pax_force_retaddr
27122+ ret
27123+ CFI_ENDPROC
27124+ENDPROC(atomic64_set_unchecked_cx8)
27125+
27126 ENTRY(atomic64_xchg_cx8)
27127 CFI_STARTPROC
27128
27129@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
27130 cmpxchg8b (%esi)
27131 jne 1b
27132
27133+ pax_force_retaddr
27134 ret
27135 CFI_ENDPROC
27136 ENDPROC(atomic64_xchg_cx8)
27137
27138-.macro addsub_return func ins insc
27139-ENTRY(atomic64_\func\()_return_cx8)
27140+.macro addsub_return func ins insc unchecked=""
27141+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
27142 CFI_STARTPROC
27143 SAVE ebp
27144 SAVE ebx
27145@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
27146 movl %edx, %ecx
27147 \ins\()l %esi, %ebx
27148 \insc\()l %edi, %ecx
27149+
27150+.ifb \unchecked
27151+#ifdef CONFIG_PAX_REFCOUNT
27152+ into
27153+2:
27154+ _ASM_EXTABLE(2b, 3f)
27155+#endif
27156+.endif
27157+
27158 LOCK_PREFIX
27159 cmpxchg8b (%ebp)
27160 jne 1b
27161-
27162-10:
27163 movl %ebx, %eax
27164 movl %ecx, %edx
27165+
27166+.ifb \unchecked
27167+#ifdef CONFIG_PAX_REFCOUNT
27168+3:
27169+#endif
27170+.endif
27171+
27172 RESTORE edi
27173 RESTORE esi
27174 RESTORE ebx
27175 RESTORE ebp
27176+ pax_force_retaddr
27177 ret
27178 CFI_ENDPROC
27179-ENDPROC(atomic64_\func\()_return_cx8)
27180+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
27181 .endm
27182
27183 addsub_return add add adc
27184 addsub_return sub sub sbb
27185+addsub_return add add adc _unchecked
27186+addsub_return sub sub sbb _unchecked
27187
27188-.macro incdec_return func ins insc
27189-ENTRY(atomic64_\func\()_return_cx8)
27190+.macro incdec_return func ins insc unchecked=""
27191+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
27192 CFI_STARTPROC
27193 SAVE ebx
27194
27195@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
27196 movl %edx, %ecx
27197 \ins\()l $1, %ebx
27198 \insc\()l $0, %ecx
27199+
27200+.ifb \unchecked
27201+#ifdef CONFIG_PAX_REFCOUNT
27202+ into
27203+2:
27204+ _ASM_EXTABLE(2b, 3f)
27205+#endif
27206+.endif
27207+
27208 LOCK_PREFIX
27209 cmpxchg8b (%esi)
27210 jne 1b
27211
27212-10:
27213 movl %ebx, %eax
27214 movl %ecx, %edx
27215+
27216+.ifb \unchecked
27217+#ifdef CONFIG_PAX_REFCOUNT
27218+3:
27219+#endif
27220+.endif
27221+
27222 RESTORE ebx
27223+ pax_force_retaddr
27224 ret
27225 CFI_ENDPROC
27226-ENDPROC(atomic64_\func\()_return_cx8)
27227+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
27228 .endm
27229
27230 incdec_return inc add adc
27231 incdec_return dec sub sbb
27232+incdec_return inc add adc _unchecked
27233+incdec_return dec sub sbb _unchecked
27234
27235 ENTRY(atomic64_dec_if_positive_cx8)
27236 CFI_STARTPROC
27237@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
27238 movl %edx, %ecx
27239 subl $1, %ebx
27240 sbb $0, %ecx
27241+
27242+#ifdef CONFIG_PAX_REFCOUNT
27243+ into
27244+1234:
27245+ _ASM_EXTABLE(1234b, 2f)
27246+#endif
27247+
27248 js 2f
27249 LOCK_PREFIX
27250 cmpxchg8b (%esi)
27251@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
27252 movl %ebx, %eax
27253 movl %ecx, %edx
27254 RESTORE ebx
27255+ pax_force_retaddr
27256 ret
27257 CFI_ENDPROC
27258 ENDPROC(atomic64_dec_if_positive_cx8)
27259@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
27260 movl %edx, %ecx
27261 addl %ebp, %ebx
27262 adcl %edi, %ecx
27263+
27264+#ifdef CONFIG_PAX_REFCOUNT
27265+ into
27266+1234:
27267+ _ASM_EXTABLE(1234b, 3f)
27268+#endif
27269+
27270 LOCK_PREFIX
27271 cmpxchg8b (%esi)
27272 jne 1b
27273@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
27274 CFI_ADJUST_CFA_OFFSET -8
27275 RESTORE ebx
27276 RESTORE ebp
27277+ pax_force_retaddr
27278 ret
27279 4:
27280 cmpl %edx, 4(%esp)
27281@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
27282 xorl %ecx, %ecx
27283 addl $1, %ebx
27284 adcl %edx, %ecx
27285+
27286+#ifdef CONFIG_PAX_REFCOUNT
27287+ into
27288+1234:
27289+ _ASM_EXTABLE(1234b, 3f)
27290+#endif
27291+
27292 LOCK_PREFIX
27293 cmpxchg8b (%esi)
27294 jne 1b
27295@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
27296 movl $1, %eax
27297 3:
27298 RESTORE ebx
27299+ pax_force_retaddr
27300 ret
27301 CFI_ENDPROC
27302 ENDPROC(atomic64_inc_not_zero_cx8)
27303diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
27304index e78b8ee..7e173a8 100644
27305--- a/arch/x86/lib/checksum_32.S
27306+++ b/arch/x86/lib/checksum_32.S
27307@@ -29,7 +29,8 @@
27308 #include <asm/dwarf2.h>
27309 #include <asm/errno.h>
27310 #include <asm/asm.h>
27311-
27312+#include <asm/segment.h>
27313+
27314 /*
27315 * computes a partial checksum, e.g. for TCP/UDP fragments
27316 */
27317@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
27318
27319 #define ARGBASE 16
27320 #define FP 12
27321-
27322-ENTRY(csum_partial_copy_generic)
27323+
27324+ENTRY(csum_partial_copy_generic_to_user)
27325 CFI_STARTPROC
27326+
27327+#ifdef CONFIG_PAX_MEMORY_UDEREF
27328+ pushl_cfi %gs
27329+ popl_cfi %es
27330+ jmp csum_partial_copy_generic
27331+#endif
27332+
27333+ENTRY(csum_partial_copy_generic_from_user)
27334+
27335+#ifdef CONFIG_PAX_MEMORY_UDEREF
27336+ pushl_cfi %gs
27337+ popl_cfi %ds
27338+#endif
27339+
27340+ENTRY(csum_partial_copy_generic)
27341 subl $4,%esp
27342 CFI_ADJUST_CFA_OFFSET 4
27343 pushl_cfi %edi
27344@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
27345 jmp 4f
27346 SRC(1: movw (%esi), %bx )
27347 addl $2, %esi
27348-DST( movw %bx, (%edi) )
27349+DST( movw %bx, %es:(%edi) )
27350 addl $2, %edi
27351 addw %bx, %ax
27352 adcl $0, %eax
27353@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
27354 SRC(1: movl (%esi), %ebx )
27355 SRC( movl 4(%esi), %edx )
27356 adcl %ebx, %eax
27357-DST( movl %ebx, (%edi) )
27358+DST( movl %ebx, %es:(%edi) )
27359 adcl %edx, %eax
27360-DST( movl %edx, 4(%edi) )
27361+DST( movl %edx, %es:4(%edi) )
27362
27363 SRC( movl 8(%esi), %ebx )
27364 SRC( movl 12(%esi), %edx )
27365 adcl %ebx, %eax
27366-DST( movl %ebx, 8(%edi) )
27367+DST( movl %ebx, %es:8(%edi) )
27368 adcl %edx, %eax
27369-DST( movl %edx, 12(%edi) )
27370+DST( movl %edx, %es:12(%edi) )
27371
27372 SRC( movl 16(%esi), %ebx )
27373 SRC( movl 20(%esi), %edx )
27374 adcl %ebx, %eax
27375-DST( movl %ebx, 16(%edi) )
27376+DST( movl %ebx, %es:16(%edi) )
27377 adcl %edx, %eax
27378-DST( movl %edx, 20(%edi) )
27379+DST( movl %edx, %es:20(%edi) )
27380
27381 SRC( movl 24(%esi), %ebx )
27382 SRC( movl 28(%esi), %edx )
27383 adcl %ebx, %eax
27384-DST( movl %ebx, 24(%edi) )
27385+DST( movl %ebx, %es:24(%edi) )
27386 adcl %edx, %eax
27387-DST( movl %edx, 28(%edi) )
27388+DST( movl %edx, %es:28(%edi) )
27389
27390 lea 32(%esi), %esi
27391 lea 32(%edi), %edi
27392@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
27393 shrl $2, %edx # This clears CF
27394 SRC(3: movl (%esi), %ebx )
27395 adcl %ebx, %eax
27396-DST( movl %ebx, (%edi) )
27397+DST( movl %ebx, %es:(%edi) )
27398 lea 4(%esi), %esi
27399 lea 4(%edi), %edi
27400 dec %edx
27401@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
27402 jb 5f
27403 SRC( movw (%esi), %cx )
27404 leal 2(%esi), %esi
27405-DST( movw %cx, (%edi) )
27406+DST( movw %cx, %es:(%edi) )
27407 leal 2(%edi), %edi
27408 je 6f
27409 shll $16,%ecx
27410 SRC(5: movb (%esi), %cl )
27411-DST( movb %cl, (%edi) )
27412+DST( movb %cl, %es:(%edi) )
27413 6: addl %ecx, %eax
27414 adcl $0, %eax
27415 7:
27416@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
27417
27418 6001:
27419 movl ARGBASE+20(%esp), %ebx # src_err_ptr
27420- movl $-EFAULT, (%ebx)
27421+ movl $-EFAULT, %ss:(%ebx)
27422
27423 # zero the complete destination - computing the rest
27424 # is too much work
27425@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
27426
27427 6002:
27428 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
27429- movl $-EFAULT,(%ebx)
27430+ movl $-EFAULT,%ss:(%ebx)
27431 jmp 5000b
27432
27433 .previous
27434
27435+ pushl_cfi %ss
27436+ popl_cfi %ds
27437+ pushl_cfi %ss
27438+ popl_cfi %es
27439 popl_cfi %ebx
27440 CFI_RESTORE ebx
27441 popl_cfi %esi
27442@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
27443 popl_cfi %ecx # equivalent to addl $4,%esp
27444 ret
27445 CFI_ENDPROC
27446-ENDPROC(csum_partial_copy_generic)
27447+ENDPROC(csum_partial_copy_generic_to_user)
27448
27449 #else
27450
27451 /* Version for PentiumII/PPro */
27452
27453 #define ROUND1(x) \
27454+ nop; nop; nop; \
27455 SRC(movl x(%esi), %ebx ) ; \
27456 addl %ebx, %eax ; \
27457- DST(movl %ebx, x(%edi) ) ;
27458+ DST(movl %ebx, %es:x(%edi)) ;
27459
27460 #define ROUND(x) \
27461+ nop; nop; nop; \
27462 SRC(movl x(%esi), %ebx ) ; \
27463 adcl %ebx, %eax ; \
27464- DST(movl %ebx, x(%edi) ) ;
27465+ DST(movl %ebx, %es:x(%edi)) ;
27466
27467 #define ARGBASE 12
27468-
27469-ENTRY(csum_partial_copy_generic)
27470+
27471+ENTRY(csum_partial_copy_generic_to_user)
27472 CFI_STARTPROC
27473+
27474+#ifdef CONFIG_PAX_MEMORY_UDEREF
27475+ pushl_cfi %gs
27476+ popl_cfi %es
27477+ jmp csum_partial_copy_generic
27478+#endif
27479+
27480+ENTRY(csum_partial_copy_generic_from_user)
27481+
27482+#ifdef CONFIG_PAX_MEMORY_UDEREF
27483+ pushl_cfi %gs
27484+ popl_cfi %ds
27485+#endif
27486+
27487+ENTRY(csum_partial_copy_generic)
27488 pushl_cfi %ebx
27489 CFI_REL_OFFSET ebx, 0
27490 pushl_cfi %edi
27491@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
27492 subl %ebx, %edi
27493 lea -1(%esi),%edx
27494 andl $-32,%edx
27495- lea 3f(%ebx,%ebx), %ebx
27496+ lea 3f(%ebx,%ebx,2), %ebx
27497 testl %esi, %esi
27498 jmp *%ebx
27499 1: addl $64,%esi
27500@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
27501 jb 5f
27502 SRC( movw (%esi), %dx )
27503 leal 2(%esi), %esi
27504-DST( movw %dx, (%edi) )
27505+DST( movw %dx, %es:(%edi) )
27506 leal 2(%edi), %edi
27507 je 6f
27508 shll $16,%edx
27509 5:
27510 SRC( movb (%esi), %dl )
27511-DST( movb %dl, (%edi) )
27512+DST( movb %dl, %es:(%edi) )
27513 6: addl %edx, %eax
27514 adcl $0, %eax
27515 7:
27516 .section .fixup, "ax"
27517 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
27518- movl $-EFAULT, (%ebx)
27519+ movl $-EFAULT, %ss:(%ebx)
27520 # zero the complete destination (computing the rest is too much work)
27521 movl ARGBASE+8(%esp),%edi # dst
27522 movl ARGBASE+12(%esp),%ecx # len
27523@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
27524 rep; stosb
27525 jmp 7b
27526 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
27527- movl $-EFAULT, (%ebx)
27528+ movl $-EFAULT, %ss:(%ebx)
27529 jmp 7b
27530 .previous
27531
27532+#ifdef CONFIG_PAX_MEMORY_UDEREF
27533+ pushl_cfi %ss
27534+ popl_cfi %ds
27535+ pushl_cfi %ss
27536+ popl_cfi %es
27537+#endif
27538+
27539 popl_cfi %esi
27540 CFI_RESTORE esi
27541 popl_cfi %edi
27542@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
27543 CFI_RESTORE ebx
27544 ret
27545 CFI_ENDPROC
27546-ENDPROC(csum_partial_copy_generic)
27547+ENDPROC(csum_partial_copy_generic_to_user)
27548
27549 #undef ROUND
27550 #undef ROUND1
27551diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
27552index f2145cf..cea889d 100644
27553--- a/arch/x86/lib/clear_page_64.S
27554+++ b/arch/x86/lib/clear_page_64.S
27555@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
27556 movl $4096/8,%ecx
27557 xorl %eax,%eax
27558 rep stosq
27559+ pax_force_retaddr
27560 ret
27561 CFI_ENDPROC
27562 ENDPROC(clear_page_c)
27563@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
27564 movl $4096,%ecx
27565 xorl %eax,%eax
27566 rep stosb
27567+ pax_force_retaddr
27568 ret
27569 CFI_ENDPROC
27570 ENDPROC(clear_page_c_e)
27571@@ -43,6 +45,7 @@ ENTRY(clear_page)
27572 leaq 64(%rdi),%rdi
27573 jnz .Lloop
27574 nop
27575+ pax_force_retaddr
27576 ret
27577 CFI_ENDPROC
27578 .Lclear_page_end:
27579@@ -58,7 +61,7 @@ ENDPROC(clear_page)
27580
27581 #include <asm/cpufeature.h>
27582
27583- .section .altinstr_replacement,"ax"
27584+ .section .altinstr_replacement,"a"
27585 1: .byte 0xeb /* jmp <disp8> */
27586 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
27587 2: .byte 0xeb /* jmp <disp8> */
27588diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
27589index 1e572c5..2a162cd 100644
27590--- a/arch/x86/lib/cmpxchg16b_emu.S
27591+++ b/arch/x86/lib/cmpxchg16b_emu.S
27592@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
27593
27594 popf
27595 mov $1, %al
27596+ pax_force_retaddr
27597 ret
27598
27599 not_same:
27600 popf
27601 xor %al,%al
27602+ pax_force_retaddr
27603 ret
27604
27605 CFI_ENDPROC
27606diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
27607index 176cca6..1166c50 100644
27608--- a/arch/x86/lib/copy_page_64.S
27609+++ b/arch/x86/lib/copy_page_64.S
27610@@ -9,6 +9,7 @@ copy_page_rep:
27611 CFI_STARTPROC
27612 movl $4096/8, %ecx
27613 rep movsq
27614+ pax_force_retaddr
27615 ret
27616 CFI_ENDPROC
27617 ENDPROC(copy_page_rep)
27618@@ -20,12 +21,14 @@ ENDPROC(copy_page_rep)
27619
27620 ENTRY(copy_page)
27621 CFI_STARTPROC
27622- subq $2*8, %rsp
27623- CFI_ADJUST_CFA_OFFSET 2*8
27624+ subq $3*8, %rsp
27625+ CFI_ADJUST_CFA_OFFSET 3*8
27626 movq %rbx, (%rsp)
27627 CFI_REL_OFFSET rbx, 0
27628 movq %r12, 1*8(%rsp)
27629 CFI_REL_OFFSET r12, 1*8
27630+ movq %r13, 2*8(%rsp)
27631+ CFI_REL_OFFSET r13, 2*8
27632
27633 movl $(4096/64)-5, %ecx
27634 .p2align 4
27635@@ -36,7 +39,7 @@ ENTRY(copy_page)
27636 movq 0x8*2(%rsi), %rdx
27637 movq 0x8*3(%rsi), %r8
27638 movq 0x8*4(%rsi), %r9
27639- movq 0x8*5(%rsi), %r10
27640+ movq 0x8*5(%rsi), %r13
27641 movq 0x8*6(%rsi), %r11
27642 movq 0x8*7(%rsi), %r12
27643
27644@@ -47,7 +50,7 @@ ENTRY(copy_page)
27645 movq %rdx, 0x8*2(%rdi)
27646 movq %r8, 0x8*3(%rdi)
27647 movq %r9, 0x8*4(%rdi)
27648- movq %r10, 0x8*5(%rdi)
27649+ movq %r13, 0x8*5(%rdi)
27650 movq %r11, 0x8*6(%rdi)
27651 movq %r12, 0x8*7(%rdi)
27652
27653@@ -66,7 +69,7 @@ ENTRY(copy_page)
27654 movq 0x8*2(%rsi), %rdx
27655 movq 0x8*3(%rsi), %r8
27656 movq 0x8*4(%rsi), %r9
27657- movq 0x8*5(%rsi), %r10
27658+ movq 0x8*5(%rsi), %r13
27659 movq 0x8*6(%rsi), %r11
27660 movq 0x8*7(%rsi), %r12
27661
27662@@ -75,7 +78,7 @@ ENTRY(copy_page)
27663 movq %rdx, 0x8*2(%rdi)
27664 movq %r8, 0x8*3(%rdi)
27665 movq %r9, 0x8*4(%rdi)
27666- movq %r10, 0x8*5(%rdi)
27667+ movq %r13, 0x8*5(%rdi)
27668 movq %r11, 0x8*6(%rdi)
27669 movq %r12, 0x8*7(%rdi)
27670
27671@@ -87,8 +90,11 @@ ENTRY(copy_page)
27672 CFI_RESTORE rbx
27673 movq 1*8(%rsp), %r12
27674 CFI_RESTORE r12
27675- addq $2*8, %rsp
27676- CFI_ADJUST_CFA_OFFSET -2*8
27677+ movq 2*8(%rsp), %r13
27678+ CFI_RESTORE r13
27679+ addq $3*8, %rsp
27680+ CFI_ADJUST_CFA_OFFSET -3*8
27681+ pax_force_retaddr
27682 ret
27683 .Lcopy_page_end:
27684 CFI_ENDPROC
27685@@ -99,7 +105,7 @@ ENDPROC(copy_page)
27686
27687 #include <asm/cpufeature.h>
27688
27689- .section .altinstr_replacement,"ax"
27690+ .section .altinstr_replacement,"a"
27691 1: .byte 0xeb /* jmp <disp8> */
27692 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
27693 2:
27694diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
27695index a30ca15..6b3f4e1 100644
27696--- a/arch/x86/lib/copy_user_64.S
27697+++ b/arch/x86/lib/copy_user_64.S
27698@@ -18,31 +18,7 @@
27699 #include <asm/alternative-asm.h>
27700 #include <asm/asm.h>
27701 #include <asm/smap.h>
27702-
27703-/*
27704- * By placing feature2 after feature1 in altinstructions section, we logically
27705- * implement:
27706- * If CPU has feature2, jmp to alt2 is used
27707- * else if CPU has feature1, jmp to alt1 is used
27708- * else jmp to orig is used.
27709- */
27710- .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
27711-0:
27712- .byte 0xe9 /* 32bit jump */
27713- .long \orig-1f /* by default jump to orig */
27714-1:
27715- .section .altinstr_replacement,"ax"
27716-2: .byte 0xe9 /* near jump with 32bit immediate */
27717- .long \alt1-1b /* offset */ /* or alternatively to alt1 */
27718-3: .byte 0xe9 /* near jump with 32bit immediate */
27719- .long \alt2-1b /* offset */ /* or alternatively to alt2 */
27720- .previous
27721-
27722- .section .altinstructions,"a"
27723- altinstruction_entry 0b,2b,\feature1,5,5
27724- altinstruction_entry 0b,3b,\feature2,5,5
27725- .previous
27726- .endm
27727+#include <asm/pgtable.h>
27728
27729 .macro ALIGN_DESTINATION
27730 #ifdef FIX_ALIGNMENT
27731@@ -70,52 +46,6 @@
27732 #endif
27733 .endm
27734
27735-/* Standard copy_to_user with segment limit checking */
27736-ENTRY(_copy_to_user)
27737- CFI_STARTPROC
27738- GET_THREAD_INFO(%rax)
27739- movq %rdi,%rcx
27740- addq %rdx,%rcx
27741- jc bad_to_user
27742- cmpq TI_addr_limit(%rax),%rcx
27743- ja bad_to_user
27744- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
27745- copy_user_generic_unrolled,copy_user_generic_string, \
27746- copy_user_enhanced_fast_string
27747- CFI_ENDPROC
27748-ENDPROC(_copy_to_user)
27749-
27750-/* Standard copy_from_user with segment limit checking */
27751-ENTRY(_copy_from_user)
27752- CFI_STARTPROC
27753- GET_THREAD_INFO(%rax)
27754- movq %rsi,%rcx
27755- addq %rdx,%rcx
27756- jc bad_from_user
27757- cmpq TI_addr_limit(%rax),%rcx
27758- ja bad_from_user
27759- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
27760- copy_user_generic_unrolled,copy_user_generic_string, \
27761- copy_user_enhanced_fast_string
27762- CFI_ENDPROC
27763-ENDPROC(_copy_from_user)
27764-
27765- .section .fixup,"ax"
27766- /* must zero dest */
27767-ENTRY(bad_from_user)
27768-bad_from_user:
27769- CFI_STARTPROC
27770- movl %edx,%ecx
27771- xorl %eax,%eax
27772- rep
27773- stosb
27774-bad_to_user:
27775- movl %edx,%eax
27776- ret
27777- CFI_ENDPROC
27778-ENDPROC(bad_from_user)
27779- .previous
27780-
27781 /*
27782 * copy_user_generic_unrolled - memory copy with exception handling.
27783 * This version is for CPUs like P4 that don't have efficient micro
27784@@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
27785 */
27786 ENTRY(copy_user_generic_unrolled)
27787 CFI_STARTPROC
27788+ ASM_PAX_OPEN_USERLAND
27789 ASM_STAC
27790 cmpl $8,%edx
27791 jb 20f /* less then 8 bytes, go to byte copy loop */
27792@@ -141,19 +72,19 @@ ENTRY(copy_user_generic_unrolled)
27793 jz 17f
27794 1: movq (%rsi),%r8
27795 2: movq 1*8(%rsi),%r9
27796-3: movq 2*8(%rsi),%r10
27797+3: movq 2*8(%rsi),%rax
27798 4: movq 3*8(%rsi),%r11
27799 5: movq %r8,(%rdi)
27800 6: movq %r9,1*8(%rdi)
27801-7: movq %r10,2*8(%rdi)
27802+7: movq %rax,2*8(%rdi)
27803 8: movq %r11,3*8(%rdi)
27804 9: movq 4*8(%rsi),%r8
27805 10: movq 5*8(%rsi),%r9
27806-11: movq 6*8(%rsi),%r10
27807+11: movq 6*8(%rsi),%rax
27808 12: movq 7*8(%rsi),%r11
27809 13: movq %r8,4*8(%rdi)
27810 14: movq %r9,5*8(%rdi)
27811-15: movq %r10,6*8(%rdi)
27812+15: movq %rax,6*8(%rdi)
27813 16: movq %r11,7*8(%rdi)
27814 leaq 64(%rsi),%rsi
27815 leaq 64(%rdi),%rdi
27816@@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
27817 jnz 21b
27818 23: xor %eax,%eax
27819 ASM_CLAC
27820+ ASM_PAX_CLOSE_USERLAND
27821+ pax_force_retaddr
27822 ret
27823
27824 .section .fixup,"ax"
27825@@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
27826 */
27827 ENTRY(copy_user_generic_string)
27828 CFI_STARTPROC
27829+ ASM_PAX_OPEN_USERLAND
27830 ASM_STAC
27831 andl %edx,%edx
27832 jz 4f
27833@@ -251,6 +185,8 @@ ENTRY(copy_user_generic_string)
27834 movsb
27835 4: xorl %eax,%eax
27836 ASM_CLAC
27837+ ASM_PAX_CLOSE_USERLAND
27838+ pax_force_retaddr
27839 ret
27840
27841 .section .fixup,"ax"
27842@@ -278,6 +214,7 @@ ENDPROC(copy_user_generic_string)
27843 */
27844 ENTRY(copy_user_enhanced_fast_string)
27845 CFI_STARTPROC
27846+ ASM_PAX_OPEN_USERLAND
27847 ASM_STAC
27848 andl %edx,%edx
27849 jz 2f
27850@@ -286,6 +223,8 @@ ENTRY(copy_user_enhanced_fast_string)
27851 movsb
27852 2: xorl %eax,%eax
27853 ASM_CLAC
27854+ ASM_PAX_CLOSE_USERLAND
27855+ pax_force_retaddr
27856 ret
27857
27858 .section .fixup,"ax"
27859diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
27860index 6a4f43c..55d26f2 100644
27861--- a/arch/x86/lib/copy_user_nocache_64.S
27862+++ b/arch/x86/lib/copy_user_nocache_64.S
27863@@ -8,6 +8,7 @@
27864
27865 #include <linux/linkage.h>
27866 #include <asm/dwarf2.h>
27867+#include <asm/alternative-asm.h>
27868
27869 #define FIX_ALIGNMENT 1
27870
27871@@ -16,6 +17,7 @@
27872 #include <asm/thread_info.h>
27873 #include <asm/asm.h>
27874 #include <asm/smap.h>
27875+#include <asm/pgtable.h>
27876
27877 .macro ALIGN_DESTINATION
27878 #ifdef FIX_ALIGNMENT
27879@@ -49,6 +51,16 @@
27880 */
27881 ENTRY(__copy_user_nocache)
27882 CFI_STARTPROC
27883+
27884+#ifdef CONFIG_PAX_MEMORY_UDEREF
27885+ mov pax_user_shadow_base,%rcx
27886+ cmp %rcx,%rsi
27887+ jae 1f
27888+ add %rcx,%rsi
27889+1:
27890+#endif
27891+
27892+ ASM_PAX_OPEN_USERLAND
27893 ASM_STAC
27894 cmpl $8,%edx
27895 jb 20f /* less then 8 bytes, go to byte copy loop */
27896@@ -59,19 +71,19 @@ ENTRY(__copy_user_nocache)
27897 jz 17f
27898 1: movq (%rsi),%r8
27899 2: movq 1*8(%rsi),%r9
27900-3: movq 2*8(%rsi),%r10
27901+3: movq 2*8(%rsi),%rax
27902 4: movq 3*8(%rsi),%r11
27903 5: movnti %r8,(%rdi)
27904 6: movnti %r9,1*8(%rdi)
27905-7: movnti %r10,2*8(%rdi)
27906+7: movnti %rax,2*8(%rdi)
27907 8: movnti %r11,3*8(%rdi)
27908 9: movq 4*8(%rsi),%r8
27909 10: movq 5*8(%rsi),%r9
27910-11: movq 6*8(%rsi),%r10
27911+11: movq 6*8(%rsi),%rax
27912 12: movq 7*8(%rsi),%r11
27913 13: movnti %r8,4*8(%rdi)
27914 14: movnti %r9,5*8(%rdi)
27915-15: movnti %r10,6*8(%rdi)
27916+15: movnti %rax,6*8(%rdi)
27917 16: movnti %r11,7*8(%rdi)
27918 leaq 64(%rsi),%rsi
27919 leaq 64(%rdi),%rdi
27920@@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
27921 jnz 21b
27922 23: xorl %eax,%eax
27923 ASM_CLAC
27924+ ASM_PAX_CLOSE_USERLAND
27925 sfence
27926+ pax_force_retaddr
27927 ret
27928
27929 .section .fixup,"ax"
27930diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
27931index 2419d5f..953ee51 100644
27932--- a/arch/x86/lib/csum-copy_64.S
27933+++ b/arch/x86/lib/csum-copy_64.S
27934@@ -9,6 +9,7 @@
27935 #include <asm/dwarf2.h>
27936 #include <asm/errno.h>
27937 #include <asm/asm.h>
27938+#include <asm/alternative-asm.h>
27939
27940 /*
27941 * Checksum copy with exception handling.
27942@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
27943 CFI_RESTORE rbp
27944 addq $7*8, %rsp
27945 CFI_ADJUST_CFA_OFFSET -7*8
27946+ pax_force_retaddr 0, 1
27947 ret
27948 CFI_RESTORE_STATE
27949
27950diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
27951index 7609e0e..b449b98 100644
27952--- a/arch/x86/lib/csum-wrappers_64.c
27953+++ b/arch/x86/lib/csum-wrappers_64.c
27954@@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
27955 len -= 2;
27956 }
27957 }
27958+ pax_open_userland();
27959 stac();
27960- isum = csum_partial_copy_generic((__force const void *)src,
27961+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
27962 dst, len, isum, errp, NULL);
27963 clac();
27964+ pax_close_userland();
27965 if (unlikely(*errp))
27966 goto out_err;
27967
27968@@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
27969 }
27970
27971 *errp = 0;
27972+ pax_open_userland();
27973 stac();
27974- ret = csum_partial_copy_generic(src, (void __force *)dst,
27975+ ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
27976 len, isum, NULL, errp);
27977 clac();
27978+ pax_close_userland();
27979 return ret;
27980 }
27981 EXPORT_SYMBOL(csum_partial_copy_to_user);
27982diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
27983index a451235..1daa956 100644
27984--- a/arch/x86/lib/getuser.S
27985+++ b/arch/x86/lib/getuser.S
27986@@ -33,17 +33,40 @@
27987 #include <asm/thread_info.h>
27988 #include <asm/asm.h>
27989 #include <asm/smap.h>
27990+#include <asm/segment.h>
27991+#include <asm/pgtable.h>
27992+#include <asm/alternative-asm.h>
27993+
27994+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
27995+#define __copyuser_seg gs;
27996+#else
27997+#define __copyuser_seg
27998+#endif
27999
28000 .text
28001 ENTRY(__get_user_1)
28002 CFI_STARTPROC
28003+
28004+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28005 GET_THREAD_INFO(%_ASM_DX)
28006 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28007 jae bad_get_user
28008 ASM_STAC
28009-1: movzbl (%_ASM_AX),%edx
28010+
28011+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28012+ mov pax_user_shadow_base,%_ASM_DX
28013+ cmp %_ASM_DX,%_ASM_AX
28014+ jae 1234f
28015+ add %_ASM_DX,%_ASM_AX
28016+1234:
28017+#endif
28018+
28019+#endif
28020+
28021+1: __copyuser_seg movzbl (%_ASM_AX),%edx
28022 xor %eax,%eax
28023 ASM_CLAC
28024+ pax_force_retaddr
28025 ret
28026 CFI_ENDPROC
28027 ENDPROC(__get_user_1)
28028@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
28029 ENTRY(__get_user_2)
28030 CFI_STARTPROC
28031 add $1,%_ASM_AX
28032+
28033+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28034 jc bad_get_user
28035 GET_THREAD_INFO(%_ASM_DX)
28036 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28037 jae bad_get_user
28038 ASM_STAC
28039-2: movzwl -1(%_ASM_AX),%edx
28040+
28041+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28042+ mov pax_user_shadow_base,%_ASM_DX
28043+ cmp %_ASM_DX,%_ASM_AX
28044+ jae 1234f
28045+ add %_ASM_DX,%_ASM_AX
28046+1234:
28047+#endif
28048+
28049+#endif
28050+
28051+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
28052 xor %eax,%eax
28053 ASM_CLAC
28054+ pax_force_retaddr
28055 ret
28056 CFI_ENDPROC
28057 ENDPROC(__get_user_2)
28058@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
28059 ENTRY(__get_user_4)
28060 CFI_STARTPROC
28061 add $3,%_ASM_AX
28062+
28063+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28064 jc bad_get_user
28065 GET_THREAD_INFO(%_ASM_DX)
28066 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28067 jae bad_get_user
28068 ASM_STAC
28069-3: movl -3(%_ASM_AX),%edx
28070+
28071+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28072+ mov pax_user_shadow_base,%_ASM_DX
28073+ cmp %_ASM_DX,%_ASM_AX
28074+ jae 1234f
28075+ add %_ASM_DX,%_ASM_AX
28076+1234:
28077+#endif
28078+
28079+#endif
28080+
28081+3: __copyuser_seg movl -3(%_ASM_AX),%edx
28082 xor %eax,%eax
28083 ASM_CLAC
28084+ pax_force_retaddr
28085 ret
28086 CFI_ENDPROC
28087 ENDPROC(__get_user_4)
28088@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
28089 GET_THREAD_INFO(%_ASM_DX)
28090 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28091 jae bad_get_user
28092+
28093+#ifdef CONFIG_PAX_MEMORY_UDEREF
28094+ mov pax_user_shadow_base,%_ASM_DX
28095+ cmp %_ASM_DX,%_ASM_AX
28096+ jae 1234f
28097+ add %_ASM_DX,%_ASM_AX
28098+1234:
28099+#endif
28100+
28101 ASM_STAC
28102 4: movq -7(%_ASM_AX),%rdx
28103 xor %eax,%eax
28104 ASM_CLAC
28105+ pax_force_retaddr
28106 ret
28107 #else
28108 add $7,%_ASM_AX
28109@@ -98,10 +159,11 @@ ENTRY(__get_user_8)
28110 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28111 jae bad_get_user_8
28112 ASM_STAC
28113-4: movl -7(%_ASM_AX),%edx
28114-5: movl -3(%_ASM_AX),%ecx
28115+4: __copyuser_seg movl -7(%_ASM_AX),%edx
28116+5: __copyuser_seg movl -3(%_ASM_AX),%ecx
28117 xor %eax,%eax
28118 ASM_CLAC
28119+ pax_force_retaddr
28120 ret
28121 #endif
28122 CFI_ENDPROC
28123@@ -113,6 +175,7 @@ bad_get_user:
28124 xor %edx,%edx
28125 mov $(-EFAULT),%_ASM_AX
28126 ASM_CLAC
28127+ pax_force_retaddr
28128 ret
28129 CFI_ENDPROC
28130 END(bad_get_user)
28131@@ -124,6 +187,7 @@ bad_get_user_8:
28132 xor %ecx,%ecx
28133 mov $(-EFAULT),%_ASM_AX
28134 ASM_CLAC
28135+ pax_force_retaddr
28136 ret
28137 CFI_ENDPROC
28138 END(bad_get_user_8)
28139diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
28140index 54fcffe..7be149e 100644
28141--- a/arch/x86/lib/insn.c
28142+++ b/arch/x86/lib/insn.c
28143@@ -20,8 +20,10 @@
28144
28145 #ifdef __KERNEL__
28146 #include <linux/string.h>
28147+#include <asm/pgtable_types.h>
28148 #else
28149 #include <string.h>
28150+#define ktla_ktva(addr) addr
28151 #endif
28152 #include <asm/inat.h>
28153 #include <asm/insn.h>
28154@@ -53,8 +55,8 @@
28155 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
28156 {
28157 memset(insn, 0, sizeof(*insn));
28158- insn->kaddr = kaddr;
28159- insn->next_byte = kaddr;
28160+ insn->kaddr = ktla_ktva(kaddr);
28161+ insn->next_byte = ktla_ktva(kaddr);
28162 insn->x86_64 = x86_64 ? 1 : 0;
28163 insn->opnd_bytes = 4;
28164 if (x86_64)
28165diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
28166index 05a95e7..326f2fa 100644
28167--- a/arch/x86/lib/iomap_copy_64.S
28168+++ b/arch/x86/lib/iomap_copy_64.S
28169@@ -17,6 +17,7 @@
28170
28171 #include <linux/linkage.h>
28172 #include <asm/dwarf2.h>
28173+#include <asm/alternative-asm.h>
28174
28175 /*
28176 * override generic version in lib/iomap_copy.c
28177@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
28178 CFI_STARTPROC
28179 movl %edx,%ecx
28180 rep movsd
28181+ pax_force_retaddr
28182 ret
28183 CFI_ENDPROC
28184 ENDPROC(__iowrite32_copy)
28185diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
28186index 56313a3..9b59269 100644
28187--- a/arch/x86/lib/memcpy_64.S
28188+++ b/arch/x86/lib/memcpy_64.S
28189@@ -24,7 +24,7 @@
28190 * This gets patched over the unrolled variant (below) via the
28191 * alternative instructions framework:
28192 */
28193- .section .altinstr_replacement, "ax", @progbits
28194+ .section .altinstr_replacement, "a", @progbits
28195 .Lmemcpy_c:
28196 movq %rdi, %rax
28197 movq %rdx, %rcx
28198@@ -33,6 +33,7 @@
28199 rep movsq
28200 movl %edx, %ecx
28201 rep movsb
28202+ pax_force_retaddr
28203 ret
28204 .Lmemcpy_e:
28205 .previous
28206@@ -44,11 +45,12 @@
28207 * This gets patched over the unrolled variant (below) via the
28208 * alternative instructions framework:
28209 */
28210- .section .altinstr_replacement, "ax", @progbits
28211+ .section .altinstr_replacement, "a", @progbits
28212 .Lmemcpy_c_e:
28213 movq %rdi, %rax
28214 movq %rdx, %rcx
28215 rep movsb
28216+ pax_force_retaddr
28217 ret
28218 .Lmemcpy_e_e:
28219 .previous
28220@@ -76,13 +78,13 @@ ENTRY(memcpy)
28221 */
28222 movq 0*8(%rsi), %r8
28223 movq 1*8(%rsi), %r9
28224- movq 2*8(%rsi), %r10
28225+ movq 2*8(%rsi), %rcx
28226 movq 3*8(%rsi), %r11
28227 leaq 4*8(%rsi), %rsi
28228
28229 movq %r8, 0*8(%rdi)
28230 movq %r9, 1*8(%rdi)
28231- movq %r10, 2*8(%rdi)
28232+ movq %rcx, 2*8(%rdi)
28233 movq %r11, 3*8(%rdi)
28234 leaq 4*8(%rdi), %rdi
28235 jae .Lcopy_forward_loop
28236@@ -105,12 +107,12 @@ ENTRY(memcpy)
28237 subq $0x20, %rdx
28238 movq -1*8(%rsi), %r8
28239 movq -2*8(%rsi), %r9
28240- movq -3*8(%rsi), %r10
28241+ movq -3*8(%rsi), %rcx
28242 movq -4*8(%rsi), %r11
28243 leaq -4*8(%rsi), %rsi
28244 movq %r8, -1*8(%rdi)
28245 movq %r9, -2*8(%rdi)
28246- movq %r10, -3*8(%rdi)
28247+ movq %rcx, -3*8(%rdi)
28248 movq %r11, -4*8(%rdi)
28249 leaq -4*8(%rdi), %rdi
28250 jae .Lcopy_backward_loop
28251@@ -130,12 +132,13 @@ ENTRY(memcpy)
28252 */
28253 movq 0*8(%rsi), %r8
28254 movq 1*8(%rsi), %r9
28255- movq -2*8(%rsi, %rdx), %r10
28256+ movq -2*8(%rsi, %rdx), %rcx
28257 movq -1*8(%rsi, %rdx), %r11
28258 movq %r8, 0*8(%rdi)
28259 movq %r9, 1*8(%rdi)
28260- movq %r10, -2*8(%rdi, %rdx)
28261+ movq %rcx, -2*8(%rdi, %rdx)
28262 movq %r11, -1*8(%rdi, %rdx)
28263+ pax_force_retaddr
28264 retq
28265 .p2align 4
28266 .Lless_16bytes:
28267@@ -148,6 +151,7 @@ ENTRY(memcpy)
28268 movq -1*8(%rsi, %rdx), %r9
28269 movq %r8, 0*8(%rdi)
28270 movq %r9, -1*8(%rdi, %rdx)
28271+ pax_force_retaddr
28272 retq
28273 .p2align 4
28274 .Lless_8bytes:
28275@@ -161,6 +165,7 @@ ENTRY(memcpy)
28276 movl -4(%rsi, %rdx), %r8d
28277 movl %ecx, (%rdi)
28278 movl %r8d, -4(%rdi, %rdx)
28279+ pax_force_retaddr
28280 retq
28281 .p2align 4
28282 .Lless_3bytes:
28283@@ -179,6 +184,7 @@ ENTRY(memcpy)
28284 movb %cl, (%rdi)
28285
28286 .Lend:
28287+ pax_force_retaddr
28288 retq
28289 CFI_ENDPROC
28290 ENDPROC(memcpy)
28291diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
28292index 65268a6..5aa7815 100644
28293--- a/arch/x86/lib/memmove_64.S
28294+++ b/arch/x86/lib/memmove_64.S
28295@@ -61,13 +61,13 @@ ENTRY(memmove)
28296 5:
28297 sub $0x20, %rdx
28298 movq 0*8(%rsi), %r11
28299- movq 1*8(%rsi), %r10
28300+ movq 1*8(%rsi), %rcx
28301 movq 2*8(%rsi), %r9
28302 movq 3*8(%rsi), %r8
28303 leaq 4*8(%rsi), %rsi
28304
28305 movq %r11, 0*8(%rdi)
28306- movq %r10, 1*8(%rdi)
28307+ movq %rcx, 1*8(%rdi)
28308 movq %r9, 2*8(%rdi)
28309 movq %r8, 3*8(%rdi)
28310 leaq 4*8(%rdi), %rdi
28311@@ -81,10 +81,10 @@ ENTRY(memmove)
28312 4:
28313 movq %rdx, %rcx
28314 movq -8(%rsi, %rdx), %r11
28315- lea -8(%rdi, %rdx), %r10
28316+ lea -8(%rdi, %rdx), %r9
28317 shrq $3, %rcx
28318 rep movsq
28319- movq %r11, (%r10)
28320+ movq %r11, (%r9)
28321 jmp 13f
28322 .Lmemmove_end_forward:
28323
28324@@ -95,14 +95,14 @@ ENTRY(memmove)
28325 7:
28326 movq %rdx, %rcx
28327 movq (%rsi), %r11
28328- movq %rdi, %r10
28329+ movq %rdi, %r9
28330 leaq -8(%rsi, %rdx), %rsi
28331 leaq -8(%rdi, %rdx), %rdi
28332 shrq $3, %rcx
28333 std
28334 rep movsq
28335 cld
28336- movq %r11, (%r10)
28337+ movq %r11, (%r9)
28338 jmp 13f
28339
28340 /*
28341@@ -127,13 +127,13 @@ ENTRY(memmove)
28342 8:
28343 subq $0x20, %rdx
28344 movq -1*8(%rsi), %r11
28345- movq -2*8(%rsi), %r10
28346+ movq -2*8(%rsi), %rcx
28347 movq -3*8(%rsi), %r9
28348 movq -4*8(%rsi), %r8
28349 leaq -4*8(%rsi), %rsi
28350
28351 movq %r11, -1*8(%rdi)
28352- movq %r10, -2*8(%rdi)
28353+ movq %rcx, -2*8(%rdi)
28354 movq %r9, -3*8(%rdi)
28355 movq %r8, -4*8(%rdi)
28356 leaq -4*8(%rdi), %rdi
28357@@ -151,11 +151,11 @@ ENTRY(memmove)
28358 * Move data from 16 bytes to 31 bytes.
28359 */
28360 movq 0*8(%rsi), %r11
28361- movq 1*8(%rsi), %r10
28362+ movq 1*8(%rsi), %rcx
28363 movq -2*8(%rsi, %rdx), %r9
28364 movq -1*8(%rsi, %rdx), %r8
28365 movq %r11, 0*8(%rdi)
28366- movq %r10, 1*8(%rdi)
28367+ movq %rcx, 1*8(%rdi)
28368 movq %r9, -2*8(%rdi, %rdx)
28369 movq %r8, -1*8(%rdi, %rdx)
28370 jmp 13f
28371@@ -167,9 +167,9 @@ ENTRY(memmove)
28372 * Move data from 8 bytes to 15 bytes.
28373 */
28374 movq 0*8(%rsi), %r11
28375- movq -1*8(%rsi, %rdx), %r10
28376+ movq -1*8(%rsi, %rdx), %r9
28377 movq %r11, 0*8(%rdi)
28378- movq %r10, -1*8(%rdi, %rdx)
28379+ movq %r9, -1*8(%rdi, %rdx)
28380 jmp 13f
28381 10:
28382 cmpq $4, %rdx
28383@@ -178,9 +178,9 @@ ENTRY(memmove)
28384 * Move data from 4 bytes to 7 bytes.
28385 */
28386 movl (%rsi), %r11d
28387- movl -4(%rsi, %rdx), %r10d
28388+ movl -4(%rsi, %rdx), %r9d
28389 movl %r11d, (%rdi)
28390- movl %r10d, -4(%rdi, %rdx)
28391+ movl %r9d, -4(%rdi, %rdx)
28392 jmp 13f
28393 11:
28394 cmp $2, %rdx
28395@@ -189,9 +189,9 @@ ENTRY(memmove)
28396 * Move data from 2 bytes to 3 bytes.
28397 */
28398 movw (%rsi), %r11w
28399- movw -2(%rsi, %rdx), %r10w
28400+ movw -2(%rsi, %rdx), %r9w
28401 movw %r11w, (%rdi)
28402- movw %r10w, -2(%rdi, %rdx)
28403+ movw %r9w, -2(%rdi, %rdx)
28404 jmp 13f
28405 12:
28406 cmp $1, %rdx
28407@@ -202,14 +202,16 @@ ENTRY(memmove)
28408 movb (%rsi), %r11b
28409 movb %r11b, (%rdi)
28410 13:
28411+ pax_force_retaddr
28412 retq
28413 CFI_ENDPROC
28414
28415- .section .altinstr_replacement,"ax"
28416+ .section .altinstr_replacement,"a"
28417 .Lmemmove_begin_forward_efs:
28418 /* Forward moving data. */
28419 movq %rdx, %rcx
28420 rep movsb
28421+ pax_force_retaddr
28422 retq
28423 .Lmemmove_end_forward_efs:
28424 .previous
28425diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
28426index 2dcb380..50a78bc 100644
28427--- a/arch/x86/lib/memset_64.S
28428+++ b/arch/x86/lib/memset_64.S
28429@@ -16,7 +16,7 @@
28430 *
28431 * rax original destination
28432 */
28433- .section .altinstr_replacement, "ax", @progbits
28434+ .section .altinstr_replacement, "a", @progbits
28435 .Lmemset_c:
28436 movq %rdi,%r9
28437 movq %rdx,%rcx
28438@@ -30,6 +30,7 @@
28439 movl %edx,%ecx
28440 rep stosb
28441 movq %r9,%rax
28442+ pax_force_retaddr
28443 ret
28444 .Lmemset_e:
28445 .previous
28446@@ -45,13 +46,14 @@
28447 *
28448 * rax original destination
28449 */
28450- .section .altinstr_replacement, "ax", @progbits
28451+ .section .altinstr_replacement, "a", @progbits
28452 .Lmemset_c_e:
28453 movq %rdi,%r9
28454 movb %sil,%al
28455 movq %rdx,%rcx
28456 rep stosb
28457 movq %r9,%rax
28458+ pax_force_retaddr
28459 ret
28460 .Lmemset_e_e:
28461 .previous
28462@@ -59,7 +61,7 @@
28463 ENTRY(memset)
28464 ENTRY(__memset)
28465 CFI_STARTPROC
28466- movq %rdi,%r10
28467+ movq %rdi,%r11
28468
28469 /* expand byte value */
28470 movzbl %sil,%ecx
28471@@ -117,7 +119,8 @@ ENTRY(__memset)
28472 jnz .Lloop_1
28473
28474 .Lende:
28475- movq %r10,%rax
28476+ movq %r11,%rax
28477+ pax_force_retaddr
28478 ret
28479
28480 CFI_RESTORE_STATE
28481diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
28482index c9f2d9b..e7fd2c0 100644
28483--- a/arch/x86/lib/mmx_32.c
28484+++ b/arch/x86/lib/mmx_32.c
28485@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
28486 {
28487 void *p;
28488 int i;
28489+ unsigned long cr0;
28490
28491 if (unlikely(in_interrupt()))
28492 return __memcpy(to, from, len);
28493@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
28494 kernel_fpu_begin();
28495
28496 __asm__ __volatile__ (
28497- "1: prefetch (%0)\n" /* This set is 28 bytes */
28498- " prefetch 64(%0)\n"
28499- " prefetch 128(%0)\n"
28500- " prefetch 192(%0)\n"
28501- " prefetch 256(%0)\n"
28502+ "1: prefetch (%1)\n" /* This set is 28 bytes */
28503+ " prefetch 64(%1)\n"
28504+ " prefetch 128(%1)\n"
28505+ " prefetch 192(%1)\n"
28506+ " prefetch 256(%1)\n"
28507 "2: \n"
28508 ".section .fixup, \"ax\"\n"
28509- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28510+ "3: \n"
28511+
28512+#ifdef CONFIG_PAX_KERNEXEC
28513+ " movl %%cr0, %0\n"
28514+ " movl %0, %%eax\n"
28515+ " andl $0xFFFEFFFF, %%eax\n"
28516+ " movl %%eax, %%cr0\n"
28517+#endif
28518+
28519+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28520+
28521+#ifdef CONFIG_PAX_KERNEXEC
28522+ " movl %0, %%cr0\n"
28523+#endif
28524+
28525 " jmp 2b\n"
28526 ".previous\n"
28527 _ASM_EXTABLE(1b, 3b)
28528- : : "r" (from));
28529+ : "=&r" (cr0) : "r" (from) : "ax");
28530
28531 for ( ; i > 5; i--) {
28532 __asm__ __volatile__ (
28533- "1: prefetch 320(%0)\n"
28534- "2: movq (%0), %%mm0\n"
28535- " movq 8(%0), %%mm1\n"
28536- " movq 16(%0), %%mm2\n"
28537- " movq 24(%0), %%mm3\n"
28538- " movq %%mm0, (%1)\n"
28539- " movq %%mm1, 8(%1)\n"
28540- " movq %%mm2, 16(%1)\n"
28541- " movq %%mm3, 24(%1)\n"
28542- " movq 32(%0), %%mm0\n"
28543- " movq 40(%0), %%mm1\n"
28544- " movq 48(%0), %%mm2\n"
28545- " movq 56(%0), %%mm3\n"
28546- " movq %%mm0, 32(%1)\n"
28547- " movq %%mm1, 40(%1)\n"
28548- " movq %%mm2, 48(%1)\n"
28549- " movq %%mm3, 56(%1)\n"
28550+ "1: prefetch 320(%1)\n"
28551+ "2: movq (%1), %%mm0\n"
28552+ " movq 8(%1), %%mm1\n"
28553+ " movq 16(%1), %%mm2\n"
28554+ " movq 24(%1), %%mm3\n"
28555+ " movq %%mm0, (%2)\n"
28556+ " movq %%mm1, 8(%2)\n"
28557+ " movq %%mm2, 16(%2)\n"
28558+ " movq %%mm3, 24(%2)\n"
28559+ " movq 32(%1), %%mm0\n"
28560+ " movq 40(%1), %%mm1\n"
28561+ " movq 48(%1), %%mm2\n"
28562+ " movq 56(%1), %%mm3\n"
28563+ " movq %%mm0, 32(%2)\n"
28564+ " movq %%mm1, 40(%2)\n"
28565+ " movq %%mm2, 48(%2)\n"
28566+ " movq %%mm3, 56(%2)\n"
28567 ".section .fixup, \"ax\"\n"
28568- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28569+ "3:\n"
28570+
28571+#ifdef CONFIG_PAX_KERNEXEC
28572+ " movl %%cr0, %0\n"
28573+ " movl %0, %%eax\n"
28574+ " andl $0xFFFEFFFF, %%eax\n"
28575+ " movl %%eax, %%cr0\n"
28576+#endif
28577+
28578+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28579+
28580+#ifdef CONFIG_PAX_KERNEXEC
28581+ " movl %0, %%cr0\n"
28582+#endif
28583+
28584 " jmp 2b\n"
28585 ".previous\n"
28586 _ASM_EXTABLE(1b, 3b)
28587- : : "r" (from), "r" (to) : "memory");
28588+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
28589
28590 from += 64;
28591 to += 64;
28592@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
28593 static void fast_copy_page(void *to, void *from)
28594 {
28595 int i;
28596+ unsigned long cr0;
28597
28598 kernel_fpu_begin();
28599
28600@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
28601 * but that is for later. -AV
28602 */
28603 __asm__ __volatile__(
28604- "1: prefetch (%0)\n"
28605- " prefetch 64(%0)\n"
28606- " prefetch 128(%0)\n"
28607- " prefetch 192(%0)\n"
28608- " prefetch 256(%0)\n"
28609+ "1: prefetch (%1)\n"
28610+ " prefetch 64(%1)\n"
28611+ " prefetch 128(%1)\n"
28612+ " prefetch 192(%1)\n"
28613+ " prefetch 256(%1)\n"
28614 "2: \n"
28615 ".section .fixup, \"ax\"\n"
28616- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28617+ "3: \n"
28618+
28619+#ifdef CONFIG_PAX_KERNEXEC
28620+ " movl %%cr0, %0\n"
28621+ " movl %0, %%eax\n"
28622+ " andl $0xFFFEFFFF, %%eax\n"
28623+ " movl %%eax, %%cr0\n"
28624+#endif
28625+
28626+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28627+
28628+#ifdef CONFIG_PAX_KERNEXEC
28629+ " movl %0, %%cr0\n"
28630+#endif
28631+
28632 " jmp 2b\n"
28633 ".previous\n"
28634- _ASM_EXTABLE(1b, 3b) : : "r" (from));
28635+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
28636
28637 for (i = 0; i < (4096-320)/64; i++) {
28638 __asm__ __volatile__ (
28639- "1: prefetch 320(%0)\n"
28640- "2: movq (%0), %%mm0\n"
28641- " movntq %%mm0, (%1)\n"
28642- " movq 8(%0), %%mm1\n"
28643- " movntq %%mm1, 8(%1)\n"
28644- " movq 16(%0), %%mm2\n"
28645- " movntq %%mm2, 16(%1)\n"
28646- " movq 24(%0), %%mm3\n"
28647- " movntq %%mm3, 24(%1)\n"
28648- " movq 32(%0), %%mm4\n"
28649- " movntq %%mm4, 32(%1)\n"
28650- " movq 40(%0), %%mm5\n"
28651- " movntq %%mm5, 40(%1)\n"
28652- " movq 48(%0), %%mm6\n"
28653- " movntq %%mm6, 48(%1)\n"
28654- " movq 56(%0), %%mm7\n"
28655- " movntq %%mm7, 56(%1)\n"
28656+ "1: prefetch 320(%1)\n"
28657+ "2: movq (%1), %%mm0\n"
28658+ " movntq %%mm0, (%2)\n"
28659+ " movq 8(%1), %%mm1\n"
28660+ " movntq %%mm1, 8(%2)\n"
28661+ " movq 16(%1), %%mm2\n"
28662+ " movntq %%mm2, 16(%2)\n"
28663+ " movq 24(%1), %%mm3\n"
28664+ " movntq %%mm3, 24(%2)\n"
28665+ " movq 32(%1), %%mm4\n"
28666+ " movntq %%mm4, 32(%2)\n"
28667+ " movq 40(%1), %%mm5\n"
28668+ " movntq %%mm5, 40(%2)\n"
28669+ " movq 48(%1), %%mm6\n"
28670+ " movntq %%mm6, 48(%2)\n"
28671+ " movq 56(%1), %%mm7\n"
28672+ " movntq %%mm7, 56(%2)\n"
28673 ".section .fixup, \"ax\"\n"
28674- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28675+ "3:\n"
28676+
28677+#ifdef CONFIG_PAX_KERNEXEC
28678+ " movl %%cr0, %0\n"
28679+ " movl %0, %%eax\n"
28680+ " andl $0xFFFEFFFF, %%eax\n"
28681+ " movl %%eax, %%cr0\n"
28682+#endif
28683+
28684+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28685+
28686+#ifdef CONFIG_PAX_KERNEXEC
28687+ " movl %0, %%cr0\n"
28688+#endif
28689+
28690 " jmp 2b\n"
28691 ".previous\n"
28692- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
28693+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
28694
28695 from += 64;
28696 to += 64;
28697@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
28698 static void fast_copy_page(void *to, void *from)
28699 {
28700 int i;
28701+ unsigned long cr0;
28702
28703 kernel_fpu_begin();
28704
28705 __asm__ __volatile__ (
28706- "1: prefetch (%0)\n"
28707- " prefetch 64(%0)\n"
28708- " prefetch 128(%0)\n"
28709- " prefetch 192(%0)\n"
28710- " prefetch 256(%0)\n"
28711+ "1: prefetch (%1)\n"
28712+ " prefetch 64(%1)\n"
28713+ " prefetch 128(%1)\n"
28714+ " prefetch 192(%1)\n"
28715+ " prefetch 256(%1)\n"
28716 "2: \n"
28717 ".section .fixup, \"ax\"\n"
28718- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28719+ "3: \n"
28720+
28721+#ifdef CONFIG_PAX_KERNEXEC
28722+ " movl %%cr0, %0\n"
28723+ " movl %0, %%eax\n"
28724+ " andl $0xFFFEFFFF, %%eax\n"
28725+ " movl %%eax, %%cr0\n"
28726+#endif
28727+
28728+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28729+
28730+#ifdef CONFIG_PAX_KERNEXEC
28731+ " movl %0, %%cr0\n"
28732+#endif
28733+
28734 " jmp 2b\n"
28735 ".previous\n"
28736- _ASM_EXTABLE(1b, 3b) : : "r" (from));
28737+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
28738
28739 for (i = 0; i < 4096/64; i++) {
28740 __asm__ __volatile__ (
28741- "1: prefetch 320(%0)\n"
28742- "2: movq (%0), %%mm0\n"
28743- " movq 8(%0), %%mm1\n"
28744- " movq 16(%0), %%mm2\n"
28745- " movq 24(%0), %%mm3\n"
28746- " movq %%mm0, (%1)\n"
28747- " movq %%mm1, 8(%1)\n"
28748- " movq %%mm2, 16(%1)\n"
28749- " movq %%mm3, 24(%1)\n"
28750- " movq 32(%0), %%mm0\n"
28751- " movq 40(%0), %%mm1\n"
28752- " movq 48(%0), %%mm2\n"
28753- " movq 56(%0), %%mm3\n"
28754- " movq %%mm0, 32(%1)\n"
28755- " movq %%mm1, 40(%1)\n"
28756- " movq %%mm2, 48(%1)\n"
28757- " movq %%mm3, 56(%1)\n"
28758+ "1: prefetch 320(%1)\n"
28759+ "2: movq (%1), %%mm0\n"
28760+ " movq 8(%1), %%mm1\n"
28761+ " movq 16(%1), %%mm2\n"
28762+ " movq 24(%1), %%mm3\n"
28763+ " movq %%mm0, (%2)\n"
28764+ " movq %%mm1, 8(%2)\n"
28765+ " movq %%mm2, 16(%2)\n"
28766+ " movq %%mm3, 24(%2)\n"
28767+ " movq 32(%1), %%mm0\n"
28768+ " movq 40(%1), %%mm1\n"
28769+ " movq 48(%1), %%mm2\n"
28770+ " movq 56(%1), %%mm3\n"
28771+ " movq %%mm0, 32(%2)\n"
28772+ " movq %%mm1, 40(%2)\n"
28773+ " movq %%mm2, 48(%2)\n"
28774+ " movq %%mm3, 56(%2)\n"
28775 ".section .fixup, \"ax\"\n"
28776- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28777+ "3:\n"
28778+
28779+#ifdef CONFIG_PAX_KERNEXEC
28780+ " movl %%cr0, %0\n"
28781+ " movl %0, %%eax\n"
28782+ " andl $0xFFFEFFFF, %%eax\n"
28783+ " movl %%eax, %%cr0\n"
28784+#endif
28785+
28786+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28787+
28788+#ifdef CONFIG_PAX_KERNEXEC
28789+ " movl %0, %%cr0\n"
28790+#endif
28791+
28792 " jmp 2b\n"
28793 ".previous\n"
28794 _ASM_EXTABLE(1b, 3b)
28795- : : "r" (from), "r" (to) : "memory");
28796+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
28797
28798 from += 64;
28799 to += 64;
28800diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
28801index f6d13ee..aca5f0b 100644
28802--- a/arch/x86/lib/msr-reg.S
28803+++ b/arch/x86/lib/msr-reg.S
28804@@ -3,6 +3,7 @@
28805 #include <asm/dwarf2.h>
28806 #include <asm/asm.h>
28807 #include <asm/msr.h>
28808+#include <asm/alternative-asm.h>
28809
28810 #ifdef CONFIG_X86_64
28811 /*
28812@@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
28813 CFI_STARTPROC
28814 pushq_cfi %rbx
28815 pushq_cfi %rbp
28816- movq %rdi, %r10 /* Save pointer */
28817+ movq %rdi, %r9 /* Save pointer */
28818 xorl %r11d, %r11d /* Return value */
28819 movl (%rdi), %eax
28820 movl 4(%rdi), %ecx
28821@@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
28822 movl 28(%rdi), %edi
28823 CFI_REMEMBER_STATE
28824 1: \op
28825-2: movl %eax, (%r10)
28826+2: movl %eax, (%r9)
28827 movl %r11d, %eax /* Return value */
28828- movl %ecx, 4(%r10)
28829- movl %edx, 8(%r10)
28830- movl %ebx, 12(%r10)
28831- movl %ebp, 20(%r10)
28832- movl %esi, 24(%r10)
28833- movl %edi, 28(%r10)
28834+ movl %ecx, 4(%r9)
28835+ movl %edx, 8(%r9)
28836+ movl %ebx, 12(%r9)
28837+ movl %ebp, 20(%r9)
28838+ movl %esi, 24(%r9)
28839+ movl %edi, 28(%r9)
28840 popq_cfi %rbp
28841 popq_cfi %rbx
28842+ pax_force_retaddr
28843 ret
28844 3:
28845 CFI_RESTORE_STATE
28846diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
28847index fc6ba17..d4d989d 100644
28848--- a/arch/x86/lib/putuser.S
28849+++ b/arch/x86/lib/putuser.S
28850@@ -16,7 +16,9 @@
28851 #include <asm/errno.h>
28852 #include <asm/asm.h>
28853 #include <asm/smap.h>
28854-
28855+#include <asm/segment.h>
28856+#include <asm/pgtable.h>
28857+#include <asm/alternative-asm.h>
28858
28859 /*
28860 * __put_user_X
28861@@ -30,57 +32,125 @@
28862 * as they get called from within inline assembly.
28863 */
28864
28865-#define ENTER CFI_STARTPROC ; \
28866- GET_THREAD_INFO(%_ASM_BX)
28867-#define EXIT ASM_CLAC ; \
28868- ret ; \
28869+#define ENTER CFI_STARTPROC
28870+#define EXIT ASM_CLAC ; \
28871+ pax_force_retaddr ; \
28872+ ret ; \
28873 CFI_ENDPROC
28874
28875+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28876+#define _DEST %_ASM_CX,%_ASM_BX
28877+#else
28878+#define _DEST %_ASM_CX
28879+#endif
28880+
28881+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28882+#define __copyuser_seg gs;
28883+#else
28884+#define __copyuser_seg
28885+#endif
28886+
28887 .text
28888 ENTRY(__put_user_1)
28889 ENTER
28890+
28891+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28892+ GET_THREAD_INFO(%_ASM_BX)
28893 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
28894 jae bad_put_user
28895 ASM_STAC
28896-1: movb %al,(%_ASM_CX)
28897+
28898+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28899+ mov pax_user_shadow_base,%_ASM_BX
28900+ cmp %_ASM_BX,%_ASM_CX
28901+ jb 1234f
28902+ xor %ebx,%ebx
28903+1234:
28904+#endif
28905+
28906+#endif
28907+
28908+1: __copyuser_seg movb %al,(_DEST)
28909 xor %eax,%eax
28910 EXIT
28911 ENDPROC(__put_user_1)
28912
28913 ENTRY(__put_user_2)
28914 ENTER
28915+
28916+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28917+ GET_THREAD_INFO(%_ASM_BX)
28918 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
28919 sub $1,%_ASM_BX
28920 cmp %_ASM_BX,%_ASM_CX
28921 jae bad_put_user
28922 ASM_STAC
28923-2: movw %ax,(%_ASM_CX)
28924+
28925+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28926+ mov pax_user_shadow_base,%_ASM_BX
28927+ cmp %_ASM_BX,%_ASM_CX
28928+ jb 1234f
28929+ xor %ebx,%ebx
28930+1234:
28931+#endif
28932+
28933+#endif
28934+
28935+2: __copyuser_seg movw %ax,(_DEST)
28936 xor %eax,%eax
28937 EXIT
28938 ENDPROC(__put_user_2)
28939
28940 ENTRY(__put_user_4)
28941 ENTER
28942+
28943+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28944+ GET_THREAD_INFO(%_ASM_BX)
28945 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
28946 sub $3,%_ASM_BX
28947 cmp %_ASM_BX,%_ASM_CX
28948 jae bad_put_user
28949 ASM_STAC
28950-3: movl %eax,(%_ASM_CX)
28951+
28952+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28953+ mov pax_user_shadow_base,%_ASM_BX
28954+ cmp %_ASM_BX,%_ASM_CX
28955+ jb 1234f
28956+ xor %ebx,%ebx
28957+1234:
28958+#endif
28959+
28960+#endif
28961+
28962+3: __copyuser_seg movl %eax,(_DEST)
28963 xor %eax,%eax
28964 EXIT
28965 ENDPROC(__put_user_4)
28966
28967 ENTRY(__put_user_8)
28968 ENTER
28969+
28970+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28971+ GET_THREAD_INFO(%_ASM_BX)
28972 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
28973 sub $7,%_ASM_BX
28974 cmp %_ASM_BX,%_ASM_CX
28975 jae bad_put_user
28976 ASM_STAC
28977-4: mov %_ASM_AX,(%_ASM_CX)
28978+
28979+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28980+ mov pax_user_shadow_base,%_ASM_BX
28981+ cmp %_ASM_BX,%_ASM_CX
28982+ jb 1234f
28983+ xor %ebx,%ebx
28984+1234:
28985+#endif
28986+
28987+#endif
28988+
28989+4: __copyuser_seg mov %_ASM_AX,(_DEST)
28990 #ifdef CONFIG_X86_32
28991-5: movl %edx,4(%_ASM_CX)
28992+5: __copyuser_seg movl %edx,4(_DEST)
28993 #endif
28994 xor %eax,%eax
28995 EXIT
28996diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
28997index 1cad221..de671ee 100644
28998--- a/arch/x86/lib/rwlock.S
28999+++ b/arch/x86/lib/rwlock.S
29000@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
29001 FRAME
29002 0: LOCK_PREFIX
29003 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
29004+
29005+#ifdef CONFIG_PAX_REFCOUNT
29006+ jno 1234f
29007+ LOCK_PREFIX
29008+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
29009+ int $4
29010+1234:
29011+ _ASM_EXTABLE(1234b, 1234b)
29012+#endif
29013+
29014 1: rep; nop
29015 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
29016 jne 1b
29017 LOCK_PREFIX
29018 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
29019+
29020+#ifdef CONFIG_PAX_REFCOUNT
29021+ jno 1234f
29022+ LOCK_PREFIX
29023+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
29024+ int $4
29025+1234:
29026+ _ASM_EXTABLE(1234b, 1234b)
29027+#endif
29028+
29029 jnz 0b
29030 ENDFRAME
29031+ pax_force_retaddr
29032 ret
29033 CFI_ENDPROC
29034 END(__write_lock_failed)
29035@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
29036 FRAME
29037 0: LOCK_PREFIX
29038 READ_LOCK_SIZE(inc) (%__lock_ptr)
29039+
29040+#ifdef CONFIG_PAX_REFCOUNT
29041+ jno 1234f
29042+ LOCK_PREFIX
29043+ READ_LOCK_SIZE(dec) (%__lock_ptr)
29044+ int $4
29045+1234:
29046+ _ASM_EXTABLE(1234b, 1234b)
29047+#endif
29048+
29049 1: rep; nop
29050 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
29051 js 1b
29052 LOCK_PREFIX
29053 READ_LOCK_SIZE(dec) (%__lock_ptr)
29054+
29055+#ifdef CONFIG_PAX_REFCOUNT
29056+ jno 1234f
29057+ LOCK_PREFIX
29058+ READ_LOCK_SIZE(inc) (%__lock_ptr)
29059+ int $4
29060+1234:
29061+ _ASM_EXTABLE(1234b, 1234b)
29062+#endif
29063+
29064 js 0b
29065 ENDFRAME
29066+ pax_force_retaddr
29067 ret
29068 CFI_ENDPROC
29069 END(__read_lock_failed)
29070diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
29071index 5dff5f0..cadebf4 100644
29072--- a/arch/x86/lib/rwsem.S
29073+++ b/arch/x86/lib/rwsem.S
29074@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
29075 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
29076 CFI_RESTORE __ASM_REG(dx)
29077 restore_common_regs
29078+ pax_force_retaddr
29079 ret
29080 CFI_ENDPROC
29081 ENDPROC(call_rwsem_down_read_failed)
29082@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
29083 movq %rax,%rdi
29084 call rwsem_down_write_failed
29085 restore_common_regs
29086+ pax_force_retaddr
29087 ret
29088 CFI_ENDPROC
29089 ENDPROC(call_rwsem_down_write_failed)
29090@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
29091 movq %rax,%rdi
29092 call rwsem_wake
29093 restore_common_regs
29094-1: ret
29095+1: pax_force_retaddr
29096+ ret
29097 CFI_ENDPROC
29098 ENDPROC(call_rwsem_wake)
29099
29100@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
29101 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
29102 CFI_RESTORE __ASM_REG(dx)
29103 restore_common_regs
29104+ pax_force_retaddr
29105 ret
29106 CFI_ENDPROC
29107 ENDPROC(call_rwsem_downgrade_wake)
29108diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
29109index a63efd6..ccecad8 100644
29110--- a/arch/x86/lib/thunk_64.S
29111+++ b/arch/x86/lib/thunk_64.S
29112@@ -8,6 +8,7 @@
29113 #include <linux/linkage.h>
29114 #include <asm/dwarf2.h>
29115 #include <asm/calling.h>
29116+#include <asm/alternative-asm.h>
29117
29118 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
29119 .macro THUNK name, func, put_ret_addr_in_rdi=0
29120@@ -41,5 +42,6 @@
29121 SAVE_ARGS
29122 restore:
29123 RESTORE_ARGS
29124+ pax_force_retaddr
29125 ret
29126 CFI_ENDPROC
29127diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
29128index 3eb18ac..6890bc3 100644
29129--- a/arch/x86/lib/usercopy_32.c
29130+++ b/arch/x86/lib/usercopy_32.c
29131@@ -42,11 +42,13 @@ do { \
29132 int __d0; \
29133 might_fault(); \
29134 __asm__ __volatile__( \
29135+ __COPYUSER_SET_ES \
29136 ASM_STAC "\n" \
29137 "0: rep; stosl\n" \
29138 " movl %2,%0\n" \
29139 "1: rep; stosb\n" \
29140 "2: " ASM_CLAC "\n" \
29141+ __COPYUSER_RESTORE_ES \
29142 ".section .fixup,\"ax\"\n" \
29143 "3: lea 0(%2,%0,4),%0\n" \
29144 " jmp 2b\n" \
29145@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
29146
29147 #ifdef CONFIG_X86_INTEL_USERCOPY
29148 static unsigned long
29149-__copy_user_intel(void __user *to, const void *from, unsigned long size)
29150+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
29151 {
29152 int d0, d1;
29153 __asm__ __volatile__(
29154@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29155 " .align 2,0x90\n"
29156 "3: movl 0(%4), %%eax\n"
29157 "4: movl 4(%4), %%edx\n"
29158- "5: movl %%eax, 0(%3)\n"
29159- "6: movl %%edx, 4(%3)\n"
29160+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
29161+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
29162 "7: movl 8(%4), %%eax\n"
29163 "8: movl 12(%4),%%edx\n"
29164- "9: movl %%eax, 8(%3)\n"
29165- "10: movl %%edx, 12(%3)\n"
29166+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
29167+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
29168 "11: movl 16(%4), %%eax\n"
29169 "12: movl 20(%4), %%edx\n"
29170- "13: movl %%eax, 16(%3)\n"
29171- "14: movl %%edx, 20(%3)\n"
29172+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
29173+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
29174 "15: movl 24(%4), %%eax\n"
29175 "16: movl 28(%4), %%edx\n"
29176- "17: movl %%eax, 24(%3)\n"
29177- "18: movl %%edx, 28(%3)\n"
29178+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
29179+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
29180 "19: movl 32(%4), %%eax\n"
29181 "20: movl 36(%4), %%edx\n"
29182- "21: movl %%eax, 32(%3)\n"
29183- "22: movl %%edx, 36(%3)\n"
29184+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
29185+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
29186 "23: movl 40(%4), %%eax\n"
29187 "24: movl 44(%4), %%edx\n"
29188- "25: movl %%eax, 40(%3)\n"
29189- "26: movl %%edx, 44(%3)\n"
29190+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
29191+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
29192 "27: movl 48(%4), %%eax\n"
29193 "28: movl 52(%4), %%edx\n"
29194- "29: movl %%eax, 48(%3)\n"
29195- "30: movl %%edx, 52(%3)\n"
29196+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
29197+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
29198 "31: movl 56(%4), %%eax\n"
29199 "32: movl 60(%4), %%edx\n"
29200- "33: movl %%eax, 56(%3)\n"
29201- "34: movl %%edx, 60(%3)\n"
29202+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
29203+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
29204 " addl $-64, %0\n"
29205 " addl $64, %4\n"
29206 " addl $64, %3\n"
29207@@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29208 " shrl $2, %0\n"
29209 " andl $3, %%eax\n"
29210 " cld\n"
29211+ __COPYUSER_SET_ES
29212 "99: rep; movsl\n"
29213 "36: movl %%eax, %0\n"
29214 "37: rep; movsb\n"
29215 "100:\n"
29216+ __COPYUSER_RESTORE_ES
29217 ".section .fixup,\"ax\"\n"
29218 "101: lea 0(%%eax,%0,4),%0\n"
29219 " jmp 100b\n"
29220@@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29221 }
29222
29223 static unsigned long
29224+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
29225+{
29226+ int d0, d1;
29227+ __asm__ __volatile__(
29228+ " .align 2,0x90\n"
29229+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
29230+ " cmpl $67, %0\n"
29231+ " jbe 3f\n"
29232+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
29233+ " .align 2,0x90\n"
29234+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
29235+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
29236+ "5: movl %%eax, 0(%3)\n"
29237+ "6: movl %%edx, 4(%3)\n"
29238+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
29239+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
29240+ "9: movl %%eax, 8(%3)\n"
29241+ "10: movl %%edx, 12(%3)\n"
29242+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
29243+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
29244+ "13: movl %%eax, 16(%3)\n"
29245+ "14: movl %%edx, 20(%3)\n"
29246+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
29247+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
29248+ "17: movl %%eax, 24(%3)\n"
29249+ "18: movl %%edx, 28(%3)\n"
29250+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
29251+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
29252+ "21: movl %%eax, 32(%3)\n"
29253+ "22: movl %%edx, 36(%3)\n"
29254+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
29255+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
29256+ "25: movl %%eax, 40(%3)\n"
29257+ "26: movl %%edx, 44(%3)\n"
29258+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
29259+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
29260+ "29: movl %%eax, 48(%3)\n"
29261+ "30: movl %%edx, 52(%3)\n"
29262+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
29263+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
29264+ "33: movl %%eax, 56(%3)\n"
29265+ "34: movl %%edx, 60(%3)\n"
29266+ " addl $-64, %0\n"
29267+ " addl $64, %4\n"
29268+ " addl $64, %3\n"
29269+ " cmpl $63, %0\n"
29270+ " ja 1b\n"
29271+ "35: movl %0, %%eax\n"
29272+ " shrl $2, %0\n"
29273+ " andl $3, %%eax\n"
29274+ " cld\n"
29275+ "99: rep; "__copyuser_seg" movsl\n"
29276+ "36: movl %%eax, %0\n"
29277+ "37: rep; "__copyuser_seg" movsb\n"
29278+ "100:\n"
29279+ ".section .fixup,\"ax\"\n"
29280+ "101: lea 0(%%eax,%0,4),%0\n"
29281+ " jmp 100b\n"
29282+ ".previous\n"
29283+ _ASM_EXTABLE(1b,100b)
29284+ _ASM_EXTABLE(2b,100b)
29285+ _ASM_EXTABLE(3b,100b)
29286+ _ASM_EXTABLE(4b,100b)
29287+ _ASM_EXTABLE(5b,100b)
29288+ _ASM_EXTABLE(6b,100b)
29289+ _ASM_EXTABLE(7b,100b)
29290+ _ASM_EXTABLE(8b,100b)
29291+ _ASM_EXTABLE(9b,100b)
29292+ _ASM_EXTABLE(10b,100b)
29293+ _ASM_EXTABLE(11b,100b)
29294+ _ASM_EXTABLE(12b,100b)
29295+ _ASM_EXTABLE(13b,100b)
29296+ _ASM_EXTABLE(14b,100b)
29297+ _ASM_EXTABLE(15b,100b)
29298+ _ASM_EXTABLE(16b,100b)
29299+ _ASM_EXTABLE(17b,100b)
29300+ _ASM_EXTABLE(18b,100b)
29301+ _ASM_EXTABLE(19b,100b)
29302+ _ASM_EXTABLE(20b,100b)
29303+ _ASM_EXTABLE(21b,100b)
29304+ _ASM_EXTABLE(22b,100b)
29305+ _ASM_EXTABLE(23b,100b)
29306+ _ASM_EXTABLE(24b,100b)
29307+ _ASM_EXTABLE(25b,100b)
29308+ _ASM_EXTABLE(26b,100b)
29309+ _ASM_EXTABLE(27b,100b)
29310+ _ASM_EXTABLE(28b,100b)
29311+ _ASM_EXTABLE(29b,100b)
29312+ _ASM_EXTABLE(30b,100b)
29313+ _ASM_EXTABLE(31b,100b)
29314+ _ASM_EXTABLE(32b,100b)
29315+ _ASM_EXTABLE(33b,100b)
29316+ _ASM_EXTABLE(34b,100b)
29317+ _ASM_EXTABLE(35b,100b)
29318+ _ASM_EXTABLE(36b,100b)
29319+ _ASM_EXTABLE(37b,100b)
29320+ _ASM_EXTABLE(99b,101b)
29321+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
29322+ : "1"(to), "2"(from), "0"(size)
29323+ : "eax", "edx", "memory");
29324+ return size;
29325+}
29326+
29327+static unsigned long __size_overflow(3)
29328 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
29329 {
29330 int d0, d1;
29331 __asm__ __volatile__(
29332 " .align 2,0x90\n"
29333- "0: movl 32(%4), %%eax\n"
29334+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
29335 " cmpl $67, %0\n"
29336 " jbe 2f\n"
29337- "1: movl 64(%4), %%eax\n"
29338+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
29339 " .align 2,0x90\n"
29340- "2: movl 0(%4), %%eax\n"
29341- "21: movl 4(%4), %%edx\n"
29342+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
29343+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
29344 " movl %%eax, 0(%3)\n"
29345 " movl %%edx, 4(%3)\n"
29346- "3: movl 8(%4), %%eax\n"
29347- "31: movl 12(%4),%%edx\n"
29348+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
29349+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
29350 " movl %%eax, 8(%3)\n"
29351 " movl %%edx, 12(%3)\n"
29352- "4: movl 16(%4), %%eax\n"
29353- "41: movl 20(%4), %%edx\n"
29354+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
29355+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
29356 " movl %%eax, 16(%3)\n"
29357 " movl %%edx, 20(%3)\n"
29358- "10: movl 24(%4), %%eax\n"
29359- "51: movl 28(%4), %%edx\n"
29360+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
29361+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
29362 " movl %%eax, 24(%3)\n"
29363 " movl %%edx, 28(%3)\n"
29364- "11: movl 32(%4), %%eax\n"
29365- "61: movl 36(%4), %%edx\n"
29366+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
29367+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
29368 " movl %%eax, 32(%3)\n"
29369 " movl %%edx, 36(%3)\n"
29370- "12: movl 40(%4), %%eax\n"
29371- "71: movl 44(%4), %%edx\n"
29372+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
29373+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
29374 " movl %%eax, 40(%3)\n"
29375 " movl %%edx, 44(%3)\n"
29376- "13: movl 48(%4), %%eax\n"
29377- "81: movl 52(%4), %%edx\n"
29378+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
29379+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
29380 " movl %%eax, 48(%3)\n"
29381 " movl %%edx, 52(%3)\n"
29382- "14: movl 56(%4), %%eax\n"
29383- "91: movl 60(%4), %%edx\n"
29384+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
29385+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
29386 " movl %%eax, 56(%3)\n"
29387 " movl %%edx, 60(%3)\n"
29388 " addl $-64, %0\n"
29389@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
29390 " shrl $2, %0\n"
29391 " andl $3, %%eax\n"
29392 " cld\n"
29393- "6: rep; movsl\n"
29394+ "6: rep; "__copyuser_seg" movsl\n"
29395 " movl %%eax,%0\n"
29396- "7: rep; movsb\n"
29397+ "7: rep; "__copyuser_seg" movsb\n"
29398 "8:\n"
29399 ".section .fixup,\"ax\"\n"
29400 "9: lea 0(%%eax,%0,4),%0\n"
29401@@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
29402 * hyoshiok@miraclelinux.com
29403 */
29404
29405-static unsigned long __copy_user_zeroing_intel_nocache(void *to,
29406+static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
29407 const void __user *from, unsigned long size)
29408 {
29409 int d0, d1;
29410
29411 __asm__ __volatile__(
29412 " .align 2,0x90\n"
29413- "0: movl 32(%4), %%eax\n"
29414+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
29415 " cmpl $67, %0\n"
29416 " jbe 2f\n"
29417- "1: movl 64(%4), %%eax\n"
29418+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
29419 " .align 2,0x90\n"
29420- "2: movl 0(%4), %%eax\n"
29421- "21: movl 4(%4), %%edx\n"
29422+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
29423+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
29424 " movnti %%eax, 0(%3)\n"
29425 " movnti %%edx, 4(%3)\n"
29426- "3: movl 8(%4), %%eax\n"
29427- "31: movl 12(%4),%%edx\n"
29428+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
29429+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
29430 " movnti %%eax, 8(%3)\n"
29431 " movnti %%edx, 12(%3)\n"
29432- "4: movl 16(%4), %%eax\n"
29433- "41: movl 20(%4), %%edx\n"
29434+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
29435+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
29436 " movnti %%eax, 16(%3)\n"
29437 " movnti %%edx, 20(%3)\n"
29438- "10: movl 24(%4), %%eax\n"
29439- "51: movl 28(%4), %%edx\n"
29440+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
29441+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
29442 " movnti %%eax, 24(%3)\n"
29443 " movnti %%edx, 28(%3)\n"
29444- "11: movl 32(%4), %%eax\n"
29445- "61: movl 36(%4), %%edx\n"
29446+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
29447+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
29448 " movnti %%eax, 32(%3)\n"
29449 " movnti %%edx, 36(%3)\n"
29450- "12: movl 40(%4), %%eax\n"
29451- "71: movl 44(%4), %%edx\n"
29452+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
29453+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
29454 " movnti %%eax, 40(%3)\n"
29455 " movnti %%edx, 44(%3)\n"
29456- "13: movl 48(%4), %%eax\n"
29457- "81: movl 52(%4), %%edx\n"
29458+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
29459+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
29460 " movnti %%eax, 48(%3)\n"
29461 " movnti %%edx, 52(%3)\n"
29462- "14: movl 56(%4), %%eax\n"
29463- "91: movl 60(%4), %%edx\n"
29464+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
29465+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
29466 " movnti %%eax, 56(%3)\n"
29467 " movnti %%edx, 60(%3)\n"
29468 " addl $-64, %0\n"
29469@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
29470 " shrl $2, %0\n"
29471 " andl $3, %%eax\n"
29472 " cld\n"
29473- "6: rep; movsl\n"
29474+ "6: rep; "__copyuser_seg" movsl\n"
29475 " movl %%eax,%0\n"
29476- "7: rep; movsb\n"
29477+ "7: rep; "__copyuser_seg" movsb\n"
29478 "8:\n"
29479 ".section .fixup,\"ax\"\n"
29480 "9: lea 0(%%eax,%0,4),%0\n"
29481@@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
29482 return size;
29483 }
29484
29485-static unsigned long __copy_user_intel_nocache(void *to,
29486+static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
29487 const void __user *from, unsigned long size)
29488 {
29489 int d0, d1;
29490
29491 __asm__ __volatile__(
29492 " .align 2,0x90\n"
29493- "0: movl 32(%4), %%eax\n"
29494+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
29495 " cmpl $67, %0\n"
29496 " jbe 2f\n"
29497- "1: movl 64(%4), %%eax\n"
29498+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
29499 " .align 2,0x90\n"
29500- "2: movl 0(%4), %%eax\n"
29501- "21: movl 4(%4), %%edx\n"
29502+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
29503+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
29504 " movnti %%eax, 0(%3)\n"
29505 " movnti %%edx, 4(%3)\n"
29506- "3: movl 8(%4), %%eax\n"
29507- "31: movl 12(%4),%%edx\n"
29508+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
29509+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
29510 " movnti %%eax, 8(%3)\n"
29511 " movnti %%edx, 12(%3)\n"
29512- "4: movl 16(%4), %%eax\n"
29513- "41: movl 20(%4), %%edx\n"
29514+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
29515+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
29516 " movnti %%eax, 16(%3)\n"
29517 " movnti %%edx, 20(%3)\n"
29518- "10: movl 24(%4), %%eax\n"
29519- "51: movl 28(%4), %%edx\n"
29520+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
29521+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
29522 " movnti %%eax, 24(%3)\n"
29523 " movnti %%edx, 28(%3)\n"
29524- "11: movl 32(%4), %%eax\n"
29525- "61: movl 36(%4), %%edx\n"
29526+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
29527+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
29528 " movnti %%eax, 32(%3)\n"
29529 " movnti %%edx, 36(%3)\n"
29530- "12: movl 40(%4), %%eax\n"
29531- "71: movl 44(%4), %%edx\n"
29532+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
29533+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
29534 " movnti %%eax, 40(%3)\n"
29535 " movnti %%edx, 44(%3)\n"
29536- "13: movl 48(%4), %%eax\n"
29537- "81: movl 52(%4), %%edx\n"
29538+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
29539+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
29540 " movnti %%eax, 48(%3)\n"
29541 " movnti %%edx, 52(%3)\n"
29542- "14: movl 56(%4), %%eax\n"
29543- "91: movl 60(%4), %%edx\n"
29544+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
29545+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
29546 " movnti %%eax, 56(%3)\n"
29547 " movnti %%edx, 60(%3)\n"
29548 " addl $-64, %0\n"
29549@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
29550 " shrl $2, %0\n"
29551 " andl $3, %%eax\n"
29552 " cld\n"
29553- "6: rep; movsl\n"
29554+ "6: rep; "__copyuser_seg" movsl\n"
29555 " movl %%eax,%0\n"
29556- "7: rep; movsb\n"
29557+ "7: rep; "__copyuser_seg" movsb\n"
29558 "8:\n"
29559 ".section .fixup,\"ax\"\n"
29560 "9: lea 0(%%eax,%0,4),%0\n"
29561@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
29562 */
29563 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
29564 unsigned long size);
29565-unsigned long __copy_user_intel(void __user *to, const void *from,
29566+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
29567+ unsigned long size);
29568+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
29569 unsigned long size);
29570 unsigned long __copy_user_zeroing_intel_nocache(void *to,
29571 const void __user *from, unsigned long size);
29572 #endif /* CONFIG_X86_INTEL_USERCOPY */
29573
29574 /* Generic arbitrary sized copy. */
29575-#define __copy_user(to, from, size) \
29576+#define __copy_user(to, from, size, prefix, set, restore) \
29577 do { \
29578 int __d0, __d1, __d2; \
29579 __asm__ __volatile__( \
29580+ set \
29581 " cmp $7,%0\n" \
29582 " jbe 1f\n" \
29583 " movl %1,%0\n" \
29584 " negl %0\n" \
29585 " andl $7,%0\n" \
29586 " subl %0,%3\n" \
29587- "4: rep; movsb\n" \
29588+ "4: rep; "prefix"movsb\n" \
29589 " movl %3,%0\n" \
29590 " shrl $2,%0\n" \
29591 " andl $3,%3\n" \
29592 " .align 2,0x90\n" \
29593- "0: rep; movsl\n" \
29594+ "0: rep; "prefix"movsl\n" \
29595 " movl %3,%0\n" \
29596- "1: rep; movsb\n" \
29597+ "1: rep; "prefix"movsb\n" \
29598 "2:\n" \
29599+ restore \
29600 ".section .fixup,\"ax\"\n" \
29601 "5: addl %3,%0\n" \
29602 " jmp 2b\n" \
29603@@ -538,14 +650,14 @@ do { \
29604 " negl %0\n" \
29605 " andl $7,%0\n" \
29606 " subl %0,%3\n" \
29607- "4: rep; movsb\n" \
29608+ "4: rep; "__copyuser_seg"movsb\n" \
29609 " movl %3,%0\n" \
29610 " shrl $2,%0\n" \
29611 " andl $3,%3\n" \
29612 " .align 2,0x90\n" \
29613- "0: rep; movsl\n" \
29614+ "0: rep; "__copyuser_seg"movsl\n" \
29615 " movl %3,%0\n" \
29616- "1: rep; movsb\n" \
29617+ "1: rep; "__copyuser_seg"movsb\n" \
29618 "2:\n" \
29619 ".section .fixup,\"ax\"\n" \
29620 "5: addl %3,%0\n" \
29621@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
29622 {
29623 stac();
29624 if (movsl_is_ok(to, from, n))
29625- __copy_user(to, from, n);
29626+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
29627 else
29628- n = __copy_user_intel(to, from, n);
29629+ n = __generic_copy_to_user_intel(to, from, n);
29630 clac();
29631 return n;
29632 }
29633@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
29634 {
29635 stac();
29636 if (movsl_is_ok(to, from, n))
29637- __copy_user(to, from, n);
29638+ __copy_user(to, from, n, __copyuser_seg, "", "");
29639 else
29640- n = __copy_user_intel((void __user *)to,
29641- (const void *)from, n);
29642+ n = __generic_copy_from_user_intel(to, from, n);
29643 clac();
29644 return n;
29645 }
29646@@ -632,60 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
29647 if (n > 64 && cpu_has_xmm2)
29648 n = __copy_user_intel_nocache(to, from, n);
29649 else
29650- __copy_user(to, from, n);
29651+ __copy_user(to, from, n, __copyuser_seg, "", "");
29652 #else
29653- __copy_user(to, from, n);
29654+ __copy_user(to, from, n, __copyuser_seg, "", "");
29655 #endif
29656 clac();
29657 return n;
29658 }
29659 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
29660
29661-/**
29662- * copy_to_user: - Copy a block of data into user space.
29663- * @to: Destination address, in user space.
29664- * @from: Source address, in kernel space.
29665- * @n: Number of bytes to copy.
29666- *
29667- * Context: User context only. This function may sleep.
29668- *
29669- * Copy data from kernel space to user space.
29670- *
29671- * Returns number of bytes that could not be copied.
29672- * On success, this will be zero.
29673- */
29674-unsigned long
29675-copy_to_user(void __user *to, const void *from, unsigned long n)
29676+#ifdef CONFIG_PAX_MEMORY_UDEREF
29677+void __set_fs(mm_segment_t x)
29678 {
29679- if (access_ok(VERIFY_WRITE, to, n))
29680- n = __copy_to_user(to, from, n);
29681- return n;
29682+ switch (x.seg) {
29683+ case 0:
29684+ loadsegment(gs, 0);
29685+ break;
29686+ case TASK_SIZE_MAX:
29687+ loadsegment(gs, __USER_DS);
29688+ break;
29689+ case -1UL:
29690+ loadsegment(gs, __KERNEL_DS);
29691+ break;
29692+ default:
29693+ BUG();
29694+ }
29695 }
29696-EXPORT_SYMBOL(copy_to_user);
29697+EXPORT_SYMBOL(__set_fs);
29698
29699-/**
29700- * copy_from_user: - Copy a block of data from user space.
29701- * @to: Destination address, in kernel space.
29702- * @from: Source address, in user space.
29703- * @n: Number of bytes to copy.
29704- *
29705- * Context: User context only. This function may sleep.
29706- *
29707- * Copy data from user space to kernel space.
29708- *
29709- * Returns number of bytes that could not be copied.
29710- * On success, this will be zero.
29711- *
29712- * If some data could not be copied, this function will pad the copied
29713- * data to the requested size using zero bytes.
29714- */
29715-unsigned long
29716-_copy_from_user(void *to, const void __user *from, unsigned long n)
29717+void set_fs(mm_segment_t x)
29718 {
29719- if (access_ok(VERIFY_READ, from, n))
29720- n = __copy_from_user(to, from, n);
29721- else
29722- memset(to, 0, n);
29723- return n;
29724+ current_thread_info()->addr_limit = x;
29725+ __set_fs(x);
29726 }
29727-EXPORT_SYMBOL(_copy_from_user);
29728+EXPORT_SYMBOL(set_fs);
29729+#endif
29730diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
29731index 906fea3..0194a18 100644
29732--- a/arch/x86/lib/usercopy_64.c
29733+++ b/arch/x86/lib/usercopy_64.c
29734@@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
29735 might_fault();
29736 /* no memory constraint because it doesn't change any memory gcc knows
29737 about */
29738+ pax_open_userland();
29739 stac();
29740 asm volatile(
29741 " testq %[size8],%[size8]\n"
29742@@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
29743 _ASM_EXTABLE(0b,3b)
29744 _ASM_EXTABLE(1b,2b)
29745 : [size8] "=&c"(size), [dst] "=&D" (__d0)
29746- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
29747+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
29748 [zero] "r" (0UL), [eight] "r" (8UL));
29749 clac();
29750+ pax_close_userland();
29751 return size;
29752 }
29753 EXPORT_SYMBOL(__clear_user);
29754@@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
29755 }
29756 EXPORT_SYMBOL(clear_user);
29757
29758-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
29759+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
29760 {
29761- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
29762- return copy_user_generic((__force void *)to, (__force void *)from, len);
29763- }
29764- return len;
29765+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
29766+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
29767+ return len;
29768 }
29769 EXPORT_SYMBOL(copy_in_user);
29770
29771@@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
29772 * it is not necessary to optimize tail handling.
29773 */
29774 unsigned long
29775-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
29776+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
29777 {
29778 char c;
29779 unsigned zero_len;
29780
29781+ clac();
29782+ pax_close_userland();
29783 for (; len; --len, to++) {
29784 if (__get_user_nocheck(c, from++, sizeof(char)))
29785 break;
29786@@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
29787 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
29788 if (__put_user_nocheck(c, to++, sizeof(char)))
29789 break;
29790- clac();
29791 return len;
29792 }
29793diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
29794index 23d8e5f..9ccc13a 100644
29795--- a/arch/x86/mm/Makefile
29796+++ b/arch/x86/mm/Makefile
29797@@ -28,3 +28,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
29798 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
29799
29800 obj-$(CONFIG_MEMTEST) += memtest.o
29801+
29802+quote:="
29803+obj-$(CONFIG_X86_64) += uderef_64.o
29804+CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
29805diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
29806index 903ec1e..c4166b2 100644
29807--- a/arch/x86/mm/extable.c
29808+++ b/arch/x86/mm/extable.c
29809@@ -6,12 +6,24 @@
29810 static inline unsigned long
29811 ex_insn_addr(const struct exception_table_entry *x)
29812 {
29813- return (unsigned long)&x->insn + x->insn;
29814+ unsigned long reloc = 0;
29815+
29816+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29817+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29818+#endif
29819+
29820+ return (unsigned long)&x->insn + x->insn + reloc;
29821 }
29822 static inline unsigned long
29823 ex_fixup_addr(const struct exception_table_entry *x)
29824 {
29825- return (unsigned long)&x->fixup + x->fixup;
29826+ unsigned long reloc = 0;
29827+
29828+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29829+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29830+#endif
29831+
29832+ return (unsigned long)&x->fixup + x->fixup + reloc;
29833 }
29834
29835 int fixup_exception(struct pt_regs *regs)
29836@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
29837 unsigned long new_ip;
29838
29839 #ifdef CONFIG_PNPBIOS
29840- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
29841+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
29842 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
29843 extern u32 pnp_bios_is_utter_crap;
29844 pnp_bios_is_utter_crap = 1;
29845@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
29846 i += 4;
29847 p->fixup -= i;
29848 i += 4;
29849+
29850+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29851+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
29852+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29853+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29854+#endif
29855+
29856 }
29857 }
29858
29859diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
29860index 654be4a..a4a3da1 100644
29861--- a/arch/x86/mm/fault.c
29862+++ b/arch/x86/mm/fault.c
29863@@ -14,11 +14,18 @@
29864 #include <linux/hugetlb.h> /* hstate_index_to_shift */
29865 #include <linux/prefetch.h> /* prefetchw */
29866 #include <linux/context_tracking.h> /* exception_enter(), ... */
29867+#include <linux/unistd.h>
29868+#include <linux/compiler.h>
29869
29870 #include <asm/traps.h> /* dotraplinkage, ... */
29871 #include <asm/pgalloc.h> /* pgd_*(), ... */
29872 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
29873 #include <asm/fixmap.h> /* VSYSCALL_START */
29874+#include <asm/tlbflush.h>
29875+
29876+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29877+#include <asm/stacktrace.h>
29878+#endif
29879
29880 /*
29881 * Page fault error code bits:
29882@@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
29883 int ret = 0;
29884
29885 /* kprobe_running() needs smp_processor_id() */
29886- if (kprobes_built_in() && !user_mode_vm(regs)) {
29887+ if (kprobes_built_in() && !user_mode(regs)) {
29888 preempt_disable();
29889 if (kprobe_running() && kprobe_fault_handler(regs, 14))
29890 ret = 1;
29891@@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
29892 return !instr_lo || (instr_lo>>1) == 1;
29893 case 0x00:
29894 /* Prefetch instruction is 0x0F0D or 0x0F18 */
29895- if (probe_kernel_address(instr, opcode))
29896+ if (user_mode(regs)) {
29897+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
29898+ return 0;
29899+ } else if (probe_kernel_address(instr, opcode))
29900 return 0;
29901
29902 *prefetch = (instr_lo == 0xF) &&
29903@@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
29904 while (instr < max_instr) {
29905 unsigned char opcode;
29906
29907- if (probe_kernel_address(instr, opcode))
29908+ if (user_mode(regs)) {
29909+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
29910+ break;
29911+ } else if (probe_kernel_address(instr, opcode))
29912 break;
29913
29914 instr++;
29915@@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
29916 force_sig_info(si_signo, &info, tsk);
29917 }
29918
29919+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
29920+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
29921+#endif
29922+
29923+#ifdef CONFIG_PAX_EMUTRAMP
29924+static int pax_handle_fetch_fault(struct pt_regs *regs);
29925+#endif
29926+
29927+#ifdef CONFIG_PAX_PAGEEXEC
29928+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
29929+{
29930+ pgd_t *pgd;
29931+ pud_t *pud;
29932+ pmd_t *pmd;
29933+
29934+ pgd = pgd_offset(mm, address);
29935+ if (!pgd_present(*pgd))
29936+ return NULL;
29937+ pud = pud_offset(pgd, address);
29938+ if (!pud_present(*pud))
29939+ return NULL;
29940+ pmd = pmd_offset(pud, address);
29941+ if (!pmd_present(*pmd))
29942+ return NULL;
29943+ return pmd;
29944+}
29945+#endif
29946+
29947 DEFINE_SPINLOCK(pgd_lock);
29948 LIST_HEAD(pgd_list);
29949
29950@@ -232,10 +273,27 @@ void vmalloc_sync_all(void)
29951 for (address = VMALLOC_START & PMD_MASK;
29952 address >= TASK_SIZE && address < FIXADDR_TOP;
29953 address += PMD_SIZE) {
29954+
29955+#ifdef CONFIG_PAX_PER_CPU_PGD
29956+ unsigned long cpu;
29957+#else
29958 struct page *page;
29959+#endif
29960
29961 spin_lock(&pgd_lock);
29962+
29963+#ifdef CONFIG_PAX_PER_CPU_PGD
29964+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
29965+ pgd_t *pgd = get_cpu_pgd(cpu, user);
29966+ pmd_t *ret;
29967+
29968+ ret = vmalloc_sync_one(pgd, address);
29969+ if (!ret)
29970+ break;
29971+ pgd = get_cpu_pgd(cpu, kernel);
29972+#else
29973 list_for_each_entry(page, &pgd_list, lru) {
29974+ pgd_t *pgd;
29975 spinlock_t *pgt_lock;
29976 pmd_t *ret;
29977
29978@@ -243,8 +301,14 @@ void vmalloc_sync_all(void)
29979 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
29980
29981 spin_lock(pgt_lock);
29982- ret = vmalloc_sync_one(page_address(page), address);
29983+ pgd = page_address(page);
29984+#endif
29985+
29986+ ret = vmalloc_sync_one(pgd, address);
29987+
29988+#ifndef CONFIG_PAX_PER_CPU_PGD
29989 spin_unlock(pgt_lock);
29990+#endif
29991
29992 if (!ret)
29993 break;
29994@@ -278,6 +342,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
29995 * an interrupt in the middle of a task switch..
29996 */
29997 pgd_paddr = read_cr3();
29998+
29999+#ifdef CONFIG_PAX_PER_CPU_PGD
30000+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
30001+ vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
30002+#endif
30003+
30004 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
30005 if (!pmd_k)
30006 return -1;
30007@@ -373,11 +443,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
30008 * happen within a race in page table update. In the later
30009 * case just flush:
30010 */
30011- pgd = pgd_offset(current->active_mm, address);
30012+
30013 pgd_ref = pgd_offset_k(address);
30014 if (pgd_none(*pgd_ref))
30015 return -1;
30016
30017+#ifdef CONFIG_PAX_PER_CPU_PGD
30018+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
30019+ pgd = pgd_offset_cpu(smp_processor_id(), user, address);
30020+ if (pgd_none(*pgd)) {
30021+ set_pgd(pgd, *pgd_ref);
30022+ arch_flush_lazy_mmu_mode();
30023+ } else {
30024+ BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
30025+ }
30026+ pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
30027+#else
30028+ pgd = pgd_offset(current->active_mm, address);
30029+#endif
30030+
30031 if (pgd_none(*pgd)) {
30032 set_pgd(pgd, *pgd_ref);
30033 arch_flush_lazy_mmu_mode();
30034@@ -543,7 +627,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
30035 static int is_errata100(struct pt_regs *regs, unsigned long address)
30036 {
30037 #ifdef CONFIG_X86_64
30038- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
30039+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
30040 return 1;
30041 #endif
30042 return 0;
30043@@ -570,7 +654,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
30044 }
30045
30046 static const char nx_warning[] = KERN_CRIT
30047-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
30048+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
30049
30050 static void
30051 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
30052@@ -579,15 +663,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
30053 if (!oops_may_print())
30054 return;
30055
30056- if (error_code & PF_INSTR) {
30057+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
30058 unsigned int level;
30059
30060 pte_t *pte = lookup_address(address, &level);
30061
30062 if (pte && pte_present(*pte) && !pte_exec(*pte))
30063- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
30064+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
30065 }
30066
30067+#ifdef CONFIG_PAX_KERNEXEC
30068+ if (init_mm.start_code <= address && address < init_mm.end_code) {
30069+ if (current->signal->curr_ip)
30070+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
30071+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
30072+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
30073+ else
30074+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
30075+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
30076+ }
30077+#endif
30078+
30079 printk(KERN_ALERT "BUG: unable to handle kernel ");
30080 if (address < PAGE_SIZE)
30081 printk(KERN_CONT "NULL pointer dereference");
30082@@ -750,6 +846,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
30083 return;
30084 }
30085 #endif
30086+
30087+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30088+ if (pax_is_fetch_fault(regs, error_code, address)) {
30089+
30090+#ifdef CONFIG_PAX_EMUTRAMP
30091+ switch (pax_handle_fetch_fault(regs)) {
30092+ case 2:
30093+ return;
30094+ }
30095+#endif
30096+
30097+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
30098+ do_group_exit(SIGKILL);
30099+ }
30100+#endif
30101+
30102 /* Kernel addresses are always protection faults: */
30103 if (address >= TASK_SIZE)
30104 error_code |= PF_PROT;
30105@@ -835,7 +947,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
30106 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
30107 printk(KERN_ERR
30108 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
30109- tsk->comm, tsk->pid, address);
30110+ tsk->comm, task_pid_nr(tsk), address);
30111 code = BUS_MCEERR_AR;
30112 }
30113 #endif
30114@@ -898,6 +1010,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
30115 return 1;
30116 }
30117
30118+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
30119+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
30120+{
30121+ pte_t *pte;
30122+ pmd_t *pmd;
30123+ spinlock_t *ptl;
30124+ unsigned char pte_mask;
30125+
30126+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
30127+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
30128+ return 0;
30129+
30130+ /* PaX: it's our fault, let's handle it if we can */
30131+
30132+ /* PaX: take a look at read faults before acquiring any locks */
30133+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
30134+ /* instruction fetch attempt from a protected page in user mode */
30135+ up_read(&mm->mmap_sem);
30136+
30137+#ifdef CONFIG_PAX_EMUTRAMP
30138+ switch (pax_handle_fetch_fault(regs)) {
30139+ case 2:
30140+ return 1;
30141+ }
30142+#endif
30143+
30144+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
30145+ do_group_exit(SIGKILL);
30146+ }
30147+
30148+ pmd = pax_get_pmd(mm, address);
30149+ if (unlikely(!pmd))
30150+ return 0;
30151+
30152+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
30153+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
30154+ pte_unmap_unlock(pte, ptl);
30155+ return 0;
30156+ }
30157+
30158+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
30159+ /* write attempt to a protected page in user mode */
30160+ pte_unmap_unlock(pte, ptl);
30161+ return 0;
30162+ }
30163+
30164+#ifdef CONFIG_SMP
30165+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
30166+#else
30167+ if (likely(address > get_limit(regs->cs)))
30168+#endif
30169+ {
30170+ set_pte(pte, pte_mkread(*pte));
30171+ __flush_tlb_one(address);
30172+ pte_unmap_unlock(pte, ptl);
30173+ up_read(&mm->mmap_sem);
30174+ return 1;
30175+ }
30176+
30177+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
30178+
30179+ /*
30180+ * PaX: fill DTLB with user rights and retry
30181+ */
30182+ __asm__ __volatile__ (
30183+ "orb %2,(%1)\n"
30184+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
30185+/*
30186+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
30187+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
30188+ * page fault when examined during a TLB load attempt. this is true not only
30189+ * for PTEs holding a non-present entry but also present entries that will
30190+ * raise a page fault (such as those set up by PaX, or the copy-on-write
30191+ * mechanism). in effect it means that we do *not* need to flush the TLBs
30192+ * for our target pages since their PTEs are simply not in the TLBs at all.
30193+
30194+ * the best thing in omitting it is that we gain around 15-20% speed in the
30195+ * fast path of the page fault handler and can get rid of tracing since we
30196+ * can no longer flush unintended entries.
30197+ */
30198+ "invlpg (%0)\n"
30199+#endif
30200+ __copyuser_seg"testb $0,(%0)\n"
30201+ "xorb %3,(%1)\n"
30202+ :
30203+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
30204+ : "memory", "cc");
30205+ pte_unmap_unlock(pte, ptl);
30206+ up_read(&mm->mmap_sem);
30207+ return 1;
30208+}
30209+#endif
30210+
30211 /*
30212 * Handle a spurious fault caused by a stale TLB entry.
30213 *
30214@@ -964,6 +1169,9 @@ int show_unhandled_signals = 1;
30215 static inline int
30216 access_error(unsigned long error_code, struct vm_area_struct *vma)
30217 {
30218+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
30219+ return 1;
30220+
30221 if (error_code & PF_WRITE) {
30222 /* write, present and write, not present: */
30223 if (unlikely(!(vma->vm_flags & VM_WRITE)))
30224@@ -992,7 +1200,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
30225 if (error_code & PF_USER)
30226 return false;
30227
30228- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
30229+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
30230 return false;
30231
30232 return true;
30233@@ -1008,18 +1216,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
30234 {
30235 struct vm_area_struct *vma;
30236 struct task_struct *tsk;
30237- unsigned long address;
30238 struct mm_struct *mm;
30239 int fault;
30240 int write = error_code & PF_WRITE;
30241 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
30242 (write ? FAULT_FLAG_WRITE : 0);
30243
30244- tsk = current;
30245- mm = tsk->mm;
30246-
30247 /* Get the faulting address: */
30248- address = read_cr2();
30249+ unsigned long address = read_cr2();
30250+
30251+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30252+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
30253+ if (!search_exception_tables(regs->ip)) {
30254+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
30255+ bad_area_nosemaphore(regs, error_code, address);
30256+ return;
30257+ }
30258+ if (address < pax_user_shadow_base) {
30259+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
30260+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
30261+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
30262+ } else
30263+ address -= pax_user_shadow_base;
30264+ }
30265+#endif
30266+
30267+ tsk = current;
30268+ mm = tsk->mm;
30269
30270 /*
30271 * Detect and handle instructions that would cause a page fault for
30272@@ -1080,7 +1303,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
30273 * User-mode registers count as a user access even for any
30274 * potential system fault or CPU buglet:
30275 */
30276- if (user_mode_vm(regs)) {
30277+ if (user_mode(regs)) {
30278 local_irq_enable();
30279 error_code |= PF_USER;
30280 } else {
30281@@ -1142,6 +1365,11 @@ retry:
30282 might_sleep();
30283 }
30284
30285+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
30286+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
30287+ return;
30288+#endif
30289+
30290 vma = find_vma(mm, address);
30291 if (unlikely(!vma)) {
30292 bad_area(regs, error_code, address);
30293@@ -1153,18 +1381,24 @@ retry:
30294 bad_area(regs, error_code, address);
30295 return;
30296 }
30297- if (error_code & PF_USER) {
30298- /*
30299- * Accessing the stack below %sp is always a bug.
30300- * The large cushion allows instructions like enter
30301- * and pusha to work. ("enter $65535, $31" pushes
30302- * 32 pointers and then decrements %sp by 65535.)
30303- */
30304- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
30305- bad_area(regs, error_code, address);
30306- return;
30307- }
30308+ /*
30309+ * Accessing the stack below %sp is always a bug.
30310+ * The large cushion allows instructions like enter
30311+ * and pusha to work. ("enter $65535, $31" pushes
30312+ * 32 pointers and then decrements %sp by 65535.)
30313+ */
30314+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
30315+ bad_area(regs, error_code, address);
30316+ return;
30317 }
30318+
30319+#ifdef CONFIG_PAX_SEGMEXEC
30320+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
30321+ bad_area(regs, error_code, address);
30322+ return;
30323+ }
30324+#endif
30325+
30326 if (unlikely(expand_stack(vma, address))) {
30327 bad_area(regs, error_code, address);
30328 return;
30329@@ -1230,3 +1464,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
30330 __do_page_fault(regs, error_code);
30331 exception_exit(prev_state);
30332 }
30333+
30334+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30335+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
30336+{
30337+ struct mm_struct *mm = current->mm;
30338+ unsigned long ip = regs->ip;
30339+
30340+ if (v8086_mode(regs))
30341+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
30342+
30343+#ifdef CONFIG_PAX_PAGEEXEC
30344+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
30345+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
30346+ return true;
30347+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
30348+ return true;
30349+ return false;
30350+ }
30351+#endif
30352+
30353+#ifdef CONFIG_PAX_SEGMEXEC
30354+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
30355+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
30356+ return true;
30357+ return false;
30358+ }
30359+#endif
30360+
30361+ return false;
30362+}
30363+#endif
30364+
30365+#ifdef CONFIG_PAX_EMUTRAMP
30366+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
30367+{
30368+ int err;
30369+
30370+ do { /* PaX: libffi trampoline emulation */
30371+ unsigned char mov, jmp;
30372+ unsigned int addr1, addr2;
30373+
30374+#ifdef CONFIG_X86_64
30375+ if ((regs->ip + 9) >> 32)
30376+ break;
30377+#endif
30378+
30379+ err = get_user(mov, (unsigned char __user *)regs->ip);
30380+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
30381+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
30382+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
30383+
30384+ if (err)
30385+ break;
30386+
30387+ if (mov == 0xB8 && jmp == 0xE9) {
30388+ regs->ax = addr1;
30389+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
30390+ return 2;
30391+ }
30392+ } while (0);
30393+
30394+ do { /* PaX: gcc trampoline emulation #1 */
30395+ unsigned char mov1, mov2;
30396+ unsigned short jmp;
30397+ unsigned int addr1, addr2;
30398+
30399+#ifdef CONFIG_X86_64
30400+ if ((regs->ip + 11) >> 32)
30401+ break;
30402+#endif
30403+
30404+ err = get_user(mov1, (unsigned char __user *)regs->ip);
30405+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
30406+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
30407+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
30408+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
30409+
30410+ if (err)
30411+ break;
30412+
30413+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
30414+ regs->cx = addr1;
30415+ regs->ax = addr2;
30416+ regs->ip = addr2;
30417+ return 2;
30418+ }
30419+ } while (0);
30420+
30421+ do { /* PaX: gcc trampoline emulation #2 */
30422+ unsigned char mov, jmp;
30423+ unsigned int addr1, addr2;
30424+
30425+#ifdef CONFIG_X86_64
30426+ if ((regs->ip + 9) >> 32)
30427+ break;
30428+#endif
30429+
30430+ err = get_user(mov, (unsigned char __user *)regs->ip);
30431+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
30432+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
30433+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
30434+
30435+ if (err)
30436+ break;
30437+
30438+ if (mov == 0xB9 && jmp == 0xE9) {
30439+ regs->cx = addr1;
30440+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
30441+ return 2;
30442+ }
30443+ } while (0);
30444+
30445+ return 1; /* PaX in action */
30446+}
30447+
30448+#ifdef CONFIG_X86_64
30449+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
30450+{
30451+ int err;
30452+
30453+ do { /* PaX: libffi trampoline emulation */
30454+ unsigned short mov1, mov2, jmp1;
30455+ unsigned char stcclc, jmp2;
30456+ unsigned long addr1, addr2;
30457+
30458+ err = get_user(mov1, (unsigned short __user *)regs->ip);
30459+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
30460+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
30461+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
30462+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
30463+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
30464+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
30465+
30466+ if (err)
30467+ break;
30468+
30469+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
30470+ regs->r11 = addr1;
30471+ regs->r10 = addr2;
30472+ if (stcclc == 0xF8)
30473+ regs->flags &= ~X86_EFLAGS_CF;
30474+ else
30475+ regs->flags |= X86_EFLAGS_CF;
30476+ regs->ip = addr1;
30477+ return 2;
30478+ }
30479+ } while (0);
30480+
30481+ do { /* PaX: gcc trampoline emulation #1 */
30482+ unsigned short mov1, mov2, jmp1;
30483+ unsigned char jmp2;
30484+ unsigned int addr1;
30485+ unsigned long addr2;
30486+
30487+ err = get_user(mov1, (unsigned short __user *)regs->ip);
30488+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
30489+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
30490+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
30491+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
30492+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
30493+
30494+ if (err)
30495+ break;
30496+
30497+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
30498+ regs->r11 = addr1;
30499+ regs->r10 = addr2;
30500+ regs->ip = addr1;
30501+ return 2;
30502+ }
30503+ } while (0);
30504+
30505+ do { /* PaX: gcc trampoline emulation #2 */
30506+ unsigned short mov1, mov2, jmp1;
30507+ unsigned char jmp2;
30508+ unsigned long addr1, addr2;
30509+
30510+ err = get_user(mov1, (unsigned short __user *)regs->ip);
30511+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
30512+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
30513+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
30514+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
30515+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
30516+
30517+ if (err)
30518+ break;
30519+
30520+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
30521+ regs->r11 = addr1;
30522+ regs->r10 = addr2;
30523+ regs->ip = addr1;
30524+ return 2;
30525+ }
30526+ } while (0);
30527+
30528+ return 1; /* PaX in action */
30529+}
30530+#endif
30531+
30532+/*
30533+ * PaX: decide what to do with offenders (regs->ip = fault address)
30534+ *
30535+ * returns 1 when task should be killed
30536+ * 2 when gcc trampoline was detected
30537+ */
30538+static int pax_handle_fetch_fault(struct pt_regs *regs)
30539+{
30540+ if (v8086_mode(regs))
30541+ return 1;
30542+
30543+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
30544+ return 1;
30545+
30546+#ifdef CONFIG_X86_32
30547+ return pax_handle_fetch_fault_32(regs);
30548+#else
30549+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
30550+ return pax_handle_fetch_fault_32(regs);
30551+ else
30552+ return pax_handle_fetch_fault_64(regs);
30553+#endif
30554+}
30555+#endif
30556+
30557+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30558+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
30559+{
30560+ long i;
30561+
30562+ printk(KERN_ERR "PAX: bytes at PC: ");
30563+ for (i = 0; i < 20; i++) {
30564+ unsigned char c;
30565+ if (get_user(c, (unsigned char __force_user *)pc+i))
30566+ printk(KERN_CONT "?? ");
30567+ else
30568+ printk(KERN_CONT "%02x ", c);
30569+ }
30570+ printk("\n");
30571+
30572+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
30573+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
30574+ unsigned long c;
30575+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
30576+#ifdef CONFIG_X86_32
30577+ printk(KERN_CONT "???????? ");
30578+#else
30579+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
30580+ printk(KERN_CONT "???????? ???????? ");
30581+ else
30582+ printk(KERN_CONT "???????????????? ");
30583+#endif
30584+ } else {
30585+#ifdef CONFIG_X86_64
30586+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
30587+ printk(KERN_CONT "%08x ", (unsigned int)c);
30588+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
30589+ } else
30590+#endif
30591+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
30592+ }
30593+ }
30594+ printk("\n");
30595+}
30596+#endif
30597+
30598+/**
30599+ * probe_kernel_write(): safely attempt to write to a location
30600+ * @dst: address to write to
30601+ * @src: pointer to the data that shall be written
30602+ * @size: size of the data chunk
30603+ *
30604+ * Safely write to address @dst from the buffer at @src. If a kernel fault
30605+ * happens, handle that and return -EFAULT.
30606+ */
30607+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
30608+{
30609+ long ret;
30610+ mm_segment_t old_fs = get_fs();
30611+
30612+ set_fs(KERNEL_DS);
30613+ pagefault_disable();
30614+ pax_open_kernel();
30615+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
30616+ pax_close_kernel();
30617+ pagefault_enable();
30618+ set_fs(old_fs);
30619+
30620+ return ret ? -EFAULT : 0;
30621+}
30622diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
30623index dd74e46..7d26398 100644
30624--- a/arch/x86/mm/gup.c
30625+++ b/arch/x86/mm/gup.c
30626@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
30627 addr = start;
30628 len = (unsigned long) nr_pages << PAGE_SHIFT;
30629 end = start + len;
30630- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
30631+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
30632 (void __user *)start, len)))
30633 return 0;
30634
30635diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
30636index 4500142..53a363c 100644
30637--- a/arch/x86/mm/highmem_32.c
30638+++ b/arch/x86/mm/highmem_32.c
30639@@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
30640 idx = type + KM_TYPE_NR*smp_processor_id();
30641 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
30642 BUG_ON(!pte_none(*(kmap_pte-idx)));
30643+
30644+ pax_open_kernel();
30645 set_pte(kmap_pte-idx, mk_pte(page, prot));
30646+ pax_close_kernel();
30647+
30648 arch_flush_lazy_mmu_mode();
30649
30650 return (void *)vaddr;
30651diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
30652index 7e73e8c..11d3b86 100644
30653--- a/arch/x86/mm/hugetlbpage.c
30654+++ b/arch/x86/mm/hugetlbpage.c
30655@@ -84,23 +84,30 @@ int pud_huge(pud_t pud)
30656 #ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
30657 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
30658 unsigned long addr, unsigned long len,
30659- unsigned long pgoff, unsigned long flags)
30660+ unsigned long pgoff, unsigned long flags, unsigned long offset)
30661 {
30662 struct hstate *h = hstate_file(file);
30663 struct vm_unmapped_area_info info;
30664-
30665+
30666 info.flags = 0;
30667 info.length = len;
30668 info.low_limit = TASK_UNMAPPED_BASE;
30669+
30670+#ifdef CONFIG_PAX_RANDMMAP
30671+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
30672+ info.low_limit += current->mm->delta_mmap;
30673+#endif
30674+
30675 info.high_limit = TASK_SIZE;
30676 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
30677 info.align_offset = 0;
30678+ info.threadstack_offset = offset;
30679 return vm_unmapped_area(&info);
30680 }
30681
30682 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
30683 unsigned long addr0, unsigned long len,
30684- unsigned long pgoff, unsigned long flags)
30685+ unsigned long pgoff, unsigned long flags, unsigned long offset)
30686 {
30687 struct hstate *h = hstate_file(file);
30688 struct vm_unmapped_area_info info;
30689@@ -112,6 +119,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
30690 info.high_limit = current->mm->mmap_base;
30691 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
30692 info.align_offset = 0;
30693+ info.threadstack_offset = offset;
30694 addr = vm_unmapped_area(&info);
30695
30696 /*
30697@@ -124,6 +132,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
30698 VM_BUG_ON(addr != -ENOMEM);
30699 info.flags = 0;
30700 info.low_limit = TASK_UNMAPPED_BASE;
30701+
30702+#ifdef CONFIG_PAX_RANDMMAP
30703+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
30704+ info.low_limit += current->mm->delta_mmap;
30705+#endif
30706+
30707 info.high_limit = TASK_SIZE;
30708 addr = vm_unmapped_area(&info);
30709 }
30710@@ -138,10 +152,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
30711 struct hstate *h = hstate_file(file);
30712 struct mm_struct *mm = current->mm;
30713 struct vm_area_struct *vma;
30714+ unsigned long pax_task_size = TASK_SIZE;
30715+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
30716
30717 if (len & ~huge_page_mask(h))
30718 return -EINVAL;
30719- if (len > TASK_SIZE)
30720+
30721+#ifdef CONFIG_PAX_SEGMEXEC
30722+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
30723+ pax_task_size = SEGMEXEC_TASK_SIZE;
30724+#endif
30725+
30726+ pax_task_size -= PAGE_SIZE;
30727+
30728+ if (len > pax_task_size)
30729 return -ENOMEM;
30730
30731 if (flags & MAP_FIXED) {
30732@@ -150,19 +174,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
30733 return addr;
30734 }
30735
30736+#ifdef CONFIG_PAX_RANDMMAP
30737+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
30738+#endif
30739+
30740 if (addr) {
30741 addr = ALIGN(addr, huge_page_size(h));
30742 vma = find_vma(mm, addr);
30743- if (TASK_SIZE - len >= addr &&
30744- (!vma || addr + len <= vma->vm_start))
30745+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
30746 return addr;
30747 }
30748 if (mm->get_unmapped_area == arch_get_unmapped_area)
30749 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
30750- pgoff, flags);
30751+ pgoff, flags, offset);
30752 else
30753 return hugetlb_get_unmapped_area_topdown(file, addr, len,
30754- pgoff, flags);
30755+ pgoff, flags, offset);
30756 }
30757
30758 #endif /*HAVE_ARCH_HUGETLB_UNMAPPED_AREA*/
30759diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
30760index 04664cd..dae6e5d 100644
30761--- a/arch/x86/mm/init.c
30762+++ b/arch/x86/mm/init.c
30763@@ -4,6 +4,7 @@
30764 #include <linux/swap.h>
30765 #include <linux/memblock.h>
30766 #include <linux/bootmem.h> /* for max_low_pfn */
30767+#include <linux/tboot.h>
30768
30769 #include <asm/cacheflush.h>
30770 #include <asm/e820.h>
30771@@ -17,6 +18,8 @@
30772 #include <asm/proto.h>
30773 #include <asm/dma.h> /* for MAX_DMA_PFN */
30774 #include <asm/microcode.h>
30775+#include <asm/desc.h>
30776+#include <asm/bios_ebda.h>
30777
30778 #include "mm_internal.h"
30779
30780@@ -465,7 +468,18 @@ void __init init_mem_mapping(void)
30781 early_ioremap_page_table_range_init();
30782 #endif
30783
30784+#ifdef CONFIG_PAX_PER_CPU_PGD
30785+ clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
30786+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
30787+ KERNEL_PGD_PTRS);
30788+ clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
30789+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
30790+ KERNEL_PGD_PTRS);
30791+ load_cr3(get_cpu_pgd(0, kernel));
30792+#else
30793 load_cr3(swapper_pg_dir);
30794+#endif
30795+
30796 __flush_tlb_all();
30797
30798 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
30799@@ -481,10 +495,40 @@ void __init init_mem_mapping(void)
30800 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
30801 * mmio resources as well as potential bios/acpi data regions.
30802 */
30803+
30804+#ifdef CONFIG_GRKERNSEC_KMEM
30805+static unsigned int ebda_start __read_only;
30806+static unsigned int ebda_end __read_only;
30807+#endif
30808+
30809 int devmem_is_allowed(unsigned long pagenr)
30810 {
30811- if (pagenr < 256)
30812+#ifdef CONFIG_GRKERNSEC_KMEM
30813+ /* allow BDA */
30814+ if (!pagenr)
30815 return 1;
30816+ /* allow EBDA */
30817+ if (pagenr >= ebda_start && pagenr < ebda_end)
30818+ return 1;
30819+ /* if tboot is in use, allow access to its hardcoded serial log range */
30820+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
30821+ return 1;
30822+#else
30823+ if (!pagenr)
30824+ return 1;
30825+#ifdef CONFIG_VM86
30826+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
30827+ return 1;
30828+#endif
30829+#endif
30830+
30831+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
30832+ return 1;
30833+#ifdef CONFIG_GRKERNSEC_KMEM
30834+ /* throw out everything else below 1MB */
30835+ if (pagenr <= 256)
30836+ return 0;
30837+#endif
30838 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
30839 return 0;
30840 if (!page_is_ram(pagenr))
30841@@ -530,8 +574,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
30842 #endif
30843 }
30844
30845+#ifdef CONFIG_GRKERNSEC_KMEM
30846+static inline void gr_init_ebda(void)
30847+{
30848+ unsigned int ebda_addr;
30849+ unsigned int ebda_size = 0;
30850+
30851+ ebda_addr = get_bios_ebda();
30852+ if (ebda_addr) {
30853+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
30854+ ebda_size <<= 10;
30855+ }
30856+ if (ebda_addr && ebda_size) {
30857+ ebda_start = ebda_addr >> PAGE_SHIFT;
30858+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
30859+ } else {
30860+ ebda_start = 0x9f000 >> PAGE_SHIFT;
30861+ ebda_end = 0xa0000 >> PAGE_SHIFT;
30862+ }
30863+}
30864+#else
30865+static inline void gr_init_ebda(void) { }
30866+#endif
30867+
30868 void free_initmem(void)
30869 {
30870+#ifdef CONFIG_PAX_KERNEXEC
30871+#ifdef CONFIG_X86_32
30872+ /* PaX: limit KERNEL_CS to actual size */
30873+ unsigned long addr, limit;
30874+ struct desc_struct d;
30875+ int cpu;
30876+#else
30877+ pgd_t *pgd;
30878+ pud_t *pud;
30879+ pmd_t *pmd;
30880+ unsigned long addr, end;
30881+#endif
30882+#endif
30883+
30884+ gr_init_ebda();
30885+
30886+#ifdef CONFIG_PAX_KERNEXEC
30887+#ifdef CONFIG_X86_32
30888+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
30889+ limit = (limit - 1UL) >> PAGE_SHIFT;
30890+
30891+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
30892+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
30893+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
30894+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
30895+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
30896+ }
30897+
30898+ /* PaX: make KERNEL_CS read-only */
30899+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
30900+ if (!paravirt_enabled())
30901+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
30902+/*
30903+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
30904+ pgd = pgd_offset_k(addr);
30905+ pud = pud_offset(pgd, addr);
30906+ pmd = pmd_offset(pud, addr);
30907+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
30908+ }
30909+*/
30910+#ifdef CONFIG_X86_PAE
30911+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
30912+/*
30913+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
30914+ pgd = pgd_offset_k(addr);
30915+ pud = pud_offset(pgd, addr);
30916+ pmd = pmd_offset(pud, addr);
30917+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
30918+ }
30919+*/
30920+#endif
30921+
30922+#ifdef CONFIG_MODULES
30923+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
30924+#endif
30925+
30926+#else
30927+ /* PaX: make kernel code/rodata read-only, rest non-executable */
30928+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
30929+ pgd = pgd_offset_k(addr);
30930+ pud = pud_offset(pgd, addr);
30931+ pmd = pmd_offset(pud, addr);
30932+ if (!pmd_present(*pmd))
30933+ continue;
30934+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
30935+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
30936+ else
30937+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
30938+ }
30939+
30940+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
30941+ end = addr + KERNEL_IMAGE_SIZE;
30942+ for (; addr < end; addr += PMD_SIZE) {
30943+ pgd = pgd_offset_k(addr);
30944+ pud = pud_offset(pgd, addr);
30945+ pmd = pmd_offset(pud, addr);
30946+ if (!pmd_present(*pmd))
30947+ continue;
30948+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
30949+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
30950+ }
30951+#endif
30952+
30953+ flush_tlb_all();
30954+#endif
30955+
30956 free_init_pages("unused kernel",
30957 (unsigned long)(&__init_begin),
30958 (unsigned long)(&__init_end));
30959diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
30960index 4287f1f..3b99c71 100644
30961--- a/arch/x86/mm/init_32.c
30962+++ b/arch/x86/mm/init_32.c
30963@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
30964 bool __read_mostly __vmalloc_start_set = false;
30965
30966 /*
30967- * Creates a middle page table and puts a pointer to it in the
30968- * given global directory entry. This only returns the gd entry
30969- * in non-PAE compilation mode, since the middle layer is folded.
30970- */
30971-static pmd_t * __init one_md_table_init(pgd_t *pgd)
30972-{
30973- pud_t *pud;
30974- pmd_t *pmd_table;
30975-
30976-#ifdef CONFIG_X86_PAE
30977- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
30978- pmd_table = (pmd_t *)alloc_low_page();
30979- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
30980- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
30981- pud = pud_offset(pgd, 0);
30982- BUG_ON(pmd_table != pmd_offset(pud, 0));
30983-
30984- return pmd_table;
30985- }
30986-#endif
30987- pud = pud_offset(pgd, 0);
30988- pmd_table = pmd_offset(pud, 0);
30989-
30990- return pmd_table;
30991-}
30992-
30993-/*
30994 * Create a page table and place a pointer to it in a middle page
30995 * directory entry:
30996 */
30997@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
30998 pte_t *page_table = (pte_t *)alloc_low_page();
30999
31000 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
31001+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31002+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
31003+#else
31004 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
31005+#endif
31006 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
31007 }
31008
31009 return pte_offset_kernel(pmd, 0);
31010 }
31011
31012+static pmd_t * __init one_md_table_init(pgd_t *pgd)
31013+{
31014+ pud_t *pud;
31015+ pmd_t *pmd_table;
31016+
31017+ pud = pud_offset(pgd, 0);
31018+ pmd_table = pmd_offset(pud, 0);
31019+
31020+ return pmd_table;
31021+}
31022+
31023 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
31024 {
31025 int pgd_idx = pgd_index(vaddr);
31026@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31027 int pgd_idx, pmd_idx;
31028 unsigned long vaddr;
31029 pgd_t *pgd;
31030+ pud_t *pud;
31031 pmd_t *pmd;
31032 pte_t *pte = NULL;
31033 unsigned long count = page_table_range_init_count(start, end);
31034@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31035 pgd = pgd_base + pgd_idx;
31036
31037 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
31038- pmd = one_md_table_init(pgd);
31039- pmd = pmd + pmd_index(vaddr);
31040+ pud = pud_offset(pgd, vaddr);
31041+ pmd = pmd_offset(pud, vaddr);
31042+
31043+#ifdef CONFIG_X86_PAE
31044+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
31045+#endif
31046+
31047 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
31048 pmd++, pmd_idx++) {
31049 pte = page_table_kmap_check(one_page_table_init(pmd),
31050@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31051 }
31052 }
31053
31054-static inline int is_kernel_text(unsigned long addr)
31055+static inline int is_kernel_text(unsigned long start, unsigned long end)
31056 {
31057- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
31058- return 1;
31059- return 0;
31060+ if ((start > ktla_ktva((unsigned long)_etext) ||
31061+ end <= ktla_ktva((unsigned long)_stext)) &&
31062+ (start > ktla_ktva((unsigned long)_einittext) ||
31063+ end <= ktla_ktva((unsigned long)_sinittext)) &&
31064+
31065+#ifdef CONFIG_ACPI_SLEEP
31066+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
31067+#endif
31068+
31069+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
31070+ return 0;
31071+ return 1;
31072 }
31073
31074 /*
31075@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
31076 unsigned long last_map_addr = end;
31077 unsigned long start_pfn, end_pfn;
31078 pgd_t *pgd_base = swapper_pg_dir;
31079- int pgd_idx, pmd_idx, pte_ofs;
31080+ unsigned int pgd_idx, pmd_idx, pte_ofs;
31081 unsigned long pfn;
31082 pgd_t *pgd;
31083+ pud_t *pud;
31084 pmd_t *pmd;
31085 pte_t *pte;
31086 unsigned pages_2m, pages_4k;
31087@@ -291,8 +295,13 @@ repeat:
31088 pfn = start_pfn;
31089 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
31090 pgd = pgd_base + pgd_idx;
31091- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
31092- pmd = one_md_table_init(pgd);
31093+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
31094+ pud = pud_offset(pgd, 0);
31095+ pmd = pmd_offset(pud, 0);
31096+
31097+#ifdef CONFIG_X86_PAE
31098+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
31099+#endif
31100
31101 if (pfn >= end_pfn)
31102 continue;
31103@@ -304,14 +313,13 @@ repeat:
31104 #endif
31105 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
31106 pmd++, pmd_idx++) {
31107- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
31108+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
31109
31110 /*
31111 * Map with big pages if possible, otherwise
31112 * create normal page tables:
31113 */
31114 if (use_pse) {
31115- unsigned int addr2;
31116 pgprot_t prot = PAGE_KERNEL_LARGE;
31117 /*
31118 * first pass will use the same initial
31119@@ -322,11 +330,7 @@ repeat:
31120 _PAGE_PSE);
31121
31122 pfn &= PMD_MASK >> PAGE_SHIFT;
31123- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
31124- PAGE_OFFSET + PAGE_SIZE-1;
31125-
31126- if (is_kernel_text(addr) ||
31127- is_kernel_text(addr2))
31128+ if (is_kernel_text(address, address + PMD_SIZE))
31129 prot = PAGE_KERNEL_LARGE_EXEC;
31130
31131 pages_2m++;
31132@@ -343,7 +347,7 @@ repeat:
31133 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
31134 pte += pte_ofs;
31135 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
31136- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
31137+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
31138 pgprot_t prot = PAGE_KERNEL;
31139 /*
31140 * first pass will use the same initial
31141@@ -351,7 +355,7 @@ repeat:
31142 */
31143 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
31144
31145- if (is_kernel_text(addr))
31146+ if (is_kernel_text(address, address + PAGE_SIZE))
31147 prot = PAGE_KERNEL_EXEC;
31148
31149 pages_4k++;
31150@@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
31151
31152 pud = pud_offset(pgd, va);
31153 pmd = pmd_offset(pud, va);
31154- if (!pmd_present(*pmd))
31155+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
31156 break;
31157
31158 /* should not be large page here */
31159@@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
31160
31161 static void __init pagetable_init(void)
31162 {
31163- pgd_t *pgd_base = swapper_pg_dir;
31164-
31165- permanent_kmaps_init(pgd_base);
31166+ permanent_kmaps_init(swapper_pg_dir);
31167 }
31168
31169-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
31170+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
31171 EXPORT_SYMBOL_GPL(__supported_pte_mask);
31172
31173 /* user-defined highmem size */
31174@@ -787,10 +789,10 @@ void __init mem_init(void)
31175 ((unsigned long)&__init_end -
31176 (unsigned long)&__init_begin) >> 10,
31177
31178- (unsigned long)&_etext, (unsigned long)&_edata,
31179- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
31180+ (unsigned long)&_sdata, (unsigned long)&_edata,
31181+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
31182
31183- (unsigned long)&_text, (unsigned long)&_etext,
31184+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
31185 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
31186
31187 /*
31188@@ -880,6 +882,7 @@ void set_kernel_text_rw(void)
31189 if (!kernel_set_to_readonly)
31190 return;
31191
31192+ start = ktla_ktva(start);
31193 pr_debug("Set kernel text: %lx - %lx for read write\n",
31194 start, start+size);
31195
31196@@ -894,6 +897,7 @@ void set_kernel_text_ro(void)
31197 if (!kernel_set_to_readonly)
31198 return;
31199
31200+ start = ktla_ktva(start);
31201 pr_debug("Set kernel text: %lx - %lx for read only\n",
31202 start, start+size);
31203
31204@@ -922,6 +926,7 @@ void mark_rodata_ro(void)
31205 unsigned long start = PFN_ALIGN(_text);
31206 unsigned long size = PFN_ALIGN(_etext) - start;
31207
31208+ start = ktla_ktva(start);
31209 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
31210 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
31211 size >> 10);
31212diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
31213index 104d56a..62ba13f1 100644
31214--- a/arch/x86/mm/init_64.c
31215+++ b/arch/x86/mm/init_64.c
31216@@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
31217 * around without checking the pgd every time.
31218 */
31219
31220-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
31221+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
31222 EXPORT_SYMBOL_GPL(__supported_pte_mask);
31223
31224 int force_personality32;
31225@@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
31226
31227 for (address = start; address <= end; address += PGDIR_SIZE) {
31228 const pgd_t *pgd_ref = pgd_offset_k(address);
31229+
31230+#ifdef CONFIG_PAX_PER_CPU_PGD
31231+ unsigned long cpu;
31232+#else
31233 struct page *page;
31234+#endif
31235
31236 if (pgd_none(*pgd_ref))
31237 continue;
31238
31239 spin_lock(&pgd_lock);
31240+
31241+#ifdef CONFIG_PAX_PER_CPU_PGD
31242+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31243+ pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
31244+
31245+ if (pgd_none(*pgd))
31246+ set_pgd(pgd, *pgd_ref);
31247+ else
31248+ BUG_ON(pgd_page_vaddr(*pgd)
31249+ != pgd_page_vaddr(*pgd_ref));
31250+ pgd = pgd_offset_cpu(cpu, kernel, address);
31251+#else
31252 list_for_each_entry(page, &pgd_list, lru) {
31253 pgd_t *pgd;
31254 spinlock_t *pgt_lock;
31255@@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
31256 /* the pgt_lock only for Xen */
31257 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31258 spin_lock(pgt_lock);
31259+#endif
31260
31261 if (pgd_none(*pgd))
31262 set_pgd(pgd, *pgd_ref);
31263@@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
31264 BUG_ON(pgd_page_vaddr(*pgd)
31265 != pgd_page_vaddr(*pgd_ref));
31266
31267+#ifndef CONFIG_PAX_PER_CPU_PGD
31268 spin_unlock(pgt_lock);
31269+#endif
31270+
31271 }
31272 spin_unlock(&pgd_lock);
31273 }
31274@@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
31275 {
31276 if (pgd_none(*pgd)) {
31277 pud_t *pud = (pud_t *)spp_getpage();
31278- pgd_populate(&init_mm, pgd, pud);
31279+ pgd_populate_kernel(&init_mm, pgd, pud);
31280 if (pud != pud_offset(pgd, 0))
31281 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
31282 pud, pud_offset(pgd, 0));
31283@@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
31284 {
31285 if (pud_none(*pud)) {
31286 pmd_t *pmd = (pmd_t *) spp_getpage();
31287- pud_populate(&init_mm, pud, pmd);
31288+ pud_populate_kernel(&init_mm, pud, pmd);
31289 if (pmd != pmd_offset(pud, 0))
31290 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
31291 pmd, pmd_offset(pud, 0));
31292@@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
31293 pmd = fill_pmd(pud, vaddr);
31294 pte = fill_pte(pmd, vaddr);
31295
31296+ pax_open_kernel();
31297 set_pte(pte, new_pte);
31298+ pax_close_kernel();
31299
31300 /*
31301 * It's enough to flush this one mapping.
31302@@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
31303 pgd = pgd_offset_k((unsigned long)__va(phys));
31304 if (pgd_none(*pgd)) {
31305 pud = (pud_t *) spp_getpage();
31306- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
31307- _PAGE_USER));
31308+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
31309 }
31310 pud = pud_offset(pgd, (unsigned long)__va(phys));
31311 if (pud_none(*pud)) {
31312 pmd = (pmd_t *) spp_getpage();
31313- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
31314- _PAGE_USER));
31315+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
31316 }
31317 pmd = pmd_offset(pud, phys);
31318 BUG_ON(!pmd_none(*pmd));
31319@@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
31320 prot);
31321
31322 spin_lock(&init_mm.page_table_lock);
31323- pud_populate(&init_mm, pud, pmd);
31324+ pud_populate_kernel(&init_mm, pud, pmd);
31325 spin_unlock(&init_mm.page_table_lock);
31326 }
31327 __flush_tlb_all();
31328@@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
31329 page_size_mask);
31330
31331 spin_lock(&init_mm.page_table_lock);
31332- pgd_populate(&init_mm, pgd, pud);
31333+ pgd_populate_kernel(&init_mm, pgd, pud);
31334 spin_unlock(&init_mm.page_table_lock);
31335 pgd_changed = true;
31336 }
31337@@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
31338 static struct vm_area_struct gate_vma = {
31339 .vm_start = VSYSCALL_START,
31340 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
31341- .vm_page_prot = PAGE_READONLY_EXEC,
31342- .vm_flags = VM_READ | VM_EXEC
31343+ .vm_page_prot = PAGE_READONLY,
31344+ .vm_flags = VM_READ
31345 };
31346
31347 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
31348@@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
31349
31350 const char *arch_vma_name(struct vm_area_struct *vma)
31351 {
31352- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
31353+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
31354 return "[vdso]";
31355 if (vma == &gate_vma)
31356 return "[vsyscall]";
31357diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
31358index 7b179b4..6bd17777 100644
31359--- a/arch/x86/mm/iomap_32.c
31360+++ b/arch/x86/mm/iomap_32.c
31361@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
31362 type = kmap_atomic_idx_push();
31363 idx = type + KM_TYPE_NR * smp_processor_id();
31364 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
31365+
31366+ pax_open_kernel();
31367 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
31368+ pax_close_kernel();
31369+
31370 arch_flush_lazy_mmu_mode();
31371
31372 return (void *)vaddr;
31373diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
31374index 0215e2c..1c62dab 100644
31375--- a/arch/x86/mm/ioremap.c
31376+++ b/arch/x86/mm/ioremap.c
31377@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
31378 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
31379 int is_ram = page_is_ram(pfn);
31380
31381- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
31382+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
31383 return NULL;
31384 WARN_ON_ONCE(is_ram);
31385 }
31386@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
31387 *
31388 * Caller must ensure there is only one unmapping for the same pointer.
31389 */
31390-void iounmap(volatile void __iomem *addr)
31391+void iounmap(const volatile void __iomem *addr)
31392 {
31393 struct vm_struct *p, *o;
31394
31395@@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
31396
31397 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
31398 if (page_is_ram(start >> PAGE_SHIFT))
31399+#ifdef CONFIG_HIGHMEM
31400+ if ((start >> PAGE_SHIFT) < max_low_pfn)
31401+#endif
31402 return __va(phys);
31403
31404 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
31405@@ -322,6 +325,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
31406 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
31407 {
31408 if (page_is_ram(phys >> PAGE_SHIFT))
31409+#ifdef CONFIG_HIGHMEM
31410+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
31411+#endif
31412 return;
31413
31414 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
31415@@ -339,7 +345,7 @@ static int __init early_ioremap_debug_setup(char *str)
31416 early_param("early_ioremap_debug", early_ioremap_debug_setup);
31417
31418 static __initdata int after_paging_init;
31419-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
31420+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
31421
31422 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
31423 {
31424@@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
31425 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
31426
31427 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
31428- memset(bm_pte, 0, sizeof(bm_pte));
31429- pmd_populate_kernel(&init_mm, pmd, bm_pte);
31430+ pmd_populate_user(&init_mm, pmd, bm_pte);
31431
31432 /*
31433 * The boot-ioremap range spans multiple pmds, for which
31434diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
31435index d87dd6d..bf3fa66 100644
31436--- a/arch/x86/mm/kmemcheck/kmemcheck.c
31437+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
31438@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
31439 * memory (e.g. tracked pages)? For now, we need this to avoid
31440 * invoking kmemcheck for PnP BIOS calls.
31441 */
31442- if (regs->flags & X86_VM_MASK)
31443+ if (v8086_mode(regs))
31444 return false;
31445- if (regs->cs != __KERNEL_CS)
31446+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
31447 return false;
31448
31449 pte = kmemcheck_pte_lookup(address);
31450diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
31451index 25e7e13..1964579 100644
31452--- a/arch/x86/mm/mmap.c
31453+++ b/arch/x86/mm/mmap.c
31454@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
31455 * Leave an at least ~128 MB hole with possible stack randomization.
31456 */
31457 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
31458-#define MAX_GAP (TASK_SIZE/6*5)
31459+#define MAX_GAP (pax_task_size/6*5)
31460
31461 static int mmap_is_legacy(void)
31462 {
31463@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
31464 return rnd << PAGE_SHIFT;
31465 }
31466
31467-static unsigned long mmap_base(void)
31468+static unsigned long mmap_base(struct mm_struct *mm)
31469 {
31470 unsigned long gap = rlimit(RLIMIT_STACK);
31471+ unsigned long pax_task_size = TASK_SIZE;
31472+
31473+#ifdef CONFIG_PAX_SEGMEXEC
31474+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
31475+ pax_task_size = SEGMEXEC_TASK_SIZE;
31476+#endif
31477
31478 if (gap < MIN_GAP)
31479 gap = MIN_GAP;
31480 else if (gap > MAX_GAP)
31481 gap = MAX_GAP;
31482
31483- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
31484+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
31485 }
31486
31487 /*
31488 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
31489 * does, but not when emulating X86_32
31490 */
31491-static unsigned long mmap_legacy_base(void)
31492+static unsigned long mmap_legacy_base(struct mm_struct *mm)
31493 {
31494- if (mmap_is_ia32())
31495+ if (mmap_is_ia32()) {
31496+
31497+#ifdef CONFIG_PAX_SEGMEXEC
31498+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
31499+ return SEGMEXEC_TASK_UNMAPPED_BASE;
31500+ else
31501+#endif
31502+
31503 return TASK_UNMAPPED_BASE;
31504- else
31505+ } else
31506 return TASK_UNMAPPED_BASE + mmap_rnd();
31507 }
31508
31509@@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
31510 */
31511 void arch_pick_mmap_layout(struct mm_struct *mm)
31512 {
31513- mm->mmap_legacy_base = mmap_legacy_base();
31514- mm->mmap_base = mmap_base();
31515+ mm->mmap_legacy_base = mmap_legacy_base(mm);
31516+ mm->mmap_base = mmap_base(mm);
31517+
31518+#ifdef CONFIG_PAX_RANDMMAP
31519+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
31520+ mm->mmap_legacy_base += mm->delta_mmap;
31521+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
31522+ }
31523+#endif
31524
31525 if (mmap_is_legacy()) {
31526 mm->mmap_base = mm->mmap_legacy_base;
31527diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
31528index 0057a7a..95c7edd 100644
31529--- a/arch/x86/mm/mmio-mod.c
31530+++ b/arch/x86/mm/mmio-mod.c
31531@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
31532 break;
31533 default:
31534 {
31535- unsigned char *ip = (unsigned char *)instptr;
31536+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
31537 my_trace->opcode = MMIO_UNKNOWN_OP;
31538 my_trace->width = 0;
31539 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
31540@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
31541 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
31542 void __iomem *addr)
31543 {
31544- static atomic_t next_id;
31545+ static atomic_unchecked_t next_id;
31546 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
31547 /* These are page-unaligned. */
31548 struct mmiotrace_map map = {
31549@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
31550 .private = trace
31551 },
31552 .phys = offset,
31553- .id = atomic_inc_return(&next_id)
31554+ .id = atomic_inc_return_unchecked(&next_id)
31555 };
31556 map.map_id = trace->id;
31557
31558@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
31559 ioremap_trace_core(offset, size, addr);
31560 }
31561
31562-static void iounmap_trace_core(volatile void __iomem *addr)
31563+static void iounmap_trace_core(const volatile void __iomem *addr)
31564 {
31565 struct mmiotrace_map map = {
31566 .phys = 0,
31567@@ -328,7 +328,7 @@ not_enabled:
31568 }
31569 }
31570
31571-void mmiotrace_iounmap(volatile void __iomem *addr)
31572+void mmiotrace_iounmap(const volatile void __iomem *addr)
31573 {
31574 might_sleep();
31575 if (is_enabled()) /* recheck and proper locking in *_core() */
31576diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
31577index 8bf93ba..dbcd670 100644
31578--- a/arch/x86/mm/numa.c
31579+++ b/arch/x86/mm/numa.c
31580@@ -474,7 +474,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
31581 return true;
31582 }
31583
31584-static int __init numa_register_memblks(struct numa_meminfo *mi)
31585+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
31586 {
31587 unsigned long uninitialized_var(pfn_align);
31588 int i, nid;
31589diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
31590index d0b1773..4c3327c 100644
31591--- a/arch/x86/mm/pageattr-test.c
31592+++ b/arch/x86/mm/pageattr-test.c
31593@@ -36,7 +36,7 @@ enum {
31594
31595 static int pte_testbit(pte_t pte)
31596 {
31597- return pte_flags(pte) & _PAGE_UNUSED1;
31598+ return pte_flags(pte) & _PAGE_CPA_TEST;
31599 }
31600
31601 struct split_state {
31602diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
31603index bb32480..75f2f5e 100644
31604--- a/arch/x86/mm/pageattr.c
31605+++ b/arch/x86/mm/pageattr.c
31606@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31607 */
31608 #ifdef CONFIG_PCI_BIOS
31609 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
31610- pgprot_val(forbidden) |= _PAGE_NX;
31611+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
31612 #endif
31613
31614 /*
31615@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31616 * Does not cover __inittext since that is gone later on. On
31617 * 64bit we do not enforce !NX on the low mapping
31618 */
31619- if (within(address, (unsigned long)_text, (unsigned long)_etext))
31620- pgprot_val(forbidden) |= _PAGE_NX;
31621+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
31622+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
31623
31624+#ifdef CONFIG_DEBUG_RODATA
31625 /*
31626 * The .rodata section needs to be read-only. Using the pfn
31627 * catches all aliases.
31628@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31629 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
31630 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
31631 pgprot_val(forbidden) |= _PAGE_RW;
31632+#endif
31633
31634 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
31635 /*
31636@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31637 }
31638 #endif
31639
31640+#ifdef CONFIG_PAX_KERNEXEC
31641+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
31642+ pgprot_val(forbidden) |= _PAGE_RW;
31643+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
31644+ }
31645+#endif
31646+
31647 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
31648
31649 return prot;
31650@@ -400,23 +409,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
31651 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
31652 {
31653 /* change init_mm */
31654+ pax_open_kernel();
31655 set_pte_atomic(kpte, pte);
31656+
31657 #ifdef CONFIG_X86_32
31658 if (!SHARED_KERNEL_PMD) {
31659+
31660+#ifdef CONFIG_PAX_PER_CPU_PGD
31661+ unsigned long cpu;
31662+#else
31663 struct page *page;
31664+#endif
31665
31666+#ifdef CONFIG_PAX_PER_CPU_PGD
31667+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31668+ pgd_t *pgd = get_cpu_pgd(cpu, kernel);
31669+#else
31670 list_for_each_entry(page, &pgd_list, lru) {
31671- pgd_t *pgd;
31672+ pgd_t *pgd = (pgd_t *)page_address(page);
31673+#endif
31674+
31675 pud_t *pud;
31676 pmd_t *pmd;
31677
31678- pgd = (pgd_t *)page_address(page) + pgd_index(address);
31679+ pgd += pgd_index(address);
31680 pud = pud_offset(pgd, address);
31681 pmd = pmd_offset(pud, address);
31682 set_pte_atomic((pte_t *)pmd, pte);
31683 }
31684 }
31685 #endif
31686+ pax_close_kernel();
31687 }
31688
31689 static int
31690diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
31691index 6574388..87e9bef 100644
31692--- a/arch/x86/mm/pat.c
31693+++ b/arch/x86/mm/pat.c
31694@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
31695
31696 if (!entry) {
31697 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
31698- current->comm, current->pid, start, end - 1);
31699+ current->comm, task_pid_nr(current), start, end - 1);
31700 return -EINVAL;
31701 }
31702
31703@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31704
31705 while (cursor < to) {
31706 if (!devmem_is_allowed(pfn)) {
31707- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
31708- current->comm, from, to - 1);
31709+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
31710+ current->comm, from, to - 1, cursor);
31711 return 0;
31712 }
31713 cursor += PAGE_SIZE;
31714@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
31715 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
31716 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
31717 "for [mem %#010Lx-%#010Lx]\n",
31718- current->comm, current->pid,
31719+ current->comm, task_pid_nr(current),
31720 cattr_name(flags),
31721 base, (unsigned long long)(base + size-1));
31722 return -EINVAL;
31723@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
31724 flags = lookup_memtype(paddr);
31725 if (want_flags != flags) {
31726 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
31727- current->comm, current->pid,
31728+ current->comm, task_pid_nr(current),
31729 cattr_name(want_flags),
31730 (unsigned long long)paddr,
31731 (unsigned long long)(paddr + size - 1),
31732@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
31733 free_memtype(paddr, paddr + size);
31734 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
31735 " for [mem %#010Lx-%#010Lx], got %s\n",
31736- current->comm, current->pid,
31737+ current->comm, task_pid_nr(current),
31738 cattr_name(want_flags),
31739 (unsigned long long)paddr,
31740 (unsigned long long)(paddr + size - 1),
31741diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
31742index 415f6c4..d319983 100644
31743--- a/arch/x86/mm/pat_rbtree.c
31744+++ b/arch/x86/mm/pat_rbtree.c
31745@@ -160,7 +160,7 @@ success:
31746
31747 failure:
31748 printk(KERN_INFO "%s:%d conflicting memory types "
31749- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
31750+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
31751 end, cattr_name(found_type), cattr_name(match->type));
31752 return -EBUSY;
31753 }
31754diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
31755index 9f0614d..92ae64a 100644
31756--- a/arch/x86/mm/pf_in.c
31757+++ b/arch/x86/mm/pf_in.c
31758@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
31759 int i;
31760 enum reason_type rv = OTHERS;
31761
31762- p = (unsigned char *)ins_addr;
31763+ p = (unsigned char *)ktla_ktva(ins_addr);
31764 p += skip_prefix(p, &prf);
31765 p += get_opcode(p, &opcode);
31766
31767@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
31768 struct prefix_bits prf;
31769 int i;
31770
31771- p = (unsigned char *)ins_addr;
31772+ p = (unsigned char *)ktla_ktva(ins_addr);
31773 p += skip_prefix(p, &prf);
31774 p += get_opcode(p, &opcode);
31775
31776@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
31777 struct prefix_bits prf;
31778 int i;
31779
31780- p = (unsigned char *)ins_addr;
31781+ p = (unsigned char *)ktla_ktva(ins_addr);
31782 p += skip_prefix(p, &prf);
31783 p += get_opcode(p, &opcode);
31784
31785@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
31786 struct prefix_bits prf;
31787 int i;
31788
31789- p = (unsigned char *)ins_addr;
31790+ p = (unsigned char *)ktla_ktva(ins_addr);
31791 p += skip_prefix(p, &prf);
31792 p += get_opcode(p, &opcode);
31793 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
31794@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
31795 struct prefix_bits prf;
31796 int i;
31797
31798- p = (unsigned char *)ins_addr;
31799+ p = (unsigned char *)ktla_ktva(ins_addr);
31800 p += skip_prefix(p, &prf);
31801 p += get_opcode(p, &opcode);
31802 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
31803diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
31804index dfa537a..fd45c64 100644
31805--- a/arch/x86/mm/pgtable.c
31806+++ b/arch/x86/mm/pgtable.c
31807@@ -91,10 +91,67 @@ static inline void pgd_list_del(pgd_t *pgd)
31808 list_del(&page->lru);
31809 }
31810
31811-#define UNSHARED_PTRS_PER_PGD \
31812- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
31813+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31814+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
31815
31816+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
31817+{
31818+ unsigned int count = USER_PGD_PTRS;
31819
31820+ if (!pax_user_shadow_base)
31821+ return;
31822+
31823+ while (count--)
31824+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
31825+}
31826+#endif
31827+
31828+#ifdef CONFIG_PAX_PER_CPU_PGD
31829+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
31830+{
31831+ unsigned int count = USER_PGD_PTRS;
31832+
31833+ while (count--) {
31834+ pgd_t pgd;
31835+
31836+#ifdef CONFIG_X86_64
31837+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
31838+#else
31839+ pgd = *src++;
31840+#endif
31841+
31842+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31843+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
31844+#endif
31845+
31846+ *dst++ = pgd;
31847+ }
31848+
31849+}
31850+#endif
31851+
31852+#ifdef CONFIG_X86_64
31853+#define pxd_t pud_t
31854+#define pyd_t pgd_t
31855+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
31856+#define pxd_free(mm, pud) pud_free((mm), (pud))
31857+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
31858+#define pyd_offset(mm, address) pgd_offset((mm), (address))
31859+#define PYD_SIZE PGDIR_SIZE
31860+#else
31861+#define pxd_t pmd_t
31862+#define pyd_t pud_t
31863+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
31864+#define pxd_free(mm, pud) pmd_free((mm), (pud))
31865+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
31866+#define pyd_offset(mm, address) pud_offset((mm), (address))
31867+#define PYD_SIZE PUD_SIZE
31868+#endif
31869+
31870+#ifdef CONFIG_PAX_PER_CPU_PGD
31871+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
31872+static inline void pgd_dtor(pgd_t *pgd) {}
31873+#else
31874 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
31875 {
31876 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
31877@@ -135,6 +192,7 @@ static void pgd_dtor(pgd_t *pgd)
31878 pgd_list_del(pgd);
31879 spin_unlock(&pgd_lock);
31880 }
31881+#endif
31882
31883 /*
31884 * List of all pgd's needed for non-PAE so it can invalidate entries
31885@@ -147,7 +205,7 @@ static void pgd_dtor(pgd_t *pgd)
31886 * -- nyc
31887 */
31888
31889-#ifdef CONFIG_X86_PAE
31890+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
31891 /*
31892 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
31893 * updating the top-level pagetable entries to guarantee the
31894@@ -159,7 +217,7 @@ static void pgd_dtor(pgd_t *pgd)
31895 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
31896 * and initialize the kernel pmds here.
31897 */
31898-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
31899+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
31900
31901 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
31902 {
31903@@ -177,36 +235,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
31904 */
31905 flush_tlb_mm(mm);
31906 }
31907+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
31908+#define PREALLOCATED_PXDS USER_PGD_PTRS
31909 #else /* !CONFIG_X86_PAE */
31910
31911 /* No need to prepopulate any pagetable entries in non-PAE modes. */
31912-#define PREALLOCATED_PMDS 0
31913+#define PREALLOCATED_PXDS 0
31914
31915 #endif /* CONFIG_X86_PAE */
31916
31917-static void free_pmds(pmd_t *pmds[])
31918+static void free_pxds(pxd_t *pxds[])
31919 {
31920 int i;
31921
31922- for(i = 0; i < PREALLOCATED_PMDS; i++)
31923- if (pmds[i])
31924- free_page((unsigned long)pmds[i]);
31925+ for(i = 0; i < PREALLOCATED_PXDS; i++)
31926+ if (pxds[i])
31927+ free_page((unsigned long)pxds[i]);
31928 }
31929
31930-static int preallocate_pmds(pmd_t *pmds[])
31931+static int preallocate_pxds(pxd_t *pxds[])
31932 {
31933 int i;
31934 bool failed = false;
31935
31936- for(i = 0; i < PREALLOCATED_PMDS; i++) {
31937- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
31938- if (pmd == NULL)
31939+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
31940+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
31941+ if (pxd == NULL)
31942 failed = true;
31943- pmds[i] = pmd;
31944+ pxds[i] = pxd;
31945 }
31946
31947 if (failed) {
31948- free_pmds(pmds);
31949+ free_pxds(pxds);
31950 return -ENOMEM;
31951 }
31952
31953@@ -219,49 +279,52 @@ static int preallocate_pmds(pmd_t *pmds[])
31954 * preallocate which never got a corresponding vma will need to be
31955 * freed manually.
31956 */
31957-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
31958+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
31959 {
31960 int i;
31961
31962- for(i = 0; i < PREALLOCATED_PMDS; i++) {
31963+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
31964 pgd_t pgd = pgdp[i];
31965
31966 if (pgd_val(pgd) != 0) {
31967- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
31968+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
31969
31970- pgdp[i] = native_make_pgd(0);
31971+ set_pgd(pgdp + i, native_make_pgd(0));
31972
31973- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
31974- pmd_free(mm, pmd);
31975+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
31976+ pxd_free(mm, pxd);
31977 }
31978 }
31979 }
31980
31981-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
31982+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
31983 {
31984- pud_t *pud;
31985+ pyd_t *pyd;
31986 int i;
31987
31988- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
31989+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
31990 return;
31991
31992- pud = pud_offset(pgd, 0);
31993-
31994- for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
31995- pmd_t *pmd = pmds[i];
31996+#ifdef CONFIG_X86_64
31997+ pyd = pyd_offset(mm, 0L);
31998+#else
31999+ pyd = pyd_offset(pgd, 0L);
32000+#endif
32001
32002+ for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
32003+ pxd_t *pxd = pxds[i];
32004 if (i >= KERNEL_PGD_BOUNDARY)
32005- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
32006- sizeof(pmd_t) * PTRS_PER_PMD);
32007+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
32008+ sizeof(pxd_t) * PTRS_PER_PMD);
32009
32010- pud_populate(mm, pud, pmd);
32011+ pyd_populate(mm, pyd, pxd);
32012 }
32013 }
32014
32015 pgd_t *pgd_alloc(struct mm_struct *mm)
32016 {
32017 pgd_t *pgd;
32018- pmd_t *pmds[PREALLOCATED_PMDS];
32019+ pxd_t *pxds[PREALLOCATED_PXDS];
32020
32021 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
32022
32023@@ -270,11 +333,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
32024
32025 mm->pgd = pgd;
32026
32027- if (preallocate_pmds(pmds) != 0)
32028+ if (preallocate_pxds(pxds) != 0)
32029 goto out_free_pgd;
32030
32031 if (paravirt_pgd_alloc(mm) != 0)
32032- goto out_free_pmds;
32033+ goto out_free_pxds;
32034
32035 /*
32036 * Make sure that pre-populating the pmds is atomic with
32037@@ -284,14 +347,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
32038 spin_lock(&pgd_lock);
32039
32040 pgd_ctor(mm, pgd);
32041- pgd_prepopulate_pmd(mm, pgd, pmds);
32042+ pgd_prepopulate_pxd(mm, pgd, pxds);
32043
32044 spin_unlock(&pgd_lock);
32045
32046 return pgd;
32047
32048-out_free_pmds:
32049- free_pmds(pmds);
32050+out_free_pxds:
32051+ free_pxds(pxds);
32052 out_free_pgd:
32053 free_page((unsigned long)pgd);
32054 out:
32055@@ -300,7 +363,7 @@ out:
32056
32057 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
32058 {
32059- pgd_mop_up_pmds(mm, pgd);
32060+ pgd_mop_up_pxds(mm, pgd);
32061 pgd_dtor(pgd);
32062 paravirt_pgd_free(mm, pgd);
32063 free_page((unsigned long)pgd);
32064diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
32065index a69bcb8..19068ab 100644
32066--- a/arch/x86/mm/pgtable_32.c
32067+++ b/arch/x86/mm/pgtable_32.c
32068@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
32069 return;
32070 }
32071 pte = pte_offset_kernel(pmd, vaddr);
32072+
32073+ pax_open_kernel();
32074 if (pte_val(pteval))
32075 set_pte_at(&init_mm, vaddr, pte, pteval);
32076 else
32077 pte_clear(&init_mm, vaddr, pte);
32078+ pax_close_kernel();
32079
32080 /*
32081 * It's enough to flush this one mapping.
32082diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
32083index e666cbb..61788c45 100644
32084--- a/arch/x86/mm/physaddr.c
32085+++ b/arch/x86/mm/physaddr.c
32086@@ -10,7 +10,7 @@
32087 #ifdef CONFIG_X86_64
32088
32089 #ifdef CONFIG_DEBUG_VIRTUAL
32090-unsigned long __phys_addr(unsigned long x)
32091+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
32092 {
32093 unsigned long y = x - __START_KERNEL_map;
32094
32095@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
32096 #else
32097
32098 #ifdef CONFIG_DEBUG_VIRTUAL
32099-unsigned long __phys_addr(unsigned long x)
32100+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
32101 {
32102 unsigned long phys_addr = x - PAGE_OFFSET;
32103 /* VMALLOC_* aren't constants */
32104diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
32105index 90555bf..f5f1828 100644
32106--- a/arch/x86/mm/setup_nx.c
32107+++ b/arch/x86/mm/setup_nx.c
32108@@ -5,8 +5,10 @@
32109 #include <asm/pgtable.h>
32110 #include <asm/proto.h>
32111
32112+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
32113 static int disable_nx;
32114
32115+#ifndef CONFIG_PAX_PAGEEXEC
32116 /*
32117 * noexec = on|off
32118 *
32119@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
32120 return 0;
32121 }
32122 early_param("noexec", noexec_setup);
32123+#endif
32124+
32125+#endif
32126
32127 void x86_configure_nx(void)
32128 {
32129+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
32130 if (cpu_has_nx && !disable_nx)
32131 __supported_pte_mask |= _PAGE_NX;
32132 else
32133+#endif
32134 __supported_pte_mask &= ~_PAGE_NX;
32135 }
32136
32137diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
32138index 282375f..e03a98f 100644
32139--- a/arch/x86/mm/tlb.c
32140+++ b/arch/x86/mm/tlb.c
32141@@ -48,7 +48,11 @@ void leave_mm(int cpu)
32142 BUG();
32143 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
32144 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
32145+
32146+#ifndef CONFIG_PAX_PER_CPU_PGD
32147 load_cr3(swapper_pg_dir);
32148+#endif
32149+
32150 }
32151 }
32152 EXPORT_SYMBOL_GPL(leave_mm);
32153diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
32154new file mode 100644
32155index 0000000..dace51c
32156--- /dev/null
32157+++ b/arch/x86/mm/uderef_64.c
32158@@ -0,0 +1,37 @@
32159+#include <linux/mm.h>
32160+#include <asm/pgtable.h>
32161+#include <asm/uaccess.h>
32162+
32163+#ifdef CONFIG_PAX_MEMORY_UDEREF
32164+/* PaX: due to the special call convention these functions must
32165+ * - remain leaf functions under all configurations,
32166+ * - never be called directly, only dereferenced from the wrappers.
32167+ */
32168+void __pax_open_userland(void)
32169+{
32170+ unsigned int cpu;
32171+
32172+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
32173+ return;
32174+
32175+ cpu = raw_get_cpu();
32176+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
32177+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
32178+ raw_put_cpu_no_resched();
32179+}
32180+EXPORT_SYMBOL(__pax_open_userland);
32181+
32182+void __pax_close_userland(void)
32183+{
32184+ unsigned int cpu;
32185+
32186+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
32187+ return;
32188+
32189+ cpu = raw_get_cpu();
32190+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
32191+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
32192+ raw_put_cpu_no_resched();
32193+}
32194+EXPORT_SYMBOL(__pax_close_userland);
32195+#endif
32196diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
32197index 877b9a1..a8ecf42 100644
32198--- a/arch/x86/net/bpf_jit.S
32199+++ b/arch/x86/net/bpf_jit.S
32200@@ -9,6 +9,7 @@
32201 */
32202 #include <linux/linkage.h>
32203 #include <asm/dwarf2.h>
32204+#include <asm/alternative-asm.h>
32205
32206 /*
32207 * Calling convention :
32208@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
32209 jle bpf_slow_path_word
32210 mov (SKBDATA,%rsi),%eax
32211 bswap %eax /* ntohl() */
32212+ pax_force_retaddr
32213 ret
32214
32215 sk_load_half:
32216@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
32217 jle bpf_slow_path_half
32218 movzwl (SKBDATA,%rsi),%eax
32219 rol $8,%ax # ntohs()
32220+ pax_force_retaddr
32221 ret
32222
32223 sk_load_byte:
32224@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
32225 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
32226 jle bpf_slow_path_byte
32227 movzbl (SKBDATA,%rsi),%eax
32228+ pax_force_retaddr
32229 ret
32230
32231 /**
32232@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
32233 movzbl (SKBDATA,%rsi),%ebx
32234 and $15,%bl
32235 shl $2,%bl
32236+ pax_force_retaddr
32237 ret
32238
32239 /* rsi contains offset and can be scratched */
32240@@ -109,6 +114,7 @@ bpf_slow_path_word:
32241 js bpf_error
32242 mov -12(%rbp),%eax
32243 bswap %eax
32244+ pax_force_retaddr
32245 ret
32246
32247 bpf_slow_path_half:
32248@@ -117,12 +123,14 @@ bpf_slow_path_half:
32249 mov -12(%rbp),%ax
32250 rol $8,%ax
32251 movzwl %ax,%eax
32252+ pax_force_retaddr
32253 ret
32254
32255 bpf_slow_path_byte:
32256 bpf_slow_path_common(1)
32257 js bpf_error
32258 movzbl -12(%rbp),%eax
32259+ pax_force_retaddr
32260 ret
32261
32262 bpf_slow_path_byte_msh:
32263@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
32264 and $15,%al
32265 shl $2,%al
32266 xchg %eax,%ebx
32267+ pax_force_retaddr
32268 ret
32269
32270 #define sk_negative_common(SIZE) \
32271@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
32272 sk_negative_common(4)
32273 mov (%rax), %eax
32274 bswap %eax
32275+ pax_force_retaddr
32276 ret
32277
32278 bpf_slow_path_half_neg:
32279@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
32280 mov (%rax),%ax
32281 rol $8,%ax
32282 movzwl %ax,%eax
32283+ pax_force_retaddr
32284 ret
32285
32286 bpf_slow_path_byte_neg:
32287@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
32288 .globl sk_load_byte_negative_offset
32289 sk_negative_common(1)
32290 movzbl (%rax), %eax
32291+ pax_force_retaddr
32292 ret
32293
32294 bpf_slow_path_byte_msh_neg:
32295@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
32296 and $15,%al
32297 shl $2,%al
32298 xchg %eax,%ebx
32299+ pax_force_retaddr
32300 ret
32301
32302 bpf_error:
32303@@ -197,4 +210,5 @@ bpf_error:
32304 xor %eax,%eax
32305 mov -8(%rbp),%rbx
32306 leaveq
32307+ pax_force_retaddr
32308 ret
32309diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
32310index 79c216a..08d39cc 100644
32311--- a/arch/x86/net/bpf_jit_comp.c
32312+++ b/arch/x86/net/bpf_jit_comp.c
32313@@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
32314 return ptr + len;
32315 }
32316
32317+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32318+#define MAX_INSTR_CODE_SIZE 96
32319+#else
32320+#define MAX_INSTR_CODE_SIZE 64
32321+#endif
32322+
32323 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
32324
32325 #define EMIT1(b1) EMIT(b1, 1)
32326 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
32327 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
32328 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
32329+
32330+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32331+/* original constant will appear in ecx */
32332+#define DILUTE_CONST_SEQUENCE(_off, _key) \
32333+do { \
32334+ /* mov ecx, randkey */ \
32335+ EMIT1(0xb9); \
32336+ EMIT(_key, 4); \
32337+ /* xor ecx, randkey ^ off */ \
32338+ EMIT2(0x81, 0xf1); \
32339+ EMIT((_key) ^ (_off), 4); \
32340+} while (0)
32341+
32342+#define EMIT1_off32(b1, _off) \
32343+do { \
32344+ switch (b1) { \
32345+ case 0x05: /* add eax, imm32 */ \
32346+ case 0x2d: /* sub eax, imm32 */ \
32347+ case 0x25: /* and eax, imm32 */ \
32348+ case 0x0d: /* or eax, imm32 */ \
32349+ case 0xb8: /* mov eax, imm32 */ \
32350+ case 0x35: /* xor eax, imm32 */ \
32351+ case 0x3d: /* cmp eax, imm32 */ \
32352+ case 0xa9: /* test eax, imm32 */ \
32353+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32354+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
32355+ break; \
32356+ case 0xbb: /* mov ebx, imm32 */ \
32357+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32358+ /* mov ebx, ecx */ \
32359+ EMIT2(0x89, 0xcb); \
32360+ break; \
32361+ case 0xbe: /* mov esi, imm32 */ \
32362+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32363+ /* mov esi, ecx */ \
32364+ EMIT2(0x89, 0xce); \
32365+ break; \
32366+ case 0xe8: /* call rel imm32, always to known funcs */ \
32367+ EMIT1(b1); \
32368+ EMIT(_off, 4); \
32369+ break; \
32370+ case 0xe9: /* jmp rel imm32 */ \
32371+ EMIT1(b1); \
32372+ EMIT(_off, 4); \
32373+ /* prevent fall-through, we're not called if off = 0 */ \
32374+ EMIT(0xcccccccc, 4); \
32375+ EMIT(0xcccccccc, 4); \
32376+ break; \
32377+ default: \
32378+ BUILD_BUG(); \
32379+ } \
32380+} while (0)
32381+
32382+#define EMIT2_off32(b1, b2, _off) \
32383+do { \
32384+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
32385+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
32386+ EMIT(randkey, 4); \
32387+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
32388+ EMIT((_off) - randkey, 4); \
32389+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
32390+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32391+ /* imul eax, ecx */ \
32392+ EMIT3(0x0f, 0xaf, 0xc1); \
32393+ } else { \
32394+ BUILD_BUG(); \
32395+ } \
32396+} while (0)
32397+#else
32398 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
32399+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
32400+#endif
32401
32402 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
32403 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
32404@@ -91,6 +168,24 @@ do { \
32405 #define X86_JBE 0x76
32406 #define X86_JA 0x77
32407
32408+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32409+#define APPEND_FLOW_VERIFY() \
32410+do { \
32411+ /* mov ecx, randkey */ \
32412+ EMIT1(0xb9); \
32413+ EMIT(randkey, 4); \
32414+ /* cmp ecx, randkey */ \
32415+ EMIT2(0x81, 0xf9); \
32416+ EMIT(randkey, 4); \
32417+ /* jz after 8 int 3s */ \
32418+ EMIT2(0x74, 0x08); \
32419+ EMIT(0xcccccccc, 4); \
32420+ EMIT(0xcccccccc, 4); \
32421+} while (0)
32422+#else
32423+#define APPEND_FLOW_VERIFY() do { } while (0)
32424+#endif
32425+
32426 #define EMIT_COND_JMP(op, offset) \
32427 do { \
32428 if (is_near(offset)) \
32429@@ -98,6 +193,7 @@ do { \
32430 else { \
32431 EMIT2(0x0f, op + 0x10); \
32432 EMIT(offset, 4); /* jxx .+off32 */ \
32433+ APPEND_FLOW_VERIFY(); \
32434 } \
32435 } while (0)
32436
32437@@ -145,55 +241,54 @@ static int pkt_type_offset(void)
32438 return -1;
32439 }
32440
32441-struct bpf_binary_header {
32442- unsigned int pages;
32443- /* Note : for security reasons, bpf code will follow a randomly
32444- * sized amount of int3 instructions
32445- */
32446- u8 image[];
32447-};
32448-
32449-static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
32450+/* Note : for security reasons, bpf code will follow a randomly
32451+ * sized amount of int3 instructions
32452+ */
32453+static u8 *bpf_alloc_binary(unsigned int proglen,
32454 u8 **image_ptr)
32455 {
32456 unsigned int sz, hole;
32457- struct bpf_binary_header *header;
32458+ u8 *header;
32459
32460 /* Most of BPF filters are really small,
32461 * but if some of them fill a page, allow at least
32462 * 128 extra bytes to insert a random section of int3
32463 */
32464- sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
32465- header = module_alloc(sz);
32466+ sz = round_up(proglen + 128, PAGE_SIZE);
32467+ header = module_alloc_exec(sz);
32468 if (!header)
32469 return NULL;
32470
32471+ pax_open_kernel();
32472 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
32473+ pax_close_kernel();
32474
32475- header->pages = sz / PAGE_SIZE;
32476- hole = sz - (proglen + sizeof(*header));
32477+ hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
32478
32479 /* insert a random number of int3 instructions before BPF code */
32480- *image_ptr = &header->image[prandom_u32() % hole];
32481+ *image_ptr = &header[prandom_u32() % hole];
32482 return header;
32483 }
32484
32485 void bpf_jit_compile(struct sk_filter *fp)
32486 {
32487- u8 temp[64];
32488+ u8 temp[MAX_INSTR_CODE_SIZE];
32489 u8 *prog;
32490 unsigned int proglen, oldproglen = 0;
32491 int ilen, i;
32492 int t_offset, f_offset;
32493 u8 t_op, f_op, seen = 0, pass;
32494 u8 *image = NULL;
32495- struct bpf_binary_header *header = NULL;
32496+ u8 *header = NULL;
32497 u8 *func;
32498 int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
32499 unsigned int cleanup_addr; /* epilogue code offset */
32500 unsigned int *addrs;
32501 const struct sock_filter *filter = fp->insns;
32502 int flen = fp->len;
32503+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32504+ unsigned int randkey;
32505+#endif
32506
32507 if (!bpf_jit_enable)
32508 return;
32509@@ -202,11 +297,15 @@ void bpf_jit_compile(struct sk_filter *fp)
32510 if (addrs == NULL)
32511 return;
32512
32513+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32514+ randkey = get_random_int();
32515+#endif
32516+
32517 /* Before first pass, make a rough estimation of addrs[]
32518- * each bpf instruction is translated to less than 64 bytes
32519+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
32520 */
32521 for (proglen = 0, i = 0; i < flen; i++) {
32522- proglen += 64;
32523+ proglen += MAX_INSTR_CODE_SIZE;
32524 addrs[i] = proglen;
32525 }
32526 cleanup_addr = proglen; /* epilogue address */
32527@@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
32528 case BPF_S_ALU_MUL_K: /* A *= K */
32529 if (is_imm8(K))
32530 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
32531- else {
32532- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
32533- EMIT(K, 4);
32534- }
32535+ else
32536+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
32537 break;
32538 case BPF_S_ALU_DIV_X: /* A /= X; */
32539 seen |= SEEN_XREG;
32540@@ -360,13 +457,23 @@ void bpf_jit_compile(struct sk_filter *fp)
32541 break;
32542 case BPF_S_ALU_MOD_K: /* A %= K; */
32543 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
32544+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32545+ DILUTE_CONST_SEQUENCE(K, randkey);
32546+#else
32547 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
32548+#endif
32549 EMIT2(0xf7, 0xf1); /* div %ecx */
32550 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
32551 break;
32552 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
32553+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32554+ DILUTE_CONST_SEQUENCE(K, randkey);
32555+ // imul rax, rcx
32556+ EMIT4(0x48, 0x0f, 0xaf, 0xc1);
32557+#else
32558 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
32559 EMIT(K, 4);
32560+#endif
32561 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
32562 break;
32563 case BPF_S_ALU_AND_X:
32564@@ -637,8 +744,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
32565 if (is_imm8(K)) {
32566 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
32567 } else {
32568- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
32569- EMIT(K, 4);
32570+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
32571 }
32572 } else {
32573 EMIT2(0x89,0xde); /* mov %ebx,%esi */
32574@@ -728,10 +834,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
32575 if (unlikely(proglen + ilen > oldproglen)) {
32576 pr_err("bpb_jit_compile fatal error\n");
32577 kfree(addrs);
32578- module_free(NULL, header);
32579+ module_free_exec(NULL, image);
32580 return;
32581 }
32582+ pax_open_kernel();
32583 memcpy(image + proglen, temp, ilen);
32584+ pax_close_kernel();
32585 }
32586 proglen += ilen;
32587 addrs[i] = proglen;
32588@@ -764,7 +872,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
32589
32590 if (image) {
32591 bpf_flush_icache(header, image + proglen);
32592- set_memory_ro((unsigned long)header, header->pages);
32593 fp->bpf_func = (void *)image;
32594 }
32595 out:
32596@@ -776,9 +883,7 @@ void bpf_jit_free(struct sk_filter *fp)
32597 {
32598 if (fp->bpf_func != sk_run_filter) {
32599 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
32600- struct bpf_binary_header *header = (void *)addr;
32601-
32602- set_memory_rw(addr, header->pages);
32603- module_free(NULL, header);
32604+ set_memory_rw(addr, 1);
32605+ module_free_exec(NULL, (void *)addr);
32606 }
32607 }
32608diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
32609index d6aa6e8..266395a 100644
32610--- a/arch/x86/oprofile/backtrace.c
32611+++ b/arch/x86/oprofile/backtrace.c
32612@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
32613 struct stack_frame_ia32 *fp;
32614 unsigned long bytes;
32615
32616- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
32617+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
32618 if (bytes != sizeof(bufhead))
32619 return NULL;
32620
32621- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
32622+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
32623
32624 oprofile_add_trace(bufhead[0].return_address);
32625
32626@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
32627 struct stack_frame bufhead[2];
32628 unsigned long bytes;
32629
32630- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
32631+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
32632 if (bytes != sizeof(bufhead))
32633 return NULL;
32634
32635@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
32636 {
32637 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
32638
32639- if (!user_mode_vm(regs)) {
32640+ if (!user_mode(regs)) {
32641 unsigned long stack = kernel_stack_pointer(regs);
32642 if (depth)
32643 dump_trace(NULL, regs, (unsigned long *)stack, 0,
32644diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
32645index 48768df..ba9143c 100644
32646--- a/arch/x86/oprofile/nmi_int.c
32647+++ b/arch/x86/oprofile/nmi_int.c
32648@@ -23,6 +23,7 @@
32649 #include <asm/nmi.h>
32650 #include <asm/msr.h>
32651 #include <asm/apic.h>
32652+#include <asm/pgtable.h>
32653
32654 #include "op_counter.h"
32655 #include "op_x86_model.h"
32656@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
32657 if (ret)
32658 return ret;
32659
32660- if (!model->num_virt_counters)
32661- model->num_virt_counters = model->num_counters;
32662+ if (!model->num_virt_counters) {
32663+ pax_open_kernel();
32664+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
32665+ pax_close_kernel();
32666+ }
32667
32668 mux_init(ops);
32669
32670diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
32671index b2b9443..be58856 100644
32672--- a/arch/x86/oprofile/op_model_amd.c
32673+++ b/arch/x86/oprofile/op_model_amd.c
32674@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
32675 num_counters = AMD64_NUM_COUNTERS;
32676 }
32677
32678- op_amd_spec.num_counters = num_counters;
32679- op_amd_spec.num_controls = num_counters;
32680- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
32681+ pax_open_kernel();
32682+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
32683+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
32684+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
32685+ pax_close_kernel();
32686
32687 return 0;
32688 }
32689diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
32690index d90528e..0127e2b 100644
32691--- a/arch/x86/oprofile/op_model_ppro.c
32692+++ b/arch/x86/oprofile/op_model_ppro.c
32693@@ -19,6 +19,7 @@
32694 #include <asm/msr.h>
32695 #include <asm/apic.h>
32696 #include <asm/nmi.h>
32697+#include <asm/pgtable.h>
32698
32699 #include "op_x86_model.h"
32700 #include "op_counter.h"
32701@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
32702
32703 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
32704
32705- op_arch_perfmon_spec.num_counters = num_counters;
32706- op_arch_perfmon_spec.num_controls = num_counters;
32707+ pax_open_kernel();
32708+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
32709+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
32710+ pax_close_kernel();
32711 }
32712
32713 static int arch_perfmon_init(struct oprofile_operations *ignore)
32714diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
32715index 71e8a67..6a313bb 100644
32716--- a/arch/x86/oprofile/op_x86_model.h
32717+++ b/arch/x86/oprofile/op_x86_model.h
32718@@ -52,7 +52,7 @@ struct op_x86_model_spec {
32719 void (*switch_ctrl)(struct op_x86_model_spec const *model,
32720 struct op_msrs const * const msrs);
32721 #endif
32722-};
32723+} __do_const;
32724
32725 struct op_counter_config;
32726
32727diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
32728index 372e9b8..e775a6c 100644
32729--- a/arch/x86/pci/irq.c
32730+++ b/arch/x86/pci/irq.c
32731@@ -50,7 +50,7 @@ struct irq_router {
32732 struct irq_router_handler {
32733 u16 vendor;
32734 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
32735-};
32736+} __do_const;
32737
32738 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
32739 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
32740@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
32741 return 0;
32742 }
32743
32744-static __initdata struct irq_router_handler pirq_routers[] = {
32745+static __initconst const struct irq_router_handler pirq_routers[] = {
32746 { PCI_VENDOR_ID_INTEL, intel_router_probe },
32747 { PCI_VENDOR_ID_AL, ali_router_probe },
32748 { PCI_VENDOR_ID_ITE, ite_router_probe },
32749@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
32750 static void __init pirq_find_router(struct irq_router *r)
32751 {
32752 struct irq_routing_table *rt = pirq_table;
32753- struct irq_router_handler *h;
32754+ const struct irq_router_handler *h;
32755
32756 #ifdef CONFIG_PCI_BIOS
32757 if (!rt->signature) {
32758@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
32759 return 0;
32760 }
32761
32762-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
32763+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
32764 {
32765 .callback = fix_broken_hp_bios_irq9,
32766 .ident = "HP Pavilion N5400 Series Laptop",
32767diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
32768index 6eb18c4..20d83de 100644
32769--- a/arch/x86/pci/mrst.c
32770+++ b/arch/x86/pci/mrst.c
32771@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
32772 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
32773 pci_mmcfg_late_init();
32774 pcibios_enable_irq = mrst_pci_irq_enable;
32775- pci_root_ops = pci_mrst_ops;
32776+ pax_open_kernel();
32777+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
32778+ pax_close_kernel();
32779 pci_soc_mode = 1;
32780 /* Continue with standard init */
32781 return 1;
32782diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
32783index c77b24a..c979855 100644
32784--- a/arch/x86/pci/pcbios.c
32785+++ b/arch/x86/pci/pcbios.c
32786@@ -79,7 +79,7 @@ union bios32 {
32787 static struct {
32788 unsigned long address;
32789 unsigned short segment;
32790-} bios32_indirect = { 0, __KERNEL_CS };
32791+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
32792
32793 /*
32794 * Returns the entry point for the given service, NULL on error
32795@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
32796 unsigned long length; /* %ecx */
32797 unsigned long entry; /* %edx */
32798 unsigned long flags;
32799+ struct desc_struct d, *gdt;
32800
32801 local_irq_save(flags);
32802- __asm__("lcall *(%%edi); cld"
32803+
32804+ gdt = get_cpu_gdt_table(smp_processor_id());
32805+
32806+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
32807+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
32808+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
32809+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
32810+
32811+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
32812 : "=a" (return_code),
32813 "=b" (address),
32814 "=c" (length),
32815 "=d" (entry)
32816 : "0" (service),
32817 "1" (0),
32818- "D" (&bios32_indirect));
32819+ "D" (&bios32_indirect),
32820+ "r"(__PCIBIOS_DS)
32821+ : "memory");
32822+
32823+ pax_open_kernel();
32824+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
32825+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
32826+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
32827+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
32828+ pax_close_kernel();
32829+
32830 local_irq_restore(flags);
32831
32832 switch (return_code) {
32833- case 0:
32834- return address + entry;
32835- case 0x80: /* Not present */
32836- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
32837- return 0;
32838- default: /* Shouldn't happen */
32839- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
32840- service, return_code);
32841+ case 0: {
32842+ int cpu;
32843+ unsigned char flags;
32844+
32845+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
32846+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
32847+ printk(KERN_WARNING "bios32_service: not valid\n");
32848 return 0;
32849+ }
32850+ address = address + PAGE_OFFSET;
32851+ length += 16UL; /* some BIOSs underreport this... */
32852+ flags = 4;
32853+ if (length >= 64*1024*1024) {
32854+ length >>= PAGE_SHIFT;
32855+ flags |= 8;
32856+ }
32857+
32858+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32859+ gdt = get_cpu_gdt_table(cpu);
32860+ pack_descriptor(&d, address, length, 0x9b, flags);
32861+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
32862+ pack_descriptor(&d, address, length, 0x93, flags);
32863+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
32864+ }
32865+ return entry;
32866+ }
32867+ case 0x80: /* Not present */
32868+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
32869+ return 0;
32870+ default: /* Shouldn't happen */
32871+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
32872+ service, return_code);
32873+ return 0;
32874 }
32875 }
32876
32877 static struct {
32878 unsigned long address;
32879 unsigned short segment;
32880-} pci_indirect = { 0, __KERNEL_CS };
32881+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
32882
32883-static int pci_bios_present;
32884+static int pci_bios_present __read_only;
32885
32886 static int check_pcibios(void)
32887 {
32888@@ -131,11 +174,13 @@ static int check_pcibios(void)
32889 unsigned long flags, pcibios_entry;
32890
32891 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
32892- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
32893+ pci_indirect.address = pcibios_entry;
32894
32895 local_irq_save(flags);
32896- __asm__(
32897- "lcall *(%%edi); cld\n\t"
32898+ __asm__("movw %w6, %%ds\n\t"
32899+ "lcall *%%ss:(%%edi); cld\n\t"
32900+ "push %%ss\n\t"
32901+ "pop %%ds\n\t"
32902 "jc 1f\n\t"
32903 "xor %%ah, %%ah\n"
32904 "1:"
32905@@ -144,7 +189,8 @@ static int check_pcibios(void)
32906 "=b" (ebx),
32907 "=c" (ecx)
32908 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
32909- "D" (&pci_indirect)
32910+ "D" (&pci_indirect),
32911+ "r" (__PCIBIOS_DS)
32912 : "memory");
32913 local_irq_restore(flags);
32914
32915@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32916
32917 switch (len) {
32918 case 1:
32919- __asm__("lcall *(%%esi); cld\n\t"
32920+ __asm__("movw %w6, %%ds\n\t"
32921+ "lcall *%%ss:(%%esi); cld\n\t"
32922+ "push %%ss\n\t"
32923+ "pop %%ds\n\t"
32924 "jc 1f\n\t"
32925 "xor %%ah, %%ah\n"
32926 "1:"
32927@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32928 : "1" (PCIBIOS_READ_CONFIG_BYTE),
32929 "b" (bx),
32930 "D" ((long)reg),
32931- "S" (&pci_indirect));
32932+ "S" (&pci_indirect),
32933+ "r" (__PCIBIOS_DS));
32934 /*
32935 * Zero-extend the result beyond 8 bits, do not trust the
32936 * BIOS having done it:
32937@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32938 *value &= 0xff;
32939 break;
32940 case 2:
32941- __asm__("lcall *(%%esi); cld\n\t"
32942+ __asm__("movw %w6, %%ds\n\t"
32943+ "lcall *%%ss:(%%esi); cld\n\t"
32944+ "push %%ss\n\t"
32945+ "pop %%ds\n\t"
32946 "jc 1f\n\t"
32947 "xor %%ah, %%ah\n"
32948 "1:"
32949@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32950 : "1" (PCIBIOS_READ_CONFIG_WORD),
32951 "b" (bx),
32952 "D" ((long)reg),
32953- "S" (&pci_indirect));
32954+ "S" (&pci_indirect),
32955+ "r" (__PCIBIOS_DS));
32956 /*
32957 * Zero-extend the result beyond 16 bits, do not trust the
32958 * BIOS having done it:
32959@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32960 *value &= 0xffff;
32961 break;
32962 case 4:
32963- __asm__("lcall *(%%esi); cld\n\t"
32964+ __asm__("movw %w6, %%ds\n\t"
32965+ "lcall *%%ss:(%%esi); cld\n\t"
32966+ "push %%ss\n\t"
32967+ "pop %%ds\n\t"
32968 "jc 1f\n\t"
32969 "xor %%ah, %%ah\n"
32970 "1:"
32971@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32972 : "1" (PCIBIOS_READ_CONFIG_DWORD),
32973 "b" (bx),
32974 "D" ((long)reg),
32975- "S" (&pci_indirect));
32976+ "S" (&pci_indirect),
32977+ "r" (__PCIBIOS_DS));
32978 break;
32979 }
32980
32981@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
32982
32983 switch (len) {
32984 case 1:
32985- __asm__("lcall *(%%esi); cld\n\t"
32986+ __asm__("movw %w6, %%ds\n\t"
32987+ "lcall *%%ss:(%%esi); cld\n\t"
32988+ "push %%ss\n\t"
32989+ "pop %%ds\n\t"
32990 "jc 1f\n\t"
32991 "xor %%ah, %%ah\n"
32992 "1:"
32993@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
32994 "c" (value),
32995 "b" (bx),
32996 "D" ((long)reg),
32997- "S" (&pci_indirect));
32998+ "S" (&pci_indirect),
32999+ "r" (__PCIBIOS_DS));
33000 break;
33001 case 2:
33002- __asm__("lcall *(%%esi); cld\n\t"
33003+ __asm__("movw %w6, %%ds\n\t"
33004+ "lcall *%%ss:(%%esi); cld\n\t"
33005+ "push %%ss\n\t"
33006+ "pop %%ds\n\t"
33007 "jc 1f\n\t"
33008 "xor %%ah, %%ah\n"
33009 "1:"
33010@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33011 "c" (value),
33012 "b" (bx),
33013 "D" ((long)reg),
33014- "S" (&pci_indirect));
33015+ "S" (&pci_indirect),
33016+ "r" (__PCIBIOS_DS));
33017 break;
33018 case 4:
33019- __asm__("lcall *(%%esi); cld\n\t"
33020+ __asm__("movw %w6, %%ds\n\t"
33021+ "lcall *%%ss:(%%esi); cld\n\t"
33022+ "push %%ss\n\t"
33023+ "pop %%ds\n\t"
33024 "jc 1f\n\t"
33025 "xor %%ah, %%ah\n"
33026 "1:"
33027@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33028 "c" (value),
33029 "b" (bx),
33030 "D" ((long)reg),
33031- "S" (&pci_indirect));
33032+ "S" (&pci_indirect),
33033+ "r" (__PCIBIOS_DS));
33034 break;
33035 }
33036
33037@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
33038
33039 DBG("PCI: Fetching IRQ routing table... ");
33040 __asm__("push %%es\n\t"
33041+ "movw %w8, %%ds\n\t"
33042 "push %%ds\n\t"
33043 "pop %%es\n\t"
33044- "lcall *(%%esi); cld\n\t"
33045+ "lcall *%%ss:(%%esi); cld\n\t"
33046 "pop %%es\n\t"
33047+ "push %%ss\n\t"
33048+ "pop %%ds\n"
33049 "jc 1f\n\t"
33050 "xor %%ah, %%ah\n"
33051 "1:"
33052@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
33053 "1" (0),
33054 "D" ((long) &opt),
33055 "S" (&pci_indirect),
33056- "m" (opt)
33057+ "m" (opt),
33058+ "r" (__PCIBIOS_DS)
33059 : "memory");
33060 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
33061 if (ret & 0xff00)
33062@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
33063 {
33064 int ret;
33065
33066- __asm__("lcall *(%%esi); cld\n\t"
33067+ __asm__("movw %w5, %%ds\n\t"
33068+ "lcall *%%ss:(%%esi); cld\n\t"
33069+ "push %%ss\n\t"
33070+ "pop %%ds\n"
33071 "jc 1f\n\t"
33072 "xor %%ah, %%ah\n"
33073 "1:"
33074@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
33075 : "0" (PCIBIOS_SET_PCI_HW_INT),
33076 "b" ((dev->bus->number << 8) | dev->devfn),
33077 "c" ((irq << 8) | (pin + 10)),
33078- "S" (&pci_indirect));
33079+ "S" (&pci_indirect),
33080+ "r" (__PCIBIOS_DS));
33081 return !(ret & 0xff00);
33082 }
33083 EXPORT_SYMBOL(pcibios_set_irq_routing);
33084diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
33085index 40e4469..d915bf9 100644
33086--- a/arch/x86/platform/efi/efi_32.c
33087+++ b/arch/x86/platform/efi/efi_32.c
33088@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
33089 {
33090 struct desc_ptr gdt_descr;
33091
33092+#ifdef CONFIG_PAX_KERNEXEC
33093+ struct desc_struct d;
33094+#endif
33095+
33096 local_irq_save(efi_rt_eflags);
33097
33098 load_cr3(initial_page_table);
33099 __flush_tlb_all();
33100
33101+#ifdef CONFIG_PAX_KERNEXEC
33102+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
33103+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
33104+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
33105+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
33106+#endif
33107+
33108 gdt_descr.address = __pa(get_cpu_gdt_table(0));
33109 gdt_descr.size = GDT_SIZE - 1;
33110 load_gdt(&gdt_descr);
33111@@ -58,11 +69,24 @@ void efi_call_phys_epilog(void)
33112 {
33113 struct desc_ptr gdt_descr;
33114
33115+#ifdef CONFIG_PAX_KERNEXEC
33116+ struct desc_struct d;
33117+
33118+ memset(&d, 0, sizeof d);
33119+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
33120+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
33121+#endif
33122+
33123 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
33124 gdt_descr.size = GDT_SIZE - 1;
33125 load_gdt(&gdt_descr);
33126
33127+#ifdef CONFIG_PAX_PER_CPU_PGD
33128+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
33129+#else
33130 load_cr3(swapper_pg_dir);
33131+#endif
33132+
33133 __flush_tlb_all();
33134
33135 local_irq_restore(efi_rt_eflags);
33136diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
33137index 39a0e7f1..872396e 100644
33138--- a/arch/x86/platform/efi/efi_64.c
33139+++ b/arch/x86/platform/efi/efi_64.c
33140@@ -76,6 +76,11 @@ void __init efi_call_phys_prelog(void)
33141 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
33142 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
33143 }
33144+
33145+#ifdef CONFIG_PAX_PER_CPU_PGD
33146+ load_cr3(swapper_pg_dir);
33147+#endif
33148+
33149 __flush_tlb_all();
33150 }
33151
33152@@ -89,6 +94,11 @@ void __init efi_call_phys_epilog(void)
33153 for (pgd = 0; pgd < n_pgds; pgd++)
33154 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
33155 kfree(save_pgd);
33156+
33157+#ifdef CONFIG_PAX_PER_CPU_PGD
33158+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
33159+#endif
33160+
33161 __flush_tlb_all();
33162 local_irq_restore(efi_flags);
33163 early_code_mapping_set_exec(0);
33164diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
33165index fbe66e6..eae5e38 100644
33166--- a/arch/x86/platform/efi/efi_stub_32.S
33167+++ b/arch/x86/platform/efi/efi_stub_32.S
33168@@ -6,7 +6,9 @@
33169 */
33170
33171 #include <linux/linkage.h>
33172+#include <linux/init.h>
33173 #include <asm/page_types.h>
33174+#include <asm/segment.h>
33175
33176 /*
33177 * efi_call_phys(void *, ...) is a function with variable parameters.
33178@@ -20,7 +22,7 @@
33179 * service functions will comply with gcc calling convention, too.
33180 */
33181
33182-.text
33183+__INIT
33184 ENTRY(efi_call_phys)
33185 /*
33186 * 0. The function can only be called in Linux kernel. So CS has been
33187@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
33188 * The mapping of lower virtual memory has been created in prelog and
33189 * epilog.
33190 */
33191- movl $1f, %edx
33192- subl $__PAGE_OFFSET, %edx
33193- jmp *%edx
33194+#ifdef CONFIG_PAX_KERNEXEC
33195+ movl $(__KERNEXEC_EFI_DS), %edx
33196+ mov %edx, %ds
33197+ mov %edx, %es
33198+ mov %edx, %ss
33199+ addl $2f,(1f)
33200+ ljmp *(1f)
33201+
33202+__INITDATA
33203+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
33204+.previous
33205+
33206+2:
33207+ subl $2b,(1b)
33208+#else
33209+ jmp 1f-__PAGE_OFFSET
33210 1:
33211+#endif
33212
33213 /*
33214 * 2. Now on the top of stack is the return
33215@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
33216 * parameter 2, ..., param n. To make things easy, we save the return
33217 * address of efi_call_phys in a global variable.
33218 */
33219- popl %edx
33220- movl %edx, saved_return_addr
33221- /* get the function pointer into ECX*/
33222- popl %ecx
33223- movl %ecx, efi_rt_function_ptr
33224- movl $2f, %edx
33225- subl $__PAGE_OFFSET, %edx
33226- pushl %edx
33227+ popl (saved_return_addr)
33228+ popl (efi_rt_function_ptr)
33229
33230 /*
33231 * 3. Clear PG bit in %CR0.
33232@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
33233 /*
33234 * 5. Call the physical function.
33235 */
33236- jmp *%ecx
33237+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
33238
33239-2:
33240 /*
33241 * 6. After EFI runtime service returns, control will return to
33242 * following instruction. We'd better readjust stack pointer first.
33243@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
33244 movl %cr0, %edx
33245 orl $0x80000000, %edx
33246 movl %edx, %cr0
33247- jmp 1f
33248-1:
33249+
33250 /*
33251 * 8. Now restore the virtual mode from flat mode by
33252 * adding EIP with PAGE_OFFSET.
33253 */
33254- movl $1f, %edx
33255- jmp *%edx
33256+#ifdef CONFIG_PAX_KERNEXEC
33257+ movl $(__KERNEL_DS), %edx
33258+ mov %edx, %ds
33259+ mov %edx, %es
33260+ mov %edx, %ss
33261+ ljmp $(__KERNEL_CS),$1f
33262+#else
33263+ jmp 1f+__PAGE_OFFSET
33264+#endif
33265 1:
33266
33267 /*
33268 * 9. Balance the stack. And because EAX contain the return value,
33269 * we'd better not clobber it.
33270 */
33271- leal efi_rt_function_ptr, %edx
33272- movl (%edx), %ecx
33273- pushl %ecx
33274+ pushl (efi_rt_function_ptr)
33275
33276 /*
33277- * 10. Push the saved return address onto the stack and return.
33278+ * 10. Return to the saved return address.
33279 */
33280- leal saved_return_addr, %edx
33281- movl (%edx), %ecx
33282- pushl %ecx
33283- ret
33284+ jmpl *(saved_return_addr)
33285 ENDPROC(efi_call_phys)
33286 .previous
33287
33288-.data
33289+__INITDATA
33290 saved_return_addr:
33291 .long 0
33292 efi_rt_function_ptr:
33293diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
33294index 4c07cca..2c8427d 100644
33295--- a/arch/x86/platform/efi/efi_stub_64.S
33296+++ b/arch/x86/platform/efi/efi_stub_64.S
33297@@ -7,6 +7,7 @@
33298 */
33299
33300 #include <linux/linkage.h>
33301+#include <asm/alternative-asm.h>
33302
33303 #define SAVE_XMM \
33304 mov %rsp, %rax; \
33305@@ -40,6 +41,7 @@ ENTRY(efi_call0)
33306 call *%rdi
33307 addq $32, %rsp
33308 RESTORE_XMM
33309+ pax_force_retaddr 0, 1
33310 ret
33311 ENDPROC(efi_call0)
33312
33313@@ -50,6 +52,7 @@ ENTRY(efi_call1)
33314 call *%rdi
33315 addq $32, %rsp
33316 RESTORE_XMM
33317+ pax_force_retaddr 0, 1
33318 ret
33319 ENDPROC(efi_call1)
33320
33321@@ -60,6 +63,7 @@ ENTRY(efi_call2)
33322 call *%rdi
33323 addq $32, %rsp
33324 RESTORE_XMM
33325+ pax_force_retaddr 0, 1
33326 ret
33327 ENDPROC(efi_call2)
33328
33329@@ -71,6 +75,7 @@ ENTRY(efi_call3)
33330 call *%rdi
33331 addq $32, %rsp
33332 RESTORE_XMM
33333+ pax_force_retaddr 0, 1
33334 ret
33335 ENDPROC(efi_call3)
33336
33337@@ -83,6 +88,7 @@ ENTRY(efi_call4)
33338 call *%rdi
33339 addq $32, %rsp
33340 RESTORE_XMM
33341+ pax_force_retaddr 0, 1
33342 ret
33343 ENDPROC(efi_call4)
33344
33345@@ -96,6 +102,7 @@ ENTRY(efi_call5)
33346 call *%rdi
33347 addq $48, %rsp
33348 RESTORE_XMM
33349+ pax_force_retaddr 0, 1
33350 ret
33351 ENDPROC(efi_call5)
33352
33353@@ -112,5 +119,6 @@ ENTRY(efi_call6)
33354 call *%rdi
33355 addq $48, %rsp
33356 RESTORE_XMM
33357+ pax_force_retaddr 0, 1
33358 ret
33359 ENDPROC(efi_call6)
33360diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
33361index 47fe66f..6206449 100644
33362--- a/arch/x86/platform/mrst/mrst.c
33363+++ b/arch/x86/platform/mrst/mrst.c
33364@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
33365 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
33366 int sfi_mrtc_num;
33367
33368-static void mrst_power_off(void)
33369+static __noreturn void mrst_power_off(void)
33370 {
33371+ BUG();
33372 }
33373
33374-static void mrst_reboot(void)
33375+static __noreturn void mrst_reboot(void)
33376 {
33377 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
33378+ BUG();
33379 }
33380
33381 /* parse all the mtimer info to a static mtimer array */
33382diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
33383index d6ee929..3637cb5 100644
33384--- a/arch/x86/platform/olpc/olpc_dt.c
33385+++ b/arch/x86/platform/olpc/olpc_dt.c
33386@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
33387 return res;
33388 }
33389
33390-static struct of_pdt_ops prom_olpc_ops __initdata = {
33391+static struct of_pdt_ops prom_olpc_ops __initconst = {
33392 .nextprop = olpc_dt_nextprop,
33393 .getproplen = olpc_dt_getproplen,
33394 .getproperty = olpc_dt_getproperty,
33395diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
33396index 1cf5b30..fd45732 100644
33397--- a/arch/x86/power/cpu.c
33398+++ b/arch/x86/power/cpu.c
33399@@ -137,11 +137,8 @@ static void do_fpu_end(void)
33400 static void fix_processor_context(void)
33401 {
33402 int cpu = smp_processor_id();
33403- struct tss_struct *t = &per_cpu(init_tss, cpu);
33404-#ifdef CONFIG_X86_64
33405- struct desc_struct *desc = get_cpu_gdt_table(cpu);
33406- tss_desc tss;
33407-#endif
33408+ struct tss_struct *t = init_tss + cpu;
33409+
33410 set_tss_desc(cpu, t); /*
33411 * This just modifies memory; should not be
33412 * necessary. But... This is necessary, because
33413@@ -150,10 +147,6 @@ static void fix_processor_context(void)
33414 */
33415
33416 #ifdef CONFIG_X86_64
33417- memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
33418- tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
33419- write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
33420-
33421 syscall_init(); /* This sets MSR_*STAR and related */
33422 #endif
33423 load_TR_desc(); /* This does ltr */
33424diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
33425index a44f457..9140171 100644
33426--- a/arch/x86/realmode/init.c
33427+++ b/arch/x86/realmode/init.c
33428@@ -70,7 +70,13 @@ void __init setup_real_mode(void)
33429 __va(real_mode_header->trampoline_header);
33430
33431 #ifdef CONFIG_X86_32
33432- trampoline_header->start = __pa_symbol(startup_32_smp);
33433+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
33434+
33435+#ifdef CONFIG_PAX_KERNEXEC
33436+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
33437+#endif
33438+
33439+ trampoline_header->boot_cs = __BOOT_CS;
33440 trampoline_header->gdt_limit = __BOOT_DS + 7;
33441 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
33442 #else
33443@@ -86,7 +92,7 @@ void __init setup_real_mode(void)
33444 *trampoline_cr4_features = read_cr4();
33445
33446 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
33447- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
33448+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
33449 trampoline_pgd[511] = init_level4_pgt[511].pgd;
33450 #endif
33451 }
33452diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
33453index 8869287..d577672 100644
33454--- a/arch/x86/realmode/rm/Makefile
33455+++ b/arch/x86/realmode/rm/Makefile
33456@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
33457 $(call cc-option, -fno-unit-at-a-time)) \
33458 $(call cc-option, -fno-stack-protector) \
33459 $(call cc-option, -mpreferred-stack-boundary=2)
33460+ifdef CONSTIFY_PLUGIN
33461+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
33462+endif
33463 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
33464 GCOV_PROFILE := n
33465diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
33466index a28221d..93c40f1 100644
33467--- a/arch/x86/realmode/rm/header.S
33468+++ b/arch/x86/realmode/rm/header.S
33469@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
33470 #endif
33471 /* APM/BIOS reboot */
33472 .long pa_machine_real_restart_asm
33473-#ifdef CONFIG_X86_64
33474+#ifdef CONFIG_X86_32
33475+ .long __KERNEL_CS
33476+#else
33477 .long __KERNEL32_CS
33478 #endif
33479 END(real_mode_header)
33480diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
33481index c1b2791..f9e31c7 100644
33482--- a/arch/x86/realmode/rm/trampoline_32.S
33483+++ b/arch/x86/realmode/rm/trampoline_32.S
33484@@ -25,6 +25,12 @@
33485 #include <asm/page_types.h>
33486 #include "realmode.h"
33487
33488+#ifdef CONFIG_PAX_KERNEXEC
33489+#define ta(X) (X)
33490+#else
33491+#define ta(X) (pa_ ## X)
33492+#endif
33493+
33494 .text
33495 .code16
33496
33497@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
33498
33499 cli # We should be safe anyway
33500
33501- movl tr_start, %eax # where we need to go
33502-
33503 movl $0xA5A5A5A5, trampoline_status
33504 # write marker for master knows we're running
33505
33506@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
33507 movw $1, %dx # protected mode (PE) bit
33508 lmsw %dx # into protected mode
33509
33510- ljmpl $__BOOT_CS, $pa_startup_32
33511+ ljmpl *(trampoline_header)
33512
33513 .section ".text32","ax"
33514 .code32
33515@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
33516 .balign 8
33517 GLOBAL(trampoline_header)
33518 tr_start: .space 4
33519- tr_gdt_pad: .space 2
33520+ tr_boot_cs: .space 2
33521 tr_gdt: .space 6
33522 END(trampoline_header)
33523
33524diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
33525index bb360dc..d0fd8f8 100644
33526--- a/arch/x86/realmode/rm/trampoline_64.S
33527+++ b/arch/x86/realmode/rm/trampoline_64.S
33528@@ -94,6 +94,7 @@ ENTRY(startup_32)
33529 movl %edx, %gs
33530
33531 movl pa_tr_cr4, %eax
33532+ andl $~X86_CR4_PCIDE, %eax
33533 movl %eax, %cr4 # Enable PAE mode
33534
33535 # Setup trampoline 4 level pagetables
33536@@ -107,7 +108,7 @@ ENTRY(startup_32)
33537 wrmsr
33538
33539 # Enable paging and in turn activate Long Mode
33540- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
33541+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
33542 movl %eax, %cr0
33543
33544 /*
33545diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
33546index e812034..c747134 100644
33547--- a/arch/x86/tools/Makefile
33548+++ b/arch/x86/tools/Makefile
33549@@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
33550
33551 $(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
33552
33553-HOST_EXTRACFLAGS += -I$(srctree)/tools/include
33554+HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
33555 hostprogs-y += relocs
33556 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
33557 relocs: $(obj)/relocs
33558diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
33559index f7bab68..b6d9886 100644
33560--- a/arch/x86/tools/relocs.c
33561+++ b/arch/x86/tools/relocs.c
33562@@ -1,5 +1,7 @@
33563 /* This is included from relocs_32/64.c */
33564
33565+#include "../../../include/generated/autoconf.h"
33566+
33567 #define ElfW(type) _ElfW(ELF_BITS, type)
33568 #define _ElfW(bits, type) __ElfW(bits, type)
33569 #define __ElfW(bits, type) Elf##bits##_##type
33570@@ -11,6 +13,7 @@
33571 #define Elf_Sym ElfW(Sym)
33572
33573 static Elf_Ehdr ehdr;
33574+static Elf_Phdr *phdr;
33575
33576 struct relocs {
33577 uint32_t *offset;
33578@@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
33579 }
33580 }
33581
33582+static void read_phdrs(FILE *fp)
33583+{
33584+ unsigned int i;
33585+
33586+ phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
33587+ if (!phdr) {
33588+ die("Unable to allocate %d program headers\n",
33589+ ehdr.e_phnum);
33590+ }
33591+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
33592+ die("Seek to %d failed: %s\n",
33593+ ehdr.e_phoff, strerror(errno));
33594+ }
33595+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
33596+ die("Cannot read ELF program headers: %s\n",
33597+ strerror(errno));
33598+ }
33599+ for(i = 0; i < ehdr.e_phnum; i++) {
33600+ phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
33601+ phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
33602+ phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
33603+ phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
33604+ phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
33605+ phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
33606+ phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
33607+ phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
33608+ }
33609+
33610+}
33611+
33612 static void read_shdrs(FILE *fp)
33613 {
33614- int i;
33615+ unsigned int i;
33616 Elf_Shdr shdr;
33617
33618 secs = calloc(ehdr.e_shnum, sizeof(struct section));
33619@@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
33620
33621 static void read_strtabs(FILE *fp)
33622 {
33623- int i;
33624+ unsigned int i;
33625 for (i = 0; i < ehdr.e_shnum; i++) {
33626 struct section *sec = &secs[i];
33627 if (sec->shdr.sh_type != SHT_STRTAB) {
33628@@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
33629
33630 static void read_symtabs(FILE *fp)
33631 {
33632- int i,j;
33633+ unsigned int i,j;
33634 for (i = 0; i < ehdr.e_shnum; i++) {
33635 struct section *sec = &secs[i];
33636 if (sec->shdr.sh_type != SHT_SYMTAB) {
33637@@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
33638 }
33639
33640
33641-static void read_relocs(FILE *fp)
33642+static void read_relocs(FILE *fp, int use_real_mode)
33643 {
33644- int i,j;
33645+ unsigned int i,j;
33646+ uint32_t base;
33647+
33648 for (i = 0; i < ehdr.e_shnum; i++) {
33649 struct section *sec = &secs[i];
33650 if (sec->shdr.sh_type != SHT_REL_TYPE) {
33651@@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
33652 die("Cannot read symbol table: %s\n",
33653 strerror(errno));
33654 }
33655+ base = 0;
33656+
33657+#ifdef CONFIG_X86_32
33658+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
33659+ if (phdr[j].p_type != PT_LOAD )
33660+ continue;
33661+ 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)
33662+ continue;
33663+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
33664+ break;
33665+ }
33666+#endif
33667+
33668 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
33669 Elf_Rel *rel = &sec->reltab[j];
33670- rel->r_offset = elf_addr_to_cpu(rel->r_offset);
33671+ rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
33672 rel->r_info = elf_xword_to_cpu(rel->r_info);
33673 #if (SHT_REL_TYPE == SHT_RELA)
33674 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
33675@@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
33676
33677 static void print_absolute_symbols(void)
33678 {
33679- int i;
33680+ unsigned int i;
33681 const char *format;
33682
33683 if (ELF_BITS == 64)
33684@@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
33685 for (i = 0; i < ehdr.e_shnum; i++) {
33686 struct section *sec = &secs[i];
33687 char *sym_strtab;
33688- int j;
33689+ unsigned int j;
33690
33691 if (sec->shdr.sh_type != SHT_SYMTAB) {
33692 continue;
33693@@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
33694
33695 static void print_absolute_relocs(void)
33696 {
33697- int i, printed = 0;
33698+ unsigned int i, printed = 0;
33699 const char *format;
33700
33701 if (ELF_BITS == 64)
33702@@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
33703 struct section *sec_applies, *sec_symtab;
33704 char *sym_strtab;
33705 Elf_Sym *sh_symtab;
33706- int j;
33707+ unsigned int j;
33708 if (sec->shdr.sh_type != SHT_REL_TYPE) {
33709 continue;
33710 }
33711@@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
33712 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
33713 Elf_Sym *sym, const char *symname))
33714 {
33715- int i;
33716+ unsigned int i;
33717 /* Walk through the relocations */
33718 for (i = 0; i < ehdr.e_shnum; i++) {
33719 char *sym_strtab;
33720 Elf_Sym *sh_symtab;
33721 struct section *sec_applies, *sec_symtab;
33722- int j;
33723+ unsigned int j;
33724 struct section *sec = &secs[i];
33725
33726 if (sec->shdr.sh_type != SHT_REL_TYPE) {
33727@@ -812,6 +860,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
33728 {
33729 unsigned r_type = ELF32_R_TYPE(rel->r_info);
33730 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
33731+ char *sym_strtab = sec->link->link->strtab;
33732+
33733+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
33734+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
33735+ return 0;
33736+
33737+#ifdef CONFIG_PAX_KERNEXEC
33738+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
33739+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
33740+ return 0;
33741+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
33742+ return 0;
33743+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
33744+ return 0;
33745+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
33746+ return 0;
33747+#endif
33748
33749 switch (r_type) {
33750 case R_386_NONE:
33751@@ -950,7 +1015,7 @@ static int write32_as_text(uint32_t v, FILE *f)
33752
33753 static void emit_relocs(int as_text, int use_real_mode)
33754 {
33755- int i;
33756+ unsigned int i;
33757 int (*write_reloc)(uint32_t, FILE *) = write32;
33758 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
33759 const char *symname);
33760@@ -1026,10 +1091,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
33761 {
33762 regex_init(use_real_mode);
33763 read_ehdr(fp);
33764+ read_phdrs(fp);
33765 read_shdrs(fp);
33766 read_strtabs(fp);
33767 read_symtabs(fp);
33768- read_relocs(fp);
33769+ read_relocs(fp, use_real_mode);
33770 if (ELF_BITS == 64)
33771 percpu_init();
33772 if (show_absolute_syms) {
33773diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
33774index 80ffa5b..a33bd15 100644
33775--- a/arch/x86/um/tls_32.c
33776+++ b/arch/x86/um/tls_32.c
33777@@ -260,7 +260,7 @@ out:
33778 if (unlikely(task == current &&
33779 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
33780 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
33781- "without flushed TLS.", current->pid);
33782+ "without flushed TLS.", task_pid_nr(current));
33783 }
33784
33785 return 0;
33786diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
33787index fd14be1..e3c79c0 100644
33788--- a/arch/x86/vdso/Makefile
33789+++ b/arch/x86/vdso/Makefile
33790@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
33791 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
33792 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
33793
33794-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
33795+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
33796 GCOV_PROFILE := n
33797
33798 #
33799diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
33800index d6bfb87..876ee18 100644
33801--- a/arch/x86/vdso/vdso32-setup.c
33802+++ b/arch/x86/vdso/vdso32-setup.c
33803@@ -25,6 +25,7 @@
33804 #include <asm/tlbflush.h>
33805 #include <asm/vdso.h>
33806 #include <asm/proto.h>
33807+#include <asm/mman.h>
33808
33809 enum {
33810 VDSO_DISABLED = 0,
33811@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
33812 void enable_sep_cpu(void)
33813 {
33814 int cpu = get_cpu();
33815- struct tss_struct *tss = &per_cpu(init_tss, cpu);
33816+ struct tss_struct *tss = init_tss + cpu;
33817
33818 if (!boot_cpu_has(X86_FEATURE_SEP)) {
33819 put_cpu();
33820@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
33821 gate_vma.vm_start = FIXADDR_USER_START;
33822 gate_vma.vm_end = FIXADDR_USER_END;
33823 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
33824- gate_vma.vm_page_prot = __P101;
33825+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
33826
33827 return 0;
33828 }
33829@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
33830 if (compat)
33831 addr = VDSO_HIGH_BASE;
33832 else {
33833- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
33834+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
33835 if (IS_ERR_VALUE(addr)) {
33836 ret = addr;
33837 goto up_fail;
33838 }
33839 }
33840
33841- current->mm->context.vdso = (void *)addr;
33842+ current->mm->context.vdso = addr;
33843
33844 if (compat_uses_vma || !compat) {
33845 /*
33846@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
33847 }
33848
33849 current_thread_info()->sysenter_return =
33850- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
33851+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
33852
33853 up_fail:
33854 if (ret)
33855- current->mm->context.vdso = NULL;
33856+ current->mm->context.vdso = 0;
33857
33858 up_write(&mm->mmap_sem);
33859
33860@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
33861
33862 const char *arch_vma_name(struct vm_area_struct *vma)
33863 {
33864- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
33865+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
33866 return "[vdso]";
33867+
33868+#ifdef CONFIG_PAX_SEGMEXEC
33869+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
33870+ return "[vdso]";
33871+#endif
33872+
33873 return NULL;
33874 }
33875
33876@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
33877 * Check to see if the corresponding task was created in compat vdso
33878 * mode.
33879 */
33880- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
33881+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
33882 return &gate_vma;
33883 return NULL;
33884 }
33885diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
33886index 431e875..cbb23f3 100644
33887--- a/arch/x86/vdso/vma.c
33888+++ b/arch/x86/vdso/vma.c
33889@@ -16,8 +16,6 @@
33890 #include <asm/vdso.h>
33891 #include <asm/page.h>
33892
33893-unsigned int __read_mostly vdso_enabled = 1;
33894-
33895 extern char vdso_start[], vdso_end[];
33896 extern unsigned short vdso_sync_cpuid;
33897
33898@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
33899 * unaligned here as a result of stack start randomization.
33900 */
33901 addr = PAGE_ALIGN(addr);
33902- addr = align_vdso_addr(addr);
33903
33904 return addr;
33905 }
33906@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
33907 unsigned size)
33908 {
33909 struct mm_struct *mm = current->mm;
33910- unsigned long addr;
33911+ unsigned long addr = 0;
33912 int ret;
33913
33914- if (!vdso_enabled)
33915- return 0;
33916-
33917 down_write(&mm->mmap_sem);
33918+
33919+#ifdef CONFIG_PAX_RANDMMAP
33920+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
33921+#endif
33922+
33923 addr = vdso_addr(mm->start_stack, size);
33924+ addr = align_vdso_addr(addr);
33925 addr = get_unmapped_area(NULL, addr, size, 0, 0);
33926 if (IS_ERR_VALUE(addr)) {
33927 ret = addr;
33928 goto up_fail;
33929 }
33930
33931- current->mm->context.vdso = (void *)addr;
33932+ mm->context.vdso = addr;
33933
33934 ret = install_special_mapping(mm, addr, size,
33935 VM_READ|VM_EXEC|
33936 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
33937 pages);
33938- if (ret) {
33939- current->mm->context.vdso = NULL;
33940- goto up_fail;
33941- }
33942+ if (ret)
33943+ mm->context.vdso = 0;
33944
33945 up_fail:
33946 up_write(&mm->mmap_sem);
33947@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
33948 vdsox32_size);
33949 }
33950 #endif
33951-
33952-static __init int vdso_setup(char *s)
33953-{
33954- vdso_enabled = simple_strtoul(s, NULL, 0);
33955- return 0;
33956-}
33957-__setup("vdso=", vdso_setup);
33958diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
33959index 193097e..7590269 100644
33960--- a/arch/x86/xen/enlighten.c
33961+++ b/arch/x86/xen/enlighten.c
33962@@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
33963
33964 struct shared_info xen_dummy_shared_info;
33965
33966-void *xen_initial_gdt;
33967-
33968 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
33969 __read_mostly int xen_have_vector_callback;
33970 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
33971@@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
33972 {
33973 unsigned long va = dtr->address;
33974 unsigned int size = dtr->size + 1;
33975- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
33976- unsigned long frames[pages];
33977+ unsigned long frames[65536 / PAGE_SIZE];
33978 int f;
33979
33980 /*
33981@@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
33982 {
33983 unsigned long va = dtr->address;
33984 unsigned int size = dtr->size + 1;
33985- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
33986- unsigned long frames[pages];
33987+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
33988 int f;
33989
33990 /*
33991@@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
33992 * 8-byte entries, or 16 4k pages..
33993 */
33994
33995- BUG_ON(size > 65536);
33996+ BUG_ON(size > GDT_SIZE);
33997 BUG_ON(va & ~PAGE_MASK);
33998
33999 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
34000@@ -985,7 +981,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
34001 return 0;
34002 }
34003
34004-static void set_xen_basic_apic_ops(void)
34005+static void __init set_xen_basic_apic_ops(void)
34006 {
34007 apic->read = xen_apic_read;
34008 apic->write = xen_apic_write;
34009@@ -1290,30 +1286,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
34010 #endif
34011 };
34012
34013-static void xen_reboot(int reason)
34014+static __noreturn void xen_reboot(int reason)
34015 {
34016 struct sched_shutdown r = { .reason = reason };
34017
34018- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
34019- BUG();
34020+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
34021+ BUG();
34022 }
34023
34024-static void xen_restart(char *msg)
34025+static __noreturn void xen_restart(char *msg)
34026 {
34027 xen_reboot(SHUTDOWN_reboot);
34028 }
34029
34030-static void xen_emergency_restart(void)
34031+static __noreturn void xen_emergency_restart(void)
34032 {
34033 xen_reboot(SHUTDOWN_reboot);
34034 }
34035
34036-static void xen_machine_halt(void)
34037+static __noreturn void xen_machine_halt(void)
34038 {
34039 xen_reboot(SHUTDOWN_poweroff);
34040 }
34041
34042-static void xen_machine_power_off(void)
34043+static __noreturn void xen_machine_power_off(void)
34044 {
34045 if (pm_power_off)
34046 pm_power_off();
34047@@ -1464,7 +1460,17 @@ asmlinkage void __init xen_start_kernel(void)
34048 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
34049
34050 /* Work out if we support NX */
34051- x86_configure_nx();
34052+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34053+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
34054+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
34055+ unsigned l, h;
34056+
34057+ __supported_pte_mask |= _PAGE_NX;
34058+ rdmsr(MSR_EFER, l, h);
34059+ l |= EFER_NX;
34060+ wrmsr(MSR_EFER, l, h);
34061+ }
34062+#endif
34063
34064 xen_setup_features();
34065
34066@@ -1495,13 +1501,6 @@ asmlinkage void __init xen_start_kernel(void)
34067
34068 machine_ops = xen_machine_ops;
34069
34070- /*
34071- * The only reliable way to retain the initial address of the
34072- * percpu gdt_page is to remember it here, so we can go and
34073- * mark it RW later, when the initial percpu area is freed.
34074- */
34075- xen_initial_gdt = &per_cpu(gdt_page, 0);
34076-
34077 xen_smp_init();
34078
34079 #ifdef CONFIG_ACPI_NUMA
34080diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
34081index fdc3ba2..3daee39 100644
34082--- a/arch/x86/xen/mmu.c
34083+++ b/arch/x86/xen/mmu.c
34084@@ -1894,6 +1894,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
34085 /* L3_k[510] -> level2_kernel_pgt
34086 * L3_i[511] -> level2_fixmap_pgt */
34087 convert_pfn_mfn(level3_kernel_pgt);
34088+ convert_pfn_mfn(level3_vmalloc_start_pgt);
34089+ convert_pfn_mfn(level3_vmalloc_end_pgt);
34090+ convert_pfn_mfn(level3_vmemmap_pgt);
34091
34092 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
34093 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
34094@@ -1923,8 +1926,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
34095 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
34096 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
34097 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
34098+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
34099+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
34100+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
34101 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
34102 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
34103+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
34104 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
34105 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
34106
34107@@ -2108,6 +2115,7 @@ static void __init xen_post_allocator_init(void)
34108 pv_mmu_ops.set_pud = xen_set_pud;
34109 #if PAGETABLE_LEVELS == 4
34110 pv_mmu_ops.set_pgd = xen_set_pgd;
34111+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
34112 #endif
34113
34114 /* This will work as long as patching hasn't happened yet
34115@@ -2186,6 +2194,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
34116 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
34117 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
34118 .set_pgd = xen_set_pgd_hyper,
34119+ .set_pgd_batched = xen_set_pgd_hyper,
34120
34121 .alloc_pud = xen_alloc_pmd_init,
34122 .release_pud = xen_release_pmd_init,
34123diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
34124index b81c88e..2cbe7b8 100644
34125--- a/arch/x86/xen/smp.c
34126+++ b/arch/x86/xen/smp.c
34127@@ -272,11 +272,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
34128 {
34129 BUG_ON(smp_processor_id() != 0);
34130 native_smp_prepare_boot_cpu();
34131-
34132- /* We've switched to the "real" per-cpu gdt, so make sure the
34133- old memory can be recycled */
34134- make_lowmem_page_readwrite(xen_initial_gdt);
34135-
34136 xen_filter_cpu_maps();
34137 xen_setup_vcpu_info_placement();
34138 }
34139@@ -346,7 +341,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
34140 ctxt->user_regs.ss = __KERNEL_DS;
34141 #ifdef CONFIG_X86_32
34142 ctxt->user_regs.fs = __KERNEL_PERCPU;
34143- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
34144+ savesegment(gs, ctxt->user_regs.gs);
34145 #else
34146 ctxt->gs_base_kernel = per_cpu_offset(cpu);
34147 #endif
34148@@ -356,8 +351,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
34149
34150 {
34151 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
34152- ctxt->user_regs.ds = __USER_DS;
34153- ctxt->user_regs.es = __USER_DS;
34154+ ctxt->user_regs.ds = __KERNEL_DS;
34155+ ctxt->user_regs.es = __KERNEL_DS;
34156
34157 xen_copy_trap_info(ctxt->trap_ctxt);
34158
34159@@ -402,13 +397,12 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
34160 int rc;
34161
34162 per_cpu(current_task, cpu) = idle;
34163+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
34164 #ifdef CONFIG_X86_32
34165 irq_ctx_init(cpu);
34166 #else
34167 clear_tsk_thread_flag(idle, TIF_FORK);
34168- per_cpu(kernel_stack, cpu) =
34169- (unsigned long)task_stack_page(idle) -
34170- KERNEL_STACK_OFFSET + THREAD_SIZE;
34171+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
34172 #endif
34173 xen_setup_runstate_info(cpu);
34174 xen_setup_timer(cpu);
34175@@ -678,7 +672,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
34176
34177 void __init xen_smp_init(void)
34178 {
34179- smp_ops = xen_smp_ops;
34180+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
34181 xen_fill_possible_map();
34182 xen_init_spinlocks();
34183 }
34184diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
34185index 33ca6e4..0ded929 100644
34186--- a/arch/x86/xen/xen-asm_32.S
34187+++ b/arch/x86/xen/xen-asm_32.S
34188@@ -84,14 +84,14 @@ ENTRY(xen_iret)
34189 ESP_OFFSET=4 # bytes pushed onto stack
34190
34191 /*
34192- * Store vcpu_info pointer for easy access. Do it this way to
34193- * avoid having to reload %fs
34194+ * Store vcpu_info pointer for easy access.
34195 */
34196 #ifdef CONFIG_SMP
34197- GET_THREAD_INFO(%eax)
34198- movl %ss:TI_cpu(%eax), %eax
34199- movl %ss:__per_cpu_offset(,%eax,4), %eax
34200- mov %ss:xen_vcpu(%eax), %eax
34201+ push %fs
34202+ mov $(__KERNEL_PERCPU), %eax
34203+ mov %eax, %fs
34204+ mov PER_CPU_VAR(xen_vcpu), %eax
34205+ pop %fs
34206 #else
34207 movl %ss:xen_vcpu, %eax
34208 #endif
34209diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
34210index 7faed58..ba4427c 100644
34211--- a/arch/x86/xen/xen-head.S
34212+++ b/arch/x86/xen/xen-head.S
34213@@ -19,6 +19,17 @@ ENTRY(startup_xen)
34214 #ifdef CONFIG_X86_32
34215 mov %esi,xen_start_info
34216 mov $init_thread_union+THREAD_SIZE,%esp
34217+#ifdef CONFIG_SMP
34218+ movl $cpu_gdt_table,%edi
34219+ movl $__per_cpu_load,%eax
34220+ movw %ax,__KERNEL_PERCPU + 2(%edi)
34221+ rorl $16,%eax
34222+ movb %al,__KERNEL_PERCPU + 4(%edi)
34223+ movb %ah,__KERNEL_PERCPU + 7(%edi)
34224+ movl $__per_cpu_end - 1,%eax
34225+ subl $__per_cpu_start,%eax
34226+ movw %ax,__KERNEL_PERCPU + 0(%edi)
34227+#endif
34228 #else
34229 mov %rsi,xen_start_info
34230 mov $init_thread_union+THREAD_SIZE,%rsp
34231diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
34232index 86782c5..fa272c8 100644
34233--- a/arch/x86/xen/xen-ops.h
34234+++ b/arch/x86/xen/xen-ops.h
34235@@ -10,8 +10,6 @@
34236 extern const char xen_hypervisor_callback[];
34237 extern const char xen_failsafe_callback[];
34238
34239-extern void *xen_initial_gdt;
34240-
34241 struct trap_info;
34242 void xen_copy_trap_info(struct trap_info *traps);
34243
34244diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
34245index 525bd3d..ef888b1 100644
34246--- a/arch/xtensa/variants/dc232b/include/variant/core.h
34247+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
34248@@ -119,9 +119,9 @@
34249 ----------------------------------------------------------------------*/
34250
34251 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
34252-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
34253 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
34254 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
34255+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
34256
34257 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
34258 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
34259diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
34260index 2f33760..835e50a 100644
34261--- a/arch/xtensa/variants/fsf/include/variant/core.h
34262+++ b/arch/xtensa/variants/fsf/include/variant/core.h
34263@@ -11,6 +11,7 @@
34264 #ifndef _XTENSA_CORE_H
34265 #define _XTENSA_CORE_H
34266
34267+#include <linux/const.h>
34268
34269 /****************************************************************************
34270 Parameters Useful for Any Code, USER or PRIVILEGED
34271@@ -112,9 +113,9 @@
34272 ----------------------------------------------------------------------*/
34273
34274 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
34275-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
34276 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
34277 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
34278+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
34279
34280 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
34281 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
34282diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
34283index af00795..2bb8105 100644
34284--- a/arch/xtensa/variants/s6000/include/variant/core.h
34285+++ b/arch/xtensa/variants/s6000/include/variant/core.h
34286@@ -11,6 +11,7 @@
34287 #ifndef _XTENSA_CORE_CONFIGURATION_H
34288 #define _XTENSA_CORE_CONFIGURATION_H
34289
34290+#include <linux/const.h>
34291
34292 /****************************************************************************
34293 Parameters Useful for Any Code, USER or PRIVILEGED
34294@@ -118,9 +119,9 @@
34295 ----------------------------------------------------------------------*/
34296
34297 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
34298-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
34299 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
34300 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
34301+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
34302
34303 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
34304 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
34305diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
34306index 290792a..416f287 100644
34307--- a/block/blk-cgroup.c
34308+++ b/block/blk-cgroup.c
34309@@ -808,7 +808,7 @@ static void blkcg_css_free(struct cgroup *cgroup)
34310
34311 static struct cgroup_subsys_state *blkcg_css_alloc(struct cgroup *cgroup)
34312 {
34313- static atomic64_t id_seq = ATOMIC64_INIT(0);
34314+ static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
34315 struct blkcg *blkcg;
34316 struct cgroup *parent = cgroup->parent;
34317
34318@@ -823,7 +823,7 @@ static struct cgroup_subsys_state *blkcg_css_alloc(struct cgroup *cgroup)
34319
34320 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
34321 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
34322- blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
34323+ blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
34324 done:
34325 spin_lock_init(&blkcg->lock);
34326 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
34327diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
34328index 4b8d9b54..a7178c0 100644
34329--- a/block/blk-iopoll.c
34330+++ b/block/blk-iopoll.c
34331@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
34332 }
34333 EXPORT_SYMBOL(blk_iopoll_complete);
34334
34335-static void blk_iopoll_softirq(struct softirq_action *h)
34336+static __latent_entropy void blk_iopoll_softirq(void)
34337 {
34338 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
34339 int rearm = 0, budget = blk_iopoll_budget;
34340diff --git a/block/blk-map.c b/block/blk-map.c
34341index 623e1cd..ca1e109 100644
34342--- a/block/blk-map.c
34343+++ b/block/blk-map.c
34344@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
34345 if (!len || !kbuf)
34346 return -EINVAL;
34347
34348- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
34349+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
34350 if (do_copy)
34351 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
34352 else
34353diff --git a/block/blk-softirq.c b/block/blk-softirq.c
34354index ec9e606..3f38839 100644
34355--- a/block/blk-softirq.c
34356+++ b/block/blk-softirq.c
34357@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
34358 * Softirq action handler - move entries to local list and loop over them
34359 * while passing them to the queue registered handler.
34360 */
34361-static void blk_done_softirq(struct softirq_action *h)
34362+static __latent_entropy void blk_done_softirq(void)
34363 {
34364 struct list_head *cpu_list, local_list;
34365
34366diff --git a/block/bsg.c b/block/bsg.c
34367index 420a5a9..23834aa 100644
34368--- a/block/bsg.c
34369+++ b/block/bsg.c
34370@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
34371 struct sg_io_v4 *hdr, struct bsg_device *bd,
34372 fmode_t has_write_perm)
34373 {
34374+ unsigned char tmpcmd[sizeof(rq->__cmd)];
34375+ unsigned char *cmdptr;
34376+
34377 if (hdr->request_len > BLK_MAX_CDB) {
34378 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
34379 if (!rq->cmd)
34380 return -ENOMEM;
34381- }
34382+ cmdptr = rq->cmd;
34383+ } else
34384+ cmdptr = tmpcmd;
34385
34386- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
34387+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
34388 hdr->request_len))
34389 return -EFAULT;
34390
34391+ if (cmdptr != rq->cmd)
34392+ memcpy(rq->cmd, cmdptr, hdr->request_len);
34393+
34394 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
34395 if (blk_verify_command(rq->cmd, has_write_perm))
34396 return -EPERM;
34397diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
34398index 7e5d474..0cf0017 100644
34399--- a/block/compat_ioctl.c
34400+++ b/block/compat_ioctl.c
34401@@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
34402 err |= __get_user(f->spec1, &uf->spec1);
34403 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
34404 err |= __get_user(name, &uf->name);
34405- f->name = compat_ptr(name);
34406+ f->name = (void __force_kernel *)compat_ptr(name);
34407 if (err) {
34408 err = -EFAULT;
34409 goto out;
34410diff --git a/block/genhd.c b/block/genhd.c
34411index dadf42b..48dc887 100644
34412--- a/block/genhd.c
34413+++ b/block/genhd.c
34414@@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
34415
34416 /*
34417 * Register device numbers dev..(dev+range-1)
34418- * range must be nonzero
34419+ * Noop if @range is zero.
34420 * The hash chain is sorted on range, so that subranges can override.
34421 */
34422 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
34423 struct kobject *(*probe)(dev_t, int *, void *),
34424 int (*lock)(dev_t, void *), void *data)
34425 {
34426- kobj_map(bdev_map, devt, range, module, probe, lock, data);
34427+ if (range)
34428+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
34429 }
34430
34431 EXPORT_SYMBOL(blk_register_region);
34432
34433+/* undo blk_register_region(), noop if @range is zero */
34434 void blk_unregister_region(dev_t devt, unsigned long range)
34435 {
34436- kobj_unmap(bdev_map, devt, range);
34437+ if (range)
34438+ kobj_unmap(bdev_map, devt, range);
34439 }
34440
34441 EXPORT_SYMBOL(blk_unregister_region);
34442diff --git a/block/partitions/efi.c b/block/partitions/efi.c
34443index c85fc89..51e690b 100644
34444--- a/block/partitions/efi.c
34445+++ b/block/partitions/efi.c
34446@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
34447 if (!gpt)
34448 return NULL;
34449
34450+ if (!le32_to_cpu(gpt->num_partition_entries))
34451+ return NULL;
34452+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
34453+ if (!pte)
34454+ return NULL;
34455+
34456 count = le32_to_cpu(gpt->num_partition_entries) *
34457 le32_to_cpu(gpt->sizeof_partition_entry);
34458- if (!count)
34459- return NULL;
34460- pte = kmalloc(count, GFP_KERNEL);
34461- if (!pte)
34462- return NULL;
34463-
34464 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
34465 (u8 *) pte,
34466 count) < count) {
34467diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
34468index a5ffcc9..3cedc9c 100644
34469--- a/block/scsi_ioctl.c
34470+++ b/block/scsi_ioctl.c
34471@@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
34472 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
34473 struct sg_io_hdr *hdr, fmode_t mode)
34474 {
34475- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
34476+ unsigned char tmpcmd[sizeof(rq->__cmd)];
34477+ unsigned char *cmdptr;
34478+
34479+ if (rq->cmd != rq->__cmd)
34480+ cmdptr = rq->cmd;
34481+ else
34482+ cmdptr = tmpcmd;
34483+
34484+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
34485 return -EFAULT;
34486+
34487+ if (cmdptr != rq->cmd)
34488+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
34489+
34490 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
34491 return -EPERM;
34492
34493@@ -434,6 +446,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
34494 int err;
34495 unsigned int in_len, out_len, bytes, opcode, cmdlen;
34496 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
34497+ unsigned char tmpcmd[sizeof(rq->__cmd)];
34498+ unsigned char *cmdptr;
34499
34500 if (!sic)
34501 return -EINVAL;
34502@@ -467,9 +481,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
34503 */
34504 err = -EFAULT;
34505 rq->cmd_len = cmdlen;
34506- if (copy_from_user(rq->cmd, sic->data, cmdlen))
34507+
34508+ if (rq->cmd != rq->__cmd)
34509+ cmdptr = rq->cmd;
34510+ else
34511+ cmdptr = tmpcmd;
34512+
34513+ if (copy_from_user(cmdptr, sic->data, cmdlen))
34514 goto error;
34515
34516+ if (rq->cmd != cmdptr)
34517+ memcpy(rq->cmd, cmdptr, cmdlen);
34518+
34519 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
34520 goto error;
34521
34522diff --git a/crypto/cryptd.c b/crypto/cryptd.c
34523index 7bdd61b..afec999 100644
34524--- a/crypto/cryptd.c
34525+++ b/crypto/cryptd.c
34526@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
34527
34528 struct cryptd_blkcipher_request_ctx {
34529 crypto_completion_t complete;
34530-};
34531+} __no_const;
34532
34533 struct cryptd_hash_ctx {
34534 struct crypto_shash *child;
34535@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
34536
34537 struct cryptd_aead_request_ctx {
34538 crypto_completion_t complete;
34539-};
34540+} __no_const;
34541
34542 static void cryptd_queue_worker(struct work_struct *work);
34543
34544diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
34545index f8c920c..ab2cb5a 100644
34546--- a/crypto/pcrypt.c
34547+++ b/crypto/pcrypt.c
34548@@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
34549 int ret;
34550
34551 pinst->kobj.kset = pcrypt_kset;
34552- ret = kobject_add(&pinst->kobj, NULL, name);
34553+ ret = kobject_add(&pinst->kobj, NULL, "%s", name);
34554 if (!ret)
34555 kobject_uevent(&pinst->kobj, KOBJ_ADD);
34556
34557diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
34558index f220d64..d359ad6 100644
34559--- a/drivers/acpi/apei/apei-internal.h
34560+++ b/drivers/acpi/apei/apei-internal.h
34561@@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
34562 struct apei_exec_ins_type {
34563 u32 flags;
34564 apei_exec_ins_func_t run;
34565-};
34566+} __do_const;
34567
34568 struct apei_exec_context {
34569 u32 ip;
34570diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
34571index 33dc6a0..4b24b47 100644
34572--- a/drivers/acpi/apei/cper.c
34573+++ b/drivers/acpi/apei/cper.c
34574@@ -39,12 +39,12 @@
34575 */
34576 u64 cper_next_record_id(void)
34577 {
34578- static atomic64_t seq;
34579+ static atomic64_unchecked_t seq;
34580
34581- if (!atomic64_read(&seq))
34582- atomic64_set(&seq, ((u64)get_seconds()) << 32);
34583+ if (!atomic64_read_unchecked(&seq))
34584+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
34585
34586- return atomic64_inc_return(&seq);
34587+ return atomic64_inc_return_unchecked(&seq);
34588 }
34589 EXPORT_SYMBOL_GPL(cper_next_record_id);
34590
34591diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
34592index ec9b57d..9682b3a 100644
34593--- a/drivers/acpi/apei/ghes.c
34594+++ b/drivers/acpi/apei/ghes.c
34595@@ -478,7 +478,7 @@ static void __ghes_print_estatus(const char *pfx,
34596 const struct acpi_hest_generic *generic,
34597 const struct acpi_hest_generic_status *estatus)
34598 {
34599- static atomic_t seqno;
34600+ static atomic_unchecked_t seqno;
34601 unsigned int curr_seqno;
34602 char pfx_seq[64];
34603
34604@@ -489,7 +489,7 @@ static void __ghes_print_estatus(const char *pfx,
34605 else
34606 pfx = KERN_ERR;
34607 }
34608- curr_seqno = atomic_inc_return(&seqno);
34609+ curr_seqno = atomic_inc_return_unchecked(&seqno);
34610 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
34611 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
34612 pfx_seq, generic->header.source_id);
34613diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
34614index be60399..778b33e8 100644
34615--- a/drivers/acpi/bgrt.c
34616+++ b/drivers/acpi/bgrt.c
34617@@ -87,8 +87,10 @@ static int __init bgrt_init(void)
34618 return -ENODEV;
34619
34620 sysfs_bin_attr_init(&image_attr);
34621- image_attr.private = bgrt_image;
34622- image_attr.size = bgrt_image_size;
34623+ pax_open_kernel();
34624+ *(void **)&image_attr.private = bgrt_image;
34625+ *(size_t *)&image_attr.size = bgrt_image_size;
34626+ pax_close_kernel();
34627
34628 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
34629 if (!bgrt_kobj)
34630diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
34631index cb96296..b81293b 100644
34632--- a/drivers/acpi/blacklist.c
34633+++ b/drivers/acpi/blacklist.c
34634@@ -52,7 +52,7 @@ struct acpi_blacklist_item {
34635 u32 is_critical_error;
34636 };
34637
34638-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
34639+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
34640
34641 /*
34642 * POLICY: If *anything* doesn't work, put it on the blacklist.
34643@@ -193,7 +193,7 @@ static int __init dmi_disable_osi_win7(const struct dmi_system_id *d)
34644 return 0;
34645 }
34646
34647-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
34648+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
34649 {
34650 .callback = dmi_disable_osi_vista,
34651 .ident = "Fujitsu Siemens",
34652diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
34653index f98dd00..7b69865 100644
34654--- a/drivers/acpi/processor_idle.c
34655+++ b/drivers/acpi/processor_idle.c
34656@@ -992,7 +992,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
34657 {
34658 int i, count = CPUIDLE_DRIVER_STATE_START;
34659 struct acpi_processor_cx *cx;
34660- struct cpuidle_state *state;
34661+ cpuidle_state_no_const *state;
34662 struct cpuidle_driver *drv = &acpi_idle_driver;
34663
34664 if (!pr->flags.power_setup_done)
34665diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
34666index 05306a5..733d1f0 100644
34667--- a/drivers/acpi/sysfs.c
34668+++ b/drivers/acpi/sysfs.c
34669@@ -423,11 +423,11 @@ static u32 num_counters;
34670 static struct attribute **all_attrs;
34671 static u32 acpi_gpe_count;
34672
34673-static struct attribute_group interrupt_stats_attr_group = {
34674+static attribute_group_no_const interrupt_stats_attr_group = {
34675 .name = "interrupts",
34676 };
34677
34678-static struct kobj_attribute *counter_attrs;
34679+static kobj_attribute_no_const *counter_attrs;
34680
34681 static void delete_gpe_attr_array(void)
34682 {
34683diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
34684index acfd0f7..e5acb08 100644
34685--- a/drivers/ata/libahci.c
34686+++ b/drivers/ata/libahci.c
34687@@ -1231,7 +1231,7 @@ int ahci_kick_engine(struct ata_port *ap)
34688 }
34689 EXPORT_SYMBOL_GPL(ahci_kick_engine);
34690
34691-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
34692+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
34693 struct ata_taskfile *tf, int is_cmd, u16 flags,
34694 unsigned long timeout_msec)
34695 {
34696diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
34697index c24354d..335c975 100644
34698--- a/drivers/ata/libata-core.c
34699+++ b/drivers/ata/libata-core.c
34700@@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
34701 static void ata_dev_xfermask(struct ata_device *dev);
34702 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
34703
34704-atomic_t ata_print_id = ATOMIC_INIT(0);
34705+atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
34706
34707 struct ata_force_param {
34708 const char *name;
34709@@ -4792,7 +4792,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
34710 struct ata_port *ap;
34711 unsigned int tag;
34712
34713- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34714+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34715 ap = qc->ap;
34716
34717 qc->flags = 0;
34718@@ -4808,7 +4808,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
34719 struct ata_port *ap;
34720 struct ata_link *link;
34721
34722- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34723+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34724 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
34725 ap = qc->ap;
34726 link = qc->dev->link;
34727@@ -5927,6 +5927,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
34728 return;
34729
34730 spin_lock(&lock);
34731+ pax_open_kernel();
34732
34733 for (cur = ops->inherits; cur; cur = cur->inherits) {
34734 void **inherit = (void **)cur;
34735@@ -5940,8 +5941,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
34736 if (IS_ERR(*pp))
34737 *pp = NULL;
34738
34739- ops->inherits = NULL;
34740+ *(struct ata_port_operations **)&ops->inherits = NULL;
34741
34742+ pax_close_kernel();
34743 spin_unlock(&lock);
34744 }
34745
34746@@ -6134,7 +6136,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
34747
34748 /* give ports names and add SCSI hosts */
34749 for (i = 0; i < host->n_ports; i++) {
34750- host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
34751+ host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
34752 host->ports[i]->local_port_no = i + 1;
34753 }
34754
34755diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
34756index b1e880a..8cf82e1 100644
34757--- a/drivers/ata/libata-scsi.c
34758+++ b/drivers/ata/libata-scsi.c
34759@@ -4104,7 +4104,7 @@ int ata_sas_port_init(struct ata_port *ap)
34760
34761 if (rc)
34762 return rc;
34763- ap->print_id = atomic_inc_return(&ata_print_id);
34764+ ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
34765 return 0;
34766 }
34767 EXPORT_SYMBOL_GPL(ata_sas_port_init);
34768diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
34769index 577d902b..cb4781e 100644
34770--- a/drivers/ata/libata.h
34771+++ b/drivers/ata/libata.h
34772@@ -53,7 +53,7 @@ enum {
34773 ATA_DNXFER_QUIET = (1 << 31),
34774 };
34775
34776-extern atomic_t ata_print_id;
34777+extern atomic_unchecked_t ata_print_id;
34778 extern int atapi_passthru16;
34779 extern int libata_fua;
34780 extern int libata_noacpi;
34781diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
34782index 848ed32..132f39d 100644
34783--- a/drivers/ata/pata_arasan_cf.c
34784+++ b/drivers/ata/pata_arasan_cf.c
34785@@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
34786 /* Handle platform specific quirks */
34787 if (quirk) {
34788 if (quirk & CF_BROKEN_PIO) {
34789- ap->ops->set_piomode = NULL;
34790+ pax_open_kernel();
34791+ *(void **)&ap->ops->set_piomode = NULL;
34792+ pax_close_kernel();
34793 ap->pio_mask = 0;
34794 }
34795 if (quirk & CF_BROKEN_MWDMA)
34796diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
34797index f9b983a..887b9d8 100644
34798--- a/drivers/atm/adummy.c
34799+++ b/drivers/atm/adummy.c
34800@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
34801 vcc->pop(vcc, skb);
34802 else
34803 dev_kfree_skb_any(skb);
34804- atomic_inc(&vcc->stats->tx);
34805+ atomic_inc_unchecked(&vcc->stats->tx);
34806
34807 return 0;
34808 }
34809diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
34810index 62a7607..cc4be104 100644
34811--- a/drivers/atm/ambassador.c
34812+++ b/drivers/atm/ambassador.c
34813@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
34814 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
34815
34816 // VC layer stats
34817- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
34818+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
34819
34820 // free the descriptor
34821 kfree (tx_descr);
34822@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
34823 dump_skb ("<<<", vc, skb);
34824
34825 // VC layer stats
34826- atomic_inc(&atm_vcc->stats->rx);
34827+ atomic_inc_unchecked(&atm_vcc->stats->rx);
34828 __net_timestamp(skb);
34829 // end of our responsibility
34830 atm_vcc->push (atm_vcc, skb);
34831@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
34832 } else {
34833 PRINTK (KERN_INFO, "dropped over-size frame");
34834 // should we count this?
34835- atomic_inc(&atm_vcc->stats->rx_drop);
34836+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
34837 }
34838
34839 } else {
34840@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
34841 }
34842
34843 if (check_area (skb->data, skb->len)) {
34844- atomic_inc(&atm_vcc->stats->tx_err);
34845+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
34846 return -ENOMEM; // ?
34847 }
34848
34849diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
34850index 0e3f8f9..765a7a5 100644
34851--- a/drivers/atm/atmtcp.c
34852+++ b/drivers/atm/atmtcp.c
34853@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
34854 if (vcc->pop) vcc->pop(vcc,skb);
34855 else dev_kfree_skb(skb);
34856 if (dev_data) return 0;
34857- atomic_inc(&vcc->stats->tx_err);
34858+ atomic_inc_unchecked(&vcc->stats->tx_err);
34859 return -ENOLINK;
34860 }
34861 size = skb->len+sizeof(struct atmtcp_hdr);
34862@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
34863 if (!new_skb) {
34864 if (vcc->pop) vcc->pop(vcc,skb);
34865 else dev_kfree_skb(skb);
34866- atomic_inc(&vcc->stats->tx_err);
34867+ atomic_inc_unchecked(&vcc->stats->tx_err);
34868 return -ENOBUFS;
34869 }
34870 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
34871@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
34872 if (vcc->pop) vcc->pop(vcc,skb);
34873 else dev_kfree_skb(skb);
34874 out_vcc->push(out_vcc,new_skb);
34875- atomic_inc(&vcc->stats->tx);
34876- atomic_inc(&out_vcc->stats->rx);
34877+ atomic_inc_unchecked(&vcc->stats->tx);
34878+ atomic_inc_unchecked(&out_vcc->stats->rx);
34879 return 0;
34880 }
34881
34882@@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
34883 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
34884 read_unlock(&vcc_sklist_lock);
34885 if (!out_vcc) {
34886- atomic_inc(&vcc->stats->tx_err);
34887+ atomic_inc_unchecked(&vcc->stats->tx_err);
34888 goto done;
34889 }
34890 skb_pull(skb,sizeof(struct atmtcp_hdr));
34891@@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
34892 __net_timestamp(new_skb);
34893 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
34894 out_vcc->push(out_vcc,new_skb);
34895- atomic_inc(&vcc->stats->tx);
34896- atomic_inc(&out_vcc->stats->rx);
34897+ atomic_inc_unchecked(&vcc->stats->tx);
34898+ atomic_inc_unchecked(&out_vcc->stats->rx);
34899 done:
34900 if (vcc->pop) vcc->pop(vcc,skb);
34901 else dev_kfree_skb(skb);
34902diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
34903index b1955ba..b179940 100644
34904--- a/drivers/atm/eni.c
34905+++ b/drivers/atm/eni.c
34906@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
34907 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
34908 vcc->dev->number);
34909 length = 0;
34910- atomic_inc(&vcc->stats->rx_err);
34911+ atomic_inc_unchecked(&vcc->stats->rx_err);
34912 }
34913 else {
34914 length = ATM_CELL_SIZE-1; /* no HEC */
34915@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
34916 size);
34917 }
34918 eff = length = 0;
34919- atomic_inc(&vcc->stats->rx_err);
34920+ atomic_inc_unchecked(&vcc->stats->rx_err);
34921 }
34922 else {
34923 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
34924@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
34925 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
34926 vcc->dev->number,vcc->vci,length,size << 2,descr);
34927 length = eff = 0;
34928- atomic_inc(&vcc->stats->rx_err);
34929+ atomic_inc_unchecked(&vcc->stats->rx_err);
34930 }
34931 }
34932 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
34933@@ -767,7 +767,7 @@ rx_dequeued++;
34934 vcc->push(vcc,skb);
34935 pushed++;
34936 }
34937- atomic_inc(&vcc->stats->rx);
34938+ atomic_inc_unchecked(&vcc->stats->rx);
34939 }
34940 wake_up(&eni_dev->rx_wait);
34941 }
34942@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
34943 PCI_DMA_TODEVICE);
34944 if (vcc->pop) vcc->pop(vcc,skb);
34945 else dev_kfree_skb_irq(skb);
34946- atomic_inc(&vcc->stats->tx);
34947+ atomic_inc_unchecked(&vcc->stats->tx);
34948 wake_up(&eni_dev->tx_wait);
34949 dma_complete++;
34950 }
34951diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
34952index b41c948..a002b17 100644
34953--- a/drivers/atm/firestream.c
34954+++ b/drivers/atm/firestream.c
34955@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
34956 }
34957 }
34958
34959- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
34960+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
34961
34962 fs_dprintk (FS_DEBUG_TXMEM, "i");
34963 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
34964@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
34965 #endif
34966 skb_put (skb, qe->p1 & 0xffff);
34967 ATM_SKB(skb)->vcc = atm_vcc;
34968- atomic_inc(&atm_vcc->stats->rx);
34969+ atomic_inc_unchecked(&atm_vcc->stats->rx);
34970 __net_timestamp(skb);
34971 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
34972 atm_vcc->push (atm_vcc, skb);
34973@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
34974 kfree (pe);
34975 }
34976 if (atm_vcc)
34977- atomic_inc(&atm_vcc->stats->rx_drop);
34978+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
34979 break;
34980 case 0x1f: /* Reassembly abort: no buffers. */
34981 /* Silently increment error counter. */
34982 if (atm_vcc)
34983- atomic_inc(&atm_vcc->stats->rx_drop);
34984+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
34985 break;
34986 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
34987 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
34988diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
34989index 204814e..cede831 100644
34990--- a/drivers/atm/fore200e.c
34991+++ b/drivers/atm/fore200e.c
34992@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
34993 #endif
34994 /* check error condition */
34995 if (*entry->status & STATUS_ERROR)
34996- atomic_inc(&vcc->stats->tx_err);
34997+ atomic_inc_unchecked(&vcc->stats->tx_err);
34998 else
34999- atomic_inc(&vcc->stats->tx);
35000+ atomic_inc_unchecked(&vcc->stats->tx);
35001 }
35002 }
35003
35004@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
35005 if (skb == NULL) {
35006 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
35007
35008- atomic_inc(&vcc->stats->rx_drop);
35009+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35010 return -ENOMEM;
35011 }
35012
35013@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
35014
35015 dev_kfree_skb_any(skb);
35016
35017- atomic_inc(&vcc->stats->rx_drop);
35018+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35019 return -ENOMEM;
35020 }
35021
35022 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
35023
35024 vcc->push(vcc, skb);
35025- atomic_inc(&vcc->stats->rx);
35026+ atomic_inc_unchecked(&vcc->stats->rx);
35027
35028 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
35029
35030@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
35031 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
35032 fore200e->atm_dev->number,
35033 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
35034- atomic_inc(&vcc->stats->rx_err);
35035+ atomic_inc_unchecked(&vcc->stats->rx_err);
35036 }
35037 }
35038
35039@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
35040 goto retry_here;
35041 }
35042
35043- atomic_inc(&vcc->stats->tx_err);
35044+ atomic_inc_unchecked(&vcc->stats->tx_err);
35045
35046 fore200e->tx_sat++;
35047 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
35048diff --git a/drivers/atm/he.c b/drivers/atm/he.c
35049index 507362a..a845e57 100644
35050--- a/drivers/atm/he.c
35051+++ b/drivers/atm/he.c
35052@@ -1698,7 +1698,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35053
35054 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
35055 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
35056- atomic_inc(&vcc->stats->rx_drop);
35057+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35058 goto return_host_buffers;
35059 }
35060
35061@@ -1725,7 +1725,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35062 RBRQ_LEN_ERR(he_dev->rbrq_head)
35063 ? "LEN_ERR" : "",
35064 vcc->vpi, vcc->vci);
35065- atomic_inc(&vcc->stats->rx_err);
35066+ atomic_inc_unchecked(&vcc->stats->rx_err);
35067 goto return_host_buffers;
35068 }
35069
35070@@ -1777,7 +1777,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35071 vcc->push(vcc, skb);
35072 spin_lock(&he_dev->global_lock);
35073
35074- atomic_inc(&vcc->stats->rx);
35075+ atomic_inc_unchecked(&vcc->stats->rx);
35076
35077 return_host_buffers:
35078 ++pdus_assembled;
35079@@ -2103,7 +2103,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
35080 tpd->vcc->pop(tpd->vcc, tpd->skb);
35081 else
35082 dev_kfree_skb_any(tpd->skb);
35083- atomic_inc(&tpd->vcc->stats->tx_err);
35084+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
35085 }
35086 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
35087 return;
35088@@ -2515,7 +2515,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35089 vcc->pop(vcc, skb);
35090 else
35091 dev_kfree_skb_any(skb);
35092- atomic_inc(&vcc->stats->tx_err);
35093+ atomic_inc_unchecked(&vcc->stats->tx_err);
35094 return -EINVAL;
35095 }
35096
35097@@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35098 vcc->pop(vcc, skb);
35099 else
35100 dev_kfree_skb_any(skb);
35101- atomic_inc(&vcc->stats->tx_err);
35102+ atomic_inc_unchecked(&vcc->stats->tx_err);
35103 return -EINVAL;
35104 }
35105 #endif
35106@@ -2538,7 +2538,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35107 vcc->pop(vcc, skb);
35108 else
35109 dev_kfree_skb_any(skb);
35110- atomic_inc(&vcc->stats->tx_err);
35111+ atomic_inc_unchecked(&vcc->stats->tx_err);
35112 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35113 return -ENOMEM;
35114 }
35115@@ -2580,7 +2580,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35116 vcc->pop(vcc, skb);
35117 else
35118 dev_kfree_skb_any(skb);
35119- atomic_inc(&vcc->stats->tx_err);
35120+ atomic_inc_unchecked(&vcc->stats->tx_err);
35121 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35122 return -ENOMEM;
35123 }
35124@@ -2611,7 +2611,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35125 __enqueue_tpd(he_dev, tpd, cid);
35126 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35127
35128- atomic_inc(&vcc->stats->tx);
35129+ atomic_inc_unchecked(&vcc->stats->tx);
35130
35131 return 0;
35132 }
35133diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
35134index 1dc0519..1aadaf7 100644
35135--- a/drivers/atm/horizon.c
35136+++ b/drivers/atm/horizon.c
35137@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
35138 {
35139 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
35140 // VC layer stats
35141- atomic_inc(&vcc->stats->rx);
35142+ atomic_inc_unchecked(&vcc->stats->rx);
35143 __net_timestamp(skb);
35144 // end of our responsibility
35145 vcc->push (vcc, skb);
35146@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
35147 dev->tx_iovec = NULL;
35148
35149 // VC layer stats
35150- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
35151+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
35152
35153 // free the skb
35154 hrz_kfree_skb (skb);
35155diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
35156index 272f009..a18ba55 100644
35157--- a/drivers/atm/idt77252.c
35158+++ b/drivers/atm/idt77252.c
35159@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
35160 else
35161 dev_kfree_skb(skb);
35162
35163- atomic_inc(&vcc->stats->tx);
35164+ atomic_inc_unchecked(&vcc->stats->tx);
35165 }
35166
35167 atomic_dec(&scq->used);
35168@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35169 if ((sb = dev_alloc_skb(64)) == NULL) {
35170 printk("%s: Can't allocate buffers for aal0.\n",
35171 card->name);
35172- atomic_add(i, &vcc->stats->rx_drop);
35173+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
35174 break;
35175 }
35176 if (!atm_charge(vcc, sb->truesize)) {
35177 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
35178 card->name);
35179- atomic_add(i - 1, &vcc->stats->rx_drop);
35180+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
35181 dev_kfree_skb(sb);
35182 break;
35183 }
35184@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35185 ATM_SKB(sb)->vcc = vcc;
35186 __net_timestamp(sb);
35187 vcc->push(vcc, sb);
35188- atomic_inc(&vcc->stats->rx);
35189+ atomic_inc_unchecked(&vcc->stats->rx);
35190
35191 cell += ATM_CELL_PAYLOAD;
35192 }
35193@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35194 "(CDC: %08x)\n",
35195 card->name, len, rpp->len, readl(SAR_REG_CDC));
35196 recycle_rx_pool_skb(card, rpp);
35197- atomic_inc(&vcc->stats->rx_err);
35198+ atomic_inc_unchecked(&vcc->stats->rx_err);
35199 return;
35200 }
35201 if (stat & SAR_RSQE_CRC) {
35202 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
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 (skb_queue_len(&rpp->queue) > 1) {
35209@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35210 RXPRINTK("%s: Can't alloc RX skb.\n",
35211 card->name);
35212 recycle_rx_pool_skb(card, rpp);
35213- atomic_inc(&vcc->stats->rx_err);
35214+ atomic_inc_unchecked(&vcc->stats->rx_err);
35215 return;
35216 }
35217 if (!atm_charge(vcc, skb->truesize)) {
35218@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35219 __net_timestamp(skb);
35220
35221 vcc->push(vcc, skb);
35222- atomic_inc(&vcc->stats->rx);
35223+ atomic_inc_unchecked(&vcc->stats->rx);
35224
35225 return;
35226 }
35227@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35228 __net_timestamp(skb);
35229
35230 vcc->push(vcc, skb);
35231- atomic_inc(&vcc->stats->rx);
35232+ atomic_inc_unchecked(&vcc->stats->rx);
35233
35234 if (skb->truesize > SAR_FB_SIZE_3)
35235 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
35236@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
35237 if (vcc->qos.aal != ATM_AAL0) {
35238 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
35239 card->name, vpi, vci);
35240- atomic_inc(&vcc->stats->rx_drop);
35241+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35242 goto drop;
35243 }
35244
35245 if ((sb = dev_alloc_skb(64)) == NULL) {
35246 printk("%s: Can't allocate buffers for AAL0.\n",
35247 card->name);
35248- atomic_inc(&vcc->stats->rx_err);
35249+ atomic_inc_unchecked(&vcc->stats->rx_err);
35250 goto drop;
35251 }
35252
35253@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
35254 ATM_SKB(sb)->vcc = vcc;
35255 __net_timestamp(sb);
35256 vcc->push(vcc, sb);
35257- atomic_inc(&vcc->stats->rx);
35258+ atomic_inc_unchecked(&vcc->stats->rx);
35259
35260 drop:
35261 skb_pull(queue, 64);
35262@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
35263
35264 if (vc == NULL) {
35265 printk("%s: NULL connection in send().\n", card->name);
35266- atomic_inc(&vcc->stats->tx_err);
35267+ atomic_inc_unchecked(&vcc->stats->tx_err);
35268 dev_kfree_skb(skb);
35269 return -EINVAL;
35270 }
35271 if (!test_bit(VCF_TX, &vc->flags)) {
35272 printk("%s: Trying to transmit on a non-tx VC.\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@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
35279 break;
35280 default:
35281 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
35282- atomic_inc(&vcc->stats->tx_err);
35283+ atomic_inc_unchecked(&vcc->stats->tx_err);
35284 dev_kfree_skb(skb);
35285 return -EINVAL;
35286 }
35287
35288 if (skb_shinfo(skb)->nr_frags != 0) {
35289 printk("%s: No scatter-gather yet.\n", card->name);
35290- atomic_inc(&vcc->stats->tx_err);
35291+ atomic_inc_unchecked(&vcc->stats->tx_err);
35292 dev_kfree_skb(skb);
35293 return -EINVAL;
35294 }
35295@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
35296
35297 err = queue_skb(card, vc, skb, oam);
35298 if (err) {
35299- atomic_inc(&vcc->stats->tx_err);
35300+ atomic_inc_unchecked(&vcc->stats->tx_err);
35301 dev_kfree_skb(skb);
35302 return err;
35303 }
35304@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
35305 skb = dev_alloc_skb(64);
35306 if (!skb) {
35307 printk("%s: Out of memory in send_oam().\n", card->name);
35308- atomic_inc(&vcc->stats->tx_err);
35309+ atomic_inc_unchecked(&vcc->stats->tx_err);
35310 return -ENOMEM;
35311 }
35312 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
35313diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
35314index 4217f29..88f547a 100644
35315--- a/drivers/atm/iphase.c
35316+++ b/drivers/atm/iphase.c
35317@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
35318 status = (u_short) (buf_desc_ptr->desc_mode);
35319 if (status & (RX_CER | RX_PTE | RX_OFL))
35320 {
35321- atomic_inc(&vcc->stats->rx_err);
35322+ atomic_inc_unchecked(&vcc->stats->rx_err);
35323 IF_ERR(printk("IA: bad packet, dropping it");)
35324 if (status & RX_CER) {
35325 IF_ERR(printk(" cause: packet CRC error\n");)
35326@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
35327 len = dma_addr - buf_addr;
35328 if (len > iadev->rx_buf_sz) {
35329 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
35330- atomic_inc(&vcc->stats->rx_err);
35331+ atomic_inc_unchecked(&vcc->stats->rx_err);
35332 goto out_free_desc;
35333 }
35334
35335@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
35336 ia_vcc = INPH_IA_VCC(vcc);
35337 if (ia_vcc == NULL)
35338 {
35339- atomic_inc(&vcc->stats->rx_err);
35340+ atomic_inc_unchecked(&vcc->stats->rx_err);
35341 atm_return(vcc, skb->truesize);
35342 dev_kfree_skb_any(skb);
35343 goto INCR_DLE;
35344@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
35345 if ((length > iadev->rx_buf_sz) || (length >
35346 (skb->len - sizeof(struct cpcs_trailer))))
35347 {
35348- atomic_inc(&vcc->stats->rx_err);
35349+ atomic_inc_unchecked(&vcc->stats->rx_err);
35350 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
35351 length, skb->len);)
35352 atm_return(vcc, skb->truesize);
35353@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
35354
35355 IF_RX(printk("rx_dle_intr: skb push");)
35356 vcc->push(vcc,skb);
35357- atomic_inc(&vcc->stats->rx);
35358+ atomic_inc_unchecked(&vcc->stats->rx);
35359 iadev->rx_pkt_cnt++;
35360 }
35361 INCR_DLE:
35362@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
35363 {
35364 struct k_sonet_stats *stats;
35365 stats = &PRIV(_ia_dev[board])->sonet_stats;
35366- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
35367- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
35368- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
35369- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
35370- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
35371- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
35372- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
35373- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
35374- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
35375+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
35376+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
35377+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
35378+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
35379+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
35380+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
35381+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
35382+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
35383+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
35384 }
35385 ia_cmds.status = 0;
35386 break;
35387@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
35388 if ((desc == 0) || (desc > iadev->num_tx_desc))
35389 {
35390 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
35391- atomic_inc(&vcc->stats->tx);
35392+ atomic_inc_unchecked(&vcc->stats->tx);
35393 if (vcc->pop)
35394 vcc->pop(vcc, skb);
35395 else
35396@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
35397 ATM_DESC(skb) = vcc->vci;
35398 skb_queue_tail(&iadev->tx_dma_q, skb);
35399
35400- atomic_inc(&vcc->stats->tx);
35401+ atomic_inc_unchecked(&vcc->stats->tx);
35402 iadev->tx_pkt_cnt++;
35403 /* Increment transaction counter */
35404 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
35405
35406 #if 0
35407 /* add flow control logic */
35408- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
35409+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
35410 if (iavcc->vc_desc_cnt > 10) {
35411 vcc->tx_quota = vcc->tx_quota * 3 / 4;
35412 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
35413diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
35414index fa7d701..1e404c7 100644
35415--- a/drivers/atm/lanai.c
35416+++ b/drivers/atm/lanai.c
35417@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
35418 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
35419 lanai_endtx(lanai, lvcc);
35420 lanai_free_skb(lvcc->tx.atmvcc, skb);
35421- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
35422+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
35423 }
35424
35425 /* Try to fill the buffer - don't call unless there is backlog */
35426@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
35427 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
35428 __net_timestamp(skb);
35429 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
35430- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
35431+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
35432 out:
35433 lvcc->rx.buf.ptr = end;
35434 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
35435@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35436 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
35437 "vcc %d\n", lanai->number, (unsigned int) s, vci);
35438 lanai->stats.service_rxnotaal5++;
35439- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35440+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35441 return 0;
35442 }
35443 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
35444@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35445 int bytes;
35446 read_unlock(&vcc_sklist_lock);
35447 DPRINTK("got trashed rx pdu on vci %d\n", vci);
35448- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35449+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35450 lvcc->stats.x.aal5.service_trash++;
35451 bytes = (SERVICE_GET_END(s) * 16) -
35452 (((unsigned long) lvcc->rx.buf.ptr) -
35453@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35454 }
35455 if (s & SERVICE_STREAM) {
35456 read_unlock(&vcc_sklist_lock);
35457- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35458+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35459 lvcc->stats.x.aal5.service_stream++;
35460 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
35461 "PDU on VCI %d!\n", lanai->number, vci);
35462@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35463 return 0;
35464 }
35465 DPRINTK("got rx crc error on vci %d\n", vci);
35466- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35467+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35468 lvcc->stats.x.aal5.service_rxcrc++;
35469 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
35470 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
35471diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
35472index 6587dc2..149833d 100644
35473--- a/drivers/atm/nicstar.c
35474+++ b/drivers/atm/nicstar.c
35475@@ -1641,7 +1641,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35476 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
35477 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
35478 card->index);
35479- atomic_inc(&vcc->stats->tx_err);
35480+ atomic_inc_unchecked(&vcc->stats->tx_err);
35481 dev_kfree_skb_any(skb);
35482 return -EINVAL;
35483 }
35484@@ -1649,7 +1649,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35485 if (!vc->tx) {
35486 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
35487 card->index);
35488- atomic_inc(&vcc->stats->tx_err);
35489+ atomic_inc_unchecked(&vcc->stats->tx_err);
35490 dev_kfree_skb_any(skb);
35491 return -EINVAL;
35492 }
35493@@ -1657,14 +1657,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35494 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
35495 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
35496 card->index);
35497- atomic_inc(&vcc->stats->tx_err);
35498+ atomic_inc_unchecked(&vcc->stats->tx_err);
35499 dev_kfree_skb_any(skb);
35500 return -EINVAL;
35501 }
35502
35503 if (skb_shinfo(skb)->nr_frags != 0) {
35504 printk("nicstar%d: No scatter-gather yet.\n", card->index);
35505- atomic_inc(&vcc->stats->tx_err);
35506+ atomic_inc_unchecked(&vcc->stats->tx_err);
35507 dev_kfree_skb_any(skb);
35508 return -EINVAL;
35509 }
35510@@ -1712,11 +1712,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35511 }
35512
35513 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
35514- atomic_inc(&vcc->stats->tx_err);
35515+ atomic_inc_unchecked(&vcc->stats->tx_err);
35516 dev_kfree_skb_any(skb);
35517 return -EIO;
35518 }
35519- atomic_inc(&vcc->stats->tx);
35520+ atomic_inc_unchecked(&vcc->stats->tx);
35521
35522 return 0;
35523 }
35524@@ -2033,14 +2033,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35525 printk
35526 ("nicstar%d: Can't allocate buffers for aal0.\n",
35527 card->index);
35528- atomic_add(i, &vcc->stats->rx_drop);
35529+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
35530 break;
35531 }
35532 if (!atm_charge(vcc, sb->truesize)) {
35533 RXPRINTK
35534 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
35535 card->index);
35536- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
35537+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
35538 dev_kfree_skb_any(sb);
35539 break;
35540 }
35541@@ -2055,7 +2055,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35542 ATM_SKB(sb)->vcc = vcc;
35543 __net_timestamp(sb);
35544 vcc->push(vcc, sb);
35545- atomic_inc(&vcc->stats->rx);
35546+ atomic_inc_unchecked(&vcc->stats->rx);
35547 cell += ATM_CELL_PAYLOAD;
35548 }
35549
35550@@ -2072,7 +2072,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35551 if (iovb == NULL) {
35552 printk("nicstar%d: Out of iovec buffers.\n",
35553 card->index);
35554- atomic_inc(&vcc->stats->rx_drop);
35555+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35556 recycle_rx_buf(card, skb);
35557 return;
35558 }
35559@@ -2096,7 +2096,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35560 small or large buffer itself. */
35561 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
35562 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
35563- atomic_inc(&vcc->stats->rx_err);
35564+ atomic_inc_unchecked(&vcc->stats->rx_err);
35565 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
35566 NS_MAX_IOVECS);
35567 NS_PRV_IOVCNT(iovb) = 0;
35568@@ -2116,7 +2116,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35569 ("nicstar%d: Expected a small buffer, and this is not one.\n",
35570 card->index);
35571 which_list(card, skb);
35572- atomic_inc(&vcc->stats->rx_err);
35573+ atomic_inc_unchecked(&vcc->stats->rx_err);
35574 recycle_rx_buf(card, skb);
35575 vc->rx_iov = NULL;
35576 recycle_iov_buf(card, iovb);
35577@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35578 ("nicstar%d: Expected a large buffer, and this is not one.\n",
35579 card->index);
35580 which_list(card, skb);
35581- atomic_inc(&vcc->stats->rx_err);
35582+ atomic_inc_unchecked(&vcc->stats->rx_err);
35583 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
35584 NS_PRV_IOVCNT(iovb));
35585 vc->rx_iov = NULL;
35586@@ -2152,7 +2152,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35587 printk(" - PDU size mismatch.\n");
35588 else
35589 printk(".\n");
35590- atomic_inc(&vcc->stats->rx_err);
35591+ atomic_inc_unchecked(&vcc->stats->rx_err);
35592 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
35593 NS_PRV_IOVCNT(iovb));
35594 vc->rx_iov = NULL;
35595@@ -2166,7 +2166,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35596 /* skb points to a small buffer */
35597 if (!atm_charge(vcc, skb->truesize)) {
35598 push_rxbufs(card, skb);
35599- atomic_inc(&vcc->stats->rx_drop);
35600+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35601 } else {
35602 skb_put(skb, len);
35603 dequeue_sm_buf(card, skb);
35604@@ -2176,7 +2176,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35605 ATM_SKB(skb)->vcc = vcc;
35606 __net_timestamp(skb);
35607 vcc->push(vcc, skb);
35608- atomic_inc(&vcc->stats->rx);
35609+ atomic_inc_unchecked(&vcc->stats->rx);
35610 }
35611 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
35612 struct sk_buff *sb;
35613@@ -2187,7 +2187,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35614 if (len <= NS_SMBUFSIZE) {
35615 if (!atm_charge(vcc, sb->truesize)) {
35616 push_rxbufs(card, sb);
35617- atomic_inc(&vcc->stats->rx_drop);
35618+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35619 } else {
35620 skb_put(sb, len);
35621 dequeue_sm_buf(card, sb);
35622@@ -2197,7 +2197,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35623 ATM_SKB(sb)->vcc = vcc;
35624 __net_timestamp(sb);
35625 vcc->push(vcc, sb);
35626- atomic_inc(&vcc->stats->rx);
35627+ atomic_inc_unchecked(&vcc->stats->rx);
35628 }
35629
35630 push_rxbufs(card, skb);
35631@@ -2206,7 +2206,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35632
35633 if (!atm_charge(vcc, skb->truesize)) {
35634 push_rxbufs(card, skb);
35635- atomic_inc(&vcc->stats->rx_drop);
35636+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35637 } else {
35638 dequeue_lg_buf(card, skb);
35639 #ifdef NS_USE_DESTRUCTORS
35640@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35641 ATM_SKB(skb)->vcc = vcc;
35642 __net_timestamp(skb);
35643 vcc->push(vcc, skb);
35644- atomic_inc(&vcc->stats->rx);
35645+ atomic_inc_unchecked(&vcc->stats->rx);
35646 }
35647
35648 push_rxbufs(card, sb);
35649@@ -2240,7 +2240,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35650 printk
35651 ("nicstar%d: Out of huge buffers.\n",
35652 card->index);
35653- atomic_inc(&vcc->stats->rx_drop);
35654+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35655 recycle_iovec_rx_bufs(card,
35656 (struct iovec *)
35657 iovb->data,
35658@@ -2291,7 +2291,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35659 card->hbpool.count++;
35660 } else
35661 dev_kfree_skb_any(hb);
35662- atomic_inc(&vcc->stats->rx_drop);
35663+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35664 } else {
35665 /* Copy the small buffer to the huge buffer */
35666 sb = (struct sk_buff *)iov->iov_base;
35667@@ -2328,7 +2328,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35668 #endif /* NS_USE_DESTRUCTORS */
35669 __net_timestamp(hb);
35670 vcc->push(vcc, hb);
35671- atomic_inc(&vcc->stats->rx);
35672+ atomic_inc_unchecked(&vcc->stats->rx);
35673 }
35674 }
35675
35676diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
35677index 32784d1..4a8434a 100644
35678--- a/drivers/atm/solos-pci.c
35679+++ b/drivers/atm/solos-pci.c
35680@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
35681 }
35682 atm_charge(vcc, skb->truesize);
35683 vcc->push(vcc, skb);
35684- atomic_inc(&vcc->stats->rx);
35685+ atomic_inc_unchecked(&vcc->stats->rx);
35686 break;
35687
35688 case PKT_STATUS:
35689@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
35690 vcc = SKB_CB(oldskb)->vcc;
35691
35692 if (vcc) {
35693- atomic_inc(&vcc->stats->tx);
35694+ atomic_inc_unchecked(&vcc->stats->tx);
35695 solos_pop(vcc, oldskb);
35696 } else {
35697 dev_kfree_skb_irq(oldskb);
35698diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
35699index 0215934..ce9f5b1 100644
35700--- a/drivers/atm/suni.c
35701+++ b/drivers/atm/suni.c
35702@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
35703
35704
35705 #define ADD_LIMITED(s,v) \
35706- atomic_add((v),&stats->s); \
35707- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
35708+ atomic_add_unchecked((v),&stats->s); \
35709+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
35710
35711
35712 static void suni_hz(unsigned long from_timer)
35713diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
35714index 5120a96..e2572bd 100644
35715--- a/drivers/atm/uPD98402.c
35716+++ b/drivers/atm/uPD98402.c
35717@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
35718 struct sonet_stats tmp;
35719 int error = 0;
35720
35721- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
35722+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
35723 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
35724 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
35725 if (zero && !error) {
35726@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
35727
35728
35729 #define ADD_LIMITED(s,v) \
35730- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
35731- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
35732- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
35733+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
35734+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
35735+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
35736
35737
35738 static void stat_event(struct atm_dev *dev)
35739@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
35740 if (reason & uPD98402_INT_PFM) stat_event(dev);
35741 if (reason & uPD98402_INT_PCO) {
35742 (void) GET(PCOCR); /* clear interrupt cause */
35743- atomic_add(GET(HECCT),
35744+ atomic_add_unchecked(GET(HECCT),
35745 &PRIV(dev)->sonet_stats.uncorr_hcs);
35746 }
35747 if ((reason & uPD98402_INT_RFO) &&
35748@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
35749 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
35750 uPD98402_INT_LOS),PIMR); /* enable them */
35751 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
35752- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
35753- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
35754- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
35755+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
35756+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
35757+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
35758 return 0;
35759 }
35760
35761diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
35762index 969c3c2..9b72956 100644
35763--- a/drivers/atm/zatm.c
35764+++ b/drivers/atm/zatm.c
35765@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
35766 }
35767 if (!size) {
35768 dev_kfree_skb_irq(skb);
35769- if (vcc) atomic_inc(&vcc->stats->rx_err);
35770+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
35771 continue;
35772 }
35773 if (!atm_charge(vcc,skb->truesize)) {
35774@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
35775 skb->len = size;
35776 ATM_SKB(skb)->vcc = vcc;
35777 vcc->push(vcc,skb);
35778- atomic_inc(&vcc->stats->rx);
35779+ atomic_inc_unchecked(&vcc->stats->rx);
35780 }
35781 zout(pos & 0xffff,MTA(mbx));
35782 #if 0 /* probably a stupid idea */
35783@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
35784 skb_queue_head(&zatm_vcc->backlog,skb);
35785 break;
35786 }
35787- atomic_inc(&vcc->stats->tx);
35788+ atomic_inc_unchecked(&vcc->stats->tx);
35789 wake_up(&zatm_vcc->tx_wait);
35790 }
35791
35792diff --git a/drivers/base/bus.c b/drivers/base/bus.c
35793index d414331..b4dd4ba 100644
35794--- a/drivers/base/bus.c
35795+++ b/drivers/base/bus.c
35796@@ -1163,7 +1163,7 @@ int subsys_interface_register(struct subsys_interface *sif)
35797 return -EINVAL;
35798
35799 mutex_lock(&subsys->p->mutex);
35800- list_add_tail(&sif->node, &subsys->p->interfaces);
35801+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
35802 if (sif->add_dev) {
35803 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
35804 while ((dev = subsys_dev_iter_next(&iter)))
35805@@ -1188,7 +1188,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
35806 subsys = sif->subsys;
35807
35808 mutex_lock(&subsys->p->mutex);
35809- list_del_init(&sif->node);
35810+ pax_list_del_init((struct list_head *)&sif->node);
35811 if (sif->remove_dev) {
35812 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
35813 while ((dev = subsys_dev_iter_next(&iter)))
35814diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
35815index 7413d06..79155fa 100644
35816--- a/drivers/base/devtmpfs.c
35817+++ b/drivers/base/devtmpfs.c
35818@@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
35819 if (!thread)
35820 return 0;
35821
35822- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
35823+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
35824 if (err)
35825 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
35826 else
35827@@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
35828 *err = sys_unshare(CLONE_NEWNS);
35829 if (*err)
35830 goto out;
35831- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
35832+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
35833 if (*err)
35834 goto out;
35835- sys_chdir("/.."); /* will traverse into overmounted root */
35836- sys_chroot(".");
35837+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
35838+ sys_chroot((char __force_user *)".");
35839 complete(&setup_done);
35840 while (1) {
35841 spin_lock(&req_lock);
35842diff --git a/drivers/base/node.c b/drivers/base/node.c
35843index 7616a77c..8f57f51 100644
35844--- a/drivers/base/node.c
35845+++ b/drivers/base/node.c
35846@@ -626,7 +626,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
35847 struct node_attr {
35848 struct device_attribute attr;
35849 enum node_states state;
35850-};
35851+} __do_const;
35852
35853 static ssize_t show_node_state(struct device *dev,
35854 struct device_attribute *attr, char *buf)
35855diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
35856index bfb8955..42c9b9a 100644
35857--- a/drivers/base/power/domain.c
35858+++ b/drivers/base/power/domain.c
35859@@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
35860 {
35861 struct cpuidle_driver *cpuidle_drv;
35862 struct gpd_cpu_data *cpu_data;
35863- struct cpuidle_state *idle_state;
35864+ cpuidle_state_no_const *idle_state;
35865 int ret = 0;
35866
35867 if (IS_ERR_OR_NULL(genpd) || state < 0)
35868@@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
35869 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
35870 {
35871 struct gpd_cpu_data *cpu_data;
35872- struct cpuidle_state *idle_state;
35873+ cpuidle_state_no_const *idle_state;
35874 int ret = 0;
35875
35876 if (IS_ERR_OR_NULL(genpd))
35877diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
35878index a53ebd2..8f73eeb 100644
35879--- a/drivers/base/power/sysfs.c
35880+++ b/drivers/base/power/sysfs.c
35881@@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
35882 return -EIO;
35883 }
35884 }
35885- return sprintf(buf, p);
35886+ return sprintf(buf, "%s", p);
35887 }
35888
35889 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
35890diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
35891index 2d56f41..8830f19 100644
35892--- a/drivers/base/power/wakeup.c
35893+++ b/drivers/base/power/wakeup.c
35894@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
35895 * They need to be modified together atomically, so it's better to use one
35896 * atomic variable to hold them both.
35897 */
35898-static atomic_t combined_event_count = ATOMIC_INIT(0);
35899+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
35900
35901 #define IN_PROGRESS_BITS (sizeof(int) * 4)
35902 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
35903
35904 static void split_counters(unsigned int *cnt, unsigned int *inpr)
35905 {
35906- unsigned int comb = atomic_read(&combined_event_count);
35907+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
35908
35909 *cnt = (comb >> IN_PROGRESS_BITS);
35910 *inpr = comb & MAX_IN_PROGRESS;
35911@@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
35912 ws->start_prevent_time = ws->last_time;
35913
35914 /* Increment the counter of events in progress. */
35915- cec = atomic_inc_return(&combined_event_count);
35916+ cec = atomic_inc_return_unchecked(&combined_event_count);
35917
35918 trace_wakeup_source_activate(ws->name, cec);
35919 }
35920@@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
35921 * Increment the counter of registered wakeup events and decrement the
35922 * couter of wakeup events in progress simultaneously.
35923 */
35924- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
35925+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
35926 trace_wakeup_source_deactivate(ws->name, cec);
35927
35928 split_counters(&cnt, &inpr);
35929diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
35930index e8d11b6..7b1b36f 100644
35931--- a/drivers/base/syscore.c
35932+++ b/drivers/base/syscore.c
35933@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
35934 void register_syscore_ops(struct syscore_ops *ops)
35935 {
35936 mutex_lock(&syscore_ops_lock);
35937- list_add_tail(&ops->node, &syscore_ops_list);
35938+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
35939 mutex_unlock(&syscore_ops_lock);
35940 }
35941 EXPORT_SYMBOL_GPL(register_syscore_ops);
35942@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
35943 void unregister_syscore_ops(struct syscore_ops *ops)
35944 {
35945 mutex_lock(&syscore_ops_lock);
35946- list_del(&ops->node);
35947+ pax_list_del((struct list_head *)&ops->node);
35948 mutex_unlock(&syscore_ops_lock);
35949 }
35950 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
35951diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
35952index 90a4e6b..002d10f 100644
35953--- a/drivers/block/cciss.c
35954+++ b/drivers/block/cciss.c
35955@@ -3011,7 +3011,7 @@ static void start_io(ctlr_info_t *h)
35956 while (!list_empty(&h->reqQ)) {
35957 c = list_entry(h->reqQ.next, CommandList_struct, list);
35958 /* can't do anything if fifo is full */
35959- if ((h->access.fifo_full(h))) {
35960+ if ((h->access->fifo_full(h))) {
35961 dev_warn(&h->pdev->dev, "fifo full\n");
35962 break;
35963 }
35964@@ -3021,7 +3021,7 @@ static void start_io(ctlr_info_t *h)
35965 h->Qdepth--;
35966
35967 /* Tell the controller execute command */
35968- h->access.submit_command(h, c);
35969+ h->access->submit_command(h, c);
35970
35971 /* Put job onto the completed Q */
35972 addQ(&h->cmpQ, c);
35973@@ -3447,17 +3447,17 @@ startio:
35974
35975 static inline unsigned long get_next_completion(ctlr_info_t *h)
35976 {
35977- return h->access.command_completed(h);
35978+ return h->access->command_completed(h);
35979 }
35980
35981 static inline int interrupt_pending(ctlr_info_t *h)
35982 {
35983- return h->access.intr_pending(h);
35984+ return h->access->intr_pending(h);
35985 }
35986
35987 static inline long interrupt_not_for_us(ctlr_info_t *h)
35988 {
35989- return ((h->access.intr_pending(h) == 0) ||
35990+ return ((h->access->intr_pending(h) == 0) ||
35991 (h->interrupts_enabled == 0));
35992 }
35993
35994@@ -3490,7 +3490,7 @@ static inline u32 next_command(ctlr_info_t *h)
35995 u32 a;
35996
35997 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
35998- return h->access.command_completed(h);
35999+ return h->access->command_completed(h);
36000
36001 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
36002 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
36003@@ -4047,7 +4047,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
36004 trans_support & CFGTBL_Trans_use_short_tags);
36005
36006 /* Change the access methods to the performant access methods */
36007- h->access = SA5_performant_access;
36008+ h->access = &SA5_performant_access;
36009 h->transMethod = CFGTBL_Trans_Performant;
36010
36011 return;
36012@@ -4320,7 +4320,7 @@ static int cciss_pci_init(ctlr_info_t *h)
36013 if (prod_index < 0)
36014 return -ENODEV;
36015 h->product_name = products[prod_index].product_name;
36016- h->access = *(products[prod_index].access);
36017+ h->access = products[prod_index].access;
36018
36019 if (cciss_board_disabled(h)) {
36020 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
36021@@ -5052,7 +5052,7 @@ reinit_after_soft_reset:
36022 }
36023
36024 /* make sure the board interrupts are off */
36025- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36026+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36027 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
36028 if (rc)
36029 goto clean2;
36030@@ -5102,7 +5102,7 @@ reinit_after_soft_reset:
36031 * fake ones to scoop up any residual completions.
36032 */
36033 spin_lock_irqsave(&h->lock, flags);
36034- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36035+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36036 spin_unlock_irqrestore(&h->lock, flags);
36037 free_irq(h->intr[h->intr_mode], h);
36038 rc = cciss_request_irq(h, cciss_msix_discard_completions,
36039@@ -5122,9 +5122,9 @@ reinit_after_soft_reset:
36040 dev_info(&h->pdev->dev, "Board READY.\n");
36041 dev_info(&h->pdev->dev,
36042 "Waiting for stale completions to drain.\n");
36043- h->access.set_intr_mask(h, CCISS_INTR_ON);
36044+ h->access->set_intr_mask(h, CCISS_INTR_ON);
36045 msleep(10000);
36046- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36047+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36048
36049 rc = controller_reset_failed(h->cfgtable);
36050 if (rc)
36051@@ -5147,7 +5147,7 @@ reinit_after_soft_reset:
36052 cciss_scsi_setup(h);
36053
36054 /* Turn the interrupts on so we can service requests */
36055- h->access.set_intr_mask(h, CCISS_INTR_ON);
36056+ h->access->set_intr_mask(h, CCISS_INTR_ON);
36057
36058 /* Get the firmware version */
36059 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
36060@@ -5219,7 +5219,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
36061 kfree(flush_buf);
36062 if (return_code != IO_OK)
36063 dev_warn(&h->pdev->dev, "Error flushing cache\n");
36064- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36065+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36066 free_irq(h->intr[h->intr_mode], h);
36067 }
36068
36069diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
36070index 7fda30e..eb5dfe0 100644
36071--- a/drivers/block/cciss.h
36072+++ b/drivers/block/cciss.h
36073@@ -101,7 +101,7 @@ struct ctlr_info
36074 /* information about each logical volume */
36075 drive_info_struct *drv[CISS_MAX_LUN];
36076
36077- struct access_method access;
36078+ struct access_method *access;
36079
36080 /* queue and queue Info */
36081 struct list_head reqQ;
36082diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
36083index 2b94403..fd6ad1f 100644
36084--- a/drivers/block/cpqarray.c
36085+++ b/drivers/block/cpqarray.c
36086@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
36087 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
36088 goto Enomem4;
36089 }
36090- hba[i]->access.set_intr_mask(hba[i], 0);
36091+ hba[i]->access->set_intr_mask(hba[i], 0);
36092 if (request_irq(hba[i]->intr, do_ida_intr,
36093 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
36094 {
36095@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
36096 add_timer(&hba[i]->timer);
36097
36098 /* Enable IRQ now that spinlock and rate limit timer are set up */
36099- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
36100+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
36101
36102 for(j=0; j<NWD; j++) {
36103 struct gendisk *disk = ida_gendisk[i][j];
36104@@ -694,7 +694,7 @@ DBGINFO(
36105 for(i=0; i<NR_PRODUCTS; i++) {
36106 if (board_id == products[i].board_id) {
36107 c->product_name = products[i].product_name;
36108- c->access = *(products[i].access);
36109+ c->access = products[i].access;
36110 break;
36111 }
36112 }
36113@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
36114 hba[ctlr]->intr = intr;
36115 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
36116 hba[ctlr]->product_name = products[j].product_name;
36117- hba[ctlr]->access = *(products[j].access);
36118+ hba[ctlr]->access = products[j].access;
36119 hba[ctlr]->ctlr = ctlr;
36120 hba[ctlr]->board_id = board_id;
36121 hba[ctlr]->pci_dev = NULL; /* not PCI */
36122@@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
36123
36124 while((c = h->reqQ) != NULL) {
36125 /* Can't do anything if we're busy */
36126- if (h->access.fifo_full(h) == 0)
36127+ if (h->access->fifo_full(h) == 0)
36128 return;
36129
36130 /* Get the first entry from the request Q */
36131@@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
36132 h->Qdepth--;
36133
36134 /* Tell the controller to do our bidding */
36135- h->access.submit_command(h, c);
36136+ h->access->submit_command(h, c);
36137
36138 /* Get onto the completion Q */
36139 addQ(&h->cmpQ, c);
36140@@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
36141 unsigned long flags;
36142 __u32 a,a1;
36143
36144- istat = h->access.intr_pending(h);
36145+ istat = h->access->intr_pending(h);
36146 /* Is this interrupt for us? */
36147 if (istat == 0)
36148 return IRQ_NONE;
36149@@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
36150 */
36151 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
36152 if (istat & FIFO_NOT_EMPTY) {
36153- while((a = h->access.command_completed(h))) {
36154+ while((a = h->access->command_completed(h))) {
36155 a1 = a; a &= ~3;
36156 if ((c = h->cmpQ) == NULL)
36157 {
36158@@ -1448,11 +1448,11 @@ static int sendcmd(
36159 /*
36160 * Disable interrupt
36161 */
36162- info_p->access.set_intr_mask(info_p, 0);
36163+ info_p->access->set_intr_mask(info_p, 0);
36164 /* Make sure there is room in the command FIFO */
36165 /* Actually it should be completely empty at this time. */
36166 for (i = 200000; i > 0; i--) {
36167- temp = info_p->access.fifo_full(info_p);
36168+ temp = info_p->access->fifo_full(info_p);
36169 if (temp != 0) {
36170 break;
36171 }
36172@@ -1465,7 +1465,7 @@ DBG(
36173 /*
36174 * Send the cmd
36175 */
36176- info_p->access.submit_command(info_p, c);
36177+ info_p->access->submit_command(info_p, c);
36178 complete = pollcomplete(ctlr);
36179
36180 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
36181@@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
36182 * we check the new geometry. Then turn interrupts back on when
36183 * we're done.
36184 */
36185- host->access.set_intr_mask(host, 0);
36186+ host->access->set_intr_mask(host, 0);
36187 getgeometry(ctlr);
36188- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
36189+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
36190
36191 for(i=0; i<NWD; i++) {
36192 struct gendisk *disk = ida_gendisk[ctlr][i];
36193@@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
36194 /* Wait (up to 2 seconds) for a command to complete */
36195
36196 for (i = 200000; i > 0; i--) {
36197- done = hba[ctlr]->access.command_completed(hba[ctlr]);
36198+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
36199 if (done == 0) {
36200 udelay(10); /* a short fixed delay */
36201 } else
36202diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
36203index be73e9d..7fbf140 100644
36204--- a/drivers/block/cpqarray.h
36205+++ b/drivers/block/cpqarray.h
36206@@ -99,7 +99,7 @@ struct ctlr_info {
36207 drv_info_t drv[NWD];
36208 struct proc_dir_entry *proc;
36209
36210- struct access_method access;
36211+ struct access_method *access;
36212
36213 cmdlist_t *reqQ;
36214 cmdlist_t *cmpQ;
36215diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
36216index 2d7f608..11245fe 100644
36217--- a/drivers/block/drbd/drbd_int.h
36218+++ b/drivers/block/drbd/drbd_int.h
36219@@ -582,7 +582,7 @@ struct drbd_epoch {
36220 struct drbd_tconn *tconn;
36221 struct list_head list;
36222 unsigned int barrier_nr;
36223- atomic_t epoch_size; /* increased on every request added. */
36224+ atomic_unchecked_t epoch_size; /* increased on every request added. */
36225 atomic_t active; /* increased on every req. added, and dec on every finished. */
36226 unsigned long flags;
36227 };
36228@@ -1022,7 +1022,7 @@ struct drbd_conf {
36229 unsigned int al_tr_number;
36230 int al_tr_cycle;
36231 wait_queue_head_t seq_wait;
36232- atomic_t packet_seq;
36233+ atomic_unchecked_t packet_seq;
36234 unsigned int peer_seq;
36235 spinlock_t peer_seq_lock;
36236 unsigned int minor;
36237@@ -1572,7 +1572,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
36238 char __user *uoptval;
36239 int err;
36240
36241- uoptval = (char __user __force *)optval;
36242+ uoptval = (char __force_user *)optval;
36243
36244 set_fs(KERNEL_DS);
36245 if (level == SOL_SOCKET)
36246diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
36247index 55635ed..40e837c 100644
36248--- a/drivers/block/drbd/drbd_main.c
36249+++ b/drivers/block/drbd/drbd_main.c
36250@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
36251 p->sector = sector;
36252 p->block_id = block_id;
36253 p->blksize = blksize;
36254- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
36255+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
36256 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
36257 }
36258
36259@@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
36260 return -EIO;
36261 p->sector = cpu_to_be64(req->i.sector);
36262 p->block_id = (unsigned long)req;
36263- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
36264+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
36265 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
36266 if (mdev->state.conn >= C_SYNC_SOURCE &&
36267 mdev->state.conn <= C_PAUSED_SYNC_T)
36268@@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
36269 {
36270 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
36271
36272- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
36273- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
36274+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
36275+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
36276 kfree(tconn->current_epoch);
36277
36278 idr_destroy(&tconn->volumes);
36279diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
36280index 8cc1e64..ba7ffa9 100644
36281--- a/drivers/block/drbd/drbd_nl.c
36282+++ b/drivers/block/drbd/drbd_nl.c
36283@@ -3440,7 +3440,7 @@ out:
36284
36285 void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
36286 {
36287- static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
36288+ static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
36289 struct sk_buff *msg;
36290 struct drbd_genlmsghdr *d_out;
36291 unsigned seq;
36292@@ -3453,7 +3453,7 @@ void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
36293 return;
36294 }
36295
36296- seq = atomic_inc_return(&drbd_genl_seq);
36297+ seq = atomic_inc_return_unchecked(&drbd_genl_seq);
36298 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
36299 if (!msg)
36300 goto failed;
36301diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
36302index cc29cd3..d4b058b 100644
36303--- a/drivers/block/drbd/drbd_receiver.c
36304+++ b/drivers/block/drbd/drbd_receiver.c
36305@@ -834,7 +834,7 @@ int drbd_connected(struct drbd_conf *mdev)
36306 {
36307 int err;
36308
36309- atomic_set(&mdev->packet_seq, 0);
36310+ atomic_set_unchecked(&mdev->packet_seq, 0);
36311 mdev->peer_seq = 0;
36312
36313 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
36314@@ -1193,7 +1193,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
36315 do {
36316 next_epoch = NULL;
36317
36318- epoch_size = atomic_read(&epoch->epoch_size);
36319+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
36320
36321 switch (ev & ~EV_CLEANUP) {
36322 case EV_PUT:
36323@@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
36324 rv = FE_DESTROYED;
36325 } else {
36326 epoch->flags = 0;
36327- atomic_set(&epoch->epoch_size, 0);
36328+ atomic_set_unchecked(&epoch->epoch_size, 0);
36329 /* atomic_set(&epoch->active, 0); is already zero */
36330 if (rv == FE_STILL_LIVE)
36331 rv = FE_RECYCLED;
36332@@ -1451,7 +1451,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
36333 conn_wait_active_ee_empty(tconn);
36334 drbd_flush(tconn);
36335
36336- if (atomic_read(&tconn->current_epoch->epoch_size)) {
36337+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
36338 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
36339 if (epoch)
36340 break;
36341@@ -1464,11 +1464,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
36342 }
36343
36344 epoch->flags = 0;
36345- atomic_set(&epoch->epoch_size, 0);
36346+ atomic_set_unchecked(&epoch->epoch_size, 0);
36347 atomic_set(&epoch->active, 0);
36348
36349 spin_lock(&tconn->epoch_lock);
36350- if (atomic_read(&tconn->current_epoch->epoch_size)) {
36351+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
36352 list_add(&epoch->list, &tconn->current_epoch->list);
36353 tconn->current_epoch = epoch;
36354 tconn->epochs++;
36355@@ -2172,7 +2172,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
36356
36357 err = wait_for_and_update_peer_seq(mdev, peer_seq);
36358 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
36359- atomic_inc(&tconn->current_epoch->epoch_size);
36360+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
36361 err2 = drbd_drain_block(mdev, pi->size);
36362 if (!err)
36363 err = err2;
36364@@ -2206,7 +2206,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
36365
36366 spin_lock(&tconn->epoch_lock);
36367 peer_req->epoch = tconn->current_epoch;
36368- atomic_inc(&peer_req->epoch->epoch_size);
36369+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
36370 atomic_inc(&peer_req->epoch->active);
36371 spin_unlock(&tconn->epoch_lock);
36372
36373@@ -4347,7 +4347,7 @@ struct data_cmd {
36374 int expect_payload;
36375 size_t pkt_size;
36376 int (*fn)(struct drbd_tconn *, struct packet_info *);
36377-};
36378+} __do_const;
36379
36380 static struct data_cmd drbd_cmd_handler[] = {
36381 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
36382@@ -4467,7 +4467,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
36383 if (!list_empty(&tconn->current_epoch->list))
36384 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
36385 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
36386- atomic_set(&tconn->current_epoch->epoch_size, 0);
36387+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
36388 tconn->send.seen_any_write_yet = false;
36389
36390 conn_info(tconn, "Connection closed\n");
36391@@ -5223,7 +5223,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
36392 struct asender_cmd {
36393 size_t pkt_size;
36394 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
36395-};
36396+} __do_const;
36397
36398 static struct asender_cmd asender_tbl[] = {
36399 [P_PING] = { 0, got_Ping },
36400diff --git a/drivers/block/loop.c b/drivers/block/loop.c
36401index 40e7155..df5c79a 100644
36402--- a/drivers/block/loop.c
36403+++ b/drivers/block/loop.c
36404@@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
36405
36406 file_start_write(file);
36407 set_fs(get_ds());
36408- bw = file->f_op->write(file, buf, len, &pos);
36409+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
36410 set_fs(old_fs);
36411 file_end_write(file);
36412 if (likely(bw == len))
36413diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
36414index f5d0ea1..c62380a 100644
36415--- a/drivers/block/pktcdvd.c
36416+++ b/drivers/block/pktcdvd.c
36417@@ -84,7 +84,7 @@
36418 #define MAX_SPEED 0xffff
36419
36420 #define ZONE(sector, pd) (((sector) + (pd)->offset) & \
36421- ~(sector_t)((pd)->settings.size - 1))
36422+ ~(sector_t)((pd)->settings.size - 1UL))
36423
36424 static DEFINE_MUTEX(pktcdvd_mutex);
36425 static struct pktcdvd_device *pkt_devs[MAX_WRITERS];
36426diff --git a/drivers/bus/arm-cci.c b/drivers/bus/arm-cci.c
36427index 7332889..9ece19e 100644
36428--- a/drivers/bus/arm-cci.c
36429+++ b/drivers/bus/arm-cci.c
36430@@ -419,7 +419,7 @@ static int __init cci_probe(void)
36431
36432 nb_cci_ports = cci_config->nb_ace + cci_config->nb_ace_lite;
36433
36434- ports = kcalloc(sizeof(*ports), nb_cci_ports, GFP_KERNEL);
36435+ ports = kcalloc(nb_cci_ports, sizeof(*ports), GFP_KERNEL);
36436 if (!ports)
36437 return -ENOMEM;
36438
36439diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
36440index 8a3aff7..d7538c2 100644
36441--- a/drivers/cdrom/cdrom.c
36442+++ b/drivers/cdrom/cdrom.c
36443@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
36444 ENSURE(reset, CDC_RESET);
36445 ENSURE(generic_packet, CDC_GENERIC_PACKET);
36446 cdi->mc_flags = 0;
36447- cdo->n_minors = 0;
36448 cdi->options = CDO_USE_FFLAGS;
36449
36450 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
36451@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
36452 else
36453 cdi->cdda_method = CDDA_OLD;
36454
36455- if (!cdo->generic_packet)
36456- cdo->generic_packet = cdrom_dummy_generic_packet;
36457+ if (!cdo->generic_packet) {
36458+ pax_open_kernel();
36459+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
36460+ pax_close_kernel();
36461+ }
36462
36463 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
36464 mutex_lock(&cdrom_mutex);
36465@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
36466 if (cdi->exit)
36467 cdi->exit(cdi);
36468
36469- cdi->ops->n_minors--;
36470 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
36471 }
36472
36473@@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
36474 */
36475 nr = nframes;
36476 do {
36477- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
36478+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
36479 if (cgc.buffer)
36480 break;
36481
36482@@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
36483 struct cdrom_device_info *cdi;
36484 int ret;
36485
36486- ret = scnprintf(info + *pos, max_size - *pos, header);
36487+ ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
36488 if (!ret)
36489 return 1;
36490
36491diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
36492index 5980cb9..6d7bd7e 100644
36493--- a/drivers/cdrom/gdrom.c
36494+++ b/drivers/cdrom/gdrom.c
36495@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
36496 .audio_ioctl = gdrom_audio_ioctl,
36497 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
36498 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
36499- .n_minors = 1,
36500 };
36501
36502 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
36503diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
36504index 1421997..33f5d6d 100644
36505--- a/drivers/char/Kconfig
36506+++ b/drivers/char/Kconfig
36507@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
36508
36509 config DEVKMEM
36510 bool "/dev/kmem virtual device support"
36511- default y
36512+ default n
36513+ depends on !GRKERNSEC_KMEM
36514 help
36515 Say Y here if you want to support the /dev/kmem device. The
36516 /dev/kmem device is rarely used, but can be used for certain
36517@@ -570,6 +571,7 @@ config DEVPORT
36518 bool
36519 depends on !M68K
36520 depends on ISA || PCI
36521+ depends on !GRKERNSEC_KMEM
36522 default y
36523
36524 source "drivers/s390/char/Kconfig"
36525diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
36526index a48e05b..6bac831 100644
36527--- a/drivers/char/agp/compat_ioctl.c
36528+++ b/drivers/char/agp/compat_ioctl.c
36529@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
36530 return -ENOMEM;
36531 }
36532
36533- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
36534+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
36535 sizeof(*usegment) * ureserve.seg_count)) {
36536 kfree(usegment);
36537 kfree(ksegment);
36538diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
36539index 1b19239..b87b143 100644
36540--- a/drivers/char/agp/frontend.c
36541+++ b/drivers/char/agp/frontend.c
36542@@ -819,7 +819,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
36543 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
36544 return -EFAULT;
36545
36546- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
36547+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
36548 return -EFAULT;
36549
36550 client = agp_find_client_by_pid(reserve.pid);
36551@@ -849,7 +849,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
36552 if (segment == NULL)
36553 return -ENOMEM;
36554
36555- if (copy_from_user(segment, (void __user *) reserve.seg_list,
36556+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
36557 sizeof(struct agp_segment) * reserve.seg_count)) {
36558 kfree(segment);
36559 return -EFAULT;
36560diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
36561index 4f94375..413694e 100644
36562--- a/drivers/char/genrtc.c
36563+++ b/drivers/char/genrtc.c
36564@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
36565 switch (cmd) {
36566
36567 case RTC_PLL_GET:
36568+ memset(&pll, 0, sizeof(pll));
36569 if (get_rtc_pll(&pll))
36570 return -EINVAL;
36571 else
36572diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
36573index 448ce5e..3a76625 100644
36574--- a/drivers/char/hpet.c
36575+++ b/drivers/char/hpet.c
36576@@ -559,7 +559,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
36577 }
36578
36579 static int
36580-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
36581+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
36582 struct hpet_info *info)
36583 {
36584 struct hpet_timer __iomem *timer;
36585diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
36586index 86fe45c..c0ea948 100644
36587--- a/drivers/char/hw_random/intel-rng.c
36588+++ b/drivers/char/hw_random/intel-rng.c
36589@@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
36590
36591 if (no_fwh_detect)
36592 return -ENODEV;
36593- printk(warning);
36594+ printk("%s", warning);
36595 return -EBUSY;
36596 }
36597
36598diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
36599index 4445fa1..7c6de37 100644
36600--- a/drivers/char/ipmi/ipmi_msghandler.c
36601+++ b/drivers/char/ipmi/ipmi_msghandler.c
36602@@ -420,7 +420,7 @@ struct ipmi_smi {
36603 struct proc_dir_entry *proc_dir;
36604 char proc_dir_name[10];
36605
36606- atomic_t stats[IPMI_NUM_STATS];
36607+ atomic_unchecked_t stats[IPMI_NUM_STATS];
36608
36609 /*
36610 * run_to_completion duplicate of smb_info, smi_info
36611@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
36612
36613
36614 #define ipmi_inc_stat(intf, stat) \
36615- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
36616+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
36617 #define ipmi_get_stat(intf, stat) \
36618- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
36619+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
36620
36621 static int is_lan_addr(struct ipmi_addr *addr)
36622 {
36623@@ -2883,7 +2883,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
36624 INIT_LIST_HEAD(&intf->cmd_rcvrs);
36625 init_waitqueue_head(&intf->waitq);
36626 for (i = 0; i < IPMI_NUM_STATS; i++)
36627- atomic_set(&intf->stats[i], 0);
36628+ atomic_set_unchecked(&intf->stats[i], 0);
36629
36630 intf->proc_dir = NULL;
36631
36632diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
36633index af4b23f..79806fc 100644
36634--- a/drivers/char/ipmi/ipmi_si_intf.c
36635+++ b/drivers/char/ipmi/ipmi_si_intf.c
36636@@ -275,7 +275,7 @@ struct smi_info {
36637 unsigned char slave_addr;
36638
36639 /* Counters and things for the proc filesystem. */
36640- atomic_t stats[SI_NUM_STATS];
36641+ atomic_unchecked_t stats[SI_NUM_STATS];
36642
36643 struct task_struct *thread;
36644
36645@@ -284,9 +284,9 @@ struct smi_info {
36646 };
36647
36648 #define smi_inc_stat(smi, stat) \
36649- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
36650+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
36651 #define smi_get_stat(smi, stat) \
36652- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
36653+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
36654
36655 #define SI_MAX_PARMS 4
36656
36657@@ -3258,7 +3258,7 @@ static int try_smi_init(struct smi_info *new_smi)
36658 atomic_set(&new_smi->req_events, 0);
36659 new_smi->run_to_completion = 0;
36660 for (i = 0; i < SI_NUM_STATS; i++)
36661- atomic_set(&new_smi->stats[i], 0);
36662+ atomic_set_unchecked(&new_smi->stats[i], 0);
36663
36664 new_smi->interrupt_disabled = 1;
36665 atomic_set(&new_smi->stop_operation, 0);
36666diff --git a/drivers/char/mem.c b/drivers/char/mem.c
36667index f895a8c..2bc9147 100644
36668--- a/drivers/char/mem.c
36669+++ b/drivers/char/mem.c
36670@@ -18,6 +18,7 @@
36671 #include <linux/raw.h>
36672 #include <linux/tty.h>
36673 #include <linux/capability.h>
36674+#include <linux/security.h>
36675 #include <linux/ptrace.h>
36676 #include <linux/device.h>
36677 #include <linux/highmem.h>
36678@@ -37,6 +38,10 @@
36679
36680 #define DEVPORT_MINOR 4
36681
36682+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
36683+extern const struct file_operations grsec_fops;
36684+#endif
36685+
36686 static inline unsigned long size_inside_page(unsigned long start,
36687 unsigned long size)
36688 {
36689@@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36690
36691 while (cursor < to) {
36692 if (!devmem_is_allowed(pfn)) {
36693+#ifdef CONFIG_GRKERNSEC_KMEM
36694+ gr_handle_mem_readwrite(from, to);
36695+#else
36696 printk(KERN_INFO
36697 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
36698 current->comm, from, to);
36699+#endif
36700 return 0;
36701 }
36702 cursor += PAGE_SIZE;
36703@@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36704 }
36705 return 1;
36706 }
36707+#elif defined(CONFIG_GRKERNSEC_KMEM)
36708+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36709+{
36710+ return 0;
36711+}
36712 #else
36713 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36714 {
36715@@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
36716
36717 while (count > 0) {
36718 unsigned long remaining;
36719+ char *temp;
36720
36721 sz = size_inside_page(p, count);
36722
36723@@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
36724 if (!ptr)
36725 return -EFAULT;
36726
36727- remaining = copy_to_user(buf, ptr, sz);
36728+#ifdef CONFIG_PAX_USERCOPY
36729+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
36730+ if (!temp) {
36731+ unxlate_dev_mem_ptr(p, ptr);
36732+ return -ENOMEM;
36733+ }
36734+ memcpy(temp, ptr, sz);
36735+#else
36736+ temp = ptr;
36737+#endif
36738+
36739+ remaining = copy_to_user(buf, temp, sz);
36740+
36741+#ifdef CONFIG_PAX_USERCOPY
36742+ kfree(temp);
36743+#endif
36744+
36745 unxlate_dev_mem_ptr(p, ptr);
36746 if (remaining)
36747 return -EFAULT;
36748@@ -364,9 +395,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
36749 size_t count, loff_t *ppos)
36750 {
36751 unsigned long p = *ppos;
36752- ssize_t low_count, read, sz;
36753+ ssize_t low_count, read, sz, err = 0;
36754 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
36755- int err = 0;
36756
36757 read = 0;
36758 if (p < (unsigned long) high_memory) {
36759@@ -388,6 +418,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
36760 }
36761 #endif
36762 while (low_count > 0) {
36763+ char *temp;
36764+
36765 sz = size_inside_page(p, low_count);
36766
36767 /*
36768@@ -397,7 +429,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
36769 */
36770 kbuf = xlate_dev_kmem_ptr((char *)p);
36771
36772- if (copy_to_user(buf, kbuf, sz))
36773+#ifdef CONFIG_PAX_USERCOPY
36774+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
36775+ if (!temp)
36776+ return -ENOMEM;
36777+ memcpy(temp, kbuf, sz);
36778+#else
36779+ temp = kbuf;
36780+#endif
36781+
36782+ err = copy_to_user(buf, temp, sz);
36783+
36784+#ifdef CONFIG_PAX_USERCOPY
36785+ kfree(temp);
36786+#endif
36787+
36788+ if (err)
36789 return -EFAULT;
36790 buf += sz;
36791 p += sz;
36792@@ -822,6 +869,9 @@ static const struct memdev {
36793 #ifdef CONFIG_PRINTK
36794 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
36795 #endif
36796+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
36797+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
36798+#endif
36799 };
36800
36801 static int memory_open(struct inode *inode, struct file *filp)
36802@@ -893,7 +943,7 @@ static int __init chr_dev_init(void)
36803 continue;
36804
36805 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
36806- NULL, devlist[minor].name);
36807+ NULL, "%s", devlist[minor].name);
36808 }
36809
36810 return tty_init();
36811diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
36812index 9df78e2..01ba9ae 100644
36813--- a/drivers/char/nvram.c
36814+++ b/drivers/char/nvram.c
36815@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
36816
36817 spin_unlock_irq(&rtc_lock);
36818
36819- if (copy_to_user(buf, contents, tmp - contents))
36820+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
36821 return -EFAULT;
36822
36823 *ppos = i;
36824diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
36825index 5c5cc00..ac9edb7 100644
36826--- a/drivers/char/pcmcia/synclink_cs.c
36827+++ b/drivers/char/pcmcia/synclink_cs.c
36828@@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
36829
36830 if (debug_level >= DEBUG_LEVEL_INFO)
36831 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
36832- __FILE__, __LINE__, info->device_name, port->count);
36833+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
36834
36835- WARN_ON(!port->count);
36836+ WARN_ON(!atomic_read(&port->count));
36837
36838 if (tty_port_close_start(port, tty, filp) == 0)
36839 goto cleanup;
36840@@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
36841 cleanup:
36842 if (debug_level >= DEBUG_LEVEL_INFO)
36843 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
36844- tty->driver->name, port->count);
36845+ tty->driver->name, atomic_read(&port->count));
36846 }
36847
36848 /* Wait until the transmitter is empty.
36849@@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
36850
36851 if (debug_level >= DEBUG_LEVEL_INFO)
36852 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
36853- __FILE__, __LINE__, tty->driver->name, port->count);
36854+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
36855
36856 /* If port is closing, signal caller to try again */
36857 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
36858@@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
36859 goto cleanup;
36860 }
36861 spin_lock(&port->lock);
36862- port->count++;
36863+ atomic_inc(&port->count);
36864 spin_unlock(&port->lock);
36865 spin_unlock_irqrestore(&info->netlock, flags);
36866
36867- if (port->count == 1) {
36868+ if (atomic_read(&port->count) == 1) {
36869 /* 1st open on this device, init hardware */
36870 retval = startup(info, tty);
36871 if (retval < 0)
36872@@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
36873 unsigned short new_crctype;
36874
36875 /* return error if TTY interface open */
36876- if (info->port.count)
36877+ if (atomic_read(&info->port.count))
36878 return -EBUSY;
36879
36880 switch (encoding)
36881@@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
36882
36883 /* arbitrate between network and tty opens */
36884 spin_lock_irqsave(&info->netlock, flags);
36885- if (info->port.count != 0 || info->netcount != 0) {
36886+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
36887 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
36888 spin_unlock_irqrestore(&info->netlock, flags);
36889 return -EBUSY;
36890@@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
36891 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
36892
36893 /* return error if TTY interface open */
36894- if (info->port.count)
36895+ if (atomic_read(&info->port.count))
36896 return -EBUSY;
36897
36898 if (cmd != SIOCWANDEV)
36899diff --git a/drivers/char/random.c b/drivers/char/random.c
36900index 92e6c67..c640ec3 100644
36901--- a/drivers/char/random.c
36902+++ b/drivers/char/random.c
36903@@ -272,8 +272,13 @@
36904 /*
36905 * Configuration information
36906 */
36907+#ifdef CONFIG_GRKERNSEC_RANDNET
36908+#define INPUT_POOL_WORDS 512
36909+#define OUTPUT_POOL_WORDS 128
36910+#else
36911 #define INPUT_POOL_WORDS 128
36912 #define OUTPUT_POOL_WORDS 32
36913+#endif
36914 #define SEC_XFER_SIZE 512
36915 #define EXTRACT_SIZE 10
36916
36917@@ -313,10 +318,17 @@ static struct poolinfo {
36918 int poolwords;
36919 int tap1, tap2, tap3, tap4, tap5;
36920 } poolinfo_table[] = {
36921+#ifdef CONFIG_GRKERNSEC_RANDNET
36922+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
36923+ { 512, 411, 308, 208, 104, 1 },
36924+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
36925+ { 128, 103, 76, 51, 25, 1 },
36926+#else
36927 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
36928 { 128, 103, 76, 51, 25, 1 },
36929 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
36930 { 32, 26, 20, 14, 7, 1 },
36931+#endif
36932 #if 0
36933 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
36934 { 2048, 1638, 1231, 819, 411, 1 },
36935@@ -524,8 +536,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
36936 input_rotate += i ? 7 : 14;
36937 }
36938
36939- ACCESS_ONCE(r->input_rotate) = input_rotate;
36940- ACCESS_ONCE(r->add_ptr) = i;
36941+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
36942+ ACCESS_ONCE_RW(r->add_ptr) = i;
36943 smp_wmb();
36944
36945 if (out)
36946@@ -1032,7 +1044,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
36947
36948 extract_buf(r, tmp);
36949 i = min_t(int, nbytes, EXTRACT_SIZE);
36950- if (copy_to_user(buf, tmp, i)) {
36951+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
36952 ret = -EFAULT;
36953 break;
36954 }
36955@@ -1368,7 +1380,7 @@ EXPORT_SYMBOL(generate_random_uuid);
36956 #include <linux/sysctl.h>
36957
36958 static int min_read_thresh = 8, min_write_thresh;
36959-static int max_read_thresh = INPUT_POOL_WORDS * 32;
36960+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
36961 static int max_write_thresh = INPUT_POOL_WORDS * 32;
36962 static char sysctl_bootid[16];
36963
36964@@ -1384,7 +1396,7 @@ static char sysctl_bootid[16];
36965 static int proc_do_uuid(struct ctl_table *table, int write,
36966 void __user *buffer, size_t *lenp, loff_t *ppos)
36967 {
36968- struct ctl_table fake_table;
36969+ ctl_table_no_const fake_table;
36970 unsigned char buf[64], tmp_uuid[16], *uuid;
36971
36972 uuid = table->data;
36973diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
36974index bf2349db..5456d53 100644
36975--- a/drivers/char/sonypi.c
36976+++ b/drivers/char/sonypi.c
36977@@ -54,6 +54,7 @@
36978
36979 #include <asm/uaccess.h>
36980 #include <asm/io.h>
36981+#include <asm/local.h>
36982
36983 #include <linux/sonypi.h>
36984
36985@@ -490,7 +491,7 @@ static struct sonypi_device {
36986 spinlock_t fifo_lock;
36987 wait_queue_head_t fifo_proc_list;
36988 struct fasync_struct *fifo_async;
36989- int open_count;
36990+ local_t open_count;
36991 int model;
36992 struct input_dev *input_jog_dev;
36993 struct input_dev *input_key_dev;
36994@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
36995 static int sonypi_misc_release(struct inode *inode, struct file *file)
36996 {
36997 mutex_lock(&sonypi_device.lock);
36998- sonypi_device.open_count--;
36999+ local_dec(&sonypi_device.open_count);
37000 mutex_unlock(&sonypi_device.lock);
37001 return 0;
37002 }
37003@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
37004 {
37005 mutex_lock(&sonypi_device.lock);
37006 /* Flush input queue on first open */
37007- if (!sonypi_device.open_count)
37008+ if (!local_read(&sonypi_device.open_count))
37009 kfifo_reset(&sonypi_device.fifo);
37010- sonypi_device.open_count++;
37011+ local_inc(&sonypi_device.open_count);
37012 mutex_unlock(&sonypi_device.lock);
37013
37014 return 0;
37015diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
37016index 64420b3..5c40b56 100644
37017--- a/drivers/char/tpm/tpm_acpi.c
37018+++ b/drivers/char/tpm/tpm_acpi.c
37019@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
37020 virt = acpi_os_map_memory(start, len);
37021 if (!virt) {
37022 kfree(log->bios_event_log);
37023+ log->bios_event_log = NULL;
37024 printk("%s: ERROR - Unable to map memory\n", __func__);
37025 return -EIO;
37026 }
37027
37028- memcpy_fromio(log->bios_event_log, virt, len);
37029+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
37030
37031 acpi_os_unmap_memory(virt, len);
37032 return 0;
37033diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
37034index 84ddc55..1d32f1e 100644
37035--- a/drivers/char/tpm/tpm_eventlog.c
37036+++ b/drivers/char/tpm/tpm_eventlog.c
37037@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
37038 event = addr;
37039
37040 if ((event->event_type == 0 && event->event_size == 0) ||
37041- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
37042+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
37043 return NULL;
37044
37045 return addr;
37046@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
37047 return NULL;
37048
37049 if ((event->event_type == 0 && event->event_size == 0) ||
37050- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
37051+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
37052 return NULL;
37053
37054 (*pos)++;
37055@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
37056 int i;
37057
37058 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
37059- seq_putc(m, data[i]);
37060+ if (!seq_putc(m, data[i]))
37061+ return -EFAULT;
37062
37063 return 0;
37064 }
37065diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
37066index fc45567..fa2a590 100644
37067--- a/drivers/char/virtio_console.c
37068+++ b/drivers/char/virtio_console.c
37069@@ -682,7 +682,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
37070 if (to_user) {
37071 ssize_t ret;
37072
37073- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
37074+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
37075 if (ret)
37076 return -EFAULT;
37077 } else {
37078@@ -785,7 +785,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
37079 if (!port_has_data(port) && !port->host_connected)
37080 return 0;
37081
37082- return fill_readbuf(port, ubuf, count, true);
37083+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
37084 }
37085
37086 static int wait_port_writable(struct port *port, bool nonblock)
37087diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
37088index a33f46f..a720eed 100644
37089--- a/drivers/clk/clk-composite.c
37090+++ b/drivers/clk/clk-composite.c
37091@@ -122,7 +122,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
37092 struct clk *clk;
37093 struct clk_init_data init;
37094 struct clk_composite *composite;
37095- struct clk_ops *clk_composite_ops;
37096+ clk_ops_no_const *clk_composite_ops;
37097
37098 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
37099 if (!composite) {
37100diff --git a/drivers/clk/socfpga/clk.c b/drivers/clk/socfpga/clk.c
37101index 5bb848c..f1d4fc9 100644
37102--- a/drivers/clk/socfpga/clk.c
37103+++ b/drivers/clk/socfpga/clk.c
37104@@ -22,6 +22,7 @@
37105 #include <linux/clk-provider.h>
37106 #include <linux/io.h>
37107 #include <linux/of.h>
37108+#include <asm/pgtable.h>
37109
37110 /* Clock Manager offsets */
37111 #define CLKMGR_CTRL 0x0
37112@@ -152,8 +153,10 @@ static __init struct clk *socfpga_clk_init(struct device_node *node,
37113 streq(clk_name, "periph_pll") ||
37114 streq(clk_name, "sdram_pll")) {
37115 socfpga_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
37116- clk_pll_ops.enable = clk_gate_ops.enable;
37117- clk_pll_ops.disable = clk_gate_ops.disable;
37118+ pax_open_kernel();
37119+ *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
37120+ *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
37121+ pax_close_kernel();
37122 }
37123
37124 clk = clk_register(NULL, &socfpga_clk->hw.hw);
37125@@ -244,7 +247,7 @@ static unsigned long socfpga_clk_recalc_rate(struct clk_hw *hwclk,
37126 return parent_rate / div;
37127 }
37128
37129-static struct clk_ops gateclk_ops = {
37130+static clk_ops_no_const gateclk_ops __read_only = {
37131 .recalc_rate = socfpga_clk_recalc_rate,
37132 .get_parent = socfpga_clk_get_parent,
37133 .set_parent = socfpga_clk_set_parent,
37134diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
37135index 3926402..37b580d 100644
37136--- a/drivers/cpufreq/acpi-cpufreq.c
37137+++ b/drivers/cpufreq/acpi-cpufreq.c
37138@@ -173,7 +173,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
37139 return sprintf(buf, "%u\n", boost_enabled);
37140 }
37141
37142-static struct global_attr global_boost = __ATTR(boost, 0644,
37143+static global_attr_no_const global_boost = __ATTR(boost, 0644,
37144 show_global_boost,
37145 store_global_boost);
37146
37147@@ -722,8 +722,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
37148 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
37149 per_cpu(acfreq_data, cpu) = data;
37150
37151- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
37152- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
37153+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
37154+ pax_open_kernel();
37155+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
37156+ pax_close_kernel();
37157+ }
37158
37159 result = acpi_processor_register_performance(data->acpi_data, cpu);
37160 if (result)
37161@@ -851,7 +854,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
37162 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
37163 break;
37164 case ACPI_ADR_SPACE_FIXED_HARDWARE:
37165- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
37166+ pax_open_kernel();
37167+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
37168+ pax_close_kernel();
37169 policy->cur = get_cur_freq_on_cpu(cpu);
37170 break;
37171 default:
37172@@ -862,8 +867,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
37173 acpi_processor_notify_smm(THIS_MODULE);
37174
37175 /* Check for APERF/MPERF support in hardware */
37176- if (boot_cpu_has(X86_FEATURE_APERFMPERF))
37177- acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
37178+ if (boot_cpu_has(X86_FEATURE_APERFMPERF)) {
37179+ pax_open_kernel();
37180+ *(void **)&acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
37181+ pax_close_kernel();
37182+ }
37183
37184 pr_debug("CPU%u - ACPI performance management activated.\n", cpu);
37185 for (i = 0; i < perf->state_count; i++)
37186diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
37187index f0a5e2b..0a7ee46 100644
37188--- a/drivers/cpufreq/cpufreq.c
37189+++ b/drivers/cpufreq/cpufreq.c
37190@@ -1959,7 +1959,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
37191 return NOTIFY_OK;
37192 }
37193
37194-static struct notifier_block __refdata cpufreq_cpu_notifier = {
37195+static struct notifier_block cpufreq_cpu_notifier = {
37196 .notifier_call = cpufreq_cpu_callback,
37197 };
37198
37199@@ -1991,8 +1991,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
37200
37201 pr_debug("trying to register driver %s\n", driver_data->name);
37202
37203- if (driver_data->setpolicy)
37204- driver_data->flags |= CPUFREQ_CONST_LOOPS;
37205+ if (driver_data->setpolicy) {
37206+ pax_open_kernel();
37207+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
37208+ pax_close_kernel();
37209+ }
37210
37211 write_lock_irqsave(&cpufreq_driver_lock, flags);
37212 if (cpufreq_driver) {
37213diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
37214index e59afaa..a53a3ff 100644
37215--- a/drivers/cpufreq/cpufreq_governor.c
37216+++ b/drivers/cpufreq/cpufreq_governor.c
37217@@ -191,7 +191,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
37218 struct dbs_data *dbs_data;
37219 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
37220 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
37221- struct od_ops *od_ops = NULL;
37222+ const struct od_ops *od_ops = NULL;
37223 struct od_dbs_tuners *od_tuners = NULL;
37224 struct cs_dbs_tuners *cs_tuners = NULL;
37225 struct cpu_dbs_common_info *cpu_cdbs;
37226@@ -257,7 +257,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
37227
37228 if ((cdata->governor == GOV_CONSERVATIVE) &&
37229 (!policy->governor->initialized)) {
37230- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37231+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37232
37233 cpufreq_register_notifier(cs_ops->notifier_block,
37234 CPUFREQ_TRANSITION_NOTIFIER);
37235@@ -277,7 +277,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
37236
37237 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
37238 (policy->governor->initialized == 1)) {
37239- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37240+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37241
37242 cpufreq_unregister_notifier(cs_ops->notifier_block,
37243 CPUFREQ_TRANSITION_NOTIFIER);
37244diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
37245index d5f12b4..eb30af1 100644
37246--- a/drivers/cpufreq/cpufreq_governor.h
37247+++ b/drivers/cpufreq/cpufreq_governor.h
37248@@ -204,7 +204,7 @@ struct common_dbs_data {
37249 void (*exit)(struct dbs_data *dbs_data);
37250
37251 /* Governor specific ops, see below */
37252- void *gov_ops;
37253+ const void *gov_ops;
37254 };
37255
37256 /* Governer Per policy data */
37257@@ -224,7 +224,7 @@ struct od_ops {
37258 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
37259 unsigned int freq_next, unsigned int relation);
37260 void (*freq_increase)(struct cpufreq_policy *p, unsigned int freq);
37261-};
37262+} __no_const;
37263
37264 struct cs_ops {
37265 struct notifier_block *notifier_block;
37266diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
37267index c087347..989aa2e 100644
37268--- a/drivers/cpufreq/cpufreq_ondemand.c
37269+++ b/drivers/cpufreq/cpufreq_ondemand.c
37270@@ -560,7 +560,7 @@ static void od_exit(struct dbs_data *dbs_data)
37271
37272 define_get_cpu_dbs_routines(od_cpu_dbs_info);
37273
37274-static struct od_ops od_ops = {
37275+static struct od_ops od_ops __read_only = {
37276 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
37277 .powersave_bias_target = generic_powersave_bias_target,
37278 .freq_increase = dbs_freq_increase,
37279@@ -615,14 +615,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
37280 (struct cpufreq_policy *, unsigned int, unsigned int),
37281 unsigned int powersave_bias)
37282 {
37283- od_ops.powersave_bias_target = f;
37284+ pax_open_kernel();
37285+ *(void **)&od_ops.powersave_bias_target = f;
37286+ pax_close_kernel();
37287 od_set_powersave_bias(powersave_bias);
37288 }
37289 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
37290
37291 void od_unregister_powersave_bias_handler(void)
37292 {
37293- od_ops.powersave_bias_target = generic_powersave_bias_target;
37294+ pax_open_kernel();
37295+ *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
37296+ pax_close_kernel();
37297 od_set_powersave_bias(0);
37298 }
37299 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
37300diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
37301index d37568c..fbb19a1 100644
37302--- a/drivers/cpufreq/cpufreq_stats.c
37303+++ b/drivers/cpufreq/cpufreq_stats.c
37304@@ -365,7 +365,7 @@ static int cpufreq_stat_cpu_callback(struct notifier_block *nfb,
37305 }
37306
37307 /* priority=1 so this will get called before cpufreq_remove_dev */
37308-static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
37309+static struct notifier_block cpufreq_stat_cpu_notifier = {
37310 .notifier_call = cpufreq_stat_cpu_callback,
37311 .priority = 1,
37312 };
37313diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
37314index 9ee7817..17b658e 100644
37315--- a/drivers/cpufreq/p4-clockmod.c
37316+++ b/drivers/cpufreq/p4-clockmod.c
37317@@ -160,10 +160,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
37318 case 0x0F: /* Core Duo */
37319 case 0x16: /* Celeron Core */
37320 case 0x1C: /* Atom */
37321- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37322+ pax_open_kernel();
37323+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37324+ pax_close_kernel();
37325 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
37326 case 0x0D: /* Pentium M (Dothan) */
37327- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37328+ pax_open_kernel();
37329+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37330+ pax_close_kernel();
37331 /* fall through */
37332 case 0x09: /* Pentium M (Banias) */
37333 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
37334@@ -175,7 +179,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
37335
37336 /* on P-4s, the TSC runs with constant frequency independent whether
37337 * throttling is active or not. */
37338- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37339+ pax_open_kernel();
37340+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37341+ pax_close_kernel();
37342
37343 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
37344 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
37345diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
37346index 880ee29..2445bc6 100644
37347--- a/drivers/cpufreq/sparc-us3-cpufreq.c
37348+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
37349@@ -18,14 +18,12 @@
37350 #include <asm/head.h>
37351 #include <asm/timer.h>
37352
37353-static struct cpufreq_driver *cpufreq_us3_driver;
37354-
37355 struct us3_freq_percpu_info {
37356 struct cpufreq_frequency_table table[4];
37357 };
37358
37359 /* Indexed by cpu number. */
37360-static struct us3_freq_percpu_info *us3_freq_table;
37361+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
37362
37363 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
37364 * in the Safari config register.
37365@@ -186,12 +184,25 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
37366
37367 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
37368 {
37369- if (cpufreq_us3_driver)
37370- us3_set_cpu_divider_index(policy, 0);
37371+ us3_set_cpu_divider_index(policy->cpu, 0);
37372
37373 return 0;
37374 }
37375
37376+static int __init us3_freq_init(void);
37377+static void __exit us3_freq_exit(void);
37378+
37379+static struct cpufreq_driver cpufreq_us3_driver = {
37380+ .init = us3_freq_cpu_init,
37381+ .verify = us3_freq_verify,
37382+ .target = us3_freq_target,
37383+ .get = us3_freq_get,
37384+ .exit = us3_freq_cpu_exit,
37385+ .owner = THIS_MODULE,
37386+ .name = "UltraSPARC-III",
37387+
37388+};
37389+
37390 static int __init us3_freq_init(void)
37391 {
37392 unsigned long manuf, impl, ver;
37393@@ -208,57 +219,15 @@ static int __init us3_freq_init(void)
37394 (impl == CHEETAH_IMPL ||
37395 impl == CHEETAH_PLUS_IMPL ||
37396 impl == JAGUAR_IMPL ||
37397- impl == PANTHER_IMPL)) {
37398- struct cpufreq_driver *driver;
37399-
37400- ret = -ENOMEM;
37401- driver = kzalloc(sizeof(struct cpufreq_driver), GFP_KERNEL);
37402- if (!driver)
37403- goto err_out;
37404-
37405- us3_freq_table = kzalloc(
37406- (NR_CPUS * sizeof(struct us3_freq_percpu_info)),
37407- GFP_KERNEL);
37408- if (!us3_freq_table)
37409- goto err_out;
37410-
37411- driver->init = us3_freq_cpu_init;
37412- driver->verify = us3_freq_verify;
37413- driver->target = us3_freq_target;
37414- driver->get = us3_freq_get;
37415- driver->exit = us3_freq_cpu_exit;
37416- driver->owner = THIS_MODULE,
37417- strcpy(driver->name, "UltraSPARC-III");
37418-
37419- cpufreq_us3_driver = driver;
37420- ret = cpufreq_register_driver(driver);
37421- if (ret)
37422- goto err_out;
37423-
37424- return 0;
37425-
37426-err_out:
37427- if (driver) {
37428- kfree(driver);
37429- cpufreq_us3_driver = NULL;
37430- }
37431- kfree(us3_freq_table);
37432- us3_freq_table = NULL;
37433- return ret;
37434- }
37435+ impl == PANTHER_IMPL))
37436+ return cpufreq_register_driver(&cpufreq_us3_driver);
37437
37438 return -ENODEV;
37439 }
37440
37441 static void __exit us3_freq_exit(void)
37442 {
37443- if (cpufreq_us3_driver) {
37444- cpufreq_unregister_driver(cpufreq_us3_driver);
37445- kfree(cpufreq_us3_driver);
37446- cpufreq_us3_driver = NULL;
37447- kfree(us3_freq_table);
37448- us3_freq_table = NULL;
37449- }
37450+ cpufreq_unregister_driver(&cpufreq_us3_driver);
37451 }
37452
37453 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
37454diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
37455index 0915e71..53376ed 100644
37456--- a/drivers/cpufreq/speedstep-centrino.c
37457+++ b/drivers/cpufreq/speedstep-centrino.c
37458@@ -353,8 +353,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
37459 !cpu_has(cpu, X86_FEATURE_EST))
37460 return -ENODEV;
37461
37462- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
37463- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
37464+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
37465+ pax_open_kernel();
37466+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
37467+ pax_close_kernel();
37468+ }
37469
37470 if (policy->cpu != 0)
37471 return -ENODEV;
37472diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
37473index fdc432f..98e64e2 100644
37474--- a/drivers/cpuidle/cpuidle.c
37475+++ b/drivers/cpuidle/cpuidle.c
37476@@ -254,7 +254,7 @@ static int poll_idle(struct cpuidle_device *dev,
37477
37478 static void poll_idle_init(struct cpuidle_driver *drv)
37479 {
37480- struct cpuidle_state *state = &drv->states[0];
37481+ cpuidle_state_no_const *state = &drv->states[0];
37482
37483 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
37484 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
37485diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
37486index ea2f8e7..70ac501 100644
37487--- a/drivers/cpuidle/governor.c
37488+++ b/drivers/cpuidle/governor.c
37489@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
37490 mutex_lock(&cpuidle_lock);
37491 if (__cpuidle_find_governor(gov->name) == NULL) {
37492 ret = 0;
37493- list_add_tail(&gov->governor_list, &cpuidle_governors);
37494+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
37495 if (!cpuidle_curr_governor ||
37496 cpuidle_curr_governor->rating < gov->rating)
37497 cpuidle_switch_governor(gov);
37498@@ -135,7 +135,7 @@ void cpuidle_unregister_governor(struct cpuidle_governor *gov)
37499 new_gov = cpuidle_replace_governor(gov->rating);
37500 cpuidle_switch_governor(new_gov);
37501 }
37502- list_del(&gov->governor_list);
37503+ pax_list_del((struct list_head *)&gov->governor_list);
37504 mutex_unlock(&cpuidle_lock);
37505 }
37506
37507diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
37508index 428754a..8bdf9cc 100644
37509--- a/drivers/cpuidle/sysfs.c
37510+++ b/drivers/cpuidle/sysfs.c
37511@@ -131,7 +131,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
37512 NULL
37513 };
37514
37515-static struct attribute_group cpuidle_attr_group = {
37516+static attribute_group_no_const cpuidle_attr_group = {
37517 .attrs = cpuidle_default_attrs,
37518 .name = "cpuidle",
37519 };
37520diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
37521index 12fea3e..1e28f47 100644
37522--- a/drivers/crypto/hifn_795x.c
37523+++ b/drivers/crypto/hifn_795x.c
37524@@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
37525 MODULE_PARM_DESC(hifn_pll_ref,
37526 "PLL reference clock (pci[freq] or ext[freq], default ext)");
37527
37528-static atomic_t hifn_dev_number;
37529+static atomic_unchecked_t hifn_dev_number;
37530
37531 #define ACRYPTO_OP_DECRYPT 0
37532 #define ACRYPTO_OP_ENCRYPT 1
37533@@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
37534 goto err_out_disable_pci_device;
37535
37536 snprintf(name, sizeof(name), "hifn%d",
37537- atomic_inc_return(&hifn_dev_number)-1);
37538+ atomic_inc_return_unchecked(&hifn_dev_number)-1);
37539
37540 err = pci_request_regions(pdev, name);
37541 if (err)
37542diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
37543index e94e619..f7e249c 100644
37544--- a/drivers/devfreq/devfreq.c
37545+++ b/drivers/devfreq/devfreq.c
37546@@ -607,7 +607,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
37547 goto err_out;
37548 }
37549
37550- list_add(&governor->node, &devfreq_governor_list);
37551+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
37552
37553 list_for_each_entry(devfreq, &devfreq_list, node) {
37554 int ret = 0;
37555@@ -695,7 +695,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
37556 }
37557 }
37558
37559- list_del(&governor->node);
37560+ pax_list_del((struct list_head *)&governor->node);
37561 err_out:
37562 mutex_unlock(&devfreq_list_lock);
37563
37564diff --git a/drivers/dma/sh/shdma.c b/drivers/dma/sh/shdma.c
37565index 5039fbc..841169f 100644
37566--- a/drivers/dma/sh/shdma.c
37567+++ b/drivers/dma/sh/shdma.c
37568@@ -488,7 +488,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
37569 return ret;
37570 }
37571
37572-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
37573+static struct notifier_block sh_dmae_nmi_notifier = {
37574 .notifier_call = sh_dmae_nmi_handler,
37575
37576 /* Run before NMI debug handler and KGDB */
37577diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
37578index 211021d..201d47f 100644
37579--- a/drivers/edac/edac_device.c
37580+++ b/drivers/edac/edac_device.c
37581@@ -474,9 +474,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
37582 */
37583 int edac_device_alloc_index(void)
37584 {
37585- static atomic_t device_indexes = ATOMIC_INIT(0);
37586+ static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
37587
37588- return atomic_inc_return(&device_indexes) - 1;
37589+ return atomic_inc_return_unchecked(&device_indexes) - 1;
37590 }
37591 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
37592
37593diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
37594index e7c32c4..6397af1 100644
37595--- a/drivers/edac/edac_mc_sysfs.c
37596+++ b/drivers/edac/edac_mc_sysfs.c
37597@@ -148,7 +148,7 @@ static const char * const edac_caps[] = {
37598 struct dev_ch_attribute {
37599 struct device_attribute attr;
37600 int channel;
37601-};
37602+} __do_const;
37603
37604 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
37605 struct dev_ch_attribute dev_attr_legacy_##_name = \
37606@@ -1005,14 +1005,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
37607 }
37608
37609 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
37610+ pax_open_kernel();
37611 if (mci->get_sdram_scrub_rate) {
37612- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
37613- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
37614+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
37615+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
37616 }
37617 if (mci->set_sdram_scrub_rate) {
37618- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
37619- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
37620+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
37621+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
37622 }
37623+ pax_close_kernel();
37624 err = device_create_file(&mci->dev,
37625 &dev_attr_sdram_scrub_rate);
37626 if (err) {
37627diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
37628index dd370f9..0281629 100644
37629--- a/drivers/edac/edac_pci.c
37630+++ b/drivers/edac/edac_pci.c
37631@@ -29,7 +29,7 @@
37632
37633 static DEFINE_MUTEX(edac_pci_ctls_mutex);
37634 static LIST_HEAD(edac_pci_list);
37635-static atomic_t pci_indexes = ATOMIC_INIT(0);
37636+static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
37637
37638 /*
37639 * edac_pci_alloc_ctl_info
37640@@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
37641 */
37642 int edac_pci_alloc_index(void)
37643 {
37644- return atomic_inc_return(&pci_indexes) - 1;
37645+ return atomic_inc_return_unchecked(&pci_indexes) - 1;
37646 }
37647 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
37648
37649diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
37650index e8658e4..22746d6 100644
37651--- a/drivers/edac/edac_pci_sysfs.c
37652+++ b/drivers/edac/edac_pci_sysfs.c
37653@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
37654 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
37655 static int edac_pci_poll_msec = 1000; /* one second workq period */
37656
37657-static atomic_t pci_parity_count = ATOMIC_INIT(0);
37658-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
37659+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
37660+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
37661
37662 static struct kobject *edac_pci_top_main_kobj;
37663 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
37664@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
37665 void *value;
37666 ssize_t(*show) (void *, char *);
37667 ssize_t(*store) (void *, const char *, size_t);
37668-};
37669+} __do_const;
37670
37671 /* Set of show/store abstract level functions for PCI Parity object */
37672 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
37673@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37674 edac_printk(KERN_CRIT, EDAC_PCI,
37675 "Signaled System Error on %s\n",
37676 pci_name(dev));
37677- atomic_inc(&pci_nonparity_count);
37678+ atomic_inc_unchecked(&pci_nonparity_count);
37679 }
37680
37681 if (status & (PCI_STATUS_PARITY)) {
37682@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37683 "Master Data Parity Error on %s\n",
37684 pci_name(dev));
37685
37686- atomic_inc(&pci_parity_count);
37687+ atomic_inc_unchecked(&pci_parity_count);
37688 }
37689
37690 if (status & (PCI_STATUS_DETECTED_PARITY)) {
37691@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37692 "Detected Parity Error on %s\n",
37693 pci_name(dev));
37694
37695- atomic_inc(&pci_parity_count);
37696+ atomic_inc_unchecked(&pci_parity_count);
37697 }
37698 }
37699
37700@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37701 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
37702 "Signaled System Error on %s\n",
37703 pci_name(dev));
37704- atomic_inc(&pci_nonparity_count);
37705+ atomic_inc_unchecked(&pci_nonparity_count);
37706 }
37707
37708 if (status & (PCI_STATUS_PARITY)) {
37709@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37710 "Master Data Parity Error on "
37711 "%s\n", pci_name(dev));
37712
37713- atomic_inc(&pci_parity_count);
37714+ atomic_inc_unchecked(&pci_parity_count);
37715 }
37716
37717 if (status & (PCI_STATUS_DETECTED_PARITY)) {
37718@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37719 "Detected Parity Error on %s\n",
37720 pci_name(dev));
37721
37722- atomic_inc(&pci_parity_count);
37723+ atomic_inc_unchecked(&pci_parity_count);
37724 }
37725 }
37726 }
37727@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
37728 if (!check_pci_errors)
37729 return;
37730
37731- before_count = atomic_read(&pci_parity_count);
37732+ before_count = atomic_read_unchecked(&pci_parity_count);
37733
37734 /* scan all PCI devices looking for a Parity Error on devices and
37735 * bridges.
37736@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
37737 /* Only if operator has selected panic on PCI Error */
37738 if (edac_pci_get_panic_on_pe()) {
37739 /* If the count is different 'after' from 'before' */
37740- if (before_count != atomic_read(&pci_parity_count))
37741+ if (before_count != atomic_read_unchecked(&pci_parity_count))
37742 panic("EDAC: PCI Parity Error");
37743 }
37744 }
37745diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
37746index 51b7e3a..aa8a3e8 100644
37747--- a/drivers/edac/mce_amd.h
37748+++ b/drivers/edac/mce_amd.h
37749@@ -77,7 +77,7 @@ struct amd_decoder_ops {
37750 bool (*mc0_mce)(u16, u8);
37751 bool (*mc1_mce)(u16, u8);
37752 bool (*mc2_mce)(u16, u8);
37753-};
37754+} __no_const;
37755
37756 void amd_report_gart_errors(bool);
37757 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
37758diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
37759index 57ea7f4..af06b76 100644
37760--- a/drivers/firewire/core-card.c
37761+++ b/drivers/firewire/core-card.c
37762@@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
37763 const struct fw_card_driver *driver,
37764 struct device *device)
37765 {
37766- static atomic_t index = ATOMIC_INIT(-1);
37767+ static atomic_unchecked_t index = ATOMIC_INIT(-1);
37768
37769- card->index = atomic_inc_return(&index);
37770+ card->index = atomic_inc_return_unchecked(&index);
37771 card->driver = driver;
37772 card->device = device;
37773 card->current_tlabel = 0;
37774@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
37775
37776 void fw_core_remove_card(struct fw_card *card)
37777 {
37778- struct fw_card_driver dummy_driver = dummy_driver_template;
37779+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
37780
37781 card->driver->update_phy_reg(card, 4,
37782 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
37783diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
37784index de4aa40..49ab1f2 100644
37785--- a/drivers/firewire/core-device.c
37786+++ b/drivers/firewire/core-device.c
37787@@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
37788 struct config_rom_attribute {
37789 struct device_attribute attr;
37790 u32 key;
37791-};
37792+} __do_const;
37793
37794 static ssize_t show_immediate(struct device *dev,
37795 struct device_attribute *dattr, char *buf)
37796diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
37797index 28a94c7..58da63a 100644
37798--- a/drivers/firewire/core-transaction.c
37799+++ b/drivers/firewire/core-transaction.c
37800@@ -38,6 +38,7 @@
37801 #include <linux/timer.h>
37802 #include <linux/types.h>
37803 #include <linux/workqueue.h>
37804+#include <linux/sched.h>
37805
37806 #include <asm/byteorder.h>
37807
37808diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
37809index 515a42c..5ecf3ba 100644
37810--- a/drivers/firewire/core.h
37811+++ b/drivers/firewire/core.h
37812@@ -111,6 +111,7 @@ struct fw_card_driver {
37813
37814 int (*stop_iso)(struct fw_iso_context *ctx);
37815 };
37816+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
37817
37818 void fw_card_initialize(struct fw_card *card,
37819 const struct fw_card_driver *driver, struct device *device);
37820diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
37821index 94a58a0..f5eba42 100644
37822--- a/drivers/firmware/dmi-id.c
37823+++ b/drivers/firmware/dmi-id.c
37824@@ -16,7 +16,7 @@
37825 struct dmi_device_attribute{
37826 struct device_attribute dev_attr;
37827 int field;
37828-};
37829+} __do_const;
37830 #define to_dmi_dev_attr(_dev_attr) \
37831 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
37832
37833diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
37834index 232fa8f..386c255 100644
37835--- a/drivers/firmware/dmi_scan.c
37836+++ b/drivers/firmware/dmi_scan.c
37837@@ -504,11 +504,6 @@ void __init dmi_scan_machine(void)
37838 }
37839 }
37840 else {
37841- /*
37842- * no iounmap() for that ioremap(); it would be a no-op, but
37843- * it's so early in setup that sucker gets confused into doing
37844- * what it shouldn't if we actually call it.
37845- */
37846 p = dmi_ioremap(0xF0000, 0x10000);
37847 if (p == NULL)
37848 goto error;
37849@@ -806,7 +801,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
37850 if (buf == NULL)
37851 return -1;
37852
37853- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
37854+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
37855
37856 iounmap(buf);
37857 return 0;
37858diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
37859index 5145fa3..0d3babd 100644
37860--- a/drivers/firmware/efi/efi.c
37861+++ b/drivers/firmware/efi/efi.c
37862@@ -65,14 +65,16 @@ static struct attribute_group efi_subsys_attr_group = {
37863 };
37864
37865 static struct efivars generic_efivars;
37866-static struct efivar_operations generic_ops;
37867+static efivar_operations_no_const generic_ops __read_only;
37868
37869 static int generic_ops_register(void)
37870 {
37871- generic_ops.get_variable = efi.get_variable;
37872- generic_ops.set_variable = efi.set_variable;
37873- generic_ops.get_next_variable = efi.get_next_variable;
37874- generic_ops.query_variable_store = efi_query_variable_store;
37875+ pax_open_kernel();
37876+ *(void **)&generic_ops.get_variable = efi.get_variable;
37877+ *(void **)&generic_ops.set_variable = efi.set_variable;
37878+ *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
37879+ *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
37880+ pax_close_kernel();
37881
37882 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
37883 }
37884diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
37885index 8a7432a..28fb839 100644
37886--- a/drivers/firmware/efi/efivars.c
37887+++ b/drivers/firmware/efi/efivars.c
37888@@ -452,7 +452,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
37889 static int
37890 create_efivars_bin_attributes(void)
37891 {
37892- struct bin_attribute *attr;
37893+ bin_attribute_no_const *attr;
37894 int error;
37895
37896 /* new_var */
37897diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
37898index 2a90ba6..07f3733 100644
37899--- a/drivers/firmware/google/memconsole.c
37900+++ b/drivers/firmware/google/memconsole.c
37901@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
37902 if (!found_memconsole())
37903 return -ENODEV;
37904
37905- memconsole_bin_attr.size = memconsole_length;
37906+ pax_open_kernel();
37907+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
37908+ pax_close_kernel();
37909
37910 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
37911
37912diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
37913index 2729e3d..f9deca1 100644
37914--- a/drivers/gpio/gpio-ich.c
37915+++ b/drivers/gpio/gpio-ich.c
37916@@ -71,7 +71,7 @@ struct ichx_desc {
37917 /* Some chipsets have quirks, let these use their own request/get */
37918 int (*request)(struct gpio_chip *chip, unsigned offset);
37919 int (*get)(struct gpio_chip *chip, unsigned offset);
37920-};
37921+} __do_const;
37922
37923 static struct {
37924 spinlock_t lock;
37925diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
37926index 9902732..64b62dd 100644
37927--- a/drivers/gpio/gpio-vr41xx.c
37928+++ b/drivers/gpio/gpio-vr41xx.c
37929@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
37930 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
37931 maskl, pendl, maskh, pendh);
37932
37933- atomic_inc(&irq_err_count);
37934+ atomic_inc_unchecked(&irq_err_count);
37935
37936 return -EINVAL;
37937 }
37938diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
37939index 6a64749..0767a9f 100644
37940--- a/drivers/gpu/drm/drm_crtc_helper.c
37941+++ b/drivers/gpu/drm/drm_crtc_helper.c
37942@@ -322,7 +322,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
37943 struct drm_crtc *tmp;
37944 int crtc_mask = 1;
37945
37946- WARN(!crtc, "checking null crtc?\n");
37947+ BUG_ON(!crtc);
37948
37949 dev = crtc->dev;
37950
37951diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
37952index 99fcd7c..13cf6c5 100644
37953--- a/drivers/gpu/drm/drm_drv.c
37954+++ b/drivers/gpu/drm/drm_drv.c
37955@@ -307,7 +307,7 @@ module_exit(drm_core_exit);
37956 /**
37957 * Copy and IOCTL return string to user space
37958 */
37959-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
37960+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
37961 {
37962 int len;
37963
37964@@ -377,7 +377,7 @@ long drm_ioctl(struct file *filp,
37965 struct drm_file *file_priv = filp->private_data;
37966 struct drm_device *dev;
37967 const struct drm_ioctl_desc *ioctl = NULL;
37968- drm_ioctl_t *func;
37969+ drm_ioctl_no_const_t func;
37970 unsigned int nr = DRM_IOCTL_NR(cmd);
37971 int retcode = -EINVAL;
37972 char stack_kdata[128];
37973@@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
37974 return -ENODEV;
37975
37976 atomic_inc(&dev->ioctl_count);
37977- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
37978+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
37979 ++file_priv->ioctl_count;
37980
37981 if ((nr >= DRM_CORE_IOCTL_COUNT) &&
37982diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
37983index 3a24385..4e426e0 100644
37984--- a/drivers/gpu/drm/drm_fops.c
37985+++ b/drivers/gpu/drm/drm_fops.c
37986@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
37987 }
37988
37989 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
37990- atomic_set(&dev->counts[i], 0);
37991+ atomic_set_unchecked(&dev->counts[i], 0);
37992
37993 dev->sigdata.lock = NULL;
37994
37995@@ -135,7 +135,7 @@ int drm_open(struct inode *inode, struct file *filp)
37996 if (drm_device_is_unplugged(dev))
37997 return -ENODEV;
37998
37999- if (!dev->open_count++)
38000+ if (local_inc_return(&dev->open_count) == 1)
38001 need_setup = 1;
38002 mutex_lock(&dev->struct_mutex);
38003 old_imapping = inode->i_mapping;
38004@@ -151,7 +151,7 @@ int drm_open(struct inode *inode, struct file *filp)
38005 retcode = drm_open_helper(inode, filp, dev);
38006 if (retcode)
38007 goto err_undo;
38008- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
38009+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
38010 if (need_setup) {
38011 retcode = drm_setup(dev);
38012 if (retcode)
38013@@ -166,7 +166,7 @@ err_undo:
38014 iput(container_of(dev->dev_mapping, struct inode, i_data));
38015 dev->dev_mapping = old_mapping;
38016 mutex_unlock(&dev->struct_mutex);
38017- dev->open_count--;
38018+ local_dec(&dev->open_count);
38019 return retcode;
38020 }
38021 EXPORT_SYMBOL(drm_open);
38022@@ -456,7 +456,7 @@ int drm_release(struct inode *inode, struct file *filp)
38023
38024 mutex_lock(&drm_global_mutex);
38025
38026- DRM_DEBUG("open_count = %d\n", dev->open_count);
38027+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
38028
38029 if (dev->driver->preclose)
38030 dev->driver->preclose(dev, file_priv);
38031@@ -465,10 +465,10 @@ int drm_release(struct inode *inode, struct file *filp)
38032 * Begin inline drm_release
38033 */
38034
38035- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
38036+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
38037 task_pid_nr(current),
38038 (long)old_encode_dev(file_priv->minor->device),
38039- dev->open_count);
38040+ local_read(&dev->open_count));
38041
38042 /* Release any auth tokens that might point to this file_priv,
38043 (do that under the drm_global_mutex) */
38044@@ -565,8 +565,8 @@ int drm_release(struct inode *inode, struct file *filp)
38045 * End inline drm_release
38046 */
38047
38048- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
38049- if (!--dev->open_count) {
38050+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
38051+ if (local_dec_and_test(&dev->open_count)) {
38052 if (atomic_read(&dev->ioctl_count)) {
38053 DRM_ERROR("Device busy: %d\n",
38054 atomic_read(&dev->ioctl_count));
38055diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
38056index f731116..629842c 100644
38057--- a/drivers/gpu/drm/drm_global.c
38058+++ b/drivers/gpu/drm/drm_global.c
38059@@ -36,7 +36,7 @@
38060 struct drm_global_item {
38061 struct mutex mutex;
38062 void *object;
38063- int refcount;
38064+ atomic_t refcount;
38065 };
38066
38067 static struct drm_global_item glob[DRM_GLOBAL_NUM];
38068@@ -49,7 +49,7 @@ void drm_global_init(void)
38069 struct drm_global_item *item = &glob[i];
38070 mutex_init(&item->mutex);
38071 item->object = NULL;
38072- item->refcount = 0;
38073+ atomic_set(&item->refcount, 0);
38074 }
38075 }
38076
38077@@ -59,7 +59,7 @@ void drm_global_release(void)
38078 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
38079 struct drm_global_item *item = &glob[i];
38080 BUG_ON(item->object != NULL);
38081- BUG_ON(item->refcount != 0);
38082+ BUG_ON(atomic_read(&item->refcount) != 0);
38083 }
38084 }
38085
38086@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
38087 void *object;
38088
38089 mutex_lock(&item->mutex);
38090- if (item->refcount == 0) {
38091+ if (atomic_read(&item->refcount) == 0) {
38092 item->object = kzalloc(ref->size, GFP_KERNEL);
38093 if (unlikely(item->object == NULL)) {
38094 ret = -ENOMEM;
38095@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
38096 goto out_err;
38097
38098 }
38099- ++item->refcount;
38100+ atomic_inc(&item->refcount);
38101 ref->object = item->object;
38102 object = item->object;
38103 mutex_unlock(&item->mutex);
38104@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
38105 struct drm_global_item *item = &glob[ref->global_type];
38106
38107 mutex_lock(&item->mutex);
38108- BUG_ON(item->refcount == 0);
38109+ BUG_ON(atomic_read(&item->refcount) == 0);
38110 BUG_ON(ref->object != item->object);
38111- if (--item->refcount == 0) {
38112+ if (atomic_dec_and_test(&item->refcount)) {
38113 ref->release(ref);
38114 item->object = NULL;
38115 }
38116diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
38117index d4b20ce..77a8d41 100644
38118--- a/drivers/gpu/drm/drm_info.c
38119+++ b/drivers/gpu/drm/drm_info.c
38120@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
38121 struct drm_local_map *map;
38122 struct drm_map_list *r_list;
38123
38124- /* Hardcoded from _DRM_FRAME_BUFFER,
38125- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
38126- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
38127- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
38128+ static const char * const types[] = {
38129+ [_DRM_FRAME_BUFFER] = "FB",
38130+ [_DRM_REGISTERS] = "REG",
38131+ [_DRM_SHM] = "SHM",
38132+ [_DRM_AGP] = "AGP",
38133+ [_DRM_SCATTER_GATHER] = "SG",
38134+ [_DRM_CONSISTENT] = "PCI",
38135+ [_DRM_GEM] = "GEM" };
38136 const char *type;
38137 int i;
38138
38139@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
38140 map = r_list->map;
38141 if (!map)
38142 continue;
38143- if (map->type < 0 || map->type > 5)
38144+ if (map->type >= ARRAY_SIZE(types))
38145 type = "??";
38146 else
38147 type = types[map->type];
38148@@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
38149 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
38150 vma->vm_flags & VM_LOCKED ? 'l' : '-',
38151 vma->vm_flags & VM_IO ? 'i' : '-',
38152+#ifdef CONFIG_GRKERNSEC_HIDESYM
38153+ 0);
38154+#else
38155 vma->vm_pgoff);
38156+#endif
38157
38158 #if defined(__i386__)
38159 pgprot = pgprot_val(vma->vm_page_prot);
38160diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
38161index 2f4c434..dd12cd2 100644
38162--- a/drivers/gpu/drm/drm_ioc32.c
38163+++ b/drivers/gpu/drm/drm_ioc32.c
38164@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
38165 request = compat_alloc_user_space(nbytes);
38166 if (!access_ok(VERIFY_WRITE, request, nbytes))
38167 return -EFAULT;
38168- list = (struct drm_buf_desc *) (request + 1);
38169+ list = (struct drm_buf_desc __user *) (request + 1);
38170
38171 if (__put_user(count, &request->count)
38172 || __put_user(list, &request->list))
38173@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
38174 request = compat_alloc_user_space(nbytes);
38175 if (!access_ok(VERIFY_WRITE, request, nbytes))
38176 return -EFAULT;
38177- list = (struct drm_buf_pub *) (request + 1);
38178+ list = (struct drm_buf_pub __user *) (request + 1);
38179
38180 if (__put_user(count, &request->count)
38181 || __put_user(list, &request->list))
38182@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
38183 return 0;
38184 }
38185
38186-drm_ioctl_compat_t *drm_compat_ioctls[] = {
38187+drm_ioctl_compat_t drm_compat_ioctls[] = {
38188 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
38189 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
38190 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
38191@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
38192 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38193 {
38194 unsigned int nr = DRM_IOCTL_NR(cmd);
38195- drm_ioctl_compat_t *fn;
38196 int ret;
38197
38198 /* Assume that ioctls without an explicit compat routine will just
38199@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38200 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
38201 return drm_ioctl(filp, cmd, arg);
38202
38203- fn = drm_compat_ioctls[nr];
38204-
38205- if (fn != NULL)
38206- ret = (*fn) (filp, cmd, arg);
38207+ if (drm_compat_ioctls[nr] != NULL)
38208+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
38209 else
38210 ret = drm_ioctl(filp, cmd, arg);
38211
38212diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
38213index ffd7a7b..a64643e 100644
38214--- a/drivers/gpu/drm/drm_ioctl.c
38215+++ b/drivers/gpu/drm/drm_ioctl.c
38216@@ -265,7 +265,7 @@ int drm_getstats(struct drm_device *dev, void *data,
38217 stats->data[i].value =
38218 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
38219 else
38220- stats->data[i].value = atomic_read(&dev->counts[i]);
38221+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
38222 stats->data[i].type = dev->types[i];
38223 }
38224
38225diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
38226index d752c96..fe08455 100644
38227--- a/drivers/gpu/drm/drm_lock.c
38228+++ b/drivers/gpu/drm/drm_lock.c
38229@@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
38230 if (drm_lock_take(&master->lock, lock->context)) {
38231 master->lock.file_priv = file_priv;
38232 master->lock.lock_time = jiffies;
38233- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
38234+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
38235 break; /* Got lock */
38236 }
38237
38238@@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
38239 return -EINVAL;
38240 }
38241
38242- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
38243+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
38244
38245 if (drm_lock_free(&master->lock, lock->context)) {
38246 /* FIXME: Should really bail out here. */
38247diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
38248index 327ca19..684d3c0 100644
38249--- a/drivers/gpu/drm/drm_stub.c
38250+++ b/drivers/gpu/drm/drm_stub.c
38251@@ -495,7 +495,7 @@ void drm_unplug_dev(struct drm_device *dev)
38252
38253 drm_device_set_unplugged(dev);
38254
38255- if (dev->open_count == 0) {
38256+ if (local_read(&dev->open_count) == 0) {
38257 drm_put_dev(dev);
38258 }
38259 mutex_unlock(&drm_global_mutex);
38260diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
38261index 2290b3b..22056a1 100644
38262--- a/drivers/gpu/drm/drm_sysfs.c
38263+++ b/drivers/gpu/drm/drm_sysfs.c
38264@@ -524,7 +524,7 @@ EXPORT_SYMBOL(drm_sysfs_hotplug_event);
38265 int drm_sysfs_device_add(struct drm_minor *minor)
38266 {
38267 int err;
38268- char *minor_str;
38269+ const char *minor_str;
38270
38271 minor->kdev.parent = minor->dev->dev;
38272
38273diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
38274index ada49ed..29275a0 100644
38275--- a/drivers/gpu/drm/i810/i810_dma.c
38276+++ b/drivers/gpu/drm/i810/i810_dma.c
38277@@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
38278 dma->buflist[vertex->idx],
38279 vertex->discard, vertex->used);
38280
38281- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
38282- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
38283+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
38284+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
38285 sarea_priv->last_enqueue = dev_priv->counter - 1;
38286 sarea_priv->last_dispatch = (int)hw_status[5];
38287
38288@@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
38289 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
38290 mc->last_render);
38291
38292- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
38293- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
38294+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
38295+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
38296 sarea_priv->last_enqueue = dev_priv->counter - 1;
38297 sarea_priv->last_dispatch = (int)hw_status[5];
38298
38299diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
38300index 6e0acad..93c8289 100644
38301--- a/drivers/gpu/drm/i810/i810_drv.h
38302+++ b/drivers/gpu/drm/i810/i810_drv.h
38303@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
38304 int page_flipping;
38305
38306 wait_queue_head_t irq_queue;
38307- atomic_t irq_received;
38308- atomic_t irq_emitted;
38309+ atomic_unchecked_t irq_received;
38310+ atomic_unchecked_t irq_emitted;
38311
38312 int front_offset;
38313 } drm_i810_private_t;
38314diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
38315index 47d6c74..279123f 100644
38316--- a/drivers/gpu/drm/i915/i915_debugfs.c
38317+++ b/drivers/gpu/drm/i915/i915_debugfs.c
38318@@ -541,7 +541,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
38319 I915_READ(GTIMR));
38320 }
38321 seq_printf(m, "Interrupts received: %d\n",
38322- atomic_read(&dev_priv->irq_received));
38323+ atomic_read_unchecked(&dev_priv->irq_received));
38324 for_each_ring(ring, dev_priv, i) {
38325 if (IS_GEN6(dev) || IS_GEN7(dev)) {
38326 seq_printf(m,
38327diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
38328index f466980..8f2883f 100644
38329--- a/drivers/gpu/drm/i915/i915_dma.c
38330+++ b/drivers/gpu/drm/i915/i915_dma.c
38331@@ -1260,7 +1260,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
38332 bool can_switch;
38333
38334 spin_lock(&dev->count_lock);
38335- can_switch = (dev->open_count == 0);
38336+ can_switch = (local_read(&dev->open_count) == 0);
38337 spin_unlock(&dev->count_lock);
38338 return can_switch;
38339 }
38340diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
38341index 2f09e80..077876d 100644
38342--- a/drivers/gpu/drm/i915/i915_drv.h
38343+++ b/drivers/gpu/drm/i915/i915_drv.h
38344@@ -1028,7 +1028,7 @@ typedef struct drm_i915_private {
38345 drm_dma_handle_t *status_page_dmah;
38346 struct resource mch_res;
38347
38348- atomic_t irq_received;
38349+ atomic_unchecked_t irq_received;
38350
38351 /* protects the irq masks */
38352 spinlock_t irq_lock;
38353diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
38354index 87a3227..cd13d8f 100644
38355--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
38356+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
38357@@ -727,9 +727,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
38358
38359 static int
38360 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
38361- int count)
38362+ unsigned int count)
38363 {
38364- int i;
38365+ unsigned int i;
38366 int relocs_total = 0;
38367 int relocs_max = INT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
38368
38369diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
38370index 3c59584..500f2e9 100644
38371--- a/drivers/gpu/drm/i915/i915_ioc32.c
38372+++ b/drivers/gpu/drm/i915/i915_ioc32.c
38373@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
38374 (unsigned long)request);
38375 }
38376
38377-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
38378+static drm_ioctl_compat_t i915_compat_ioctls[] = {
38379 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
38380 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
38381 [DRM_I915_GETPARAM] = compat_i915_getparam,
38382@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
38383 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38384 {
38385 unsigned int nr = DRM_IOCTL_NR(cmd);
38386- drm_ioctl_compat_t *fn = NULL;
38387 int ret;
38388
38389 if (nr < DRM_COMMAND_BASE)
38390 return drm_compat_ioctl(filp, cmd, arg);
38391
38392- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
38393- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
38394-
38395- if (fn != NULL)
38396+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
38397+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
38398 ret = (*fn) (filp, cmd, arg);
38399- else
38400+ } else
38401 ret = drm_ioctl(filp, cmd, arg);
38402
38403 return ret;
38404diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
38405index 46d46ba..6e49848 100644
38406--- a/drivers/gpu/drm/i915/i915_irq.c
38407+++ b/drivers/gpu/drm/i915/i915_irq.c
38408@@ -975,7 +975,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
38409 int pipe;
38410 u32 pipe_stats[I915_MAX_PIPES];
38411
38412- atomic_inc(&dev_priv->irq_received);
38413+ atomic_inc_unchecked(&dev_priv->irq_received);
38414
38415 while (true) {
38416 iir = I915_READ(VLV_IIR);
38417@@ -1192,7 +1192,7 @@ static irqreturn_t ivybridge_irq_handler(int irq, void *arg)
38418 irqreturn_t ret = IRQ_NONE;
38419 int i;
38420
38421- atomic_inc(&dev_priv->irq_received);
38422+ atomic_inc_unchecked(&dev_priv->irq_received);
38423
38424 /* We get interrupts on unclaimed registers, so check for this before we
38425 * do any I915_{READ,WRITE}. */
38426@@ -1312,7 +1312,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
38427 int ret = IRQ_NONE;
38428 u32 de_iir, gt_iir, de_ier, pm_iir, sde_ier;
38429
38430- atomic_inc(&dev_priv->irq_received);
38431+ atomic_inc_unchecked(&dev_priv->irq_received);
38432
38433 /* disable master interrupt before clearing iir */
38434 de_ier = I915_READ(DEIER);
38435@@ -2617,7 +2617,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
38436 {
38437 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38438
38439- atomic_set(&dev_priv->irq_received, 0);
38440+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38441
38442 I915_WRITE(HWSTAM, 0xeffe);
38443
38444@@ -2639,7 +2639,7 @@ static void ivybridge_irq_preinstall(struct drm_device *dev)
38445 {
38446 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38447
38448- atomic_set(&dev_priv->irq_received, 0);
38449+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38450
38451 I915_WRITE(HWSTAM, 0xeffe);
38452
38453@@ -2667,7 +2667,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
38454 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38455 int pipe;
38456
38457- atomic_set(&dev_priv->irq_received, 0);
38458+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38459
38460 /* VLV magic */
38461 I915_WRITE(VLV_IMR, 0);
38462@@ -2979,7 +2979,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
38463 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38464 int pipe;
38465
38466- atomic_set(&dev_priv->irq_received, 0);
38467+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38468
38469 for_each_pipe(pipe)
38470 I915_WRITE(PIPESTAT(pipe), 0);
38471@@ -3058,7 +3058,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
38472 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
38473 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
38474
38475- atomic_inc(&dev_priv->irq_received);
38476+ atomic_inc_unchecked(&dev_priv->irq_received);
38477
38478 iir = I915_READ16(IIR);
38479 if (iir == 0)
38480@@ -3133,7 +3133,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
38481 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38482 int pipe;
38483
38484- atomic_set(&dev_priv->irq_received, 0);
38485+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38486
38487 if (I915_HAS_HOTPLUG(dev)) {
38488 I915_WRITE(PORT_HOTPLUG_EN, 0);
38489@@ -3232,7 +3232,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
38490 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
38491 int pipe, ret = IRQ_NONE;
38492
38493- atomic_inc(&dev_priv->irq_received);
38494+ atomic_inc_unchecked(&dev_priv->irq_received);
38495
38496 iir = I915_READ(IIR);
38497 do {
38498@@ -3356,7 +3356,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
38499 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38500 int pipe;
38501
38502- atomic_set(&dev_priv->irq_received, 0);
38503+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38504
38505 I915_WRITE(PORT_HOTPLUG_EN, 0);
38506 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
38507@@ -3465,7 +3465,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
38508 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
38509 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
38510
38511- atomic_inc(&dev_priv->irq_received);
38512+ atomic_inc_unchecked(&dev_priv->irq_received);
38513
38514 iir = I915_READ(IIR);
38515
38516diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
38517index 90a7c17..ecedc6a 100644
38518--- a/drivers/gpu/drm/i915/intel_display.c
38519+++ b/drivers/gpu/drm/i915/intel_display.c
38520@@ -9424,13 +9424,13 @@ struct intel_quirk {
38521 int subsystem_vendor;
38522 int subsystem_device;
38523 void (*hook)(struct drm_device *dev);
38524-};
38525+} __do_const;
38526
38527 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
38528 struct intel_dmi_quirk {
38529 void (*hook)(struct drm_device *dev);
38530 const struct dmi_system_id (*dmi_id_list)[];
38531-};
38532+} __do_const;
38533
38534 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
38535 {
38536@@ -9438,18 +9438,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
38537 return 1;
38538 }
38539
38540-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
38541+static const struct dmi_system_id intel_dmi_quirks_table[] = {
38542 {
38543- .dmi_id_list = &(const struct dmi_system_id[]) {
38544- {
38545- .callback = intel_dmi_reverse_brightness,
38546- .ident = "NCR Corporation",
38547- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
38548- DMI_MATCH(DMI_PRODUCT_NAME, ""),
38549- },
38550- },
38551- { } /* terminating entry */
38552+ .callback = intel_dmi_reverse_brightness,
38553+ .ident = "NCR Corporation",
38554+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
38555+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
38556 },
38557+ },
38558+ { } /* terminating entry */
38559+};
38560+
38561+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
38562+ {
38563+ .dmi_id_list = &intel_dmi_quirks_table,
38564 .hook = quirk_invert_brightness,
38565 },
38566 };
38567diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
38568index 54558a0..2d97005 100644
38569--- a/drivers/gpu/drm/mga/mga_drv.h
38570+++ b/drivers/gpu/drm/mga/mga_drv.h
38571@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
38572 u32 clear_cmd;
38573 u32 maccess;
38574
38575- atomic_t vbl_received; /**< Number of vblanks received. */
38576+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
38577 wait_queue_head_t fence_queue;
38578- atomic_t last_fence_retired;
38579+ atomic_unchecked_t last_fence_retired;
38580 u32 next_fence_to_post;
38581
38582 unsigned int fb_cpp;
38583diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
38584index 709e90d..89a1c0d 100644
38585--- a/drivers/gpu/drm/mga/mga_ioc32.c
38586+++ b/drivers/gpu/drm/mga/mga_ioc32.c
38587@@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
38588 return 0;
38589 }
38590
38591-drm_ioctl_compat_t *mga_compat_ioctls[] = {
38592+drm_ioctl_compat_t mga_compat_ioctls[] = {
38593 [DRM_MGA_INIT] = compat_mga_init,
38594 [DRM_MGA_GETPARAM] = compat_mga_getparam,
38595 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
38596@@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
38597 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38598 {
38599 unsigned int nr = DRM_IOCTL_NR(cmd);
38600- drm_ioctl_compat_t *fn = NULL;
38601 int ret;
38602
38603 if (nr < DRM_COMMAND_BASE)
38604 return drm_compat_ioctl(filp, cmd, arg);
38605
38606- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
38607- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
38608-
38609- if (fn != NULL)
38610+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
38611+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
38612 ret = (*fn) (filp, cmd, arg);
38613- else
38614+ } else
38615 ret = drm_ioctl(filp, cmd, arg);
38616
38617 return ret;
38618diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
38619index 598c281..60d590e 100644
38620--- a/drivers/gpu/drm/mga/mga_irq.c
38621+++ b/drivers/gpu/drm/mga/mga_irq.c
38622@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
38623 if (crtc != 0)
38624 return 0;
38625
38626- return atomic_read(&dev_priv->vbl_received);
38627+ return atomic_read_unchecked(&dev_priv->vbl_received);
38628 }
38629
38630
38631@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
38632 /* VBLANK interrupt */
38633 if (status & MGA_VLINEPEN) {
38634 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
38635- atomic_inc(&dev_priv->vbl_received);
38636+ atomic_inc_unchecked(&dev_priv->vbl_received);
38637 drm_handle_vblank(dev, 0);
38638 handled = 1;
38639 }
38640@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
38641 if ((prim_start & ~0x03) != (prim_end & ~0x03))
38642 MGA_WRITE(MGA_PRIMEND, prim_end);
38643
38644- atomic_inc(&dev_priv->last_fence_retired);
38645+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
38646 DRM_WAKEUP(&dev_priv->fence_queue);
38647 handled = 1;
38648 }
38649@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
38650 * using fences.
38651 */
38652 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
38653- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
38654+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
38655 - *sequence) <= (1 << 23)));
38656
38657 *sequence = cur_fence;
38658diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
38659index 3e72876..d1c15ad 100644
38660--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
38661+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
38662@@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
38663 struct bit_table {
38664 const char id;
38665 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
38666-};
38667+} __no_const;
38668
38669 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
38670
38671diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
38672index 41ff7e0..fa854ef 100644
38673--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
38674+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
38675@@ -92,7 +92,6 @@ struct nouveau_drm {
38676 struct drm_global_reference mem_global_ref;
38677 struct ttm_bo_global_ref bo_global_ref;
38678 struct ttm_bo_device bdev;
38679- atomic_t validate_sequence;
38680 int (*move)(struct nouveau_channel *,
38681 struct ttm_buffer_object *,
38682 struct ttm_mem_reg *, struct ttm_mem_reg *);
38683diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
38684index 08214bc..9208577 100644
38685--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
38686+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
38687@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
38688 unsigned long arg)
38689 {
38690 unsigned int nr = DRM_IOCTL_NR(cmd);
38691- drm_ioctl_compat_t *fn = NULL;
38692+ drm_ioctl_compat_t fn = NULL;
38693 int ret;
38694
38695 if (nr < DRM_COMMAND_BASE)
38696diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
38697index 25d3495..d81aaf6 100644
38698--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
38699+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
38700@@ -62,7 +62,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
38701 bool can_switch;
38702
38703 spin_lock(&dev->count_lock);
38704- can_switch = (dev->open_count == 0);
38705+ can_switch = (local_read(&dev->open_count) == 0);
38706 spin_unlock(&dev->count_lock);
38707 return can_switch;
38708 }
38709diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
38710index 1dfd84c..104896c 100644
38711--- a/drivers/gpu/drm/qxl/qxl_ttm.c
38712+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
38713@@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
38714 }
38715 }
38716
38717-static struct vm_operations_struct qxl_ttm_vm_ops;
38718+static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
38719 static const struct vm_operations_struct *ttm_vm_ops;
38720
38721 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
38722@@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
38723 return r;
38724 if (unlikely(ttm_vm_ops == NULL)) {
38725 ttm_vm_ops = vma->vm_ops;
38726+ pax_open_kernel();
38727 qxl_ttm_vm_ops = *ttm_vm_ops;
38728 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
38729+ pax_close_kernel();
38730 }
38731 vma->vm_ops = &qxl_ttm_vm_ops;
38732 return 0;
38733@@ -556,25 +558,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
38734 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
38735 {
38736 #if defined(CONFIG_DEBUG_FS)
38737- static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
38738- static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
38739- unsigned i;
38740+ static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
38741+ {
38742+ .name = "qxl_mem_mm",
38743+ .show = &qxl_mm_dump_table,
38744+ },
38745+ {
38746+ .name = "qxl_surf_mm",
38747+ .show = &qxl_mm_dump_table,
38748+ }
38749+ };
38750
38751- for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
38752- if (i == 0)
38753- sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
38754- else
38755- sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
38756- qxl_mem_types_list[i].name = qxl_mem_types_names[i];
38757- qxl_mem_types_list[i].show = &qxl_mm_dump_table;
38758- qxl_mem_types_list[i].driver_features = 0;
38759- if (i == 0)
38760- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
38761- else
38762- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
38763+ pax_open_kernel();
38764+ *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
38765+ *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
38766+ pax_close_kernel();
38767
38768- }
38769- return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
38770+ return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
38771 #else
38772 return 0;
38773 #endif
38774diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
38775index d4660cf..70dbe65 100644
38776--- a/drivers/gpu/drm/r128/r128_cce.c
38777+++ b/drivers/gpu/drm/r128/r128_cce.c
38778@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
38779
38780 /* GH: Simple idle check.
38781 */
38782- atomic_set(&dev_priv->idle_count, 0);
38783+ atomic_set_unchecked(&dev_priv->idle_count, 0);
38784
38785 /* We don't support anything other than bus-mastering ring mode,
38786 * but the ring can be in either AGP or PCI space for the ring
38787diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
38788index 930c71b..499aded 100644
38789--- a/drivers/gpu/drm/r128/r128_drv.h
38790+++ b/drivers/gpu/drm/r128/r128_drv.h
38791@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
38792 int is_pci;
38793 unsigned long cce_buffers_offset;
38794
38795- atomic_t idle_count;
38796+ atomic_unchecked_t idle_count;
38797
38798 int page_flipping;
38799 int current_page;
38800 u32 crtc_offset;
38801 u32 crtc_offset_cntl;
38802
38803- atomic_t vbl_received;
38804+ atomic_unchecked_t vbl_received;
38805
38806 u32 color_fmt;
38807 unsigned int front_offset;
38808diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
38809index a954c54..9cc595c 100644
38810--- a/drivers/gpu/drm/r128/r128_ioc32.c
38811+++ b/drivers/gpu/drm/r128/r128_ioc32.c
38812@@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
38813 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
38814 }
38815
38816-drm_ioctl_compat_t *r128_compat_ioctls[] = {
38817+drm_ioctl_compat_t r128_compat_ioctls[] = {
38818 [DRM_R128_INIT] = compat_r128_init,
38819 [DRM_R128_DEPTH] = compat_r128_depth,
38820 [DRM_R128_STIPPLE] = compat_r128_stipple,
38821@@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
38822 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38823 {
38824 unsigned int nr = DRM_IOCTL_NR(cmd);
38825- drm_ioctl_compat_t *fn = NULL;
38826 int ret;
38827
38828 if (nr < DRM_COMMAND_BASE)
38829 return drm_compat_ioctl(filp, cmd, arg);
38830
38831- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
38832- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
38833-
38834- if (fn != NULL)
38835+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
38836+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
38837 ret = (*fn) (filp, cmd, arg);
38838- else
38839+ } else
38840 ret = drm_ioctl(filp, cmd, arg);
38841
38842 return ret;
38843diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
38844index 2ea4f09..d391371 100644
38845--- a/drivers/gpu/drm/r128/r128_irq.c
38846+++ b/drivers/gpu/drm/r128/r128_irq.c
38847@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
38848 if (crtc != 0)
38849 return 0;
38850
38851- return atomic_read(&dev_priv->vbl_received);
38852+ return atomic_read_unchecked(&dev_priv->vbl_received);
38853 }
38854
38855 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
38856@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
38857 /* VBLANK interrupt */
38858 if (status & R128_CRTC_VBLANK_INT) {
38859 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
38860- atomic_inc(&dev_priv->vbl_received);
38861+ atomic_inc_unchecked(&dev_priv->vbl_received);
38862 drm_handle_vblank(dev, 0);
38863 return IRQ_HANDLED;
38864 }
38865diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
38866index 19bb7e6..de7e2a2 100644
38867--- a/drivers/gpu/drm/r128/r128_state.c
38868+++ b/drivers/gpu/drm/r128/r128_state.c
38869@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
38870
38871 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
38872 {
38873- if (atomic_read(&dev_priv->idle_count) == 0)
38874+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
38875 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
38876 else
38877- atomic_set(&dev_priv->idle_count, 0);
38878+ atomic_set_unchecked(&dev_priv->idle_count, 0);
38879 }
38880
38881 #endif
38882diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
38883index af85299..ed9ac8d 100644
38884--- a/drivers/gpu/drm/radeon/mkregtable.c
38885+++ b/drivers/gpu/drm/radeon/mkregtable.c
38886@@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
38887 regex_t mask_rex;
38888 regmatch_t match[4];
38889 char buf[1024];
38890- size_t end;
38891+ long end;
38892 int len;
38893 int done = 0;
38894 int r;
38895 unsigned o;
38896 struct offset *offset;
38897 char last_reg_s[10];
38898- int last_reg;
38899+ unsigned long last_reg;
38900
38901 if (regcomp
38902 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
38903diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
38904index d15f27e..ef11ffc 100644
38905--- a/drivers/gpu/drm/radeon/radeon_device.c
38906+++ b/drivers/gpu/drm/radeon/radeon_device.c
38907@@ -1105,7 +1105,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
38908 bool can_switch;
38909
38910 spin_lock(&dev->count_lock);
38911- can_switch = (dev->open_count == 0);
38912+ can_switch = (local_read(&dev->open_count) == 0);
38913 spin_unlock(&dev->count_lock);
38914 return can_switch;
38915 }
38916diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
38917index b369d42..8dd04eb 100644
38918--- a/drivers/gpu/drm/radeon/radeon_drv.h
38919+++ b/drivers/gpu/drm/radeon/radeon_drv.h
38920@@ -258,7 +258,7 @@ typedef struct drm_radeon_private {
38921
38922 /* SW interrupt */
38923 wait_queue_head_t swi_queue;
38924- atomic_t swi_emitted;
38925+ atomic_unchecked_t swi_emitted;
38926 int vblank_crtc;
38927 uint32_t irq_enable_reg;
38928 uint32_t r500_disp_irq_reg;
38929diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
38930index c180df8..5fd8186 100644
38931--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
38932+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
38933@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
38934 request = compat_alloc_user_space(sizeof(*request));
38935 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
38936 || __put_user(req32.param, &request->param)
38937- || __put_user((void __user *)(unsigned long)req32.value,
38938+ || __put_user((unsigned long)req32.value,
38939 &request->value))
38940 return -EFAULT;
38941
38942@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
38943 #define compat_radeon_cp_setparam NULL
38944 #endif /* X86_64 || IA64 */
38945
38946-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
38947+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
38948 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
38949 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
38950 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
38951@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
38952 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38953 {
38954 unsigned int nr = DRM_IOCTL_NR(cmd);
38955- drm_ioctl_compat_t *fn = NULL;
38956 int ret;
38957
38958 if (nr < DRM_COMMAND_BASE)
38959 return drm_compat_ioctl(filp, cmd, arg);
38960
38961- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
38962- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
38963-
38964- if (fn != NULL)
38965+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
38966+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
38967 ret = (*fn) (filp, cmd, arg);
38968- else
38969+ } else
38970 ret = drm_ioctl(filp, cmd, arg);
38971
38972 return ret;
38973diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
38974index 8d68e97..9dcfed8 100644
38975--- a/drivers/gpu/drm/radeon/radeon_irq.c
38976+++ b/drivers/gpu/drm/radeon/radeon_irq.c
38977@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
38978 unsigned int ret;
38979 RING_LOCALS;
38980
38981- atomic_inc(&dev_priv->swi_emitted);
38982- ret = atomic_read(&dev_priv->swi_emitted);
38983+ atomic_inc_unchecked(&dev_priv->swi_emitted);
38984+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
38985
38986 BEGIN_RING(4);
38987 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
38988@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
38989 drm_radeon_private_t *dev_priv =
38990 (drm_radeon_private_t *) dev->dev_private;
38991
38992- atomic_set(&dev_priv->swi_emitted, 0);
38993+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
38994 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
38995
38996 dev->max_vblank_count = 0x001fffff;
38997diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
38998index 4d20910..6726b6d 100644
38999--- a/drivers/gpu/drm/radeon/radeon_state.c
39000+++ b/drivers/gpu/drm/radeon/radeon_state.c
39001@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
39002 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
39003 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
39004
39005- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
39006+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
39007 sarea_priv->nbox * sizeof(depth_boxes[0])))
39008 return -EFAULT;
39009
39010@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
39011 {
39012 drm_radeon_private_t *dev_priv = dev->dev_private;
39013 drm_radeon_getparam_t *param = data;
39014- int value;
39015+ int value = 0;
39016
39017 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
39018
39019diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
39020index 6c0ce89..57a2529 100644
39021--- a/drivers/gpu/drm/radeon/radeon_ttm.c
39022+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
39023@@ -782,7 +782,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
39024 man->size = size >> PAGE_SHIFT;
39025 }
39026
39027-static struct vm_operations_struct radeon_ttm_vm_ops;
39028+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
39029 static const struct vm_operations_struct *ttm_vm_ops = NULL;
39030
39031 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
39032@@ -823,8 +823,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
39033 }
39034 if (unlikely(ttm_vm_ops == NULL)) {
39035 ttm_vm_ops = vma->vm_ops;
39036+ pax_open_kernel();
39037 radeon_ttm_vm_ops = *ttm_vm_ops;
39038 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
39039+ pax_close_kernel();
39040 }
39041 vma->vm_ops = &radeon_ttm_vm_ops;
39042 return 0;
39043@@ -853,38 +855,33 @@ static int radeon_mm_dump_table(struct seq_file *m, void *data)
39044 static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
39045 {
39046 #if defined(CONFIG_DEBUG_FS)
39047- static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2];
39048- static char radeon_mem_types_names[RADEON_DEBUGFS_MEM_TYPES+2][32];
39049+ static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2] = {
39050+ {
39051+ .name = "radeon_vram_mm",
39052+ .show = &radeon_mm_dump_table,
39053+ },
39054+ {
39055+ .name = "radeon_gtt_mm",
39056+ .show = &radeon_mm_dump_table,
39057+ },
39058+ {
39059+ .name = "ttm_page_pool",
39060+ .show = &ttm_page_alloc_debugfs,
39061+ },
39062+ {
39063+ .name = "ttm_dma_page_pool",
39064+ .show = &ttm_dma_page_alloc_debugfs,
39065+ },
39066+ };
39067 unsigned i;
39068
39069- for (i = 0; i < RADEON_DEBUGFS_MEM_TYPES; i++) {
39070- if (i == 0)
39071- sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
39072- else
39073- sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
39074- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
39075- radeon_mem_types_list[i].show = &radeon_mm_dump_table;
39076- radeon_mem_types_list[i].driver_features = 0;
39077- if (i == 0)
39078- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
39079- else
39080- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
39081-
39082- }
39083- /* Add ttm page pool to debugfs */
39084- sprintf(radeon_mem_types_names[i], "ttm_page_pool");
39085- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
39086- radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
39087- radeon_mem_types_list[i].driver_features = 0;
39088- radeon_mem_types_list[i++].data = NULL;
39089+ pax_open_kernel();
39090+ *(void **)&radeon_mem_types_list[0].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
39091+ *(void **)&radeon_mem_types_list[1].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
39092+ pax_close_kernel();
39093 #ifdef CONFIG_SWIOTLB
39094- if (swiotlb_nr_tbl()) {
39095- sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
39096- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
39097- radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
39098- radeon_mem_types_list[i].driver_features = 0;
39099- radeon_mem_types_list[i++].data = NULL;
39100- }
39101+ if (swiotlb_nr_tbl())
39102+ i++;
39103 #endif
39104 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
39105
39106diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
39107index d8ddfb3..609de1d 100644
39108--- a/drivers/gpu/drm/radeon/rs690.c
39109+++ b/drivers/gpu/drm/radeon/rs690.c
39110@@ -345,9 +345,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
39111 if (max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
39112 rdev->pm.sideport_bandwidth.full)
39113 max_bandwidth = rdev->pm.sideport_bandwidth;
39114- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
39115+ read_delay_latency.full = dfixed_const(800 * 1000);
39116 read_delay_latency.full = dfixed_div(read_delay_latency,
39117 rdev->pm.igp_sideport_mclk);
39118+ a.full = dfixed_const(370);
39119+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
39120 } else {
39121 if (max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
39122 rdev->pm.k8_bandwidth.full)
39123diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
39124index dbc2def..0a9f710 100644
39125--- a/drivers/gpu/drm/ttm/ttm_memory.c
39126+++ b/drivers/gpu/drm/ttm/ttm_memory.c
39127@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
39128 zone->glob = glob;
39129 glob->zone_kernel = zone;
39130 ret = kobject_init_and_add(
39131- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
39132+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
39133 if (unlikely(ret != 0)) {
39134 kobject_put(&zone->kobj);
39135 return ret;
39136@@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
39137 zone->glob = glob;
39138 glob->zone_dma32 = zone;
39139 ret = kobject_init_and_add(
39140- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
39141+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
39142 if (unlikely(ret != 0)) {
39143 kobject_put(&zone->kobj);
39144 return ret;
39145diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
39146index bd2a3b4..122d9ad 100644
39147--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
39148+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
39149@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
39150 static int ttm_pool_mm_shrink(struct shrinker *shrink,
39151 struct shrink_control *sc)
39152 {
39153- static atomic_t start_pool = ATOMIC_INIT(0);
39154+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
39155 unsigned i;
39156- unsigned pool_offset = atomic_add_return(1, &start_pool);
39157+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
39158 struct ttm_page_pool *pool;
39159 int shrink_pages = sc->nr_to_scan;
39160
39161diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
39162index 97e9d61..bf23c461 100644
39163--- a/drivers/gpu/drm/udl/udl_fb.c
39164+++ b/drivers/gpu/drm/udl/udl_fb.c
39165@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
39166 fb_deferred_io_cleanup(info);
39167 kfree(info->fbdefio);
39168 info->fbdefio = NULL;
39169- info->fbops->fb_mmap = udl_fb_mmap;
39170 }
39171
39172 pr_warn("released /dev/fb%d user=%d count=%d\n",
39173diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
39174index 893a650..6190d3b 100644
39175--- a/drivers/gpu/drm/via/via_drv.h
39176+++ b/drivers/gpu/drm/via/via_drv.h
39177@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
39178 typedef uint32_t maskarray_t[5];
39179
39180 typedef struct drm_via_irq {
39181- atomic_t irq_received;
39182+ atomic_unchecked_t irq_received;
39183 uint32_t pending_mask;
39184 uint32_t enable_mask;
39185 wait_queue_head_t irq_queue;
39186@@ -75,7 +75,7 @@ typedef struct drm_via_private {
39187 struct timeval last_vblank;
39188 int last_vblank_valid;
39189 unsigned usec_per_vblank;
39190- atomic_t vbl_received;
39191+ atomic_unchecked_t vbl_received;
39192 drm_via_state_t hc_state;
39193 char pci_buf[VIA_PCI_BUF_SIZE];
39194 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
39195diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
39196index ac98964..5dbf512 100644
39197--- a/drivers/gpu/drm/via/via_irq.c
39198+++ b/drivers/gpu/drm/via/via_irq.c
39199@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
39200 if (crtc != 0)
39201 return 0;
39202
39203- return atomic_read(&dev_priv->vbl_received);
39204+ return atomic_read_unchecked(&dev_priv->vbl_received);
39205 }
39206
39207 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39208@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39209
39210 status = VIA_READ(VIA_REG_INTERRUPT);
39211 if (status & VIA_IRQ_VBLANK_PENDING) {
39212- atomic_inc(&dev_priv->vbl_received);
39213- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
39214+ atomic_inc_unchecked(&dev_priv->vbl_received);
39215+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
39216 do_gettimeofday(&cur_vblank);
39217 if (dev_priv->last_vblank_valid) {
39218 dev_priv->usec_per_vblank =
39219@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39220 dev_priv->last_vblank = cur_vblank;
39221 dev_priv->last_vblank_valid = 1;
39222 }
39223- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
39224+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
39225 DRM_DEBUG("US per vblank is: %u\n",
39226 dev_priv->usec_per_vblank);
39227 }
39228@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39229
39230 for (i = 0; i < dev_priv->num_irqs; ++i) {
39231 if (status & cur_irq->pending_mask) {
39232- atomic_inc(&cur_irq->irq_received);
39233+ atomic_inc_unchecked(&cur_irq->irq_received);
39234 DRM_WAKEUP(&cur_irq->irq_queue);
39235 handled = 1;
39236 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
39237@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
39238 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
39239 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
39240 masks[irq][4]));
39241- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
39242+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
39243 } else {
39244 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
39245 (((cur_irq_sequence =
39246- atomic_read(&cur_irq->irq_received)) -
39247+ atomic_read_unchecked(&cur_irq->irq_received)) -
39248 *sequence) <= (1 << 23)));
39249 }
39250 *sequence = cur_irq_sequence;
39251@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
39252 }
39253
39254 for (i = 0; i < dev_priv->num_irqs; ++i) {
39255- atomic_set(&cur_irq->irq_received, 0);
39256+ atomic_set_unchecked(&cur_irq->irq_received, 0);
39257 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
39258 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
39259 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
39260@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
39261 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
39262 case VIA_IRQ_RELATIVE:
39263 irqwait->request.sequence +=
39264- atomic_read(&cur_irq->irq_received);
39265+ atomic_read_unchecked(&cur_irq->irq_received);
39266 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
39267 case VIA_IRQ_ABSOLUTE:
39268 break;
39269diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
39270index 13aeda7..4a952d1 100644
39271--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
39272+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
39273@@ -290,7 +290,7 @@ struct vmw_private {
39274 * Fencing and IRQs.
39275 */
39276
39277- atomic_t marker_seq;
39278+ atomic_unchecked_t marker_seq;
39279 wait_queue_head_t fence_queue;
39280 wait_queue_head_t fifo_queue;
39281 int fence_queue_waiters; /* Protected by hw_mutex */
39282diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
39283index 3eb1486..0a47ee9 100644
39284--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
39285+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
39286@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
39287 (unsigned int) min,
39288 (unsigned int) fifo->capabilities);
39289
39290- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
39291+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
39292 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
39293 vmw_marker_queue_init(&fifo->marker_queue);
39294 return vmw_fifo_send_fence(dev_priv, &dummy);
39295@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
39296 if (reserveable)
39297 iowrite32(bytes, fifo_mem +
39298 SVGA_FIFO_RESERVED);
39299- return fifo_mem + (next_cmd >> 2);
39300+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
39301 } else {
39302 need_bounce = true;
39303 }
39304@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
39305
39306 fm = vmw_fifo_reserve(dev_priv, bytes);
39307 if (unlikely(fm == NULL)) {
39308- *seqno = atomic_read(&dev_priv->marker_seq);
39309+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
39310 ret = -ENOMEM;
39311 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
39312 false, 3*HZ);
39313@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
39314 }
39315
39316 do {
39317- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
39318+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
39319 } while (*seqno == 0);
39320
39321 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
39322diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
39323index c509d40..3b640c3 100644
39324--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
39325+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
39326@@ -138,7 +138,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
39327 int ret;
39328
39329 num_clips = arg->num_clips;
39330- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
39331+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
39332
39333 if (unlikely(num_clips == 0))
39334 return 0;
39335@@ -222,7 +222,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
39336 int ret;
39337
39338 num_clips = arg->num_clips;
39339- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
39340+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
39341
39342 if (unlikely(num_clips == 0))
39343 return 0;
39344diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
39345index 4640adb..e1384ed 100644
39346--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
39347+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
39348@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
39349 * emitted. Then the fence is stale and signaled.
39350 */
39351
39352- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
39353+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
39354 > VMW_FENCE_WRAP);
39355
39356 return ret;
39357@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
39358
39359 if (fifo_idle)
39360 down_read(&fifo_state->rwsem);
39361- signal_seq = atomic_read(&dev_priv->marker_seq);
39362+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
39363 ret = 0;
39364
39365 for (;;) {
39366diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
39367index 8a8725c2..afed796 100644
39368--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
39369+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
39370@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
39371 while (!vmw_lag_lt(queue, us)) {
39372 spin_lock(&queue->lock);
39373 if (list_empty(&queue->head))
39374- seqno = atomic_read(&dev_priv->marker_seq);
39375+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
39376 else {
39377 marker = list_first_entry(&queue->head,
39378 struct vmw_marker, head);
39379diff --git a/drivers/gpu/host1x/drm/dc.c b/drivers/gpu/host1x/drm/dc.c
39380index 5360e5a..c2c0d26 100644
39381--- a/drivers/gpu/host1x/drm/dc.c
39382+++ b/drivers/gpu/host1x/drm/dc.c
39383@@ -1004,7 +1004,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
39384 }
39385
39386 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
39387- dc->debugfs_files[i].data = dc;
39388+ *(void **)&dc->debugfs_files[i].data = dc;
39389
39390 err = drm_debugfs_create_files(dc->debugfs_files,
39391 ARRAY_SIZE(debugfs_files),
39392diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
39393index 9f60d63..c89e0b7 100644
39394--- a/drivers/hid/hid-core.c
39395+++ b/drivers/hid/hid-core.c
39396@@ -2370,7 +2370,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
39397
39398 int hid_add_device(struct hid_device *hdev)
39399 {
39400- static atomic_t id = ATOMIC_INIT(0);
39401+ static atomic_unchecked_t id = ATOMIC_INIT(0);
39402 int ret;
39403
39404 if (WARN_ON(hdev->status & HID_STAT_ADDED))
39405@@ -2404,7 +2404,7 @@ int hid_add_device(struct hid_device *hdev)
39406 /* XXX hack, any other cleaner solution after the driver core
39407 * is converted to allow more than 20 bytes as the device name? */
39408 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
39409- hdev->vendor, hdev->product, atomic_inc_return(&id));
39410+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
39411
39412 hid_debug_register(hdev, dev_name(&hdev->dev));
39413 ret = device_add(&hdev->dev);
39414diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
39415index c13fb5b..55a3802 100644
39416--- a/drivers/hid/hid-wiimote-debug.c
39417+++ b/drivers/hid/hid-wiimote-debug.c
39418@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
39419 else if (size == 0)
39420 return -EIO;
39421
39422- if (copy_to_user(u, buf, size))
39423+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
39424 return -EFAULT;
39425
39426 *off += size;
39427diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
39428index 145a4cb..2353a3e 100644
39429--- a/drivers/hid/uhid.c
39430+++ b/drivers/hid/uhid.c
39431@@ -47,7 +47,7 @@ struct uhid_device {
39432 struct mutex report_lock;
39433 wait_queue_head_t report_wait;
39434 atomic_t report_done;
39435- atomic_t report_id;
39436+ atomic_unchecked_t report_id;
39437 struct uhid_event report_buf;
39438 };
39439
39440@@ -187,7 +187,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
39441
39442 spin_lock_irqsave(&uhid->qlock, flags);
39443 ev->type = UHID_FEATURE;
39444- ev->u.feature.id = atomic_inc_return(&uhid->report_id);
39445+ ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
39446 ev->u.feature.rnum = rnum;
39447 ev->u.feature.rtype = report_type;
39448
39449@@ -471,7 +471,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
39450 spin_lock_irqsave(&uhid->qlock, flags);
39451
39452 /* id for old report; drop it silently */
39453- if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
39454+ if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
39455 goto unlock;
39456 if (atomic_read(&uhid->report_done))
39457 goto unlock;
39458diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
39459index 6de6c98..18319e9 100644
39460--- a/drivers/hv/channel.c
39461+++ b/drivers/hv/channel.c
39462@@ -406,8 +406,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
39463 int ret = 0;
39464 int t;
39465
39466- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
39467- atomic_inc(&vmbus_connection.next_gpadl_handle);
39468+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
39469+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
39470
39471 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
39472 if (ret)
39473diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
39474index 88f4096..e50452e 100644
39475--- a/drivers/hv/hv.c
39476+++ b/drivers/hv/hv.c
39477@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
39478 u64 output_address = (output) ? virt_to_phys(output) : 0;
39479 u32 output_address_hi = output_address >> 32;
39480 u32 output_address_lo = output_address & 0xFFFFFFFF;
39481- void *hypercall_page = hv_context.hypercall_page;
39482+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
39483
39484 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
39485 "=a"(hv_status_lo) : "d" (control_hi),
39486diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
39487index deb5c25..ed2d4fd 100644
39488--- a/drivers/hv/hv_balloon.c
39489+++ b/drivers/hv/hv_balloon.c
39490@@ -464,7 +464,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
39491
39492 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
39493 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
39494-static atomic_t trans_id = ATOMIC_INIT(0);
39495+static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
39496
39497 static int dm_ring_size = (5 * PAGE_SIZE);
39498
39499@@ -825,7 +825,7 @@ static void hot_add_req(struct work_struct *dummy)
39500 memset(&resp, 0, sizeof(struct dm_hot_add_response));
39501 resp.hdr.type = DM_MEM_HOT_ADD_RESPONSE;
39502 resp.hdr.size = sizeof(struct dm_hot_add_response);
39503- resp.hdr.trans_id = atomic_inc_return(&trans_id);
39504+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39505
39506 #ifdef CONFIG_MEMORY_HOTPLUG
39507 pg_start = dm->ha_wrk.ha_page_range.finfo.start_page;
39508@@ -960,7 +960,7 @@ static void post_status(struct hv_dynmem_device *dm)
39509 memset(&status, 0, sizeof(struct dm_status));
39510 status.hdr.type = DM_STATUS_REPORT;
39511 status.hdr.size = sizeof(struct dm_status);
39512- status.hdr.trans_id = atomic_inc_return(&trans_id);
39513+ status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39514
39515 /*
39516 * The host expects the guest to report free memory.
39517@@ -980,7 +980,7 @@ static void post_status(struct hv_dynmem_device *dm)
39518 * send the status. This can happen if we were interrupted
39519 * after we picked our transaction ID.
39520 */
39521- if (status.hdr.trans_id != atomic_read(&trans_id))
39522+ if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
39523 return;
39524
39525 vmbus_sendpacket(dm->dev->channel, &status,
39526@@ -1081,7 +1081,7 @@ static void balloon_up(struct work_struct *dummy)
39527 bl_resp = (struct dm_balloon_response *)send_buffer;
39528 memset(send_buffer, 0, PAGE_SIZE);
39529 bl_resp->hdr.type = DM_BALLOON_RESPONSE;
39530- bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
39531+ bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39532 bl_resp->hdr.size = sizeof(struct dm_balloon_response);
39533 bl_resp->more_pages = 1;
39534
39535@@ -1152,7 +1152,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
39536
39537 memset(&resp, 0, sizeof(struct dm_unballoon_response));
39538 resp.hdr.type = DM_UNBALLOON_RESPONSE;
39539- resp.hdr.trans_id = atomic_inc_return(&trans_id);
39540+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39541 resp.hdr.size = sizeof(struct dm_unballoon_response);
39542
39543 vmbus_sendpacket(dm_device.dev->channel, &resp,
39544@@ -1215,7 +1215,7 @@ static void version_resp(struct hv_dynmem_device *dm,
39545 memset(&version_req, 0, sizeof(struct dm_version_request));
39546 version_req.hdr.type = DM_VERSION_REQUEST;
39547 version_req.hdr.size = sizeof(struct dm_version_request);
39548- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
39549+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39550 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
39551 version_req.is_last_attempt = 1;
39552
39553@@ -1385,7 +1385,7 @@ static int balloon_probe(struct hv_device *dev,
39554 memset(&version_req, 0, sizeof(struct dm_version_request));
39555 version_req.hdr.type = DM_VERSION_REQUEST;
39556 version_req.hdr.size = sizeof(struct dm_version_request);
39557- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
39558+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39559 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
39560 version_req.is_last_attempt = 0;
39561
39562@@ -1416,7 +1416,7 @@ static int balloon_probe(struct hv_device *dev,
39563 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
39564 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
39565 cap_msg.hdr.size = sizeof(struct dm_capabilities);
39566- cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
39567+ cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39568
39569 cap_msg.caps.cap_bits.balloon = 1;
39570 cap_msg.caps.cap_bits.hot_add = 1;
39571diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
39572index d84918f..7f38f9f 100644
39573--- a/drivers/hv/hyperv_vmbus.h
39574+++ b/drivers/hv/hyperv_vmbus.h
39575@@ -595,7 +595,7 @@ enum vmbus_connect_state {
39576 struct vmbus_connection {
39577 enum vmbus_connect_state conn_state;
39578
39579- atomic_t next_gpadl_handle;
39580+ atomic_unchecked_t next_gpadl_handle;
39581
39582 /*
39583 * Represents channel interrupts. Each bit position represents a
39584diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
39585index e8e071f..5b4b245 100644
39586--- a/drivers/hv/vmbus_drv.c
39587+++ b/drivers/hv/vmbus_drv.c
39588@@ -672,10 +672,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
39589 {
39590 int ret = 0;
39591
39592- static atomic_t device_num = ATOMIC_INIT(0);
39593+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
39594
39595 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
39596- atomic_inc_return(&device_num));
39597+ atomic_inc_return_unchecked(&device_num));
39598
39599 child_device_obj->device.bus = &hv_bus;
39600 child_device_obj->device.parent = &hv_acpi_dev->dev;
39601diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
39602index 6351aba..dc4aaf4 100644
39603--- a/drivers/hwmon/acpi_power_meter.c
39604+++ b/drivers/hwmon/acpi_power_meter.c
39605@@ -117,7 +117,7 @@ struct sensor_template {
39606 struct device_attribute *devattr,
39607 const char *buf, size_t count);
39608 int index;
39609-};
39610+} __do_const;
39611
39612 /* Averaging interval */
39613 static int update_avg_interval(struct acpi_power_meter_resource *resource)
39614@@ -629,7 +629,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
39615 struct sensor_template *attrs)
39616 {
39617 struct device *dev = &resource->acpi_dev->dev;
39618- struct sensor_device_attribute *sensors =
39619+ sensor_device_attribute_no_const *sensors =
39620 &resource->sensors[resource->num_sensors];
39621 int res = 0;
39622
39623diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
39624index 3288f13..71cfb4e 100644
39625--- a/drivers/hwmon/applesmc.c
39626+++ b/drivers/hwmon/applesmc.c
39627@@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
39628 {
39629 struct applesmc_node_group *grp;
39630 struct applesmc_dev_attr *node;
39631- struct attribute *attr;
39632+ attribute_no_const *attr;
39633 int ret, i;
39634
39635 for (grp = groups; grp->format; grp++) {
39636diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
39637index b25c643..a13460d 100644
39638--- a/drivers/hwmon/asus_atk0110.c
39639+++ b/drivers/hwmon/asus_atk0110.c
39640@@ -152,10 +152,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
39641 struct atk_sensor_data {
39642 struct list_head list;
39643 struct atk_data *data;
39644- struct device_attribute label_attr;
39645- struct device_attribute input_attr;
39646- struct device_attribute limit1_attr;
39647- struct device_attribute limit2_attr;
39648+ device_attribute_no_const label_attr;
39649+ device_attribute_no_const input_attr;
39650+ device_attribute_no_const limit1_attr;
39651+ device_attribute_no_const limit2_attr;
39652 char label_attr_name[ATTR_NAME_SIZE];
39653 char input_attr_name[ATTR_NAME_SIZE];
39654 char limit1_attr_name[ATTR_NAME_SIZE];
39655@@ -275,7 +275,7 @@ static ssize_t atk_name_show(struct device *dev,
39656 static struct device_attribute atk_name_attr =
39657 __ATTR(name, 0444, atk_name_show, NULL);
39658
39659-static void atk_init_attribute(struct device_attribute *attr, char *name,
39660+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
39661 sysfs_show_func show)
39662 {
39663 sysfs_attr_init(&attr->attr);
39664diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
39665index 2e5e2dc..5208b31 100644
39666--- a/drivers/hwmon/coretemp.c
39667+++ b/drivers/hwmon/coretemp.c
39668@@ -785,7 +785,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
39669 return NOTIFY_OK;
39670 }
39671
39672-static struct notifier_block coretemp_cpu_notifier __refdata = {
39673+static struct notifier_block coretemp_cpu_notifier = {
39674 .notifier_call = coretemp_cpu_callback,
39675 };
39676
39677diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
39678index 1429f6e..ee03d59 100644
39679--- a/drivers/hwmon/ibmaem.c
39680+++ b/drivers/hwmon/ibmaem.c
39681@@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
39682 struct aem_rw_sensor_template *rw)
39683 {
39684 struct device *dev = &data->pdev->dev;
39685- struct sensor_device_attribute *sensors = data->sensors;
39686+ sensor_device_attribute_no_const *sensors = data->sensors;
39687 int err;
39688
39689 /* Set up read-only sensors */
39690diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
39691index 708081b..fe2d4ab 100644
39692--- a/drivers/hwmon/iio_hwmon.c
39693+++ b/drivers/hwmon/iio_hwmon.c
39694@@ -73,7 +73,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
39695 {
39696 struct device *dev = &pdev->dev;
39697 struct iio_hwmon_state *st;
39698- struct sensor_device_attribute *a;
39699+ sensor_device_attribute_no_const *a;
39700 int ret, i;
39701 int in_i = 1, temp_i = 1, curr_i = 1;
39702 enum iio_chan_type type;
39703diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
39704index 9add6092..ee7ba3f 100644
39705--- a/drivers/hwmon/pmbus/pmbus_core.c
39706+++ b/drivers/hwmon/pmbus/pmbus_core.c
39707@@ -781,7 +781,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
39708 return 0;
39709 }
39710
39711-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
39712+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
39713 const char *name,
39714 umode_t mode,
39715 ssize_t (*show)(struct device *dev,
39716@@ -798,7 +798,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
39717 dev_attr->store = store;
39718 }
39719
39720-static void pmbus_attr_init(struct sensor_device_attribute *a,
39721+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
39722 const char *name,
39723 umode_t mode,
39724 ssize_t (*show)(struct device *dev,
39725@@ -820,7 +820,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
39726 u16 reg, u8 mask)
39727 {
39728 struct pmbus_boolean *boolean;
39729- struct sensor_device_attribute *a;
39730+ sensor_device_attribute_no_const *a;
39731
39732 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
39733 if (!boolean)
39734@@ -845,7 +845,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
39735 bool update, bool readonly)
39736 {
39737 struct pmbus_sensor *sensor;
39738- struct device_attribute *a;
39739+ device_attribute_no_const *a;
39740
39741 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
39742 if (!sensor)
39743@@ -876,7 +876,7 @@ static int pmbus_add_label(struct pmbus_data *data,
39744 const char *lstring, int index)
39745 {
39746 struct pmbus_label *label;
39747- struct device_attribute *a;
39748+ device_attribute_no_const *a;
39749
39750 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
39751 if (!label)
39752diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
39753index 2507f90..1645765 100644
39754--- a/drivers/hwmon/sht15.c
39755+++ b/drivers/hwmon/sht15.c
39756@@ -169,7 +169,7 @@ struct sht15_data {
39757 int supply_uv;
39758 bool supply_uv_valid;
39759 struct work_struct update_supply_work;
39760- atomic_t interrupt_handled;
39761+ atomic_unchecked_t interrupt_handled;
39762 };
39763
39764 /**
39765@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
39766 ret = gpio_direction_input(data->pdata->gpio_data);
39767 if (ret)
39768 return ret;
39769- atomic_set(&data->interrupt_handled, 0);
39770+ atomic_set_unchecked(&data->interrupt_handled, 0);
39771
39772 enable_irq(gpio_to_irq(data->pdata->gpio_data));
39773 if (gpio_get_value(data->pdata->gpio_data) == 0) {
39774 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
39775 /* Only relevant if the interrupt hasn't occurred. */
39776- if (!atomic_read(&data->interrupt_handled))
39777+ if (!atomic_read_unchecked(&data->interrupt_handled))
39778 schedule_work(&data->read_work);
39779 }
39780 ret = wait_event_timeout(data->wait_queue,
39781@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
39782
39783 /* First disable the interrupt */
39784 disable_irq_nosync(irq);
39785- atomic_inc(&data->interrupt_handled);
39786+ atomic_inc_unchecked(&data->interrupt_handled);
39787 /* Then schedule a reading work struct */
39788 if (data->state != SHT15_READING_NOTHING)
39789 schedule_work(&data->read_work);
39790@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
39791 * If not, then start the interrupt again - care here as could
39792 * have gone low in meantime so verify it hasn't!
39793 */
39794- atomic_set(&data->interrupt_handled, 0);
39795+ atomic_set_unchecked(&data->interrupt_handled, 0);
39796 enable_irq(gpio_to_irq(data->pdata->gpio_data));
39797 /* If still not occurred or another handler was scheduled */
39798 if (gpio_get_value(data->pdata->gpio_data)
39799- || atomic_read(&data->interrupt_handled))
39800+ || atomic_read_unchecked(&data->interrupt_handled))
39801 return;
39802 }
39803
39804diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
39805index 38944e9..ae9e5ed 100644
39806--- a/drivers/hwmon/via-cputemp.c
39807+++ b/drivers/hwmon/via-cputemp.c
39808@@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
39809 return NOTIFY_OK;
39810 }
39811
39812-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
39813+static struct notifier_block via_cputemp_cpu_notifier = {
39814 .notifier_call = via_cputemp_cpu_callback,
39815 };
39816
39817diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
39818index 07f01ac..d79ad3d 100644
39819--- a/drivers/i2c/busses/i2c-amd756-s4882.c
39820+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
39821@@ -43,7 +43,7 @@
39822 extern struct i2c_adapter amd756_smbus;
39823
39824 static struct i2c_adapter *s4882_adapter;
39825-static struct i2c_algorithm *s4882_algo;
39826+static i2c_algorithm_no_const *s4882_algo;
39827
39828 /* Wrapper access functions for multiplexed SMBus */
39829 static DEFINE_MUTEX(amd756_lock);
39830diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
39831index 2ca268d..c6acbdf 100644
39832--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
39833+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
39834@@ -41,7 +41,7 @@
39835 extern struct i2c_adapter *nforce2_smbus;
39836
39837 static struct i2c_adapter *s4985_adapter;
39838-static struct i2c_algorithm *s4985_algo;
39839+static i2c_algorithm_no_const *s4985_algo;
39840
39841 /* Wrapper access functions for multiplexed SMBus */
39842 static DEFINE_MUTEX(nforce2_lock);
39843diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
39844index c3ccdea..5b3dc1a 100644
39845--- a/drivers/i2c/i2c-dev.c
39846+++ b/drivers/i2c/i2c-dev.c
39847@@ -271,7 +271,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
39848 break;
39849 }
39850
39851- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
39852+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
39853 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
39854 if (IS_ERR(rdwr_pa[i].buf)) {
39855 res = PTR_ERR(rdwr_pa[i].buf);
39856diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
39857index 0b510ba..4fbb5085 100644
39858--- a/drivers/ide/ide-cd.c
39859+++ b/drivers/ide/ide-cd.c
39860@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
39861 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
39862 if ((unsigned long)buf & alignment
39863 || blk_rq_bytes(rq) & q->dma_pad_mask
39864- || object_is_on_stack(buf))
39865+ || object_starts_on_stack(buf))
39866 drive->dma = 0;
39867 }
39868 }
39869diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
39870index e145931..08bfc59 100644
39871--- a/drivers/iio/industrialio-core.c
39872+++ b/drivers/iio/industrialio-core.c
39873@@ -506,7 +506,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
39874 }
39875
39876 static
39877-int __iio_device_attr_init(struct device_attribute *dev_attr,
39878+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
39879 const char *postfix,
39880 struct iio_chan_spec const *chan,
39881 ssize_t (*readfunc)(struct device *dev,
39882diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
39883index 784b97c..c9ceadf 100644
39884--- a/drivers/infiniband/core/cm.c
39885+++ b/drivers/infiniband/core/cm.c
39886@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
39887
39888 struct cm_counter_group {
39889 struct kobject obj;
39890- atomic_long_t counter[CM_ATTR_COUNT];
39891+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
39892 };
39893
39894 struct cm_counter_attribute {
39895@@ -1395,7 +1395,7 @@ static void cm_dup_req_handler(struct cm_work *work,
39896 struct ib_mad_send_buf *msg = NULL;
39897 int ret;
39898
39899- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
39900+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
39901 counter[CM_REQ_COUNTER]);
39902
39903 /* Quick state check to discard duplicate REQs. */
39904@@ -1779,7 +1779,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
39905 if (!cm_id_priv)
39906 return;
39907
39908- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
39909+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
39910 counter[CM_REP_COUNTER]);
39911 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
39912 if (ret)
39913@@ -1946,7 +1946,7 @@ static int cm_rtu_handler(struct cm_work *work)
39914 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
39915 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
39916 spin_unlock_irq(&cm_id_priv->lock);
39917- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
39918+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
39919 counter[CM_RTU_COUNTER]);
39920 goto out;
39921 }
39922@@ -2129,7 +2129,7 @@ static int cm_dreq_handler(struct cm_work *work)
39923 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
39924 dreq_msg->local_comm_id);
39925 if (!cm_id_priv) {
39926- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
39927+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
39928 counter[CM_DREQ_COUNTER]);
39929 cm_issue_drep(work->port, work->mad_recv_wc);
39930 return -EINVAL;
39931@@ -2154,7 +2154,7 @@ static int cm_dreq_handler(struct cm_work *work)
39932 case IB_CM_MRA_REP_RCVD:
39933 break;
39934 case IB_CM_TIMEWAIT:
39935- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
39936+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
39937 counter[CM_DREQ_COUNTER]);
39938 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
39939 goto unlock;
39940@@ -2168,7 +2168,7 @@ static int cm_dreq_handler(struct cm_work *work)
39941 cm_free_msg(msg);
39942 goto deref;
39943 case IB_CM_DREQ_RCVD:
39944- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
39945+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
39946 counter[CM_DREQ_COUNTER]);
39947 goto unlock;
39948 default:
39949@@ -2535,7 +2535,7 @@ static int cm_mra_handler(struct cm_work *work)
39950 ib_modify_mad(cm_id_priv->av.port->mad_agent,
39951 cm_id_priv->msg, timeout)) {
39952 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
39953- atomic_long_inc(&work->port->
39954+ atomic_long_inc_unchecked(&work->port->
39955 counter_group[CM_RECV_DUPLICATES].
39956 counter[CM_MRA_COUNTER]);
39957 goto out;
39958@@ -2544,7 +2544,7 @@ static int cm_mra_handler(struct cm_work *work)
39959 break;
39960 case IB_CM_MRA_REQ_RCVD:
39961 case IB_CM_MRA_REP_RCVD:
39962- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
39963+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
39964 counter[CM_MRA_COUNTER]);
39965 /* fall through */
39966 default:
39967@@ -2706,7 +2706,7 @@ static int cm_lap_handler(struct cm_work *work)
39968 case IB_CM_LAP_IDLE:
39969 break;
39970 case IB_CM_MRA_LAP_SENT:
39971- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
39972+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
39973 counter[CM_LAP_COUNTER]);
39974 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
39975 goto unlock;
39976@@ -2722,7 +2722,7 @@ static int cm_lap_handler(struct cm_work *work)
39977 cm_free_msg(msg);
39978 goto deref;
39979 case IB_CM_LAP_RCVD:
39980- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
39981+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
39982 counter[CM_LAP_COUNTER]);
39983 goto unlock;
39984 default:
39985@@ -3006,7 +3006,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
39986 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
39987 if (cur_cm_id_priv) {
39988 spin_unlock_irq(&cm.lock);
39989- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
39990+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
39991 counter[CM_SIDR_REQ_COUNTER]);
39992 goto out; /* Duplicate message. */
39993 }
39994@@ -3218,10 +3218,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
39995 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
39996 msg->retries = 1;
39997
39998- atomic_long_add(1 + msg->retries,
39999+ atomic_long_add_unchecked(1 + msg->retries,
40000 &port->counter_group[CM_XMIT].counter[attr_index]);
40001 if (msg->retries)
40002- atomic_long_add(msg->retries,
40003+ atomic_long_add_unchecked(msg->retries,
40004 &port->counter_group[CM_XMIT_RETRIES].
40005 counter[attr_index]);
40006
40007@@ -3431,7 +3431,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
40008 }
40009
40010 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
40011- atomic_long_inc(&port->counter_group[CM_RECV].
40012+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
40013 counter[attr_id - CM_ATTR_ID_OFFSET]);
40014
40015 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
40016@@ -3636,7 +3636,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
40017 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
40018
40019 return sprintf(buf, "%ld\n",
40020- atomic_long_read(&group->counter[cm_attr->index]));
40021+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
40022 }
40023
40024 static const struct sysfs_ops cm_counter_ops = {
40025diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
40026index 9f5ad7c..588cd84 100644
40027--- a/drivers/infiniband/core/fmr_pool.c
40028+++ b/drivers/infiniband/core/fmr_pool.c
40029@@ -98,8 +98,8 @@ struct ib_fmr_pool {
40030
40031 struct task_struct *thread;
40032
40033- atomic_t req_ser;
40034- atomic_t flush_ser;
40035+ atomic_unchecked_t req_ser;
40036+ atomic_unchecked_t flush_ser;
40037
40038 wait_queue_head_t force_wait;
40039 };
40040@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
40041 struct ib_fmr_pool *pool = pool_ptr;
40042
40043 do {
40044- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
40045+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
40046 ib_fmr_batch_release(pool);
40047
40048- atomic_inc(&pool->flush_ser);
40049+ atomic_inc_unchecked(&pool->flush_ser);
40050 wake_up_interruptible(&pool->force_wait);
40051
40052 if (pool->flush_function)
40053@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
40054 }
40055
40056 set_current_state(TASK_INTERRUPTIBLE);
40057- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
40058+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
40059 !kthread_should_stop())
40060 schedule();
40061 __set_current_state(TASK_RUNNING);
40062@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
40063 pool->dirty_watermark = params->dirty_watermark;
40064 pool->dirty_len = 0;
40065 spin_lock_init(&pool->pool_lock);
40066- atomic_set(&pool->req_ser, 0);
40067- atomic_set(&pool->flush_ser, 0);
40068+ atomic_set_unchecked(&pool->req_ser, 0);
40069+ atomic_set_unchecked(&pool->flush_ser, 0);
40070 init_waitqueue_head(&pool->force_wait);
40071
40072 pool->thread = kthread_run(ib_fmr_cleanup_thread,
40073@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
40074 }
40075 spin_unlock_irq(&pool->pool_lock);
40076
40077- serial = atomic_inc_return(&pool->req_ser);
40078+ serial = atomic_inc_return_unchecked(&pool->req_ser);
40079 wake_up_process(pool->thread);
40080
40081 if (wait_event_interruptible(pool->force_wait,
40082- atomic_read(&pool->flush_ser) - serial >= 0))
40083+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
40084 return -EINTR;
40085
40086 return 0;
40087@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
40088 } else {
40089 list_add_tail(&fmr->list, &pool->dirty_list);
40090 if (++pool->dirty_len >= pool->dirty_watermark) {
40091- atomic_inc(&pool->req_ser);
40092+ atomic_inc_unchecked(&pool->req_ser);
40093 wake_up_process(pool->thread);
40094 }
40095 }
40096diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
40097index 4cb8eb2..146bf60 100644
40098--- a/drivers/infiniband/hw/cxgb4/mem.c
40099+++ b/drivers/infiniband/hw/cxgb4/mem.c
40100@@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
40101 int err;
40102 struct fw_ri_tpte tpt;
40103 u32 stag_idx;
40104- static atomic_t key;
40105+ static atomic_unchecked_t key;
40106
40107 if (c4iw_fatal_error(rdev))
40108 return -EIO;
40109@@ -266,7 +266,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
40110 if (rdev->stats.stag.cur > rdev->stats.stag.max)
40111 rdev->stats.stag.max = rdev->stats.stag.cur;
40112 mutex_unlock(&rdev->stats.lock);
40113- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
40114+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
40115 }
40116 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
40117 __func__, stag_state, type, pdid, stag_idx);
40118diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
40119index 79b3dbc..96e5fcc 100644
40120--- a/drivers/infiniband/hw/ipath/ipath_rc.c
40121+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
40122@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
40123 struct ib_atomic_eth *ateth;
40124 struct ipath_ack_entry *e;
40125 u64 vaddr;
40126- atomic64_t *maddr;
40127+ atomic64_unchecked_t *maddr;
40128 u64 sdata;
40129 u32 rkey;
40130 u8 next;
40131@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
40132 IB_ACCESS_REMOTE_ATOMIC)))
40133 goto nack_acc_unlck;
40134 /* Perform atomic OP and save result. */
40135- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
40136+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
40137 sdata = be64_to_cpu(ateth->swap_data);
40138 e = &qp->s_ack_queue[qp->r_head_ack_queue];
40139 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
40140- (u64) atomic64_add_return(sdata, maddr) - sdata :
40141+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
40142 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
40143 be64_to_cpu(ateth->compare_data),
40144 sdata);
40145diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
40146index 1f95bba..9530f87 100644
40147--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
40148+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
40149@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
40150 unsigned long flags;
40151 struct ib_wc wc;
40152 u64 sdata;
40153- atomic64_t *maddr;
40154+ atomic64_unchecked_t *maddr;
40155 enum ib_wc_status send_status;
40156
40157 /*
40158@@ -382,11 +382,11 @@ again:
40159 IB_ACCESS_REMOTE_ATOMIC)))
40160 goto acc_err;
40161 /* Perform atomic OP and save result. */
40162- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
40163+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
40164 sdata = wqe->wr.wr.atomic.compare_add;
40165 *(u64 *) sqp->s_sge.sge.vaddr =
40166 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
40167- (u64) atomic64_add_return(sdata, maddr) - sdata :
40168+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
40169 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
40170 sdata, wqe->wr.wr.atomic.swap);
40171 goto send_comp;
40172diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
40173index f2a3f48..673ec79 100644
40174--- a/drivers/infiniband/hw/mlx4/mad.c
40175+++ b/drivers/infiniband/hw/mlx4/mad.c
40176@@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
40177
40178 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
40179 {
40180- return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
40181+ return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
40182 cpu_to_be64(0xff00000000000000LL);
40183 }
40184
40185diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
40186index 25b2cdf..099ff97 100644
40187--- a/drivers/infiniband/hw/mlx4/mcg.c
40188+++ b/drivers/infiniband/hw/mlx4/mcg.c
40189@@ -1040,7 +1040,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
40190 {
40191 char name[20];
40192
40193- atomic_set(&ctx->tid, 0);
40194+ atomic_set_unchecked(&ctx->tid, 0);
40195 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
40196 ctx->mcg_wq = create_singlethread_workqueue(name);
40197 if (!ctx->mcg_wq)
40198diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
40199index f61ec26..ebf72cf 100644
40200--- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
40201+++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
40202@@ -398,7 +398,7 @@ struct mlx4_ib_demux_ctx {
40203 struct list_head mcg_mgid0_list;
40204 struct workqueue_struct *mcg_wq;
40205 struct mlx4_ib_demux_pv_ctx **tun;
40206- atomic_t tid;
40207+ atomic_unchecked_t tid;
40208 int flushing; /* flushing the work queue */
40209 };
40210
40211diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
40212index 9d3e5c1..d9afe4a 100644
40213--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
40214+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
40215@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
40216 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
40217 }
40218
40219-int mthca_QUERY_FW(struct mthca_dev *dev)
40220+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
40221 {
40222 struct mthca_mailbox *mailbox;
40223 u32 *outbox;
40224diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
40225index ed9a989..e0c5871 100644
40226--- a/drivers/infiniband/hw/mthca/mthca_mr.c
40227+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
40228@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
40229 return key;
40230 }
40231
40232-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
40233+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
40234 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
40235 {
40236 struct mthca_mailbox *mailbox;
40237diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
40238index 4291410..d2ab1fb 100644
40239--- a/drivers/infiniband/hw/nes/nes.c
40240+++ b/drivers/infiniband/hw/nes/nes.c
40241@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
40242 LIST_HEAD(nes_adapter_list);
40243 static LIST_HEAD(nes_dev_list);
40244
40245-atomic_t qps_destroyed;
40246+atomic_unchecked_t qps_destroyed;
40247
40248 static unsigned int ee_flsh_adapter;
40249 static unsigned int sysfs_nonidx_addr;
40250@@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
40251 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
40252 struct nes_adapter *nesadapter = nesdev->nesadapter;
40253
40254- atomic_inc(&qps_destroyed);
40255+ atomic_inc_unchecked(&qps_destroyed);
40256
40257 /* Free the control structures */
40258
40259diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
40260index 33cc589..3bd6538 100644
40261--- a/drivers/infiniband/hw/nes/nes.h
40262+++ b/drivers/infiniband/hw/nes/nes.h
40263@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
40264 extern unsigned int wqm_quanta;
40265 extern struct list_head nes_adapter_list;
40266
40267-extern atomic_t cm_connects;
40268-extern atomic_t cm_accepts;
40269-extern atomic_t cm_disconnects;
40270-extern atomic_t cm_closes;
40271-extern atomic_t cm_connecteds;
40272-extern atomic_t cm_connect_reqs;
40273-extern atomic_t cm_rejects;
40274-extern atomic_t mod_qp_timouts;
40275-extern atomic_t qps_created;
40276-extern atomic_t qps_destroyed;
40277-extern atomic_t sw_qps_destroyed;
40278+extern atomic_unchecked_t cm_connects;
40279+extern atomic_unchecked_t cm_accepts;
40280+extern atomic_unchecked_t cm_disconnects;
40281+extern atomic_unchecked_t cm_closes;
40282+extern atomic_unchecked_t cm_connecteds;
40283+extern atomic_unchecked_t cm_connect_reqs;
40284+extern atomic_unchecked_t cm_rejects;
40285+extern atomic_unchecked_t mod_qp_timouts;
40286+extern atomic_unchecked_t qps_created;
40287+extern atomic_unchecked_t qps_destroyed;
40288+extern atomic_unchecked_t sw_qps_destroyed;
40289 extern u32 mh_detected;
40290 extern u32 mh_pauses_sent;
40291 extern u32 cm_packets_sent;
40292@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
40293 extern u32 cm_packets_received;
40294 extern u32 cm_packets_dropped;
40295 extern u32 cm_packets_retrans;
40296-extern atomic_t cm_listens_created;
40297-extern atomic_t cm_listens_destroyed;
40298+extern atomic_unchecked_t cm_listens_created;
40299+extern atomic_unchecked_t cm_listens_destroyed;
40300 extern u32 cm_backlog_drops;
40301-extern atomic_t cm_loopbacks;
40302-extern atomic_t cm_nodes_created;
40303-extern atomic_t cm_nodes_destroyed;
40304-extern atomic_t cm_accel_dropped_pkts;
40305-extern atomic_t cm_resets_recvd;
40306-extern atomic_t pau_qps_created;
40307-extern atomic_t pau_qps_destroyed;
40308+extern atomic_unchecked_t cm_loopbacks;
40309+extern atomic_unchecked_t cm_nodes_created;
40310+extern atomic_unchecked_t cm_nodes_destroyed;
40311+extern atomic_unchecked_t cm_accel_dropped_pkts;
40312+extern atomic_unchecked_t cm_resets_recvd;
40313+extern atomic_unchecked_t pau_qps_created;
40314+extern atomic_unchecked_t pau_qps_destroyed;
40315
40316 extern u32 int_mod_timer_init;
40317 extern u32 int_mod_cq_depth_256;
40318diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
40319index 24b9f1a..00fd004 100644
40320--- a/drivers/infiniband/hw/nes/nes_cm.c
40321+++ b/drivers/infiniband/hw/nes/nes_cm.c
40322@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
40323 u32 cm_packets_retrans;
40324 u32 cm_packets_created;
40325 u32 cm_packets_received;
40326-atomic_t cm_listens_created;
40327-atomic_t cm_listens_destroyed;
40328+atomic_unchecked_t cm_listens_created;
40329+atomic_unchecked_t cm_listens_destroyed;
40330 u32 cm_backlog_drops;
40331-atomic_t cm_loopbacks;
40332-atomic_t cm_nodes_created;
40333-atomic_t cm_nodes_destroyed;
40334-atomic_t cm_accel_dropped_pkts;
40335-atomic_t cm_resets_recvd;
40336+atomic_unchecked_t cm_loopbacks;
40337+atomic_unchecked_t cm_nodes_created;
40338+atomic_unchecked_t cm_nodes_destroyed;
40339+atomic_unchecked_t cm_accel_dropped_pkts;
40340+atomic_unchecked_t cm_resets_recvd;
40341
40342 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
40343 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
40344@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
40345
40346 static struct nes_cm_core *g_cm_core;
40347
40348-atomic_t cm_connects;
40349-atomic_t cm_accepts;
40350-atomic_t cm_disconnects;
40351-atomic_t cm_closes;
40352-atomic_t cm_connecteds;
40353-atomic_t cm_connect_reqs;
40354-atomic_t cm_rejects;
40355+atomic_unchecked_t cm_connects;
40356+atomic_unchecked_t cm_accepts;
40357+atomic_unchecked_t cm_disconnects;
40358+atomic_unchecked_t cm_closes;
40359+atomic_unchecked_t cm_connecteds;
40360+atomic_unchecked_t cm_connect_reqs;
40361+atomic_unchecked_t cm_rejects;
40362
40363 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
40364 {
40365@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
40366 kfree(listener);
40367 listener = NULL;
40368 ret = 0;
40369- atomic_inc(&cm_listens_destroyed);
40370+ atomic_inc_unchecked(&cm_listens_destroyed);
40371 } else {
40372 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
40373 }
40374@@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
40375 cm_node->rem_mac);
40376
40377 add_hte_node(cm_core, cm_node);
40378- atomic_inc(&cm_nodes_created);
40379+ atomic_inc_unchecked(&cm_nodes_created);
40380
40381 return cm_node;
40382 }
40383@@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
40384 }
40385
40386 atomic_dec(&cm_core->node_cnt);
40387- atomic_inc(&cm_nodes_destroyed);
40388+ atomic_inc_unchecked(&cm_nodes_destroyed);
40389 nesqp = cm_node->nesqp;
40390 if (nesqp) {
40391 nesqp->cm_node = NULL;
40392@@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
40393
40394 static void drop_packet(struct sk_buff *skb)
40395 {
40396- atomic_inc(&cm_accel_dropped_pkts);
40397+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
40398 dev_kfree_skb_any(skb);
40399 }
40400
40401@@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
40402 {
40403
40404 int reset = 0; /* whether to send reset in case of err.. */
40405- atomic_inc(&cm_resets_recvd);
40406+ atomic_inc_unchecked(&cm_resets_recvd);
40407 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
40408 " refcnt=%d\n", cm_node, cm_node->state,
40409 atomic_read(&cm_node->ref_count));
40410@@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
40411 rem_ref_cm_node(cm_node->cm_core, cm_node);
40412 return NULL;
40413 }
40414- atomic_inc(&cm_loopbacks);
40415+ atomic_inc_unchecked(&cm_loopbacks);
40416 loopbackremotenode->loopbackpartner = cm_node;
40417 loopbackremotenode->tcp_cntxt.rcv_wscale =
40418 NES_CM_DEFAULT_RCV_WND_SCALE;
40419@@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
40420 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
40421 else {
40422 rem_ref_cm_node(cm_core, cm_node);
40423- atomic_inc(&cm_accel_dropped_pkts);
40424+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
40425 dev_kfree_skb_any(skb);
40426 }
40427 break;
40428@@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
40429
40430 if ((cm_id) && (cm_id->event_handler)) {
40431 if (issue_disconn) {
40432- atomic_inc(&cm_disconnects);
40433+ atomic_inc_unchecked(&cm_disconnects);
40434 cm_event.event = IW_CM_EVENT_DISCONNECT;
40435 cm_event.status = disconn_status;
40436 cm_event.local_addr = cm_id->local_addr;
40437@@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
40438 }
40439
40440 if (issue_close) {
40441- atomic_inc(&cm_closes);
40442+ atomic_inc_unchecked(&cm_closes);
40443 nes_disconnect(nesqp, 1);
40444
40445 cm_id->provider_data = nesqp;
40446@@ -3033,7 +3033,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
40447
40448 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
40449 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
40450- atomic_inc(&cm_accepts);
40451+ atomic_inc_unchecked(&cm_accepts);
40452
40453 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
40454 netdev_refcnt_read(nesvnic->netdev));
40455@@ -3228,7 +3228,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
40456 struct nes_cm_core *cm_core;
40457 u8 *start_buff;
40458
40459- atomic_inc(&cm_rejects);
40460+ atomic_inc_unchecked(&cm_rejects);
40461 cm_node = (struct nes_cm_node *)cm_id->provider_data;
40462 loopback = cm_node->loopbackpartner;
40463 cm_core = cm_node->cm_core;
40464@@ -3288,7 +3288,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
40465 ntohl(cm_id->local_addr.sin_addr.s_addr),
40466 ntohs(cm_id->local_addr.sin_port));
40467
40468- atomic_inc(&cm_connects);
40469+ atomic_inc_unchecked(&cm_connects);
40470 nesqp->active_conn = 1;
40471
40472 /* cache the cm_id in the qp */
40473@@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
40474 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
40475 return err;
40476 }
40477- atomic_inc(&cm_listens_created);
40478+ atomic_inc_unchecked(&cm_listens_created);
40479 }
40480
40481 cm_id->add_ref(cm_id);
40482@@ -3499,7 +3499,7 @@ static void cm_event_connected(struct nes_cm_event *event)
40483
40484 if (nesqp->destroyed)
40485 return;
40486- atomic_inc(&cm_connecteds);
40487+ atomic_inc_unchecked(&cm_connecteds);
40488 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
40489 " local port 0x%04X. jiffies = %lu.\n",
40490 nesqp->hwqp.qp_id,
40491@@ -3679,7 +3679,7 @@ static void cm_event_reset(struct nes_cm_event *event)
40492
40493 cm_id->add_ref(cm_id);
40494 ret = cm_id->event_handler(cm_id, &cm_event);
40495- atomic_inc(&cm_closes);
40496+ atomic_inc_unchecked(&cm_closes);
40497 cm_event.event = IW_CM_EVENT_CLOSE;
40498 cm_event.status = 0;
40499 cm_event.provider_data = cm_id->provider_data;
40500@@ -3715,7 +3715,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
40501 return;
40502 cm_id = cm_node->cm_id;
40503
40504- atomic_inc(&cm_connect_reqs);
40505+ atomic_inc_unchecked(&cm_connect_reqs);
40506 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
40507 cm_node, cm_id, jiffies);
40508
40509@@ -3755,7 +3755,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
40510 return;
40511 cm_id = cm_node->cm_id;
40512
40513- atomic_inc(&cm_connect_reqs);
40514+ atomic_inc_unchecked(&cm_connect_reqs);
40515 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
40516 cm_node, cm_id, jiffies);
40517
40518diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
40519index 4166452..fc952c3 100644
40520--- a/drivers/infiniband/hw/nes/nes_mgt.c
40521+++ b/drivers/infiniband/hw/nes/nes_mgt.c
40522@@ -40,8 +40,8 @@
40523 #include "nes.h"
40524 #include "nes_mgt.h"
40525
40526-atomic_t pau_qps_created;
40527-atomic_t pau_qps_destroyed;
40528+atomic_unchecked_t pau_qps_created;
40529+atomic_unchecked_t pau_qps_destroyed;
40530
40531 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
40532 {
40533@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
40534 {
40535 struct sk_buff *skb;
40536 unsigned long flags;
40537- atomic_inc(&pau_qps_destroyed);
40538+ atomic_inc_unchecked(&pau_qps_destroyed);
40539
40540 /* Free packets that have not yet been forwarded */
40541 /* Lock is acquired by skb_dequeue when removing the skb */
40542@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
40543 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
40544 skb_queue_head_init(&nesqp->pau_list);
40545 spin_lock_init(&nesqp->pau_lock);
40546- atomic_inc(&pau_qps_created);
40547+ atomic_inc_unchecked(&pau_qps_created);
40548 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
40549 }
40550
40551diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
40552index 49eb511..a774366 100644
40553--- a/drivers/infiniband/hw/nes/nes_nic.c
40554+++ b/drivers/infiniband/hw/nes/nes_nic.c
40555@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
40556 target_stat_values[++index] = mh_detected;
40557 target_stat_values[++index] = mh_pauses_sent;
40558 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
40559- target_stat_values[++index] = atomic_read(&cm_connects);
40560- target_stat_values[++index] = atomic_read(&cm_accepts);
40561- target_stat_values[++index] = atomic_read(&cm_disconnects);
40562- target_stat_values[++index] = atomic_read(&cm_connecteds);
40563- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
40564- target_stat_values[++index] = atomic_read(&cm_rejects);
40565- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
40566- target_stat_values[++index] = atomic_read(&qps_created);
40567- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
40568- target_stat_values[++index] = atomic_read(&qps_destroyed);
40569- target_stat_values[++index] = atomic_read(&cm_closes);
40570+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
40571+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
40572+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
40573+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
40574+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
40575+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
40576+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
40577+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
40578+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
40579+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
40580+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
40581 target_stat_values[++index] = cm_packets_sent;
40582 target_stat_values[++index] = cm_packets_bounced;
40583 target_stat_values[++index] = cm_packets_created;
40584 target_stat_values[++index] = cm_packets_received;
40585 target_stat_values[++index] = cm_packets_dropped;
40586 target_stat_values[++index] = cm_packets_retrans;
40587- target_stat_values[++index] = atomic_read(&cm_listens_created);
40588- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
40589+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
40590+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
40591 target_stat_values[++index] = cm_backlog_drops;
40592- target_stat_values[++index] = atomic_read(&cm_loopbacks);
40593- target_stat_values[++index] = atomic_read(&cm_nodes_created);
40594- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
40595- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
40596- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
40597+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
40598+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
40599+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
40600+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
40601+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
40602 target_stat_values[++index] = nesadapter->free_4kpbl;
40603 target_stat_values[++index] = nesadapter->free_256pbl;
40604 target_stat_values[++index] = int_mod_timer_init;
40605 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
40606 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
40607 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
40608- target_stat_values[++index] = atomic_read(&pau_qps_created);
40609- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
40610+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
40611+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
40612 }
40613
40614 /**
40615diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
40616index 5b53ca5..443da3c 100644
40617--- a/drivers/infiniband/hw/nes/nes_verbs.c
40618+++ b/drivers/infiniband/hw/nes/nes_verbs.c
40619@@ -46,9 +46,9 @@
40620
40621 #include <rdma/ib_umem.h>
40622
40623-atomic_t mod_qp_timouts;
40624-atomic_t qps_created;
40625-atomic_t sw_qps_destroyed;
40626+atomic_unchecked_t mod_qp_timouts;
40627+atomic_unchecked_t qps_created;
40628+atomic_unchecked_t sw_qps_destroyed;
40629
40630 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
40631
40632@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
40633 if (init_attr->create_flags)
40634 return ERR_PTR(-EINVAL);
40635
40636- atomic_inc(&qps_created);
40637+ atomic_inc_unchecked(&qps_created);
40638 switch (init_attr->qp_type) {
40639 case IB_QPT_RC:
40640 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
40641@@ -1466,7 +1466,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
40642 struct iw_cm_event cm_event;
40643 int ret = 0;
40644
40645- atomic_inc(&sw_qps_destroyed);
40646+ atomic_inc_unchecked(&sw_qps_destroyed);
40647 nesqp->destroyed = 1;
40648
40649 /* Blow away the connection if it exists. */
40650diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
40651index 4a9af79..b993f75 100644
40652--- a/drivers/infiniband/hw/qib/qib.h
40653+++ b/drivers/infiniband/hw/qib/qib.h
40654@@ -52,6 +52,7 @@
40655 #include <linux/kref.h>
40656 #include <linux/sched.h>
40657 #include <linux/kthread.h>
40658+#include <linux/slab.h>
40659
40660 #include "qib_common.h"
40661 #include "qib_verbs.h"
40662diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
40663index da739d9..da1c7f4 100644
40664--- a/drivers/input/gameport/gameport.c
40665+++ b/drivers/input/gameport/gameport.c
40666@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
40667 */
40668 static void gameport_init_port(struct gameport *gameport)
40669 {
40670- static atomic_t gameport_no = ATOMIC_INIT(0);
40671+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
40672
40673 __module_get(THIS_MODULE);
40674
40675 mutex_init(&gameport->drv_mutex);
40676 device_initialize(&gameport->dev);
40677 dev_set_name(&gameport->dev, "gameport%lu",
40678- (unsigned long)atomic_inc_return(&gameport_no) - 1);
40679+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
40680 gameport->dev.bus = &gameport_bus;
40681 gameport->dev.release = gameport_release_port;
40682 if (gameport->parent)
40683diff --git a/drivers/input/input.c b/drivers/input/input.c
40684index c044699..174d71a 100644
40685--- a/drivers/input/input.c
40686+++ b/drivers/input/input.c
40687@@ -2019,7 +2019,7 @@ static void devm_input_device_unregister(struct device *dev, void *res)
40688 */
40689 int input_register_device(struct input_dev *dev)
40690 {
40691- static atomic_t input_no = ATOMIC_INIT(0);
40692+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
40693 struct input_devres *devres = NULL;
40694 struct input_handler *handler;
40695 unsigned int packet_size;
40696@@ -2074,7 +2074,7 @@ int input_register_device(struct input_dev *dev)
40697 dev->setkeycode = input_default_setkeycode;
40698
40699 dev_set_name(&dev->dev, "input%ld",
40700- (unsigned long) atomic_inc_return(&input_no) - 1);
40701+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
40702
40703 error = device_add(&dev->dev);
40704 if (error)
40705diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
40706index 04c69af..5f92d00 100644
40707--- a/drivers/input/joystick/sidewinder.c
40708+++ b/drivers/input/joystick/sidewinder.c
40709@@ -30,6 +30,7 @@
40710 #include <linux/kernel.h>
40711 #include <linux/module.h>
40712 #include <linux/slab.h>
40713+#include <linux/sched.h>
40714 #include <linux/init.h>
40715 #include <linux/input.h>
40716 #include <linux/gameport.h>
40717diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
40718index 75e3b10..fb390fd 100644
40719--- a/drivers/input/joystick/xpad.c
40720+++ b/drivers/input/joystick/xpad.c
40721@@ -736,7 +736,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
40722
40723 static int xpad_led_probe(struct usb_xpad *xpad)
40724 {
40725- static atomic_t led_seq = ATOMIC_INIT(0);
40726+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
40727 long led_no;
40728 struct xpad_led *led;
40729 struct led_classdev *led_cdev;
40730@@ -749,7 +749,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
40731 if (!led)
40732 return -ENOMEM;
40733
40734- led_no = (long)atomic_inc_return(&led_seq) - 1;
40735+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
40736
40737 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
40738 led->xpad = xpad;
40739diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
40740index e204f26..8459f15 100644
40741--- a/drivers/input/misc/ims-pcu.c
40742+++ b/drivers/input/misc/ims-pcu.c
40743@@ -1621,7 +1621,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
40744
40745 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
40746 {
40747- static atomic_t device_no = ATOMIC_INIT(0);
40748+ static atomic_unchecked_t device_no = ATOMIC_INIT(0);
40749
40750 const struct ims_pcu_device_info *info;
40751 u8 device_id;
40752@@ -1653,7 +1653,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
40753 }
40754
40755 /* Device appears to be operable, complete initialization */
40756- pcu->device_no = atomic_inc_return(&device_no) - 1;
40757+ pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
40758
40759 error = ims_pcu_setup_backlight(pcu);
40760 if (error)
40761diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
40762index 2f0b39d..7370f13 100644
40763--- a/drivers/input/mouse/psmouse.h
40764+++ b/drivers/input/mouse/psmouse.h
40765@@ -116,7 +116,7 @@ struct psmouse_attribute {
40766 ssize_t (*set)(struct psmouse *psmouse, void *data,
40767 const char *buf, size_t count);
40768 bool protect;
40769-};
40770+} __do_const;
40771 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
40772
40773 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
40774diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
40775index 4c842c3..590b0bf 100644
40776--- a/drivers/input/mousedev.c
40777+++ b/drivers/input/mousedev.c
40778@@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
40779
40780 spin_unlock_irq(&client->packet_lock);
40781
40782- if (copy_to_user(buffer, data, count))
40783+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
40784 return -EFAULT;
40785
40786 return count;
40787diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
40788index 25fc597..558bf3b3 100644
40789--- a/drivers/input/serio/serio.c
40790+++ b/drivers/input/serio/serio.c
40791@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
40792 */
40793 static void serio_init_port(struct serio *serio)
40794 {
40795- static atomic_t serio_no = ATOMIC_INIT(0);
40796+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
40797
40798 __module_get(THIS_MODULE);
40799
40800@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
40801 mutex_init(&serio->drv_mutex);
40802 device_initialize(&serio->dev);
40803 dev_set_name(&serio->dev, "serio%ld",
40804- (long)atomic_inc_return(&serio_no) - 1);
40805+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
40806 serio->dev.bus = &serio_bus;
40807 serio->dev.release = serio_release_port;
40808 serio->dev.groups = serio_device_attr_groups;
40809diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
40810index 59df2e7..8f1cafb 100644
40811--- a/drivers/input/serio/serio_raw.c
40812+++ b/drivers/input/serio/serio_raw.c
40813@@ -293,7 +293,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
40814
40815 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
40816 {
40817- static atomic_t serio_raw_no = ATOMIC_INIT(0);
40818+ static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
40819 struct serio_raw *serio_raw;
40820 int err;
40821
40822@@ -304,7 +304,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
40823 }
40824
40825 snprintf(serio_raw->name, sizeof(serio_raw->name),
40826- "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
40827+ "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
40828 kref_init(&serio_raw->kref);
40829 INIT_LIST_HEAD(&serio_raw->client_list);
40830 init_waitqueue_head(&serio_raw->wait);
40831diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
40832index fbe9ca7..dbee61d 100644
40833--- a/drivers/iommu/iommu.c
40834+++ b/drivers/iommu/iommu.c
40835@@ -583,7 +583,7 @@ static struct notifier_block iommu_bus_nb = {
40836 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
40837 {
40838 bus_register_notifier(bus, &iommu_bus_nb);
40839- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
40840+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
40841 }
40842
40843 /**
40844diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
40845index 39f81ae..2660096 100644
40846--- a/drivers/iommu/irq_remapping.c
40847+++ b/drivers/iommu/irq_remapping.c
40848@@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
40849 void panic_if_irq_remap(const char *msg)
40850 {
40851 if (irq_remapping_enabled)
40852- panic(msg);
40853+ panic("%s", msg);
40854 }
40855
40856 static void ir_ack_apic_edge(struct irq_data *data)
40857@@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
40858
40859 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
40860 {
40861- chip->irq_print_chip = ir_print_prefix;
40862- chip->irq_ack = ir_ack_apic_edge;
40863- chip->irq_eoi = ir_ack_apic_level;
40864- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
40865+ pax_open_kernel();
40866+ *(void **)&chip->irq_print_chip = ir_print_prefix;
40867+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
40868+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
40869+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
40870+ pax_close_kernel();
40871 }
40872
40873 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
40874diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
40875index ee7c503..5d4ce08 100644
40876--- a/drivers/irqchip/irq-gic.c
40877+++ b/drivers/irqchip/irq-gic.c
40878@@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
40879 * Supported arch specific GIC irq extension.
40880 * Default make them NULL.
40881 */
40882-struct irq_chip gic_arch_extn = {
40883+irq_chip_no_const gic_arch_extn = {
40884 .irq_eoi = NULL,
40885 .irq_mask = NULL,
40886 .irq_unmask = NULL,
40887@@ -333,7 +333,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
40888 chained_irq_exit(chip, desc);
40889 }
40890
40891-static struct irq_chip gic_chip = {
40892+static irq_chip_no_const gic_chip __read_only = {
40893 .name = "GIC",
40894 .irq_mask = gic_mask_irq,
40895 .irq_unmask = gic_unmask_irq,
40896diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
40897index ac6f72b..81150f2 100644
40898--- a/drivers/isdn/capi/capi.c
40899+++ b/drivers/isdn/capi/capi.c
40900@@ -81,8 +81,8 @@ struct capiminor {
40901
40902 struct capi20_appl *ap;
40903 u32 ncci;
40904- atomic_t datahandle;
40905- atomic_t msgid;
40906+ atomic_unchecked_t datahandle;
40907+ atomic_unchecked_t msgid;
40908
40909 struct tty_port port;
40910 int ttyinstop;
40911@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
40912 capimsg_setu16(s, 2, mp->ap->applid);
40913 capimsg_setu8 (s, 4, CAPI_DATA_B3);
40914 capimsg_setu8 (s, 5, CAPI_RESP);
40915- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
40916+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
40917 capimsg_setu32(s, 8, mp->ncci);
40918 capimsg_setu16(s, 12, datahandle);
40919 }
40920@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
40921 mp->outbytes -= len;
40922 spin_unlock_bh(&mp->outlock);
40923
40924- datahandle = atomic_inc_return(&mp->datahandle);
40925+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
40926 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
40927 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
40928 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
40929 capimsg_setu16(skb->data, 2, mp->ap->applid);
40930 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
40931 capimsg_setu8 (skb->data, 5, CAPI_REQ);
40932- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
40933+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
40934 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
40935 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
40936 capimsg_setu16(skb->data, 16, len); /* Data length */
40937diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
40938index 600c79b..3752bab 100644
40939--- a/drivers/isdn/gigaset/interface.c
40940+++ b/drivers/isdn/gigaset/interface.c
40941@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
40942 }
40943 tty->driver_data = cs;
40944
40945- ++cs->port.count;
40946+ atomic_inc(&cs->port.count);
40947
40948- if (cs->port.count == 1) {
40949+ if (atomic_read(&cs->port.count) == 1) {
40950 tty_port_tty_set(&cs->port, tty);
40951 cs->port.low_latency = 1;
40952 }
40953@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
40954
40955 if (!cs->connected)
40956 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
40957- else if (!cs->port.count)
40958+ else if (!atomic_read(&cs->port.count))
40959 dev_warn(cs->dev, "%s: device not opened\n", __func__);
40960- else if (!--cs->port.count)
40961+ else if (!atomic_dec_return(&cs->port.count))
40962 tty_port_tty_set(&cs->port, NULL);
40963
40964 mutex_unlock(&cs->mutex);
40965diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
40966index d0a41cb..f0cdb8c 100644
40967--- a/drivers/isdn/gigaset/usb-gigaset.c
40968+++ b/drivers/isdn/gigaset/usb-gigaset.c
40969@@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
40970 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
40971 memcpy(cs->hw.usb->bchars, buf, 6);
40972 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
40973- 0, 0, &buf, 6, 2000);
40974+ 0, 0, buf, 6, 2000);
40975 }
40976
40977 static void gigaset_freebcshw(struct bc_state *bcs)
40978diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
40979index 4d9b195..455075c 100644
40980--- a/drivers/isdn/hardware/avm/b1.c
40981+++ b/drivers/isdn/hardware/avm/b1.c
40982@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
40983 }
40984 if (left) {
40985 if (t4file->user) {
40986- if (copy_from_user(buf, dp, left))
40987+ if (left > sizeof buf || copy_from_user(buf, dp, left))
40988 return -EFAULT;
40989 } else {
40990 memcpy(buf, dp, left);
40991@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
40992 }
40993 if (left) {
40994 if (config->user) {
40995- if (copy_from_user(buf, dp, left))
40996+ if (left > sizeof buf || copy_from_user(buf, dp, left))
40997 return -EFAULT;
40998 } else {
40999 memcpy(buf, dp, left);
41000diff --git a/drivers/isdn/hisax/amd7930_fn.c b/drivers/isdn/hisax/amd7930_fn.c
41001index 1063bab..36817e0 100644
41002--- a/drivers/isdn/hisax/amd7930_fn.c
41003+++ b/drivers/isdn/hisax/amd7930_fn.c
41004@@ -314,7 +314,7 @@ Amd7930_empty_Dfifo(struct IsdnCardState *cs, int flag)
41005
41006 t += sprintf(t, "Amd7930: empty_Dfifo cnt: %d |", cs->rcvidx);
41007 QuickHex(t, cs->rcvbuf, cs->rcvidx);
41008- debugl1(cs, cs->dlog);
41009+ debugl1(cs, "%s", cs->dlog);
41010 }
41011 /* moves received data in sk-buffer */
41012 memcpy(skb_put(skb, cs->rcvidx), cs->rcvbuf, cs->rcvidx);
41013@@ -406,7 +406,7 @@ Amd7930_fill_Dfifo(struct IsdnCardState *cs)
41014
41015 t += sprintf(t, "Amd7930: fill_Dfifo cnt: %d |", count);
41016 QuickHex(t, deb_ptr, count);
41017- debugl1(cs, cs->dlog);
41018+ debugl1(cs, "%s", cs->dlog);
41019 }
41020 /* AMD interrupts on */
41021 AmdIrqOn(cs);
41022diff --git a/drivers/isdn/hisax/avm_pci.c b/drivers/isdn/hisax/avm_pci.c
41023index ee9b9a0..d1427bd 100644
41024--- a/drivers/isdn/hisax/avm_pci.c
41025+++ b/drivers/isdn/hisax/avm_pci.c
41026@@ -285,7 +285,7 @@ hdlc_empty_fifo(struct BCState *bcs, int count)
41027 t += sprintf(t, "hdlc_empty_fifo %c cnt %d",
41028 bcs->channel ? 'B' : 'A', count);
41029 QuickHex(t, p, count);
41030- debugl1(cs, bcs->blog);
41031+ debugl1(cs, "%s", bcs->blog);
41032 }
41033 }
41034
41035@@ -345,7 +345,7 @@ hdlc_fill_fifo(struct BCState *bcs)
41036 t += sprintf(t, "hdlc_fill_fifo %c cnt %d",
41037 bcs->channel ? 'B' : 'A', count);
41038 QuickHex(t, p, count);
41039- debugl1(cs, bcs->blog);
41040+ debugl1(cs, "%s", bcs->blog);
41041 }
41042 }
41043
41044diff --git a/drivers/isdn/hisax/config.c b/drivers/isdn/hisax/config.c
41045index bf04d2a..b33f53b 100644
41046--- a/drivers/isdn/hisax/config.c
41047+++ b/drivers/isdn/hisax/config.c
41048@@ -1896,7 +1896,7 @@ static void EChannel_proc_rcv(struct hisax_d_if *d_if)
41049 ptr--;
41050 *ptr++ = '\n';
41051 *ptr = 0;
41052- HiSax_putstatus(cs, NULL, cs->dlog);
41053+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41054 } else
41055 HiSax_putstatus(cs, "LogEcho: ",
41056 "warning Frame too big (%d)",
41057diff --git a/drivers/isdn/hisax/diva.c b/drivers/isdn/hisax/diva.c
41058index 8d0cf6e..4fc90de 100644
41059--- a/drivers/isdn/hisax/diva.c
41060+++ b/drivers/isdn/hisax/diva.c
41061@@ -427,7 +427,7 @@ Memhscx_empty_fifo(struct BCState *bcs, int count)
41062 t += sprintf(t, "hscx_empty_fifo %c cnt %d",
41063 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41064 QuickHex(t, ptr, count);
41065- debugl1(cs, bcs->blog);
41066+ debugl1(cs, "%s", bcs->blog);
41067 }
41068 }
41069
41070@@ -469,7 +469,7 @@ Memhscx_fill_fifo(struct BCState *bcs)
41071 t += sprintf(t, "hscx_fill_fifo %c cnt %d",
41072 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41073 QuickHex(t, ptr, count);
41074- debugl1(cs, bcs->blog);
41075+ debugl1(cs, "%s", bcs->blog);
41076 }
41077 }
41078
41079diff --git a/drivers/isdn/hisax/elsa.c b/drivers/isdn/hisax/elsa.c
41080index 1df6f9a..2be1c8a 100644
41081--- a/drivers/isdn/hisax/elsa.c
41082+++ b/drivers/isdn/hisax/elsa.c
41083@@ -535,7 +535,7 @@ check_arcofi(struct IsdnCardState *cs)
41084 t = tmp;
41085 t += sprintf(tmp, "Arcofi data");
41086 QuickHex(t, p, cs->dc.isac.mon_rxp);
41087- debugl1(cs, tmp);
41088+ debugl1(cs, "%s", tmp);
41089 if ((cs->dc.isac.mon_rxp == 2) && (cs->dc.isac.mon_rx[0] == 0xa0)) {
41090 switch (cs->dc.isac.mon_rx[1]) {
41091 case 0x80:
41092diff --git a/drivers/isdn/hisax/elsa_ser.c b/drivers/isdn/hisax/elsa_ser.c
41093index d4c98d3..3f84dd8 100644
41094--- a/drivers/isdn/hisax/elsa_ser.c
41095+++ b/drivers/isdn/hisax/elsa_ser.c
41096@@ -344,7 +344,7 @@ static inline void receive_chars(struct IsdnCardState *cs,
41097
41098 t += sprintf(t, "modem read cnt %d", cs->hw.elsa.rcvcnt);
41099 QuickHex(t, cs->hw.elsa.rcvbuf, cs->hw.elsa.rcvcnt);
41100- debugl1(cs, tmp);
41101+ debugl1(cs, "%s", tmp);
41102 }
41103 cs->hw.elsa.rcvcnt = 0;
41104 }
41105diff --git a/drivers/isdn/hisax/hfc_pci.c b/drivers/isdn/hisax/hfc_pci.c
41106index 3ccd724..497bd02 100644
41107--- a/drivers/isdn/hisax/hfc_pci.c
41108+++ b/drivers/isdn/hisax/hfc_pci.c
41109@@ -901,7 +901,7 @@ Begin:
41110 ptr--;
41111 *ptr++ = '\n';
41112 *ptr = 0;
41113- HiSax_putstatus(cs, NULL, cs->dlog);
41114+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41115 } else
41116 HiSax_putstatus(cs, "LogEcho: ", "warning Frame too big (%d)", total - 3);
41117 }
41118diff --git a/drivers/isdn/hisax/hfc_sx.c b/drivers/isdn/hisax/hfc_sx.c
41119index dc4574f..fa1fefd 100644
41120--- a/drivers/isdn/hisax/hfc_sx.c
41121+++ b/drivers/isdn/hisax/hfc_sx.c
41122@@ -674,7 +674,7 @@ receive_emsg(struct IsdnCardState *cs)
41123 ptr--;
41124 *ptr++ = '\n';
41125 *ptr = 0;
41126- HiSax_putstatus(cs, NULL, cs->dlog);
41127+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41128 } else
41129 HiSax_putstatus(cs, "LogEcho: ", "warning Frame too big (%d)", skb->len);
41130 }
41131diff --git a/drivers/isdn/hisax/hscx_irq.c b/drivers/isdn/hisax/hscx_irq.c
41132index f398d48..a8d6188 100644
41133--- a/drivers/isdn/hisax/hscx_irq.c
41134+++ b/drivers/isdn/hisax/hscx_irq.c
41135@@ -75,7 +75,7 @@ hscx_empty_fifo(struct BCState *bcs, int count)
41136 t += sprintf(t, "hscx_empty_fifo %c cnt %d",
41137 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41138 QuickHex(t, ptr, count);
41139- debugl1(cs, bcs->blog);
41140+ debugl1(cs, "%s", bcs->blog);
41141 }
41142 }
41143
41144@@ -115,7 +115,7 @@ hscx_fill_fifo(struct BCState *bcs)
41145 t += sprintf(t, "hscx_fill_fifo %c cnt %d",
41146 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41147 QuickHex(t, ptr, count);
41148- debugl1(cs, bcs->blog);
41149+ debugl1(cs, "%s", bcs->blog);
41150 }
41151 }
41152
41153diff --git a/drivers/isdn/hisax/icc.c b/drivers/isdn/hisax/icc.c
41154index db5321f..51dae91 100644
41155--- a/drivers/isdn/hisax/icc.c
41156+++ b/drivers/isdn/hisax/icc.c
41157@@ -134,7 +134,7 @@ icc_empty_fifo(struct IsdnCardState *cs, int count)
41158
41159 t += sprintf(t, "icc_empty_fifo cnt %d", count);
41160 QuickHex(t, ptr, count);
41161- debugl1(cs, cs->dlog);
41162+ debugl1(cs, "%s", cs->dlog);
41163 }
41164 }
41165
41166@@ -176,7 +176,7 @@ icc_fill_fifo(struct IsdnCardState *cs)
41167
41168 t += sprintf(t, "icc_fill_fifo cnt %d", count);
41169 QuickHex(t, ptr, count);
41170- debugl1(cs, cs->dlog);
41171+ debugl1(cs, "%s", cs->dlog);
41172 }
41173 }
41174
41175diff --git a/drivers/isdn/hisax/ipacx.c b/drivers/isdn/hisax/ipacx.c
41176index 74feb5c..5faa5de 100644
41177--- a/drivers/isdn/hisax/ipacx.c
41178+++ b/drivers/isdn/hisax/ipacx.c
41179@@ -260,7 +260,7 @@ dch_empty_fifo(struct IsdnCardState *cs, int count)
41180
41181 t += sprintf(t, "dch_empty_fifo() cnt %d", count);
41182 QuickHex(t, ptr, count);
41183- debugl1(cs, cs->dlog);
41184+ debugl1(cs, "%s", cs->dlog);
41185 }
41186 }
41187
41188@@ -307,7 +307,7 @@ dch_fill_fifo(struct IsdnCardState *cs)
41189
41190 t += sprintf(t, "dch_fill_fifo() cnt %d", count);
41191 QuickHex(t, ptr, count);
41192- debugl1(cs, cs->dlog);
41193+ debugl1(cs, "%s", cs->dlog);
41194 }
41195 }
41196
41197@@ -539,7 +539,7 @@ bch_empty_fifo(struct BCState *bcs, int count)
41198
41199 t += sprintf(t, "bch_empty_fifo() B-%d cnt %d", hscx, count);
41200 QuickHex(t, ptr, count);
41201- debugl1(cs, bcs->blog);
41202+ debugl1(cs, "%s", bcs->blog);
41203 }
41204 }
41205
41206@@ -582,7 +582,7 @@ bch_fill_fifo(struct BCState *bcs)
41207
41208 t += sprintf(t, "chb_fill_fifo() B-%d cnt %d", hscx, count);
41209 QuickHex(t, ptr, count);
41210- debugl1(cs, bcs->blog);
41211+ debugl1(cs, "%s", bcs->blog);
41212 }
41213 }
41214
41215diff --git a/drivers/isdn/hisax/isac.c b/drivers/isdn/hisax/isac.c
41216index a365ccc..7fdf78f 100644
41217--- a/drivers/isdn/hisax/isac.c
41218+++ b/drivers/isdn/hisax/isac.c
41219@@ -137,7 +137,7 @@ isac_empty_fifo(struct IsdnCardState *cs, int count)
41220
41221 t += sprintf(t, "isac_empty_fifo cnt %d", count);
41222 QuickHex(t, ptr, count);
41223- debugl1(cs, cs->dlog);
41224+ debugl1(cs, "%s", cs->dlog);
41225 }
41226 }
41227
41228@@ -179,7 +179,7 @@ isac_fill_fifo(struct IsdnCardState *cs)
41229
41230 t += sprintf(t, "isac_fill_fifo cnt %d", count);
41231 QuickHex(t, ptr, count);
41232- debugl1(cs, cs->dlog);
41233+ debugl1(cs, "%s", cs->dlog);
41234 }
41235 }
41236
41237diff --git a/drivers/isdn/hisax/isar.c b/drivers/isdn/hisax/isar.c
41238index 7fdf347..f4956c7 100644
41239--- a/drivers/isdn/hisax/isar.c
41240+++ b/drivers/isdn/hisax/isar.c
41241@@ -74,7 +74,7 @@ sendmsg(struct IsdnCardState *cs, u_char his, u_char creg, u_char len,
41242 t = tmp;
41243 t += sprintf(t, "sendmbox cnt %d", len);
41244 QuickHex(t, &msg[len-i], (i > 64) ? 64 : i);
41245- debugl1(cs, tmp);
41246+ debugl1(cs, "%s", tmp);
41247 i -= 64;
41248 }
41249 }
41250@@ -105,7 +105,7 @@ rcv_mbox(struct IsdnCardState *cs, struct isar_reg *ireg, u_char *msg)
41251 t = tmp;
41252 t += sprintf(t, "rcv_mbox cnt %d", ireg->clsb);
41253 QuickHex(t, &msg[ireg->clsb - i], (i > 64) ? 64 : i);
41254- debugl1(cs, tmp);
41255+ debugl1(cs, "%s", tmp);
41256 i -= 64;
41257 }
41258 }
41259@@ -1248,7 +1248,7 @@ isar_int_main(struct IsdnCardState *cs)
41260 tp += sprintf(debbuf, "msg iis(%x) msb(%x)",
41261 ireg->iis, ireg->cmsb);
41262 QuickHex(tp, (u_char *)ireg->par, ireg->clsb);
41263- debugl1(cs, debbuf);
41264+ debugl1(cs, "%s", debbuf);
41265 }
41266 break;
41267 case ISAR_IIS_INVMSG:
41268diff --git a/drivers/isdn/hisax/jade.c b/drivers/isdn/hisax/jade.c
41269index f946c58..e2ae787 100644
41270--- a/drivers/isdn/hisax/jade.c
41271+++ b/drivers/isdn/hisax/jade.c
41272@@ -81,10 +81,7 @@ modejade(struct BCState *bcs, int mode, int bc)
41273 int jade = bcs->hw.hscx.hscx;
41274
41275 if (cs->debug & L1_DEB_HSCX) {
41276- char tmp[40];
41277- sprintf(tmp, "jade %c mode %d ichan %d",
41278- 'A' + jade, mode, bc);
41279- debugl1(cs, tmp);
41280+ debugl1(cs, "jade %c mode %d ichan %d", 'A' + jade, mode, bc);
41281 }
41282 bcs->mode = mode;
41283 bcs->channel = bc;
41284@@ -257,23 +254,18 @@ void
41285 clear_pending_jade_ints(struct IsdnCardState *cs)
41286 {
41287 int val;
41288- char tmp[64];
41289
41290 cs->BC_Write_Reg(cs, 0, jade_HDLC_IMR, 0x00);
41291 cs->BC_Write_Reg(cs, 1, jade_HDLC_IMR, 0x00);
41292
41293 val = cs->BC_Read_Reg(cs, 1, jade_HDLC_ISR);
41294- sprintf(tmp, "jade B ISTA %x", val);
41295- debugl1(cs, tmp);
41296+ debugl1(cs, "jade B ISTA %x", val);
41297 val = cs->BC_Read_Reg(cs, 0, jade_HDLC_ISR);
41298- sprintf(tmp, "jade A ISTA %x", val);
41299- debugl1(cs, tmp);
41300+ debugl1(cs, "jade A ISTA %x", val);
41301 val = cs->BC_Read_Reg(cs, 1, jade_HDLC_STAR);
41302- sprintf(tmp, "jade B STAR %x", val);
41303- debugl1(cs, tmp);
41304+ debugl1(cs, "jade B STAR %x", val);
41305 val = cs->BC_Read_Reg(cs, 0, jade_HDLC_STAR);
41306- sprintf(tmp, "jade A STAR %x", val);
41307- debugl1(cs, tmp);
41308+ debugl1(cs, "jade A STAR %x", val);
41309 /* Unmask ints */
41310 cs->BC_Write_Reg(cs, 0, jade_HDLC_IMR, 0xF8);
41311 cs->BC_Write_Reg(cs, 1, jade_HDLC_IMR, 0xF8);
41312diff --git a/drivers/isdn/hisax/jade_irq.c b/drivers/isdn/hisax/jade_irq.c
41313index f521fc8..b930da9 100644
41314--- a/drivers/isdn/hisax/jade_irq.c
41315+++ b/drivers/isdn/hisax/jade_irq.c
41316@@ -65,7 +65,7 @@ jade_empty_fifo(struct BCState *bcs, int count)
41317 t += sprintf(t, "jade_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@@ -105,7 +105,7 @@ jade_fill_fifo(struct BCState *bcs)
41326 t += sprintf(t, "jade_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/l3_1tr6.c b/drivers/isdn/hisax/l3_1tr6.c
41335index 4c1bca5..875402e 100644
41336--- a/drivers/isdn/hisax/l3_1tr6.c
41337+++ b/drivers/isdn/hisax/l3_1tr6.c
41338@@ -63,7 +63,7 @@ l3_1tr6_error(struct l3_process *pc, u_char *msg, struct sk_buff *skb)
41339 {
41340 dev_kfree_skb(skb);
41341 if (pc->st->l3.debug & L3_DEB_WARN)
41342- l3_debug(pc->st, msg);
41343+ l3_debug(pc->st, "%s", msg);
41344 l3_1tr6_release_req(pc, 0, NULL);
41345 }
41346
41347@@ -161,7 +161,6 @@ l3_1tr6_setup(struct l3_process *pc, u_char pr, void *arg)
41348 {
41349 u_char *p;
41350 int bcfound = 0;
41351- char tmp[80];
41352 struct sk_buff *skb = arg;
41353
41354 /* Channel Identification */
41355@@ -214,10 +213,9 @@ l3_1tr6_setup(struct l3_process *pc, u_char pr, void *arg)
41356 /* Signal all services, linklevel takes care of Service-Indicator */
41357 if (bcfound) {
41358 if ((pc->para.setup.si1 != 7) && (pc->st->l3.debug & L3_DEB_WARN)) {
41359- sprintf(tmp, "non-digital call: %s -> %s",
41360+ l3_debug(pc->st, "non-digital call: %s -> %s",
41361 pc->para.setup.phone,
41362 pc->para.setup.eazmsn);
41363- l3_debug(pc->st, tmp);
41364 }
41365 newl3state(pc, 6);
41366 pc->st->l3.l3l4(pc->st, CC_SETUP | INDICATION, pc);
41367@@ -301,7 +299,7 @@ l3_1tr6_info(struct l3_process *pc, u_char pr, void *arg)
41368 {
41369 u_char *p;
41370 int i, tmpcharge = 0;
41371- char a_charge[8], tmp[32];
41372+ char a_charge[8];
41373 struct sk_buff *skb = arg;
41374
41375 p = skb->data;
41376@@ -316,8 +314,8 @@ l3_1tr6_info(struct l3_process *pc, u_char pr, void *arg)
41377 pc->st->l3.l3l4(pc->st, CC_CHARGE | INDICATION, pc);
41378 }
41379 if (pc->st->l3.debug & L3_DEB_CHARGE) {
41380- sprintf(tmp, "charging info %d", pc->para.chargeinfo);
41381- l3_debug(pc->st, tmp);
41382+ l3_debug(pc->st, "charging info %d",
41383+ pc->para.chargeinfo);
41384 }
41385 } else if (pc->st->l3.debug & L3_DEB_CHARGE)
41386 l3_debug(pc->st, "charging info not found");
41387@@ -399,7 +397,7 @@ l3_1tr6_disc(struct l3_process *pc, u_char pr, void *arg)
41388 struct sk_buff *skb = arg;
41389 u_char *p;
41390 int i, tmpcharge = 0;
41391- char a_charge[8], tmp[32];
41392+ char a_charge[8];
41393
41394 StopAllL3Timer(pc);
41395 p = skb->data;
41396@@ -414,8 +412,8 @@ l3_1tr6_disc(struct l3_process *pc, u_char pr, void *arg)
41397 pc->st->l3.l3l4(pc->st, CC_CHARGE | INDICATION, pc);
41398 }
41399 if (pc->st->l3.debug & L3_DEB_CHARGE) {
41400- sprintf(tmp, "charging info %d", pc->para.chargeinfo);
41401- l3_debug(pc->st, tmp);
41402+ l3_debug(pc->st, "charging info %d",
41403+ pc->para.chargeinfo);
41404 }
41405 } else if (pc->st->l3.debug & L3_DEB_CHARGE)
41406 l3_debug(pc->st, "charging info not found");
41407@@ -746,7 +744,6 @@ up1tr6(struct PStack *st, int pr, void *arg)
41408 int i, mt, cr;
41409 struct l3_process *proc;
41410 struct sk_buff *skb = arg;
41411- char tmp[80];
41412
41413 switch (pr) {
41414 case (DL_DATA | INDICATION):
41415@@ -762,26 +759,23 @@ up1tr6(struct PStack *st, int pr, void *arg)
41416 }
41417 if (skb->len < 4) {
41418 if (st->l3.debug & L3_DEB_PROTERR) {
41419- sprintf(tmp, "up1tr6 len only %d", skb->len);
41420- l3_debug(st, tmp);
41421+ l3_debug(st, "up1tr6 len only %d", skb->len);
41422 }
41423 dev_kfree_skb(skb);
41424 return;
41425 }
41426 if ((skb->data[0] & 0xfe) != PROTO_DIS_N0) {
41427 if (st->l3.debug & L3_DEB_PROTERR) {
41428- sprintf(tmp, "up1tr6%sunexpected discriminator %x message len %d",
41429+ l3_debug(st, "up1tr6%sunexpected discriminator %x message len %d",
41430 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
41431 skb->data[0], skb->len);
41432- l3_debug(st, tmp);
41433 }
41434 dev_kfree_skb(skb);
41435 return;
41436 }
41437 if (skb->data[1] != 1) {
41438 if (st->l3.debug & L3_DEB_PROTERR) {
41439- sprintf(tmp, "up1tr6 CR len not 1");
41440- l3_debug(st, tmp);
41441+ l3_debug(st, "up1tr6 CR len not 1");
41442 }
41443 dev_kfree_skb(skb);
41444 return;
41445@@ -791,9 +785,8 @@ up1tr6(struct PStack *st, int pr, void *arg)
41446 if (skb->data[0] == PROTO_DIS_N0) {
41447 dev_kfree_skb(skb);
41448 if (st->l3.debug & L3_DEB_STATE) {
41449- sprintf(tmp, "up1tr6%s N0 mt %x unhandled",
41450+ l3_debug(st, "up1tr6%s N0 mt %x unhandled",
41451 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ", mt);
41452- l3_debug(st, tmp);
41453 }
41454 } else if (skb->data[0] == PROTO_DIS_N1) {
41455 if (!(proc = getl3proc(st, cr))) {
41456@@ -801,8 +794,7 @@ up1tr6(struct PStack *st, int pr, void *arg)
41457 if (cr < 128) {
41458 if (!(proc = new_l3_process(st, cr))) {
41459 if (st->l3.debug & L3_DEB_PROTERR) {
41460- sprintf(tmp, "up1tr6 no roc mem");
41461- l3_debug(st, tmp);
41462+ l3_debug(st, "up1tr6 no roc mem");
41463 }
41464 dev_kfree_skb(skb);
41465 return;
41466@@ -821,8 +813,7 @@ up1tr6(struct PStack *st, int pr, void *arg)
41467 } else {
41468 if (!(proc = new_l3_process(st, cr))) {
41469 if (st->l3.debug & L3_DEB_PROTERR) {
41470- sprintf(tmp, "up1tr6 no roc mem");
41471- l3_debug(st, tmp);
41472+ l3_debug(st, "up1tr6 no roc mem");
41473 }
41474 dev_kfree_skb(skb);
41475 return;
41476@@ -837,18 +828,16 @@ up1tr6(struct PStack *st, int pr, void *arg)
41477 if (i == ARRAY_SIZE(datastln1)) {
41478 dev_kfree_skb(skb);
41479 if (st->l3.debug & L3_DEB_STATE) {
41480- sprintf(tmp, "up1tr6%sstate %d mt %x unhandled",
41481+ l3_debug(st, "up1tr6%sstate %d mt %x unhandled",
41482 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
41483 proc->state, mt);
41484- l3_debug(st, tmp);
41485 }
41486 return;
41487 } else {
41488 if (st->l3.debug & L3_DEB_STATE) {
41489- sprintf(tmp, "up1tr6%sstate %d mt %x",
41490+ l3_debug(st, "up1tr6%sstate %d mt %x",
41491 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
41492 proc->state, mt);
41493- l3_debug(st, tmp);
41494 }
41495 datastln1[i].rout(proc, pr, skb);
41496 }
41497@@ -861,7 +850,6 @@ down1tr6(struct PStack *st, int pr, void *arg)
41498 int i, cr;
41499 struct l3_process *proc;
41500 struct Channel *chan;
41501- char tmp[80];
41502
41503 if ((DL_ESTABLISH | REQUEST) == pr) {
41504 l3_msg(st, pr, NULL);
41505@@ -888,15 +876,13 @@ down1tr6(struct PStack *st, int pr, void *arg)
41506 break;
41507 if (i == ARRAY_SIZE(downstl)) {
41508 if (st->l3.debug & L3_DEB_STATE) {
41509- sprintf(tmp, "down1tr6 state %d prim %d unhandled",
41510+ l3_debug(st, "down1tr6 state %d prim %d unhandled",
41511 proc->state, pr);
41512- l3_debug(st, tmp);
41513 }
41514 } else {
41515 if (st->l3.debug & L3_DEB_STATE) {
41516- sprintf(tmp, "down1tr6 state %d prim %d",
41517+ l3_debug(st, "down1tr6 state %d prim %d",
41518 proc->state, pr);
41519- l3_debug(st, tmp);
41520 }
41521 downstl[i].rout(proc, pr, arg);
41522 }
41523diff --git a/drivers/isdn/hisax/netjet.c b/drivers/isdn/hisax/netjet.c
41524index b646eed..233e432 100644
41525--- a/drivers/isdn/hisax/netjet.c
41526+++ b/drivers/isdn/hisax/netjet.c
41527@@ -176,7 +176,7 @@ static void printframe(struct IsdnCardState *cs, u_char *buf, int count, char *s
41528 else
41529 j = i;
41530 QuickHex(t, p, j);
41531- debugl1(cs, tmp);
41532+ debugl1(cs, "%s", tmp);
41533 p += j;
41534 i -= j;
41535 t = tmp;
41536diff --git a/drivers/isdn/hisax/q931.c b/drivers/isdn/hisax/q931.c
41537index 041bf52..af1b020 100644
41538--- a/drivers/isdn/hisax/q931.c
41539+++ b/drivers/isdn/hisax/q931.c
41540@@ -1179,7 +1179,7 @@ LogFrame(struct IsdnCardState *cs, u_char *buf, int size)
41541 dp--;
41542 *dp++ = '\n';
41543 *dp = 0;
41544- HiSax_putstatus(cs, NULL, cs->dlog);
41545+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41546 } else
41547 HiSax_putstatus(cs, "LogFrame: ", "warning Frame too big (%d)", size);
41548 }
41549@@ -1246,7 +1246,7 @@ dlogframe(struct IsdnCardState *cs, struct sk_buff *skb, int dir)
41550 }
41551 if (finish) {
41552 *dp = 0;
41553- HiSax_putstatus(cs, NULL, cs->dlog);
41554+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41555 return;
41556 }
41557 if ((0xfe & buf[0]) == PROTO_DIS_N0) { /* 1TR6 */
41558@@ -1509,5 +1509,5 @@ dlogframe(struct IsdnCardState *cs, struct sk_buff *skb, int dir)
41559 dp += sprintf(dp, "Unknown protocol %x!", buf[0]);
41560 }
41561 *dp = 0;
41562- HiSax_putstatus(cs, NULL, cs->dlog);
41563+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41564 }
41565diff --git a/drivers/isdn/hisax/w6692.c b/drivers/isdn/hisax/w6692.c
41566index d8cac69..a858955 100644
41567--- a/drivers/isdn/hisax/w6692.c
41568+++ b/drivers/isdn/hisax/w6692.c
41569@@ -154,7 +154,7 @@ W6692_empty_fifo(struct IsdnCardState *cs, int count)
41570
41571 t += sprintf(t, "W6692_empty_fifo cnt %d", count);
41572 QuickHex(t, ptr, count);
41573- debugl1(cs, cs->dlog);
41574+ debugl1(cs, "%s", cs->dlog);
41575 }
41576 }
41577
41578@@ -196,7 +196,7 @@ W6692_fill_fifo(struct IsdnCardState *cs)
41579
41580 t += sprintf(t, "W6692_fill_fifo cnt %d", count);
41581 QuickHex(t, ptr, count);
41582- debugl1(cs, cs->dlog);
41583+ debugl1(cs, "%s", cs->dlog);
41584 }
41585 }
41586
41587@@ -226,7 +226,7 @@ W6692B_empty_fifo(struct BCState *bcs, int count)
41588 t += sprintf(t, "W6692B_empty_fifo %c cnt %d",
41589 bcs->channel + '1', count);
41590 QuickHex(t, ptr, count);
41591- debugl1(cs, bcs->blog);
41592+ debugl1(cs, "%s", bcs->blog);
41593 }
41594 }
41595
41596@@ -264,7 +264,7 @@ W6692B_fill_fifo(struct BCState *bcs)
41597 t += sprintf(t, "W6692B_fill_fifo %c cnt %d",
41598 bcs->channel + '1', count);
41599 QuickHex(t, ptr, count);
41600- debugl1(cs, bcs->blog);
41601+ debugl1(cs, "%s", bcs->blog);
41602 }
41603 }
41604
41605diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
41606index 9bb12ba..d4262f7 100644
41607--- a/drivers/isdn/i4l/isdn_common.c
41608+++ b/drivers/isdn/i4l/isdn_common.c
41609@@ -1651,6 +1651,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
41610 } else
41611 return -EINVAL;
41612 case IIOCDBGVAR:
41613+ if (!capable(CAP_SYS_RAWIO))
41614+ return -EPERM;
41615 if (arg) {
41616 if (copy_to_user(argp, &dev, sizeof(ulong)))
41617 return -EFAULT;
41618diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
41619index 3c5f249..5fac4d0 100644
41620--- a/drivers/isdn/i4l/isdn_tty.c
41621+++ b/drivers/isdn/i4l/isdn_tty.c
41622@@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
41623
41624 #ifdef ISDN_DEBUG_MODEM_OPEN
41625 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
41626- port->count);
41627+ atomic_read(&port->count));
41628 #endif
41629- port->count++;
41630+ atomic_inc(&port->count);
41631 port->tty = tty;
41632 /*
41633 * Start up serial port
41634@@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
41635 #endif
41636 return;
41637 }
41638- if ((tty->count == 1) && (port->count != 1)) {
41639+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
41640 /*
41641 * Uh, oh. tty->count is 1, which means that the tty
41642 * structure will be freed. Info->count should always
41643@@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
41644 * serial port won't be shutdown.
41645 */
41646 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
41647- "info->count is %d\n", port->count);
41648- port->count = 1;
41649+ "info->count is %d\n", atomic_read(&port->count));
41650+ atomic_set(&port->count, 1);
41651 }
41652- if (--port->count < 0) {
41653+ if (atomic_dec_return(&port->count) < 0) {
41654 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
41655- info->line, port->count);
41656- port->count = 0;
41657+ info->line, atomic_read(&port->count));
41658+ atomic_set(&port->count, 0);
41659 }
41660- if (port->count) {
41661+ if (atomic_read(&port->count)) {
41662 #ifdef ISDN_DEBUG_MODEM_OPEN
41663 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
41664 #endif
41665@@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
41666 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
41667 return;
41668 isdn_tty_shutdown(info);
41669- port->count = 0;
41670+ atomic_set(&port->count, 0);
41671 port->flags &= ~ASYNC_NORMAL_ACTIVE;
41672 port->tty = NULL;
41673 wake_up_interruptible(&port->open_wait);
41674@@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
41675 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
41676 modem_info *info = &dev->mdm.info[i];
41677
41678- if (info->port.count == 0)
41679+ if (atomic_read(&info->port.count) == 0)
41680 continue;
41681 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
41682 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
41683diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
41684index e74df7c..03a03ba 100644
41685--- a/drivers/isdn/icn/icn.c
41686+++ b/drivers/isdn/icn/icn.c
41687@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
41688 if (count > len)
41689 count = len;
41690 if (user) {
41691- if (copy_from_user(msg, buf, count))
41692+ if (count > sizeof msg || copy_from_user(msg, buf, count))
41693 return -EFAULT;
41694 } else
41695 memcpy(msg, buf, count);
41696diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
41697index 6a8405d..0bd1c7e 100644
41698--- a/drivers/leds/leds-clevo-mail.c
41699+++ b/drivers/leds/leds-clevo-mail.c
41700@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
41701 * detected as working, but in reality it is not) as low as
41702 * possible.
41703 */
41704-static struct dmi_system_id __initdata clevo_mail_led_dmi_table[] = {
41705+static const struct dmi_system_id __initconst clevo_mail_led_dmi_table[] = {
41706 {
41707 .callback = clevo_mail_led_dmi_callback,
41708 .ident = "Clevo D410J",
41709diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
41710index 64e204e..c6bf189 100644
41711--- a/drivers/leds/leds-ss4200.c
41712+++ b/drivers/leds/leds-ss4200.c
41713@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
41714 * detected as working, but in reality it is not) as low as
41715 * possible.
41716 */
41717-static struct dmi_system_id __initdata nas_led_whitelist[] = {
41718+static const struct dmi_system_id __initconst nas_led_whitelist[] = {
41719 {
41720 .callback = ss4200_led_dmi_callback,
41721 .ident = "Intel SS4200-E",
41722diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
41723index 0bf1e4e..b4bf44e 100644
41724--- a/drivers/lguest/core.c
41725+++ b/drivers/lguest/core.c
41726@@ -97,9 +97,17 @@ static __init int map_switcher(void)
41727 * The end address needs +1 because __get_vm_area allocates an
41728 * extra guard page, so we need space for that.
41729 */
41730+
41731+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
41732+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
41733+ VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
41734+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
41735+#else
41736 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
41737 VM_ALLOC, switcher_addr, switcher_addr
41738 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
41739+#endif
41740+
41741 if (!switcher_vma) {
41742 err = -ENOMEM;
41743 printk("lguest: could not map switcher pages high\n");
41744@@ -124,7 +132,7 @@ static __init int map_switcher(void)
41745 * Now the Switcher is mapped at the right address, we can't fail!
41746 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
41747 */
41748- memcpy(switcher_vma->addr, start_switcher_text,
41749+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
41750 end_switcher_text - start_switcher_text);
41751
41752 printk(KERN_INFO "lguest: mapped switcher at %p\n",
41753diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
41754index a35d8d1..59fb772 100644
41755--- a/drivers/lguest/page_tables.c
41756+++ b/drivers/lguest/page_tables.c
41757@@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
41758 /*:*/
41759
41760 #ifdef CONFIG_X86_PAE
41761-static void release_pmd(pmd_t *spmd)
41762+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
41763 {
41764 /* If the entry's not present, there's nothing to release. */
41765 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
41766diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
41767index 5169239..47cb4db 100644
41768--- a/drivers/lguest/x86/core.c
41769+++ b/drivers/lguest/x86/core.c
41770@@ -59,7 +59,7 @@ static struct {
41771 /* Offset from where switcher.S was compiled to where we've copied it */
41772 static unsigned long switcher_offset(void)
41773 {
41774- return switcher_addr - (unsigned long)start_switcher_text;
41775+ return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
41776 }
41777
41778 /* This cpu's struct lguest_pages (after the Switcher text page) */
41779@@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
41780 * These copies are pretty cheap, so we do them unconditionally: */
41781 /* Save the current Host top-level page directory.
41782 */
41783+
41784+#ifdef CONFIG_PAX_PER_CPU_PGD
41785+ pages->state.host_cr3 = read_cr3();
41786+#else
41787 pages->state.host_cr3 = __pa(current->mm->pgd);
41788+#endif
41789+
41790 /*
41791 * Set up the Guest's page tables to see this CPU's pages (and no
41792 * other CPU's pages).
41793@@ -475,7 +481,7 @@ void __init lguest_arch_host_init(void)
41794 * compiled-in switcher code and the high-mapped copy we just made.
41795 */
41796 for (i = 0; i < IDT_ENTRIES; i++)
41797- default_idt_entries[i] += switcher_offset();
41798+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
41799
41800 /*
41801 * Set up the Switcher's per-cpu areas.
41802@@ -558,7 +564,7 @@ void __init lguest_arch_host_init(void)
41803 * it will be undisturbed when we switch. To change %cs and jump we
41804 * need this structure to feed to Intel's "lcall" instruction.
41805 */
41806- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
41807+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
41808 lguest_entry.segment = LGUEST_CS;
41809
41810 /*
41811diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
41812index 40634b0..4f5855e 100644
41813--- a/drivers/lguest/x86/switcher_32.S
41814+++ b/drivers/lguest/x86/switcher_32.S
41815@@ -87,6 +87,7 @@
41816 #include <asm/page.h>
41817 #include <asm/segment.h>
41818 #include <asm/lguest.h>
41819+#include <asm/processor-flags.h>
41820
41821 // We mark the start of the code to copy
41822 // It's placed in .text tho it's never run here
41823@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
41824 // Changes type when we load it: damn Intel!
41825 // For after we switch over our page tables
41826 // That entry will be read-only: we'd crash.
41827+
41828+#ifdef CONFIG_PAX_KERNEXEC
41829+ mov %cr0, %edx
41830+ xor $X86_CR0_WP, %edx
41831+ mov %edx, %cr0
41832+#endif
41833+
41834 movl $(GDT_ENTRY_TSS*8), %edx
41835 ltr %dx
41836
41837@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
41838 // Let's clear it again for our return.
41839 // The GDT descriptor of the Host
41840 // Points to the table after two "size" bytes
41841- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
41842+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
41843 // Clear "used" from type field (byte 5, bit 2)
41844- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
41845+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
41846+
41847+#ifdef CONFIG_PAX_KERNEXEC
41848+ mov %cr0, %eax
41849+ xor $X86_CR0_WP, %eax
41850+ mov %eax, %cr0
41851+#endif
41852
41853 // Once our page table's switched, the Guest is live!
41854 // The Host fades as we run this final step.
41855@@ -295,13 +309,12 @@ deliver_to_host:
41856 // I consulted gcc, and it gave
41857 // These instructions, which I gladly credit:
41858 leal (%edx,%ebx,8), %eax
41859- movzwl (%eax),%edx
41860- movl 4(%eax), %eax
41861- xorw %ax, %ax
41862- orl %eax, %edx
41863+ movl 4(%eax), %edx
41864+ movw (%eax), %dx
41865 // Now the address of the handler's in %edx
41866 // We call it now: its "iret" drops us home.
41867- jmp *%edx
41868+ ljmp $__KERNEL_CS, $1f
41869+1: jmp *%edx
41870
41871 // Every interrupt can come to us here
41872 // But we must truly tell each apart.
41873diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
41874index 0003992..854bbce 100644
41875--- a/drivers/md/bcache/closure.h
41876+++ b/drivers/md/bcache/closure.h
41877@@ -622,7 +622,7 @@ static inline void closure_wake_up(struct closure_waitlist *list)
41878 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
41879 struct workqueue_struct *wq)
41880 {
41881- BUG_ON(object_is_on_stack(cl));
41882+ BUG_ON(object_starts_on_stack(cl));
41883 closure_set_ip(cl);
41884 cl->fn = fn;
41885 cl->wq = wq;
41886diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
41887index 547c4c5..5be1de4 100644
41888--- a/drivers/md/bcache/super.c
41889+++ b/drivers/md/bcache/super.c
41890@@ -1644,7 +1644,7 @@ err_unlock_gc:
41891 err:
41892 closure_sync(&op.cl);
41893 /* XXX: test this, it's broken */
41894- bch_cache_set_error(c, err);
41895+ bch_cache_set_error(c, "%s", err);
41896 }
41897
41898 static bool can_attach_cache(struct cache *ca, struct cache_set *c)
41899diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
41900index a7fd821..9dcf6c3 100644
41901--- a/drivers/md/bitmap.c
41902+++ b/drivers/md/bitmap.c
41903@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
41904 chunk_kb ? "KB" : "B");
41905 if (bitmap->storage.file) {
41906 seq_printf(seq, ", file: ");
41907- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
41908+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
41909 }
41910
41911 seq_printf(seq, "\n");
41912diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
41913index f1b7586..a49c4bd 100644
41914--- a/drivers/md/dm-ioctl.c
41915+++ b/drivers/md/dm-ioctl.c
41916@@ -1739,7 +1739,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
41917 cmd == DM_LIST_VERSIONS_CMD)
41918 return 0;
41919
41920- if ((cmd == DM_DEV_CREATE_CMD)) {
41921+ if (cmd == DM_DEV_CREATE_CMD) {
41922 if (!*param->name) {
41923 DMWARN("name not supplied when creating device");
41924 return -EINVAL;
41925diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
41926index 699b5be..eac0a15 100644
41927--- a/drivers/md/dm-raid1.c
41928+++ b/drivers/md/dm-raid1.c
41929@@ -40,7 +40,7 @@ enum dm_raid1_error {
41930
41931 struct mirror {
41932 struct mirror_set *ms;
41933- atomic_t error_count;
41934+ atomic_unchecked_t error_count;
41935 unsigned long error_type;
41936 struct dm_dev *dev;
41937 sector_t offset;
41938@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
41939 struct mirror *m;
41940
41941 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
41942- if (!atomic_read(&m->error_count))
41943+ if (!atomic_read_unchecked(&m->error_count))
41944 return m;
41945
41946 return NULL;
41947@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
41948 * simple way to tell if a device has encountered
41949 * errors.
41950 */
41951- atomic_inc(&m->error_count);
41952+ atomic_inc_unchecked(&m->error_count);
41953
41954 if (test_and_set_bit(error_type, &m->error_type))
41955 return;
41956@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
41957 struct mirror *m = get_default_mirror(ms);
41958
41959 do {
41960- if (likely(!atomic_read(&m->error_count)))
41961+ if (likely(!atomic_read_unchecked(&m->error_count)))
41962 return m;
41963
41964 if (m-- == ms->mirror)
41965@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
41966 {
41967 struct mirror *default_mirror = get_default_mirror(m->ms);
41968
41969- return !atomic_read(&default_mirror->error_count);
41970+ return !atomic_read_unchecked(&default_mirror->error_count);
41971 }
41972
41973 static int mirror_available(struct mirror_set *ms, struct bio *bio)
41974@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
41975 */
41976 if (likely(region_in_sync(ms, region, 1)))
41977 m = choose_mirror(ms, bio->bi_sector);
41978- else if (m && atomic_read(&m->error_count))
41979+ else if (m && atomic_read_unchecked(&m->error_count))
41980 m = NULL;
41981
41982 if (likely(m))
41983@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
41984 }
41985
41986 ms->mirror[mirror].ms = ms;
41987- atomic_set(&(ms->mirror[mirror].error_count), 0);
41988+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
41989 ms->mirror[mirror].error_type = 0;
41990 ms->mirror[mirror].offset = offset;
41991
41992@@ -1340,7 +1340,7 @@ static void mirror_resume(struct dm_target *ti)
41993 */
41994 static char device_status_char(struct mirror *m)
41995 {
41996- if (!atomic_read(&(m->error_count)))
41997+ if (!atomic_read_unchecked(&(m->error_count)))
41998 return 'A';
41999
42000 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
42001diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
42002index d907ca6..cfb8384 100644
42003--- a/drivers/md/dm-stripe.c
42004+++ b/drivers/md/dm-stripe.c
42005@@ -20,7 +20,7 @@ struct stripe {
42006 struct dm_dev *dev;
42007 sector_t physical_start;
42008
42009- atomic_t error_count;
42010+ atomic_unchecked_t error_count;
42011 };
42012
42013 struct stripe_c {
42014@@ -185,7 +185,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
42015 kfree(sc);
42016 return r;
42017 }
42018- atomic_set(&(sc->stripe[i].error_count), 0);
42019+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
42020 }
42021
42022 ti->private = sc;
42023@@ -326,7 +326,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
42024 DMEMIT("%d ", sc->stripes);
42025 for (i = 0; i < sc->stripes; i++) {
42026 DMEMIT("%s ", sc->stripe[i].dev->name);
42027- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
42028+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
42029 'D' : 'A';
42030 }
42031 buffer[i] = '\0';
42032@@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
42033 */
42034 for (i = 0; i < sc->stripes; i++)
42035 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
42036- atomic_inc(&(sc->stripe[i].error_count));
42037- if (atomic_read(&(sc->stripe[i].error_count)) <
42038+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
42039+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
42040 DM_IO_ERROR_THRESHOLD)
42041 schedule_work(&sc->trigger_event);
42042 }
42043diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
42044index f221812..aca962b 100644
42045--- a/drivers/md/dm-table.c
42046+++ b/drivers/md/dm-table.c
42047@@ -354,7 +354,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
42048 if (!dev_size)
42049 return 0;
42050
42051- if ((start >= dev_size) || (start + len > dev_size)) {
42052+ if ((start >= dev_size) || (len > dev_size - start)) {
42053 DMWARN("%s: %s too small for target: "
42054 "start=%llu, len=%llu, dev_size=%llu",
42055 dm_device_name(ti->table->md), bdevname(bdev, b),
42056diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
42057index 60bce43..9b997d0 100644
42058--- a/drivers/md/dm-thin-metadata.c
42059+++ b/drivers/md/dm-thin-metadata.c
42060@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
42061 {
42062 pmd->info.tm = pmd->tm;
42063 pmd->info.levels = 2;
42064- pmd->info.value_type.context = pmd->data_sm;
42065+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
42066 pmd->info.value_type.size = sizeof(__le64);
42067 pmd->info.value_type.inc = data_block_inc;
42068 pmd->info.value_type.dec = data_block_dec;
42069@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
42070
42071 pmd->bl_info.tm = pmd->tm;
42072 pmd->bl_info.levels = 1;
42073- pmd->bl_info.value_type.context = pmd->data_sm;
42074+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
42075 pmd->bl_info.value_type.size = sizeof(__le64);
42076 pmd->bl_info.value_type.inc = data_block_inc;
42077 pmd->bl_info.value_type.dec = data_block_dec;
42078diff --git a/drivers/md/dm.c b/drivers/md/dm.c
42079index 995e1fc..2468cec 100644
42080--- a/drivers/md/dm.c
42081+++ b/drivers/md/dm.c
42082@@ -178,9 +178,9 @@ struct mapped_device {
42083 /*
42084 * Event handling.
42085 */
42086- atomic_t event_nr;
42087+ atomic_unchecked_t event_nr;
42088 wait_queue_head_t eventq;
42089- atomic_t uevent_seq;
42090+ atomic_unchecked_t uevent_seq;
42091 struct list_head uevent_list;
42092 spinlock_t uevent_lock; /* Protect access to uevent_list */
42093
42094@@ -1916,8 +1916,8 @@ static struct mapped_device *alloc_dev(int minor)
42095 spin_lock_init(&md->deferred_lock);
42096 atomic_set(&md->holders, 1);
42097 atomic_set(&md->open_count, 0);
42098- atomic_set(&md->event_nr, 0);
42099- atomic_set(&md->uevent_seq, 0);
42100+ atomic_set_unchecked(&md->event_nr, 0);
42101+ atomic_set_unchecked(&md->uevent_seq, 0);
42102 INIT_LIST_HEAD(&md->uevent_list);
42103 spin_lock_init(&md->uevent_lock);
42104
42105@@ -2068,7 +2068,7 @@ static void event_callback(void *context)
42106
42107 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
42108
42109- atomic_inc(&md->event_nr);
42110+ atomic_inc_unchecked(&md->event_nr);
42111 wake_up(&md->eventq);
42112 }
42113
42114@@ -2727,18 +2727,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
42115
42116 uint32_t dm_next_uevent_seq(struct mapped_device *md)
42117 {
42118- return atomic_add_return(1, &md->uevent_seq);
42119+ return atomic_add_return_unchecked(1, &md->uevent_seq);
42120 }
42121
42122 uint32_t dm_get_event_nr(struct mapped_device *md)
42123 {
42124- return atomic_read(&md->event_nr);
42125+ return atomic_read_unchecked(&md->event_nr);
42126 }
42127
42128 int dm_wait_event(struct mapped_device *md, int event_nr)
42129 {
42130 return wait_event_interruptible(md->eventq,
42131- (event_nr != atomic_read(&md->event_nr)));
42132+ (event_nr != atomic_read_unchecked(&md->event_nr)));
42133 }
42134
42135 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
42136diff --git a/drivers/md/md.c b/drivers/md/md.c
42137index 9f13e13..411a5b8 100644
42138--- a/drivers/md/md.c
42139+++ b/drivers/md/md.c
42140@@ -234,10 +234,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
42141 * start build, activate spare
42142 */
42143 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
42144-static atomic_t md_event_count;
42145+static atomic_unchecked_t md_event_count;
42146 void md_new_event(struct mddev *mddev)
42147 {
42148- atomic_inc(&md_event_count);
42149+ atomic_inc_unchecked(&md_event_count);
42150 wake_up(&md_event_waiters);
42151 }
42152 EXPORT_SYMBOL_GPL(md_new_event);
42153@@ -247,7 +247,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
42154 */
42155 static void md_new_event_inintr(struct mddev *mddev)
42156 {
42157- atomic_inc(&md_event_count);
42158+ atomic_inc_unchecked(&md_event_count);
42159 wake_up(&md_event_waiters);
42160 }
42161
42162@@ -1502,7 +1502,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
42163 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
42164 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
42165 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
42166- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
42167+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
42168
42169 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
42170 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
42171@@ -1746,7 +1746,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
42172 else
42173 sb->resync_offset = cpu_to_le64(0);
42174
42175- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
42176+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
42177
42178 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
42179 sb->size = cpu_to_le64(mddev->dev_sectors);
42180@@ -2751,7 +2751,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
42181 static ssize_t
42182 errors_show(struct md_rdev *rdev, char *page)
42183 {
42184- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
42185+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
42186 }
42187
42188 static ssize_t
42189@@ -2760,7 +2760,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
42190 char *e;
42191 unsigned long n = simple_strtoul(buf, &e, 10);
42192 if (*buf && (*e == 0 || *e == '\n')) {
42193- atomic_set(&rdev->corrected_errors, n);
42194+ atomic_set_unchecked(&rdev->corrected_errors, n);
42195 return len;
42196 }
42197 return -EINVAL;
42198@@ -3208,8 +3208,8 @@ int md_rdev_init(struct md_rdev *rdev)
42199 rdev->sb_loaded = 0;
42200 rdev->bb_page = NULL;
42201 atomic_set(&rdev->nr_pending, 0);
42202- atomic_set(&rdev->read_errors, 0);
42203- atomic_set(&rdev->corrected_errors, 0);
42204+ atomic_set_unchecked(&rdev->read_errors, 0);
42205+ atomic_set_unchecked(&rdev->corrected_errors, 0);
42206
42207 INIT_LIST_HEAD(&rdev->same_set);
42208 init_waitqueue_head(&rdev->blocked_wait);
42209@@ -7024,7 +7024,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
42210
42211 spin_unlock(&pers_lock);
42212 seq_printf(seq, "\n");
42213- seq->poll_event = atomic_read(&md_event_count);
42214+ seq->poll_event = atomic_read_unchecked(&md_event_count);
42215 return 0;
42216 }
42217 if (v == (void*)2) {
42218@@ -7127,7 +7127,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
42219 return error;
42220
42221 seq = file->private_data;
42222- seq->poll_event = atomic_read(&md_event_count);
42223+ seq->poll_event = atomic_read_unchecked(&md_event_count);
42224 return error;
42225 }
42226
42227@@ -7141,7 +7141,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
42228 /* always allow read */
42229 mask = POLLIN | POLLRDNORM;
42230
42231- if (seq->poll_event != atomic_read(&md_event_count))
42232+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
42233 mask |= POLLERR | POLLPRI;
42234 return mask;
42235 }
42236@@ -7185,7 +7185,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
42237 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
42238 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
42239 (int)part_stat_read(&disk->part0, sectors[1]) -
42240- atomic_read(&disk->sync_io);
42241+ atomic_read_unchecked(&disk->sync_io);
42242 /* sync IO will cause sync_io to increase before the disk_stats
42243 * as sync_io is counted when a request starts, and
42244 * disk_stats is counted when it completes.
42245diff --git a/drivers/md/md.h b/drivers/md/md.h
42246index 20f02c0..fd8c821 100644
42247--- a/drivers/md/md.h
42248+++ b/drivers/md/md.h
42249@@ -94,13 +94,13 @@ struct md_rdev {
42250 * only maintained for arrays that
42251 * support hot removal
42252 */
42253- atomic_t read_errors; /* number of consecutive read errors that
42254+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
42255 * we have tried to ignore.
42256 */
42257 struct timespec last_read_error; /* monotonic time since our
42258 * last read error
42259 */
42260- atomic_t corrected_errors; /* number of corrected read errors,
42261+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
42262 * for reporting to userspace and storing
42263 * in superblock.
42264 */
42265@@ -442,7 +442,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
42266
42267 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
42268 {
42269- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
42270+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
42271 }
42272
42273 struct md_personality
42274diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
42275index 3e6d115..ffecdeb 100644
42276--- a/drivers/md/persistent-data/dm-space-map.h
42277+++ b/drivers/md/persistent-data/dm-space-map.h
42278@@ -71,6 +71,7 @@ struct dm_space_map {
42279 dm_sm_threshold_fn fn,
42280 void *context);
42281 };
42282+typedef struct dm_space_map __no_const dm_space_map_no_const;
42283
42284 /*----------------------------------------------------------------*/
42285
42286diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
42287index d60412c..8d4c982 100644
42288--- a/drivers/md/raid1.c
42289+++ b/drivers/md/raid1.c
42290@@ -1823,7 +1823,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
42291 if (r1_sync_page_io(rdev, sect, s,
42292 bio->bi_io_vec[idx].bv_page,
42293 READ) != 0)
42294- atomic_add(s, &rdev->corrected_errors);
42295+ atomic_add_unchecked(s, &rdev->corrected_errors);
42296 }
42297 sectors -= s;
42298 sect += s;
42299@@ -2050,7 +2050,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
42300 test_bit(In_sync, &rdev->flags)) {
42301 if (r1_sync_page_io(rdev, sect, s,
42302 conf->tmppage, READ)) {
42303- atomic_add(s, &rdev->corrected_errors);
42304+ atomic_add_unchecked(s, &rdev->corrected_errors);
42305 printk(KERN_INFO
42306 "md/raid1:%s: read error corrected "
42307 "(%d sectors at %llu on %s)\n",
42308diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
42309index df7b0a0..a257495 100644
42310--- a/drivers/md/raid10.c
42311+++ b/drivers/md/raid10.c
42312@@ -1962,7 +1962,7 @@ static void end_sync_read(struct bio *bio, int error)
42313 /* The write handler will notice the lack of
42314 * R10BIO_Uptodate and record any errors etc
42315 */
42316- atomic_add(r10_bio->sectors,
42317+ atomic_add_unchecked(r10_bio->sectors,
42318 &conf->mirrors[d].rdev->corrected_errors);
42319
42320 /* for reconstruct, we always reschedule after a read.
42321@@ -2320,7 +2320,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
42322 {
42323 struct timespec cur_time_mon;
42324 unsigned long hours_since_last;
42325- unsigned int read_errors = atomic_read(&rdev->read_errors);
42326+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
42327
42328 ktime_get_ts(&cur_time_mon);
42329
42330@@ -2342,9 +2342,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
42331 * overflowing the shift of read_errors by hours_since_last.
42332 */
42333 if (hours_since_last >= 8 * sizeof(read_errors))
42334- atomic_set(&rdev->read_errors, 0);
42335+ atomic_set_unchecked(&rdev->read_errors, 0);
42336 else
42337- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
42338+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
42339 }
42340
42341 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
42342@@ -2398,8 +2398,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42343 return;
42344
42345 check_decay_read_errors(mddev, rdev);
42346- atomic_inc(&rdev->read_errors);
42347- if (atomic_read(&rdev->read_errors) > max_read_errors) {
42348+ atomic_inc_unchecked(&rdev->read_errors);
42349+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
42350 char b[BDEVNAME_SIZE];
42351 bdevname(rdev->bdev, b);
42352
42353@@ -2407,7 +2407,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42354 "md/raid10:%s: %s: Raid device exceeded "
42355 "read_error threshold [cur %d:max %d]\n",
42356 mdname(mddev), b,
42357- atomic_read(&rdev->read_errors), max_read_errors);
42358+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
42359 printk(KERN_NOTICE
42360 "md/raid10:%s: %s: Failing raid device\n",
42361 mdname(mddev), b);
42362@@ -2562,7 +2562,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42363 sect +
42364 choose_data_offset(r10_bio, rdev)),
42365 bdevname(rdev->bdev, b));
42366- atomic_add(s, &rdev->corrected_errors);
42367+ atomic_add_unchecked(s, &rdev->corrected_errors);
42368 }
42369
42370 rdev_dec_pending(rdev, mddev);
42371diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
42372index 78ea443..7d57513 100644
42373--- a/drivers/md/raid5.c
42374+++ b/drivers/md/raid5.c
42375@@ -1764,21 +1764,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
42376 mdname(conf->mddev), STRIPE_SECTORS,
42377 (unsigned long long)s,
42378 bdevname(rdev->bdev, b));
42379- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
42380+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
42381 clear_bit(R5_ReadError, &sh->dev[i].flags);
42382 clear_bit(R5_ReWrite, &sh->dev[i].flags);
42383 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
42384 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
42385
42386- if (atomic_read(&rdev->read_errors))
42387- atomic_set(&rdev->read_errors, 0);
42388+ if (atomic_read_unchecked(&rdev->read_errors))
42389+ atomic_set_unchecked(&rdev->read_errors, 0);
42390 } else {
42391 const char *bdn = bdevname(rdev->bdev, b);
42392 int retry = 0;
42393 int set_bad = 0;
42394
42395 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
42396- atomic_inc(&rdev->read_errors);
42397+ atomic_inc_unchecked(&rdev->read_errors);
42398 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
42399 printk_ratelimited(
42400 KERN_WARNING
42401@@ -1806,7 +1806,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
42402 mdname(conf->mddev),
42403 (unsigned long long)s,
42404 bdn);
42405- } else if (atomic_read(&rdev->read_errors)
42406+ } else if (atomic_read_unchecked(&rdev->read_errors)
42407 > conf->max_nr_stripes)
42408 printk(KERN_WARNING
42409 "md/raid:%s: Too many read errors, failing device %s.\n",
42410diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
42411index 401ef64..836e563 100644
42412--- a/drivers/media/dvb-core/dvbdev.c
42413+++ b/drivers/media/dvb-core/dvbdev.c
42414@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
42415 const struct dvb_device *template, void *priv, int type)
42416 {
42417 struct dvb_device *dvbdev;
42418- struct file_operations *dvbdevfops;
42419+ file_operations_no_const *dvbdevfops;
42420 struct device *clsdev;
42421 int minor;
42422 int id;
42423diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
42424index 9b6c3bb..baeb5c7 100644
42425--- a/drivers/media/dvb-frontends/dib3000.h
42426+++ b/drivers/media/dvb-frontends/dib3000.h
42427@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
42428 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
42429 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
42430 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
42431-};
42432+} __no_const;
42433
42434 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
42435 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
42436diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
42437index ecf21d9..b992428d 100644
42438--- a/drivers/media/pci/cx88/cx88-video.c
42439+++ b/drivers/media/pci/cx88/cx88-video.c
42440@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
42441
42442 /* ------------------------------------------------------------------ */
42443
42444-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42445-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42446-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42447+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42448+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42449+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42450
42451 module_param_array(video_nr, int, NULL, 0444);
42452 module_param_array(vbi_nr, int, NULL, 0444);
42453diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
42454index c08ae3e..eb59af1 100644
42455--- a/drivers/media/pci/ivtv/ivtv-driver.c
42456+++ b/drivers/media/pci/ivtv/ivtv-driver.c
42457@@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
42458 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
42459
42460 /* ivtv instance counter */
42461-static atomic_t ivtv_instance = ATOMIC_INIT(0);
42462+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
42463
42464 /* Parameter declarations */
42465 static int cardtype[IVTV_MAX_CARDS];
42466diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
42467index dfd0a21..6bbb465 100644
42468--- a/drivers/media/platform/omap/omap_vout.c
42469+++ b/drivers/media/platform/omap/omap_vout.c
42470@@ -63,7 +63,6 @@ enum omap_vout_channels {
42471 OMAP_VIDEO2,
42472 };
42473
42474-static struct videobuf_queue_ops video_vbq_ops;
42475 /* Variables configurable through module params*/
42476 static u32 video1_numbuffers = 3;
42477 static u32 video2_numbuffers = 3;
42478@@ -1014,6 +1013,12 @@ static int omap_vout_open(struct file *file)
42479 {
42480 struct videobuf_queue *q;
42481 struct omap_vout_device *vout = NULL;
42482+ static struct videobuf_queue_ops video_vbq_ops = {
42483+ .buf_setup = omap_vout_buffer_setup,
42484+ .buf_prepare = omap_vout_buffer_prepare,
42485+ .buf_release = omap_vout_buffer_release,
42486+ .buf_queue = omap_vout_buffer_queue,
42487+ };
42488
42489 vout = video_drvdata(file);
42490 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
42491@@ -1031,10 +1036,6 @@ static int omap_vout_open(struct file *file)
42492 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
42493
42494 q = &vout->vbq;
42495- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
42496- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
42497- video_vbq_ops.buf_release = omap_vout_buffer_release;
42498- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
42499 spin_lock_init(&vout->vbq_lock);
42500
42501 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
42502diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
42503index 04e6490..2df65bf 100644
42504--- a/drivers/media/platform/s5p-tv/mixer.h
42505+++ b/drivers/media/platform/s5p-tv/mixer.h
42506@@ -156,7 +156,7 @@ struct mxr_layer {
42507 /** layer index (unique identifier) */
42508 int idx;
42509 /** callbacks for layer methods */
42510- struct mxr_layer_ops ops;
42511+ struct mxr_layer_ops *ops;
42512 /** format array */
42513 const struct mxr_format **fmt_array;
42514 /** size of format array */
42515diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
42516index b93a21f..2535195 100644
42517--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
42518+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
42519@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
42520 {
42521 struct mxr_layer *layer;
42522 int ret;
42523- struct mxr_layer_ops ops = {
42524+ static struct mxr_layer_ops ops = {
42525 .release = mxr_graph_layer_release,
42526 .buffer_set = mxr_graph_buffer_set,
42527 .stream_set = mxr_graph_stream_set,
42528diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
42529index b713403..53cb5ad 100644
42530--- a/drivers/media/platform/s5p-tv/mixer_reg.c
42531+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
42532@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
42533 layer->update_buf = next;
42534 }
42535
42536- layer->ops.buffer_set(layer, layer->update_buf);
42537+ layer->ops->buffer_set(layer, layer->update_buf);
42538
42539 if (done && done != layer->shadow_buf)
42540 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
42541diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
42542index 641b1f0..49cff30 100644
42543--- a/drivers/media/platform/s5p-tv/mixer_video.c
42544+++ b/drivers/media/platform/s5p-tv/mixer_video.c
42545@@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
42546 layer->geo.src.height = layer->geo.src.full_height;
42547
42548 mxr_geometry_dump(mdev, &layer->geo);
42549- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42550+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42551 mxr_geometry_dump(mdev, &layer->geo);
42552 }
42553
42554@@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
42555 layer->geo.dst.full_width = mbus_fmt.width;
42556 layer->geo.dst.full_height = mbus_fmt.height;
42557 layer->geo.dst.field = mbus_fmt.field;
42558- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42559+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42560
42561 mxr_geometry_dump(mdev, &layer->geo);
42562 }
42563@@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
42564 /* set source size to highest accepted value */
42565 geo->src.full_width = max(geo->dst.full_width, pix->width);
42566 geo->src.full_height = max(geo->dst.full_height, pix->height);
42567- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
42568+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
42569 mxr_geometry_dump(mdev, &layer->geo);
42570 /* set cropping to total visible screen */
42571 geo->src.width = pix->width;
42572@@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
42573 geo->src.x_offset = 0;
42574 geo->src.y_offset = 0;
42575 /* assure consistency of geometry */
42576- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
42577+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
42578 mxr_geometry_dump(mdev, &layer->geo);
42579 /* set full size to lowest possible value */
42580 geo->src.full_width = 0;
42581 geo->src.full_height = 0;
42582- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
42583+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
42584 mxr_geometry_dump(mdev, &layer->geo);
42585
42586 /* returning results */
42587@@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
42588 target->width = s->r.width;
42589 target->height = s->r.height;
42590
42591- layer->ops.fix_geometry(layer, stage, s->flags);
42592+ layer->ops->fix_geometry(layer, stage, s->flags);
42593
42594 /* retrieve update selection rectangle */
42595 res.left = target->x_offset;
42596@@ -955,13 +955,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
42597 mxr_output_get(mdev);
42598
42599 mxr_layer_update_output(layer);
42600- layer->ops.format_set(layer);
42601+ layer->ops->format_set(layer);
42602 /* enabling layer in hardware */
42603 spin_lock_irqsave(&layer->enq_slock, flags);
42604 layer->state = MXR_LAYER_STREAMING;
42605 spin_unlock_irqrestore(&layer->enq_slock, flags);
42606
42607- layer->ops.stream_set(layer, MXR_ENABLE);
42608+ layer->ops->stream_set(layer, MXR_ENABLE);
42609 mxr_streamer_get(mdev);
42610
42611 return 0;
42612@@ -1031,7 +1031,7 @@ static int stop_streaming(struct vb2_queue *vq)
42613 spin_unlock_irqrestore(&layer->enq_slock, flags);
42614
42615 /* disabling layer in hardware */
42616- layer->ops.stream_set(layer, MXR_DISABLE);
42617+ layer->ops->stream_set(layer, MXR_DISABLE);
42618 /* remove one streamer */
42619 mxr_streamer_put(mdev);
42620 /* allow changes in output configuration */
42621@@ -1070,8 +1070,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
42622
42623 void mxr_layer_release(struct mxr_layer *layer)
42624 {
42625- if (layer->ops.release)
42626- layer->ops.release(layer);
42627+ if (layer->ops->release)
42628+ layer->ops->release(layer);
42629 }
42630
42631 void mxr_base_layer_release(struct mxr_layer *layer)
42632@@ -1097,7 +1097,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
42633
42634 layer->mdev = mdev;
42635 layer->idx = idx;
42636- layer->ops = *ops;
42637+ layer->ops = ops;
42638
42639 spin_lock_init(&layer->enq_slock);
42640 INIT_LIST_HEAD(&layer->enq_list);
42641diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
42642index 3d13a63..da31bf1 100644
42643--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
42644+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
42645@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
42646 {
42647 struct mxr_layer *layer;
42648 int ret;
42649- struct mxr_layer_ops ops = {
42650+ static struct mxr_layer_ops ops = {
42651 .release = mxr_vp_layer_release,
42652 .buffer_set = mxr_vp_buffer_set,
42653 .stream_set = mxr_vp_stream_set,
42654diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
42655index 545c04c..a14bded 100644
42656--- a/drivers/media/radio/radio-cadet.c
42657+++ b/drivers/media/radio/radio-cadet.c
42658@@ -324,6 +324,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
42659 unsigned char readbuf[RDS_BUFFER];
42660 int i = 0;
42661
42662+ if (count > RDS_BUFFER)
42663+ return -EFAULT;
42664 mutex_lock(&dev->lock);
42665 if (dev->rdsstat == 0)
42666 cadet_start_rds(dev);
42667@@ -339,7 +341,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
42668 while (i < count && dev->rdsin != dev->rdsout)
42669 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
42670
42671- if (i && copy_to_user(data, readbuf, i))
42672+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
42673 i = -EFAULT;
42674 unlock:
42675 mutex_unlock(&dev->lock);
42676diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
42677index bd4d3a7..ffc0b9d 100644
42678--- a/drivers/media/radio/radio-maxiradio.c
42679+++ b/drivers/media/radio/radio-maxiradio.c
42680@@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
42681 /* TEA5757 pin mappings */
42682 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
42683
42684-static atomic_t maxiradio_instance = ATOMIC_INIT(0);
42685+static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
42686
42687 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
42688 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
42689diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
42690index 8fa18ab..caee70f 100644
42691--- a/drivers/media/radio/radio-shark.c
42692+++ b/drivers/media/radio/radio-shark.c
42693@@ -79,7 +79,7 @@ struct shark_device {
42694 u32 last_val;
42695 };
42696
42697-static atomic_t shark_instance = ATOMIC_INIT(0);
42698+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
42699
42700 static void shark_write_val(struct snd_tea575x *tea, u32 val)
42701 {
42702diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
42703index 9fb6697..f167415 100644
42704--- a/drivers/media/radio/radio-shark2.c
42705+++ b/drivers/media/radio/radio-shark2.c
42706@@ -74,7 +74,7 @@ struct shark_device {
42707 u8 *transfer_buffer;
42708 };
42709
42710-static atomic_t shark_instance = ATOMIC_INIT(0);
42711+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
42712
42713 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
42714 {
42715diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
42716index 9c9084c..a9e8dfb 100644
42717--- a/drivers/media/radio/radio-si476x.c
42718+++ b/drivers/media/radio/radio-si476x.c
42719@@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
42720 struct si476x_radio *radio;
42721 struct v4l2_ctrl *ctrl;
42722
42723- static atomic_t instance = ATOMIC_INIT(0);
42724+ static atomic_unchecked_t instance = ATOMIC_INIT(0);
42725
42726 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
42727 if (!radio)
42728diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
42729index 1cf382a..c22998c 100644
42730--- a/drivers/media/rc/rc-main.c
42731+++ b/drivers/media/rc/rc-main.c
42732@@ -1030,7 +1030,7 @@ EXPORT_SYMBOL_GPL(rc_free_device);
42733 int rc_register_device(struct rc_dev *dev)
42734 {
42735 static bool raw_init = false; /* raw decoders loaded? */
42736- static atomic_t devno = ATOMIC_INIT(0);
42737+ static atomic_unchecked_t devno = ATOMIC_INIT(0);
42738 struct rc_map *rc_map;
42739 const char *path;
42740 int rc;
42741@@ -1061,7 +1061,7 @@ int rc_register_device(struct rc_dev *dev)
42742 */
42743 mutex_lock(&dev->lock);
42744
42745- dev->devno = (unsigned long)(atomic_inc_return(&devno) - 1);
42746+ dev->devno = (unsigned long)(atomic_inc_return_unchecked(&devno) - 1);
42747 dev_set_name(&dev->dev, "rc%ld", dev->devno);
42748 dev_set_drvdata(&dev->dev, dev);
42749 rc = device_add(&dev->dev);
42750diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
42751index 3940bb0..fb3952a 100644
42752--- a/drivers/media/usb/dvb-usb/cxusb.c
42753+++ b/drivers/media/usb/dvb-usb/cxusb.c
42754@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
42755
42756 struct dib0700_adapter_state {
42757 int (*set_param_save) (struct dvb_frontend *);
42758-};
42759+} __no_const;
42760
42761 static int dib7070_set_param_override(struct dvb_frontend *fe)
42762 {
42763diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
42764index 6e237b6..dc25556 100644
42765--- a/drivers/media/usb/dvb-usb/dw2102.c
42766+++ b/drivers/media/usb/dvb-usb/dw2102.c
42767@@ -118,7 +118,7 @@ struct su3000_state {
42768
42769 struct s6x0_state {
42770 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
42771-};
42772+} __no_const;
42773
42774 /* debug */
42775 static int dvb_usb_dw2102_debug;
42776diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
42777index 8f7a6a4..59502dd 100644
42778--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
42779+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
42780@@ -326,7 +326,7 @@ struct v4l2_buffer32 {
42781 __u32 reserved;
42782 };
42783
42784-static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
42785+static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
42786 enum v4l2_memory memory)
42787 {
42788 void __user *up_pln;
42789@@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
42790 return 0;
42791 }
42792
42793-static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
42794+static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
42795 enum v4l2_memory memory)
42796 {
42797 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
42798@@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
42799 put_user(kp->start_block, &up->start_block) ||
42800 put_user(kp->blocks, &up->blocks) ||
42801 put_user(tmp, &up->edid) ||
42802- copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
42803+ copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
42804 return -EFAULT;
42805 return 0;
42806 }
42807diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
42808index 02d1b63..5fd6b16 100644
42809--- a/drivers/media/v4l2-core/v4l2-device.c
42810+++ b/drivers/media/v4l2-core/v4l2-device.c
42811@@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
42812 EXPORT_SYMBOL_GPL(v4l2_device_put);
42813
42814 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
42815- atomic_t *instance)
42816+ atomic_unchecked_t *instance)
42817 {
42818- int num = atomic_inc_return(instance) - 1;
42819+ int num = atomic_inc_return_unchecked(instance) - 1;
42820 int len = strlen(basename);
42821
42822 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
42823diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
42824index 68e6b5e..d8b923e 100644
42825--- a/drivers/media/v4l2-core/v4l2-ioctl.c
42826+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
42827@@ -1939,7 +1939,8 @@ struct v4l2_ioctl_info {
42828 struct file *file, void *fh, void *p);
42829 } u;
42830 void (*debug)(const void *arg, bool write_only);
42831-};
42832+} __do_const;
42833+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
42834
42835 /* This control needs a priority check */
42836 #define INFO_FL_PRIO (1 << 0)
42837@@ -2120,7 +2121,7 @@ static long __video_do_ioctl(struct file *file,
42838 struct video_device *vfd = video_devdata(file);
42839 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
42840 bool write_only = false;
42841- struct v4l2_ioctl_info default_info;
42842+ v4l2_ioctl_info_no_const default_info;
42843 const struct v4l2_ioctl_info *info;
42844 void *fh = file->private_data;
42845 struct v4l2_fh *vfh = NULL;
42846@@ -2194,7 +2195,7 @@ done:
42847 }
42848
42849 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
42850- void * __user *user_ptr, void ***kernel_ptr)
42851+ void __user **user_ptr, void ***kernel_ptr)
42852 {
42853 int ret = 0;
42854
42855@@ -2210,7 +2211,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
42856 ret = -EINVAL;
42857 break;
42858 }
42859- *user_ptr = (void __user *)buf->m.planes;
42860+ *user_ptr = (void __force_user *)buf->m.planes;
42861 *kernel_ptr = (void *)&buf->m.planes;
42862 *array_size = sizeof(struct v4l2_plane) * buf->length;
42863 ret = 1;
42864@@ -2245,7 +2246,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
42865 ret = -EINVAL;
42866 break;
42867 }
42868- *user_ptr = (void __user *)ctrls->controls;
42869+ *user_ptr = (void __force_user *)ctrls->controls;
42870 *kernel_ptr = (void *)&ctrls->controls;
42871 *array_size = sizeof(struct v4l2_ext_control)
42872 * ctrls->count;
42873diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
42874index 767ff4d..c69d259 100644
42875--- a/drivers/message/fusion/mptbase.c
42876+++ b/drivers/message/fusion/mptbase.c
42877@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
42878 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
42879 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
42880
42881+#ifdef CONFIG_GRKERNSEC_HIDESYM
42882+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
42883+#else
42884 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
42885 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
42886+#endif
42887+
42888 /*
42889 * Rounding UP to nearest 4-kB boundary here...
42890 */
42891@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
42892 ioc->facts.GlobalCredits);
42893
42894 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
42895+#ifdef CONFIG_GRKERNSEC_HIDESYM
42896+ NULL, NULL);
42897+#else
42898 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
42899+#endif
42900 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
42901 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
42902 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
42903diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
42904index dd239bd..689c4f7 100644
42905--- a/drivers/message/fusion/mptsas.c
42906+++ b/drivers/message/fusion/mptsas.c
42907@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
42908 return 0;
42909 }
42910
42911+static inline void
42912+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
42913+{
42914+ if (phy_info->port_details) {
42915+ phy_info->port_details->rphy = rphy;
42916+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
42917+ ioc->name, rphy));
42918+ }
42919+
42920+ if (rphy) {
42921+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
42922+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
42923+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
42924+ ioc->name, rphy, rphy->dev.release));
42925+ }
42926+}
42927+
42928 /* no mutex */
42929 static void
42930 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
42931@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
42932 return NULL;
42933 }
42934
42935-static inline void
42936-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
42937-{
42938- if (phy_info->port_details) {
42939- phy_info->port_details->rphy = rphy;
42940- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
42941- ioc->name, rphy));
42942- }
42943-
42944- if (rphy) {
42945- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
42946- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
42947- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
42948- ioc->name, rphy, rphy->dev.release));
42949- }
42950-}
42951-
42952 static inline struct sas_port *
42953 mptsas_get_port(struct mptsas_phyinfo *phy_info)
42954 {
42955diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
42956index 727819c..ad74694 100644
42957--- a/drivers/message/fusion/mptscsih.c
42958+++ b/drivers/message/fusion/mptscsih.c
42959@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
42960
42961 h = shost_priv(SChost);
42962
42963- if (h) {
42964- if (h->info_kbuf == NULL)
42965- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
42966- return h->info_kbuf;
42967- h->info_kbuf[0] = '\0';
42968+ if (!h)
42969+ return NULL;
42970
42971- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
42972- h->info_kbuf[size-1] = '\0';
42973- }
42974+ if (h->info_kbuf == NULL)
42975+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
42976+ return h->info_kbuf;
42977+ h->info_kbuf[0] = '\0';
42978+
42979+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
42980+ h->info_kbuf[size-1] = '\0';
42981
42982 return h->info_kbuf;
42983 }
42984diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
42985index b7d87cd..9890039 100644
42986--- a/drivers/message/i2o/i2o_proc.c
42987+++ b/drivers/message/i2o/i2o_proc.c
42988@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
42989 "Array Controller Device"
42990 };
42991
42992-static char *chtostr(char *tmp, u8 *chars, int n)
42993-{
42994- tmp[0] = 0;
42995- return strncat(tmp, (char *)chars, n);
42996-}
42997-
42998 static int i2o_report_query_status(struct seq_file *seq, int block_status,
42999 char *group)
43000 {
43001@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
43002 } *result;
43003
43004 i2o_exec_execute_ddm_table ddm_table;
43005- char tmp[28 + 1];
43006
43007 result = kmalloc(sizeof(*result), GFP_KERNEL);
43008 if (!result)
43009@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
43010
43011 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
43012 seq_printf(seq, "%-#8x", ddm_table.module_id);
43013- seq_printf(seq, "%-29s",
43014- chtostr(tmp, ddm_table.module_name_version, 28));
43015+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
43016 seq_printf(seq, "%9d ", ddm_table.data_size);
43017 seq_printf(seq, "%8d", ddm_table.code_size);
43018
43019@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
43020
43021 i2o_driver_result_table *result;
43022 i2o_driver_store_table *dst;
43023- char tmp[28 + 1];
43024
43025 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
43026 if (result == NULL)
43027@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
43028
43029 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
43030 seq_printf(seq, "%-#8x", dst->module_id);
43031- seq_printf(seq, "%-29s",
43032- chtostr(tmp, dst->module_name_version, 28));
43033- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
43034+ seq_printf(seq, "%-.28s", dst->module_name_version);
43035+ seq_printf(seq, "%-.8s", dst->date);
43036 seq_printf(seq, "%8d ", dst->module_size);
43037 seq_printf(seq, "%8d ", dst->mpb_size);
43038 seq_printf(seq, "0x%04x", dst->module_flags);
43039@@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
43040 // == (allow) 512d bytes (max)
43041 static u16 *work16 = (u16 *) work32;
43042 int token;
43043- char tmp[16 + 1];
43044
43045 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
43046
43047@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
43048 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
43049 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
43050 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
43051- seq_printf(seq, "Vendor info : %s\n",
43052- chtostr(tmp, (u8 *) (work32 + 2), 16));
43053- seq_printf(seq, "Product info : %s\n",
43054- chtostr(tmp, (u8 *) (work32 + 6), 16));
43055- seq_printf(seq, "Description : %s\n",
43056- chtostr(tmp, (u8 *) (work32 + 10), 16));
43057- seq_printf(seq, "Product rev. : %s\n",
43058- chtostr(tmp, (u8 *) (work32 + 14), 8));
43059+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
43060+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
43061+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
43062+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
43063
43064 seq_printf(seq, "Serial number : ");
43065 print_serial_number(seq, (u8 *) (work32 + 16),
43066@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
43067 u8 pad[256]; // allow up to 256 byte (max) serial number
43068 } result;
43069
43070- char tmp[24 + 1];
43071-
43072 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
43073
43074 if (token < 0) {
43075@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
43076 }
43077
43078 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
43079- seq_printf(seq, "Module name : %s\n",
43080- chtostr(tmp, result.module_name, 24));
43081- seq_printf(seq, "Module revision : %s\n",
43082- chtostr(tmp, result.module_rev, 8));
43083+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
43084+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
43085
43086 seq_printf(seq, "Serial number : ");
43087 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
43088@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
43089 u8 instance_number[4];
43090 } result;
43091
43092- char tmp[64 + 1];
43093-
43094 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
43095
43096 if (token < 0) {
43097@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
43098 return 0;
43099 }
43100
43101- seq_printf(seq, "Device name : %s\n",
43102- chtostr(tmp, result.device_name, 64));
43103- seq_printf(seq, "Service name : %s\n",
43104- chtostr(tmp, result.service_name, 64));
43105- seq_printf(seq, "Physical name : %s\n",
43106- chtostr(tmp, result.physical_location, 64));
43107- seq_printf(seq, "Instance number : %s\n",
43108- chtostr(tmp, result.instance_number, 4));
43109+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
43110+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
43111+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
43112+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
43113
43114 return 0;
43115 }
43116diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
43117index a8c08f3..155fe3d 100644
43118--- a/drivers/message/i2o/iop.c
43119+++ b/drivers/message/i2o/iop.c
43120@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
43121
43122 spin_lock_irqsave(&c->context_list_lock, flags);
43123
43124- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
43125- atomic_inc(&c->context_list_counter);
43126+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
43127+ atomic_inc_unchecked(&c->context_list_counter);
43128
43129- entry->context = atomic_read(&c->context_list_counter);
43130+ entry->context = atomic_read_unchecked(&c->context_list_counter);
43131
43132 list_add(&entry->list, &c->context_list);
43133
43134@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
43135
43136 #if BITS_PER_LONG == 64
43137 spin_lock_init(&c->context_list_lock);
43138- atomic_set(&c->context_list_counter, 0);
43139+ atomic_set_unchecked(&c->context_list_counter, 0);
43140 INIT_LIST_HEAD(&c->context_list);
43141 #endif
43142
43143diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
43144index fcbb2e9..2635e11 100644
43145--- a/drivers/mfd/janz-cmodio.c
43146+++ b/drivers/mfd/janz-cmodio.c
43147@@ -13,6 +13,7 @@
43148
43149 #include <linux/kernel.h>
43150 #include <linux/module.h>
43151+#include <linux/slab.h>
43152 #include <linux/init.h>
43153 #include <linux/pci.h>
43154 #include <linux/interrupt.h>
43155diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
43156index 9aa6d1e..1631bfc 100644
43157--- a/drivers/mfd/twl4030-irq.c
43158+++ b/drivers/mfd/twl4030-irq.c
43159@@ -35,6 +35,7 @@
43160 #include <linux/of.h>
43161 #include <linux/irqdomain.h>
43162 #include <linux/i2c/twl.h>
43163+#include <asm/pgtable.h>
43164
43165 #include "twl-core.h"
43166
43167@@ -726,10 +727,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
43168 * Install an irq handler for each of the SIH modules;
43169 * clone dummy irq_chip since PIH can't *do* anything
43170 */
43171- twl4030_irq_chip = dummy_irq_chip;
43172- twl4030_irq_chip.name = "twl4030";
43173+ pax_open_kernel();
43174+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
43175+ *(const char **)&twl4030_irq_chip.name = "twl4030";
43176
43177- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
43178+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
43179+ pax_close_kernel();
43180
43181 for (i = irq_base; i < irq_end; i++) {
43182 irq_set_chip_and_handler(i, &twl4030_irq_chip,
43183diff --git a/drivers/mfd/twl6030-irq.c b/drivers/mfd/twl6030-irq.c
43184index 277a8db..0e0b754 100644
43185--- a/drivers/mfd/twl6030-irq.c
43186+++ b/drivers/mfd/twl6030-irq.c
43187@@ -387,10 +387,12 @@ int twl6030_init_irq(struct device *dev, int irq_num)
43188 * install an irq handler for each of the modules;
43189 * clone dummy irq_chip since PIH can't *do* anything
43190 */
43191- twl6030_irq_chip = dummy_irq_chip;
43192- twl6030_irq_chip.name = "twl6030";
43193- twl6030_irq_chip.irq_set_type = NULL;
43194- twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
43195+ pax_open_kernel();
43196+ memcpy((void *)&twl6030_irq_chip, &dummy_irq_chip, sizeof twl6030_irq_chip);
43197+ *(const char **)&twl6030_irq_chip.name = "twl6030";
43198+ *(void **)&twl6030_irq_chip.irq_set_type = NULL;
43199+ *(void **)&twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
43200+ pax_close_kernel();
43201
43202 for (i = irq_base; i < irq_end; i++) {
43203 irq_set_chip_and_handler(i, &twl6030_irq_chip,
43204diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
43205index f32550a..e3e52a2 100644
43206--- a/drivers/misc/c2port/core.c
43207+++ b/drivers/misc/c2port/core.c
43208@@ -920,7 +920,9 @@ struct c2port_device *c2port_device_register(char *name,
43209 mutex_init(&c2dev->mutex);
43210
43211 /* Create binary file */
43212- c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
43213+ pax_open_kernel();
43214+ *(size_t *)&c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
43215+ pax_close_kernel();
43216 ret = device_create_bin_file(c2dev->dev, &c2port_bin_attrs);
43217 if (unlikely(ret))
43218 goto error_device_create_bin_file;
43219diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
43220index 36f5d52..32311c3 100644
43221--- a/drivers/misc/kgdbts.c
43222+++ b/drivers/misc/kgdbts.c
43223@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
43224 char before[BREAK_INSTR_SIZE];
43225 char after[BREAK_INSTR_SIZE];
43226
43227- probe_kernel_read(before, (char *)kgdbts_break_test,
43228+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
43229 BREAK_INSTR_SIZE);
43230 init_simple_test();
43231 ts.tst = plant_and_detach_test;
43232@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
43233 /* Activate test with initial breakpoint */
43234 if (!is_early)
43235 kgdb_breakpoint();
43236- probe_kernel_read(after, (char *)kgdbts_break_test,
43237+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
43238 BREAK_INSTR_SIZE);
43239 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
43240 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
43241diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
43242index 036effe..b3a6336 100644
43243--- a/drivers/misc/lis3lv02d/lis3lv02d.c
43244+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
43245@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
43246 * the lid is closed. This leads to interrupts as soon as a little move
43247 * is done.
43248 */
43249- atomic_inc(&lis3->count);
43250+ atomic_inc_unchecked(&lis3->count);
43251
43252 wake_up_interruptible(&lis3->misc_wait);
43253 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
43254@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
43255 if (lis3->pm_dev)
43256 pm_runtime_get_sync(lis3->pm_dev);
43257
43258- atomic_set(&lis3->count, 0);
43259+ atomic_set_unchecked(&lis3->count, 0);
43260 return 0;
43261 }
43262
43263@@ -616,7 +616,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
43264 add_wait_queue(&lis3->misc_wait, &wait);
43265 while (true) {
43266 set_current_state(TASK_INTERRUPTIBLE);
43267- data = atomic_xchg(&lis3->count, 0);
43268+ data = atomic_xchg_unchecked(&lis3->count, 0);
43269 if (data)
43270 break;
43271
43272@@ -657,7 +657,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
43273 struct lis3lv02d, miscdev);
43274
43275 poll_wait(file, &lis3->misc_wait, wait);
43276- if (atomic_read(&lis3->count))
43277+ if (atomic_read_unchecked(&lis3->count))
43278 return POLLIN | POLLRDNORM;
43279 return 0;
43280 }
43281diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
43282index c439c82..1f20f57 100644
43283--- a/drivers/misc/lis3lv02d/lis3lv02d.h
43284+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
43285@@ -297,7 +297,7 @@ struct lis3lv02d {
43286 struct input_polled_dev *idev; /* input device */
43287 struct platform_device *pdev; /* platform device */
43288 struct regulator_bulk_data regulators[2];
43289- atomic_t count; /* interrupt count after last read */
43290+ atomic_unchecked_t count; /* interrupt count after last read */
43291 union axis_conversion ac; /* hw -> logical axis */
43292 int mapped_btns[3];
43293
43294diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
43295index 2f30bad..c4c13d0 100644
43296--- a/drivers/misc/sgi-gru/gruhandles.c
43297+++ b/drivers/misc/sgi-gru/gruhandles.c
43298@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
43299 unsigned long nsec;
43300
43301 nsec = CLKS2NSEC(clks);
43302- atomic_long_inc(&mcs_op_statistics[op].count);
43303- atomic_long_add(nsec, &mcs_op_statistics[op].total);
43304+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
43305+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
43306 if (mcs_op_statistics[op].max < nsec)
43307 mcs_op_statistics[op].max = nsec;
43308 }
43309diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
43310index 4f76359..cdfcb2e 100644
43311--- a/drivers/misc/sgi-gru/gruprocfs.c
43312+++ b/drivers/misc/sgi-gru/gruprocfs.c
43313@@ -32,9 +32,9 @@
43314
43315 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
43316
43317-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
43318+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
43319 {
43320- unsigned long val = atomic_long_read(v);
43321+ unsigned long val = atomic_long_read_unchecked(v);
43322
43323 seq_printf(s, "%16lu %s\n", val, id);
43324 }
43325@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
43326
43327 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
43328 for (op = 0; op < mcsop_last; op++) {
43329- count = atomic_long_read(&mcs_op_statistics[op].count);
43330- total = atomic_long_read(&mcs_op_statistics[op].total);
43331+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
43332+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
43333 max = mcs_op_statistics[op].max;
43334 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
43335 count ? total / count : 0, max);
43336diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
43337index 5c3ce24..4915ccb 100644
43338--- a/drivers/misc/sgi-gru/grutables.h
43339+++ b/drivers/misc/sgi-gru/grutables.h
43340@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
43341 * GRU statistics.
43342 */
43343 struct gru_stats_s {
43344- atomic_long_t vdata_alloc;
43345- atomic_long_t vdata_free;
43346- atomic_long_t gts_alloc;
43347- atomic_long_t gts_free;
43348- atomic_long_t gms_alloc;
43349- atomic_long_t gms_free;
43350- atomic_long_t gts_double_allocate;
43351- atomic_long_t assign_context;
43352- atomic_long_t assign_context_failed;
43353- atomic_long_t free_context;
43354- atomic_long_t load_user_context;
43355- atomic_long_t load_kernel_context;
43356- atomic_long_t lock_kernel_context;
43357- atomic_long_t unlock_kernel_context;
43358- atomic_long_t steal_user_context;
43359- atomic_long_t steal_kernel_context;
43360- atomic_long_t steal_context_failed;
43361- atomic_long_t nopfn;
43362- atomic_long_t asid_new;
43363- atomic_long_t asid_next;
43364- atomic_long_t asid_wrap;
43365- atomic_long_t asid_reuse;
43366- atomic_long_t intr;
43367- atomic_long_t intr_cbr;
43368- atomic_long_t intr_tfh;
43369- atomic_long_t intr_spurious;
43370- atomic_long_t intr_mm_lock_failed;
43371- atomic_long_t call_os;
43372- atomic_long_t call_os_wait_queue;
43373- atomic_long_t user_flush_tlb;
43374- atomic_long_t user_unload_context;
43375- atomic_long_t user_exception;
43376- atomic_long_t set_context_option;
43377- atomic_long_t check_context_retarget_intr;
43378- atomic_long_t check_context_unload;
43379- atomic_long_t tlb_dropin;
43380- atomic_long_t tlb_preload_page;
43381- atomic_long_t tlb_dropin_fail_no_asid;
43382- atomic_long_t tlb_dropin_fail_upm;
43383- atomic_long_t tlb_dropin_fail_invalid;
43384- atomic_long_t tlb_dropin_fail_range_active;
43385- atomic_long_t tlb_dropin_fail_idle;
43386- atomic_long_t tlb_dropin_fail_fmm;
43387- atomic_long_t tlb_dropin_fail_no_exception;
43388- atomic_long_t tfh_stale_on_fault;
43389- atomic_long_t mmu_invalidate_range;
43390- atomic_long_t mmu_invalidate_page;
43391- atomic_long_t flush_tlb;
43392- atomic_long_t flush_tlb_gru;
43393- atomic_long_t flush_tlb_gru_tgh;
43394- atomic_long_t flush_tlb_gru_zero_asid;
43395+ atomic_long_unchecked_t vdata_alloc;
43396+ atomic_long_unchecked_t vdata_free;
43397+ atomic_long_unchecked_t gts_alloc;
43398+ atomic_long_unchecked_t gts_free;
43399+ atomic_long_unchecked_t gms_alloc;
43400+ atomic_long_unchecked_t gms_free;
43401+ atomic_long_unchecked_t gts_double_allocate;
43402+ atomic_long_unchecked_t assign_context;
43403+ atomic_long_unchecked_t assign_context_failed;
43404+ atomic_long_unchecked_t free_context;
43405+ atomic_long_unchecked_t load_user_context;
43406+ atomic_long_unchecked_t load_kernel_context;
43407+ atomic_long_unchecked_t lock_kernel_context;
43408+ atomic_long_unchecked_t unlock_kernel_context;
43409+ atomic_long_unchecked_t steal_user_context;
43410+ atomic_long_unchecked_t steal_kernel_context;
43411+ atomic_long_unchecked_t steal_context_failed;
43412+ atomic_long_unchecked_t nopfn;
43413+ atomic_long_unchecked_t asid_new;
43414+ atomic_long_unchecked_t asid_next;
43415+ atomic_long_unchecked_t asid_wrap;
43416+ atomic_long_unchecked_t asid_reuse;
43417+ atomic_long_unchecked_t intr;
43418+ atomic_long_unchecked_t intr_cbr;
43419+ atomic_long_unchecked_t intr_tfh;
43420+ atomic_long_unchecked_t intr_spurious;
43421+ atomic_long_unchecked_t intr_mm_lock_failed;
43422+ atomic_long_unchecked_t call_os;
43423+ atomic_long_unchecked_t call_os_wait_queue;
43424+ atomic_long_unchecked_t user_flush_tlb;
43425+ atomic_long_unchecked_t user_unload_context;
43426+ atomic_long_unchecked_t user_exception;
43427+ atomic_long_unchecked_t set_context_option;
43428+ atomic_long_unchecked_t check_context_retarget_intr;
43429+ atomic_long_unchecked_t check_context_unload;
43430+ atomic_long_unchecked_t tlb_dropin;
43431+ atomic_long_unchecked_t tlb_preload_page;
43432+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
43433+ atomic_long_unchecked_t tlb_dropin_fail_upm;
43434+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
43435+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
43436+ atomic_long_unchecked_t tlb_dropin_fail_idle;
43437+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
43438+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
43439+ atomic_long_unchecked_t tfh_stale_on_fault;
43440+ atomic_long_unchecked_t mmu_invalidate_range;
43441+ atomic_long_unchecked_t mmu_invalidate_page;
43442+ atomic_long_unchecked_t flush_tlb;
43443+ atomic_long_unchecked_t flush_tlb_gru;
43444+ atomic_long_unchecked_t flush_tlb_gru_tgh;
43445+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
43446
43447- atomic_long_t copy_gpa;
43448- atomic_long_t read_gpa;
43449+ atomic_long_unchecked_t copy_gpa;
43450+ atomic_long_unchecked_t read_gpa;
43451
43452- atomic_long_t mesq_receive;
43453- atomic_long_t mesq_receive_none;
43454- atomic_long_t mesq_send;
43455- atomic_long_t mesq_send_failed;
43456- atomic_long_t mesq_noop;
43457- atomic_long_t mesq_send_unexpected_error;
43458- atomic_long_t mesq_send_lb_overflow;
43459- atomic_long_t mesq_send_qlimit_reached;
43460- atomic_long_t mesq_send_amo_nacked;
43461- atomic_long_t mesq_send_put_nacked;
43462- atomic_long_t mesq_page_overflow;
43463- atomic_long_t mesq_qf_locked;
43464- atomic_long_t mesq_qf_noop_not_full;
43465- atomic_long_t mesq_qf_switch_head_failed;
43466- atomic_long_t mesq_qf_unexpected_error;
43467- atomic_long_t mesq_noop_unexpected_error;
43468- atomic_long_t mesq_noop_lb_overflow;
43469- atomic_long_t mesq_noop_qlimit_reached;
43470- atomic_long_t mesq_noop_amo_nacked;
43471- atomic_long_t mesq_noop_put_nacked;
43472- atomic_long_t mesq_noop_page_overflow;
43473+ atomic_long_unchecked_t mesq_receive;
43474+ atomic_long_unchecked_t mesq_receive_none;
43475+ atomic_long_unchecked_t mesq_send;
43476+ atomic_long_unchecked_t mesq_send_failed;
43477+ atomic_long_unchecked_t mesq_noop;
43478+ atomic_long_unchecked_t mesq_send_unexpected_error;
43479+ atomic_long_unchecked_t mesq_send_lb_overflow;
43480+ atomic_long_unchecked_t mesq_send_qlimit_reached;
43481+ atomic_long_unchecked_t mesq_send_amo_nacked;
43482+ atomic_long_unchecked_t mesq_send_put_nacked;
43483+ atomic_long_unchecked_t mesq_page_overflow;
43484+ atomic_long_unchecked_t mesq_qf_locked;
43485+ atomic_long_unchecked_t mesq_qf_noop_not_full;
43486+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
43487+ atomic_long_unchecked_t mesq_qf_unexpected_error;
43488+ atomic_long_unchecked_t mesq_noop_unexpected_error;
43489+ atomic_long_unchecked_t mesq_noop_lb_overflow;
43490+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
43491+ atomic_long_unchecked_t mesq_noop_amo_nacked;
43492+ atomic_long_unchecked_t mesq_noop_put_nacked;
43493+ atomic_long_unchecked_t mesq_noop_page_overflow;
43494
43495 };
43496
43497@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
43498 tghop_invalidate, mcsop_last};
43499
43500 struct mcs_op_statistic {
43501- atomic_long_t count;
43502- atomic_long_t total;
43503+ atomic_long_unchecked_t count;
43504+ atomic_long_unchecked_t total;
43505 unsigned long max;
43506 };
43507
43508@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
43509
43510 #define STAT(id) do { \
43511 if (gru_options & OPT_STATS) \
43512- atomic_long_inc(&gru_stats.id); \
43513+ atomic_long_inc_unchecked(&gru_stats.id); \
43514 } while (0)
43515
43516 #ifdef CONFIG_SGI_GRU_DEBUG
43517diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
43518index c862cd4..0d176fe 100644
43519--- a/drivers/misc/sgi-xp/xp.h
43520+++ b/drivers/misc/sgi-xp/xp.h
43521@@ -288,7 +288,7 @@ struct xpc_interface {
43522 xpc_notify_func, void *);
43523 void (*received) (short, int, void *);
43524 enum xp_retval (*partid_to_nasids) (short, void *);
43525-};
43526+} __no_const;
43527
43528 extern struct xpc_interface xpc_interface;
43529
43530diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
43531index b94d5f7..7f494c5 100644
43532--- a/drivers/misc/sgi-xp/xpc.h
43533+++ b/drivers/misc/sgi-xp/xpc.h
43534@@ -835,6 +835,7 @@ struct xpc_arch_operations {
43535 void (*received_payload) (struct xpc_channel *, void *);
43536 void (*notify_senders_of_disconnect) (struct xpc_channel *);
43537 };
43538+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
43539
43540 /* struct xpc_partition act_state values (for XPC HB) */
43541
43542@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
43543 /* found in xpc_main.c */
43544 extern struct device *xpc_part;
43545 extern struct device *xpc_chan;
43546-extern struct xpc_arch_operations xpc_arch_ops;
43547+extern xpc_arch_operations_no_const xpc_arch_ops;
43548 extern int xpc_disengage_timelimit;
43549 extern int xpc_disengage_timedout;
43550 extern int xpc_activate_IRQ_rcvd;
43551diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
43552index 82dc574..8539ab2 100644
43553--- a/drivers/misc/sgi-xp/xpc_main.c
43554+++ b/drivers/misc/sgi-xp/xpc_main.c
43555@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
43556 .notifier_call = xpc_system_die,
43557 };
43558
43559-struct xpc_arch_operations xpc_arch_ops;
43560+xpc_arch_operations_no_const xpc_arch_ops;
43561
43562 /*
43563 * Timer function to enforce the timelimit on the partition disengage.
43564@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
43565
43566 if (((die_args->trapnr == X86_TRAP_MF) ||
43567 (die_args->trapnr == X86_TRAP_XF)) &&
43568- !user_mode_vm(die_args->regs))
43569+ !user_mode(die_args->regs))
43570 xpc_die_deactivate();
43571
43572 break;
43573diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
43574index 837fc73..acb5862 100644
43575--- a/drivers/mmc/core/mmc_ops.c
43576+++ b/drivers/mmc/core/mmc_ops.c
43577@@ -213,7 +213,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
43578 void *data_buf;
43579 int is_on_stack;
43580
43581- is_on_stack = object_is_on_stack(buf);
43582+ is_on_stack = object_starts_on_stack(buf);
43583 if (is_on_stack) {
43584 /*
43585 * dma onto stack is unsafe/nonportable, but callers to this
43586diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
43587index 81b2994..dce857e 100644
43588--- a/drivers/mmc/host/dw_mmc.h
43589+++ b/drivers/mmc/host/dw_mmc.h
43590@@ -203,5 +203,5 @@ struct dw_mci_drv_data {
43591 void (*prepare_command)(struct dw_mci *host, u32 *cmdr);
43592 void (*set_ios)(struct dw_mci *host, struct mmc_ios *ios);
43593 int (*parse_dt)(struct dw_mci *host);
43594-};
43595+} __do_const;
43596 #endif /* _DW_MMC_H_ */
43597diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
43598index c3785ed..1984c44 100644
43599--- a/drivers/mmc/host/mmci.c
43600+++ b/drivers/mmc/host/mmci.c
43601@@ -1482,7 +1482,9 @@ static int mmci_probe(struct amba_device *dev,
43602 }
43603
43604 if (variant->busy_detect) {
43605- mmci_ops.card_busy = mmci_card_busy;
43606+ pax_open_kernel();
43607+ *(void **)&mmci_ops.card_busy = mmci_card_busy;
43608+ pax_close_kernel();
43609 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
43610 }
43611
43612diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
43613index 926aaf6..8e153e2 100644
43614--- a/drivers/mmc/host/sdhci-s3c.c
43615+++ b/drivers/mmc/host/sdhci-s3c.c
43616@@ -664,9 +664,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
43617 * we can use overriding functions instead of default.
43618 */
43619 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
43620- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
43621- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
43622- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
43623+ pax_open_kernel();
43624+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
43625+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
43626+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
43627+ pax_close_kernel();
43628 }
43629
43630 /* It supports additional host capabilities if needed */
43631diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
43632index 0c8bb6b..6f35deb 100644
43633--- a/drivers/mtd/nand/denali.c
43634+++ b/drivers/mtd/nand/denali.c
43635@@ -24,6 +24,7 @@
43636 #include <linux/slab.h>
43637 #include <linux/mtd/mtd.h>
43638 #include <linux/module.h>
43639+#include <linux/slab.h>
43640
43641 #include "denali.h"
43642
43643diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
43644index 51b9d6a..52af9a7 100644
43645--- a/drivers/mtd/nftlmount.c
43646+++ b/drivers/mtd/nftlmount.c
43647@@ -24,6 +24,7 @@
43648 #include <asm/errno.h>
43649 #include <linux/delay.h>
43650 #include <linux/slab.h>
43651+#include <linux/sched.h>
43652 #include <linux/mtd/mtd.h>
43653 #include <linux/mtd/nand.h>
43654 #include <linux/mtd/nftl.h>
43655diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
43656index f9d5615..99dd95f 100644
43657--- a/drivers/mtd/sm_ftl.c
43658+++ b/drivers/mtd/sm_ftl.c
43659@@ -56,7 +56,7 @@ ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
43660 #define SM_CIS_VENDOR_OFFSET 0x59
43661 struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
43662 {
43663- struct attribute_group *attr_group;
43664+ attribute_group_no_const *attr_group;
43665 struct attribute **attributes;
43666 struct sm_sysfs_attribute *vendor_attribute;
43667
43668diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
43669index 5e31046..82f8ddc 100644
43670--- a/drivers/net/bonding/bond_main.c
43671+++ b/drivers/net/bonding/bond_main.c
43672@@ -4839,7 +4839,7 @@ static unsigned int bond_get_num_tx_queues(void)
43673 return tx_queues;
43674 }
43675
43676-static struct rtnl_link_ops bond_link_ops __read_mostly = {
43677+static struct rtnl_link_ops bond_link_ops = {
43678 .kind = "bond",
43679 .priv_size = sizeof(struct bonding),
43680 .setup = bond_setup,
43681@@ -4964,8 +4964,8 @@ static void __exit bonding_exit(void)
43682
43683 bond_destroy_debugfs();
43684
43685- rtnl_link_unregister(&bond_link_ops);
43686 unregister_pernet_subsys(&bond_net_ops);
43687+ rtnl_link_unregister(&bond_link_ops);
43688
43689 #ifdef CONFIG_NET_POLL_CONTROLLER
43690 /*
43691diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
43692index e1d2643..7f4133b 100644
43693--- a/drivers/net/ethernet/8390/ax88796.c
43694+++ b/drivers/net/ethernet/8390/ax88796.c
43695@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
43696 if (ax->plat->reg_offsets)
43697 ei_local->reg_offset = ax->plat->reg_offsets;
43698 else {
43699+ resource_size_t _mem_size = mem_size;
43700+ do_div(_mem_size, 0x18);
43701 ei_local->reg_offset = ax->reg_offsets;
43702 for (ret = 0; ret < 0x18; ret++)
43703- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
43704+ ax->reg_offsets[ret] = _mem_size * ret;
43705 }
43706
43707 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
43708diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
43709index c07a6d0..ca88c45 100644
43710--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
43711+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
43712@@ -1137,7 +1137,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
43713 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
43714 {
43715 /* RX_MODE controlling object */
43716- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
43717+ bnx2x_init_rx_mode_obj(bp);
43718
43719 /* multicast configuration controlling object */
43720 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
43721diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
43722index 8f03c98..dd0ef10 100644
43723--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
43724+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
43725@@ -2345,15 +2345,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
43726 return rc;
43727 }
43728
43729-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
43730- struct bnx2x_rx_mode_obj *o)
43731+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
43732 {
43733 if (CHIP_IS_E1x(bp)) {
43734- o->wait_comp = bnx2x_empty_rx_mode_wait;
43735- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
43736+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
43737+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
43738 } else {
43739- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
43740- o->config_rx_mode = bnx2x_set_rx_mode_e2;
43741+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
43742+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
43743 }
43744 }
43745
43746diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
43747index 798dfe9..05d0a44 100644
43748--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
43749+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
43750@@ -1311,8 +1311,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
43751
43752 /********************* RX MODE ****************/
43753
43754-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
43755- struct bnx2x_rx_mode_obj *o);
43756+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
43757
43758 /**
43759 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
43760diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
43761index cd63d11..b67dd78 100644
43762--- a/drivers/net/ethernet/broadcom/tg3.h
43763+++ b/drivers/net/ethernet/broadcom/tg3.h
43764@@ -147,6 +147,7 @@
43765 #define CHIPREV_ID_5750_A0 0x4000
43766 #define CHIPREV_ID_5750_A1 0x4001
43767 #define CHIPREV_ID_5750_A3 0x4003
43768+#define CHIPREV_ID_5750_C1 0x4201
43769 #define CHIPREV_ID_5750_C2 0x4202
43770 #define CHIPREV_ID_5752_A0_HW 0x5000
43771 #define CHIPREV_ID_5752_A0 0x6000
43772diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
43773index 8cffcdf..aadf043 100644
43774--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
43775+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
43776@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
43777 */
43778 struct l2t_skb_cb {
43779 arp_failure_handler_func arp_failure_handler;
43780-};
43781+} __no_const;
43782
43783 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
43784
43785diff --git a/drivers/net/ethernet/chelsio/cxgb3/sge.c b/drivers/net/ethernet/chelsio/cxgb3/sge.c
43786index 9c89dc8..725ecc3 100644
43787--- a/drivers/net/ethernet/chelsio/cxgb3/sge.c
43788+++ b/drivers/net/ethernet/chelsio/cxgb3/sge.c
43789@@ -1599,7 +1599,7 @@ static void write_ofld_wr(struct adapter *adap, struct sk_buff *skb,
43790 flits = skb_transport_offset(skb) / 8;
43791 sgp = ndesc == 1 ? (struct sg_ent *)&d->flit[flits] : sgl;
43792 sgl_flits = make_sgl(skb, sgp, skb_transport_header(skb),
43793- skb->tail - skb->transport_header,
43794+ skb_tail_pointer(skb) - skb_transport_header(skb),
43795 adap->pdev);
43796 if (need_skb_unmap()) {
43797 setup_deferred_unmapping(skb, adap->pdev, sgp, sgl_flits);
43798diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
43799index 4c83003..2a2a5b9 100644
43800--- a/drivers/net/ethernet/dec/tulip/de4x5.c
43801+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
43802@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
43803 for (i=0; i<ETH_ALEN; i++) {
43804 tmp.addr[i] = dev->dev_addr[i];
43805 }
43806- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
43807+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
43808 break;
43809
43810 case DE4X5_SET_HWADDR: /* Set the hardware address */
43811@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
43812 spin_lock_irqsave(&lp->lock, flags);
43813 memcpy(&statbuf, &lp->pktStats, ioc->len);
43814 spin_unlock_irqrestore(&lp->lock, flags);
43815- if (copy_to_user(ioc->data, &statbuf, ioc->len))
43816+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
43817 return -EFAULT;
43818 break;
43819 }
43820diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
43821index 3d91a5e..1014702 100644
43822--- a/drivers/net/ethernet/emulex/benet/be_main.c
43823+++ b/drivers/net/ethernet/emulex/benet/be_main.c
43824@@ -469,7 +469,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
43825
43826 if (wrapped)
43827 newacc += 65536;
43828- ACCESS_ONCE(*acc) = newacc;
43829+ ACCESS_ONCE_RW(*acc) = newacc;
43830 }
43831
43832 void populate_erx_stats(struct be_adapter *adapter,
43833diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
43834index 934e1ae..b262e6b 100644
43835--- a/drivers/net/ethernet/faraday/ftgmac100.c
43836+++ b/drivers/net/ethernet/faraday/ftgmac100.c
43837@@ -31,6 +31,8 @@
43838 #include <linux/netdevice.h>
43839 #include <linux/phy.h>
43840 #include <linux/platform_device.h>
43841+#include <linux/interrupt.h>
43842+#include <linux/irqreturn.h>
43843 #include <net/ip.h>
43844
43845 #include "ftgmac100.h"
43846diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
43847index 4658f4c..407d155 100644
43848--- a/drivers/net/ethernet/faraday/ftmac100.c
43849+++ b/drivers/net/ethernet/faraday/ftmac100.c
43850@@ -31,6 +31,8 @@
43851 #include <linux/module.h>
43852 #include <linux/netdevice.h>
43853 #include <linux/platform_device.h>
43854+#include <linux/interrupt.h>
43855+#include <linux/irqreturn.h>
43856
43857 #include "ftmac100.h"
43858
43859diff --git a/drivers/net/ethernet/intel/igb/igb_ethtool.c b/drivers/net/ethernet/intel/igb/igb_ethtool.c
43860index 85fe7b5..e2da180 100644
43861--- a/drivers/net/ethernet/intel/igb/igb_ethtool.c
43862+++ b/drivers/net/ethernet/intel/igb/igb_ethtool.c
43863@@ -2637,6 +2637,8 @@ static int igb_set_eee(struct net_device *netdev,
43864 (hw->phy.media_type != e1000_media_type_copper))
43865 return -EOPNOTSUPP;
43866
43867+ memset(&eee_curr, 0, sizeof(struct ethtool_eee));
43868+
43869 ret_val = igb_get_eee(netdev, &eee_curr);
43870 if (ret_val)
43871 return ret_val;
43872diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
43873index 331987d..3be1135 100644
43874--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
43875+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
43876@@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
43877 }
43878
43879 /* update the base incval used to calculate frequency adjustment */
43880- ACCESS_ONCE(adapter->base_incval) = incval;
43881+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
43882 smp_mb();
43883
43884 /* need lock to prevent incorrect read while modifying cyclecounter */
43885diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
43886index fbe5363..266b4e3 100644
43887--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
43888+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
43889@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
43890 struct __vxge_hw_fifo *fifo;
43891 struct vxge_hw_fifo_config *config;
43892 u32 txdl_size, txdl_per_memblock;
43893- struct vxge_hw_mempool_cbs fifo_mp_callback;
43894+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
43895+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
43896+ };
43897+
43898 struct __vxge_hw_virtualpath *vpath;
43899
43900 if ((vp == NULL) || (attr == NULL)) {
43901@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
43902 goto exit;
43903 }
43904
43905- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
43906-
43907 fifo->mempool =
43908 __vxge_hw_mempool_create(vpath->hldev,
43909 fifo->config->memblock_size,
43910diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
43911index 345d987..af69721 100644
43912--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
43913+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
43914@@ -2011,7 +2011,9 @@ int qlcnic_83xx_config_default_opmode(struct qlcnic_adapter *adapter)
43915 op_mode = QLC_83XX_DEFAULT_OPMODE;
43916
43917 if (op_mode == QLC_83XX_DEFAULT_OPMODE) {
43918- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
43919+ pax_open_kernel();
43920+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
43921+ pax_close_kernel();
43922 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
43923 } else {
43924 return -EIO;
43925diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
43926index 599d1fd..59868fe 100644
43927--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
43928+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
43929@@ -191,17 +191,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
43930 case QLCNIC_NON_PRIV_FUNC:
43931 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
43932 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
43933- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
43934+ pax_open_kernel();
43935+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
43936+ pax_close_kernel();
43937 break;
43938 case QLCNIC_PRIV_FUNC:
43939 ahw->op_mode = QLCNIC_PRIV_FUNC;
43940 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
43941- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
43942+ pax_open_kernel();
43943+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
43944+ pax_close_kernel();
43945 break;
43946 case QLCNIC_MGMT_FUNC:
43947 ahw->op_mode = QLCNIC_MGMT_FUNC;
43948 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
43949- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
43950+ pax_open_kernel();
43951+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
43952+ pax_close_kernel();
43953 break;
43954 default:
43955 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
43956diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
43957index 7ba68e0..618c73d 100644
43958--- a/drivers/net/ethernet/realtek/r8169.c
43959+++ b/drivers/net/ethernet/realtek/r8169.c
43960@@ -759,22 +759,22 @@ struct rtl8169_private {
43961 struct mdio_ops {
43962 void (*write)(struct rtl8169_private *, int, int);
43963 int (*read)(struct rtl8169_private *, int);
43964- } mdio_ops;
43965+ } __no_const mdio_ops;
43966
43967 struct pll_power_ops {
43968 void (*down)(struct rtl8169_private *);
43969 void (*up)(struct rtl8169_private *);
43970- } pll_power_ops;
43971+ } __no_const pll_power_ops;
43972
43973 struct jumbo_ops {
43974 void (*enable)(struct rtl8169_private *);
43975 void (*disable)(struct rtl8169_private *);
43976- } jumbo_ops;
43977+ } __no_const jumbo_ops;
43978
43979 struct csi_ops {
43980 void (*write)(struct rtl8169_private *, int, int);
43981 u32 (*read)(struct rtl8169_private *, int);
43982- } csi_ops;
43983+ } __no_const csi_ops;
43984
43985 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
43986 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
43987diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
43988index b495394..0748c54 100644
43989--- a/drivers/net/ethernet/sfc/ptp.c
43990+++ b/drivers/net/ethernet/sfc/ptp.c
43991@@ -535,7 +535,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
43992 (u32)((u64)ptp->start.dma_addr >> 32));
43993
43994 /* Clear flag that signals MC ready */
43995- ACCESS_ONCE(*start) = 0;
43996+ ACCESS_ONCE_RW(*start) = 0;
43997 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
43998 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
43999
44000diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
44001index 50617c5..b13724c 100644
44002--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
44003+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
44004@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
44005
44006 writel(value, ioaddr + MMC_CNTRL);
44007
44008- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
44009- MMC_CNTRL, value);
44010+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
44011+// MMC_CNTRL, value);
44012 }
44013
44014 /* To mask all all interrupts.*/
44015diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
44016index e6fe0d8..2b7d752 100644
44017--- a/drivers/net/hyperv/hyperv_net.h
44018+++ b/drivers/net/hyperv/hyperv_net.h
44019@@ -101,7 +101,7 @@ struct rndis_device {
44020
44021 enum rndis_device_state state;
44022 bool link_state;
44023- atomic_t new_req_id;
44024+ atomic_unchecked_t new_req_id;
44025
44026 spinlock_t request_lock;
44027 struct list_head req_list;
44028diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
44029index 0775f0a..d4fb316 100644
44030--- a/drivers/net/hyperv/rndis_filter.c
44031+++ b/drivers/net/hyperv/rndis_filter.c
44032@@ -104,7 +104,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
44033 * template
44034 */
44035 set = &rndis_msg->msg.set_req;
44036- set->req_id = atomic_inc_return(&dev->new_req_id);
44037+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
44038
44039 /* Add to the request list */
44040 spin_lock_irqsave(&dev->request_lock, flags);
44041@@ -752,7 +752,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
44042
44043 /* Setup the rndis set */
44044 halt = &request->request_msg.msg.halt_req;
44045- halt->req_id = atomic_inc_return(&dev->new_req_id);
44046+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
44047
44048 /* Ignore return since this msg is optional. */
44049 rndis_filter_send_request(dev, request);
44050diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
44051index bf0d55e..82bcfbd1 100644
44052--- a/drivers/net/ieee802154/fakehard.c
44053+++ b/drivers/net/ieee802154/fakehard.c
44054@@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
44055 phy->transmit_power = 0xbf;
44056
44057 dev->netdev_ops = &fake_ops;
44058- dev->ml_priv = &fake_mlme;
44059+ dev->ml_priv = (void *)&fake_mlme;
44060
44061 priv = netdev_priv(dev);
44062 priv->phy = phy;
44063diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
44064index 16b43bf..ead0c35 100644
44065--- a/drivers/net/macvlan.c
44066+++ b/drivers/net/macvlan.c
44067@@ -934,13 +934,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
44068 int macvlan_link_register(struct rtnl_link_ops *ops)
44069 {
44070 /* common fields */
44071- ops->priv_size = sizeof(struct macvlan_dev);
44072- ops->validate = macvlan_validate;
44073- ops->maxtype = IFLA_MACVLAN_MAX;
44074- ops->policy = macvlan_policy;
44075- ops->changelink = macvlan_changelink;
44076- ops->get_size = macvlan_get_size;
44077- ops->fill_info = macvlan_fill_info;
44078+ pax_open_kernel();
44079+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
44080+ *(void **)&ops->validate = macvlan_validate;
44081+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
44082+ *(const void **)&ops->policy = macvlan_policy;
44083+ *(void **)&ops->changelink = macvlan_changelink;
44084+ *(void **)&ops->get_size = macvlan_get_size;
44085+ *(void **)&ops->fill_info = macvlan_fill_info;
44086+ pax_close_kernel();
44087
44088 return rtnl_link_register(ops);
44089 };
44090@@ -996,7 +998,7 @@ static int macvlan_device_event(struct notifier_block *unused,
44091 return NOTIFY_DONE;
44092 }
44093
44094-static struct notifier_block macvlan_notifier_block __read_mostly = {
44095+static struct notifier_block macvlan_notifier_block = {
44096 .notifier_call = macvlan_device_event,
44097 };
44098
44099diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
44100index ea53abb..2e4d087 100644
44101--- a/drivers/net/macvtap.c
44102+++ b/drivers/net/macvtap.c
44103@@ -1286,7 +1286,7 @@ static int macvtap_device_event(struct notifier_block *unused,
44104 return NOTIFY_DONE;
44105 }
44106
44107-static struct notifier_block macvtap_notifier_block __read_mostly = {
44108+static struct notifier_block macvtap_notifier_block = {
44109 .notifier_call = macvtap_device_event,
44110 };
44111
44112diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
44113index daec9b0..6428fcb 100644
44114--- a/drivers/net/phy/mdio-bitbang.c
44115+++ b/drivers/net/phy/mdio-bitbang.c
44116@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
44117 struct mdiobb_ctrl *ctrl = bus->priv;
44118
44119 module_put(ctrl->ops->owner);
44120+ mdiobus_unregister(bus);
44121 mdiobus_free(bus);
44122 }
44123 EXPORT_SYMBOL(free_mdio_bitbang);
44124diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
44125index 72ff14b..11d442d 100644
44126--- a/drivers/net/ppp/ppp_generic.c
44127+++ b/drivers/net/ppp/ppp_generic.c
44128@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44129 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
44130 struct ppp_stats stats;
44131 struct ppp_comp_stats cstats;
44132- char *vers;
44133
44134 switch (cmd) {
44135 case SIOCGPPPSTATS:
44136@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44137 break;
44138
44139 case SIOCGPPPVER:
44140- vers = PPP_VERSION;
44141- if (copy_to_user(addr, vers, strlen(vers) + 1))
44142+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
44143 break;
44144 err = 0;
44145 break;
44146diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
44147index 1252d9c..80e660b 100644
44148--- a/drivers/net/slip/slhc.c
44149+++ b/drivers/net/slip/slhc.c
44150@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
44151 register struct tcphdr *thp;
44152 register struct iphdr *ip;
44153 register struct cstate *cs;
44154- int len, hdrlen;
44155+ long len, hdrlen;
44156 unsigned char *cp = icp;
44157
44158 /* We've got a compressed packet; read the change byte */
44159diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
44160index bff7e0b..7315137 100644
44161--- a/drivers/net/team/team.c
44162+++ b/drivers/net/team/team.c
44163@@ -2702,7 +2702,7 @@ static int team_device_event(struct notifier_block *unused,
44164 return NOTIFY_DONE;
44165 }
44166
44167-static struct notifier_block team_notifier_block __read_mostly = {
44168+static struct notifier_block team_notifier_block = {
44169 .notifier_call = team_device_event,
44170 };
44171
44172diff --git a/drivers/net/tun.c b/drivers/net/tun.c
44173index 68b9aa3..b3c20f3 100644
44174--- a/drivers/net/tun.c
44175+++ b/drivers/net/tun.c
44176@@ -1874,7 +1874,7 @@ unlock:
44177 }
44178
44179 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
44180- unsigned long arg, int ifreq_len)
44181+ unsigned long arg, size_t ifreq_len)
44182 {
44183 struct tun_file *tfile = file->private_data;
44184 struct tun_struct *tun;
44185@@ -1886,6 +1886,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
44186 int vnet_hdr_sz;
44187 int ret;
44188
44189+ if (ifreq_len > sizeof ifr)
44190+ return -EFAULT;
44191+
44192 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
44193 if (copy_from_user(&ifr, argp, ifreq_len))
44194 return -EFAULT;
44195diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
44196index 86292e6..8d34433 100644
44197--- a/drivers/net/usb/hso.c
44198+++ b/drivers/net/usb/hso.c
44199@@ -71,7 +71,7 @@
44200 #include <asm/byteorder.h>
44201 #include <linux/serial_core.h>
44202 #include <linux/serial.h>
44203-
44204+#include <asm/local.h>
44205
44206 #define MOD_AUTHOR "Option Wireless"
44207 #define MOD_DESCRIPTION "USB High Speed Option driver"
44208@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
44209 struct urb *urb;
44210
44211 urb = serial->rx_urb[0];
44212- if (serial->port.count > 0) {
44213+ if (atomic_read(&serial->port.count) > 0) {
44214 count = put_rxbuf_data(urb, serial);
44215 if (count == -1)
44216 return;
44217@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
44218 DUMP1(urb->transfer_buffer, urb->actual_length);
44219
44220 /* Anyone listening? */
44221- if (serial->port.count == 0)
44222+ if (atomic_read(&serial->port.count) == 0)
44223 return;
44224
44225 if (status == 0) {
44226@@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
44227 tty_port_tty_set(&serial->port, tty);
44228
44229 /* check for port already opened, if not set the termios */
44230- serial->port.count++;
44231- if (serial->port.count == 1) {
44232+ if (atomic_inc_return(&serial->port.count) == 1) {
44233 serial->rx_state = RX_IDLE;
44234 /* Force default termio settings */
44235 _hso_serial_set_termios(tty, NULL);
44236@@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
44237 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
44238 if (result) {
44239 hso_stop_serial_device(serial->parent);
44240- serial->port.count--;
44241+ atomic_dec(&serial->port.count);
44242 kref_put(&serial->parent->ref, hso_serial_ref_free);
44243 }
44244 } else {
44245@@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
44246
44247 /* reset the rts and dtr */
44248 /* do the actual close */
44249- serial->port.count--;
44250+ atomic_dec(&serial->port.count);
44251
44252- if (serial->port.count <= 0) {
44253- serial->port.count = 0;
44254+ if (atomic_read(&serial->port.count) <= 0) {
44255+ atomic_set(&serial->port.count, 0);
44256 tty_port_tty_set(&serial->port, NULL);
44257 if (!usb_gone)
44258 hso_stop_serial_device(serial->parent);
44259@@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
44260
44261 /* the actual setup */
44262 spin_lock_irqsave(&serial->serial_lock, flags);
44263- if (serial->port.count)
44264+ if (atomic_read(&serial->port.count))
44265 _hso_serial_set_termios(tty, old);
44266 else
44267 tty->termios = *old;
44268@@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
44269 D1("Pending read interrupt on port %d\n", i);
44270 spin_lock(&serial->serial_lock);
44271 if (serial->rx_state == RX_IDLE &&
44272- serial->port.count > 0) {
44273+ atomic_read(&serial->port.count) > 0) {
44274 /* Setup and send a ctrl req read on
44275 * port i */
44276 if (!serial->rx_urb_filled[0]) {
44277@@ -3062,7 +3061,7 @@ static int hso_resume(struct usb_interface *iface)
44278 /* Start all serial ports */
44279 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
44280 if (serial_table[i] && (serial_table[i]->interface == iface)) {
44281- if (dev2ser(serial_table[i])->port.count) {
44282+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
44283 result =
44284 hso_start_serial_device(serial_table[i], GFP_NOIO);
44285 hso_kick_transmit(dev2ser(serial_table[i]));
44286diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
44287index a79e9d3..78cd4fa 100644
44288--- a/drivers/net/usb/sierra_net.c
44289+++ b/drivers/net/usb/sierra_net.c
44290@@ -52,7 +52,7 @@ static const char driver_name[] = "sierra_net";
44291 /* atomic counter partially included in MAC address to make sure 2 devices
44292 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
44293 */
44294-static atomic_t iface_counter = ATOMIC_INIT(0);
44295+static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
44296
44297 /*
44298 * SYNC Timer Delay definition used to set the expiry time
44299@@ -698,7 +698,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
44300 dev->net->netdev_ops = &sierra_net_device_ops;
44301
44302 /* change MAC addr to include, ifacenum, and to be unique */
44303- dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
44304+ dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
44305 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
44306
44307 /* we will have to manufacture ethernet headers, prepare template */
44308diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
44309index 8a05d77..ba8b9c5 100644
44310--- a/drivers/net/vxlan.c
44311+++ b/drivers/net/vxlan.c
44312@@ -1870,7 +1870,7 @@ nla_put_failure:
44313 return -EMSGSIZE;
44314 }
44315
44316-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
44317+static struct rtnl_link_ops vxlan_link_ops = {
44318 .kind = "vxlan",
44319 .maxtype = IFLA_VXLAN_MAX,
44320 .policy = vxlan_policy,
44321diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
44322index 0b60295..b8bfa5b 100644
44323--- a/drivers/net/wimax/i2400m/rx.c
44324+++ b/drivers/net/wimax/i2400m/rx.c
44325@@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
44326 if (i2400m->rx_roq == NULL)
44327 goto error_roq_alloc;
44328
44329- rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
44330+ rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
44331 GFP_KERNEL);
44332 if (rd == NULL) {
44333 result = -ENOMEM;
44334diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
44335index 34c8a33..3261fdc 100644
44336--- a/drivers/net/wireless/at76c50x-usb.c
44337+++ b/drivers/net/wireless/at76c50x-usb.c
44338@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
44339 }
44340
44341 /* Convert timeout from the DFU status to jiffies */
44342-static inline unsigned long at76_get_timeout(struct dfu_status *s)
44343+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
44344 {
44345 return msecs_to_jiffies((s->poll_timeout[2] << 16)
44346 | (s->poll_timeout[1] << 8)
44347diff --git a/drivers/net/wireless/ath/ath10k/core.c b/drivers/net/wireless/ath/ath10k/core.c
44348index 2b3426b..1f564be 100644
44349--- a/drivers/net/wireless/ath/ath10k/core.c
44350+++ b/drivers/net/wireless/ath/ath10k/core.c
44351@@ -507,7 +507,9 @@ EXPORT_SYMBOL(ath10k_core_destroy);
44352
44353 int ath10k_core_register(struct ath10k *ar)
44354 {
44355- struct ath10k_htc_ops htc_ops;
44356+ static struct ath10k_htc_ops htc_ops = {
44357+ .target_send_suspend_complete = ath10k_send_suspend_complete,
44358+ };
44359 struct bmi_target_info target_info;
44360 int status;
44361
44362@@ -536,8 +538,6 @@ int ath10k_core_register(struct ath10k *ar)
44363 if (status)
44364 goto err;
44365
44366- htc_ops.target_send_suspend_complete = ath10k_send_suspend_complete;
44367-
44368 ar->htc = ath10k_htc_create(ar, &htc_ops);
44369 if (IS_ERR(ar->htc)) {
44370 status = PTR_ERR(ar->htc);
44371diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
44372index 74363c9..237b926 100644
44373--- a/drivers/net/wireless/ath/ath10k/htc.c
44374+++ b/drivers/net/wireless/ath/ath10k/htc.c
44375@@ -963,7 +963,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
44376 struct ath10k_htc *ath10k_htc_create(struct ath10k *ar,
44377 struct ath10k_htc_ops *htc_ops)
44378 {
44379- struct ath10k_hif_cb htc_callbacks;
44380+ static struct ath10k_hif_cb htc_callbacks = {
44381+ .rx_completion = ath10k_htc_rx_completion_handler,
44382+ .tx_completion = ath10k_htc_tx_completion_handler,
44383+ };
44384 struct ath10k_htc_ep *ep = NULL;
44385 struct ath10k_htc *htc = NULL;
44386
44387@@ -979,8 +982,6 @@ struct ath10k_htc *ath10k_htc_create(struct ath10k *ar,
44388 ath10k_htc_reset_endpoint_states(htc);
44389
44390 /* setup HIF layer callbacks */
44391- htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
44392- htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
44393 htc->ar = ar;
44394
44395 /* Get HIF default pipe for HTC message exchange */
44396diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44397index 8d78253..bebbb68 100644
44398--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44399+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44400@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44401 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
44402 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
44403
44404- ACCESS_ONCE(ads->ds_link) = i->link;
44405- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
44406+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
44407+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
44408
44409 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
44410 ctl6 = SM(i->keytype, AR_EncrType);
44411@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44412
44413 if ((i->is_first || i->is_last) &&
44414 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
44415- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
44416+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
44417 | set11nTries(i->rates, 1)
44418 | set11nTries(i->rates, 2)
44419 | set11nTries(i->rates, 3)
44420 | (i->dur_update ? AR_DurUpdateEna : 0)
44421 | SM(0, AR_BurstDur);
44422
44423- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
44424+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
44425 | set11nRate(i->rates, 1)
44426 | set11nRate(i->rates, 2)
44427 | set11nRate(i->rates, 3);
44428 } else {
44429- ACCESS_ONCE(ads->ds_ctl2) = 0;
44430- ACCESS_ONCE(ads->ds_ctl3) = 0;
44431+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
44432+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
44433 }
44434
44435 if (!i->is_first) {
44436- ACCESS_ONCE(ads->ds_ctl0) = 0;
44437- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
44438- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
44439+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
44440+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
44441+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
44442 return;
44443 }
44444
44445@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44446 break;
44447 }
44448
44449- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
44450+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
44451 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
44452 | SM(i->txpower, AR_XmitPower)
44453 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
44454@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44455 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
44456 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
44457
44458- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
44459- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
44460+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
44461+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
44462
44463 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
44464 return;
44465
44466- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
44467+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
44468 | set11nPktDurRTSCTS(i->rates, 1);
44469
44470- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
44471+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
44472 | set11nPktDurRTSCTS(i->rates, 3);
44473
44474- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
44475+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
44476 | set11nRateFlags(i->rates, 1)
44477 | set11nRateFlags(i->rates, 2)
44478 | set11nRateFlags(i->rates, 3)
44479diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
44480index 5163abd..3ada4c2 100644
44481--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
44482+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
44483@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44484 (i->qcu << AR_TxQcuNum_S) | desc_len;
44485
44486 checksum += val;
44487- ACCESS_ONCE(ads->info) = val;
44488+ ACCESS_ONCE_RW(ads->info) = val;
44489
44490 checksum += i->link;
44491- ACCESS_ONCE(ads->link) = i->link;
44492+ ACCESS_ONCE_RW(ads->link) = i->link;
44493
44494 checksum += i->buf_addr[0];
44495- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
44496+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
44497 checksum += i->buf_addr[1];
44498- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
44499+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
44500 checksum += i->buf_addr[2];
44501- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
44502+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
44503 checksum += i->buf_addr[3];
44504- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
44505+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
44506
44507 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
44508- ACCESS_ONCE(ads->ctl3) = val;
44509+ ACCESS_ONCE_RW(ads->ctl3) = val;
44510 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
44511- ACCESS_ONCE(ads->ctl5) = val;
44512+ ACCESS_ONCE_RW(ads->ctl5) = val;
44513 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
44514- ACCESS_ONCE(ads->ctl7) = val;
44515+ ACCESS_ONCE_RW(ads->ctl7) = val;
44516 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
44517- ACCESS_ONCE(ads->ctl9) = val;
44518+ ACCESS_ONCE_RW(ads->ctl9) = val;
44519
44520 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
44521- ACCESS_ONCE(ads->ctl10) = checksum;
44522+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
44523
44524 if (i->is_first || i->is_last) {
44525- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
44526+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
44527 | set11nTries(i->rates, 1)
44528 | set11nTries(i->rates, 2)
44529 | set11nTries(i->rates, 3)
44530 | (i->dur_update ? AR_DurUpdateEna : 0)
44531 | SM(0, AR_BurstDur);
44532
44533- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
44534+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
44535 | set11nRate(i->rates, 1)
44536 | set11nRate(i->rates, 2)
44537 | set11nRate(i->rates, 3);
44538 } else {
44539- ACCESS_ONCE(ads->ctl13) = 0;
44540- ACCESS_ONCE(ads->ctl14) = 0;
44541+ ACCESS_ONCE_RW(ads->ctl13) = 0;
44542+ ACCESS_ONCE_RW(ads->ctl14) = 0;
44543 }
44544
44545 ads->ctl20 = 0;
44546@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44547
44548 ctl17 = SM(i->keytype, AR_EncrType);
44549 if (!i->is_first) {
44550- ACCESS_ONCE(ads->ctl11) = 0;
44551- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
44552- ACCESS_ONCE(ads->ctl15) = 0;
44553- ACCESS_ONCE(ads->ctl16) = 0;
44554- ACCESS_ONCE(ads->ctl17) = ctl17;
44555- ACCESS_ONCE(ads->ctl18) = 0;
44556- ACCESS_ONCE(ads->ctl19) = 0;
44557+ ACCESS_ONCE_RW(ads->ctl11) = 0;
44558+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
44559+ ACCESS_ONCE_RW(ads->ctl15) = 0;
44560+ ACCESS_ONCE_RW(ads->ctl16) = 0;
44561+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
44562+ ACCESS_ONCE_RW(ads->ctl18) = 0;
44563+ ACCESS_ONCE_RW(ads->ctl19) = 0;
44564 return;
44565 }
44566
44567- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
44568+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
44569 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
44570 | SM(i->txpower, AR_XmitPower)
44571 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
44572@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44573 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
44574 ctl12 |= SM(val, AR_PAPRDChainMask);
44575
44576- ACCESS_ONCE(ads->ctl12) = ctl12;
44577- ACCESS_ONCE(ads->ctl17) = ctl17;
44578+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
44579+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
44580
44581- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
44582+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
44583 | set11nPktDurRTSCTS(i->rates, 1);
44584
44585- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
44586+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
44587 | set11nPktDurRTSCTS(i->rates, 3);
44588
44589- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
44590+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
44591 | set11nRateFlags(i->rates, 1)
44592 | set11nRateFlags(i->rates, 2)
44593 | set11nRateFlags(i->rates, 3)
44594 | SM(i->rtscts_rate, AR_RTSCTSRate);
44595
44596- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
44597+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
44598 }
44599
44600 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
44601diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
44602index cd74b3a..6a28d24 100644
44603--- a/drivers/net/wireless/ath/ath9k/hw.h
44604+++ b/drivers/net/wireless/ath/ath9k/hw.h
44605@@ -652,7 +652,7 @@ struct ath_hw_private_ops {
44606
44607 /* ANI */
44608 void (*ani_cache_ini_regs)(struct ath_hw *ah);
44609-};
44610+} __no_const;
44611
44612 /**
44613 * struct ath_spec_scan - parameters for Atheros spectral scan
44614@@ -721,7 +721,7 @@ struct ath_hw_ops {
44615 struct ath_spec_scan *param);
44616 void (*spectral_scan_trigger)(struct ath_hw *ah);
44617 void (*spectral_scan_wait)(struct ath_hw *ah);
44618-};
44619+} __no_const;
44620
44621 struct ath_nf_limits {
44622 s16 max;
44623diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
44624index 9581d07..84f6a76 100644
44625--- a/drivers/net/wireless/iwlegacy/3945-mac.c
44626+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
44627@@ -3639,7 +3639,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
44628 */
44629 if (il3945_mod_params.disable_hw_scan) {
44630 D_INFO("Disabling hw_scan\n");
44631- il3945_mac_ops.hw_scan = NULL;
44632+ pax_open_kernel();
44633+ *(void **)&il3945_mac_ops.hw_scan = NULL;
44634+ pax_close_kernel();
44635 }
44636
44637 D_INFO("*** LOAD DRIVER ***\n");
44638diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
44639index d532948..e0d8bb1 100644
44640--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
44641+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
44642@@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
44643 {
44644 struct iwl_priv *priv = file->private_data;
44645 char buf[64];
44646- int buf_size;
44647+ size_t buf_size;
44648 u32 offset, len;
44649
44650 memset(buf, 0, sizeof(buf));
44651@@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
44652 struct iwl_priv *priv = file->private_data;
44653
44654 char buf[8];
44655- int buf_size;
44656+ size_t buf_size;
44657 u32 reset_flag;
44658
44659 memset(buf, 0, sizeof(buf));
44660@@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
44661 {
44662 struct iwl_priv *priv = file->private_data;
44663 char buf[8];
44664- int buf_size;
44665+ size_t buf_size;
44666 int ht40;
44667
44668 memset(buf, 0, sizeof(buf));
44669@@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
44670 {
44671 struct iwl_priv *priv = file->private_data;
44672 char buf[8];
44673- int buf_size;
44674+ size_t buf_size;
44675 int value;
44676
44677 memset(buf, 0, sizeof(buf));
44678@@ -698,10 +698,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
44679 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
44680 DEBUGFS_READ_FILE_OPS(current_sleep_command);
44681
44682-static const char *fmt_value = " %-30s %10u\n";
44683-static const char *fmt_hex = " %-30s 0x%02X\n";
44684-static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
44685-static const char *fmt_header =
44686+static const char fmt_value[] = " %-30s %10u\n";
44687+static const char fmt_hex[] = " %-30s 0x%02X\n";
44688+static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
44689+static const char fmt_header[] =
44690 "%-32s current cumulative delta max\n";
44691
44692 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
44693@@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
44694 {
44695 struct iwl_priv *priv = file->private_data;
44696 char buf[8];
44697- int buf_size;
44698+ size_t buf_size;
44699 int clear;
44700
44701 memset(buf, 0, sizeof(buf));
44702@@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
44703 {
44704 struct iwl_priv *priv = file->private_data;
44705 char buf[8];
44706- int buf_size;
44707+ size_t buf_size;
44708 int trace;
44709
44710 memset(buf, 0, sizeof(buf));
44711@@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
44712 {
44713 struct iwl_priv *priv = file->private_data;
44714 char buf[8];
44715- int buf_size;
44716+ size_t buf_size;
44717 int missed;
44718
44719 memset(buf, 0, sizeof(buf));
44720@@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
44721
44722 struct iwl_priv *priv = file->private_data;
44723 char buf[8];
44724- int buf_size;
44725+ size_t buf_size;
44726 int plcp;
44727
44728 memset(buf, 0, sizeof(buf));
44729@@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
44730
44731 struct iwl_priv *priv = file->private_data;
44732 char buf[8];
44733- int buf_size;
44734+ size_t buf_size;
44735 int flush;
44736
44737 memset(buf, 0, sizeof(buf));
44738@@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
44739
44740 struct iwl_priv *priv = file->private_data;
44741 char buf[8];
44742- int buf_size;
44743+ size_t buf_size;
44744 int rts;
44745
44746 if (!priv->cfg->ht_params)
44747@@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
44748 {
44749 struct iwl_priv *priv = file->private_data;
44750 char buf[8];
44751- int buf_size;
44752+ size_t buf_size;
44753
44754 memset(buf, 0, sizeof(buf));
44755 buf_size = min(count, sizeof(buf) - 1);
44756@@ -2254,7 +2254,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
44757 struct iwl_priv *priv = file->private_data;
44758 u32 event_log_flag;
44759 char buf[8];
44760- int buf_size;
44761+ size_t buf_size;
44762
44763 /* check that the interface is up */
44764 if (!iwl_is_ready(priv))
44765@@ -2308,7 +2308,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
44766 struct iwl_priv *priv = file->private_data;
44767 char buf[8];
44768 u32 calib_disabled;
44769- int buf_size;
44770+ size_t buf_size;
44771
44772 memset(buf, 0, sizeof(buf));
44773 buf_size = min(count, sizeof(buf) - 1);
44774diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
44775index 1531a4f..21d2641 100644
44776--- a/drivers/net/wireless/iwlwifi/dvm/main.c
44777+++ b/drivers/net/wireless/iwlwifi/dvm/main.c
44778@@ -1180,7 +1180,7 @@ static void iwl_option_config(struct iwl_priv *priv)
44779 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
44780 {
44781 struct iwl_nvm_data *data = priv->nvm_data;
44782- char *debug_msg;
44783+ static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
44784
44785 if (data->sku_cap_11n_enable &&
44786 !priv->cfg->ht_params) {
44787@@ -1194,7 +1194,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
44788 return -EINVAL;
44789 }
44790
44791- debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
44792 IWL_DEBUG_INFO(priv, debug_msg,
44793 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
44794 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
44795diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
44796index 390e2f0..75cfbaf 100644
44797--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
44798+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
44799@@ -1350,7 +1350,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
44800 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
44801
44802 char buf[8];
44803- int buf_size;
44804+ size_t buf_size;
44805 u32 reset_flag;
44806
44807 memset(buf, 0, sizeof(buf));
44808@@ -1371,7 +1371,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
44809 {
44810 struct iwl_trans *trans = file->private_data;
44811 char buf[8];
44812- int buf_size;
44813+ size_t buf_size;
44814 int csr;
44815
44816 memset(buf, 0, sizeof(buf));
44817diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
44818index cb34c78..9fec0dc 100644
44819--- a/drivers/net/wireless/mac80211_hwsim.c
44820+++ b/drivers/net/wireless/mac80211_hwsim.c
44821@@ -2195,25 +2195,19 @@ static int __init init_mac80211_hwsim(void)
44822
44823 if (channels > 1) {
44824 hwsim_if_comb.num_different_channels = channels;
44825- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
44826- mac80211_hwsim_ops.cancel_hw_scan =
44827- mac80211_hwsim_cancel_hw_scan;
44828- mac80211_hwsim_ops.sw_scan_start = NULL;
44829- mac80211_hwsim_ops.sw_scan_complete = NULL;
44830- mac80211_hwsim_ops.remain_on_channel =
44831- mac80211_hwsim_roc;
44832- mac80211_hwsim_ops.cancel_remain_on_channel =
44833- mac80211_hwsim_croc;
44834- mac80211_hwsim_ops.add_chanctx =
44835- mac80211_hwsim_add_chanctx;
44836- mac80211_hwsim_ops.remove_chanctx =
44837- mac80211_hwsim_remove_chanctx;
44838- mac80211_hwsim_ops.change_chanctx =
44839- mac80211_hwsim_change_chanctx;
44840- mac80211_hwsim_ops.assign_vif_chanctx =
44841- mac80211_hwsim_assign_vif_chanctx;
44842- mac80211_hwsim_ops.unassign_vif_chanctx =
44843- mac80211_hwsim_unassign_vif_chanctx;
44844+ pax_open_kernel();
44845+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
44846+ *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
44847+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
44848+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
44849+ *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
44850+ *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
44851+ *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
44852+ *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
44853+ *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
44854+ *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
44855+ *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
44856+ pax_close_kernel();
44857 }
44858
44859 spin_lock_init(&hwsim_radio_lock);
44860diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
44861index 8169a85..7fa3b47 100644
44862--- a/drivers/net/wireless/rndis_wlan.c
44863+++ b/drivers/net/wireless/rndis_wlan.c
44864@@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
44865
44866 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
44867
44868- if (rts_threshold < 0 || rts_threshold > 2347)
44869+ if (rts_threshold > 2347)
44870 rts_threshold = 2347;
44871
44872 tmp = cpu_to_le32(rts_threshold);
44873diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
44874index ee3fc57..ed5ddc9 100644
44875--- a/drivers/net/wireless/rt2x00/rt2x00.h
44876+++ b/drivers/net/wireless/rt2x00/rt2x00.h
44877@@ -386,7 +386,7 @@ struct rt2x00_intf {
44878 * for hardware which doesn't support hardware
44879 * sequence counting.
44880 */
44881- atomic_t seqno;
44882+ atomic_unchecked_t seqno;
44883 };
44884
44885 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
44886diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
44887index aa95c6c..a59dd67 100644
44888--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
44889+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
44890@@ -252,9 +252,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
44891 * sequence counter given by mac80211.
44892 */
44893 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
44894- seqno = atomic_add_return(0x10, &intf->seqno);
44895+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
44896 else
44897- seqno = atomic_read(&intf->seqno);
44898+ seqno = atomic_read_unchecked(&intf->seqno);
44899
44900 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
44901 hdr->seq_ctrl |= cpu_to_le16(seqno);
44902diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
44903index e2b3d9c..67a5184 100644
44904--- a/drivers/net/wireless/ti/wl1251/sdio.c
44905+++ b/drivers/net/wireless/ti/wl1251/sdio.c
44906@@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
44907
44908 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
44909
44910- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
44911- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
44912+ pax_open_kernel();
44913+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
44914+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
44915+ pax_close_kernel();
44916
44917 wl1251_info("using dedicated interrupt line");
44918 } else {
44919- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
44920- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
44921+ pax_open_kernel();
44922+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
44923+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
44924+ pax_close_kernel();
44925
44926 wl1251_info("using SDIO interrupt");
44927 }
44928diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
44929index 1c627da..69f7d17 100644
44930--- a/drivers/net/wireless/ti/wl12xx/main.c
44931+++ b/drivers/net/wireless/ti/wl12xx/main.c
44932@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
44933 sizeof(wl->conf.mem));
44934
44935 /* read data preparation is only needed by wl127x */
44936- wl->ops->prepare_read = wl127x_prepare_read;
44937+ pax_open_kernel();
44938+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
44939+ pax_close_kernel();
44940
44941 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
44942 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
44943@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
44944 sizeof(wl->conf.mem));
44945
44946 /* read data preparation is only needed by wl127x */
44947- wl->ops->prepare_read = wl127x_prepare_read;
44948+ pax_open_kernel();
44949+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
44950+ pax_close_kernel();
44951
44952 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
44953 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
44954diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
44955index 7aa0eb8..5a9ef38 100644
44956--- a/drivers/net/wireless/ti/wl18xx/main.c
44957+++ b/drivers/net/wireless/ti/wl18xx/main.c
44958@@ -1730,8 +1730,10 @@ static int wl18xx_setup(struct wl1271 *wl)
44959 }
44960
44961 if (!checksum_param) {
44962- wl18xx_ops.set_rx_csum = NULL;
44963- wl18xx_ops.init_vif = NULL;
44964+ pax_open_kernel();
44965+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
44966+ *(void **)&wl18xx_ops.init_vif = NULL;
44967+ pax_close_kernel();
44968 }
44969
44970 /* Enable 11a Band only if we have 5G antennas */
44971diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
44972index 7ef0b4a..ff65c28 100644
44973--- a/drivers/net/wireless/zd1211rw/zd_usb.c
44974+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
44975@@ -386,7 +386,7 @@ static inline void handle_regs_int(struct urb *urb)
44976 {
44977 struct zd_usb *usb = urb->context;
44978 struct zd_usb_interrupt *intr = &usb->intr;
44979- int len;
44980+ unsigned int len;
44981 u16 int_num;
44982
44983 ZD_ASSERT(in_interrupt());
44984diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
44985index d93b2b6..ae50401 100644
44986--- a/drivers/oprofile/buffer_sync.c
44987+++ b/drivers/oprofile/buffer_sync.c
44988@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
44989 if (cookie == NO_COOKIE)
44990 offset = pc;
44991 if (cookie == INVALID_COOKIE) {
44992- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
44993+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
44994 offset = pc;
44995 }
44996 if (cookie != last_cookie) {
44997@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
44998 /* add userspace sample */
44999
45000 if (!mm) {
45001- atomic_inc(&oprofile_stats.sample_lost_no_mm);
45002+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
45003 return 0;
45004 }
45005
45006 cookie = lookup_dcookie(mm, s->eip, &offset);
45007
45008 if (cookie == INVALID_COOKIE) {
45009- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
45010+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
45011 return 0;
45012 }
45013
45014@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
45015 /* ignore backtraces if failed to add a sample */
45016 if (state == sb_bt_start) {
45017 state = sb_bt_ignore;
45018- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
45019+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
45020 }
45021 }
45022 release_mm(mm);
45023diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
45024index c0cc4e7..44d4e54 100644
45025--- a/drivers/oprofile/event_buffer.c
45026+++ b/drivers/oprofile/event_buffer.c
45027@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
45028 }
45029
45030 if (buffer_pos == buffer_size) {
45031- atomic_inc(&oprofile_stats.event_lost_overflow);
45032+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
45033 return;
45034 }
45035
45036diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
45037index ed2c3ec..deda85a 100644
45038--- a/drivers/oprofile/oprof.c
45039+++ b/drivers/oprofile/oprof.c
45040@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
45041 if (oprofile_ops.switch_events())
45042 return;
45043
45044- atomic_inc(&oprofile_stats.multiplex_counter);
45045+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
45046 start_switch_worker();
45047 }
45048
45049diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
45050index 84a208d..d61b0a1 100644
45051--- a/drivers/oprofile/oprofile_files.c
45052+++ b/drivers/oprofile/oprofile_files.c
45053@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
45054
45055 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
45056
45057-static ssize_t timeout_read(struct file *file, char __user *buf,
45058+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
45059 size_t count, loff_t *offset)
45060 {
45061 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
45062diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
45063index 917d28e..d62d981 100644
45064--- a/drivers/oprofile/oprofile_stats.c
45065+++ b/drivers/oprofile/oprofile_stats.c
45066@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
45067 cpu_buf->sample_invalid_eip = 0;
45068 }
45069
45070- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
45071- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
45072- atomic_set(&oprofile_stats.event_lost_overflow, 0);
45073- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
45074- atomic_set(&oprofile_stats.multiplex_counter, 0);
45075+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
45076+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
45077+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
45078+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
45079+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
45080 }
45081
45082
45083diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
45084index 38b6fc0..b5cbfce 100644
45085--- a/drivers/oprofile/oprofile_stats.h
45086+++ b/drivers/oprofile/oprofile_stats.h
45087@@ -13,11 +13,11 @@
45088 #include <linux/atomic.h>
45089
45090 struct oprofile_stat_struct {
45091- atomic_t sample_lost_no_mm;
45092- atomic_t sample_lost_no_mapping;
45093- atomic_t bt_lost_no_mapping;
45094- atomic_t event_lost_overflow;
45095- atomic_t multiplex_counter;
45096+ atomic_unchecked_t sample_lost_no_mm;
45097+ atomic_unchecked_t sample_lost_no_mapping;
45098+ atomic_unchecked_t bt_lost_no_mapping;
45099+ atomic_unchecked_t event_lost_overflow;
45100+ atomic_unchecked_t multiplex_counter;
45101 };
45102
45103 extern struct oprofile_stat_struct oprofile_stats;
45104diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
45105index 7c12d9c..558bf3bb 100644
45106--- a/drivers/oprofile/oprofilefs.c
45107+++ b/drivers/oprofile/oprofilefs.c
45108@@ -190,7 +190,7 @@ static const struct file_operations atomic_ro_fops = {
45109
45110
45111 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
45112- char const *name, atomic_t *val)
45113+ char const *name, atomic_unchecked_t *val)
45114 {
45115 return __oprofilefs_create_file(sb, root, name,
45116 &atomic_ro_fops, 0444, val);
45117diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
45118index 61be1d9..dec05d7 100644
45119--- a/drivers/oprofile/timer_int.c
45120+++ b/drivers/oprofile/timer_int.c
45121@@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
45122 return NOTIFY_OK;
45123 }
45124
45125-static struct notifier_block __refdata oprofile_cpu_notifier = {
45126+static struct notifier_block oprofile_cpu_notifier = {
45127 .notifier_call = oprofile_cpu_notify,
45128 };
45129
45130diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
45131index 92ed045..62d39bd7 100644
45132--- a/drivers/parport/procfs.c
45133+++ b/drivers/parport/procfs.c
45134@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
45135
45136 *ppos += len;
45137
45138- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
45139+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
45140 }
45141
45142 #ifdef CONFIG_PARPORT_1284
45143@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
45144
45145 *ppos += len;
45146
45147- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
45148+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
45149 }
45150 #endif /* IEEE1284.3 support. */
45151
45152diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
45153index c35e8ad..fc33beb 100644
45154--- a/drivers/pci/hotplug/acpiphp_ibm.c
45155+++ b/drivers/pci/hotplug/acpiphp_ibm.c
45156@@ -464,7 +464,9 @@ static int __init ibm_acpiphp_init(void)
45157 goto init_cleanup;
45158 }
45159
45160- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
45161+ pax_open_kernel();
45162+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
45163+ pax_close_kernel();
45164 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
45165
45166 return retval;
45167diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
45168index a6a71c4..c91097b 100644
45169--- a/drivers/pci/hotplug/cpcihp_generic.c
45170+++ b/drivers/pci/hotplug/cpcihp_generic.c
45171@@ -73,7 +73,6 @@ static u16 port;
45172 static unsigned int enum_bit;
45173 static u8 enum_mask;
45174
45175-static struct cpci_hp_controller_ops generic_hpc_ops;
45176 static struct cpci_hp_controller generic_hpc;
45177
45178 static int __init validate_parameters(void)
45179@@ -139,6 +138,10 @@ static int query_enum(void)
45180 return ((value & enum_mask) == enum_mask);
45181 }
45182
45183+static struct cpci_hp_controller_ops generic_hpc_ops = {
45184+ .query_enum = query_enum,
45185+};
45186+
45187 static int __init cpcihp_generic_init(void)
45188 {
45189 int status;
45190@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
45191 pci_dev_put(dev);
45192
45193 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
45194- generic_hpc_ops.query_enum = query_enum;
45195 generic_hpc.ops = &generic_hpc_ops;
45196
45197 status = cpci_hp_register_controller(&generic_hpc);
45198diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
45199index 449b4bb..257e2e8 100644
45200--- a/drivers/pci/hotplug/cpcihp_zt5550.c
45201+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
45202@@ -59,7 +59,6 @@
45203 /* local variables */
45204 static bool debug;
45205 static bool poll;
45206-static struct cpci_hp_controller_ops zt5550_hpc_ops;
45207 static struct cpci_hp_controller zt5550_hpc;
45208
45209 /* Primary cPCI bus bridge device */
45210@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
45211 return 0;
45212 }
45213
45214+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
45215+ .query_enum = zt5550_hc_query_enum,
45216+};
45217+
45218 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
45219 {
45220 int status;
45221@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
45222 dbg("returned from zt5550_hc_config");
45223
45224 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
45225- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
45226 zt5550_hpc.ops = &zt5550_hpc_ops;
45227 if(!poll) {
45228 zt5550_hpc.irq = hc_dev->irq;
45229 zt5550_hpc.irq_flags = IRQF_SHARED;
45230 zt5550_hpc.dev_id = hc_dev;
45231
45232- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
45233- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
45234- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
45235+ pax_open_kernel();
45236+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
45237+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
45238+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
45239+ pax_open_kernel();
45240 } else {
45241 info("using ENUM# polling mode");
45242 }
45243diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
45244index 76ba8a1..20ca857 100644
45245--- a/drivers/pci/hotplug/cpqphp_nvram.c
45246+++ b/drivers/pci/hotplug/cpqphp_nvram.c
45247@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
45248
45249 void compaq_nvram_init (void __iomem *rom_start)
45250 {
45251+
45252+#ifndef CONFIG_PAX_KERNEXEC
45253 if (rom_start) {
45254 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
45255 }
45256+#endif
45257+
45258 dbg("int15 entry = %p\n", compaq_int15_entry_point);
45259
45260 /* initialize our int15 lock */
45261diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
45262index ec20f74..c1d961e 100644
45263--- a/drivers/pci/hotplug/pci_hotplug_core.c
45264+++ b/drivers/pci/hotplug/pci_hotplug_core.c
45265@@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
45266 return -EINVAL;
45267 }
45268
45269- slot->ops->owner = owner;
45270- slot->ops->mod_name = mod_name;
45271+ pax_open_kernel();
45272+ *(struct module **)&slot->ops->owner = owner;
45273+ *(const char **)&slot->ops->mod_name = mod_name;
45274+ pax_close_kernel();
45275
45276 mutex_lock(&pci_hp_mutex);
45277 /*
45278diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
45279index 7d72c5e..edce02c 100644
45280--- a/drivers/pci/hotplug/pciehp_core.c
45281+++ b/drivers/pci/hotplug/pciehp_core.c
45282@@ -91,7 +91,7 @@ static int init_slot(struct controller *ctrl)
45283 struct slot *slot = ctrl->slot;
45284 struct hotplug_slot *hotplug = NULL;
45285 struct hotplug_slot_info *info = NULL;
45286- struct hotplug_slot_ops *ops = NULL;
45287+ hotplug_slot_ops_no_const *ops = NULL;
45288 char name[SLOT_NAME_SIZE];
45289 int retval = -ENOMEM;
45290
45291diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
45292index c0dbe1f..94cf3d8 100644
45293--- a/drivers/pci/pci-sysfs.c
45294+++ b/drivers/pci/pci-sysfs.c
45295@@ -1073,7 +1073,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
45296 {
45297 /* allocate attribute structure, piggyback attribute name */
45298 int name_len = write_combine ? 13 : 10;
45299- struct bin_attribute *res_attr;
45300+ bin_attribute_no_const *res_attr;
45301 int retval;
45302
45303 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
45304@@ -1258,7 +1258,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
45305 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
45306 {
45307 int retval;
45308- struct bin_attribute *attr;
45309+ bin_attribute_no_const *attr;
45310
45311 /* If the device has VPD, try to expose it in sysfs. */
45312 if (dev->vpd) {
45313@@ -1305,7 +1305,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
45314 {
45315 int retval;
45316 int rom_size = 0;
45317- struct bin_attribute *attr;
45318+ bin_attribute_no_const *attr;
45319
45320 if (!sysfs_initialized)
45321 return -EACCES;
45322diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
45323index d1182c4..2a138ec 100644
45324--- a/drivers/pci/pci.h
45325+++ b/drivers/pci/pci.h
45326@@ -92,7 +92,7 @@ struct pci_vpd_ops {
45327 struct pci_vpd {
45328 unsigned int len;
45329 const struct pci_vpd_ops *ops;
45330- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
45331+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
45332 };
45333
45334 int pci_vpd_pci22_init(struct pci_dev *dev);
45335diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
45336index 403a443..034e050 100644
45337--- a/drivers/pci/pcie/aspm.c
45338+++ b/drivers/pci/pcie/aspm.c
45339@@ -27,9 +27,9 @@
45340 #define MODULE_PARAM_PREFIX "pcie_aspm."
45341
45342 /* Note: those are not register definitions */
45343-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
45344-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
45345-#define ASPM_STATE_L1 (4) /* L1 state */
45346+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
45347+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
45348+#define ASPM_STATE_L1 (4U) /* L1 state */
45349 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
45350 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
45351
45352diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
45353index 46ada5c..20da716 100644
45354--- a/drivers/pci/probe.c
45355+++ b/drivers/pci/probe.c
45356@@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
45357 struct pci_bus_region region, inverted_region;
45358 bool bar_too_big = false, bar_disabled = false;
45359
45360- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
45361+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
45362
45363 /* No printks while decoding is disabled! */
45364 if (!dev->mmio_always_on) {
45365diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
45366index cdc7836..528635c 100644
45367--- a/drivers/pci/proc.c
45368+++ b/drivers/pci/proc.c
45369@@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
45370 static int __init pci_proc_init(void)
45371 {
45372 struct pci_dev *dev = NULL;
45373+
45374+#ifdef CONFIG_GRKERNSEC_PROC_ADD
45375+#ifdef CONFIG_GRKERNSEC_PROC_USER
45376+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
45377+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45378+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
45379+#endif
45380+#else
45381 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
45382+#endif
45383 proc_create("devices", 0, proc_bus_pci_dir,
45384 &proc_bus_pci_dev_operations);
45385 proc_initialized = 1;
45386diff --git a/drivers/platform/x86/chromeos_laptop.c b/drivers/platform/x86/chromeos_laptop.c
45387index 3e5b4497..dcdfb70 100644
45388--- a/drivers/platform/x86/chromeos_laptop.c
45389+++ b/drivers/platform/x86/chromeos_laptop.c
45390@@ -301,7 +301,7 @@ static int __init setup_tsl2563_als(const struct dmi_system_id *id)
45391 return 0;
45392 }
45393
45394-static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
45395+static struct dmi_system_id __initconst chromeos_laptop_dmi_table[] = {
45396 {
45397 .ident = "Samsung Series 5 550 - Touchpad",
45398 .matches = {
45399diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
45400index 62f8030..c7f2a45 100644
45401--- a/drivers/platform/x86/msi-laptop.c
45402+++ b/drivers/platform/x86/msi-laptop.c
45403@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
45404
45405 if (!quirks->ec_read_only) {
45406 /* allow userland write sysfs file */
45407- dev_attr_bluetooth.store = store_bluetooth;
45408- dev_attr_wlan.store = store_wlan;
45409- dev_attr_threeg.store = store_threeg;
45410- dev_attr_bluetooth.attr.mode |= S_IWUSR;
45411- dev_attr_wlan.attr.mode |= S_IWUSR;
45412- dev_attr_threeg.attr.mode |= S_IWUSR;
45413+ pax_open_kernel();
45414+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
45415+ *(void **)&dev_attr_wlan.store = store_wlan;
45416+ *(void **)&dev_attr_threeg.store = store_threeg;
45417+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
45418+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
45419+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
45420+ pax_close_kernel();
45421 }
45422
45423 /* disable hardware control by fn key */
45424diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
45425index 3a1b6bf..b453930 100644
45426--- a/drivers/platform/x86/sony-laptop.c
45427+++ b/drivers/platform/x86/sony-laptop.c
45428@@ -2486,7 +2486,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
45429 }
45430
45431 /* High speed charging function */
45432-static struct device_attribute *hsc_handle;
45433+static device_attribute_no_const *hsc_handle;
45434
45435 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
45436 struct device_attribute *attr,
45437diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
45438index 54d31c0..3f896d3 100644
45439--- a/drivers/platform/x86/thinkpad_acpi.c
45440+++ b/drivers/platform/x86/thinkpad_acpi.c
45441@@ -2093,7 +2093,7 @@ static int hotkey_mask_get(void)
45442 return 0;
45443 }
45444
45445-void static hotkey_mask_warn_incomplete_mask(void)
45446+static void hotkey_mask_warn_incomplete_mask(void)
45447 {
45448 /* log only what the user can fix... */
45449 const u32 wantedmask = hotkey_driver_mask &
45450@@ -2324,11 +2324,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
45451 }
45452 }
45453
45454-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45455- struct tp_nvram_state *newn,
45456- const u32 event_mask)
45457-{
45458-
45459 #define TPACPI_COMPARE_KEY(__scancode, __member) \
45460 do { \
45461 if ((event_mask & (1 << __scancode)) && \
45462@@ -2342,36 +2337,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45463 tpacpi_hotkey_send_key(__scancode); \
45464 } while (0)
45465
45466- void issue_volchange(const unsigned int oldvol,
45467- const unsigned int newvol)
45468- {
45469- unsigned int i = oldvol;
45470+static void issue_volchange(const unsigned int oldvol,
45471+ const unsigned int newvol,
45472+ const u32 event_mask)
45473+{
45474+ unsigned int i = oldvol;
45475
45476- while (i > newvol) {
45477- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
45478- i--;
45479- }
45480- while (i < newvol) {
45481- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
45482- i++;
45483- }
45484+ while (i > newvol) {
45485+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
45486+ i--;
45487 }
45488+ while (i < newvol) {
45489+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
45490+ i++;
45491+ }
45492+}
45493
45494- void issue_brightnesschange(const unsigned int oldbrt,
45495- const unsigned int newbrt)
45496- {
45497- unsigned int i = oldbrt;
45498+static void issue_brightnesschange(const unsigned int oldbrt,
45499+ const unsigned int newbrt,
45500+ const u32 event_mask)
45501+{
45502+ unsigned int i = oldbrt;
45503
45504- while (i > newbrt) {
45505- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
45506- i--;
45507- }
45508- while (i < newbrt) {
45509- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
45510- i++;
45511- }
45512+ while (i > newbrt) {
45513+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
45514+ i--;
45515+ }
45516+ while (i < newbrt) {
45517+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
45518+ i++;
45519 }
45520+}
45521
45522+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45523+ struct tp_nvram_state *newn,
45524+ const u32 event_mask)
45525+{
45526 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
45527 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
45528 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
45529@@ -2405,7 +2406,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45530 oldn->volume_level != newn->volume_level) {
45531 /* recently muted, or repeated mute keypress, or
45532 * multiple presses ending in mute */
45533- issue_volchange(oldn->volume_level, newn->volume_level);
45534+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
45535 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
45536 }
45537 } else {
45538@@ -2415,7 +2416,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45539 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
45540 }
45541 if (oldn->volume_level != newn->volume_level) {
45542- issue_volchange(oldn->volume_level, newn->volume_level);
45543+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
45544 } else if (oldn->volume_toggle != newn->volume_toggle) {
45545 /* repeated vol up/down keypress at end of scale ? */
45546 if (newn->volume_level == 0)
45547@@ -2428,7 +2429,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45548 /* handle brightness */
45549 if (oldn->brightness_level != newn->brightness_level) {
45550 issue_brightnesschange(oldn->brightness_level,
45551- newn->brightness_level);
45552+ newn->brightness_level,
45553+ event_mask);
45554 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
45555 /* repeated key presses that didn't change state */
45556 if (newn->brightness_level == 0)
45557@@ -2437,10 +2439,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45558 && !tp_features.bright_unkfw)
45559 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
45560 }
45561+}
45562
45563 #undef TPACPI_COMPARE_KEY
45564 #undef TPACPI_MAY_SEND_KEY
45565-}
45566
45567 /*
45568 * Polling driver
45569diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
45570index 769d265..a3a05ca 100644
45571--- a/drivers/pnp/pnpbios/bioscalls.c
45572+++ b/drivers/pnp/pnpbios/bioscalls.c
45573@@ -58,7 +58,7 @@ do { \
45574 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
45575 } while(0)
45576
45577-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
45578+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
45579 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
45580
45581 /*
45582@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
45583
45584 cpu = get_cpu();
45585 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
45586+
45587+ pax_open_kernel();
45588 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
45589+ pax_close_kernel();
45590
45591 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
45592 spin_lock_irqsave(&pnp_bios_lock, flags);
45593@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
45594 :"memory");
45595 spin_unlock_irqrestore(&pnp_bios_lock, flags);
45596
45597+ pax_open_kernel();
45598 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
45599+ pax_close_kernel();
45600+
45601 put_cpu();
45602
45603 /* If we get here and this is set then the PnP BIOS faulted on us. */
45604@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
45605 return status;
45606 }
45607
45608-void pnpbios_calls_init(union pnp_bios_install_struct *header)
45609+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
45610 {
45611 int i;
45612
45613@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
45614 pnp_bios_callpoint.offset = header->fields.pm16offset;
45615 pnp_bios_callpoint.segment = PNP_CS16;
45616
45617+ pax_open_kernel();
45618+
45619 for_each_possible_cpu(i) {
45620 struct desc_struct *gdt = get_cpu_gdt_table(i);
45621 if (!gdt)
45622@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
45623 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
45624 (unsigned long)__va(header->fields.pm16dseg));
45625 }
45626+
45627+ pax_close_kernel();
45628 }
45629diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
45630index d95e101..67f0c3f 100644
45631--- a/drivers/pnp/resource.c
45632+++ b/drivers/pnp/resource.c
45633@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
45634 return 1;
45635
45636 /* check if the resource is valid */
45637- if (*irq < 0 || *irq > 15)
45638+ if (*irq > 15)
45639 return 0;
45640
45641 /* check if the resource is reserved */
45642@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
45643 return 1;
45644
45645 /* check if the resource is valid */
45646- if (*dma < 0 || *dma == 4 || *dma > 7)
45647+ if (*dma == 4 || *dma > 7)
45648 return 0;
45649
45650 /* check if the resource is reserved */
45651diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
45652index 0c52e2a..3421ab7 100644
45653--- a/drivers/power/pda_power.c
45654+++ b/drivers/power/pda_power.c
45655@@ -37,7 +37,11 @@ static int polling;
45656
45657 #if IS_ENABLED(CONFIG_USB_PHY)
45658 static struct usb_phy *transceiver;
45659-static struct notifier_block otg_nb;
45660+static int otg_handle_notification(struct notifier_block *nb,
45661+ unsigned long event, void *unused);
45662+static struct notifier_block otg_nb = {
45663+ .notifier_call = otg_handle_notification
45664+};
45665 #endif
45666
45667 static struct regulator *ac_draw;
45668@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
45669
45670 #if IS_ENABLED(CONFIG_USB_PHY)
45671 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
45672- otg_nb.notifier_call = otg_handle_notification;
45673 ret = usb_register_notifier(transceiver, &otg_nb);
45674 if (ret) {
45675 dev_err(dev, "failure to register otg notifier\n");
45676diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
45677index cc439fd..8fa30df 100644
45678--- a/drivers/power/power_supply.h
45679+++ b/drivers/power/power_supply.h
45680@@ -16,12 +16,12 @@ struct power_supply;
45681
45682 #ifdef CONFIG_SYSFS
45683
45684-extern void power_supply_init_attrs(struct device_type *dev_type);
45685+extern void power_supply_init_attrs(void);
45686 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
45687
45688 #else
45689
45690-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
45691+static inline void power_supply_init_attrs(void) {}
45692 #define power_supply_uevent NULL
45693
45694 #endif /* CONFIG_SYSFS */
45695diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
45696index 3b2d5df..3207114 100644
45697--- a/drivers/power/power_supply_core.c
45698+++ b/drivers/power/power_supply_core.c
45699@@ -24,7 +24,10 @@
45700 struct class *power_supply_class;
45701 EXPORT_SYMBOL_GPL(power_supply_class);
45702
45703-static struct device_type power_supply_dev_type;
45704+extern const struct attribute_group *power_supply_attr_groups[];
45705+static struct device_type power_supply_dev_type = {
45706+ .groups = power_supply_attr_groups,
45707+};
45708
45709 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
45710 struct power_supply *supply)
45711@@ -558,7 +561,7 @@ static int __init power_supply_class_init(void)
45712 return PTR_ERR(power_supply_class);
45713
45714 power_supply_class->dev_uevent = power_supply_uevent;
45715- power_supply_init_attrs(&power_supply_dev_type);
45716+ power_supply_init_attrs();
45717
45718 return 0;
45719 }
45720diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
45721index 29178f7..c65f324 100644
45722--- a/drivers/power/power_supply_sysfs.c
45723+++ b/drivers/power/power_supply_sysfs.c
45724@@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
45725 .is_visible = power_supply_attr_is_visible,
45726 };
45727
45728-static const struct attribute_group *power_supply_attr_groups[] = {
45729+const struct attribute_group *power_supply_attr_groups[] = {
45730 &power_supply_attr_group,
45731 NULL,
45732 };
45733
45734-void power_supply_init_attrs(struct device_type *dev_type)
45735+void power_supply_init_attrs(void)
45736 {
45737 int i;
45738
45739- dev_type->groups = power_supply_attr_groups;
45740-
45741 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
45742 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
45743 }
45744diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
45745index 288c75a..065bc84 100644
45746--- a/drivers/regulator/core.c
45747+++ b/drivers/regulator/core.c
45748@@ -3544,7 +3544,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
45749 {
45750 const struct regulation_constraints *constraints = NULL;
45751 const struct regulator_init_data *init_data;
45752- static atomic_t regulator_no = ATOMIC_INIT(0);
45753+ static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
45754 struct regulator_dev *rdev;
45755 struct device *dev;
45756 int ret, i;
45757@@ -3614,7 +3614,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
45758 rdev->dev.of_node = config->of_node;
45759 rdev->dev.parent = dev;
45760 dev_set_name(&rdev->dev, "regulator.%d",
45761- atomic_inc_return(&regulator_no) - 1);
45762+ atomic_inc_return_unchecked(&regulator_no) - 1);
45763 ret = device_register(&rdev->dev);
45764 if (ret != 0) {
45765 put_device(&rdev->dev);
45766diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
45767index d428ef9..fdc0357 100644
45768--- a/drivers/regulator/max8660.c
45769+++ b/drivers/regulator/max8660.c
45770@@ -333,8 +333,10 @@ static int max8660_probe(struct i2c_client *client,
45771 max8660->shadow_regs[MAX8660_OVER1] = 5;
45772 } else {
45773 /* Otherwise devices can be toggled via software */
45774- max8660_dcdc_ops.enable = max8660_dcdc_enable;
45775- max8660_dcdc_ops.disable = max8660_dcdc_disable;
45776+ pax_open_kernel();
45777+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
45778+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
45779+ pax_close_kernel();
45780 }
45781
45782 /*
45783diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
45784index 0c5195a..637a453d 100644
45785--- a/drivers/regulator/max8973-regulator.c
45786+++ b/drivers/regulator/max8973-regulator.c
45787@@ -406,9 +406,11 @@ static int max8973_probe(struct i2c_client *client,
45788 if (!pdata || !pdata->enable_ext_control) {
45789 max->desc.enable_reg = MAX8973_VOUT;
45790 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
45791- max->ops.enable = regulator_enable_regmap;
45792- max->ops.disable = regulator_disable_regmap;
45793- max->ops.is_enabled = regulator_is_enabled_regmap;
45794+ pax_open_kernel();
45795+ *(void **)&max->ops.enable = regulator_enable_regmap;
45796+ *(void **)&max->ops.disable = regulator_disable_regmap;
45797+ *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
45798+ pax_close_kernel();
45799 }
45800
45801 if (pdata) {
45802diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
45803index 1037e07..e64dea1 100644
45804--- a/drivers/regulator/mc13892-regulator.c
45805+++ b/drivers/regulator/mc13892-regulator.c
45806@@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
45807 }
45808 mc13xxx_unlock(mc13892);
45809
45810- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
45811+ pax_open_kernel();
45812+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
45813 = mc13892_vcam_set_mode;
45814- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
45815+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
45816 = mc13892_vcam_get_mode;
45817+ pax_close_kernel();
45818
45819 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
45820 ARRAY_SIZE(mc13892_regulators));
45821diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
45822index be06d71..264aee9 100644
45823--- a/drivers/rtc/rtc-cmos.c
45824+++ b/drivers/rtc/rtc-cmos.c
45825@@ -731,7 +731,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
45826 hpet_rtc_timer_init();
45827
45828 /* export at least the first block of NVRAM */
45829- nvram.size = address_space - NVRAM_OFFSET;
45830+ pax_open_kernel();
45831+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
45832+ pax_close_kernel();
45833 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
45834 if (retval < 0) {
45835 dev_dbg(dev, "can't create nvram file? %d\n", retval);
45836diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
45837index d049393..bb20be0 100644
45838--- a/drivers/rtc/rtc-dev.c
45839+++ b/drivers/rtc/rtc-dev.c
45840@@ -16,6 +16,7 @@
45841 #include <linux/module.h>
45842 #include <linux/rtc.h>
45843 #include <linux/sched.h>
45844+#include <linux/grsecurity.h>
45845 #include "rtc-core.h"
45846
45847 static dev_t rtc_devt;
45848@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
45849 if (copy_from_user(&tm, uarg, sizeof(tm)))
45850 return -EFAULT;
45851
45852+ gr_log_timechange();
45853+
45854 return rtc_set_time(rtc, &tm);
45855
45856 case RTC_PIE_ON:
45857diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
45858index ca18fd1..055e42d 100644
45859--- a/drivers/rtc/rtc-ds1307.c
45860+++ b/drivers/rtc/rtc-ds1307.c
45861@@ -107,7 +107,7 @@ struct ds1307 {
45862 u8 offset; /* register's offset */
45863 u8 regs[11];
45864 u16 nvram_offset;
45865- struct bin_attribute *nvram;
45866+ bin_attribute_no_const *nvram;
45867 enum ds_type type;
45868 unsigned long flags;
45869 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
45870diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
45871index fcb0329..d77b7f2 100644
45872--- a/drivers/rtc/rtc-m48t59.c
45873+++ b/drivers/rtc/rtc-m48t59.c
45874@@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
45875 if (IS_ERR(m48t59->rtc))
45876 return PTR_ERR(m48t59->rtc);
45877
45878- m48t59_nvram_attr.size = pdata->offset;
45879+ pax_open_kernel();
45880+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
45881+ pax_close_kernel();
45882
45883 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
45884 if (ret)
45885diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
45886index 408a42e..f0d432c 100644
45887--- a/drivers/scsi/aacraid/linit.c
45888+++ b/drivers/scsi/aacraid/linit.c
45889@@ -771,6 +771,8 @@ static long aac_compat_do_ioctl(struct aac_dev *dev, unsigned cmd, unsigned long
45890 static int aac_compat_ioctl(struct scsi_device *sdev, int cmd, void __user *arg)
45891 {
45892 struct aac_dev *dev = (struct aac_dev *)sdev->host->hostdata;
45893+ if (!capable(CAP_SYS_RAWIO))
45894+ return -EPERM;
45895 return aac_compat_do_ioctl(dev, cmd, (unsigned long)arg);
45896 }
45897
45898diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
45899index e693af6..2e525b6 100644
45900--- a/drivers/scsi/bfa/bfa_fcpim.h
45901+++ b/drivers/scsi/bfa/bfa_fcpim.h
45902@@ -36,7 +36,7 @@ struct bfa_iotag_s {
45903
45904 struct bfa_itn_s {
45905 bfa_isr_func_t isr;
45906-};
45907+} __no_const;
45908
45909 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
45910 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
45911diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
45912index 90814fe..4384138 100644
45913--- a/drivers/scsi/bfa/bfa_ioc.h
45914+++ b/drivers/scsi/bfa/bfa_ioc.h
45915@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
45916 bfa_ioc_disable_cbfn_t disable_cbfn;
45917 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
45918 bfa_ioc_reset_cbfn_t reset_cbfn;
45919-};
45920+} __no_const;
45921
45922 /*
45923 * IOC event notification mechanism.
45924@@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
45925 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
45926 enum bfi_ioc_state fwstate);
45927 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
45928-};
45929+} __no_const;
45930
45931 /*
45932 * Queue element to wait for room in request queue. FIFO order is
45933diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
45934index c9382d6..6619864 100644
45935--- a/drivers/scsi/fcoe/fcoe_sysfs.c
45936+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
45937@@ -33,8 +33,8 @@
45938 */
45939 #include "libfcoe.h"
45940
45941-static atomic_t ctlr_num;
45942-static atomic_t fcf_num;
45943+static atomic_unchecked_t ctlr_num;
45944+static atomic_unchecked_t fcf_num;
45945
45946 /*
45947 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
45948@@ -681,7 +681,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
45949 if (!ctlr)
45950 goto out;
45951
45952- ctlr->id = atomic_inc_return(&ctlr_num) - 1;
45953+ ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
45954 ctlr->f = f;
45955 ctlr->mode = FIP_CONN_TYPE_FABRIC;
45956 INIT_LIST_HEAD(&ctlr->fcfs);
45957@@ -898,7 +898,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
45958 fcf->dev.parent = &ctlr->dev;
45959 fcf->dev.bus = &fcoe_bus_type;
45960 fcf->dev.type = &fcoe_fcf_device_type;
45961- fcf->id = atomic_inc_return(&fcf_num) - 1;
45962+ fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
45963 fcf->state = FCOE_FCF_STATE_UNKNOWN;
45964
45965 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
45966@@ -934,8 +934,8 @@ int __init fcoe_sysfs_setup(void)
45967 {
45968 int error;
45969
45970- atomic_set(&ctlr_num, 0);
45971- atomic_set(&fcf_num, 0);
45972+ atomic_set_unchecked(&ctlr_num, 0);
45973+ atomic_set_unchecked(&fcf_num, 0);
45974
45975 error = bus_register(&fcoe_bus_type);
45976 if (error)
45977diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
45978index df0c3c7..b00e1d0 100644
45979--- a/drivers/scsi/hosts.c
45980+++ b/drivers/scsi/hosts.c
45981@@ -42,7 +42,7 @@
45982 #include "scsi_logging.h"
45983
45984
45985-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
45986+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
45987
45988
45989 static void scsi_host_cls_release(struct device *dev)
45990@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
45991 * subtract one because we increment first then return, but we need to
45992 * know what the next host number was before increment
45993 */
45994- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
45995+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
45996 shost->dma_channel = 0xff;
45997
45998 /* These three are default values which can be overridden */
45999diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
46000index 7f4f790..b75b92a 100644
46001--- a/drivers/scsi/hpsa.c
46002+++ b/drivers/scsi/hpsa.c
46003@@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
46004 unsigned long flags;
46005
46006 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
46007- return h->access.command_completed(h, q);
46008+ return h->access->command_completed(h, q);
46009
46010 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
46011 a = rq->head[rq->current_entry];
46012@@ -3422,7 +3422,7 @@ static void start_io(struct ctlr_info *h)
46013 while (!list_empty(&h->reqQ)) {
46014 c = list_entry(h->reqQ.next, struct CommandList, list);
46015 /* can't do anything if fifo is full */
46016- if ((h->access.fifo_full(h))) {
46017+ if ((h->access->fifo_full(h))) {
46018 dev_warn(&h->pdev->dev, "fifo full\n");
46019 break;
46020 }
46021@@ -3444,7 +3444,7 @@ static void start_io(struct ctlr_info *h)
46022
46023 /* Tell the controller execute command */
46024 spin_unlock_irqrestore(&h->lock, flags);
46025- h->access.submit_command(h, c);
46026+ h->access->submit_command(h, c);
46027 spin_lock_irqsave(&h->lock, flags);
46028 }
46029 spin_unlock_irqrestore(&h->lock, flags);
46030@@ -3452,17 +3452,17 @@ static void start_io(struct ctlr_info *h)
46031
46032 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
46033 {
46034- return h->access.command_completed(h, q);
46035+ return h->access->command_completed(h, q);
46036 }
46037
46038 static inline bool interrupt_pending(struct ctlr_info *h)
46039 {
46040- return h->access.intr_pending(h);
46041+ return h->access->intr_pending(h);
46042 }
46043
46044 static inline long interrupt_not_for_us(struct ctlr_info *h)
46045 {
46046- return (h->access.intr_pending(h) == 0) ||
46047+ return (h->access->intr_pending(h) == 0) ||
46048 (h->interrupts_enabled == 0);
46049 }
46050
46051@@ -4364,7 +4364,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
46052 if (prod_index < 0)
46053 return -ENODEV;
46054 h->product_name = products[prod_index].product_name;
46055- h->access = *(products[prod_index].access);
46056+ h->access = products[prod_index].access;
46057
46058 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
46059 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
46060@@ -4646,7 +4646,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
46061
46062 assert_spin_locked(&lockup_detector_lock);
46063 remove_ctlr_from_lockup_detector_list(h);
46064- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46065+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46066 spin_lock_irqsave(&h->lock, flags);
46067 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
46068 spin_unlock_irqrestore(&h->lock, flags);
46069@@ -4823,7 +4823,7 @@ reinit_after_soft_reset:
46070 }
46071
46072 /* make sure the board interrupts are off */
46073- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46074+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46075
46076 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
46077 goto clean2;
46078@@ -4857,7 +4857,7 @@ reinit_after_soft_reset:
46079 * fake ones to scoop up any residual completions.
46080 */
46081 spin_lock_irqsave(&h->lock, flags);
46082- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46083+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46084 spin_unlock_irqrestore(&h->lock, flags);
46085 free_irqs(h);
46086 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
46087@@ -4876,9 +4876,9 @@ reinit_after_soft_reset:
46088 dev_info(&h->pdev->dev, "Board READY.\n");
46089 dev_info(&h->pdev->dev,
46090 "Waiting for stale completions to drain.\n");
46091- h->access.set_intr_mask(h, HPSA_INTR_ON);
46092+ h->access->set_intr_mask(h, HPSA_INTR_ON);
46093 msleep(10000);
46094- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46095+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46096
46097 rc = controller_reset_failed(h->cfgtable);
46098 if (rc)
46099@@ -4899,7 +4899,7 @@ reinit_after_soft_reset:
46100 }
46101
46102 /* Turn the interrupts on so we can service requests */
46103- h->access.set_intr_mask(h, HPSA_INTR_ON);
46104+ h->access->set_intr_mask(h, HPSA_INTR_ON);
46105
46106 hpsa_hba_inquiry(h);
46107 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
46108@@ -4954,7 +4954,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
46109 * To write all data in the battery backed cache to disks
46110 */
46111 hpsa_flush_cache(h);
46112- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46113+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46114 hpsa_free_irqs_and_disable_msix(h);
46115 }
46116
46117@@ -5122,7 +5122,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
46118 return;
46119 }
46120 /* Change the access methods to the performant access methods */
46121- h->access = SA5_performant_access;
46122+ h->access = &SA5_performant_access;
46123 h->transMethod = CFGTBL_Trans_Performant;
46124 }
46125
46126diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
46127index 9816479..c5d4e97 100644
46128--- a/drivers/scsi/hpsa.h
46129+++ b/drivers/scsi/hpsa.h
46130@@ -79,7 +79,7 @@ struct ctlr_info {
46131 unsigned int msix_vector;
46132 unsigned int msi_vector;
46133 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
46134- struct access_method access;
46135+ struct access_method *access;
46136
46137 /* queue and queue Info */
46138 struct list_head reqQ;
46139diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
46140index 5879929..32b241d 100644
46141--- a/drivers/scsi/libfc/fc_exch.c
46142+++ b/drivers/scsi/libfc/fc_exch.c
46143@@ -100,12 +100,12 @@ struct fc_exch_mgr {
46144 u16 pool_max_index;
46145
46146 struct {
46147- atomic_t no_free_exch;
46148- atomic_t no_free_exch_xid;
46149- atomic_t xid_not_found;
46150- atomic_t xid_busy;
46151- atomic_t seq_not_found;
46152- atomic_t non_bls_resp;
46153+ atomic_unchecked_t no_free_exch;
46154+ atomic_unchecked_t no_free_exch_xid;
46155+ atomic_unchecked_t xid_not_found;
46156+ atomic_unchecked_t xid_busy;
46157+ atomic_unchecked_t seq_not_found;
46158+ atomic_unchecked_t non_bls_resp;
46159 } stats;
46160 };
46161
46162@@ -736,7 +736,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
46163 /* allocate memory for exchange */
46164 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
46165 if (!ep) {
46166- atomic_inc(&mp->stats.no_free_exch);
46167+ atomic_inc_unchecked(&mp->stats.no_free_exch);
46168 goto out;
46169 }
46170 memset(ep, 0, sizeof(*ep));
46171@@ -797,7 +797,7 @@ out:
46172 return ep;
46173 err:
46174 spin_unlock_bh(&pool->lock);
46175- atomic_inc(&mp->stats.no_free_exch_xid);
46176+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
46177 mempool_free(ep, mp->ep_pool);
46178 return NULL;
46179 }
46180@@ -940,7 +940,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46181 xid = ntohs(fh->fh_ox_id); /* we originated exch */
46182 ep = fc_exch_find(mp, xid);
46183 if (!ep) {
46184- atomic_inc(&mp->stats.xid_not_found);
46185+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46186 reject = FC_RJT_OX_ID;
46187 goto out;
46188 }
46189@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46190 ep = fc_exch_find(mp, xid);
46191 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
46192 if (ep) {
46193- atomic_inc(&mp->stats.xid_busy);
46194+ atomic_inc_unchecked(&mp->stats.xid_busy);
46195 reject = FC_RJT_RX_ID;
46196 goto rel;
46197 }
46198@@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46199 }
46200 xid = ep->xid; /* get our XID */
46201 } else if (!ep) {
46202- atomic_inc(&mp->stats.xid_not_found);
46203+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46204 reject = FC_RJT_RX_ID; /* XID not found */
46205 goto out;
46206 }
46207@@ -998,7 +998,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46208 } else {
46209 sp = &ep->seq;
46210 if (sp->id != fh->fh_seq_id) {
46211- atomic_inc(&mp->stats.seq_not_found);
46212+ atomic_inc_unchecked(&mp->stats.seq_not_found);
46213 if (f_ctl & FC_FC_END_SEQ) {
46214 /*
46215 * Update sequence_id based on incoming last
46216@@ -1448,22 +1448,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46217
46218 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
46219 if (!ep) {
46220- atomic_inc(&mp->stats.xid_not_found);
46221+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46222 goto out;
46223 }
46224 if (ep->esb_stat & ESB_ST_COMPLETE) {
46225- atomic_inc(&mp->stats.xid_not_found);
46226+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46227 goto rel;
46228 }
46229 if (ep->rxid == FC_XID_UNKNOWN)
46230 ep->rxid = ntohs(fh->fh_rx_id);
46231 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
46232- atomic_inc(&mp->stats.xid_not_found);
46233+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46234 goto rel;
46235 }
46236 if (ep->did != ntoh24(fh->fh_s_id) &&
46237 ep->did != FC_FID_FLOGI) {
46238- atomic_inc(&mp->stats.xid_not_found);
46239+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46240 goto rel;
46241 }
46242 sof = fr_sof(fp);
46243@@ -1472,7 +1472,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46244 sp->ssb_stat |= SSB_ST_RESP;
46245 sp->id = fh->fh_seq_id;
46246 } else if (sp->id != fh->fh_seq_id) {
46247- atomic_inc(&mp->stats.seq_not_found);
46248+ atomic_inc_unchecked(&mp->stats.seq_not_found);
46249 goto rel;
46250 }
46251
46252@@ -1536,9 +1536,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46253 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
46254
46255 if (!sp)
46256- atomic_inc(&mp->stats.xid_not_found);
46257+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46258 else
46259- atomic_inc(&mp->stats.non_bls_resp);
46260+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
46261
46262 fc_frame_free(fp);
46263 }
46264@@ -2185,13 +2185,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
46265
46266 list_for_each_entry(ema, &lport->ema_list, ema_list) {
46267 mp = ema->mp;
46268- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
46269+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
46270 st->fc_no_free_exch_xid +=
46271- atomic_read(&mp->stats.no_free_exch_xid);
46272- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
46273- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
46274- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
46275- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
46276+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
46277+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
46278+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
46279+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
46280+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
46281 }
46282 }
46283 EXPORT_SYMBOL(fc_exch_update_stats);
46284diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
46285index 161c98e..6d563b3 100644
46286--- a/drivers/scsi/libsas/sas_ata.c
46287+++ b/drivers/scsi/libsas/sas_ata.c
46288@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
46289 .postreset = ata_std_postreset,
46290 .error_handler = ata_std_error_handler,
46291 .post_internal_cmd = sas_ata_post_internal,
46292- .qc_defer = ata_std_qc_defer,
46293+ .qc_defer = ata_std_qc_defer,
46294 .qc_prep = ata_noop_qc_prep,
46295 .qc_issue = sas_ata_qc_issue,
46296 .qc_fill_rtf = sas_ata_qc_fill_rtf,
46297diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
46298index 93f222d..73e977b 100644
46299--- a/drivers/scsi/lpfc/lpfc.h
46300+++ b/drivers/scsi/lpfc/lpfc.h
46301@@ -431,7 +431,7 @@ struct lpfc_vport {
46302 struct dentry *debug_nodelist;
46303 struct dentry *vport_debugfs_root;
46304 struct lpfc_debugfs_trc *disc_trc;
46305- atomic_t disc_trc_cnt;
46306+ atomic_unchecked_t disc_trc_cnt;
46307 #endif
46308 uint8_t stat_data_enabled;
46309 uint8_t stat_data_blocked;
46310@@ -865,8 +865,8 @@ struct lpfc_hba {
46311 struct timer_list fabric_block_timer;
46312 unsigned long bit_flags;
46313 #define FABRIC_COMANDS_BLOCKED 0
46314- atomic_t num_rsrc_err;
46315- atomic_t num_cmd_success;
46316+ atomic_unchecked_t num_rsrc_err;
46317+ atomic_unchecked_t num_cmd_success;
46318 unsigned long last_rsrc_error_time;
46319 unsigned long last_ramp_down_time;
46320 unsigned long last_ramp_up_time;
46321@@ -902,7 +902,7 @@ struct lpfc_hba {
46322
46323 struct dentry *debug_slow_ring_trc;
46324 struct lpfc_debugfs_trc *slow_ring_trc;
46325- atomic_t slow_ring_trc_cnt;
46326+ atomic_unchecked_t slow_ring_trc_cnt;
46327 /* iDiag debugfs sub-directory */
46328 struct dentry *idiag_root;
46329 struct dentry *idiag_pci_cfg;
46330diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
46331index 60084e6..0e2e700 100644
46332--- a/drivers/scsi/lpfc/lpfc_debugfs.c
46333+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
46334@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
46335
46336 #include <linux/debugfs.h>
46337
46338-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
46339+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
46340 static unsigned long lpfc_debugfs_start_time = 0L;
46341
46342 /* iDiag */
46343@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
46344 lpfc_debugfs_enable = 0;
46345
46346 len = 0;
46347- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
46348+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
46349 (lpfc_debugfs_max_disc_trc - 1);
46350 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
46351 dtp = vport->disc_trc + i;
46352@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
46353 lpfc_debugfs_enable = 0;
46354
46355 len = 0;
46356- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
46357+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
46358 (lpfc_debugfs_max_slow_ring_trc - 1);
46359 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
46360 dtp = phba->slow_ring_trc + i;
46361@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
46362 !vport || !vport->disc_trc)
46363 return;
46364
46365- index = atomic_inc_return(&vport->disc_trc_cnt) &
46366+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
46367 (lpfc_debugfs_max_disc_trc - 1);
46368 dtp = vport->disc_trc + index;
46369 dtp->fmt = fmt;
46370 dtp->data1 = data1;
46371 dtp->data2 = data2;
46372 dtp->data3 = data3;
46373- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
46374+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
46375 dtp->jif = jiffies;
46376 #endif
46377 return;
46378@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
46379 !phba || !phba->slow_ring_trc)
46380 return;
46381
46382- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
46383+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
46384 (lpfc_debugfs_max_slow_ring_trc - 1);
46385 dtp = phba->slow_ring_trc + index;
46386 dtp->fmt = fmt;
46387 dtp->data1 = data1;
46388 dtp->data2 = data2;
46389 dtp->data3 = data3;
46390- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
46391+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
46392 dtp->jif = jiffies;
46393 #endif
46394 return;
46395@@ -4168,7 +4168,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
46396 "slow_ring buffer\n");
46397 goto debug_failed;
46398 }
46399- atomic_set(&phba->slow_ring_trc_cnt, 0);
46400+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
46401 memset(phba->slow_ring_trc, 0,
46402 (sizeof(struct lpfc_debugfs_trc) *
46403 lpfc_debugfs_max_slow_ring_trc));
46404@@ -4214,7 +4214,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
46405 "buffer\n");
46406 goto debug_failed;
46407 }
46408- atomic_set(&vport->disc_trc_cnt, 0);
46409+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
46410
46411 snprintf(name, sizeof(name), "discovery_trace");
46412 vport->debug_disc_trc =
46413diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
46414index e0b20fa..30c2c0d 100644
46415--- a/drivers/scsi/lpfc/lpfc_init.c
46416+++ b/drivers/scsi/lpfc/lpfc_init.c
46417@@ -10936,8 +10936,10 @@ lpfc_init(void)
46418 "misc_register returned with status %d", error);
46419
46420 if (lpfc_enable_npiv) {
46421- lpfc_transport_functions.vport_create = lpfc_vport_create;
46422- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
46423+ pax_open_kernel();
46424+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
46425+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
46426+ pax_close_kernel();
46427 }
46428 lpfc_transport_template =
46429 fc_attach_transport(&lpfc_transport_functions);
46430diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
46431index 243de1d..f40e3e5 100644
46432--- a/drivers/scsi/lpfc/lpfc_scsi.c
46433+++ b/drivers/scsi/lpfc/lpfc_scsi.c
46434@@ -353,7 +353,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
46435 uint32_t evt_posted;
46436
46437 spin_lock_irqsave(&phba->hbalock, flags);
46438- atomic_inc(&phba->num_rsrc_err);
46439+ atomic_inc_unchecked(&phba->num_rsrc_err);
46440 phba->last_rsrc_error_time = jiffies;
46441
46442 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
46443@@ -394,7 +394,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
46444 unsigned long flags;
46445 struct lpfc_hba *phba = vport->phba;
46446 uint32_t evt_posted;
46447- atomic_inc(&phba->num_cmd_success);
46448+ atomic_inc_unchecked(&phba->num_cmd_success);
46449
46450 if (vport->cfg_lun_queue_depth <= queue_depth)
46451 return;
46452@@ -438,8 +438,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
46453 unsigned long num_rsrc_err, num_cmd_success;
46454 int i;
46455
46456- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
46457- num_cmd_success = atomic_read(&phba->num_cmd_success);
46458+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
46459+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
46460
46461 /*
46462 * The error and success command counters are global per
46463@@ -467,8 +467,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
46464 }
46465 }
46466 lpfc_destroy_vport_work_array(phba, vports);
46467- atomic_set(&phba->num_rsrc_err, 0);
46468- atomic_set(&phba->num_cmd_success, 0);
46469+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
46470+ atomic_set_unchecked(&phba->num_cmd_success, 0);
46471 }
46472
46473 /**
46474@@ -502,8 +502,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
46475 }
46476 }
46477 lpfc_destroy_vport_work_array(phba, vports);
46478- atomic_set(&phba->num_rsrc_err, 0);
46479- atomic_set(&phba->num_cmd_success, 0);
46480+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
46481+ atomic_set_unchecked(&phba->num_cmd_success, 0);
46482 }
46483
46484 /**
46485diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
46486index 1eb7b028..b2a6080 100644
46487--- a/drivers/scsi/pmcraid.c
46488+++ b/drivers/scsi/pmcraid.c
46489@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
46490 res->scsi_dev = scsi_dev;
46491 scsi_dev->hostdata = res;
46492 res->change_detected = 0;
46493- atomic_set(&res->read_failures, 0);
46494- atomic_set(&res->write_failures, 0);
46495+ atomic_set_unchecked(&res->read_failures, 0);
46496+ atomic_set_unchecked(&res->write_failures, 0);
46497 rc = 0;
46498 }
46499 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
46500@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
46501
46502 /* If this was a SCSI read/write command keep count of errors */
46503 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
46504- atomic_inc(&res->read_failures);
46505+ atomic_inc_unchecked(&res->read_failures);
46506 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
46507- atomic_inc(&res->write_failures);
46508+ atomic_inc_unchecked(&res->write_failures);
46509
46510 if (!RES_IS_GSCSI(res->cfg_entry) &&
46511 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
46512@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
46513 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
46514 * hrrq_id assigned here in queuecommand
46515 */
46516- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
46517+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
46518 pinstance->num_hrrq;
46519 cmd->cmd_done = pmcraid_io_done;
46520
46521@@ -3846,7 +3846,7 @@ static long pmcraid_ioctl_passthrough(
46522 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
46523 * hrrq_id assigned here in queuecommand
46524 */
46525- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
46526+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
46527 pinstance->num_hrrq;
46528
46529 if (request_size) {
46530@@ -4483,7 +4483,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
46531
46532 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
46533 /* add resources only after host is added into system */
46534- if (!atomic_read(&pinstance->expose_resources))
46535+ if (!atomic_read_unchecked(&pinstance->expose_resources))
46536 return;
46537
46538 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
46539@@ -5310,8 +5310,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
46540 init_waitqueue_head(&pinstance->reset_wait_q);
46541
46542 atomic_set(&pinstance->outstanding_cmds, 0);
46543- atomic_set(&pinstance->last_message_id, 0);
46544- atomic_set(&pinstance->expose_resources, 0);
46545+ atomic_set_unchecked(&pinstance->last_message_id, 0);
46546+ atomic_set_unchecked(&pinstance->expose_resources, 0);
46547
46548 INIT_LIST_HEAD(&pinstance->free_res_q);
46549 INIT_LIST_HEAD(&pinstance->used_res_q);
46550@@ -6024,7 +6024,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
46551 /* Schedule worker thread to handle CCN and take care of adding and
46552 * removing devices to OS
46553 */
46554- atomic_set(&pinstance->expose_resources, 1);
46555+ atomic_set_unchecked(&pinstance->expose_resources, 1);
46556 schedule_work(&pinstance->worker_q);
46557 return rc;
46558
46559diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
46560index e1d150f..6c6df44 100644
46561--- a/drivers/scsi/pmcraid.h
46562+++ b/drivers/scsi/pmcraid.h
46563@@ -748,7 +748,7 @@ struct pmcraid_instance {
46564 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
46565
46566 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
46567- atomic_t last_message_id;
46568+ atomic_unchecked_t last_message_id;
46569
46570 /* configuration table */
46571 struct pmcraid_config_table *cfg_table;
46572@@ -777,7 +777,7 @@ struct pmcraid_instance {
46573 atomic_t outstanding_cmds;
46574
46575 /* should add/delete resources to mid-layer now ?*/
46576- atomic_t expose_resources;
46577+ atomic_unchecked_t expose_resources;
46578
46579
46580
46581@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
46582 struct pmcraid_config_table_entry_ext cfg_entry_ext;
46583 };
46584 struct scsi_device *scsi_dev; /* Link scsi_device structure */
46585- atomic_t read_failures; /* count of failed READ commands */
46586- atomic_t write_failures; /* count of failed WRITE commands */
46587+ atomic_unchecked_t read_failures; /* count of failed READ commands */
46588+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
46589
46590 /* To indicate add/delete/modify during CCN */
46591 u8 change_detected;
46592diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
46593index d7a99ae..801df70 100644
46594--- a/drivers/scsi/qla2xxx/qla_attr.c
46595+++ b/drivers/scsi/qla2xxx/qla_attr.c
46596@@ -2004,7 +2004,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
46597 return 0;
46598 }
46599
46600-struct fc_function_template qla2xxx_transport_functions = {
46601+fc_function_template_no_const qla2xxx_transport_functions = {
46602
46603 .show_host_node_name = 1,
46604 .show_host_port_name = 1,
46605@@ -2051,7 +2051,7 @@ struct fc_function_template qla2xxx_transport_functions = {
46606 .bsg_timeout = qla24xx_bsg_timeout,
46607 };
46608
46609-struct fc_function_template qla2xxx_transport_vport_functions = {
46610+fc_function_template_no_const qla2xxx_transport_vport_functions = {
46611
46612 .show_host_node_name = 1,
46613 .show_host_port_name = 1,
46614diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
46615index 2d98232..a84298e 100644
46616--- a/drivers/scsi/qla2xxx/qla_gbl.h
46617+++ b/drivers/scsi/qla2xxx/qla_gbl.h
46618@@ -528,8 +528,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
46619 struct device_attribute;
46620 extern struct device_attribute *qla2x00_host_attrs[];
46621 struct fc_function_template;
46622-extern struct fc_function_template qla2xxx_transport_functions;
46623-extern struct fc_function_template qla2xxx_transport_vport_functions;
46624+extern fc_function_template_no_const qla2xxx_transport_functions;
46625+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
46626 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
46627 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
46628 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
46629diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
46630index 3e21e9f..426ba79 100644
46631--- a/drivers/scsi/qla2xxx/qla_os.c
46632+++ b/drivers/scsi/qla2xxx/qla_os.c
46633@@ -1570,8 +1570,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
46634 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
46635 /* Ok, a 64bit DMA mask is applicable. */
46636 ha->flags.enable_64bit_addressing = 1;
46637- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
46638- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
46639+ pax_open_kernel();
46640+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
46641+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
46642+ pax_close_kernel();
46643 return;
46644 }
46645 }
46646diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
46647index ddf16a8..80f4dd0 100644
46648--- a/drivers/scsi/qla4xxx/ql4_def.h
46649+++ b/drivers/scsi/qla4xxx/ql4_def.h
46650@@ -291,7 +291,7 @@ struct ddb_entry {
46651 * (4000 only) */
46652 atomic_t relogin_timer; /* Max Time to wait for
46653 * relogin to complete */
46654- atomic_t relogin_retry_count; /* Num of times relogin has been
46655+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
46656 * retried */
46657 uint32_t default_time2wait; /* Default Min time between
46658 * relogins (+aens) */
46659diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
46660index b246b3c..897004d 100644
46661--- a/drivers/scsi/qla4xxx/ql4_os.c
46662+++ b/drivers/scsi/qla4xxx/ql4_os.c
46663@@ -2971,12 +2971,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
46664 */
46665 if (!iscsi_is_session_online(cls_sess)) {
46666 /* Reset retry relogin timer */
46667- atomic_inc(&ddb_entry->relogin_retry_count);
46668+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
46669 DEBUG2(ql4_printk(KERN_INFO, ha,
46670 "%s: index[%d] relogin timed out-retrying"
46671 " relogin (%d), retry (%d)\n", __func__,
46672 ddb_entry->fw_ddb_index,
46673- atomic_read(&ddb_entry->relogin_retry_count),
46674+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
46675 ddb_entry->default_time2wait + 4));
46676 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
46677 atomic_set(&ddb_entry->retry_relogin_timer,
46678@@ -5081,7 +5081,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
46679
46680 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
46681 atomic_set(&ddb_entry->relogin_timer, 0);
46682- atomic_set(&ddb_entry->relogin_retry_count, 0);
46683+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
46684 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
46685 ddb_entry->default_relogin_timeout =
46686 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
46687diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
46688index eaa808e..95f8841 100644
46689--- a/drivers/scsi/scsi.c
46690+++ b/drivers/scsi/scsi.c
46691@@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
46692 unsigned long timeout;
46693 int rtn = 0;
46694
46695- atomic_inc(&cmd->device->iorequest_cnt);
46696+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
46697
46698 /* check if the device is still usable */
46699 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
46700diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
46701index 124392f..75eb43e 100644
46702--- a/drivers/scsi/scsi_lib.c
46703+++ b/drivers/scsi/scsi_lib.c
46704@@ -1474,7 +1474,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
46705 shost = sdev->host;
46706 scsi_init_cmd_errh(cmd);
46707 cmd->result = DID_NO_CONNECT << 16;
46708- atomic_inc(&cmd->device->iorequest_cnt);
46709+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
46710
46711 /*
46712 * SCSI request completion path will do scsi_device_unbusy(),
46713@@ -1500,9 +1500,9 @@ static void scsi_softirq_done(struct request *rq)
46714
46715 INIT_LIST_HEAD(&cmd->eh_entry);
46716
46717- atomic_inc(&cmd->device->iodone_cnt);
46718+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
46719 if (cmd->result)
46720- atomic_inc(&cmd->device->ioerr_cnt);
46721+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
46722
46723 disposition = scsi_decide_disposition(cmd);
46724 if (disposition != SUCCESS &&
46725diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
46726index 7e50061..71db7a6 100644
46727--- a/drivers/scsi/scsi_sysfs.c
46728+++ b/drivers/scsi/scsi_sysfs.c
46729@@ -687,7 +687,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
46730 char *buf) \
46731 { \
46732 struct scsi_device *sdev = to_scsi_device(dev); \
46733- unsigned long long count = atomic_read(&sdev->field); \
46734+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
46735 return snprintf(buf, 20, "0x%llx\n", count); \
46736 } \
46737 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
46738diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
46739index 84a1fdf..693b0d6 100644
46740--- a/drivers/scsi/scsi_tgt_lib.c
46741+++ b/drivers/scsi/scsi_tgt_lib.c
46742@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
46743 int err;
46744
46745 dprintk("%lx %u\n", uaddr, len);
46746- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
46747+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
46748 if (err) {
46749 /*
46750 * TODO: need to fixup sg_tablesize, max_segment_size,
46751diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
46752index 4628fd5..a94a1c2 100644
46753--- a/drivers/scsi/scsi_transport_fc.c
46754+++ b/drivers/scsi/scsi_transport_fc.c
46755@@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
46756 * Netlink Infrastructure
46757 */
46758
46759-static atomic_t fc_event_seq;
46760+static atomic_unchecked_t fc_event_seq;
46761
46762 /**
46763 * fc_get_event_number - Obtain the next sequential FC event number
46764@@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
46765 u32
46766 fc_get_event_number(void)
46767 {
46768- return atomic_add_return(1, &fc_event_seq);
46769+ return atomic_add_return_unchecked(1, &fc_event_seq);
46770 }
46771 EXPORT_SYMBOL(fc_get_event_number);
46772
46773@@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
46774 {
46775 int error;
46776
46777- atomic_set(&fc_event_seq, 0);
46778+ atomic_set_unchecked(&fc_event_seq, 0);
46779
46780 error = transport_class_register(&fc_host_class);
46781 if (error)
46782@@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
46783 char *cp;
46784
46785 *val = simple_strtoul(buf, &cp, 0);
46786- if ((*cp && (*cp != '\n')) || (*val < 0))
46787+ if (*cp && (*cp != '\n'))
46788 return -EINVAL;
46789 /*
46790 * Check for overflow; dev_loss_tmo is u32
46791diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
46792index abf7c40..c3240ed 100644
46793--- a/drivers/scsi/scsi_transport_iscsi.c
46794+++ b/drivers/scsi/scsi_transport_iscsi.c
46795@@ -80,7 +80,7 @@ struct iscsi_internal {
46796 struct transport_container session_cont;
46797 };
46798
46799-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
46800+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
46801 static struct workqueue_struct *iscsi_eh_timer_workq;
46802
46803 static DEFINE_IDA(iscsi_sess_ida);
46804@@ -1738,7 +1738,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
46805 int err;
46806
46807 ihost = shost->shost_data;
46808- session->sid = atomic_add_return(1, &iscsi_session_nr);
46809+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
46810
46811 if (target_id == ISCSI_MAX_TARGET) {
46812 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
46813@@ -3956,7 +3956,7 @@ static __init int iscsi_transport_init(void)
46814 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
46815 ISCSI_TRANSPORT_VERSION);
46816
46817- atomic_set(&iscsi_session_nr, 0);
46818+ atomic_set_unchecked(&iscsi_session_nr, 0);
46819
46820 err = class_register(&iscsi_transport_class);
46821 if (err)
46822diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
46823index f379c7f..e8fc69c 100644
46824--- a/drivers/scsi/scsi_transport_srp.c
46825+++ b/drivers/scsi/scsi_transport_srp.c
46826@@ -33,7 +33,7 @@
46827 #include "scsi_transport_srp_internal.h"
46828
46829 struct srp_host_attrs {
46830- atomic_t next_port_id;
46831+ atomic_unchecked_t next_port_id;
46832 };
46833 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
46834
46835@@ -61,7 +61,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
46836 struct Scsi_Host *shost = dev_to_shost(dev);
46837 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
46838
46839- atomic_set(&srp_host->next_port_id, 0);
46840+ atomic_set_unchecked(&srp_host->next_port_id, 0);
46841 return 0;
46842 }
46843
46844@@ -210,7 +210,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
46845 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
46846 rport->roles = ids->roles;
46847
46848- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
46849+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
46850 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
46851
46852 transport_setup_device(&rport->dev);
46853diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
46854index 2783dd7..d20395b 100644
46855--- a/drivers/scsi/sd.c
46856+++ b/drivers/scsi/sd.c
46857@@ -2933,7 +2933,7 @@ static int sd_probe(struct device *dev)
46858 sdkp->disk = gd;
46859 sdkp->index = index;
46860 atomic_set(&sdkp->openers, 0);
46861- atomic_set(&sdkp->device->ioerr_cnt, 0);
46862+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
46863
46864 if (!sdp->request_queue->rq_timeout) {
46865 if (sdp->type != TYPE_MOD)
46866diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
46867index df5e961..df6b97f 100644
46868--- a/drivers/scsi/sg.c
46869+++ b/drivers/scsi/sg.c
46870@@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
46871 sdp->disk->disk_name,
46872 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
46873 NULL,
46874- (char *)arg);
46875+ (char __user *)arg);
46876 case BLKTRACESTART:
46877 return blk_trace_startstop(sdp->device->request_queue, 1);
46878 case BLKTRACESTOP:
46879diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
46880index 978dda2..cb19aa0 100644
46881--- a/drivers/spi/spi.c
46882+++ b/drivers/spi/spi.c
46883@@ -1631,7 +1631,7 @@ int spi_bus_unlock(struct spi_master *master)
46884 EXPORT_SYMBOL_GPL(spi_bus_unlock);
46885
46886 /* portable code must never pass more than 32 bytes */
46887-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
46888+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
46889
46890 static u8 *buf;
46891
46892diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
46893index ee3a57f..18368c1 100644
46894--- a/drivers/staging/android/timed_output.c
46895+++ b/drivers/staging/android/timed_output.c
46896@@ -25,7 +25,7 @@
46897 #include "timed_output.h"
46898
46899 static struct class *timed_output_class;
46900-static atomic_t device_count;
46901+static atomic_unchecked_t device_count;
46902
46903 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
46904 char *buf)
46905@@ -59,7 +59,7 @@ static int create_timed_output_class(void)
46906 timed_output_class = class_create(THIS_MODULE, "timed_output");
46907 if (IS_ERR(timed_output_class))
46908 return PTR_ERR(timed_output_class);
46909- atomic_set(&device_count, 0);
46910+ atomic_set_unchecked(&device_count, 0);
46911 }
46912
46913 return 0;
46914@@ -76,7 +76,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
46915 if (ret < 0)
46916 return ret;
46917
46918- tdev->index = atomic_inc_return(&device_count);
46919+ tdev->index = atomic_inc_return_unchecked(&device_count);
46920 tdev->dev = device_create(timed_output_class, NULL,
46921 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
46922 if (IS_ERR(tdev->dev))
46923diff --git a/drivers/staging/bcm/Bcmchar.c b/drivers/staging/bcm/Bcmchar.c
46924index f67a225..756b634 100644
46925--- a/drivers/staging/bcm/Bcmchar.c
46926+++ b/drivers/staging/bcm/Bcmchar.c
46927@@ -1960,6 +1960,7 @@ cntrlEnd:
46928
46929 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Called IOCTL_BCM_GET_DEVICE_DRIVER_INFO\n");
46930
46931+ memset(&DevInfo, 0, sizeof(DevInfo));
46932 DevInfo.MaxRDMBufferSize = BUFFER_4K;
46933 DevInfo.u32DSDStartOffset = EEPROM_CALPARAM_START;
46934 DevInfo.u32RxAlignmentCorrection = 0;
46935diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
46936index 3675020..e80d92c 100644
46937--- a/drivers/staging/media/solo6x10/solo6x10-core.c
46938+++ b/drivers/staging/media/solo6x10/solo6x10-core.c
46939@@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
46940
46941 static int solo_sysfs_init(struct solo_dev *solo_dev)
46942 {
46943- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
46944+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
46945 struct device *dev = &solo_dev->dev;
46946 const char *driver;
46947 int i;
46948diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
46949index 3335941..2b26186 100644
46950--- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
46951+++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
46952@@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
46953
46954 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
46955 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
46956- p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
46957+ p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
46958 if (p2m_id < 0)
46959 p2m_id = -p2m_id;
46960 }
46961diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
46962index 6f91d2e..3f011d2 100644
46963--- a/drivers/staging/media/solo6x10/solo6x10.h
46964+++ b/drivers/staging/media/solo6x10/solo6x10.h
46965@@ -238,7 +238,7 @@ struct solo_dev {
46966
46967 /* P2M DMA Engine */
46968 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
46969- atomic_t p2m_count;
46970+ atomic_unchecked_t p2m_count;
46971 int p2m_jiffies;
46972 unsigned int p2m_timeouts;
46973
46974diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
46975index 34afc16..ffe44dd 100644
46976--- a/drivers/staging/octeon/ethernet-rx.c
46977+++ b/drivers/staging/octeon/ethernet-rx.c
46978@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
46979 /* Increment RX stats for virtual ports */
46980 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
46981 #ifdef CONFIG_64BIT
46982- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
46983- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
46984+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
46985+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
46986 #else
46987- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
46988- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
46989+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
46990+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
46991 #endif
46992 }
46993 netif_receive_skb(skb);
46994@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
46995 dev->name);
46996 */
46997 #ifdef CONFIG_64BIT
46998- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
46999+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
47000 #else
47001- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
47002+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
47003 #endif
47004 dev_kfree_skb_irq(skb);
47005 }
47006diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
47007index c3a90e7..023619a 100644
47008--- a/drivers/staging/octeon/ethernet.c
47009+++ b/drivers/staging/octeon/ethernet.c
47010@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
47011 * since the RX tasklet also increments it.
47012 */
47013 #ifdef CONFIG_64BIT
47014- atomic64_add(rx_status.dropped_packets,
47015- (atomic64_t *)&priv->stats.rx_dropped);
47016+ atomic64_add_unchecked(rx_status.dropped_packets,
47017+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
47018 #else
47019- atomic_add(rx_status.dropped_packets,
47020- (atomic_t *)&priv->stats.rx_dropped);
47021+ atomic_add_unchecked(rx_status.dropped_packets,
47022+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
47023 #endif
47024 }
47025
47026diff --git a/drivers/staging/ozwpan/ozcdev.c b/drivers/staging/ozwpan/ozcdev.c
47027index 374fdc3..ea5f9f3 100644
47028--- a/drivers/staging/ozwpan/ozcdev.c
47029+++ b/drivers/staging/ozwpan/ozcdev.c
47030@@ -152,6 +152,9 @@ static ssize_t oz_cdev_write(struct file *filp, const char __user *buf,
47031 struct oz_app_hdr *app_hdr;
47032 struct oz_serial_ctx *ctx;
47033
47034+ if (count > sizeof(ei->data) - sizeof(*elt) - sizeof(*app_hdr))
47035+ return -EINVAL;
47036+
47037 spin_lock_bh(&g_cdev.lock);
47038 pd = g_cdev.active_pd;
47039 if (pd)
47040diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
47041index dc23395..cf7e9b1 100644
47042--- a/drivers/staging/rtl8712/rtl871x_io.h
47043+++ b/drivers/staging/rtl8712/rtl871x_io.h
47044@@ -108,7 +108,7 @@ struct _io_ops {
47045 u8 *pmem);
47046 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
47047 u8 *pmem);
47048-};
47049+} __no_const;
47050
47051 struct io_req {
47052 struct list_head list;
47053diff --git a/drivers/staging/sb105x/sb_pci_mp.c b/drivers/staging/sb105x/sb_pci_mp.c
47054index 23db32f..a10cdb1 100644
47055--- a/drivers/staging/sb105x/sb_pci_mp.c
47056+++ b/drivers/staging/sb105x/sb_pci_mp.c
47057@@ -1063,7 +1063,7 @@ static int mp_wait_modem_status(struct sb_uart_state *state, unsigned long arg)
47058
47059 static int mp_get_count(struct sb_uart_state *state, struct serial_icounter_struct *icnt)
47060 {
47061- struct serial_icounter_struct icount;
47062+ struct serial_icounter_struct icount = {};
47063 struct sb_uart_icount cnow;
47064 struct sb_uart_port *port = state->port;
47065
47066diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
47067index 1f5088b..0e59820 100644
47068--- a/drivers/staging/sbe-2t3e3/netdev.c
47069+++ b/drivers/staging/sbe-2t3e3/netdev.c
47070@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
47071 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
47072
47073 if (rlen)
47074- if (copy_to_user(data, &resp, rlen))
47075+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
47076 return -EFAULT;
47077
47078 return 0;
47079diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
47080index a863a98..d272795 100644
47081--- a/drivers/staging/usbip/vhci.h
47082+++ b/drivers/staging/usbip/vhci.h
47083@@ -83,7 +83,7 @@ struct vhci_hcd {
47084 unsigned resuming:1;
47085 unsigned long re_timeout;
47086
47087- atomic_t seqnum;
47088+ atomic_unchecked_t seqnum;
47089
47090 /*
47091 * NOTE:
47092diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
47093index d7974cb..d78076b 100644
47094--- a/drivers/staging/usbip/vhci_hcd.c
47095+++ b/drivers/staging/usbip/vhci_hcd.c
47096@@ -441,7 +441,7 @@ static void vhci_tx_urb(struct urb *urb)
47097
47098 spin_lock(&vdev->priv_lock);
47099
47100- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
47101+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
47102 if (priv->seqnum == 0xffff)
47103 dev_info(&urb->dev->dev, "seqnum max\n");
47104
47105@@ -687,7 +687,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
47106 return -ENOMEM;
47107 }
47108
47109- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
47110+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
47111 if (unlink->seqnum == 0xffff)
47112 pr_info("seqnum max\n");
47113
47114@@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
47115 vdev->rhport = rhport;
47116 }
47117
47118- atomic_set(&vhci->seqnum, 0);
47119+ atomic_set_unchecked(&vhci->seqnum, 0);
47120 spin_lock_init(&vhci->lock);
47121
47122 hcd->power_budget = 0; /* no limit */
47123diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
47124index d07fcb5..358e1e1 100644
47125--- a/drivers/staging/usbip/vhci_rx.c
47126+++ b/drivers/staging/usbip/vhci_rx.c
47127@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
47128 if (!urb) {
47129 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
47130 pr_info("max seqnum %d\n",
47131- atomic_read(&the_controller->seqnum));
47132+ atomic_read_unchecked(&the_controller->seqnum));
47133 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
47134 return;
47135 }
47136diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
47137index 57a08c5..5b4bb7c 100644
47138--- a/drivers/staging/vt6655/hostap.c
47139+++ b/drivers/staging/vt6655/hostap.c
47140@@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
47141 *
47142 */
47143
47144+static net_device_ops_no_const apdev_netdev_ops;
47145+
47146 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
47147 {
47148 PSDevice apdev_priv;
47149 struct net_device *dev = pDevice->dev;
47150 int ret;
47151- const struct net_device_ops apdev_netdev_ops = {
47152- .ndo_start_xmit = pDevice->tx_80211,
47153- };
47154
47155 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
47156
47157@@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
47158 *apdev_priv = *pDevice;
47159 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
47160
47161+ /* only half broken now */
47162+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
47163 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
47164
47165 pDevice->apdev->type = ARPHRD_IEEE80211;
47166diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
47167index c699a30..b90a5fd 100644
47168--- a/drivers/staging/vt6656/hostap.c
47169+++ b/drivers/staging/vt6656/hostap.c
47170@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
47171 *
47172 */
47173
47174+static net_device_ops_no_const apdev_netdev_ops;
47175+
47176 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
47177 {
47178 struct vnt_private *apdev_priv;
47179 struct net_device *dev = pDevice->dev;
47180 int ret;
47181- const struct net_device_ops apdev_netdev_ops = {
47182- .ndo_start_xmit = pDevice->tx_80211,
47183- };
47184
47185 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
47186
47187@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
47188 *apdev_priv = *pDevice;
47189 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
47190
47191+ /* only half broken now */
47192+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
47193 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
47194
47195 pDevice->apdev->type = ARPHRD_IEEE80211;
47196diff --git a/drivers/staging/wlags49_h2/wl_priv.c b/drivers/staging/wlags49_h2/wl_priv.c
47197index c97e0e1..7e10dcd 100644
47198--- a/drivers/staging/wlags49_h2/wl_priv.c
47199+++ b/drivers/staging/wlags49_h2/wl_priv.c
47200@@ -570,6 +570,7 @@ int wvlan_uil_put_info(struct uilreq *urq, struct wl_private *lp)
47201 ltv_t *pLtv;
47202 bool_t ltvAllocated = FALSE;
47203 ENCSTRCT sEncryption;
47204+ size_t len;
47205
47206 #ifdef USE_WDS
47207 hcf_16 hcfPort = HCF_PORT_0;
47208@@ -686,7 +687,8 @@ int wvlan_uil_put_info(struct uilreq *urq, struct wl_private *lp)
47209 break;
47210 case CFG_CNF_OWN_NAME:
47211 memset(lp->StationName, 0, sizeof(lp->StationName));
47212- memcpy((void *)lp->StationName, (void *)&pLtv->u.u8[2], (size_t)pLtv->u.u16[0]);
47213+ len = min_t(size_t, pLtv->u.u16[0], sizeof(lp->StationName));
47214+ strlcpy(lp->StationName, &pLtv->u.u8[2], len);
47215 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
47216 break;
47217 case CFG_CNF_LOAD_BALANCING:
47218@@ -1783,6 +1785,7 @@ int wvlan_set_station_nickname(struct net_device *dev,
47219 {
47220 struct wl_private *lp = wl_priv(dev);
47221 unsigned long flags;
47222+ size_t len;
47223 int ret = 0;
47224 /*------------------------------------------------------------------------*/
47225
47226@@ -1793,8 +1796,8 @@ int wvlan_set_station_nickname(struct net_device *dev,
47227 wl_lock(lp, &flags);
47228
47229 memset(lp->StationName, 0, sizeof(lp->StationName));
47230-
47231- memcpy(lp->StationName, extra, wrqu->data.length);
47232+ len = min_t(size_t, wrqu->data.length, sizeof(lp->StationName));
47233+ strlcpy(lp->StationName, extra, len);
47234
47235 /* Commit the adapter parameters */
47236 wl_apply(lp);
47237diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
47238index d128ce2..fc1f9a1 100644
47239--- a/drivers/staging/zcache/tmem.h
47240+++ b/drivers/staging/zcache/tmem.h
47241@@ -225,7 +225,7 @@ struct tmem_pamops {
47242 bool (*is_remote)(void *);
47243 int (*replace_in_obj)(void *, struct tmem_obj *);
47244 #endif
47245-};
47246+} __no_const;
47247 extern void tmem_register_pamops(struct tmem_pamops *m);
47248
47249 /* memory allocation methods provided by the host implementation */
47250@@ -234,7 +234,7 @@ struct tmem_hostops {
47251 void (*obj_free)(struct tmem_obj *, struct tmem_pool *);
47252 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
47253 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
47254-};
47255+} __no_const;
47256 extern void tmem_register_hostops(struct tmem_hostops *m);
47257
47258 /* core tmem accessor functions */
47259diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
47260index e51b09a..5ebac31 100644
47261--- a/drivers/target/sbp/sbp_target.c
47262+++ b/drivers/target/sbp/sbp_target.c
47263@@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
47264
47265 #define SESSION_MAINTENANCE_INTERVAL HZ
47266
47267-static atomic_t login_id = ATOMIC_INIT(0);
47268+static atomic_unchecked_t login_id = ATOMIC_INIT(0);
47269
47270 static void session_maintenance_work(struct work_struct *);
47271 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
47272@@ -444,7 +444,7 @@ static void sbp_management_request_login(
47273 login->lun = se_lun;
47274 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
47275 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
47276- login->login_id = atomic_inc_return(&login_id);
47277+ login->login_id = atomic_inc_return_unchecked(&login_id);
47278
47279 login->tgt_agt = sbp_target_agent_register(login);
47280 if (IS_ERR(login->tgt_agt)) {
47281diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
47282index 8f4142f..b127f7d 100644
47283--- a/drivers/target/target_core_device.c
47284+++ b/drivers/target/target_core_device.c
47285@@ -1400,7 +1400,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
47286 spin_lock_init(&dev->se_port_lock);
47287 spin_lock_init(&dev->se_tmr_lock);
47288 spin_lock_init(&dev->qf_cmd_lock);
47289- atomic_set(&dev->dev_ordered_id, 0);
47290+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
47291 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
47292 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
47293 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
47294diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
47295index d8e49d7..6fcfdec 100644
47296--- a/drivers/target/target_core_transport.c
47297+++ b/drivers/target/target_core_transport.c
47298@@ -1080,7 +1080,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
47299 * Used to determine when ORDERED commands should go from
47300 * Dormant to Active status.
47301 */
47302- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
47303+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
47304 smp_mb__after_atomic_inc();
47305 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
47306 cmd->se_ordered_id, cmd->sam_task_attr,
47307diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
47308index 33f83fe..d80f8e1 100644
47309--- a/drivers/tty/cyclades.c
47310+++ b/drivers/tty/cyclades.c
47311@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
47312 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
47313 info->port.count);
47314 #endif
47315- info->port.count++;
47316+ atomic_inc(&info->port.count);
47317 #ifdef CY_DEBUG_COUNT
47318 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
47319- current->pid, info->port.count);
47320+ current->pid, atomic_read(&info->port.count));
47321 #endif
47322
47323 /*
47324@@ -3972,7 +3972,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
47325 for (j = 0; j < cy_card[i].nports; j++) {
47326 info = &cy_card[i].ports[j];
47327
47328- if (info->port.count) {
47329+ if (atomic_read(&info->port.count)) {
47330 /* XXX is the ldisc num worth this? */
47331 struct tty_struct *tty;
47332 struct tty_ldisc *ld;
47333diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
47334index eb255e8..f637a57 100644
47335--- a/drivers/tty/hvc/hvc_console.c
47336+++ b/drivers/tty/hvc/hvc_console.c
47337@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
47338
47339 spin_lock_irqsave(&hp->port.lock, flags);
47340 /* Check and then increment for fast path open. */
47341- if (hp->port.count++ > 0) {
47342+ if (atomic_inc_return(&hp->port.count) > 1) {
47343 spin_unlock_irqrestore(&hp->port.lock, flags);
47344 hvc_kick();
47345 return 0;
47346@@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
47347
47348 spin_lock_irqsave(&hp->port.lock, flags);
47349
47350- if (--hp->port.count == 0) {
47351+ if (atomic_dec_return(&hp->port.count) == 0) {
47352 spin_unlock_irqrestore(&hp->port.lock, flags);
47353 /* We are done with the tty pointer now. */
47354 tty_port_tty_set(&hp->port, NULL);
47355@@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
47356 */
47357 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
47358 } else {
47359- if (hp->port.count < 0)
47360+ if (atomic_read(&hp->port.count) < 0)
47361 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
47362- hp->vtermno, hp->port.count);
47363+ hp->vtermno, atomic_read(&hp->port.count));
47364 spin_unlock_irqrestore(&hp->port.lock, flags);
47365 }
47366 }
47367@@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
47368 * open->hangup case this can be called after the final close so prevent
47369 * that from happening for now.
47370 */
47371- if (hp->port.count <= 0) {
47372+ if (atomic_read(&hp->port.count) <= 0) {
47373 spin_unlock_irqrestore(&hp->port.lock, flags);
47374 return;
47375 }
47376
47377- hp->port.count = 0;
47378+ atomic_set(&hp->port.count, 0);
47379 spin_unlock_irqrestore(&hp->port.lock, flags);
47380 tty_port_tty_set(&hp->port, NULL);
47381
47382@@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
47383 return -EPIPE;
47384
47385 /* FIXME what's this (unprotected) check for? */
47386- if (hp->port.count <= 0)
47387+ if (atomic_read(&hp->port.count) <= 0)
47388 return -EIO;
47389
47390 spin_lock_irqsave(&hp->lock, flags);
47391diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
47392index 81e939e..95ead10 100644
47393--- a/drivers/tty/hvc/hvcs.c
47394+++ b/drivers/tty/hvc/hvcs.c
47395@@ -83,6 +83,7 @@
47396 #include <asm/hvcserver.h>
47397 #include <asm/uaccess.h>
47398 #include <asm/vio.h>
47399+#include <asm/local.h>
47400
47401 /*
47402 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
47403@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
47404
47405 spin_lock_irqsave(&hvcsd->lock, flags);
47406
47407- if (hvcsd->port.count > 0) {
47408+ if (atomic_read(&hvcsd->port.count) > 0) {
47409 spin_unlock_irqrestore(&hvcsd->lock, flags);
47410 printk(KERN_INFO "HVCS: vterm state unchanged. "
47411 "The hvcs device node is still in use.\n");
47412@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
47413 }
47414 }
47415
47416- hvcsd->port.count = 0;
47417+ atomic_set(&hvcsd->port.count, 0);
47418 hvcsd->port.tty = tty;
47419 tty->driver_data = hvcsd;
47420
47421@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
47422 unsigned long flags;
47423
47424 spin_lock_irqsave(&hvcsd->lock, flags);
47425- hvcsd->port.count++;
47426+ atomic_inc(&hvcsd->port.count);
47427 hvcsd->todo_mask |= HVCS_SCHED_READ;
47428 spin_unlock_irqrestore(&hvcsd->lock, flags);
47429
47430@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
47431 hvcsd = tty->driver_data;
47432
47433 spin_lock_irqsave(&hvcsd->lock, flags);
47434- if (--hvcsd->port.count == 0) {
47435+ if (atomic_dec_and_test(&hvcsd->port.count)) {
47436
47437 vio_disable_interrupts(hvcsd->vdev);
47438
47439@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
47440
47441 free_irq(irq, hvcsd);
47442 return;
47443- } else if (hvcsd->port.count < 0) {
47444+ } else if (atomic_read(&hvcsd->port.count) < 0) {
47445 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
47446 " is missmanaged.\n",
47447- hvcsd->vdev->unit_address, hvcsd->port.count);
47448+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
47449 }
47450
47451 spin_unlock_irqrestore(&hvcsd->lock, flags);
47452@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
47453
47454 spin_lock_irqsave(&hvcsd->lock, flags);
47455 /* Preserve this so that we know how many kref refs to put */
47456- temp_open_count = hvcsd->port.count;
47457+ temp_open_count = atomic_read(&hvcsd->port.count);
47458
47459 /*
47460 * Don't kref put inside the spinlock because the destruction
47461@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
47462 tty->driver_data = NULL;
47463 hvcsd->port.tty = NULL;
47464
47465- hvcsd->port.count = 0;
47466+ atomic_set(&hvcsd->port.count, 0);
47467
47468 /* This will drop any buffered data on the floor which is OK in a hangup
47469 * scenario. */
47470@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
47471 * the middle of a write operation? This is a crummy place to do this
47472 * but we want to keep it all in the spinlock.
47473 */
47474- if (hvcsd->port.count <= 0) {
47475+ if (atomic_read(&hvcsd->port.count) <= 0) {
47476 spin_unlock_irqrestore(&hvcsd->lock, flags);
47477 return -ENODEV;
47478 }
47479@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
47480 {
47481 struct hvcs_struct *hvcsd = tty->driver_data;
47482
47483- if (!hvcsd || hvcsd->port.count <= 0)
47484+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
47485 return 0;
47486
47487 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
47488diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
47489index 4190199..48f2920 100644
47490--- a/drivers/tty/hvc/hvsi.c
47491+++ b/drivers/tty/hvc/hvsi.c
47492@@ -85,7 +85,7 @@ struct hvsi_struct {
47493 int n_outbuf;
47494 uint32_t vtermno;
47495 uint32_t virq;
47496- atomic_t seqno; /* HVSI packet sequence number */
47497+ atomic_unchecked_t seqno; /* HVSI packet sequence number */
47498 uint16_t mctrl;
47499 uint8_t state; /* HVSI protocol state */
47500 uint8_t flags;
47501@@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
47502
47503 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
47504 packet.hdr.len = sizeof(struct hvsi_query_response);
47505- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47506+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47507 packet.verb = VSV_SEND_VERSION_NUMBER;
47508 packet.u.version = HVSI_VERSION;
47509 packet.query_seqno = query_seqno+1;
47510@@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
47511
47512 packet.hdr.type = VS_QUERY_PACKET_HEADER;
47513 packet.hdr.len = sizeof(struct hvsi_query);
47514- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47515+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47516 packet.verb = verb;
47517
47518 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
47519@@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
47520 int wrote;
47521
47522 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
47523- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47524+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47525 packet.hdr.len = sizeof(struct hvsi_control);
47526 packet.verb = VSV_SET_MODEM_CTL;
47527 packet.mask = HVSI_TSDTR;
47528@@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
47529 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
47530
47531 packet.hdr.type = VS_DATA_PACKET_HEADER;
47532- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47533+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47534 packet.hdr.len = count + sizeof(struct hvsi_header);
47535 memcpy(&packet.data, buf, count);
47536
47537@@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
47538 struct hvsi_control packet __ALIGNED__;
47539
47540 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
47541- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47542+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47543 packet.hdr.len = 6;
47544 packet.verb = VSV_CLOSE_PROTOCOL;
47545
47546diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
47547index ac27671..0f627ee 100644
47548--- a/drivers/tty/hvc/hvsi_lib.c
47549+++ b/drivers/tty/hvc/hvsi_lib.c
47550@@ -9,7 +9,7 @@
47551
47552 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
47553 {
47554- packet->seqno = atomic_inc_return(&pv->seqno);
47555+ packet->seqno = atomic_inc_return_unchecked(&pv->seqno);
47556
47557 /* Assumes that always succeeds, works in practice */
47558 return pv->put_chars(pv->termno, (char *)packet, packet->len);
47559@@ -21,7 +21,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
47560
47561 /* Reset state */
47562 pv->established = 0;
47563- atomic_set(&pv->seqno, 0);
47564+ atomic_set_unchecked(&pv->seqno, 0);
47565
47566 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
47567
47568@@ -265,7 +265,7 @@ int hvsilib_read_mctrl(struct hvsi_priv *pv)
47569 pv->mctrl_update = 0;
47570 q.hdr.type = VS_QUERY_PACKET_HEADER;
47571 q.hdr.len = sizeof(struct hvsi_query);
47572- q.hdr.seqno = atomic_inc_return(&pv->seqno);
47573+ q.hdr.seqno = atomic_inc_return_unchecked(&pv->seqno);
47574 q.verb = VSV_SEND_MODEM_CTL_STATUS;
47575 rc = hvsi_send_packet(pv, &q.hdr);
47576 if (rc <= 0) {
47577diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
47578index 8fd72ff..34a0bed 100644
47579--- a/drivers/tty/ipwireless/tty.c
47580+++ b/drivers/tty/ipwireless/tty.c
47581@@ -29,6 +29,7 @@
47582 #include <linux/tty_driver.h>
47583 #include <linux/tty_flip.h>
47584 #include <linux/uaccess.h>
47585+#include <asm/local.h>
47586
47587 #include "tty.h"
47588 #include "network.h"
47589@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
47590 mutex_unlock(&tty->ipw_tty_mutex);
47591 return -ENODEV;
47592 }
47593- if (tty->port.count == 0)
47594+ if (atomic_read(&tty->port.count) == 0)
47595 tty->tx_bytes_queued = 0;
47596
47597- tty->port.count++;
47598+ atomic_inc(&tty->port.count);
47599
47600 tty->port.tty = linux_tty;
47601 linux_tty->driver_data = tty;
47602@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
47603
47604 static void do_ipw_close(struct ipw_tty *tty)
47605 {
47606- tty->port.count--;
47607-
47608- if (tty->port.count == 0) {
47609+ if (atomic_dec_return(&tty->port.count) == 0) {
47610 struct tty_struct *linux_tty = tty->port.tty;
47611
47612 if (linux_tty != NULL) {
47613@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
47614 return;
47615
47616 mutex_lock(&tty->ipw_tty_mutex);
47617- if (tty->port.count == 0) {
47618+ if (atomic_read(&tty->port.count) == 0) {
47619 mutex_unlock(&tty->ipw_tty_mutex);
47620 return;
47621 }
47622@@ -164,7 +163,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
47623
47624 mutex_lock(&tty->ipw_tty_mutex);
47625
47626- if (!tty->port.count) {
47627+ if (!atomic_read(&tty->port.count)) {
47628 mutex_unlock(&tty->ipw_tty_mutex);
47629 return;
47630 }
47631@@ -206,7 +205,7 @@ static int ipw_write(struct tty_struct *linux_tty,
47632 return -ENODEV;
47633
47634 mutex_lock(&tty->ipw_tty_mutex);
47635- if (!tty->port.count) {
47636+ if (!atomic_read(&tty->port.count)) {
47637 mutex_unlock(&tty->ipw_tty_mutex);
47638 return -EINVAL;
47639 }
47640@@ -246,7 +245,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
47641 if (!tty)
47642 return -ENODEV;
47643
47644- if (!tty->port.count)
47645+ if (!atomic_read(&tty->port.count))
47646 return -EINVAL;
47647
47648 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
47649@@ -288,7 +287,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
47650 if (!tty)
47651 return 0;
47652
47653- if (!tty->port.count)
47654+ if (!atomic_read(&tty->port.count))
47655 return 0;
47656
47657 return tty->tx_bytes_queued;
47658@@ -369,7 +368,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
47659 if (!tty)
47660 return -ENODEV;
47661
47662- if (!tty->port.count)
47663+ if (!atomic_read(&tty->port.count))
47664 return -EINVAL;
47665
47666 return get_control_lines(tty);
47667@@ -385,7 +384,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
47668 if (!tty)
47669 return -ENODEV;
47670
47671- if (!tty->port.count)
47672+ if (!atomic_read(&tty->port.count))
47673 return -EINVAL;
47674
47675 return set_control_lines(tty, set, clear);
47676@@ -399,7 +398,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
47677 if (!tty)
47678 return -ENODEV;
47679
47680- if (!tty->port.count)
47681+ if (!atomic_read(&tty->port.count))
47682 return -EINVAL;
47683
47684 /* FIXME: Exactly how is the tty object locked here .. */
47685@@ -555,7 +554,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
47686 * are gone */
47687 mutex_lock(&ttyj->ipw_tty_mutex);
47688 }
47689- while (ttyj->port.count)
47690+ while (atomic_read(&ttyj->port.count))
47691 do_ipw_close(ttyj);
47692 ipwireless_disassociate_network_ttys(network,
47693 ttyj->channel_idx);
47694diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
47695index 1deaca4..c8582d4 100644
47696--- a/drivers/tty/moxa.c
47697+++ b/drivers/tty/moxa.c
47698@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
47699 }
47700
47701 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
47702- ch->port.count++;
47703+ atomic_inc(&ch->port.count);
47704 tty->driver_data = ch;
47705 tty_port_tty_set(&ch->port, tty);
47706 mutex_lock(&ch->port.mutex);
47707diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
47708index 6422390..49003ac8 100644
47709--- a/drivers/tty/n_gsm.c
47710+++ b/drivers/tty/n_gsm.c
47711@@ -1632,7 +1632,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
47712 spin_lock_init(&dlci->lock);
47713 mutex_init(&dlci->mutex);
47714 dlci->fifo = &dlci->_fifo;
47715- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
47716+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
47717 kfree(dlci);
47718 return NULL;
47719 }
47720@@ -2932,7 +2932,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
47721 struct gsm_dlci *dlci = tty->driver_data;
47722 struct tty_port *port = &dlci->port;
47723
47724- port->count++;
47725+ atomic_inc(&port->count);
47726 dlci_get(dlci);
47727 dlci_get(dlci->gsm->dlci[0]);
47728 mux_get(dlci->gsm);
47729diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
47730index 4bf0fc0..433bd58 100644
47731--- a/drivers/tty/n_tty.c
47732+++ b/drivers/tty/n_tty.c
47733@@ -2217,6 +2217,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
47734 {
47735 *ops = tty_ldisc_N_TTY;
47736 ops->owner = NULL;
47737- ops->refcount = ops->flags = 0;
47738+ atomic_set(&ops->refcount, 0);
47739+ ops->flags = 0;
47740 }
47741 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
47742diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
47743index abfd990..5ab5da9 100644
47744--- a/drivers/tty/pty.c
47745+++ b/drivers/tty/pty.c
47746@@ -796,8 +796,10 @@ static void __init unix98_pty_init(void)
47747 panic("Couldn't register Unix98 pts driver");
47748
47749 /* Now create the /dev/ptmx special device */
47750+ pax_open_kernel();
47751 tty_default_fops(&ptmx_fops);
47752- ptmx_fops.open = ptmx_open;
47753+ *(void **)&ptmx_fops.open = ptmx_open;
47754+ pax_close_kernel();
47755
47756 cdev_init(&ptmx_cdev, &ptmx_fops);
47757 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
47758diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
47759index 354564e..fe50d9a 100644
47760--- a/drivers/tty/rocket.c
47761+++ b/drivers/tty/rocket.c
47762@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
47763 tty->driver_data = info;
47764 tty_port_tty_set(port, tty);
47765
47766- if (port->count++ == 0) {
47767+ if (atomic_inc_return(&port->count) == 1) {
47768 atomic_inc(&rp_num_ports_open);
47769
47770 #ifdef ROCKET_DEBUG_OPEN
47771@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
47772 #endif
47773 }
47774 #ifdef ROCKET_DEBUG_OPEN
47775- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
47776+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
47777 #endif
47778
47779 /*
47780@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
47781 spin_unlock_irqrestore(&info->port.lock, flags);
47782 return;
47783 }
47784- if (info->port.count)
47785+ if (atomic_read(&info->port.count))
47786 atomic_dec(&rp_num_ports_open);
47787 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
47788 spin_unlock_irqrestore(&info->port.lock, flags);
47789diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
47790index e2520ab..034e20b 100644
47791--- a/drivers/tty/serial/ioc4_serial.c
47792+++ b/drivers/tty/serial/ioc4_serial.c
47793@@ -437,7 +437,7 @@ struct ioc4_soft {
47794 } is_intr_info[MAX_IOC4_INTR_ENTS];
47795
47796 /* Number of entries active in the above array */
47797- atomic_t is_num_intrs;
47798+ atomic_unchecked_t is_num_intrs;
47799 } is_intr_type[IOC4_NUM_INTR_TYPES];
47800
47801 /* is_ir_lock must be held while
47802@@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
47803 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
47804 || (type == IOC4_OTHER_INTR_TYPE)));
47805
47806- i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
47807+ i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
47808 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
47809
47810 /* Save off the lower level interrupt handler */
47811@@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
47812
47813 soft = arg;
47814 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
47815- num_intrs = (int)atomic_read(
47816+ num_intrs = (int)atomic_read_unchecked(
47817 &soft->is_intr_type[intr_type].is_num_intrs);
47818
47819 this_mir = this_ir = pending_intrs(soft, intr_type);
47820diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
47821index 1002054..dd644a8 100644
47822--- a/drivers/tty/serial/kgdboc.c
47823+++ b/drivers/tty/serial/kgdboc.c
47824@@ -24,8 +24,9 @@
47825 #define MAX_CONFIG_LEN 40
47826
47827 static struct kgdb_io kgdboc_io_ops;
47828+static struct kgdb_io kgdboc_io_ops_console;
47829
47830-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
47831+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
47832 static int configured = -1;
47833
47834 static char config[MAX_CONFIG_LEN];
47835@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
47836 kgdboc_unregister_kbd();
47837 if (configured == 1)
47838 kgdb_unregister_io_module(&kgdboc_io_ops);
47839+ else if (configured == 2)
47840+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
47841 }
47842
47843 static int configure_kgdboc(void)
47844@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
47845 int err;
47846 char *cptr = config;
47847 struct console *cons;
47848+ int is_console = 0;
47849
47850 err = kgdboc_option_setup(config);
47851 if (err || !strlen(config) || isspace(config[0]))
47852 goto noconfig;
47853
47854 err = -ENODEV;
47855- kgdboc_io_ops.is_console = 0;
47856 kgdb_tty_driver = NULL;
47857
47858 kgdboc_use_kms = 0;
47859@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
47860 int idx;
47861 if (cons->device && cons->device(cons, &idx) == p &&
47862 idx == tty_line) {
47863- kgdboc_io_ops.is_console = 1;
47864+ is_console = 1;
47865 break;
47866 }
47867 cons = cons->next;
47868@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
47869 kgdb_tty_line = tty_line;
47870
47871 do_register:
47872- err = kgdb_register_io_module(&kgdboc_io_ops);
47873+ if (is_console) {
47874+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
47875+ configured = 2;
47876+ } else {
47877+ err = kgdb_register_io_module(&kgdboc_io_ops);
47878+ configured = 1;
47879+ }
47880 if (err)
47881 goto noconfig;
47882
47883@@ -205,8 +214,6 @@ do_register:
47884 if (err)
47885 goto nmi_con_failed;
47886
47887- configured = 1;
47888-
47889 return 0;
47890
47891 nmi_con_failed:
47892@@ -223,7 +230,7 @@ noconfig:
47893 static int __init init_kgdboc(void)
47894 {
47895 /* Already configured? */
47896- if (configured == 1)
47897+ if (configured >= 1)
47898 return 0;
47899
47900 return configure_kgdboc();
47901@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
47902 if (config[len - 1] == '\n')
47903 config[len - 1] = '\0';
47904
47905- if (configured == 1)
47906+ if (configured >= 1)
47907 cleanup_kgdboc();
47908
47909 /* Go and configure with the new params. */
47910@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
47911 .post_exception = kgdboc_post_exp_handler,
47912 };
47913
47914+static struct kgdb_io kgdboc_io_ops_console = {
47915+ .name = "kgdboc",
47916+ .read_char = kgdboc_get_char,
47917+ .write_char = kgdboc_put_char,
47918+ .pre_exception = kgdboc_pre_exp_handler,
47919+ .post_exception = kgdboc_post_exp_handler,
47920+ .is_console = 1
47921+};
47922+
47923 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
47924 /* This is only available if kgdboc is a built in for early debugging */
47925 static int __init kgdboc_early_init(char *opt)
47926diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
47927index 2c6cfb3..048274e 100644
47928--- a/drivers/tty/serial/msm_serial.c
47929+++ b/drivers/tty/serial/msm_serial.c
47930@@ -857,7 +857,7 @@ static struct uart_driver msm_uart_driver = {
47931 .cons = MSM_CONSOLE,
47932 };
47933
47934-static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
47935+static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
47936
47937 static int __init msm_serial_probe(struct platform_device *pdev)
47938 {
47939@@ -867,7 +867,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
47940 int irq;
47941
47942 if (pdev->id == -1)
47943- pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
47944+ pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
47945
47946 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
47947 return -ENXIO;
47948diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
47949index 376079b..d8de7aa 100644
47950--- a/drivers/tty/serial/samsung.c
47951+++ b/drivers/tty/serial/samsung.c
47952@@ -453,11 +453,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
47953 }
47954 }
47955
47956+static int s3c64xx_serial_startup(struct uart_port *port);
47957 static int s3c24xx_serial_startup(struct uart_port *port)
47958 {
47959 struct s3c24xx_uart_port *ourport = to_ourport(port);
47960 int ret;
47961
47962+ /* Startup sequence is different for s3c64xx and higher SoC's */
47963+ if (s3c24xx_serial_has_interrupt_mask(port))
47964+ return s3c64xx_serial_startup(port);
47965+
47966 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
47967 port->mapbase, port->membase);
47968
47969@@ -1124,10 +1129,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
47970 /* setup info for port */
47971 port->dev = &platdev->dev;
47972
47973- /* Startup sequence is different for s3c64xx and higher SoC's */
47974- if (s3c24xx_serial_has_interrupt_mask(port))
47975- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
47976-
47977 port->uartclk = 1;
47978
47979 if (cfg->uart_flags & UPF_CONS_FLOW) {
47980diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
47981index 28cdd28..56f1d60 100644
47982--- a/drivers/tty/serial/serial_core.c
47983+++ b/drivers/tty/serial/serial_core.c
47984@@ -1448,7 +1448,7 @@ static void uart_hangup(struct tty_struct *tty)
47985 uart_flush_buffer(tty);
47986 uart_shutdown(tty, state);
47987 spin_lock_irqsave(&port->lock, flags);
47988- port->count = 0;
47989+ atomic_set(&port->count, 0);
47990 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
47991 spin_unlock_irqrestore(&port->lock, flags);
47992 tty_port_tty_set(port, NULL);
47993@@ -1544,7 +1544,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
47994 goto end;
47995 }
47996
47997- port->count++;
47998+ atomic_inc(&port->count);
47999 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
48000 retval = -ENXIO;
48001 goto err_dec_count;
48002@@ -1572,7 +1572,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
48003 /*
48004 * Make sure the device is in D0 state.
48005 */
48006- if (port->count == 1)
48007+ if (atomic_read(&port->count) == 1)
48008 uart_change_pm(state, UART_PM_STATE_ON);
48009
48010 /*
48011@@ -1590,7 +1590,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
48012 end:
48013 return retval;
48014 err_dec_count:
48015- port->count--;
48016+ atomic_inc(&port->count);
48017 mutex_unlock(&port->mutex);
48018 goto end;
48019 }
48020diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
48021index 8eaf1ab..85c030d 100644
48022--- a/drivers/tty/synclink.c
48023+++ b/drivers/tty/synclink.c
48024@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
48025
48026 if (debug_level >= DEBUG_LEVEL_INFO)
48027 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
48028- __FILE__,__LINE__, info->device_name, info->port.count);
48029+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
48030
48031 if (tty_port_close_start(&info->port, tty, filp) == 0)
48032 goto cleanup;
48033@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
48034 cleanup:
48035 if (debug_level >= DEBUG_LEVEL_INFO)
48036 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
48037- tty->driver->name, info->port.count);
48038+ tty->driver->name, atomic_read(&info->port.count));
48039
48040 } /* end of mgsl_close() */
48041
48042@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
48043
48044 mgsl_flush_buffer(tty);
48045 shutdown(info);
48046-
48047- info->port.count = 0;
48048+
48049+ atomic_set(&info->port.count, 0);
48050 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48051 info->port.tty = NULL;
48052
48053@@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48054
48055 if (debug_level >= DEBUG_LEVEL_INFO)
48056 printk("%s(%d):block_til_ready before block on %s count=%d\n",
48057- __FILE__,__LINE__, tty->driver->name, port->count );
48058+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48059
48060 spin_lock_irqsave(&info->irq_spinlock, flags);
48061 if (!tty_hung_up_p(filp)) {
48062 extra_count = true;
48063- port->count--;
48064+ atomic_dec(&port->count);
48065 }
48066 spin_unlock_irqrestore(&info->irq_spinlock, flags);
48067 port->blocked_open++;
48068@@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48069
48070 if (debug_level >= DEBUG_LEVEL_INFO)
48071 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
48072- __FILE__,__LINE__, tty->driver->name, port->count );
48073+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48074
48075 tty_unlock(tty);
48076 schedule();
48077@@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48078
48079 /* FIXME: Racy on hangup during close wait */
48080 if (extra_count)
48081- port->count++;
48082+ atomic_inc(&port->count);
48083 port->blocked_open--;
48084
48085 if (debug_level >= DEBUG_LEVEL_INFO)
48086 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
48087- __FILE__,__LINE__, tty->driver->name, port->count );
48088+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48089
48090 if (!retval)
48091 port->flags |= ASYNC_NORMAL_ACTIVE;
48092@@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
48093
48094 if (debug_level >= DEBUG_LEVEL_INFO)
48095 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
48096- __FILE__,__LINE__,tty->driver->name, info->port.count);
48097+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
48098
48099 /* If port is closing, signal caller to try again */
48100 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48101@@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
48102 spin_unlock_irqrestore(&info->netlock, flags);
48103 goto cleanup;
48104 }
48105- info->port.count++;
48106+ atomic_inc(&info->port.count);
48107 spin_unlock_irqrestore(&info->netlock, flags);
48108
48109- if (info->port.count == 1) {
48110+ if (atomic_read(&info->port.count) == 1) {
48111 /* 1st open on this device, init hardware */
48112 retval = startup(info);
48113 if (retval < 0)
48114@@ -3446,8 +3446,8 @@ cleanup:
48115 if (retval) {
48116 if (tty->count == 1)
48117 info->port.tty = NULL; /* tty layer will release tty struct */
48118- if(info->port.count)
48119- info->port.count--;
48120+ if (atomic_read(&info->port.count))
48121+ atomic_dec(&info->port.count);
48122 }
48123
48124 return retval;
48125@@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48126 unsigned short new_crctype;
48127
48128 /* return error if TTY interface open */
48129- if (info->port.count)
48130+ if (atomic_read(&info->port.count))
48131 return -EBUSY;
48132
48133 switch (encoding)
48134@@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
48135
48136 /* arbitrate between network and tty opens */
48137 spin_lock_irqsave(&info->netlock, flags);
48138- if (info->port.count != 0 || info->netcount != 0) {
48139+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48140 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
48141 spin_unlock_irqrestore(&info->netlock, flags);
48142 return -EBUSY;
48143@@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48144 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
48145
48146 /* return error if TTY interface open */
48147- if (info->port.count)
48148+ if (atomic_read(&info->port.count))
48149 return -EBUSY;
48150
48151 if (cmd != SIOCWANDEV)
48152diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
48153index 1abf946..1ee34fc 100644
48154--- a/drivers/tty/synclink_gt.c
48155+++ b/drivers/tty/synclink_gt.c
48156@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
48157 tty->driver_data = info;
48158 info->port.tty = tty;
48159
48160- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
48161+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
48162
48163 /* If port is closing, signal caller to try again */
48164 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48165@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
48166 mutex_unlock(&info->port.mutex);
48167 goto cleanup;
48168 }
48169- info->port.count++;
48170+ atomic_inc(&info->port.count);
48171 spin_unlock_irqrestore(&info->netlock, flags);
48172
48173- if (info->port.count == 1) {
48174+ if (atomic_read(&info->port.count) == 1) {
48175 /* 1st open on this device, init hardware */
48176 retval = startup(info);
48177 if (retval < 0) {
48178@@ -715,8 +715,8 @@ cleanup:
48179 if (retval) {
48180 if (tty->count == 1)
48181 info->port.tty = NULL; /* tty layer will release tty struct */
48182- if(info->port.count)
48183- info->port.count--;
48184+ if(atomic_read(&info->port.count))
48185+ atomic_dec(&info->port.count);
48186 }
48187
48188 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
48189@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48190
48191 if (sanity_check(info, tty->name, "close"))
48192 return;
48193- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
48194+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
48195
48196 if (tty_port_close_start(&info->port, tty, filp) == 0)
48197 goto cleanup;
48198@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48199 tty_port_close_end(&info->port, tty);
48200 info->port.tty = NULL;
48201 cleanup:
48202- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
48203+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
48204 }
48205
48206 static void hangup(struct tty_struct *tty)
48207@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
48208 shutdown(info);
48209
48210 spin_lock_irqsave(&info->port.lock, flags);
48211- info->port.count = 0;
48212+ atomic_set(&info->port.count, 0);
48213 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48214 info->port.tty = NULL;
48215 spin_unlock_irqrestore(&info->port.lock, flags);
48216@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48217 unsigned short new_crctype;
48218
48219 /* return error if TTY interface open */
48220- if (info->port.count)
48221+ if (atomic_read(&info->port.count))
48222 return -EBUSY;
48223
48224 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
48225@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
48226
48227 /* arbitrate between network and tty opens */
48228 spin_lock_irqsave(&info->netlock, flags);
48229- if (info->port.count != 0 || info->netcount != 0) {
48230+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48231 DBGINFO(("%s hdlc_open busy\n", dev->name));
48232 spin_unlock_irqrestore(&info->netlock, flags);
48233 return -EBUSY;
48234@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48235 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
48236
48237 /* return error if TTY interface open */
48238- if (info->port.count)
48239+ if (atomic_read(&info->port.count))
48240 return -EBUSY;
48241
48242 if (cmd != SIOCWANDEV)
48243@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
48244 if (port == NULL)
48245 continue;
48246 spin_lock(&port->lock);
48247- if ((port->port.count || port->netcount) &&
48248+ if ((atomic_read(&port->port.count) || port->netcount) &&
48249 port->pending_bh && !port->bh_running &&
48250 !port->bh_requested) {
48251 DBGISR(("%s bh queued\n", port->device_name));
48252@@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48253 spin_lock_irqsave(&info->lock, flags);
48254 if (!tty_hung_up_p(filp)) {
48255 extra_count = true;
48256- port->count--;
48257+ atomic_dec(&port->count);
48258 }
48259 spin_unlock_irqrestore(&info->lock, flags);
48260 port->blocked_open++;
48261@@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48262 remove_wait_queue(&port->open_wait, &wait);
48263
48264 if (extra_count)
48265- port->count++;
48266+ atomic_inc(&port->count);
48267 port->blocked_open--;
48268
48269 if (!retval)
48270diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
48271index dc6e969..5dc8786 100644
48272--- a/drivers/tty/synclinkmp.c
48273+++ b/drivers/tty/synclinkmp.c
48274@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
48275
48276 if (debug_level >= DEBUG_LEVEL_INFO)
48277 printk("%s(%d):%s open(), old ref count = %d\n",
48278- __FILE__,__LINE__,tty->driver->name, info->port.count);
48279+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
48280
48281 /* If port is closing, signal caller to try again */
48282 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48283@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
48284 spin_unlock_irqrestore(&info->netlock, flags);
48285 goto cleanup;
48286 }
48287- info->port.count++;
48288+ atomic_inc(&info->port.count);
48289 spin_unlock_irqrestore(&info->netlock, flags);
48290
48291- if (info->port.count == 1) {
48292+ if (atomic_read(&info->port.count) == 1) {
48293 /* 1st open on this device, init hardware */
48294 retval = startup(info);
48295 if (retval < 0)
48296@@ -796,8 +796,8 @@ cleanup:
48297 if (retval) {
48298 if (tty->count == 1)
48299 info->port.tty = NULL; /* tty layer will release tty struct */
48300- if(info->port.count)
48301- info->port.count--;
48302+ if(atomic_read(&info->port.count))
48303+ atomic_dec(&info->port.count);
48304 }
48305
48306 return retval;
48307@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48308
48309 if (debug_level >= DEBUG_LEVEL_INFO)
48310 printk("%s(%d):%s close() entry, count=%d\n",
48311- __FILE__,__LINE__, info->device_name, info->port.count);
48312+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
48313
48314 if (tty_port_close_start(&info->port, tty, filp) == 0)
48315 goto cleanup;
48316@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48317 cleanup:
48318 if (debug_level >= DEBUG_LEVEL_INFO)
48319 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
48320- tty->driver->name, info->port.count);
48321+ tty->driver->name, atomic_read(&info->port.count));
48322 }
48323
48324 /* Called by tty_hangup() when a hangup is signaled.
48325@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
48326 shutdown(info);
48327
48328 spin_lock_irqsave(&info->port.lock, flags);
48329- info->port.count = 0;
48330+ atomic_set(&info->port.count, 0);
48331 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48332 info->port.tty = NULL;
48333 spin_unlock_irqrestore(&info->port.lock, flags);
48334@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48335 unsigned short new_crctype;
48336
48337 /* return error if TTY interface open */
48338- if (info->port.count)
48339+ if (atomic_read(&info->port.count))
48340 return -EBUSY;
48341
48342 switch (encoding)
48343@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
48344
48345 /* arbitrate between network and tty opens */
48346 spin_lock_irqsave(&info->netlock, flags);
48347- if (info->port.count != 0 || info->netcount != 0) {
48348+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48349 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
48350 spin_unlock_irqrestore(&info->netlock, flags);
48351 return -EBUSY;
48352@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48353 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
48354
48355 /* return error if TTY interface open */
48356- if (info->port.count)
48357+ if (atomic_read(&info->port.count))
48358 return -EBUSY;
48359
48360 if (cmd != SIOCWANDEV)
48361@@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
48362 * do not request bottom half processing if the
48363 * device is not open in a normal mode.
48364 */
48365- if ( port && (port->port.count || port->netcount) &&
48366+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
48367 port->pending_bh && !port->bh_running &&
48368 !port->bh_requested ) {
48369 if ( debug_level >= DEBUG_LEVEL_ISR )
48370@@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48371
48372 if (debug_level >= DEBUG_LEVEL_INFO)
48373 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
48374- __FILE__,__LINE__, tty->driver->name, port->count );
48375+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48376
48377 spin_lock_irqsave(&info->lock, flags);
48378 if (!tty_hung_up_p(filp)) {
48379 extra_count = true;
48380- port->count--;
48381+ atomic_dec(&port->count);
48382 }
48383 spin_unlock_irqrestore(&info->lock, flags);
48384 port->blocked_open++;
48385@@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48386
48387 if (debug_level >= DEBUG_LEVEL_INFO)
48388 printk("%s(%d):%s block_til_ready() count=%d\n",
48389- __FILE__,__LINE__, tty->driver->name, port->count );
48390+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48391
48392 tty_unlock(tty);
48393 schedule();
48394@@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48395 remove_wait_queue(&port->open_wait, &wait);
48396
48397 if (extra_count)
48398- port->count++;
48399+ atomic_inc(&port->count);
48400 port->blocked_open--;
48401
48402 if (debug_level >= DEBUG_LEVEL_INFO)
48403 printk("%s(%d):%s block_til_ready() after, count=%d\n",
48404- __FILE__,__LINE__, tty->driver->name, port->count );
48405+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48406
48407 if (!retval)
48408 port->flags |= ASYNC_NORMAL_ACTIVE;
48409diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
48410index d5cc3ac..3263411 100644
48411--- a/drivers/tty/sysrq.c
48412+++ b/drivers/tty/sysrq.c
48413@@ -1033,7 +1033,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
48414 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
48415 size_t count, loff_t *ppos)
48416 {
48417- if (count) {
48418+ if (count && capable(CAP_SYS_ADMIN)) {
48419 char c;
48420
48421 if (get_user(c, buf))
48422diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
48423index 20689b9..7fd3a31 100644
48424--- a/drivers/tty/tty_io.c
48425+++ b/drivers/tty/tty_io.c
48426@@ -3468,7 +3468,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
48427
48428 void tty_default_fops(struct file_operations *fops)
48429 {
48430- *fops = tty_fops;
48431+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
48432 }
48433
48434 /*
48435diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
48436index 1afe192..73d2c20 100644
48437--- a/drivers/tty/tty_ldisc.c
48438+++ b/drivers/tty/tty_ldisc.c
48439@@ -66,7 +66,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
48440 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
48441 tty_ldiscs[disc] = new_ldisc;
48442 new_ldisc->num = disc;
48443- new_ldisc->refcount = 0;
48444+ atomic_set(&new_ldisc->refcount, 0);
48445 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
48446
48447 return ret;
48448@@ -94,7 +94,7 @@ int tty_unregister_ldisc(int disc)
48449 return -EINVAL;
48450
48451 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
48452- if (tty_ldiscs[disc]->refcount)
48453+ if (atomic_read(&tty_ldiscs[disc]->refcount))
48454 ret = -EBUSY;
48455 else
48456 tty_ldiscs[disc] = NULL;
48457@@ -115,7 +115,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
48458 if (ldops) {
48459 ret = ERR_PTR(-EAGAIN);
48460 if (try_module_get(ldops->owner)) {
48461- ldops->refcount++;
48462+ atomic_inc(&ldops->refcount);
48463 ret = ldops;
48464 }
48465 }
48466@@ -128,7 +128,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
48467 unsigned long flags;
48468
48469 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
48470- ldops->refcount--;
48471+ atomic_dec(&ldops->refcount);
48472 module_put(ldops->owner);
48473 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
48474 }
48475@@ -196,7 +196,7 @@ static inline void tty_ldisc_put(struct tty_ldisc *ld)
48476 /* unreleased reader reference(s) will cause this WARN */
48477 WARN_ON(!atomic_dec_and_test(&ld->users));
48478
48479- ld->ops->refcount--;
48480+ atomic_dec(&ld->ops->refcount);
48481 module_put(ld->ops->owner);
48482 kfree(ld);
48483 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
48484diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
48485index f597e88..b7f68ed 100644
48486--- a/drivers/tty/tty_port.c
48487+++ b/drivers/tty/tty_port.c
48488@@ -232,7 +232,7 @@ void tty_port_hangup(struct tty_port *port)
48489 unsigned long flags;
48490
48491 spin_lock_irqsave(&port->lock, flags);
48492- port->count = 0;
48493+ atomic_set(&port->count, 0);
48494 port->flags &= ~ASYNC_NORMAL_ACTIVE;
48495 tty = port->tty;
48496 if (tty)
48497@@ -390,7 +390,7 @@ int tty_port_block_til_ready(struct tty_port *port,
48498 /* The port lock protects the port counts */
48499 spin_lock_irqsave(&port->lock, flags);
48500 if (!tty_hung_up_p(filp))
48501- port->count--;
48502+ atomic_dec(&port->count);
48503 port->blocked_open++;
48504 spin_unlock_irqrestore(&port->lock, flags);
48505
48506@@ -432,7 +432,7 @@ int tty_port_block_til_ready(struct tty_port *port,
48507 we must not mess that up further */
48508 spin_lock_irqsave(&port->lock, flags);
48509 if (!tty_hung_up_p(filp))
48510- port->count++;
48511+ atomic_inc(&port->count);
48512 port->blocked_open--;
48513 if (retval == 0)
48514 port->flags |= ASYNC_NORMAL_ACTIVE;
48515@@ -466,19 +466,19 @@ int tty_port_close_start(struct tty_port *port,
48516 return 0;
48517 }
48518
48519- if (tty->count == 1 && port->count != 1) {
48520+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
48521 printk(KERN_WARNING
48522 "tty_port_close_start: tty->count = 1 port count = %d.\n",
48523- port->count);
48524- port->count = 1;
48525+ atomic_read(&port->count));
48526+ atomic_set(&port->count, 1);
48527 }
48528- if (--port->count < 0) {
48529+ if (atomic_dec_return(&port->count) < 0) {
48530 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
48531- port->count);
48532- port->count = 0;
48533+ atomic_read(&port->count));
48534+ atomic_set(&port->count, 0);
48535 }
48536
48537- if (port->count) {
48538+ if (atomic_read(&port->count)) {
48539 spin_unlock_irqrestore(&port->lock, flags);
48540 if (port->ops->drop)
48541 port->ops->drop(port);
48542@@ -564,7 +564,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
48543 {
48544 spin_lock_irq(&port->lock);
48545 if (!tty_hung_up_p(filp))
48546- ++port->count;
48547+ atomic_inc(&port->count);
48548 spin_unlock_irq(&port->lock);
48549 tty_port_tty_set(port, tty);
48550
48551diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
48552index a9af1b9a..1e08e7f 100644
48553--- a/drivers/tty/vt/keyboard.c
48554+++ b/drivers/tty/vt/keyboard.c
48555@@ -647,6 +647,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
48556 kbd->kbdmode == VC_OFF) &&
48557 value != KVAL(K_SAK))
48558 return; /* SAK is allowed even in raw mode */
48559+
48560+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48561+ {
48562+ void *func = fn_handler[value];
48563+ if (func == fn_show_state || func == fn_show_ptregs ||
48564+ func == fn_show_mem)
48565+ return;
48566+ }
48567+#endif
48568+
48569 fn_handler[value](vc);
48570 }
48571
48572@@ -1795,9 +1805,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
48573 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
48574 return -EFAULT;
48575
48576- if (!capable(CAP_SYS_TTY_CONFIG))
48577- perm = 0;
48578-
48579 switch (cmd) {
48580 case KDGKBENT:
48581 /* Ensure another thread doesn't free it under us */
48582@@ -1812,6 +1819,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
48583 spin_unlock_irqrestore(&kbd_event_lock, flags);
48584 return put_user(val, &user_kbe->kb_value);
48585 case KDSKBENT:
48586+ if (!capable(CAP_SYS_TTY_CONFIG))
48587+ perm = 0;
48588+
48589 if (!perm)
48590 return -EPERM;
48591 if (!i && v == K_NOSUCHMAP) {
48592@@ -1902,9 +1912,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
48593 int i, j, k;
48594 int ret;
48595
48596- if (!capable(CAP_SYS_TTY_CONFIG))
48597- perm = 0;
48598-
48599 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
48600 if (!kbs) {
48601 ret = -ENOMEM;
48602@@ -1938,6 +1945,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
48603 kfree(kbs);
48604 return ((p && *p) ? -EOVERFLOW : 0);
48605 case KDSKBSENT:
48606+ if (!capable(CAP_SYS_TTY_CONFIG))
48607+ perm = 0;
48608+
48609 if (!perm) {
48610 ret = -EPERM;
48611 goto reterr;
48612diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
48613index 3b96f18..6f6a8f1 100644
48614--- a/drivers/uio/uio.c
48615+++ b/drivers/uio/uio.c
48616@@ -25,6 +25,7 @@
48617 #include <linux/kobject.h>
48618 #include <linux/cdev.h>
48619 #include <linux/uio_driver.h>
48620+#include <asm/local.h>
48621
48622 #define UIO_MAX_DEVICES (1U << MINORBITS)
48623
48624@@ -32,10 +33,10 @@ struct uio_device {
48625 struct module *owner;
48626 struct device *dev;
48627 int minor;
48628- atomic_t event;
48629+ atomic_unchecked_t event;
48630 struct fasync_struct *async_queue;
48631 wait_queue_head_t wait;
48632- int vma_count;
48633+ local_t vma_count;
48634 struct uio_info *info;
48635 struct kobject *map_dir;
48636 struct kobject *portio_dir;
48637@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
48638 struct device_attribute *attr, char *buf)
48639 {
48640 struct uio_device *idev = dev_get_drvdata(dev);
48641- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
48642+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
48643 }
48644
48645 static struct device_attribute uio_class_attributes[] = {
48646@@ -398,7 +399,7 @@ void uio_event_notify(struct uio_info *info)
48647 {
48648 struct uio_device *idev = info->uio_dev;
48649
48650- atomic_inc(&idev->event);
48651+ atomic_inc_unchecked(&idev->event);
48652 wake_up_interruptible(&idev->wait);
48653 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
48654 }
48655@@ -451,7 +452,7 @@ static int uio_open(struct inode *inode, struct file *filep)
48656 }
48657
48658 listener->dev = idev;
48659- listener->event_count = atomic_read(&idev->event);
48660+ listener->event_count = atomic_read_unchecked(&idev->event);
48661 filep->private_data = listener;
48662
48663 if (idev->info->open) {
48664@@ -502,7 +503,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
48665 return -EIO;
48666
48667 poll_wait(filep, &idev->wait, wait);
48668- if (listener->event_count != atomic_read(&idev->event))
48669+ if (listener->event_count != atomic_read_unchecked(&idev->event))
48670 return POLLIN | POLLRDNORM;
48671 return 0;
48672 }
48673@@ -527,7 +528,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
48674 do {
48675 set_current_state(TASK_INTERRUPTIBLE);
48676
48677- event_count = atomic_read(&idev->event);
48678+ event_count = atomic_read_unchecked(&idev->event);
48679 if (event_count != listener->event_count) {
48680 if (copy_to_user(buf, &event_count, count))
48681 retval = -EFAULT;
48682@@ -584,9 +585,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
48683 static int uio_find_mem_index(struct vm_area_struct *vma)
48684 {
48685 struct uio_device *idev = vma->vm_private_data;
48686+ unsigned long size;
48687
48688 if (vma->vm_pgoff < MAX_UIO_MAPS) {
48689- if (idev->info->mem[vma->vm_pgoff].size == 0)
48690+ size = idev->info->mem[vma->vm_pgoff].size;
48691+ if (size == 0)
48692+ return -1;
48693+ if (vma->vm_end - vma->vm_start > size)
48694 return -1;
48695 return (int)vma->vm_pgoff;
48696 }
48697@@ -596,13 +601,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
48698 static void uio_vma_open(struct vm_area_struct *vma)
48699 {
48700 struct uio_device *idev = vma->vm_private_data;
48701- idev->vma_count++;
48702+ local_inc(&idev->vma_count);
48703 }
48704
48705 static void uio_vma_close(struct vm_area_struct *vma)
48706 {
48707 struct uio_device *idev = vma->vm_private_data;
48708- idev->vma_count--;
48709+ local_dec(&idev->vma_count);
48710 }
48711
48712 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
48713@@ -640,14 +645,25 @@ static int uio_mmap_physical(struct vm_area_struct *vma)
48714 {
48715 struct uio_device *idev = vma->vm_private_data;
48716 int mi = uio_find_mem_index(vma);
48717+ struct uio_mem *mem;
48718 if (mi < 0)
48719 return -EINVAL;
48720+ mem = idev->info->mem + mi;
48721
48722 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
48723
48724+ /*
48725+ * We cannot use the vm_iomap_memory() helper here,
48726+ * because vma->vm_pgoff is the map index we looked
48727+ * up above in uio_find_mem_index(), rather than an
48728+ * actual page offset into the mmap.
48729+ *
48730+ * So we just do the physical mmap without a page
48731+ * offset.
48732+ */
48733 return remap_pfn_range(vma,
48734 vma->vm_start,
48735- idev->info->mem[mi].addr >> PAGE_SHIFT,
48736+ mem->addr >> PAGE_SHIFT,
48737 vma->vm_end - vma->vm_start,
48738 vma->vm_page_prot);
48739 }
48740@@ -809,7 +825,7 @@ int __uio_register_device(struct module *owner,
48741 idev->owner = owner;
48742 idev->info = info;
48743 init_waitqueue_head(&idev->wait);
48744- atomic_set(&idev->event, 0);
48745+ atomic_set_unchecked(&idev->event, 0);
48746
48747 ret = uio_get_minor(idev);
48748 if (ret)
48749diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
48750index 8a7eb77..c00402f 100644
48751--- a/drivers/usb/atm/cxacru.c
48752+++ b/drivers/usb/atm/cxacru.c
48753@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
48754 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
48755 if (ret < 2)
48756 return -EINVAL;
48757- if (index < 0 || index > 0x7f)
48758+ if (index > 0x7f)
48759 return -EINVAL;
48760 pos += tmp;
48761
48762diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
48763index 5e0d33a..cc10579 100644
48764--- a/drivers/usb/atm/usbatm.c
48765+++ b/drivers/usb/atm/usbatm.c
48766@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
48767 if (printk_ratelimit())
48768 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
48769 __func__, vpi, vci);
48770- atomic_inc(&vcc->stats->rx_err);
48771+ atomic_inc_unchecked(&vcc->stats->rx_err);
48772 return;
48773 }
48774
48775@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
48776 if (length > ATM_MAX_AAL5_PDU) {
48777 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
48778 __func__, length, vcc);
48779- atomic_inc(&vcc->stats->rx_err);
48780+ atomic_inc_unchecked(&vcc->stats->rx_err);
48781 goto out;
48782 }
48783
48784@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
48785 if (sarb->len < pdu_length) {
48786 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
48787 __func__, pdu_length, sarb->len, vcc);
48788- atomic_inc(&vcc->stats->rx_err);
48789+ atomic_inc_unchecked(&vcc->stats->rx_err);
48790 goto out;
48791 }
48792
48793 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
48794 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
48795 __func__, vcc);
48796- atomic_inc(&vcc->stats->rx_err);
48797+ atomic_inc_unchecked(&vcc->stats->rx_err);
48798 goto out;
48799 }
48800
48801@@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
48802 if (printk_ratelimit())
48803 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
48804 __func__, length);
48805- atomic_inc(&vcc->stats->rx_drop);
48806+ atomic_inc_unchecked(&vcc->stats->rx_drop);
48807 goto out;
48808 }
48809
48810@@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
48811
48812 vcc->push(vcc, skb);
48813
48814- atomic_inc(&vcc->stats->rx);
48815+ atomic_inc_unchecked(&vcc->stats->rx);
48816 out:
48817 skb_trim(sarb, 0);
48818 }
48819@@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
48820 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
48821
48822 usbatm_pop(vcc, skb);
48823- atomic_inc(&vcc->stats->tx);
48824+ atomic_inc_unchecked(&vcc->stats->tx);
48825
48826 skb = skb_dequeue(&instance->sndqueue);
48827 }
48828@@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
48829 if (!left--)
48830 return sprintf(page,
48831 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
48832- atomic_read(&atm_dev->stats.aal5.tx),
48833- atomic_read(&atm_dev->stats.aal5.tx_err),
48834- atomic_read(&atm_dev->stats.aal5.rx),
48835- atomic_read(&atm_dev->stats.aal5.rx_err),
48836- atomic_read(&atm_dev->stats.aal5.rx_drop));
48837+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
48838+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
48839+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
48840+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
48841+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
48842
48843 if (!left--) {
48844 if (instance->disconnected)
48845diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
48846index 2a3bbdf..91d72cf 100644
48847--- a/drivers/usb/core/devices.c
48848+++ b/drivers/usb/core/devices.c
48849@@ -126,7 +126,7 @@ static const char format_endpt[] =
48850 * time it gets called.
48851 */
48852 static struct device_connect_event {
48853- atomic_t count;
48854+ atomic_unchecked_t count;
48855 wait_queue_head_t wait;
48856 } device_event = {
48857 .count = ATOMIC_INIT(1),
48858@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
48859
48860 void usbfs_conn_disc_event(void)
48861 {
48862- atomic_add(2, &device_event.count);
48863+ atomic_add_unchecked(2, &device_event.count);
48864 wake_up(&device_event.wait);
48865 }
48866
48867@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
48868
48869 poll_wait(file, &device_event.wait, wait);
48870
48871- event_count = atomic_read(&device_event.count);
48872+ event_count = atomic_read_unchecked(&device_event.count);
48873 if (file->f_version != event_count) {
48874 file->f_version = event_count;
48875 return POLLIN | POLLRDNORM;
48876diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
48877index 014dc99..4d25fd7 100644
48878--- a/drivers/usb/core/hcd.c
48879+++ b/drivers/usb/core/hcd.c
48880@@ -1551,7 +1551,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
48881 */
48882 usb_get_urb(urb);
48883 atomic_inc(&urb->use_count);
48884- atomic_inc(&urb->dev->urbnum);
48885+ atomic_inc_unchecked(&urb->dev->urbnum);
48886 usbmon_urb_submit(&hcd->self, urb);
48887
48888 /* NOTE requirements on root-hub callers (usbfs and the hub
48889@@ -1578,7 +1578,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
48890 urb->hcpriv = NULL;
48891 INIT_LIST_HEAD(&urb->urb_list);
48892 atomic_dec(&urb->use_count);
48893- atomic_dec(&urb->dev->urbnum);
48894+ atomic_dec_unchecked(&urb->dev->urbnum);
48895 if (atomic_read(&urb->reject))
48896 wake_up(&usb_kill_urb_queue);
48897 usb_put_urb(urb);
48898diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
48899index 17c3785..deffb11 100644
48900--- a/drivers/usb/core/hub.c
48901+++ b/drivers/usb/core/hub.c
48902@@ -27,6 +27,7 @@
48903 #include <linux/freezer.h>
48904 #include <linux/random.h>
48905 #include <linux/pm_qos.h>
48906+#include <linux/grsecurity.h>
48907
48908 #include <asm/uaccess.h>
48909 #include <asm/byteorder.h>
48910@@ -4421,6 +4422,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
48911 goto done;
48912 return;
48913 }
48914+
48915+ if (gr_handle_new_usb())
48916+ goto done;
48917+
48918 if (hub_is_superspeed(hub->hdev))
48919 unit_load = 150;
48920 else
48921diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
48922index e7ee1e4..1dfc9ea4 100644
48923--- a/drivers/usb/core/message.c
48924+++ b/drivers/usb/core/message.c
48925@@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
48926 * method can wait for it to complete. Since you don't have a handle on the
48927 * URB used, you can't cancel the request.
48928 */
48929-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
48930+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
48931 __u8 requesttype, __u16 value, __u16 index, void *data,
48932 __u16 size, int timeout)
48933 {
48934diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
48935index d9284b9..17023c7 100644
48936--- a/drivers/usb/core/sysfs.c
48937+++ b/drivers/usb/core/sysfs.c
48938@@ -239,7 +239,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
48939 struct usb_device *udev;
48940
48941 udev = to_usb_device(dev);
48942- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
48943+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
48944 }
48945 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
48946
48947diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
48948index 7dad603..350f7a9 100644
48949--- a/drivers/usb/core/usb.c
48950+++ b/drivers/usb/core/usb.c
48951@@ -422,7 +422,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
48952 set_dev_node(&dev->dev, dev_to_node(bus->controller));
48953 dev->state = USB_STATE_ATTACHED;
48954 dev->lpm_disable_count = 1;
48955- atomic_set(&dev->urbnum, 0);
48956+ atomic_set_unchecked(&dev->urbnum, 0);
48957
48958 INIT_LIST_HEAD(&dev->ep0.urb_list);
48959 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
48960diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
48961index 14d28d6..5f511ac 100644
48962--- a/drivers/usb/dwc3/gadget.c
48963+++ b/drivers/usb/dwc3/gadget.c
48964@@ -550,8 +550,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
48965 if (!usb_endpoint_xfer_isoc(desc))
48966 return 0;
48967
48968- memset(&trb_link, 0, sizeof(trb_link));
48969-
48970 /* Link TRB for ISOC. The HWO bit is never reset */
48971 trb_st_hw = &dep->trb_pool[0];
48972
48973diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
48974index 5e29dde..eca992f 100644
48975--- a/drivers/usb/early/ehci-dbgp.c
48976+++ b/drivers/usb/early/ehci-dbgp.c
48977@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
48978
48979 #ifdef CONFIG_KGDB
48980 static struct kgdb_io kgdbdbgp_io_ops;
48981-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
48982+static struct kgdb_io kgdbdbgp_io_ops_console;
48983+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
48984 #else
48985 #define dbgp_kgdb_mode (0)
48986 #endif
48987@@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
48988 .write_char = kgdbdbgp_write_char,
48989 };
48990
48991+static struct kgdb_io kgdbdbgp_io_ops_console = {
48992+ .name = "kgdbdbgp",
48993+ .read_char = kgdbdbgp_read_char,
48994+ .write_char = kgdbdbgp_write_char,
48995+ .is_console = 1
48996+};
48997+
48998 static int kgdbdbgp_wait_time;
48999
49000 static int __init kgdbdbgp_parse_config(char *str)
49001@@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
49002 ptr++;
49003 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
49004 }
49005- kgdb_register_io_module(&kgdbdbgp_io_ops);
49006- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
49007+ if (early_dbgp_console.index != -1)
49008+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
49009+ else
49010+ kgdb_register_io_module(&kgdbdbgp_io_ops);
49011
49012 return 0;
49013 }
49014diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
49015index b369292..9f3ba40 100644
49016--- a/drivers/usb/gadget/u_serial.c
49017+++ b/drivers/usb/gadget/u_serial.c
49018@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
49019 spin_lock_irq(&port->port_lock);
49020
49021 /* already open? Great. */
49022- if (port->port.count) {
49023+ if (atomic_read(&port->port.count)) {
49024 status = 0;
49025- port->port.count++;
49026+ atomic_inc(&port->port.count);
49027
49028 /* currently opening/closing? wait ... */
49029 } else if (port->openclose) {
49030@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
49031 tty->driver_data = port;
49032 port->port.tty = tty;
49033
49034- port->port.count = 1;
49035+ atomic_set(&port->port.count, 1);
49036 port->openclose = false;
49037
49038 /* if connected, start the I/O stream */
49039@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
49040
49041 spin_lock_irq(&port->port_lock);
49042
49043- if (port->port.count != 1) {
49044- if (port->port.count == 0)
49045+ if (atomic_read(&port->port.count) != 1) {
49046+ if (atomic_read(&port->port.count) == 0)
49047 WARN_ON(1);
49048 else
49049- --port->port.count;
49050+ atomic_dec(&port->port.count);
49051 goto exit;
49052 }
49053
49054@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
49055 * and sleep if necessary
49056 */
49057 port->openclose = true;
49058- port->port.count = 0;
49059+ atomic_set(&port->port.count, 0);
49060
49061 gser = port->port_usb;
49062 if (gser && gser->disconnect)
49063@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
49064 int cond;
49065
49066 spin_lock_irq(&port->port_lock);
49067- cond = (port->port.count == 0) && !port->openclose;
49068+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
49069 spin_unlock_irq(&port->port_lock);
49070 return cond;
49071 }
49072@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
49073 /* if it's already open, start I/O ... and notify the serial
49074 * protocol about open/close status (connect/disconnect).
49075 */
49076- if (port->port.count) {
49077+ if (atomic_read(&port->port.count)) {
49078 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
49079 gs_start_io(port);
49080 if (gser->connect)
49081@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
49082
49083 port->port_usb = NULL;
49084 gser->ioport = NULL;
49085- if (port->port.count > 0 || port->openclose) {
49086+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
49087 wake_up_interruptible(&port->drain_wait);
49088 if (port->port.tty)
49089 tty_hangup(port->port.tty);
49090@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
49091
49092 /* finally, free any unused/unusable I/O buffers */
49093 spin_lock_irqsave(&port->port_lock, flags);
49094- if (port->port.count == 0 && !port->openclose)
49095+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
49096 gs_buf_free(&port->port_write_buf);
49097 gs_free_requests(gser->out, &port->read_pool, NULL);
49098 gs_free_requests(gser->out, &port->read_queue, NULL);
49099diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
49100index ba6a5d6..f88f7f3 100644
49101--- a/drivers/usb/misc/appledisplay.c
49102+++ b/drivers/usb/misc/appledisplay.c
49103@@ -83,7 +83,7 @@ struct appledisplay {
49104 spinlock_t lock;
49105 };
49106
49107-static atomic_t count_displays = ATOMIC_INIT(0);
49108+static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
49109 static struct workqueue_struct *wq;
49110
49111 static void appledisplay_complete(struct urb *urb)
49112@@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
49113
49114 /* Register backlight device */
49115 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
49116- atomic_inc_return(&count_displays) - 1);
49117+ atomic_inc_return_unchecked(&count_displays) - 1);
49118 memset(&props, 0, sizeof(struct backlight_properties));
49119 props.type = BACKLIGHT_RAW;
49120 props.max_brightness = 0xff;
49121diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
49122index afb50ea..7b0b1cf 100644
49123--- a/drivers/usb/serial/console.c
49124+++ b/drivers/usb/serial/console.c
49125@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
49126
49127 info->port = port;
49128
49129- ++port->port.count;
49130+ atomic_inc(&port->port.count);
49131 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
49132 if (serial->type->set_termios) {
49133 /*
49134@@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
49135 }
49136 /* Now that any required fake tty operations are completed restore
49137 * the tty port count */
49138- --port->port.count;
49139+ atomic_dec(&port->port.count);
49140 /* The console is special in terms of closing the device so
49141 * indicate this port is now acting as a system console. */
49142 port->port.console = 1;
49143@@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
49144 free_tty:
49145 kfree(tty);
49146 reset_open_count:
49147- port->port.count = 0;
49148+ atomic_set(&port->port.count, 0);
49149 usb_autopm_put_interface(serial->interface);
49150 error_get_interface:
49151 usb_serial_put(serial);
49152diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
49153index 75f70f0..d467e1a 100644
49154--- a/drivers/usb/storage/usb.h
49155+++ b/drivers/usb/storage/usb.h
49156@@ -63,7 +63,7 @@ struct us_unusual_dev {
49157 __u8 useProtocol;
49158 __u8 useTransport;
49159 int (*initFunction)(struct us_data *);
49160-};
49161+} __do_const;
49162
49163
49164 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
49165diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
49166index d6bea3e..60b250e 100644
49167--- a/drivers/usb/wusbcore/wa-hc.h
49168+++ b/drivers/usb/wusbcore/wa-hc.h
49169@@ -192,7 +192,7 @@ struct wahc {
49170 struct list_head xfer_delayed_list;
49171 spinlock_t xfer_list_lock;
49172 struct work_struct xfer_work;
49173- atomic_t xfer_id_count;
49174+ atomic_unchecked_t xfer_id_count;
49175 };
49176
49177
49178@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
49179 INIT_LIST_HEAD(&wa->xfer_delayed_list);
49180 spin_lock_init(&wa->xfer_list_lock);
49181 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
49182- atomic_set(&wa->xfer_id_count, 1);
49183+ atomic_set_unchecked(&wa->xfer_id_count, 1);
49184 }
49185
49186 /**
49187diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
49188index d3493ca..0c33b7e 100644
49189--- a/drivers/usb/wusbcore/wa-xfer.c
49190+++ b/drivers/usb/wusbcore/wa-xfer.c
49191@@ -297,7 +297,7 @@ out:
49192 */
49193 static void wa_xfer_id_init(struct wa_xfer *xfer)
49194 {
49195- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
49196+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
49197 }
49198
49199 /*
49200diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
49201index 842f450..d1d7409 100644
49202--- a/drivers/vfio/vfio.c
49203+++ b/drivers/vfio/vfio.c
49204@@ -488,7 +488,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
49205 return 0;
49206
49207 /* TODO Prevent device auto probing */
49208- WARN("Device %s added to live group %d!\n", dev_name(dev),
49209+ WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
49210 iommu_group_id(group->iommu_group));
49211
49212 return 0;
49213diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
49214index 5174eba..86e764a 100644
49215--- a/drivers/vhost/vringh.c
49216+++ b/drivers/vhost/vringh.c
49217@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
49218
49219 static inline int putu16_kern(u16 *p, u16 val)
49220 {
49221- ACCESS_ONCE(*p) = val;
49222+ ACCESS_ONCE_RW(*p) = val;
49223 return 0;
49224 }
49225
49226diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
49227index a4dfe8c..297ddd9 100644
49228--- a/drivers/video/aty/aty128fb.c
49229+++ b/drivers/video/aty/aty128fb.c
49230@@ -149,7 +149,7 @@ enum {
49231 };
49232
49233 /* Must match above enum */
49234-static char * const r128_family[] = {
49235+static const char * const r128_family[] = {
49236 "AGP",
49237 "PCI",
49238 "PRO AGP",
49239diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
49240index 9b0f12c..024673d 100644
49241--- a/drivers/video/aty/atyfb_base.c
49242+++ b/drivers/video/aty/atyfb_base.c
49243@@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
49244 par->accel_flags = var->accel_flags; /* hack */
49245
49246 if (var->accel_flags) {
49247- info->fbops->fb_sync = atyfb_sync;
49248+ pax_open_kernel();
49249+ *(void **)&info->fbops->fb_sync = atyfb_sync;
49250+ pax_close_kernel();
49251 info->flags &= ~FBINFO_HWACCEL_DISABLED;
49252 } else {
49253- info->fbops->fb_sync = NULL;
49254+ pax_open_kernel();
49255+ *(void **)&info->fbops->fb_sync = NULL;
49256+ pax_close_kernel();
49257 info->flags |= FBINFO_HWACCEL_DISABLED;
49258 }
49259
49260diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
49261index 95ec042..e6affdd 100644
49262--- a/drivers/video/aty/mach64_cursor.c
49263+++ b/drivers/video/aty/mach64_cursor.c
49264@@ -7,6 +7,7 @@
49265 #include <linux/string.h>
49266
49267 #include <asm/io.h>
49268+#include <asm/pgtable.h>
49269
49270 #ifdef __sparc__
49271 #include <asm/fbio.h>
49272@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
49273 info->sprite.buf_align = 16; /* and 64 lines tall. */
49274 info->sprite.flags = FB_PIXMAP_IO;
49275
49276- info->fbops->fb_cursor = atyfb_cursor;
49277+ pax_open_kernel();
49278+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
49279+ pax_close_kernel();
49280
49281 return 0;
49282 }
49283diff --git a/drivers/video/au1100fb.c b/drivers/video/au1100fb.c
49284index a54ccdc..22ad8524 100644
49285--- a/drivers/video/au1100fb.c
49286+++ b/drivers/video/au1100fb.c
49287@@ -361,37 +361,13 @@ void au1100fb_fb_rotate(struct fb_info *fbi, int angle)
49288 int au1100fb_fb_mmap(struct fb_info *fbi, struct vm_area_struct *vma)
49289 {
49290 struct au1100fb_device *fbdev;
49291- unsigned int len;
49292- unsigned long start=0, off;
49293
49294 fbdev = to_au1100fb_device(fbi);
49295
49296- if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT)) {
49297- return -EINVAL;
49298- }
49299-
49300- start = fbdev->fb_phys & PAGE_MASK;
49301- len = PAGE_ALIGN((start & ~PAGE_MASK) + fbdev->fb_len);
49302-
49303- off = vma->vm_pgoff << PAGE_SHIFT;
49304-
49305- if ((vma->vm_end - vma->vm_start + off) > len) {
49306- return -EINVAL;
49307- }
49308-
49309- off += start;
49310- vma->vm_pgoff = off >> PAGE_SHIFT;
49311-
49312 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
49313 pgprot_val(vma->vm_page_prot) |= (6 << 9); //CCA=6
49314
49315- if (io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT,
49316- vma->vm_end - vma->vm_start,
49317- vma->vm_page_prot)) {
49318- return -EAGAIN;
49319- }
49320-
49321- return 0;
49322+ return vm_iomap_memory(vma, fbdev->fb_phys, fbdev->fb_len);
49323 }
49324
49325 static struct fb_ops au1100fb_ops =
49326diff --git a/drivers/video/au1200fb.c b/drivers/video/au1200fb.c
49327index 301224e..1d02897 100644
49328--- a/drivers/video/au1200fb.c
49329+++ b/drivers/video/au1200fb.c
49330@@ -1233,34 +1233,13 @@ static int au1200fb_fb_blank(int blank_mode, struct fb_info *fbi)
49331 * method mainly to allow the use of the TLB streaming flag (CCA=6)
49332 */
49333 static int au1200fb_fb_mmap(struct fb_info *info, struct vm_area_struct *vma)
49334-
49335 {
49336- unsigned int len;
49337- unsigned long start=0, off;
49338 struct au1200fb_device *fbdev = info->par;
49339
49340- if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT)) {
49341- return -EINVAL;
49342- }
49343-
49344- start = fbdev->fb_phys & PAGE_MASK;
49345- len = PAGE_ALIGN((start & ~PAGE_MASK) + fbdev->fb_len);
49346-
49347- off = vma->vm_pgoff << PAGE_SHIFT;
49348-
49349- if ((vma->vm_end - vma->vm_start + off) > len) {
49350- return -EINVAL;
49351- }
49352-
49353- off += start;
49354- vma->vm_pgoff = off >> PAGE_SHIFT;
49355-
49356 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
49357 pgprot_val(vma->vm_page_prot) |= _CACHE_MASK; /* CCA=7 */
49358
49359- return io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT,
49360- vma->vm_end - vma->vm_start,
49361- vma->vm_page_prot);
49362+ return vm_iomap_memory(vma, fbdev->fb_phys, fbdev->fb_len);
49363 }
49364
49365 static void set_global(u_int cmd, struct au1200_lcd_global_regs_t *pdata)
49366diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
49367index bca6ccc..252107e 100644
49368--- a/drivers/video/backlight/kb3886_bl.c
49369+++ b/drivers/video/backlight/kb3886_bl.c
49370@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
49371 static unsigned long kb3886bl_flags;
49372 #define KB3886BL_SUSPENDED 0x01
49373
49374-static struct dmi_system_id __initdata kb3886bl_device_table[] = {
49375+static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
49376 {
49377 .ident = "Sahara Touch-iT",
49378 .matches = {
49379diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
49380index 900aa4e..6d49418 100644
49381--- a/drivers/video/fb_defio.c
49382+++ b/drivers/video/fb_defio.c
49383@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
49384
49385 BUG_ON(!fbdefio);
49386 mutex_init(&fbdefio->lock);
49387- info->fbops->fb_mmap = fb_deferred_io_mmap;
49388+ pax_open_kernel();
49389+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
49390+ pax_close_kernel();
49391 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
49392 INIT_LIST_HEAD(&fbdefio->pagelist);
49393 if (fbdefio->delay == 0) /* set a default of 1 s */
49394@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
49395 page->mapping = NULL;
49396 }
49397
49398- info->fbops->fb_mmap = NULL;
49399+ *(void **)&info->fbops->fb_mmap = NULL;
49400 mutex_destroy(&fbdefio->lock);
49401 }
49402 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
49403diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
49404index 5c3960d..15cf8fc 100644
49405--- a/drivers/video/fbcmap.c
49406+++ b/drivers/video/fbcmap.c
49407@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
49408 rc = -ENODEV;
49409 goto out;
49410 }
49411- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
49412- !info->fbops->fb_setcmap)) {
49413+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
49414 rc = -EINVAL;
49415 goto out1;
49416 }
49417diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
49418index 36e1fe2..c744820 100644
49419--- a/drivers/video/fbmem.c
49420+++ b/drivers/video/fbmem.c
49421@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
49422 image->dx += image->width + 8;
49423 }
49424 } else if (rotate == FB_ROTATE_UD) {
49425- for (x = 0; x < num && image->dx >= 0; x++) {
49426+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
49427 info->fbops->fb_imageblit(info, image);
49428 image->dx -= image->width + 8;
49429 }
49430@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
49431 image->dy += image->height + 8;
49432 }
49433 } else if (rotate == FB_ROTATE_CCW) {
49434- for (x = 0; x < num && image->dy >= 0; x++) {
49435+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
49436 info->fbops->fb_imageblit(info, image);
49437 image->dy -= image->height + 8;
49438 }
49439@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
49440 return -EFAULT;
49441 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
49442 return -EINVAL;
49443- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
49444+ if (con2fb.framebuffer >= FB_MAX)
49445 return -EINVAL;
49446 if (!registered_fb[con2fb.framebuffer])
49447 request_module("fb%d", con2fb.framebuffer);
49448diff --git a/drivers/video/hyperv_fb.c b/drivers/video/hyperv_fb.c
49449index d4d2c5f..ebbd113 100644
49450--- a/drivers/video/hyperv_fb.c
49451+++ b/drivers/video/hyperv_fb.c
49452@@ -233,7 +233,7 @@ static uint screen_fb_size;
49453 static inline int synthvid_send(struct hv_device *hdev,
49454 struct synthvid_msg *msg)
49455 {
49456- static atomic64_t request_id = ATOMIC64_INIT(0);
49457+ static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
49458 int ret;
49459
49460 msg->pipe_hdr.type = PIPE_MSG_DATA;
49461@@ -241,7 +241,7 @@ static inline int synthvid_send(struct hv_device *hdev,
49462
49463 ret = vmbus_sendpacket(hdev->channel, msg,
49464 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
49465- atomic64_inc_return(&request_id),
49466+ atomic64_inc_return_unchecked(&request_id),
49467 VM_PKT_DATA_INBAND, 0);
49468
49469 if (ret)
49470diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
49471index 7672d2e..b56437f 100644
49472--- a/drivers/video/i810/i810_accel.c
49473+++ b/drivers/video/i810/i810_accel.c
49474@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
49475 }
49476 }
49477 printk("ringbuffer lockup!!!\n");
49478+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
49479 i810_report_error(mmio);
49480 par->dev_flags |= LOCKUP;
49481 info->pixmap.scan_align = 1;
49482diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
49483index 285d552..eafa544 100644
49484--- a/drivers/video/logo/logo_linux_clut224.ppm
49485+++ b/drivers/video/logo/logo_linux_clut224.ppm
49486@@ -1,883 +1,1123 @@
49487 P3
49488 80 80
49489 255
49490-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49491-0 0 0 0 0 0 0 0 0 0 0 0 11 15 17 33 49 54 59 85 92 73 97 106
49492-83 116 129 105 131 142 115 114 122 74 88 93 20 29 31 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 6 6 6 6 6 6 10 10 10 10 10 10
49495-10 10 10 6 6 6 6 6 6 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
49496-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49497-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49498-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49499-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49500-
49501-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49502-0 0 0 0 0 0 2 3 3 17 23 26 50 67 72 73 97 106 59 85 92 73 97 106
49503-105 131 142 124 127 131 105 131 142 105 131 142 53 75 83 6 8 8 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 6 6 6 10 10 10 14 14 14 22 22 22 26 26 26 30 30 30 34 34 34
49506-30 30 30 30 30 30 26 26 26 18 18 18 14 14 14 10 10 10 6 6 6 0 0 0
49507-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49508-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49509-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49510-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49511-
49512-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0
49513-0 0 0 1 1 1 26 35 39 59 85 92 59 85 92 59 85 92 29 43 47 53 75 83
49514-108 122 132 132 98 104 108 122 132 105 131 142 101 101 101 43 45 48 6 8 8 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-6 6 6 14 14 14 26 26 26 42 42 42 54 54 54 66 66 66 78 78 78 78 78 78
49517-78 78 78 74 74 74 66 66 66 54 54 54 42 42 42 26 26 26 18 18 18 10 10 10
49518-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49519-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49520-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49521-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49522-
49523-0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0
49524-11 15 17 27 40 45 59 85 92 59 85 92 27 40 45 31 45 49 73 97 106 93 121 133
49525-108 122 132 108 122 132 105 131 142 108 122 132 105 131 142 73 97 106 26 35 39 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 10 10 10
49527-22 22 22 42 42 42 66 66 66 86 86 86 66 66 66 38 38 38 38 38 38 22 22 22
49528-26 26 26 34 34 34 54 54 54 66 66 66 86 86 86 70 70 70 46 46 46 26 26 26
49529-14 14 14 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49530-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49531-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49532-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49533-
49534-0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 7 12 13 21 31 35 42 59 64
49535-53 75 83 53 75 83 50 67 72 42 59 64 32 40 45 42 59 64 73 97 106 116 116 116
49536-132 98 104 116 116 116 108 122 132 117 104 110 105 131 142 83 116 129 50 67 72 7 12 13
49537-1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10 26 26 26
49538-50 50 50 82 82 82 58 58 58 6 6 6 2 2 6 2 2 6 2 2 6 2 2 6
49539-2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 54 54 54 86 86 86 66 66 66
49540-38 38 38 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49541-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49542-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49543-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49544-
49545-0 0 0 1 1 1 6 8 8 15 22 25 26 35 39 36 54 60 53 75 83 59 85 92
49546-59 85 92 48 63 69 15 22 25 12 17 20 52 67 79 94 94 94 132 98 104 132 98 104
49547-117 104 110 108 122 132 108 122 132 115 114 122 105 131 142 77 105 114 59 85 92 36 54 60
49548-7 12 13 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22 50 50 50
49549-78 78 78 34 34 34 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49550-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 70 70 70
49551-78 78 78 46 46 46 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
49552-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49553-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49554-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49555-
49556-0 0 0 15 22 25 29 43 47 36 54 60 42 59 64 42 59 64 48 63 69 21 31 35
49557-6 8 8 29 43 47 36 50 56 43 45 48 79 78 84 132 98 104 165 78 79 132 98 104
49558-108 122 132 117 104 110 117 104 110 108 122 132 77 105 114 73 97 106 95 131 149 78 102 129
49559-36 50 56 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18 42 42 42 82 82 82
49560-26 26 26 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49561-2 2 6 2 2 6 2 2 6 14 14 14 46 46 46 34 34 34 6 6 6 2 2 6
49562-42 42 42 78 78 78 42 42 42 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
49563-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49564-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49565-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49566-
49567-27 40 45 53 75 83 48 63 69 24 31 37 6 8 12 0 0 0 18 25 28 26 35 39
49568-12 17 20 26 35 39 65 78 84 112 81 86 152 81 83 137 83 86 132 98 104 117 104 110
49569-117 104 110 132 98 104 132 98 104 115 114 122 73 97 106 53 75 83 95 131 149 93 124 152
49570-68 78 128 15 22 25 0 0 0 0 0 0 10 10 10 30 30 30 66 66 66 58 58 58
49571-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49572-2 2 6 2 2 6 2 2 6 26 26 26 86 86 86 101 101 101 46 46 46 10 10 10
49573-2 2 6 58 58 58 70 70 70 34 34 34 10 10 10 0 0 0 0 0 0 0 0 0
49574-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49575-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49576-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49577-
49578-36 50 56 21 30 33 4 7 7 0 0 0 1 1 1 17 12 12 69 31 31 68 59 64
49579-57 59 63 21 31 35 32 40 45 86 73 69 152 81 83 152 81 83 117 104 110 132 98 104
49580-152 81 83 132 98 104 108 122 132 77 105 114 77 105 114 93 121 133 95 131 149 93 124 152
49581-95 131 149 53 75 83 11 15 17 0 0 0 14 14 14 42 42 42 86 86 86 10 10 10
49582-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49583-2 2 6 2 2 6 2 2 6 30 30 30 94 94 94 94 94 94 58 58 58 26 26 26
49584-2 2 6 6 6 6 78 78 78 54 54 54 22 22 22 6 6 6 0 0 0 0 0 0
49585-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49586-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49587-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49588-
49589-17 23 26 2 3 3 0 0 0 17 12 12 69 31 31 123 55 55 123 55 55 152 81 83
49590-86 73 69 17 23 26 7 12 13 45 54 57 101 101 101 137 83 86 132 98 104 132 98 104
49591-137 83 86 117 104 110 77 105 114 42 59 64 50 67 72 78 102 129 91 117 157 91 117 157
49592-95 131 149 83 116 129 40 48 73 6 6 6 22 22 22 62 62 62 62 62 62 2 2 6
49593-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49594-2 2 6 2 2 6 2 2 6 26 26 26 54 54 54 38 38 38 18 18 18 10 10 10
49595-2 2 6 2 2 6 34 34 34 82 82 82 38 38 38 14 14 14 0 0 0 0 0 0
49596-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49597-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49598-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49599-
49600-1 1 1 1 2 2 2 3 3 28 12 12 123 55 55 174 79 79 174 79 79 174 79 79
49601-152 81 83 68 59 64 26 35 39 27 40 45 79 78 84 137 83 86 165 78 79 137 83 86
49602-94 94 94 48 63 69 36 50 56 50 67 72 73 97 106 93 121 133 93 124 152 93 124 152
49603-95 131 149 91 118 149 78 102 129 27 40 45 30 30 30 78 78 78 30 30 30 2 2 6
49604-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49605-2 2 6 2 2 6 2 2 6 10 10 10 10 10 10 2 2 6 2 2 6 2 2 6
49606-2 2 6 2 2 6 2 2 6 78 78 78 50 50 50 18 18 18 6 6 6 0 0 0
49607-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49608-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49609-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49610-
49611-4 5 3 24 53 24 19 31 15 8 7 3 90 61 47 165 78 79 174 79 79 174 79 79
49612-174 79 79 137 83 86 60 52 57 7 12 13 17 23 26 70 70 70 132 98 104 112 81 86
49613-79 78 84 31 45 49 15 22 25 53 75 83 91 118 149 86 106 160 91 117 157 93 124 152
49614-91 117 157 93 124 152 95 131 149 53 75 83 50 50 50 86 86 86 14 14 14 2 2 6
49615-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49616-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49617-2 2 6 2 2 6 2 2 6 54 54 54 66 66 66 26 26 26 6 6 6 0 0 0
49618-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49619-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49620-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49621-
49622-19 31 15 34 76 34 34 76 34 19 31 15 28 12 12 123 55 55 174 79 79 174 79 79
49623-174 79 79 165 78 79 112 81 86 32 40 45 15 22 25 38 53 58 65 78 84 29 31 32
49624-21 30 33 42 59 64 60 80 103 78 102 129 87 112 149 84 96 162 91 117 157 93 124 152
49625-91 117 157 93 124 152 93 121 133 59 85 92 57 68 71 82 85 86 2 2 6 2 2 6
49626-2 2 6 6 6 6 10 10 10 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49627-2 2 6 2 2 6 2 2 6 6 6 6 14 14 14 10 10 10 2 2 6 2 2 6
49628-2 2 6 2 2 6 2 2 6 18 18 18 82 82 82 34 34 34 10 10 10 0 0 0
49629-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49630-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49631-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49632-
49633-34 76 34 40 89 40 40 89 40 34 76 34 8 15 6 48 26 18 123 55 55 174 79 79
49634-174 79 79 174 79 79 137 83 86 68 59 64 32 40 45 21 30 33 31 45 49 21 31 35
49635-12 17 20 48 63 69 78 102 129 81 88 166 84 96 162 91 117 157 93 124 152 91 117 157
49636-93 124 152 95 131 149 83 116 129 59 85 92 57 68 71 86 86 86 2 2 6 2 2 6
49637-6 6 6 6 6 6 22 22 22 34 34 34 6 6 6 2 2 6 2 2 6 2 2 6
49638-2 2 6 2 2 6 18 18 18 34 34 34 10 10 10 50 50 50 22 22 22 2 2 6
49639-2 2 6 2 2 6 2 2 6 10 10 10 86 86 86 42 42 42 14 14 14 0 0 0
49640-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49641-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49642-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49643-
49644-40 89 40 40 89 40 40 89 40 40 89 40 24 53 24 6 6 6 69 31 31 123 55 55
49645-123 55 55 90 61 47 69 31 31 36 32 33 21 31 35 7 12 13 18 25 28 48 63 69
49646-60 80 103 68 78 128 84 101 153 84 96 162 84 96 162 91 117 157 91 117 157 84 96 162
49647-91 117 157 73 97 106 48 63 69 50 67 72 57 59 63 86 86 86 2 2 6 2 2 6
49648-38 38 38 116 116 116 94 94 94 22 22 22 22 22 22 2 2 6 2 2 6 2 2 6
49649-14 14 14 86 86 86 124 131 137 170 170 170 151 151 151 38 38 38 26 26 26 6 6 6
49650-2 2 6 2 2 6 2 2 6 2 2 6 86 86 86 46 46 46 14 14 14 0 0 0
49651-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49652-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49653-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49654-
49655-34 76 34 40 89 40 40 89 40 40 89 40 34 76 34 19 31 15 17 12 12 48 26 18
49656-48 26 18 8 7 3 10 10 22 23 29 47 51 61 92 42 59 64 21 30 33 34 45 54
49657-68 78 128 81 88 166 81 82 173 86 106 160 86 106 160 84 96 162 86 106 160 87 112 149
49658-91 118 149 77 105 114 52 67 79 32 40 45 50 50 50 86 86 86 2 2 6 14 14 14
49659-124 131 137 198 198 198 195 195 195 116 116 116 10 10 10 2 2 6 2 2 6 6 6 6
49660-101 98 89 187 187 187 210 210 210 218 218 218 214 214 214 124 131 137 14 14 14 6 6 6
49661-2 2 6 2 2 6 2 2 6 2 2 6 86 86 86 50 50 50 18 18 18 6 6 6
49662-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49663-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49664-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49665-
49666-19 31 15 34 76 34 40 89 40 40 89 40 40 89 40 24 53 24 8 7 3 0 0 0
49667-6 8 12 28 32 52 51 61 92 54 54 122 74 77 160 68 78 128 26 35 39 6 8 8
49668-34 45 54 68 78 128 84 96 162 86 106 160 86 106 160 81 88 166 84 96 162 87 112 149
49669-73 97 106 36 50 56 33 49 54 18 18 18 46 46 46 86 86 86 2 2 6 54 54 54
49670-218 218 218 195 195 195 226 226 226 246 246 246 58 58 58 2 2 6 2 2 6 30 30 30
49671-210 210 210 253 253 253 170 170 170 124 127 131 221 221 221 234 234 234 74 74 74 2 2 6
49672-2 2 6 2 2 6 2 2 6 2 2 6 70 70 70 58 58 58 22 22 22 6 6 6
49673-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49674-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49675-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49676-
49677-4 5 3 24 53 24 40 89 40 40 89 40 34 76 34 12 22 15 4 5 3 4 5 3
49678-13 17 26 54 54 122 78 78 174 78 78 174 78 78 174 74 77 160 51 61 92 21 31 35
49679-26 35 39 53 75 83 84 101 153 81 82 173 81 88 166 84 101 153 60 80 103 60 80 103
49680-53 75 83 38 53 58 42 59 64 22 22 22 46 46 46 82 82 82 2 2 6 106 106 106
49681-170 170 170 26 26 26 86 86 86 226 226 226 124 127 131 10 10 10 14 14 14 46 46 46
49682-231 231 231 190 190 190 6 6 6 70 70 70 90 90 90 238 238 238 151 151 151 2 2 6
49683-2 2 6 2 2 6 2 2 6 2 2 6 70 70 70 58 58 58 22 22 22 6 6 6
49684-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49685-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49686-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49687-
49688-1 2 2 8 15 6 24 53 24 34 76 34 19 31 15 8 15 6 63 55 20 63 55 20
49689-18 18 18 40 48 73 74 77 160 78 78 174 78 78 174 81 82 173 74 77 160 52 67 79
49690-17 23 26 21 31 35 60 80 103 81 88 166 74 77 160 78 102 129 36 54 60 12 17 20
49691-42 59 64 48 63 69 21 31 35 18 18 18 42 42 42 86 86 86 6 6 6 116 116 116
49692-106 106 106 6 6 6 70 70 70 151 151 151 124 127 131 18 18 18 38 38 38 54 54 54
49693-221 221 221 106 106 106 2 2 6 14 14 14 46 46 46 190 190 190 198 198 198 2 2 6
49694-2 2 6 2 2 6 2 2 6 2 2 6 74 74 74 62 62 62 22 22 22 6 6 6
49695-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49696-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49697-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49698-
49699-11 15 17 0 0 0 12 22 15 19 31 15 8 15 6 63 55 20 149 139 69 149 139 69
49700-63 55 20 10 10 22 54 54 122 78 78 174 78 78 174 78 78 174 81 82 173 68 78 128
49701-24 31 37 6 6 6 36 50 56 60 80 103 51 61 92 42 59 64 36 50 56 31 45 49
49702-29 43 47 27 40 45 6 8 8 14 14 14 42 42 42 94 94 94 14 14 14 101 101 101
49703-124 127 131 2 2 6 18 18 18 116 116 116 106 107 48 121 92 8 121 92 8 98 70 6
49704-170 170 170 106 106 106 2 2 6 2 2 6 2 2 6 195 195 195 195 195 195 6 6 6
49705-2 2 6 2 2 6 2 2 6 2 2 6 74 74 74 62 62 62 22 22 22 6 6 6
49706-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49707-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49708-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49709-
49710-26 35 39 3 5 6 1 1 1 2 3 3 35 31 12 133 118 54 175 176 80 175 176 80
49711-133 118 54 35 31 12 23 29 47 54 54 122 78 78 174 78 78 174 74 77 160 68 78 128
49712-51 61 92 31 45 49 26 35 39 36 50 56 29 43 47 7 12 13 21 30 33 42 59 64
49713-18 25 28 7 12 13 1 1 1 10 10 10 38 38 38 90 90 90 14 14 14 58 58 58
49714-210 210 210 26 26 26 62 42 6 154 114 10 226 170 11 237 188 10 220 174 15 184 138 11
49715-220 174 15 174 140 55 35 31 12 2 2 6 70 70 70 246 246 246 124 131 137 2 2 6
49716-2 2 6 2 2 6 2 2 6 2 2 6 70 70 70 66 66 66 26 26 26 6 6 6
49717-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49718-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49719-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49720-
49721-27 40 45 17 23 26 2 3 3 1 1 1 56 77 35 165 152 80 175 176 80 175 176 80
49722-175 176 80 106 107 48 22 22 22 28 32 52 54 54 122 54 54 122 51 61 92 28 32 52
49723-20 27 34 31 45 49 11 15 17 7 12 13 36 50 56 31 45 49 29 43 47 36 50 56
49724-6 8 8 0 0 0 0 0 0 10 10 10 38 38 38 86 86 86 14 14 14 10 10 10
49725-195 195 195 198 179 130 192 133 9 220 174 15 239 182 13 237 188 10 232 195 16 239 207 25
49726-237 201 50 241 208 19 232 195 16 184 138 11 198 179 130 208 206 196 42 42 42 2 2 6
49727-2 2 6 2 2 6 2 2 6 2 2 6 50 50 50 74 74 74 30 30 30 6 6 6
49728-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49729-0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49731-
49732-15 22 25 26 35 39 15 22 25 0 0 0 35 31 12 133 118 54 175 176 80 175 176 80
49733-175 176 80 165 152 80 56 77 35 6 8 12 23 29 47 13 17 26 2 2 6 0 0 0
49734-1 2 2 26 35 39 26 35 39 26 35 39 42 59 64 42 59 64 20 29 31 6 8 8
49735-0 0 0 0 0 0 0 0 0 10 10 10 34 34 34 86 86 86 14 14 14 2 2 6
49736-121 92 8 192 133 9 219 162 10 239 182 13 237 188 10 232 195 16 241 208 19 237 201 50
49737-237 201 50 239 207 25 241 208 19 241 208 19 241 208 19 230 187 11 121 92 8 2 2 6
49738-2 2 6 2 2 6 2 2 6 2 2 6 50 50 50 82 82 82 34 34 34 10 10 10
49739-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49740-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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49742-
49743-1 2 2 15 22 25 31 45 49 6 8 12 4 5 3 63 55 20 149 139 69 175 176 80
49744-175 176 80 175 176 80 106 107 48 20 16 6 1 1 1 0 0 0 2 3 3 11 15 17
49745-21 30 33 36 50 56 36 50 56 24 31 37 15 22 25 6 8 8 0 0 0 0 0 0
49746-0 0 0 0 0 0 0 0 0 10 10 10 34 34 34 82 82 82 30 30 30 62 42 6
49747-180 123 7 206 145 10 230 174 11 239 182 13 237 188 10 238 202 15 241 208 19 237 201 50
49748-239 207 25 241 208 19 241 208 19 241 208 19 230 187 11 220 174 15 184 138 11 6 6 6
49749-2 2 6 2 2 6 2 2 6 2 2 6 26 26 26 94 94 94 42 42 42 14 14 14
49750-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49751-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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49753-
49754-0 0 0 1 2 2 29 43 47 26 35 39 3 5 6 8 7 3 106 107 48 165 152 80
49755-175 176 80 149 139 69 63 55 20 4 5 3 2 3 3 12 17 20 26 35 39 26 35 39
49756-17 23 26 7 12 13 6 8 8 3 5 6 1 2 2 0 0 0 0 0 0 0 0 0
49757-0 0 0 0 0 0 0 0 0 10 10 10 30 30 30 78 78 78 50 50 50 104 69 6
49758-192 133 9 216 158 10 236 178 12 237 188 10 232 195 16 241 208 19 237 201 50 237 201 50
49759-241 208 19 241 208 19 241 208 19 204 160 10 200 144 11 216 158 10 156 118 10 2 2 6
49760-2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 90 90 90 54 54 54 18 18 18
49761-6 6 6 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49764-
49765-0 0 0 0 0 0 12 17 20 27 40 45 18 25 28 1 1 1 35 31 12 106 107 48
49766-149 139 69 56 77 35 8 7 3 1 2 2 12 17 20 26 35 39 21 31 35 11 15 17
49767-3 5 6 1 1 1 0 0 0 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 10 10 10 30 30 30 78 78 78 46 46 46 22 22 22
49769-137 92 6 204 160 10 239 182 13 237 188 10 238 202 15 241 208 19 241 208 19 241 208 19
49770-241 208 19 204 160 10 184 138 11 210 150 10 216 158 10 210 150 10 98 70 6 2 2 6
49771-6 6 6 54 54 54 14 14 14 2 2 6 2 2 6 62 62 62 74 74 74 30 30 30
49772-10 10 10 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49775-
49776-0 0 0 0 0 0 1 1 1 15 22 25 33 49 54 12 17 20 2 3 3 35 31 12
49777-56 77 35 20 16 6 1 1 1 18 25 28 21 31 35 11 15 17 1 1 1 0 0 0
49778-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49779-0 0 0 0 0 0 0 0 0 10 10 10 34 34 34 78 78 78 50 50 50 6 6 6
49780-88 55 22 139 102 15 190 146 13 230 187 11 239 207 25 232 195 16 220 174 15 190 146 13
49781-171 120 8 192 133 9 210 150 10 213 154 11 185 146 40 165 152 80 101 98 89 2 2 6
49782-2 2 6 78 78 78 116 116 116 58 58 58 2 2 6 22 22 22 90 90 90 46 46 46
49783-18 18 18 6 6 6 0 0 0 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49786-
49787-0 0 0 0 0 0 0 0 0 1 1 1 27 40 45 29 43 47 3 5 6 2 3 3
49788-8 7 3 1 1 1 17 23 26 31 45 49 15 22 25 0 0 0 0 0 0 0 0 0
49789-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49790-0 0 0 0 0 0 0 0 0 10 10 10 38 38 38 86 86 86 50 50 50 6 6 6
49791-124 127 131 168 158 138 156 107 11 171 120 8 204 160 10 184 138 11 197 138 11 200 144 11
49792-206 145 10 206 145 10 197 138 11 198 179 130 195 195 195 198 198 198 170 170 170 14 14 14
49793-2 2 6 22 22 22 116 116 116 116 116 116 22 22 22 2 2 6 74 74 74 70 70 70
49794-30 30 30 10 10 10 0 0 0 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-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49797-
49798-0 0 0 0 0 0 0 0 0 0 0 0 11 15 17 31 45 49 26 35 39 3 5 6
49799-0 0 0 7 12 13 27 40 45 18 25 28 0 0 0 0 0 0 0 0 0 0 0 0
49800-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49801-0 0 0 0 0 0 6 6 6 18 18 18 50 50 50 101 101 101 26 26 26 10 10 10
49802-124 131 137 190 190 190 168 158 138 156 107 11 197 138 11 200 144 11 197 138 11 192 133 9
49803-180 123 7 185 146 40 198 179 130 187 187 187 202 202 202 221 221 221 214 214 214 66 66 66
49804-2 2 6 2 2 6 50 50 50 62 62 62 6 6 6 2 2 6 10 10 10 90 90 90
49805-50 50 50 18 18 18 6 6 6 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 0 0 0
49807-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49808-
49809-0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 15 22 25 36 54 60 18 25 28
49810-0 0 0 21 30 33 27 40 45 2 3 3 0 0 0 0 0 0 0 0 0 0 0 0
49811-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49812-0 0 0 0 0 0 10 10 10 34 34 34 74 74 74 74 74 74 2 2 6 6 6 6
49813-151 151 151 198 198 198 190 190 190 168 158 138 148 132 55 156 107 11 156 107 11 169 125 40
49814-168 158 138 187 187 187 190 190 190 210 210 210 246 246 246 253 253 253 253 253 253 180 180 180
49815-6 6 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 62 62
49816-74 74 74 34 34 34 14 14 14 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 0 0 0
49818-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49819-
49820-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 27 40 45 35 52 58
49821-18 25 28 35 52 58 17 23 26 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49822-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49823-0 0 0 10 10 10 22 22 22 54 54 54 94 94 94 18 18 18 2 2 6 46 46 46
49824-234 234 234 221 221 221 190 190 190 190 190 190 190 190 190 187 187 187 187 187 187 190 190 190
49825-190 190 190 195 195 195 214 214 214 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
49826-82 82 82 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 14 14 14
49827-86 86 86 54 54 54 22 22 22 6 6 6 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 0 0 0 0 0 0
49829-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49830-
49831-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 12 13 33 49 54
49832-52 72 81 36 54 60 6 8 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49833-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49834-6 6 6 18 18 18 46 46 46 90 90 90 46 46 46 18 18 18 6 6 6 180 180 180
49835-253 253 253 246 246 246 202 202 202 190 190 190 190 190 190 190 190 190 190 190 190 190 190 190
49836-202 202 202 231 231 231 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49837-202 202 202 14 14 14 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49838-42 42 42 86 86 86 42 42 42 18 18 18 6 6 6 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 0 0 0 0 0 0 0 0 0
49840-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49841-
49842-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 12 17 20
49843-36 54 60 29 43 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49844-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
49845-14 14 14 38 38 38 74 74 74 66 66 66 2 2 6 6 6 6 90 90 90 250 250 250
49846-253 253 253 253 253 253 238 238 238 198 198 198 190 190 190 190 190 190 195 195 195 221 221 221
49847-246 246 246 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49848-253 253 253 82 82 82 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49849-2 2 6 78 78 78 70 70 70 34 34 34 14 14 14 6 6 6 0 0 0 0 0 0
49850-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49851-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49852-
49853-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49854-21 30 33 35 52 58 6 8 12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49855-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 14 14
49856-34 34 34 66 66 66 78 78 78 6 6 6 2 2 6 18 18 18 218 218 218 253 253 253
49857-253 253 253 253 253 253 253 253 253 246 246 246 226 226 226 231 231 231 246 246 246 253 253 253
49858-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49859-253 253 253 180 180 180 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49860-2 2 6 18 18 18 90 90 90 62 62 62 30 30 30 10 10 10 0 0 0 0 0 0
49861-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49862-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49863-
49864-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49865-12 17 20 36 54 60 29 43 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49866-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10 26 26 26
49867-58 58 58 90 90 90 18 18 18 2 2 6 2 2 6 106 106 106 253 253 253 253 253 253
49868-253 253 253 253 253 253 253 253 253 253 253 253 250 250 250 253 253 253 253 253 253 253 253 253
49869-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49870-253 253 253 231 231 231 18 18 18 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49871-2 2 6 2 2 6 18 18 18 94 94 94 54 54 54 26 26 26 10 10 10 0 0 0
49872-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49873-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49874-
49875-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49876-0 0 0 21 30 33 35 52 58 6 8 12 0 0 0 0 0 0 0 0 0 0 0 0
49877-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22 50 50 50
49878-90 90 90 26 26 26 2 2 6 2 2 6 14 14 14 195 195 195 250 250 250 253 253 253
49879-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49880-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49881-250 250 250 242 242 242 54 54 54 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49882-2 2 6 2 2 6 2 2 6 38 38 38 86 86 86 50 50 50 22 22 22 6 6 6
49883-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49884-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49885-
49886-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49887-0 0 0 0 0 0 12 17 20 36 54 60 29 43 47 0 0 0 0 0 0 0 0 0
49888-0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 14 14 14 38 38 38 82 82 82
49889-34 34 34 2 2 6 2 2 6 2 2 6 42 42 42 195 195 195 246 246 246 253 253 253
49890-253 253 253 253 253 253 253 253 253 250 250 250 242 242 242 242 242 242 250 250 250 253 253 253
49891-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 250 250 250 246 246 246 238 238 238
49892-226 226 226 231 231 231 101 101 101 6 6 6 2 2 6 2 2 6 2 2 6 2 2 6
49893-2 2 6 2 2 6 2 2 6 2 2 6 38 38 38 82 82 82 42 42 42 14 14 14
49894-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49895-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49896-
49897-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49898-0 0 0 0 0 0 0 0 0 21 30 33 35 52 58 6 8 12 0 0 0 0 0 0
49899-0 0 0 0 0 0 0 0 0 0 0 0 10 10 10 26 26 26 62 62 62 66 66 66
49900-2 2 6 2 2 6 2 2 6 6 6 6 70 70 70 170 170 170 202 202 202 234 234 234
49901-246 246 246 250 250 250 250 250 250 238 238 238 226 226 226 231 231 231 238 238 238 250 250 250
49902-250 250 250 250 250 250 246 246 246 231 231 231 214 214 214 202 202 202 202 202 202 202 202 202
49903-198 198 198 202 202 202 180 180 180 18 18 18 2 2 6 2 2 6 2 2 6 2 2 6
49904-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 62 62 66 66 66 30 30 30
49905-10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49906-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49907-
49908-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49909-0 0 0 0 0 0 0 0 0 12 17 20 36 54 60 29 43 47 0 0 0 0 0 0
49910-0 0 0 0 0 0 0 0 0 0 0 0 14 14 14 42 42 42 82 82 82 18 18 18
49911-2 2 6 2 2 6 2 2 6 10 10 10 94 94 94 180 180 180 218 218 218 242 242 242
49912-250 250 250 253 253 253 253 253 253 250 250 250 234 234 234 253 253 253 253 253 253 253 253 253
49913-253 253 253 253 253 253 253 253 253 246 246 246 238 238 238 226 226 226 210 210 210 202 202 202
49914-195 195 195 195 195 195 210 210 210 151 151 151 6 6 6 14 14 14 50 50 50 14 14 14
49915-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 86 86 86 46 46 46
49916-18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49917-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49918-
49919-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49920-0 0 0 0 0 0 0 0 0 0 0 0 21 30 33 35 52 58 6 8 12 0 0 0
49921-0 0 0 0 0 0 0 0 0 6 6 6 22 22 22 54 54 54 70 70 70 2 2 6
49922-2 2 6 10 10 10 2 2 6 22 22 22 170 170 170 231 231 231 250 250 250 253 253 253
49923-253 253 253 253 253 253 253 253 253 250 250 250 242 242 242 253 253 253 253 253 253 253 253 253
49924-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 246 246 246
49925-231 231 231 202 202 202 198 198 198 226 226 226 94 94 94 2 2 6 6 6 6 38 38 38
49926-30 30 30 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 62 62 66 66 66
49927-26 26 26 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49928-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49929-
49930-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49931-0 0 0 0 0 0 0 0 0 0 0 0 6 8 8 33 49 54 29 43 47 6 8 12
49932-0 0 0 0 0 0 0 0 0 10 10 10 30 30 30 74 74 74 50 50 50 2 2 6
49933-26 26 26 26 26 26 2 2 6 106 106 106 238 238 238 253 253 253 253 253 253 253 253 253
49934-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49935-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49936-253 253 253 246 246 246 218 218 218 202 202 202 210 210 210 14 14 14 2 2 6 2 2 6
49937-30 30 30 22 22 22 2 2 6 2 2 6 2 2 6 2 2 6 18 18 18 86 86 86
49938-42 42 42 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49939-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49940-
49941-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49942-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 12 17 20 33 49 54 17 23 26
49943-0 0 0 0 0 0 0 0 0 14 14 14 42 42 42 90 90 90 22 22 22 2 2 6
49944-42 42 42 2 2 6 18 18 18 218 218 218 253 253 253 253 253 253 253 253 253 253 253 253
49945-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49946-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49947-253 253 253 253 253 253 250 250 250 221 221 221 218 218 218 101 101 101 2 2 6 14 14 14
49948-18 18 18 38 38 38 10 10 10 2 2 6 2 2 6 2 2 6 2 2 6 78 78 78
49949-58 58 58 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49950-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49951-
49952-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49953-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 15 22 25 36 54 60
49954-0 0 0 0 0 0 0 0 0 18 18 18 54 54 54 82 82 82 2 2 6 26 26 26
49955-22 22 22 2 2 6 124 127 131 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49956-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49957-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49958-253 253 253 253 253 253 253 253 253 250 250 250 238 238 238 198 198 198 6 6 6 38 38 38
49959-58 58 58 26 26 26 38 38 38 2 2 6 2 2 6 2 2 6 2 2 6 46 46 46
49960-78 78 78 30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49961-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49962-
49963-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49964-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 21 30 33
49965-36 54 60 0 0 0 0 0 0 30 30 30 74 74 74 58 58 58 2 2 6 42 42 42
49966-2 2 6 22 22 22 231 231 231 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49967-253 253 253 253 253 253 253 253 253 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253
49968-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49969-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 246 246 246 46 46 46 38 38 38
49970-42 42 42 14 14 14 38 38 38 14 14 14 2 2 6 2 2 6 2 2 6 6 6 6
49971-86 86 86 46 46 46 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49972-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49973-
49974-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49975-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49976-36 54 60 0 0 0 0 0 0 42 42 42 90 90 90 18 18 18 18 18 18 26 26 26
49977-2 2 6 116 116 116 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49978-253 253 253 253 253 253 250 250 250 238 238 238 253 253 253 253 253 253 253 253 253 253 253 253
49979-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49980-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 94 94 94 6 6 6
49981-2 2 6 2 2 6 10 10 10 34 34 34 2 2 6 2 2 6 2 2 6 2 2 6
49982-74 74 74 58 58 58 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
49983-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49984-
49985-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49986-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49987-0 0 0 36 54 60 26 26 26 66 66 66 82 82 82 2 2 6 38 38 38 6 6 6
49988-14 14 14 210 210 210 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49989-253 253 253 253 253 253 246 246 246 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
49990-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49991-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 151 151 151 2 2 6
49992-2 2 6 2 2 6 2 2 6 46 46 46 2 2 6 2 2 6 2 2 6 2 2 6
49993-42 42 42 74 74 74 30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0
49994-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49995-
49996-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49997-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49998-6 6 6 36 54 60 21 30 33 90 90 90 26 26 26 6 6 6 42 42 42 2 2 6
49999-74 74 74 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50000-253 253 253 253 253 253 242 242 242 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50001-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50002-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 180 180 180 2 2 6
50003-2 2 6 2 2 6 2 2 6 46 46 46 2 2 6 2 2 6 2 2 6 2 2 6
50004-10 10 10 86 86 86 38 38 38 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0
50005-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50006-
50007-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50008-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50009-10 10 10 26 26 26 36 54 60 82 82 82 2 2 6 22 22 22 18 18 18 2 2 6
50010-151 151 151 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50011-253 253 253 253 253 253 234 234 234 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50012-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50013-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 202 202 202 2 2 6
50014-2 2 6 2 2 6 2 2 6 38 38 38 2 2 6 2 2 6 2 2 6 2 2 6
50015-6 6 6 86 86 86 46 46 46 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0
50016-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50017-
50018-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50019-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50020-18 18 18 46 46 46 86 86 86 36 54 60 2 2 6 34 34 34 10 10 10 6 6 6
50021-210 210 210 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50022-253 253 253 253 253 253 234 234 234 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50023-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50024-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 221 221 221 6 6 6
50025-2 2 6 2 2 6 6 6 6 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6
50026-2 2 6 82 82 82 54 54 54 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
50027-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50028-
50029-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50030-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50031-26 26 26 66 66 66 62 62 62 2 2 6 2 2 6 38 38 38 10 10 10 26 26 26
50032-238 238 238 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50033-253 253 253 253 253 253 231 231 231 238 238 238 253 253 253 253 253 253 253 253 253 253 253 253
50034-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50035-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 231 231 231 6 6 6
50036-2 2 6 2 2 6 10 10 10 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6
50037-2 2 6 66 66 66 58 58 58 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0
50038-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50039-
50040-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50041-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50042-38 38 38 78 78 78 6 6 6 2 2 6 2 2 6 46 46 46 14 14 14 42 42 42
50043-246 246 246 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50044-253 253 253 253 253 253 231 231 231 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50045-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50046-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 234 234 234 10 10 10
50047-2 2 6 2 2 6 22 22 22 14 14 14 2 2 6 2 2 6 2 2 6 2 2 6
50048-2 2 6 66 66 66 62 62 62 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0
50049-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50050-
50051-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50052-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18
50053-50 50 50 74 74 74 2 2 6 2 2 6 14 14 14 70 70 70 34 34 34 62 62 62
50054-250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50055-253 253 253 253 253 253 231 231 231 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253
50056-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50057-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 234 234 234 14 14 14
50058-2 2 6 2 2 6 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50059-2 2 6 66 66 66 62 62 62 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0
50060-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50061-
50062-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50063-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18
50064-54 54 54 62 62 62 2 2 6 2 2 6 2 2 6 30 30 30 46 46 46 70 70 70
50065-250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50066-253 253 253 253 253 253 231 231 231 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253
50067-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50068-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 226 226 226 10 10 10
50069-2 2 6 6 6 6 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50070-2 2 6 66 66 66 58 58 58 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0
50071-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50072-
50073-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50074-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22
50075-58 58 58 62 62 62 2 2 6 2 2 6 2 2 6 2 2 6 30 30 30 78 78 78
50076-250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50077-253 253 253 253 253 253 231 231 231 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253
50078-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50079-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 202 202 202 2 2 6
50080-22 22 22 34 34 34 20 16 6 22 22 22 26 26 26 18 18 18 6 6 6 2 2 6
50081-2 2 6 82 82 82 54 54 54 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
50082-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50083-
50084-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50085-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 26 26 26
50086-62 62 62 106 106 106 63 55 20 184 138 11 204 160 10 121 92 8 6 6 6 62 62 62
50087-238 238 238 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50088-253 253 253 253 253 253 231 231 231 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253
50089-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50090-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 151 151 151 18 18 18
50091-14 14 14 2 2 6 2 2 6 2 2 6 6 6 6 18 18 18 66 66 66 38 38 38
50092-6 6 6 94 94 94 50 50 50 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
50093-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50094-
50095-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50096-0 0 0 0 0 0 0 0 0 6 6 6 10 10 10 10 10 10 18 18 18 38 38 38
50097-78 78 78 138 132 106 216 158 10 242 186 14 246 190 14 246 190 14 156 118 10 10 10 10
50098-90 90 90 238 238 238 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50099-253 253 253 253 253 253 231 231 231 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253
50100-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50101-253 253 253 253 253 253 253 253 253 246 230 190 214 187 87 214 187 87 185 146 40 35 31 12
50102-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 38 38 38 46 46 46
50103-26 26 26 106 106 106 54 54 54 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
50104-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50105-
50106-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50107-0 0 0 6 6 6 14 14 14 22 22 22 30 30 30 38 38 38 50 50 50 70 70 70
50108-106 106 106 185 146 40 226 170 11 242 186 14 246 190 14 246 190 14 246 190 14 154 114 10
50109-6 6 6 74 74 74 226 226 226 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50110-253 253 253 253 253 253 231 231 231 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253
50111-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50112-253 253 253 253 253 253 253 253 253 237 201 50 241 196 14 241 208 19 232 195 16 35 31 12
50113-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 30 30 30 26 26 26
50114-204 160 10 165 152 80 66 66 66 26 26 26 6 6 6 0 0 0 0 0 0 0 0 0
50115-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50116-
50117-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50118-6 6 6 18 18 18 38 38 38 58 58 58 78 78 78 86 86 86 101 101 101 124 127 131
50119-174 140 55 210 150 10 234 174 13 246 186 14 246 190 14 246 190 14 246 190 14 237 188 10
50120-98 70 6 2 2 6 46 46 46 198 198 198 253 253 253 253 253 253 253 253 253 253 253 253
50121-253 253 253 253 253 253 234 234 234 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50122-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50123-253 253 253 253 253 253 253 253 253 214 187 87 242 186 14 241 196 14 204 160 10 20 16 6
50124-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 121 92 8
50125-238 202 15 232 195 16 82 82 82 34 34 34 10 10 10 0 0 0 0 0 0 0 0 0
50126-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50127-
50128-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50129-14 14 14 38 38 38 70 70 70 148 132 55 185 146 40 200 144 11 197 138 11 197 138 11
50130-213 154 11 226 170 11 242 186 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50131-220 174 15 35 31 12 2 2 6 22 22 22 151 151 151 250 250 250 253 253 253 253 253 253
50132-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50133-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50134-253 253 253 250 250 250 242 242 242 214 187 87 239 182 13 237 188 10 213 154 11 35 31 12
50135-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 42 6 220 174 15
50136-237 188 10 237 188 10 113 101 86 42 42 42 14 14 14 0 0 0 0 0 0 0 0 0
50137-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50138-
50139-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50140-22 22 22 54 54 54 148 132 55 213 154 11 226 170 11 230 174 11 226 170 11 226 170 11
50141-236 178 12 242 186 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50142-241 196 14 184 138 11 10 10 10 2 2 6 6 6 6 116 116 116 242 242 242 253 253 253
50143-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50144-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50145-253 253 253 231 231 231 198 198 198 213 164 39 236 178 12 236 178 12 210 150 10 137 92 6
50146-20 16 6 2 2 6 2 2 6 2 2 6 6 6 6 62 42 6 200 144 11 236 178 12
50147-239 182 13 239 182 13 124 112 88 58 58 58 22 22 22 6 6 6 0 0 0 0 0 0
50148-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50149-
50150-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50151-30 30 30 70 70 70 169 125 40 226 170 11 239 182 13 242 186 14 242 186 14 246 186 14
50152-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50153-246 190 14 232 195 16 98 70 6 2 2 6 2 2 6 2 2 6 66 66 66 221 221 221
50154-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50155-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50156-253 253 253 202 202 202 198 198 198 213 164 39 230 174 11 230 174 11 216 158 10 192 133 9
50157-163 110 8 120 80 7 98 70 6 120 80 7 167 114 7 197 138 11 226 170 11 239 182 13
50158-242 186 14 242 186 14 165 152 80 78 78 78 34 34 34 14 14 14 6 6 6 0 0 0
50159-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50160-
50161-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50162-30 30 30 78 78 78 185 146 40 226 170 11 239 182 13 246 190 14 246 190 14 246 190 14
50163-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50164-246 190 14 241 196 14 204 160 10 20 16 6 2 2 6 2 2 6 2 2 6 38 38 38
50165-218 218 218 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50166-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50167-250 250 250 202 202 202 198 198 198 213 164 39 226 170 11 236 178 12 224 166 10 210 150 10
50168-200 144 11 197 138 11 192 133 9 197 138 11 210 150 10 226 170 11 242 186 14 246 190 14
50169-246 190 14 246 186 14 220 174 15 124 112 88 62 62 62 30 30 30 14 14 14 6 6 6
50170-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50171-
50172-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50173-30 30 30 78 78 78 174 140 55 224 166 10 239 182 13 246 190 14 246 190 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 241 196 14 139 102 15 2 2 6 2 2 6 2 2 6 2 2 6
50176-78 78 78 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50177-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50178-250 250 250 214 214 214 198 198 198 185 146 40 219 162 10 236 178 12 234 174 13 224 166 10
50179-216 158 10 213 154 11 213 154 11 216 158 10 226 170 11 239 182 13 246 190 14 246 190 14
50180-246 190 14 246 190 14 242 186 14 213 164 39 101 101 101 58 58 58 30 30 30 14 14 14
50181-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50182-
50183-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50184-30 30 30 74 74 74 174 140 55 216 158 10 236 178 12 246 190 14 246 190 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 241 196 14 230 187 11 62 42 6 2 2 6 2 2 6 2 2 6
50187-22 22 22 238 238 238 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50188-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50189-253 253 253 226 226 226 187 187 187 169 125 40 216 158 10 236 178 12 239 182 13 236 178 12
50190-230 174 11 226 170 11 226 170 11 230 174 11 236 178 12 242 186 14 246 190 14 246 190 14
50191-246 190 14 246 190 14 246 186 14 239 182 13 213 164 39 106 106 106 66 66 66 34 34 34
50192-14 14 14 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50193-
50194-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50195-26 26 26 70 70 70 149 139 69 213 154 11 236 178 12 246 190 14 246 190 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 241 196 14 190 146 13 20 16 6 2 2 6 2 2 6
50198-46 46 46 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50199-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50200-253 253 253 221 221 221 86 86 86 156 107 11 216 158 10 236 178 12 242 186 14 246 186 14
50201-242 186 14 239 182 13 239 182 13 242 186 14 242 186 14 246 186 14 246 190 14 246 190 14
50202-246 190 14 246 190 14 246 190 14 246 190 14 242 186 14 220 174 15 149 139 69 66 66 66
50203-30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50204-
50205-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50206-26 26 26 70 70 70 149 139 69 210 150 10 236 178 12 246 190 14 246 190 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 246 190 14 232 195 16 121 92 8 34 34 34 106 106 106
50209-221 221 221 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50210-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50211-242 242 242 82 82 82 20 16 6 163 110 8 216 158 10 236 178 12 242 186 14 246 190 14
50212-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 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 242 186 14 149 139 69
50214-46 46 46 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50215-
50216-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50217-30 30 30 78 78 78 149 139 69 210 150 10 236 178 12 246 186 14 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 246 190 14 246 190 14 246 190 14 241 196 14 220 174 15 198 179 130 253 253 253
50220-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50221-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 218 218 218
50222-58 58 58 2 2 6 20 16 6 167 114 7 216 158 10 236 178 12 246 186 14 246 190 14
50223-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50224-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 186 14 242 186 14 185 146 40
50225-54 54 54 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50226-
50227-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 14 14
50228-38 38 38 86 86 86 169 125 40 213 154 11 236 178 12 246 186 14 246 190 14 246 190 14
50229-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50230-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 232 195 16 190 146 13 214 214 214
50231-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50232-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 250 250 250 170 170 170 26 26 26
50233-2 2 6 2 2 6 35 31 12 163 110 8 219 162 10 239 182 13 246 186 14 246 190 14
50234-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50235-246 190 14 246 190 14 246 190 14 246 190 14 246 186 14 236 178 12 224 166 10 149 139 69
50236-46 46 46 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50237-
50238-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18
50239-50 50 50 113 101 86 192 133 9 224 166 10 242 186 14 246 190 14 246 190 14 246 190 14
50240-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50241-246 190 14 246 190 14 246 190 14 246 190 14 242 186 14 230 187 11 204 160 10 133 118 54
50242-226 226 226 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50243-253 253 253 253 253 253 253 253 253 253 253 253 198 198 198 66 66 66 2 2 6 2 2 6
50244-2 2 6 2 2 6 62 42 6 156 107 11 219 162 10 239 182 13 246 186 14 246 190 14
50245-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50246-246 190 14 246 190 14 246 190 14 242 186 14 234 174 13 213 154 11 148 132 55 66 66 66
50247-30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50248-
50249-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22
50250-58 58 58 148 132 55 206 145 10 234 174 13 242 186 14 246 186 14 246 190 14 246 190 14
50251-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50252-246 190 14 246 190 14 246 190 14 246 190 14 246 186 14 236 178 12 204 160 10 163 110 8
50253-62 42 6 124 131 137 218 218 218 250 250 250 253 253 253 253 253 253 253 253 253 250 250 250
50254-242 242 242 210 210 210 151 151 151 66 66 66 6 6 6 2 2 6 2 2 6 2 2 6
50255-2 2 6 2 2 6 62 42 6 163 110 8 216 158 10 236 178 12 246 190 14 246 190 14
50256-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50257-246 190 14 239 182 13 230 174 11 216 158 10 185 146 40 124 112 88 70 70 70 38 38 38
50258-18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50259-
50260-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22
50261-62 62 62 169 125 40 206 145 10 224 166 10 236 178 12 239 182 13 242 186 14 242 186 14
50262-246 186 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50263-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 236 178 12 216 158 10 171 120 8
50264-85 57 6 2 2 6 6 6 6 30 30 30 54 54 54 62 62 62 50 50 50 38 38 38
50265-14 14 14 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50266-2 2 6 6 6 6 85 57 6 167 114 7 213 154 11 236 178 12 246 190 14 246 190 14
50267-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 242 186 14 239 182 13 239 182 13
50268-230 174 11 210 150 10 174 140 55 124 112 88 82 82 82 54 54 54 34 34 34 18 18 18
50269-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50270-
50271-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18
50272-50 50 50 169 125 40 192 133 9 200 144 11 216 158 10 219 162 10 224 166 10 226 170 11
50273-230 174 11 236 178 12 239 182 13 239 182 13 242 186 14 246 186 14 246 190 14 246 190 14
50274-246 190 14 246 190 14 246 190 14 246 190 14 246 186 14 230 174 11 210 150 10 163 110 8
50275-104 69 6 10 10 10 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50276-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50277-2 2 6 6 6 6 85 57 6 167 114 7 206 145 10 230 174 11 242 186 14 246 190 14
50278-246 190 14 246 190 14 246 186 14 242 186 14 239 182 13 230 174 11 224 166 10 213 154 11
50279-169 125 40 124 112 88 86 86 86 58 58 58 38 38 38 22 22 22 10 10 10 6 6 6
50280-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50281-
50282-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 14 14
50283-34 34 34 70 70 70 133 118 54 169 125 40 167 114 7 180 123 7 192 133 9 197 138 11
50284-200 144 11 206 145 10 213 154 11 219 162 10 224 166 10 230 174 11 239 182 13 242 186 14
50285-246 186 14 246 186 14 246 186 14 246 186 14 239 182 13 216 158 10 184 138 11 152 99 6
50286-104 69 6 20 16 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50287-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50288-2 2 6 6 6 6 85 57 6 152 99 6 192 133 9 219 162 10 236 178 12 239 182 13
50289-246 186 14 242 186 14 239 182 13 236 178 12 224 166 10 206 145 10 192 133 9 148 132 55
50290-94 94 94 62 62 62 42 42 42 22 22 22 14 14 14 6 6 6 0 0 0 0 0 0
50291-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50292-
50293-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50294-18 18 18 34 34 34 58 58 58 78 78 78 101 98 89 124 112 88 133 118 54 156 107 11
50295-163 110 8 167 114 7 171 120 8 180 123 7 184 138 11 197 138 11 210 150 10 219 162 10
50296-226 170 11 236 178 12 236 178 12 234 174 13 219 162 10 197 138 11 163 110 8 134 84 6
50297-85 57 6 10 10 10 2 2 6 2 2 6 18 18 18 38 38 38 38 38 38 38 38 38
50298-38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 26 26 26 2 2 6
50299-2 2 6 6 6 6 62 42 6 137 92 6 171 120 8 200 144 11 219 162 10 230 174 11
50300-234 174 13 230 174 11 219 162 10 210 150 10 192 133 9 163 110 8 124 112 88 82 82 82
50301-50 50 50 30 30 30 14 14 14 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
50302-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50303-
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 14 14 14 22 22 22 34 34 34 42 42 42 58 58 58 74 74 74 86 86 86
50306-101 98 89 113 101 86 133 118 54 121 92 8 137 92 6 152 99 6 163 110 8 180 123 7
50307-184 138 11 197 138 11 206 145 10 200 144 11 180 123 7 156 107 11 134 84 6 104 69 6
50308-62 42 6 54 54 54 106 106 106 101 98 89 86 86 86 82 82 82 78 78 78 78 78 78
50309-78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 82 82 82 86 86 86 94 94 94
50310-106 106 106 101 101 101 90 61 47 120 80 7 156 107 11 180 123 7 192 133 9 200 144 11
50311-206 145 10 200 144 11 192 133 9 171 120 8 139 102 15 113 101 86 70 70 70 42 42 42
50312-22 22 22 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50313-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50314-
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 0 0 0 6 6 6 10 10 10 14 14 14 22 22 22 30 30 30 38 38 38
50317-50 50 50 62 62 62 74 74 74 90 90 90 101 98 89 113 101 86 121 92 8 120 80 7
50318-137 92 6 152 99 6 152 99 6 152 99 6 134 84 6 120 80 7 98 70 6 88 55 22
50319-101 98 89 82 82 82 58 58 58 46 46 46 38 38 38 34 34 34 34 34 34 34 34 34
50320-34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 38 38 38 42 42 42
50321-54 54 54 82 82 82 94 86 71 85 57 6 134 84 6 156 107 11 167 114 7 171 120 8
50322-171 120 8 167 114 7 152 99 6 121 92 8 101 98 89 62 62 62 34 34 34 18 18 18
50323-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50324-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50325-
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 0 0 0 0 0 0 6 6 6 6 6 6 10 10 10
50328-18 18 18 22 22 22 30 30 30 42 42 42 50 50 50 66 66 66 86 86 86 101 98 89
50329-94 86 71 98 70 6 104 69 6 104 69 6 104 69 6 85 57 6 88 55 22 90 90 90
50330-62 62 62 38 38 38 22 22 22 14 14 14 10 10 10 10 10 10 10 10 10 10 10 10
50331-10 10 10 10 10 10 6 6 6 10 10 10 10 10 10 10 10 10 10 10 10 14 14 14
50332-22 22 22 42 42 42 70 70 70 94 86 71 85 57 6 104 69 6 120 80 7 137 92 6
50333-134 84 6 120 80 7 94 86 71 86 86 86 58 58 58 30 30 30 14 14 14 6 6 6
50334-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50335-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50336-
50337-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50338-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50339-0 0 0 6 6 6 10 10 10 14 14 14 18 18 18 26 26 26 38 38 38 54 54 54
50340-70 70 70 86 86 86 94 86 71 94 86 71 94 86 71 86 86 86 74 74 74 50 50 50
50341-30 30 30 14 14 14 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50342-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50343-6 6 6 18 18 18 34 34 34 58 58 58 82 82 82 94 86 71 94 86 71 94 86 71
50344-94 86 71 94 86 71 74 74 74 50 50 50 26 26 26 14 14 14 6 6 6 0 0 0
50345-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50346-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50347-
50348-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50349-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50350-0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 6 6 6 14 14 14 18 18 18
50351-30 30 30 38 38 38 46 46 46 54 54 54 50 50 50 42 42 42 30 30 30 18 18 18
50352-10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50353-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50354-0 0 0 6 6 6 14 14 14 26 26 26 38 38 38 50 50 50 58 58 58 58 58 58
50355-54 54 54 42 42 42 30 30 30 18 18 18 10 10 10 0 0 0 0 0 0 0 0 0
50356-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50357-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50358-
50359-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50360-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50361-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50362-6 6 6 10 10 10 14 14 14 18 18 18 18 18 18 14 14 14 10 10 10 6 6 6
50363-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50364-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50365-0 0 0 0 0 0 0 0 0 6 6 6 14 14 14 18 18 18 22 22 22 22 22 22
50366-18 18 18 14 14 14 10 10 10 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
50367-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50368-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50369-
50370+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50371+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50372+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50373+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50374+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50375+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50376+4 4 4 4 4 4 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
50384+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50385+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50386+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50387+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50388+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50389+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50390+4 4 4 4 4 4 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
50398+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50399+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50400+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50401+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50402+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50403+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50404+4 4 4 4 4 4 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
50412+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50413+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50414+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50415+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50416+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50417+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50418+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50419+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50420+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50421+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50422+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50423+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50424+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50425+4 4 4 4 4 4
50426+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50427+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50428+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50429+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50430+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50431+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50432+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50433+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50434+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50435+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50436+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50437+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50438+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50439+4 4 4 4 4 4
50440+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50441+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50442+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50443+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50444+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50445+4 4 4 4 4 4 4 4 4 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+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50449+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50450+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50451+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
50454+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50455+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50456+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50457+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50458+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
50459+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4
50462+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50463+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
50464+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
50465+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
50466+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50467+4 4 4 4 4 4
50468+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50469+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50470+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50471+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50472+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
50473+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
50474+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50475+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50476+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50477+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
50478+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
50479+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
50480+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50481+4 4 4 4 4 4
50482+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50483+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50484+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50485+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50486+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
50487+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
50488+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
50489+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50490+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50491+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
50492+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
50493+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
50494+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
50495+4 4 4 4 4 4
50496+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50497+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50498+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50499+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
50500+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
50501+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
50502+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
50503+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50504+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
50505+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
50506+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
50507+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
50508+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
50509+4 4 4 4 4 4
50510+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50511+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50512+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50513+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
50514+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
50515+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
50516+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
50517+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
50518+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
50519+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
50520+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
50521+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
50522+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
50523+4 4 4 4 4 4
50524+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50525+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50526+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
50527+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
50528+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
50529+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
50530+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
50531+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
50532+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
50533+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
50534+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
50535+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
50536+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
50537+4 4 4 4 4 4
50538+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50539+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50540+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
50541+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
50542+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
50543+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
50544+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
50545+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
50546+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
50547+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
50548+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
50549+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
50550+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
50551+4 4 4 4 4 4
50552+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50553+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50554+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
50555+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
50556+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
50557+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
50558+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
50559+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
50560+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
50561+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
50562+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
50563+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
50564+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
50565+4 4 4 4 4 4
50566+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50567+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50568+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
50569+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
50570+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
50571+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
50572+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
50573+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
50574+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
50575+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
50576+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
50577+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
50578+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
50579+4 4 4 4 4 4
50580+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50581+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50582+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
50583+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
50584+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
50585+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
50586+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
50587+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
50588+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
50589+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
50590+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
50591+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
50592+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
50593+4 4 4 4 4 4
50594+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50595+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
50596+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
50597+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
50598+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
50599+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
50600+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
50601+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
50602+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
50603+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
50604+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
50605+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
50606+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
50607+4 4 4 4 4 4
50608+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50609+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
50610+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
50611+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
50612+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
50613+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
50614+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
50615+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
50616+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
50617+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
50618+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
50619+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
50620+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
50621+0 0 0 4 4 4
50622+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
50623+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
50624+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
50625+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
50626+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
50627+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
50628+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
50629+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
50630+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
50631+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
50632+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
50633+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
50634+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
50635+2 0 0 0 0 0
50636+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
50637+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
50638+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
50639+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
50640+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
50641+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
50642+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
50643+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
50644+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
50645+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
50646+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
50647+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
50648+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
50649+37 38 37 0 0 0
50650+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
50651+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
50652+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
50653+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
50654+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
50655+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
50656+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
50657+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
50658+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
50659+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
50660+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
50661+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
50662+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
50663+85 115 134 4 0 0
50664+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
50665+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
50666+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
50667+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
50668+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
50669+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
50670+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
50671+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
50672+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
50673+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
50674+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
50675+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
50676+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
50677+60 73 81 4 0 0
50678+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
50679+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
50680+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
50681+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
50682+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
50683+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
50684+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
50685+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
50686+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
50687+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
50688+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
50689+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
50690+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
50691+16 19 21 4 0 0
50692+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
50693+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
50694+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
50695+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
50696+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
50697+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
50698+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
50699+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
50700+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
50701+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
50702+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
50703+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
50704+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
50705+4 0 0 4 3 3
50706+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
50707+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
50708+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
50709+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
50710+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
50711+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
50712+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
50713+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
50714+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
50715+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
50716+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
50717+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
50718+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
50719+3 2 2 4 4 4
50720+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
50721+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
50722+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
50723+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
50724+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
50725+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
50726+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50727+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
50728+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
50729+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
50730+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
50731+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
50732+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
50733+4 4 4 4 4 4
50734+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
50735+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
50736+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
50737+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
50738+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
50739+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
50740+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
50741+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
50742+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
50743+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
50744+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
50745+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
50746+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
50747+4 4 4 4 4 4
50748+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
50749+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
50750+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
50751+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
50752+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
50753+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
50754+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
50755+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
50756+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
50757+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
50758+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
50759+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
50760+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
50761+5 5 5 5 5 5
50762+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
50763+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
50764+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
50765+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
50766+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
50767+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
50768+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
50769+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
50770+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
50771+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
50772+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
50773+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
50774+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
50775+5 5 5 4 4 4
50776+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
50777+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
50778+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
50779+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
50780+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
50781+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
50782+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
50783+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
50784+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
50785+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
50786+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
50787+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
50788+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50789+4 4 4 4 4 4
50790+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
50791+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
50792+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
50793+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
50794+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
50795+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
50796+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
50797+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
50798+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
50799+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
50800+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
50801+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
50802+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50803+4 4 4 4 4 4
50804+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
50805+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
50806+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
50807+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
50808+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
50809+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
50810+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
50811+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
50812+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
50813+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
50814+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
50815+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50816+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50817+4 4 4 4 4 4
50818+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
50819+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
50820+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
50821+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
50822+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
50823+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
50824+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
50825+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
50826+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
50827+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
50828+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
50829+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50830+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50831+4 4 4 4 4 4
50832+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
50833+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
50834+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
50835+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
50836+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
50837+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
50838+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
50839+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
50840+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
50841+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
50842+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50843+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50844+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50845+4 4 4 4 4 4
50846+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
50847+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
50848+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
50849+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
50850+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
50851+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
50852+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
50853+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
50854+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
50855+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
50856+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
50857+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50858+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50859+4 4 4 4 4 4
50860+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
50861+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
50862+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
50863+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
50864+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
50865+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
50866+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
50867+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
50868+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
50869+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
50870+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
50871+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50872+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50873+4 4 4 4 4 4
50874+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
50875+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
50876+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
50877+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
50878+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
50879+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
50880+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
50881+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
50882+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
50883+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
50884+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50885+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50886+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50887+4 4 4 4 4 4
50888+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
50889+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
50890+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
50891+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
50892+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
50893+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
50894+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
50895+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
50896+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
50897+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
50898+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50899+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50900+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50901+4 4 4 4 4 4
50902+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
50903+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
50904+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
50905+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
50906+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
50907+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
50908+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
50909+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
50910+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
50911+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
50912+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50913+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50914+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50915+4 4 4 4 4 4
50916+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
50917+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
50918+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
50919+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
50920+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
50921+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
50922+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
50923+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
50924+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
50925+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50926+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50927+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50928+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50929+4 4 4 4 4 4
50930+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
50931+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
50932+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
50933+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
50934+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
50935+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
50936+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
50937+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
50938+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
50939+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50940+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50941+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50942+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50943+4 4 4 4 4 4
50944+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
50945+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
50946+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
50947+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
50948+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
50949+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
50950+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
50951+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
50952+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
50953+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50954+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50955+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50956+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50957+4 4 4 4 4 4
50958+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
50959+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
50960+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
50961+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
50962+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
50963+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
50964+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
50965+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
50966+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
50967+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50968+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50969+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50970+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50971+4 4 4 4 4 4
50972+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
50973+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
50974+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
50975+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
50976+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
50977+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
50978+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
50979+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
50980+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
50981+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50982+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50983+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50984+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50985+4 4 4 4 4 4
50986+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
50987+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
50988+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
50989+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
50990+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
50991+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
50992+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
50993+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
50994+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
50995+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50996+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50997+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50998+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50999+4 4 4 4 4 4
51000+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
51001+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
51002+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
51003+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
51004+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
51005+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
51006+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
51007+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
51008+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
51009+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51010+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51011+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51012+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51013+4 4 4 4 4 4
51014+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
51015+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
51016+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
51017+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
51018+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
51019+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
51020+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
51021+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
51022+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51023+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51024+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51025+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51026+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51027+4 4 4 4 4 4
51028+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
51029+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
51030+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
51031+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
51032+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
51033+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
51034+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
51035+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
51036+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
51037+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51038+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51039+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51040+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51041+4 4 4 4 4 4
51042+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
51043+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
51044+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
51045+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
51046+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
51047+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
51048+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51049+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
51050+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51051+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51052+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51053+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51054+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51055+4 4 4 4 4 4
51056+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
51057+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
51058+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
51059+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
51060+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
51061+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
51062+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51063+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
51064+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
51065+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51066+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51067+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51068+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51069+4 4 4 4 4 4
51070+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
51071+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
51072+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
51073+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
51074+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
51075+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
51076+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
51077+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
51078+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
51079+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51080+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51081+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51082+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51083+4 4 4 4 4 4
51084+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
51085+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
51086+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
51087+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
51088+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
51089+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
51090+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
51091+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
51092+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
51093+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51094+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51095+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51096+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51097+4 4 4 4 4 4
51098+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
51099+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
51100+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
51101+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
51102+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
51103+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
51104+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
51105+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
51106+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
51107+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51108+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51109+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51110+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51111+4 4 4 4 4 4
51112+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
51113+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
51114+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
51115+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
51116+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
51117+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
51118+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
51119+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
51120+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
51121+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51122+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51123+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51124+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51125+4 4 4 4 4 4
51126+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
51127+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
51128+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
51129+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
51130+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
51131+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
51132+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
51133+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
51134+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
51135+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
51136+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51137+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51138+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51139+4 4 4 4 4 4
51140+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
51141+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
51142+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
51143+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
51144+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
51145+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
51146+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
51147+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
51148+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
51149+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
51150+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51151+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51152+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51153+4 4 4 4 4 4
51154+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
51155+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
51156+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
51157+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
51158+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
51159+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
51160+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51161+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
51162+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
51163+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
51164+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
51165+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51166+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51167+4 4 4 4 4 4
51168+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
51169+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
51170+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
51171+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
51172+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
51173+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
51174+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
51175+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
51176+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
51177+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
51178+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51179+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51180+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51181+4 4 4 4 4 4
51182+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
51183+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
51184+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
51185+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
51186+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
51187+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
51188+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
51189+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
51190+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
51191+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
51192+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51193+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51194+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51195+4 4 4 4 4 4
51196+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
51197+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
51198+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
51199+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
51200+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
51201+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
51202+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
51203+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
51204+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
51205+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
51206+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51207+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51208+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51209+4 4 4 4 4 4
51210+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
51211+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
51212+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
51213+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
51214+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
51215+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
51216+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
51217+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
51218+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
51219+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
51220+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51221+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51222+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51223+4 4 4 4 4 4
51224+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
51225+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
51226+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
51227+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
51228+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
51229+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
51230+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
51231+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
51232+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
51233+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
51234+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51235+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51236+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51237+4 4 4 4 4 4
51238+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
51239+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
51240+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
51241+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
51242+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
51243+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
51244+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
51245+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
51246+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
51247+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51248+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51249+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51250+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51251+4 4 4 4 4 4
51252+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
51253+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
51254+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
51255+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
51256+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
51257+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
51258+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
51259+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
51260+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
51261+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51262+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51263+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51264+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51265+4 4 4 4 4 4
51266+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
51267+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
51268+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
51269+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
51270+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
51271+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
51272+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
51273+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
51274+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51275+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51276+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51277+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51278+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51279+4 4 4 4 4 4
51280+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
51281+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
51282+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
51283+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
51284+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
51285+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
51286+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
51287+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
51288+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51289+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51290+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51291+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51292+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51293+4 4 4 4 4 4
51294+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
51295+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
51296+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
51297+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
51298+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
51299+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
51300+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
51301+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
51302+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51303+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51304+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51305+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51306+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51307+4 4 4 4 4 4
51308+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
51309+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
51310+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
51311+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
51312+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
51313+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
51314+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
51315+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
51316+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51317+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51318+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51319+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51320+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51321+4 4 4 4 4 4
51322+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51323+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
51324+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
51325+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
51326+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
51327+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
51328+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
51329+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
51330+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51331+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51332+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51333+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51334+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51335+4 4 4 4 4 4
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 5 5 5 5 5 5 5 5 5
51338+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
51339+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
51340+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
51341+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
51342+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
51343+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
51344+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51345+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51346+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51347+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51348+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51349+4 4 4 4 4 4
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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
51353+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
51354+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
51355+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
51356+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
51357+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
51358+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51359+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51360+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51361+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51362+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51363+4 4 4 4 4 4
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 5 5 5
51367+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
51368+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
51369+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
51370+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
51371+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51372+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51373+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51374+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51375+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51376+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51377+4 4 4 4 4 4
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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
51382+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
51383+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
51384+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
51385+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51386+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51387+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51388+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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
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 5 5 5 4 3 3 5 5 5 6 6 6
51396+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
51397+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
51398+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
51399+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51400+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51401+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51402+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51403+4 4 4 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
51406+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51407+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51408+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51409+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
51410+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
51411+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
51412+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
51413+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51414+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51415+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51416+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51417+4 4 4 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
51420+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51421+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51422+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51423+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
51424+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
51425+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
51426+6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4
51429+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51430+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51431+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51432+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51433+4 4 4 4 4 4
51434+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51435+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51436+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51437+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51438+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
51439+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
51440+4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4
51443+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51444+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51445+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51446+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51447+4 4 4 4 4 4
51448+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51449+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51450+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51451+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51452+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
51453+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
51454+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51455+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51456+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51457+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51458+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51459+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51460+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51461+4 4 4 4 4 4
51462+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51463+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51464+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51465+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51466+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
51467+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
51468+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51469+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51470+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51471+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51472+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51473+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51474+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51475+4 4 4 4 4 4
51476+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51477+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51478+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51479+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51480+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
51481+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
51482+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51483+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51484+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51485+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51486+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51487+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51488+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51489+4 4 4 4 4 4
51490diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
51491index fe92eed..106e085 100644
51492--- a/drivers/video/mb862xx/mb862xxfb_accel.c
51493+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
51494@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
51495 struct mb862xxfb_par *par = info->par;
51496
51497 if (info->var.bits_per_pixel == 32) {
51498- info->fbops->fb_fillrect = cfb_fillrect;
51499- info->fbops->fb_copyarea = cfb_copyarea;
51500- info->fbops->fb_imageblit = cfb_imageblit;
51501+ pax_open_kernel();
51502+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
51503+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
51504+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
51505+ pax_close_kernel();
51506 } else {
51507 outreg(disp, GC_L0EM, 3);
51508- info->fbops->fb_fillrect = mb86290fb_fillrect;
51509- info->fbops->fb_copyarea = mb86290fb_copyarea;
51510- info->fbops->fb_imageblit = mb86290fb_imageblit;
51511+ pax_open_kernel();
51512+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
51513+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
51514+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
51515+ pax_close_kernel();
51516 }
51517 outreg(draw, GDC_REG_DRAW_BASE, 0);
51518 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
51519diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
51520index ff22871..b129bed 100644
51521--- a/drivers/video/nvidia/nvidia.c
51522+++ b/drivers/video/nvidia/nvidia.c
51523@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
51524 info->fix.line_length = (info->var.xres_virtual *
51525 info->var.bits_per_pixel) >> 3;
51526 if (info->var.accel_flags) {
51527- info->fbops->fb_imageblit = nvidiafb_imageblit;
51528- info->fbops->fb_fillrect = nvidiafb_fillrect;
51529- info->fbops->fb_copyarea = nvidiafb_copyarea;
51530- info->fbops->fb_sync = nvidiafb_sync;
51531+ pax_open_kernel();
51532+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
51533+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
51534+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
51535+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
51536+ pax_close_kernel();
51537 info->pixmap.scan_align = 4;
51538 info->flags &= ~FBINFO_HWACCEL_DISABLED;
51539 info->flags |= FBINFO_READS_FAST;
51540 NVResetGraphics(info);
51541 } else {
51542- info->fbops->fb_imageblit = cfb_imageblit;
51543- info->fbops->fb_fillrect = cfb_fillrect;
51544- info->fbops->fb_copyarea = cfb_copyarea;
51545- info->fbops->fb_sync = NULL;
51546+ pax_open_kernel();
51547+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
51548+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
51549+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
51550+ *(void **)&info->fbops->fb_sync = NULL;
51551+ pax_close_kernel();
51552 info->pixmap.scan_align = 1;
51553 info->flags |= FBINFO_HWACCEL_DISABLED;
51554 info->flags &= ~FBINFO_READS_FAST;
51555@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
51556 info->pixmap.size = 8 * 1024;
51557 info->pixmap.flags = FB_PIXMAP_SYSTEM;
51558
51559- if (!hwcur)
51560- info->fbops->fb_cursor = NULL;
51561+ if (!hwcur) {
51562+ pax_open_kernel();
51563+ *(void **)&info->fbops->fb_cursor = NULL;
51564+ pax_close_kernel();
51565+ }
51566
51567 info->var.accel_flags = (!noaccel);
51568
51569diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
51570index 05c2dc3..ea1f391 100644
51571--- a/drivers/video/s1d13xxxfb.c
51572+++ b/drivers/video/s1d13xxxfb.c
51573@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
51574
51575 switch(prod_id) {
51576 case S1D13506_PROD_ID: /* activate acceleration */
51577- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
51578- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
51579+ pax_open_kernel();
51580+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
51581+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
51582+ pax_close_kernel();
51583 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
51584 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
51585 break;
51586diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
51587index e188ada..aac63c8 100644
51588--- a/drivers/video/smscufx.c
51589+++ b/drivers/video/smscufx.c
51590@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
51591 fb_deferred_io_cleanup(info);
51592 kfree(info->fbdefio);
51593 info->fbdefio = NULL;
51594- info->fbops->fb_mmap = ufx_ops_mmap;
51595+ pax_open_kernel();
51596+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
51597+ pax_close_kernel();
51598 }
51599
51600 pr_debug("released /dev/fb%d user=%d count=%d",
51601diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
51602index d2e5bc3..4cb05d1 100644
51603--- a/drivers/video/udlfb.c
51604+++ b/drivers/video/udlfb.c
51605@@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
51606 dlfb_urb_completion(urb);
51607
51608 error:
51609- atomic_add(bytes_sent, &dev->bytes_sent);
51610- atomic_add(bytes_identical, &dev->bytes_identical);
51611- atomic_add(width*height*2, &dev->bytes_rendered);
51612+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
51613+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
51614+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
51615 end_cycles = get_cycles();
51616- atomic_add(((unsigned int) ((end_cycles - start_cycles)
51617+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
51618 >> 10)), /* Kcycles */
51619 &dev->cpu_kcycles_used);
51620
51621@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
51622 dlfb_urb_completion(urb);
51623
51624 error:
51625- atomic_add(bytes_sent, &dev->bytes_sent);
51626- atomic_add(bytes_identical, &dev->bytes_identical);
51627- atomic_add(bytes_rendered, &dev->bytes_rendered);
51628+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
51629+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
51630+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
51631 end_cycles = get_cycles();
51632- atomic_add(((unsigned int) ((end_cycles - start_cycles)
51633+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
51634 >> 10)), /* Kcycles */
51635 &dev->cpu_kcycles_used);
51636 }
51637@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
51638 fb_deferred_io_cleanup(info);
51639 kfree(info->fbdefio);
51640 info->fbdefio = NULL;
51641- info->fbops->fb_mmap = dlfb_ops_mmap;
51642+ pax_open_kernel();
51643+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
51644+ pax_close_kernel();
51645 }
51646
51647 pr_warn("released /dev/fb%d user=%d count=%d\n",
51648@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
51649 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51650 struct dlfb_data *dev = fb_info->par;
51651 return snprintf(buf, PAGE_SIZE, "%u\n",
51652- atomic_read(&dev->bytes_rendered));
51653+ atomic_read_unchecked(&dev->bytes_rendered));
51654 }
51655
51656 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
51657@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
51658 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51659 struct dlfb_data *dev = fb_info->par;
51660 return snprintf(buf, PAGE_SIZE, "%u\n",
51661- atomic_read(&dev->bytes_identical));
51662+ atomic_read_unchecked(&dev->bytes_identical));
51663 }
51664
51665 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
51666@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
51667 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51668 struct dlfb_data *dev = fb_info->par;
51669 return snprintf(buf, PAGE_SIZE, "%u\n",
51670- atomic_read(&dev->bytes_sent));
51671+ atomic_read_unchecked(&dev->bytes_sent));
51672 }
51673
51674 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
51675@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
51676 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51677 struct dlfb_data *dev = fb_info->par;
51678 return snprintf(buf, PAGE_SIZE, "%u\n",
51679- atomic_read(&dev->cpu_kcycles_used));
51680+ atomic_read_unchecked(&dev->cpu_kcycles_used));
51681 }
51682
51683 static ssize_t edid_show(
51684@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
51685 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51686 struct dlfb_data *dev = fb_info->par;
51687
51688- atomic_set(&dev->bytes_rendered, 0);
51689- atomic_set(&dev->bytes_identical, 0);
51690- atomic_set(&dev->bytes_sent, 0);
51691- atomic_set(&dev->cpu_kcycles_used, 0);
51692+ atomic_set_unchecked(&dev->bytes_rendered, 0);
51693+ atomic_set_unchecked(&dev->bytes_identical, 0);
51694+ atomic_set_unchecked(&dev->bytes_sent, 0);
51695+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
51696
51697 return count;
51698 }
51699diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
51700index 7aec6f3..e3b2d55 100644
51701--- a/drivers/video/uvesafb.c
51702+++ b/drivers/video/uvesafb.c
51703@@ -19,6 +19,7 @@
51704 #include <linux/io.h>
51705 #include <linux/mutex.h>
51706 #include <linux/slab.h>
51707+#include <linux/moduleloader.h>
51708 #include <video/edid.h>
51709 #include <video/uvesafb.h>
51710 #ifdef CONFIG_X86
51711@@ -566,10 +567,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
51712 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
51713 par->pmi_setpal = par->ypan = 0;
51714 } else {
51715+
51716+#ifdef CONFIG_PAX_KERNEXEC
51717+#ifdef CONFIG_MODULES
51718+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
51719+#endif
51720+ if (!par->pmi_code) {
51721+ par->pmi_setpal = par->ypan = 0;
51722+ return 0;
51723+ }
51724+#endif
51725+
51726 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
51727 + task->t.regs.edi);
51728+
51729+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51730+ pax_open_kernel();
51731+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
51732+ pax_close_kernel();
51733+
51734+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
51735+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
51736+#else
51737 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
51738 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
51739+#endif
51740+
51741 printk(KERN_INFO "uvesafb: protected mode interface info at "
51742 "%04x:%04x\n",
51743 (u16)task->t.regs.es, (u16)task->t.regs.edi);
51744@@ -814,13 +837,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
51745 par->ypan = ypan;
51746
51747 if (par->pmi_setpal || par->ypan) {
51748+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
51749 if (__supported_pte_mask & _PAGE_NX) {
51750 par->pmi_setpal = par->ypan = 0;
51751 printk(KERN_WARNING "uvesafb: NX protection is active, "
51752 "better not use the PMI.\n");
51753- } else {
51754+ } else
51755+#endif
51756 uvesafb_vbe_getpmi(task, par);
51757- }
51758 }
51759 #else
51760 /* The protected mode interface is not available on non-x86. */
51761@@ -1454,8 +1478,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
51762 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
51763
51764 /* Disable blanking if the user requested so. */
51765- if (!blank)
51766- info->fbops->fb_blank = NULL;
51767+ if (!blank) {
51768+ pax_open_kernel();
51769+ *(void **)&info->fbops->fb_blank = NULL;
51770+ pax_close_kernel();
51771+ }
51772
51773 /*
51774 * Find out how much IO memory is required for the mode with
51775@@ -1531,8 +1558,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
51776 info->flags = FBINFO_FLAG_DEFAULT |
51777 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
51778
51779- if (!par->ypan)
51780- info->fbops->fb_pan_display = NULL;
51781+ if (!par->ypan) {
51782+ pax_open_kernel();
51783+ *(void **)&info->fbops->fb_pan_display = NULL;
51784+ pax_close_kernel();
51785+ }
51786 }
51787
51788 static void uvesafb_init_mtrr(struct fb_info *info)
51789@@ -1796,6 +1826,11 @@ out:
51790 if (par->vbe_modes)
51791 kfree(par->vbe_modes);
51792
51793+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51794+ if (par->pmi_code)
51795+ module_free_exec(NULL, par->pmi_code);
51796+#endif
51797+
51798 framebuffer_release(info);
51799 return err;
51800 }
51801@@ -1823,6 +1858,12 @@ static int uvesafb_remove(struct platform_device *dev)
51802 kfree(par->vbe_state_orig);
51803 if (par->vbe_state_saved)
51804 kfree(par->vbe_state_saved);
51805+
51806+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51807+ if (par->pmi_code)
51808+ module_free_exec(NULL, par->pmi_code);
51809+#endif
51810+
51811 }
51812
51813 framebuffer_release(info);
51814diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
51815index 501b340..d80aa17 100644
51816--- a/drivers/video/vesafb.c
51817+++ b/drivers/video/vesafb.c
51818@@ -9,6 +9,7 @@
51819 */
51820
51821 #include <linux/module.h>
51822+#include <linux/moduleloader.h>
51823 #include <linux/kernel.h>
51824 #include <linux/errno.h>
51825 #include <linux/string.h>
51826@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
51827 static int vram_total __initdata; /* Set total amount of memory */
51828 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
51829 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
51830-static void (*pmi_start)(void) __read_mostly;
51831-static void (*pmi_pal) (void) __read_mostly;
51832+static void (*pmi_start)(void) __read_only;
51833+static void (*pmi_pal) (void) __read_only;
51834 static int depth __read_mostly;
51835 static int vga_compat __read_mostly;
51836 /* --------------------------------------------------------------------- */
51837@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
51838 unsigned int size_vmode;
51839 unsigned int size_remap;
51840 unsigned int size_total;
51841+ void *pmi_code = NULL;
51842
51843 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
51844 return -ENODEV;
51845@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
51846 size_remap = size_total;
51847 vesafb_fix.smem_len = size_remap;
51848
51849-#ifndef __i386__
51850- screen_info.vesapm_seg = 0;
51851-#endif
51852-
51853 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
51854 printk(KERN_WARNING
51855 "vesafb: cannot reserve video memory at 0x%lx\n",
51856@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
51857 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
51858 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
51859
51860+#ifdef __i386__
51861+
51862+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51863+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
51864+ if (!pmi_code)
51865+#elif !defined(CONFIG_PAX_KERNEXEC)
51866+ if (0)
51867+#endif
51868+
51869+#endif
51870+ screen_info.vesapm_seg = 0;
51871+
51872 if (screen_info.vesapm_seg) {
51873- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
51874- screen_info.vesapm_seg,screen_info.vesapm_off);
51875+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
51876+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
51877 }
51878
51879 if (screen_info.vesapm_seg < 0xc000)
51880@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
51881
51882 if (ypan || pmi_setpal) {
51883 unsigned short *pmi_base;
51884+
51885 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
51886- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
51887- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
51888+
51889+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51890+ pax_open_kernel();
51891+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
51892+#else
51893+ pmi_code = pmi_base;
51894+#endif
51895+
51896+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
51897+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
51898+
51899+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51900+ pmi_start = ktva_ktla(pmi_start);
51901+ pmi_pal = ktva_ktla(pmi_pal);
51902+ pax_close_kernel();
51903+#endif
51904+
51905 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
51906 if (pmi_base[3]) {
51907 printk(KERN_INFO "vesafb: pmi: ports = ");
51908@@ -472,8 +498,11 @@ static int __init vesafb_probe(struct platform_device *dev)
51909 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
51910 (ypan ? FBINFO_HWACCEL_YPAN : 0);
51911
51912- if (!ypan)
51913- info->fbops->fb_pan_display = NULL;
51914+ if (!ypan) {
51915+ pax_open_kernel();
51916+ *(void **)&info->fbops->fb_pan_display = NULL;
51917+ pax_close_kernel();
51918+ }
51919
51920 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
51921 err = -ENOMEM;
51922@@ -488,6 +517,11 @@ static int __init vesafb_probe(struct platform_device *dev)
51923 info->node, info->fix.id);
51924 return 0;
51925 err:
51926+
51927+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51928+ module_free_exec(NULL, pmi_code);
51929+#endif
51930+
51931 if (info->screen_base)
51932 iounmap(info->screen_base);
51933 framebuffer_release(info);
51934diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
51935index 88714ae..16c2e11 100644
51936--- a/drivers/video/via/via_clock.h
51937+++ b/drivers/video/via/via_clock.h
51938@@ -56,7 +56,7 @@ struct via_clock {
51939
51940 void (*set_engine_pll_state)(u8 state);
51941 void (*set_engine_pll)(struct via_pll_config config);
51942-};
51943+} __no_const;
51944
51945
51946 static inline u32 get_pll_internal_frequency(u32 ref_freq,
51947diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
51948index fef20db..d28b1ab 100644
51949--- a/drivers/xen/xenfs/xenstored.c
51950+++ b/drivers/xen/xenfs/xenstored.c
51951@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
51952 static int xsd_kva_open(struct inode *inode, struct file *file)
51953 {
51954 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
51955+#ifdef CONFIG_GRKERNSEC_HIDESYM
51956+ NULL);
51957+#else
51958 xen_store_interface);
51959+#endif
51960+
51961 if (!file->private_data)
51962 return -ENOMEM;
51963 return 0;
51964diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
51965index 9ff073f..05cef23 100644
51966--- a/fs/9p/vfs_addr.c
51967+++ b/fs/9p/vfs_addr.c
51968@@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
51969
51970 retval = v9fs_file_write_internal(inode,
51971 v9inode->writeback_fid,
51972- (__force const char __user *)buffer,
51973+ (const char __force_user *)buffer,
51974 len, &offset, 0);
51975 if (retval > 0)
51976 retval = 0;
51977diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
51978index 25b018e..b941525 100644
51979--- a/fs/9p/vfs_inode.c
51980+++ b/fs/9p/vfs_inode.c
51981@@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
51982 void
51983 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
51984 {
51985- char *s = nd_get_link(nd);
51986+ const char *s = nd_get_link(nd);
51987
51988 p9_debug(P9_DEBUG_VFS, " %s %s\n",
51989 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
51990diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
51991index 370b24c..ff0be7b 100644
51992--- a/fs/Kconfig.binfmt
51993+++ b/fs/Kconfig.binfmt
51994@@ -103,7 +103,7 @@ config HAVE_AOUT
51995
51996 config BINFMT_AOUT
51997 tristate "Kernel support for a.out and ECOFF binaries"
51998- depends on HAVE_AOUT
51999+ depends on HAVE_AOUT && BROKEN
52000 ---help---
52001 A.out (Assembler.OUTput) is a set of formats for libraries and
52002 executables used in the earliest versions of UNIX. Linux used
52003diff --git a/fs/afs/inode.c b/fs/afs/inode.c
52004index 789bc25..fafaeea 100644
52005--- a/fs/afs/inode.c
52006+++ b/fs/afs/inode.c
52007@@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
52008 struct afs_vnode *vnode;
52009 struct super_block *sb;
52010 struct inode *inode;
52011- static atomic_t afs_autocell_ino;
52012+ static atomic_unchecked_t afs_autocell_ino;
52013
52014 _enter("{%x:%u},%*.*s,",
52015 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
52016@@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
52017 data.fid.unique = 0;
52018 data.fid.vnode = 0;
52019
52020- inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
52021+ inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
52022 afs_iget5_autocell_test, afs_iget5_set,
52023 &data);
52024 if (!inode) {
52025diff --git a/fs/aio.c b/fs/aio.c
52026index 9b5ca11..c530886 100644
52027--- a/fs/aio.c
52028+++ b/fs/aio.c
52029@@ -162,7 +162,7 @@ static int aio_setup_ring(struct kioctx *ctx)
52030 size += sizeof(struct io_event) * nr_events;
52031 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
52032
52033- if (nr_pages < 0)
52034+ if (nr_pages <= 0)
52035 return -EINVAL;
52036
52037 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
52038@@ -952,6 +952,7 @@ static ssize_t aio_rw_vect_retry(struct kiocb *iocb, int rw, aio_rw_op *rw_op)
52039 static ssize_t aio_setup_vectored_rw(int rw, struct kiocb *kiocb, bool compat)
52040 {
52041 ssize_t ret;
52042+ struct iovec iovstack;
52043
52044 kiocb->ki_nr_segs = kiocb->ki_nbytes;
52045
52046@@ -959,17 +960,22 @@ static ssize_t aio_setup_vectored_rw(int rw, struct kiocb *kiocb, bool compat)
52047 if (compat)
52048 ret = compat_rw_copy_check_uvector(rw,
52049 (struct compat_iovec __user *)kiocb->ki_buf,
52050- kiocb->ki_nr_segs, 1, &kiocb->ki_inline_vec,
52051+ kiocb->ki_nr_segs, 1, &iovstack,
52052 &kiocb->ki_iovec);
52053 else
52054 #endif
52055 ret = rw_copy_check_uvector(rw,
52056 (struct iovec __user *)kiocb->ki_buf,
52057- kiocb->ki_nr_segs, 1, &kiocb->ki_inline_vec,
52058+ kiocb->ki_nr_segs, 1, &iovstack,
52059 &kiocb->ki_iovec);
52060 if (ret < 0)
52061 return ret;
52062
52063+ if (kiocb->ki_iovec == &iovstack) {
52064+ kiocb->ki_inline_vec = iovstack;
52065+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
52066+ }
52067+
52068 /* ki_nbytes now reflect bytes instead of segs */
52069 kiocb->ki_nbytes = ret;
52070 return 0;
52071diff --git a/fs/attr.c b/fs/attr.c
52072index 1449adb..a2038c2 100644
52073--- a/fs/attr.c
52074+++ b/fs/attr.c
52075@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
52076 unsigned long limit;
52077
52078 limit = rlimit(RLIMIT_FSIZE);
52079+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
52080 if (limit != RLIM_INFINITY && offset > limit)
52081 goto out_sig;
52082 if (offset > inode->i_sb->s_maxbytes)
52083diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
52084index 3db70da..7aeec5b 100644
52085--- a/fs/autofs4/waitq.c
52086+++ b/fs/autofs4/waitq.c
52087@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
52088 {
52089 unsigned long sigpipe, flags;
52090 mm_segment_t fs;
52091- const char *data = (const char *)addr;
52092+ const char __user *data = (const char __force_user *)addr;
52093 ssize_t wr = 0;
52094
52095 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
52096@@ -346,6 +346,10 @@ static int validate_request(struct autofs_wait_queue **wait,
52097 return 1;
52098 }
52099
52100+#ifdef CONFIG_GRKERNSEC_HIDESYM
52101+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
52102+#endif
52103+
52104 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
52105 enum autofs_notify notify)
52106 {
52107@@ -379,7 +383,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
52108
52109 /* If this is a direct mount request create a dummy name */
52110 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
52111+#ifdef CONFIG_GRKERNSEC_HIDESYM
52112+ /* this name does get written to userland via autofs4_write() */
52113+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
52114+#else
52115 qstr.len = sprintf(name, "%p", dentry);
52116+#endif
52117 else {
52118 qstr.len = autofs4_getpath(sbi, dentry, &name);
52119 if (!qstr.len) {
52120diff --git a/fs/befs/endian.h b/fs/befs/endian.h
52121index 2722387..c8dd2a7 100644
52122--- a/fs/befs/endian.h
52123+++ b/fs/befs/endian.h
52124@@ -11,7 +11,7 @@
52125
52126 #include <asm/byteorder.h>
52127
52128-static inline u64
52129+static inline u64 __intentional_overflow(-1)
52130 fs64_to_cpu(const struct super_block *sb, fs64 n)
52131 {
52132 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
52133@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
52134 return (__force fs64)cpu_to_be64(n);
52135 }
52136
52137-static inline u32
52138+static inline u32 __intentional_overflow(-1)
52139 fs32_to_cpu(const struct super_block *sb, fs32 n)
52140 {
52141 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
52142diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
52143index e9c75e2..1baece1 100644
52144--- a/fs/befs/linuxvfs.c
52145+++ b/fs/befs/linuxvfs.c
52146@@ -514,7 +514,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
52147 {
52148 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
52149 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
52150- char *link = nd_get_link(nd);
52151+ const char *link = nd_get_link(nd);
52152 if (!IS_ERR(link))
52153 kfree(link);
52154 }
52155diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
52156index 89dec7f..361b0d75 100644
52157--- a/fs/binfmt_aout.c
52158+++ b/fs/binfmt_aout.c
52159@@ -16,6 +16,7 @@
52160 #include <linux/string.h>
52161 #include <linux/fs.h>
52162 #include <linux/file.h>
52163+#include <linux/security.h>
52164 #include <linux/stat.h>
52165 #include <linux/fcntl.h>
52166 #include <linux/ptrace.h>
52167@@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
52168 #endif
52169 # define START_STACK(u) ((void __user *)u.start_stack)
52170
52171+ memset(&dump, 0, sizeof(dump));
52172+
52173 fs = get_fs();
52174 set_fs(KERNEL_DS);
52175 has_dumped = 1;
52176@@ -69,10 +72,12 @@ static int aout_core_dump(struct coredump_params *cprm)
52177
52178 /* If the size of the dump file exceeds the rlimit, then see what would happen
52179 if we wrote the stack, but not the data area. */
52180+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
52181 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
52182 dump.u_dsize = 0;
52183
52184 /* Make sure we have enough room to write the stack and data areas. */
52185+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
52186 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
52187 dump.u_ssize = 0;
52188
52189@@ -233,6 +238,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
52190 rlim = rlimit(RLIMIT_DATA);
52191 if (rlim >= RLIM_INFINITY)
52192 rlim = ~0;
52193+
52194+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
52195 if (ex.a_data + ex.a_bss > rlim)
52196 return -ENOMEM;
52197
52198@@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
52199
52200 install_exec_creds(bprm);
52201
52202+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52203+ current->mm->pax_flags = 0UL;
52204+#endif
52205+
52206+#ifdef CONFIG_PAX_PAGEEXEC
52207+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
52208+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
52209+
52210+#ifdef CONFIG_PAX_EMUTRAMP
52211+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
52212+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
52213+#endif
52214+
52215+#ifdef CONFIG_PAX_MPROTECT
52216+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
52217+ current->mm->pax_flags |= MF_PAX_MPROTECT;
52218+#endif
52219+
52220+ }
52221+#endif
52222+
52223 if (N_MAGIC(ex) == OMAGIC) {
52224 unsigned long text_addr, map_size;
52225 loff_t pos;
52226@@ -322,7 +350,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
52227 }
52228
52229 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
52230- PROT_READ | PROT_WRITE | PROT_EXEC,
52231+ PROT_READ | PROT_WRITE,
52232 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
52233 fd_offset + ex.a_text);
52234 if (error != N_DATADDR(ex)) {
52235diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
52236index 4c94a79..f428019 100644
52237--- a/fs/binfmt_elf.c
52238+++ b/fs/binfmt_elf.c
52239@@ -34,6 +34,7 @@
52240 #include <linux/utsname.h>
52241 #include <linux/coredump.h>
52242 #include <linux/sched.h>
52243+#include <linux/xattr.h>
52244 #include <asm/uaccess.h>
52245 #include <asm/param.h>
52246 #include <asm/page.h>
52247@@ -60,6 +61,14 @@ static int elf_core_dump(struct coredump_params *cprm);
52248 #define elf_core_dump NULL
52249 #endif
52250
52251+#ifdef CONFIG_PAX_MPROTECT
52252+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
52253+#endif
52254+
52255+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
52256+static void elf_handle_mmap(struct file *file);
52257+#endif
52258+
52259 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
52260 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
52261 #else
52262@@ -79,6 +88,15 @@ static struct linux_binfmt elf_format = {
52263 .load_binary = load_elf_binary,
52264 .load_shlib = load_elf_library,
52265 .core_dump = elf_core_dump,
52266+
52267+#ifdef CONFIG_PAX_MPROTECT
52268+ .handle_mprotect= elf_handle_mprotect,
52269+#endif
52270+
52271+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
52272+ .handle_mmap = elf_handle_mmap,
52273+#endif
52274+
52275 .min_coredump = ELF_EXEC_PAGESIZE,
52276 };
52277
52278@@ -86,6 +104,8 @@ static struct linux_binfmt elf_format = {
52279
52280 static int set_brk(unsigned long start, unsigned long end)
52281 {
52282+ unsigned long e = end;
52283+
52284 start = ELF_PAGEALIGN(start);
52285 end = ELF_PAGEALIGN(end);
52286 if (end > start) {
52287@@ -94,7 +114,7 @@ static int set_brk(unsigned long start, unsigned long end)
52288 if (BAD_ADDR(addr))
52289 return addr;
52290 }
52291- current->mm->start_brk = current->mm->brk = end;
52292+ current->mm->start_brk = current->mm->brk = e;
52293 return 0;
52294 }
52295
52296@@ -155,12 +175,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
52297 elf_addr_t __user *u_rand_bytes;
52298 const char *k_platform = ELF_PLATFORM;
52299 const char *k_base_platform = ELF_BASE_PLATFORM;
52300- unsigned char k_rand_bytes[16];
52301+ u32 k_rand_bytes[4];
52302 int items;
52303 elf_addr_t *elf_info;
52304 int ei_index = 0;
52305 const struct cred *cred = current_cred();
52306 struct vm_area_struct *vma;
52307+ unsigned long saved_auxv[AT_VECTOR_SIZE];
52308
52309 /*
52310 * In some cases (e.g. Hyper-Threading), we want to avoid L1
52311@@ -202,8 +223,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
52312 * Generate 16 random bytes for userspace PRNG seeding.
52313 */
52314 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
52315- u_rand_bytes = (elf_addr_t __user *)
52316- STACK_ALLOC(p, sizeof(k_rand_bytes));
52317+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
52318+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
52319+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
52320+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
52321+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
52322+ u_rand_bytes = (elf_addr_t __user *) p;
52323 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
52324 return -EFAULT;
52325
52326@@ -318,9 +343,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
52327 return -EFAULT;
52328 current->mm->env_end = p;
52329
52330+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
52331+
52332 /* Put the elf_info on the stack in the right place. */
52333 sp = (elf_addr_t __user *)envp + 1;
52334- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
52335+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
52336 return -EFAULT;
52337 return 0;
52338 }
52339@@ -388,15 +415,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
52340 an ELF header */
52341
52342 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52343- struct file *interpreter, unsigned long *interp_map_addr,
52344- unsigned long no_base)
52345+ struct file *interpreter, unsigned long no_base)
52346 {
52347 struct elf_phdr *elf_phdata;
52348 struct elf_phdr *eppnt;
52349- unsigned long load_addr = 0;
52350+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
52351 int load_addr_set = 0;
52352 unsigned long last_bss = 0, elf_bss = 0;
52353- unsigned long error = ~0UL;
52354+ unsigned long error = -EINVAL;
52355 unsigned long total_size;
52356 int retval, i, size;
52357
52358@@ -442,6 +468,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52359 goto out_close;
52360 }
52361
52362+#ifdef CONFIG_PAX_SEGMEXEC
52363+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
52364+ pax_task_size = SEGMEXEC_TASK_SIZE;
52365+#endif
52366+
52367 eppnt = elf_phdata;
52368 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
52369 if (eppnt->p_type == PT_LOAD) {
52370@@ -465,8 +496,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52371 map_addr = elf_map(interpreter, load_addr + vaddr,
52372 eppnt, elf_prot, elf_type, total_size);
52373 total_size = 0;
52374- if (!*interp_map_addr)
52375- *interp_map_addr = map_addr;
52376 error = map_addr;
52377 if (BAD_ADDR(map_addr))
52378 goto out_close;
52379@@ -485,8 +514,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52380 k = load_addr + eppnt->p_vaddr;
52381 if (BAD_ADDR(k) ||
52382 eppnt->p_filesz > eppnt->p_memsz ||
52383- eppnt->p_memsz > TASK_SIZE ||
52384- TASK_SIZE - eppnt->p_memsz < k) {
52385+ eppnt->p_memsz > pax_task_size ||
52386+ pax_task_size - eppnt->p_memsz < k) {
52387 error = -ENOMEM;
52388 goto out_close;
52389 }
52390@@ -525,9 +554,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52391 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
52392
52393 /* Map the last of the bss segment */
52394- error = vm_brk(elf_bss, last_bss - elf_bss);
52395- if (BAD_ADDR(error))
52396- goto out_close;
52397+ if (last_bss > elf_bss) {
52398+ error = vm_brk(elf_bss, last_bss - elf_bss);
52399+ if (BAD_ADDR(error))
52400+ goto out_close;
52401+ }
52402 }
52403
52404 error = load_addr;
52405@@ -538,6 +569,315 @@ out:
52406 return error;
52407 }
52408
52409+#ifdef CONFIG_PAX_PT_PAX_FLAGS
52410+#ifdef CONFIG_PAX_SOFTMODE
52411+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
52412+{
52413+ unsigned long pax_flags = 0UL;
52414+
52415+#ifdef CONFIG_PAX_PAGEEXEC
52416+ if (elf_phdata->p_flags & PF_PAGEEXEC)
52417+ pax_flags |= MF_PAX_PAGEEXEC;
52418+#endif
52419+
52420+#ifdef CONFIG_PAX_SEGMEXEC
52421+ if (elf_phdata->p_flags & PF_SEGMEXEC)
52422+ pax_flags |= MF_PAX_SEGMEXEC;
52423+#endif
52424+
52425+#ifdef CONFIG_PAX_EMUTRAMP
52426+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
52427+ pax_flags |= MF_PAX_EMUTRAMP;
52428+#endif
52429+
52430+#ifdef CONFIG_PAX_MPROTECT
52431+ if (elf_phdata->p_flags & PF_MPROTECT)
52432+ pax_flags |= MF_PAX_MPROTECT;
52433+#endif
52434+
52435+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
52436+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
52437+ pax_flags |= MF_PAX_RANDMMAP;
52438+#endif
52439+
52440+ return pax_flags;
52441+}
52442+#endif
52443+
52444+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
52445+{
52446+ unsigned long pax_flags = 0UL;
52447+
52448+#ifdef CONFIG_PAX_PAGEEXEC
52449+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
52450+ pax_flags |= MF_PAX_PAGEEXEC;
52451+#endif
52452+
52453+#ifdef CONFIG_PAX_SEGMEXEC
52454+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
52455+ pax_flags |= MF_PAX_SEGMEXEC;
52456+#endif
52457+
52458+#ifdef CONFIG_PAX_EMUTRAMP
52459+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
52460+ pax_flags |= MF_PAX_EMUTRAMP;
52461+#endif
52462+
52463+#ifdef CONFIG_PAX_MPROTECT
52464+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
52465+ pax_flags |= MF_PAX_MPROTECT;
52466+#endif
52467+
52468+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
52469+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
52470+ pax_flags |= MF_PAX_RANDMMAP;
52471+#endif
52472+
52473+ return pax_flags;
52474+}
52475+#endif
52476+
52477+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
52478+#ifdef CONFIG_PAX_SOFTMODE
52479+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
52480+{
52481+ unsigned long pax_flags = 0UL;
52482+
52483+#ifdef CONFIG_PAX_PAGEEXEC
52484+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
52485+ pax_flags |= MF_PAX_PAGEEXEC;
52486+#endif
52487+
52488+#ifdef CONFIG_PAX_SEGMEXEC
52489+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
52490+ pax_flags |= MF_PAX_SEGMEXEC;
52491+#endif
52492+
52493+#ifdef CONFIG_PAX_EMUTRAMP
52494+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
52495+ pax_flags |= MF_PAX_EMUTRAMP;
52496+#endif
52497+
52498+#ifdef CONFIG_PAX_MPROTECT
52499+ if (pax_flags_softmode & MF_PAX_MPROTECT)
52500+ pax_flags |= MF_PAX_MPROTECT;
52501+#endif
52502+
52503+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
52504+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
52505+ pax_flags |= MF_PAX_RANDMMAP;
52506+#endif
52507+
52508+ return pax_flags;
52509+}
52510+#endif
52511+
52512+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
52513+{
52514+ unsigned long pax_flags = 0UL;
52515+
52516+#ifdef CONFIG_PAX_PAGEEXEC
52517+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
52518+ pax_flags |= MF_PAX_PAGEEXEC;
52519+#endif
52520+
52521+#ifdef CONFIG_PAX_SEGMEXEC
52522+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
52523+ pax_flags |= MF_PAX_SEGMEXEC;
52524+#endif
52525+
52526+#ifdef CONFIG_PAX_EMUTRAMP
52527+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
52528+ pax_flags |= MF_PAX_EMUTRAMP;
52529+#endif
52530+
52531+#ifdef CONFIG_PAX_MPROTECT
52532+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
52533+ pax_flags |= MF_PAX_MPROTECT;
52534+#endif
52535+
52536+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
52537+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
52538+ pax_flags |= MF_PAX_RANDMMAP;
52539+#endif
52540+
52541+ return pax_flags;
52542+}
52543+#endif
52544+
52545+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52546+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
52547+{
52548+ unsigned long pax_flags = 0UL;
52549+
52550+#ifdef CONFIG_PAX_EI_PAX
52551+
52552+#ifdef CONFIG_PAX_PAGEEXEC
52553+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
52554+ pax_flags |= MF_PAX_PAGEEXEC;
52555+#endif
52556+
52557+#ifdef CONFIG_PAX_SEGMEXEC
52558+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
52559+ pax_flags |= MF_PAX_SEGMEXEC;
52560+#endif
52561+
52562+#ifdef CONFIG_PAX_EMUTRAMP
52563+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
52564+ pax_flags |= MF_PAX_EMUTRAMP;
52565+#endif
52566+
52567+#ifdef CONFIG_PAX_MPROTECT
52568+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
52569+ pax_flags |= MF_PAX_MPROTECT;
52570+#endif
52571+
52572+#ifdef CONFIG_PAX_ASLR
52573+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
52574+ pax_flags |= MF_PAX_RANDMMAP;
52575+#endif
52576+
52577+#else
52578+
52579+#ifdef CONFIG_PAX_PAGEEXEC
52580+ pax_flags |= MF_PAX_PAGEEXEC;
52581+#endif
52582+
52583+#ifdef CONFIG_PAX_SEGMEXEC
52584+ pax_flags |= MF_PAX_SEGMEXEC;
52585+#endif
52586+
52587+#ifdef CONFIG_PAX_MPROTECT
52588+ pax_flags |= MF_PAX_MPROTECT;
52589+#endif
52590+
52591+#ifdef CONFIG_PAX_RANDMMAP
52592+ if (randomize_va_space)
52593+ pax_flags |= MF_PAX_RANDMMAP;
52594+#endif
52595+
52596+#endif
52597+
52598+ return pax_flags;
52599+}
52600+
52601+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
52602+{
52603+
52604+#ifdef CONFIG_PAX_PT_PAX_FLAGS
52605+ unsigned long i;
52606+
52607+ for (i = 0UL; i < elf_ex->e_phnum; i++)
52608+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
52609+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
52610+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
52611+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
52612+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
52613+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
52614+ return ~0UL;
52615+
52616+#ifdef CONFIG_PAX_SOFTMODE
52617+ if (pax_softmode)
52618+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
52619+ else
52620+#endif
52621+
52622+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
52623+ break;
52624+ }
52625+#endif
52626+
52627+ return ~0UL;
52628+}
52629+
52630+static unsigned long pax_parse_xattr_pax(struct file * const file)
52631+{
52632+
52633+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
52634+ ssize_t xattr_size, i;
52635+ unsigned char xattr_value[sizeof("pemrs") - 1];
52636+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
52637+
52638+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
52639+ if (xattr_size <= 0 || xattr_size > sizeof xattr_value)
52640+ return ~0UL;
52641+
52642+ for (i = 0; i < xattr_size; i++)
52643+ switch (xattr_value[i]) {
52644+ default:
52645+ return ~0UL;
52646+
52647+#define parse_flag(option1, option2, flag) \
52648+ case option1: \
52649+ if (pax_flags_hardmode & MF_PAX_##flag) \
52650+ return ~0UL; \
52651+ pax_flags_hardmode |= MF_PAX_##flag; \
52652+ break; \
52653+ case option2: \
52654+ if (pax_flags_softmode & MF_PAX_##flag) \
52655+ return ~0UL; \
52656+ pax_flags_softmode |= MF_PAX_##flag; \
52657+ break;
52658+
52659+ parse_flag('p', 'P', PAGEEXEC);
52660+ parse_flag('e', 'E', EMUTRAMP);
52661+ parse_flag('m', 'M', MPROTECT);
52662+ parse_flag('r', 'R', RANDMMAP);
52663+ parse_flag('s', 'S', SEGMEXEC);
52664+
52665+#undef parse_flag
52666+ }
52667+
52668+ if (pax_flags_hardmode & pax_flags_softmode)
52669+ return ~0UL;
52670+
52671+#ifdef CONFIG_PAX_SOFTMODE
52672+ if (pax_softmode)
52673+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
52674+ else
52675+#endif
52676+
52677+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
52678+#else
52679+ return ~0UL;
52680+#endif
52681+
52682+}
52683+
52684+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
52685+{
52686+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
52687+
52688+ pax_flags = pax_parse_ei_pax(elf_ex);
52689+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
52690+ xattr_pax_flags = pax_parse_xattr_pax(file);
52691+
52692+ if (pt_pax_flags == ~0UL)
52693+ pt_pax_flags = xattr_pax_flags;
52694+ else if (xattr_pax_flags == ~0UL)
52695+ xattr_pax_flags = pt_pax_flags;
52696+ if (pt_pax_flags != xattr_pax_flags)
52697+ return -EINVAL;
52698+ if (pt_pax_flags != ~0UL)
52699+ pax_flags = pt_pax_flags;
52700+
52701+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
52702+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
52703+ if ((__supported_pte_mask & _PAGE_NX))
52704+ pax_flags &= ~MF_PAX_SEGMEXEC;
52705+ else
52706+ pax_flags &= ~MF_PAX_PAGEEXEC;
52707+ }
52708+#endif
52709+
52710+ if (0 > pax_check_flags(&pax_flags))
52711+ return -EINVAL;
52712+
52713+ current->mm->pax_flags = pax_flags;
52714+ return 0;
52715+}
52716+#endif
52717+
52718 /*
52719 * These are the functions used to load ELF style executables and shared
52720 * libraries. There is no binary dependent code anywhere else.
52721@@ -554,6 +894,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
52722 {
52723 unsigned int random_variable = 0;
52724
52725+#ifdef CONFIG_PAX_RANDUSTACK
52726+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
52727+ return stack_top - current->mm->delta_stack;
52728+#endif
52729+
52730 if ((current->flags & PF_RANDOMIZE) &&
52731 !(current->personality & ADDR_NO_RANDOMIZE)) {
52732 random_variable = get_random_int() & STACK_RND_MASK;
52733@@ -572,7 +917,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
52734 unsigned long load_addr = 0, load_bias = 0;
52735 int load_addr_set = 0;
52736 char * elf_interpreter = NULL;
52737- unsigned long error;
52738+ unsigned long error = 0;
52739 struct elf_phdr *elf_ppnt, *elf_phdata;
52740 unsigned long elf_bss, elf_brk;
52741 int retval, i;
52742@@ -582,12 +927,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
52743 unsigned long start_code, end_code, start_data, end_data;
52744 unsigned long reloc_func_desc __maybe_unused = 0;
52745 int executable_stack = EXSTACK_DEFAULT;
52746- unsigned long def_flags = 0;
52747 struct pt_regs *regs = current_pt_regs();
52748 struct {
52749 struct elfhdr elf_ex;
52750 struct elfhdr interp_elf_ex;
52751 } *loc;
52752+ unsigned long pax_task_size = TASK_SIZE;
52753
52754 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
52755 if (!loc) {
52756@@ -723,11 +1068,81 @@ static int load_elf_binary(struct linux_binprm *bprm)
52757 goto out_free_dentry;
52758
52759 /* OK, This is the point of no return */
52760- current->mm->def_flags = def_flags;
52761+
52762+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52763+ current->mm->pax_flags = 0UL;
52764+#endif
52765+
52766+#ifdef CONFIG_PAX_DLRESOLVE
52767+ current->mm->call_dl_resolve = 0UL;
52768+#endif
52769+
52770+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
52771+ current->mm->call_syscall = 0UL;
52772+#endif
52773+
52774+#ifdef CONFIG_PAX_ASLR
52775+ current->mm->delta_mmap = 0UL;
52776+ current->mm->delta_stack = 0UL;
52777+#endif
52778+
52779+ current->mm->def_flags = 0;
52780+
52781+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52782+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
52783+ send_sig(SIGKILL, current, 0);
52784+ goto out_free_dentry;
52785+ }
52786+#endif
52787+
52788+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
52789+ pax_set_initial_flags(bprm);
52790+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
52791+ if (pax_set_initial_flags_func)
52792+ (pax_set_initial_flags_func)(bprm);
52793+#endif
52794+
52795+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
52796+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
52797+ current->mm->context.user_cs_limit = PAGE_SIZE;
52798+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
52799+ }
52800+#endif
52801+
52802+#ifdef CONFIG_PAX_SEGMEXEC
52803+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
52804+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
52805+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
52806+ pax_task_size = SEGMEXEC_TASK_SIZE;
52807+ current->mm->def_flags |= VM_NOHUGEPAGE;
52808+ }
52809+#endif
52810+
52811+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
52812+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
52813+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
52814+ put_cpu();
52815+ }
52816+#endif
52817
52818 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
52819 may depend on the personality. */
52820 SET_PERSONALITY(loc->elf_ex);
52821+
52822+#ifdef CONFIG_PAX_ASLR
52823+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
52824+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
52825+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
52826+ }
52827+#endif
52828+
52829+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
52830+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
52831+ executable_stack = EXSTACK_DISABLE_X;
52832+ current->personality &= ~READ_IMPLIES_EXEC;
52833+ } else
52834+#endif
52835+
52836 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
52837 current->personality |= READ_IMPLIES_EXEC;
52838
52839@@ -817,6 +1232,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
52840 #else
52841 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
52842 #endif
52843+
52844+#ifdef CONFIG_PAX_RANDMMAP
52845+ /* PaX: randomize base address at the default exe base if requested */
52846+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
52847+#ifdef CONFIG_SPARC64
52848+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
52849+#else
52850+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
52851+#endif
52852+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
52853+ elf_flags |= MAP_FIXED;
52854+ }
52855+#endif
52856+
52857 }
52858
52859 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
52860@@ -849,9 +1278,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
52861 * allowed task size. Note that p_filesz must always be
52862 * <= p_memsz so it is only necessary to check p_memsz.
52863 */
52864- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
52865- elf_ppnt->p_memsz > TASK_SIZE ||
52866- TASK_SIZE - elf_ppnt->p_memsz < k) {
52867+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
52868+ elf_ppnt->p_memsz > pax_task_size ||
52869+ pax_task_size - elf_ppnt->p_memsz < k) {
52870 /* set_brk can never work. Avoid overflows. */
52871 send_sig(SIGKILL, current, 0);
52872 retval = -EINVAL;
52873@@ -890,17 +1319,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
52874 goto out_free_dentry;
52875 }
52876 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
52877- send_sig(SIGSEGV, current, 0);
52878- retval = -EFAULT; /* Nobody gets to see this, but.. */
52879- goto out_free_dentry;
52880+ /*
52881+ * This bss-zeroing can fail if the ELF
52882+ * file specifies odd protections. So
52883+ * we don't check the return value
52884+ */
52885 }
52886
52887+#ifdef CONFIG_PAX_RANDMMAP
52888+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
52889+ unsigned long start, size, flags;
52890+ vm_flags_t vm_flags;
52891+
52892+ start = ELF_PAGEALIGN(elf_brk);
52893+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
52894+ flags = MAP_FIXED | MAP_PRIVATE;
52895+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
52896+
52897+ down_write(&current->mm->mmap_sem);
52898+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
52899+ retval = -ENOMEM;
52900+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
52901+// if (current->personality & ADDR_NO_RANDOMIZE)
52902+// vm_flags |= VM_READ | VM_MAYREAD;
52903+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
52904+ retval = IS_ERR_VALUE(start) ? start : 0;
52905+ }
52906+ up_write(&current->mm->mmap_sem);
52907+ if (retval == 0)
52908+ retval = set_brk(start + size, start + size + PAGE_SIZE);
52909+ if (retval < 0) {
52910+ send_sig(SIGKILL, current, 0);
52911+ goto out_free_dentry;
52912+ }
52913+ }
52914+#endif
52915+
52916 if (elf_interpreter) {
52917- unsigned long interp_map_addr = 0;
52918-
52919 elf_entry = load_elf_interp(&loc->interp_elf_ex,
52920 interpreter,
52921- &interp_map_addr,
52922 load_bias);
52923 if (!IS_ERR((void *)elf_entry)) {
52924 /*
52925@@ -1122,7 +1579,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
52926 * Decide what to dump of a segment, part, all or none.
52927 */
52928 static unsigned long vma_dump_size(struct vm_area_struct *vma,
52929- unsigned long mm_flags)
52930+ unsigned long mm_flags, long signr)
52931 {
52932 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
52933
52934@@ -1160,7 +1617,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
52935 if (vma->vm_file == NULL)
52936 return 0;
52937
52938- if (FILTER(MAPPED_PRIVATE))
52939+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
52940 goto whole;
52941
52942 /*
52943@@ -1385,9 +1842,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
52944 {
52945 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
52946 int i = 0;
52947- do
52948+ do {
52949 i += 2;
52950- while (auxv[i - 2] != AT_NULL);
52951+ } while (auxv[i - 2] != AT_NULL);
52952 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
52953 }
52954
52955@@ -1396,7 +1853,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
52956 {
52957 mm_segment_t old_fs = get_fs();
52958 set_fs(KERNEL_DS);
52959- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
52960+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
52961 set_fs(old_fs);
52962 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
52963 }
52964@@ -2023,14 +2480,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
52965 }
52966
52967 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
52968- unsigned long mm_flags)
52969+ struct coredump_params *cprm)
52970 {
52971 struct vm_area_struct *vma;
52972 size_t size = 0;
52973
52974 for (vma = first_vma(current, gate_vma); vma != NULL;
52975 vma = next_vma(vma, gate_vma))
52976- size += vma_dump_size(vma, mm_flags);
52977+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
52978 return size;
52979 }
52980
52981@@ -2123,7 +2580,7 @@ static int elf_core_dump(struct coredump_params *cprm)
52982
52983 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
52984
52985- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
52986+ offset += elf_core_vma_data_size(gate_vma, cprm);
52987 offset += elf_core_extra_data_size();
52988 e_shoff = offset;
52989
52990@@ -2137,10 +2594,12 @@ static int elf_core_dump(struct coredump_params *cprm)
52991 offset = dataoff;
52992
52993 size += sizeof(*elf);
52994+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
52995 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
52996 goto end_coredump;
52997
52998 size += sizeof(*phdr4note);
52999+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
53000 if (size > cprm->limit
53001 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
53002 goto end_coredump;
53003@@ -2154,7 +2613,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53004 phdr.p_offset = offset;
53005 phdr.p_vaddr = vma->vm_start;
53006 phdr.p_paddr = 0;
53007- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
53008+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
53009 phdr.p_memsz = vma->vm_end - vma->vm_start;
53010 offset += phdr.p_filesz;
53011 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
53012@@ -2165,6 +2624,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53013 phdr.p_align = ELF_EXEC_PAGESIZE;
53014
53015 size += sizeof(phdr);
53016+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
53017 if (size > cprm->limit
53018 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
53019 goto end_coredump;
53020@@ -2189,7 +2649,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53021 unsigned long addr;
53022 unsigned long end;
53023
53024- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
53025+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
53026
53027 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
53028 struct page *page;
53029@@ -2198,6 +2658,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53030 page = get_dump_page(addr);
53031 if (page) {
53032 void *kaddr = kmap(page);
53033+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
53034 stop = ((size += PAGE_SIZE) > cprm->limit) ||
53035 !dump_write(cprm->file, kaddr,
53036 PAGE_SIZE);
53037@@ -2215,6 +2676,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53038
53039 if (e_phnum == PN_XNUM) {
53040 size += sizeof(*shdr4extnum);
53041+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
53042 if (size > cprm->limit
53043 || !dump_write(cprm->file, shdr4extnum,
53044 sizeof(*shdr4extnum)))
53045@@ -2235,6 +2697,167 @@ out:
53046
53047 #endif /* CONFIG_ELF_CORE */
53048
53049+#ifdef CONFIG_PAX_MPROTECT
53050+/* PaX: non-PIC ELF libraries need relocations on their executable segments
53051+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
53052+ * we'll remove VM_MAYWRITE for good on RELRO segments.
53053+ *
53054+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
53055+ * basis because we want to allow the common case and not the special ones.
53056+ */
53057+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
53058+{
53059+ struct elfhdr elf_h;
53060+ struct elf_phdr elf_p;
53061+ unsigned long i;
53062+ unsigned long oldflags;
53063+ bool is_textrel_rw, is_textrel_rx, is_relro;
53064+
53065+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
53066+ return;
53067+
53068+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
53069+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
53070+
53071+#ifdef CONFIG_PAX_ELFRELOCS
53072+ /* possible TEXTREL */
53073+ is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
53074+ is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
53075+#else
53076+ is_textrel_rw = false;
53077+ is_textrel_rx = false;
53078+#endif
53079+
53080+ /* possible RELRO */
53081+ is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
53082+
53083+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
53084+ return;
53085+
53086+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
53087+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
53088+
53089+#ifdef CONFIG_PAX_ETEXECRELOCS
53090+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
53091+#else
53092+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
53093+#endif
53094+
53095+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
53096+ !elf_check_arch(&elf_h) ||
53097+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
53098+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
53099+ return;
53100+
53101+ for (i = 0UL; i < elf_h.e_phnum; i++) {
53102+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
53103+ return;
53104+ switch (elf_p.p_type) {
53105+ case PT_DYNAMIC:
53106+ if (!is_textrel_rw && !is_textrel_rx)
53107+ continue;
53108+ i = 0UL;
53109+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
53110+ elf_dyn dyn;
53111+
53112+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
53113+ break;
53114+ if (dyn.d_tag == DT_NULL)
53115+ break;
53116+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
53117+ gr_log_textrel(vma);
53118+ if (is_textrel_rw)
53119+ vma->vm_flags |= VM_MAYWRITE;
53120+ else
53121+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
53122+ vma->vm_flags &= ~VM_MAYWRITE;
53123+ break;
53124+ }
53125+ i++;
53126+ }
53127+ is_textrel_rw = false;
53128+ is_textrel_rx = false;
53129+ continue;
53130+
53131+ case PT_GNU_RELRO:
53132+ if (!is_relro)
53133+ continue;
53134+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
53135+ vma->vm_flags &= ~VM_MAYWRITE;
53136+ is_relro = false;
53137+ continue;
53138+
53139+#ifdef CONFIG_PAX_PT_PAX_FLAGS
53140+ case PT_PAX_FLAGS: {
53141+ const char *msg_mprotect = "", *msg_emutramp = "";
53142+ char *buffer_lib, *buffer_exe;
53143+
53144+ if (elf_p.p_flags & PF_NOMPROTECT)
53145+ msg_mprotect = "MPROTECT disabled";
53146+
53147+#ifdef CONFIG_PAX_EMUTRAMP
53148+ if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
53149+ msg_emutramp = "EMUTRAMP enabled";
53150+#endif
53151+
53152+ if (!msg_mprotect[0] && !msg_emutramp[0])
53153+ continue;
53154+
53155+ if (!printk_ratelimit())
53156+ continue;
53157+
53158+ buffer_lib = (char *)__get_free_page(GFP_KERNEL);
53159+ buffer_exe = (char *)__get_free_page(GFP_KERNEL);
53160+ if (buffer_lib && buffer_exe) {
53161+ char *path_lib, *path_exe;
53162+
53163+ path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
53164+ path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
53165+
53166+ pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
53167+ (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
53168+
53169+ }
53170+ free_page((unsigned long)buffer_exe);
53171+ free_page((unsigned long)buffer_lib);
53172+ continue;
53173+ }
53174+#endif
53175+
53176+ }
53177+ }
53178+}
53179+#endif
53180+
53181+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
53182+
53183+extern int grsec_enable_log_rwxmaps;
53184+
53185+static void elf_handle_mmap(struct file *file)
53186+{
53187+ struct elfhdr elf_h;
53188+ struct elf_phdr elf_p;
53189+ unsigned long i;
53190+
53191+ if (!grsec_enable_log_rwxmaps)
53192+ return;
53193+
53194+ if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
53195+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
53196+ (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
53197+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
53198+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
53199+ return;
53200+
53201+ for (i = 0UL; i < elf_h.e_phnum; i++) {
53202+ if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
53203+ return;
53204+ if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
53205+ gr_log_ptgnustack(file);
53206+ }
53207+}
53208+#endif
53209+
53210 static int __init init_elf_binfmt(void)
53211 {
53212 register_binfmt(&elf_format);
53213diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
53214index d50bbe5..af3b649 100644
53215--- a/fs/binfmt_flat.c
53216+++ b/fs/binfmt_flat.c
53217@@ -566,7 +566,9 @@ static int load_flat_file(struct linux_binprm * bprm,
53218 realdatastart = (unsigned long) -ENOMEM;
53219 printk("Unable to allocate RAM for process data, errno %d\n",
53220 (int)-realdatastart);
53221+ down_write(&current->mm->mmap_sem);
53222 vm_munmap(textpos, text_len);
53223+ up_write(&current->mm->mmap_sem);
53224 ret = realdatastart;
53225 goto err;
53226 }
53227@@ -590,8 +592,10 @@ static int load_flat_file(struct linux_binprm * bprm,
53228 }
53229 if (IS_ERR_VALUE(result)) {
53230 printk("Unable to read data+bss, errno %d\n", (int)-result);
53231+ down_write(&current->mm->mmap_sem);
53232 vm_munmap(textpos, text_len);
53233 vm_munmap(realdatastart, len);
53234+ up_write(&current->mm->mmap_sem);
53235 ret = result;
53236 goto err;
53237 }
53238@@ -653,8 +657,10 @@ static int load_flat_file(struct linux_binprm * bprm,
53239 }
53240 if (IS_ERR_VALUE(result)) {
53241 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
53242+ down_write(&current->mm->mmap_sem);
53243 vm_munmap(textpos, text_len + data_len + extra +
53244 MAX_SHARED_LIBS * sizeof(unsigned long));
53245+ up_write(&current->mm->mmap_sem);
53246 ret = result;
53247 goto err;
53248 }
53249diff --git a/fs/bio.c b/fs/bio.c
53250index 5e7507d..418c639 100644
53251--- a/fs/bio.c
53252+++ b/fs/bio.c
53253@@ -1106,7 +1106,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
53254 /*
53255 * Overflow, abort
53256 */
53257- if (end < start)
53258+ if (end < start || end - start > INT_MAX - nr_pages)
53259 return ERR_PTR(-EINVAL);
53260
53261 nr_pages += end - start;
53262@@ -1240,7 +1240,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
53263 /*
53264 * Overflow, abort
53265 */
53266- if (end < start)
53267+ if (end < start || end - start > INT_MAX - nr_pages)
53268 return ERR_PTR(-EINVAL);
53269
53270 nr_pages += end - start;
53271@@ -1502,7 +1502,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
53272 const int read = bio_data_dir(bio) == READ;
53273 struct bio_map_data *bmd = bio->bi_private;
53274 int i;
53275- char *p = bmd->sgvecs[0].iov_base;
53276+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
53277
53278 bio_for_each_segment_all(bvec, bio, i) {
53279 char *addr = page_address(bvec->bv_page);
53280diff --git a/fs/block_dev.c b/fs/block_dev.c
53281index c7bda5c..2121e94 100644
53282--- a/fs/block_dev.c
53283+++ b/fs/block_dev.c
53284@@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
53285 else if (bdev->bd_contains == bdev)
53286 return true; /* is a whole device which isn't held */
53287
53288- else if (whole->bd_holder == bd_may_claim)
53289+ else if (whole->bd_holder == (void *)bd_may_claim)
53290 return true; /* is a partition of a device that is being partitioned */
53291 else if (whole->bd_holder != NULL)
53292 return false; /* is a partition of a held device */
53293diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
53294index ed50460..fe84385 100644
53295--- a/fs/btrfs/ctree.c
53296+++ b/fs/btrfs/ctree.c
53297@@ -1076,9 +1076,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
53298 free_extent_buffer(buf);
53299 add_root_to_dirty_list(root);
53300 } else {
53301- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
53302- parent_start = parent->start;
53303- else
53304+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
53305+ if (parent)
53306+ parent_start = parent->start;
53307+ else
53308+ parent_start = 0;
53309+ } else
53310 parent_start = 0;
53311
53312 WARN_ON(trans->transid != btrfs_header_generation(parent));
53313diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
53314index 3755109..e3d457f 100644
53315--- a/fs/btrfs/delayed-inode.c
53316+++ b/fs/btrfs/delayed-inode.c
53317@@ -458,7 +458,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
53318
53319 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
53320 {
53321- int seq = atomic_inc_return(&delayed_root->items_seq);
53322+ int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
53323 if ((atomic_dec_return(&delayed_root->items) <
53324 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
53325 waitqueue_active(&delayed_root->wait))
53326@@ -1377,7 +1377,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
53327 static int refs_newer(struct btrfs_delayed_root *delayed_root,
53328 int seq, int count)
53329 {
53330- int val = atomic_read(&delayed_root->items_seq);
53331+ int val = atomic_read_unchecked(&delayed_root->items_seq);
53332
53333 if (val < seq || val >= seq + count)
53334 return 1;
53335@@ -1394,7 +1394,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
53336 if (atomic_read(&delayed_root->items) < BTRFS_DELAYED_BACKGROUND)
53337 return;
53338
53339- seq = atomic_read(&delayed_root->items_seq);
53340+ seq = atomic_read_unchecked(&delayed_root->items_seq);
53341
53342 if (atomic_read(&delayed_root->items) >= BTRFS_DELAYED_WRITEBACK) {
53343 int ret;
53344diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
53345index a4b38f9..f86a509 100644
53346--- a/fs/btrfs/delayed-inode.h
53347+++ b/fs/btrfs/delayed-inode.h
53348@@ -43,7 +43,7 @@ struct btrfs_delayed_root {
53349 */
53350 struct list_head prepare_list;
53351 atomic_t items; /* for delayed items */
53352- atomic_t items_seq; /* for delayed items */
53353+ atomic_unchecked_t items_seq; /* for delayed items */
53354 int nodes; /* for delayed nodes */
53355 wait_queue_head_t wait;
53356 };
53357@@ -87,7 +87,7 @@ static inline void btrfs_init_delayed_root(
53358 struct btrfs_delayed_root *delayed_root)
53359 {
53360 atomic_set(&delayed_root->items, 0);
53361- atomic_set(&delayed_root->items_seq, 0);
53362+ atomic_set_unchecked(&delayed_root->items_seq, 0);
53363 delayed_root->nodes = 0;
53364 spin_lock_init(&delayed_root->lock);
53365 init_waitqueue_head(&delayed_root->wait);
53366diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
53367index 9877a2a..7ebf9ab 100644
53368--- a/fs/btrfs/ioctl.c
53369+++ b/fs/btrfs/ioctl.c
53370@@ -3097,9 +3097,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
53371 for (i = 0; i < num_types; i++) {
53372 struct btrfs_space_info *tmp;
53373
53374+ /* Don't copy in more than we allocated */
53375 if (!slot_count)
53376 break;
53377
53378+ slot_count--;
53379+
53380 info = NULL;
53381 rcu_read_lock();
53382 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
53383@@ -3121,10 +3124,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
53384 memcpy(dest, &space, sizeof(space));
53385 dest++;
53386 space_args.total_spaces++;
53387- slot_count--;
53388 }
53389- if (!slot_count)
53390- break;
53391 }
53392 up_read(&info->groups_sem);
53393 }
53394diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
53395index 8eb6191..eda91e2 100644
53396--- a/fs/btrfs/super.c
53397+++ b/fs/btrfs/super.c
53398@@ -264,7 +264,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
53399 function, line, errstr);
53400 return;
53401 }
53402- ACCESS_ONCE(trans->transaction->aborted) = errno;
53403+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
53404 /* Wake up anybody who may be waiting on this transaction */
53405 wake_up(&root->fs_info->transaction_wait);
53406 wake_up(&root->fs_info->transaction_blocked_wait);
53407diff --git a/fs/buffer.c b/fs/buffer.c
53408index 4d74335..7bd000a 100644
53409--- a/fs/buffer.c
53410+++ b/fs/buffer.c
53411@@ -1005,9 +1005,19 @@ grow_dev_page(struct block_device *bdev, sector_t block,
53412 struct buffer_head *bh;
53413 sector_t end_block;
53414 int ret = 0; /* Will call free_more_memory() */
53415+ gfp_t gfp_mask;
53416
53417- page = find_or_create_page(inode->i_mapping, index,
53418- (mapping_gfp_mask(inode->i_mapping) & ~__GFP_FS)|__GFP_MOVABLE);
53419+ gfp_mask = mapping_gfp_mask(inode->i_mapping) & ~__GFP_FS;
53420+ gfp_mask |= __GFP_MOVABLE;
53421+ /*
53422+ * XXX: __getblk_slow() can not really deal with failure and
53423+ * will endlessly loop on improvised global reclaim. Prefer
53424+ * looping in the allocator rather than here, at least that
53425+ * code knows what it's doing.
53426+ */
53427+ gfp_mask |= __GFP_NOFAIL;
53428+
53429+ page = find_or_create_page(inode->i_mapping, index, gfp_mask);
53430 if (!page)
53431 return ret;
53432
53433@@ -3416,7 +3426,7 @@ void __init buffer_init(void)
53434 bh_cachep = kmem_cache_create("buffer_head",
53435 sizeof(struct buffer_head), 0,
53436 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
53437- SLAB_MEM_SPREAD),
53438+ SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
53439 NULL);
53440
53441 /*
53442diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
53443index 622f469..e8d2d55 100644
53444--- a/fs/cachefiles/bind.c
53445+++ b/fs/cachefiles/bind.c
53446@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
53447 args);
53448
53449 /* start by checking things over */
53450- ASSERT(cache->fstop_percent >= 0 &&
53451- cache->fstop_percent < cache->fcull_percent &&
53452+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
53453 cache->fcull_percent < cache->frun_percent &&
53454 cache->frun_percent < 100);
53455
53456- ASSERT(cache->bstop_percent >= 0 &&
53457- cache->bstop_percent < cache->bcull_percent &&
53458+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
53459 cache->bcull_percent < cache->brun_percent &&
53460 cache->brun_percent < 100);
53461
53462diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
53463index 0a1467b..6a53245 100644
53464--- a/fs/cachefiles/daemon.c
53465+++ b/fs/cachefiles/daemon.c
53466@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
53467 if (n > buflen)
53468 return -EMSGSIZE;
53469
53470- if (copy_to_user(_buffer, buffer, n) != 0)
53471+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
53472 return -EFAULT;
53473
53474 return n;
53475@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
53476 if (test_bit(CACHEFILES_DEAD, &cache->flags))
53477 return -EIO;
53478
53479- if (datalen < 0 || datalen > PAGE_SIZE - 1)
53480+ if (datalen > PAGE_SIZE - 1)
53481 return -EOPNOTSUPP;
53482
53483 /* drag the command string into the kernel so we can parse it */
53484@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
53485 if (args[0] != '%' || args[1] != '\0')
53486 return -EINVAL;
53487
53488- if (fstop < 0 || fstop >= cache->fcull_percent)
53489+ if (fstop >= cache->fcull_percent)
53490 return cachefiles_daemon_range_error(cache, args);
53491
53492 cache->fstop_percent = fstop;
53493@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
53494 if (args[0] != '%' || args[1] != '\0')
53495 return -EINVAL;
53496
53497- if (bstop < 0 || bstop >= cache->bcull_percent)
53498+ if (bstop >= cache->bcull_percent)
53499 return cachefiles_daemon_range_error(cache, args);
53500
53501 cache->bstop_percent = bstop;
53502diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
53503index 4938251..7e01445 100644
53504--- a/fs/cachefiles/internal.h
53505+++ b/fs/cachefiles/internal.h
53506@@ -59,7 +59,7 @@ struct cachefiles_cache {
53507 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
53508 struct rb_root active_nodes; /* active nodes (can't be culled) */
53509 rwlock_t active_lock; /* lock for active_nodes */
53510- atomic_t gravecounter; /* graveyard uniquifier */
53511+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
53512 unsigned frun_percent; /* when to stop culling (% files) */
53513 unsigned fcull_percent; /* when to start culling (% files) */
53514 unsigned fstop_percent; /* when to stop allocating (% files) */
53515@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
53516 * proc.c
53517 */
53518 #ifdef CONFIG_CACHEFILES_HISTOGRAM
53519-extern atomic_t cachefiles_lookup_histogram[HZ];
53520-extern atomic_t cachefiles_mkdir_histogram[HZ];
53521-extern atomic_t cachefiles_create_histogram[HZ];
53522+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
53523+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
53524+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
53525
53526 extern int __init cachefiles_proc_init(void);
53527 extern void cachefiles_proc_cleanup(void);
53528 static inline
53529-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
53530+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
53531 {
53532 unsigned long jif = jiffies - start_jif;
53533 if (jif >= HZ)
53534 jif = HZ - 1;
53535- atomic_inc(&histogram[jif]);
53536+ atomic_inc_unchecked(&histogram[jif]);
53537 }
53538
53539 #else
53540diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
53541index 25badd1..d70d918 100644
53542--- a/fs/cachefiles/namei.c
53543+++ b/fs/cachefiles/namei.c
53544@@ -317,7 +317,7 @@ try_again:
53545 /* first step is to make up a grave dentry in the graveyard */
53546 sprintf(nbuffer, "%08x%08x",
53547 (uint32_t) get_seconds(),
53548- (uint32_t) atomic_inc_return(&cache->gravecounter));
53549+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
53550
53551 /* do the multiway lock magic */
53552 trap = lock_rename(cache->graveyard, dir);
53553diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
53554index eccd339..4c1d995 100644
53555--- a/fs/cachefiles/proc.c
53556+++ b/fs/cachefiles/proc.c
53557@@ -14,9 +14,9 @@
53558 #include <linux/seq_file.h>
53559 #include "internal.h"
53560
53561-atomic_t cachefiles_lookup_histogram[HZ];
53562-atomic_t cachefiles_mkdir_histogram[HZ];
53563-atomic_t cachefiles_create_histogram[HZ];
53564+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
53565+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
53566+atomic_unchecked_t cachefiles_create_histogram[HZ];
53567
53568 /*
53569 * display the latency histogram
53570@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
53571 return 0;
53572 default:
53573 index = (unsigned long) v - 3;
53574- x = atomic_read(&cachefiles_lookup_histogram[index]);
53575- y = atomic_read(&cachefiles_mkdir_histogram[index]);
53576- z = atomic_read(&cachefiles_create_histogram[index]);
53577+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
53578+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
53579+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
53580 if (x == 0 && y == 0 && z == 0)
53581 return 0;
53582
53583diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
53584index ebaff36..7e3ea26 100644
53585--- a/fs/cachefiles/rdwr.c
53586+++ b/fs/cachefiles/rdwr.c
53587@@ -950,7 +950,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
53588 old_fs = get_fs();
53589 set_fs(KERNEL_DS);
53590 ret = file->f_op->write(
53591- file, (const void __user *) data, len, &pos);
53592+ file, (const void __force_user *) data, len, &pos);
53593 set_fs(old_fs);
53594 kunmap(page);
53595 file_end_write(file);
53596diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
53597index a40ceda..f43d17c 100644
53598--- a/fs/ceph/dir.c
53599+++ b/fs/ceph/dir.c
53600@@ -240,7 +240,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
53601 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
53602 struct ceph_mds_client *mdsc = fsc->mdsc;
53603 unsigned frag = fpos_frag(ctx->pos);
53604- int off = fpos_off(ctx->pos);
53605+ unsigned int off = fpos_off(ctx->pos);
53606 int err;
53607 u32 ftype;
53608 struct ceph_mds_reply_info_parsed *rinfo;
53609diff --git a/fs/ceph/super.c b/fs/ceph/super.c
53610index 6627b26..634ec4b 100644
53611--- a/fs/ceph/super.c
53612+++ b/fs/ceph/super.c
53613@@ -839,7 +839,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
53614 /*
53615 * construct our own bdi so we can control readahead, etc.
53616 */
53617-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
53618+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
53619
53620 static int ceph_register_bdi(struct super_block *sb,
53621 struct ceph_fs_client *fsc)
53622@@ -856,7 +856,7 @@ static int ceph_register_bdi(struct super_block *sb,
53623 default_backing_dev_info.ra_pages;
53624
53625 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
53626- atomic_long_inc_return(&bdi_seq));
53627+ atomic_long_inc_return_unchecked(&bdi_seq));
53628 if (!err)
53629 sb->s_bdi = &fsc->backing_dev_info;
53630 return err;
53631diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
53632index f3ac415..3d2420c 100644
53633--- a/fs/cifs/cifs_debug.c
53634+++ b/fs/cifs/cifs_debug.c
53635@@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
53636
53637 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
53638 #ifdef CONFIG_CIFS_STATS2
53639- atomic_set(&totBufAllocCount, 0);
53640- atomic_set(&totSmBufAllocCount, 0);
53641+ atomic_set_unchecked(&totBufAllocCount, 0);
53642+ atomic_set_unchecked(&totSmBufAllocCount, 0);
53643 #endif /* CONFIG_CIFS_STATS2 */
53644 spin_lock(&cifs_tcp_ses_lock);
53645 list_for_each(tmp1, &cifs_tcp_ses_list) {
53646@@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
53647 tcon = list_entry(tmp3,
53648 struct cifs_tcon,
53649 tcon_list);
53650- atomic_set(&tcon->num_smbs_sent, 0);
53651+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
53652 if (server->ops->clear_stats)
53653 server->ops->clear_stats(tcon);
53654 }
53655@@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
53656 smBufAllocCount.counter, cifs_min_small);
53657 #ifdef CONFIG_CIFS_STATS2
53658 seq_printf(m, "Total Large %d Small %d Allocations\n",
53659- atomic_read(&totBufAllocCount),
53660- atomic_read(&totSmBufAllocCount));
53661+ atomic_read_unchecked(&totBufAllocCount),
53662+ atomic_read_unchecked(&totSmBufAllocCount));
53663 #endif /* CONFIG_CIFS_STATS2 */
53664
53665 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
53666@@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
53667 if (tcon->need_reconnect)
53668 seq_puts(m, "\tDISCONNECTED ");
53669 seq_printf(m, "\nSMBs: %d",
53670- atomic_read(&tcon->num_smbs_sent));
53671+ atomic_read_unchecked(&tcon->num_smbs_sent));
53672 if (server->ops->print_stats)
53673 server->ops->print_stats(m, tcon);
53674 }
53675diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
53676index 85ea98d..1eee040 100644
53677--- a/fs/cifs/cifsfs.c
53678+++ b/fs/cifs/cifsfs.c
53679@@ -120,14 +120,16 @@ cifs_read_super(struct super_block *sb)
53680 {
53681 struct inode *inode;
53682 struct cifs_sb_info *cifs_sb;
53683+ struct cifs_tcon *tcon;
53684 int rc = 0;
53685
53686 cifs_sb = CIFS_SB(sb);
53687+ tcon = cifs_sb_master_tcon(cifs_sb);
53688
53689 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIXACL)
53690 sb->s_flags |= MS_POSIXACL;
53691
53692- if (cifs_sb_master_tcon(cifs_sb)->ses->capabilities & CAP_LARGE_FILES)
53693+ if (tcon->ses->capabilities & tcon->ses->server->vals->cap_large_files)
53694 sb->s_maxbytes = MAX_LFS_FILESIZE;
53695 else
53696 sb->s_maxbytes = MAX_NON_LFS;
53697@@ -147,7 +149,7 @@ cifs_read_super(struct super_block *sb)
53698 goto out_no_root;
53699 }
53700
53701- if (cifs_sb_master_tcon(cifs_sb)->nocase)
53702+ if (tcon->nocase)
53703 sb->s_d_op = &cifs_ci_dentry_ops;
53704 else
53705 sb->s_d_op = &cifs_dentry_ops;
53706@@ -1037,7 +1039,7 @@ cifs_init_request_bufs(void)
53707 */
53708 cifs_req_cachep = kmem_cache_create("cifs_request",
53709 CIFSMaxBufSize + max_hdr_size, 0,
53710- SLAB_HWCACHE_ALIGN, NULL);
53711+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
53712 if (cifs_req_cachep == NULL)
53713 return -ENOMEM;
53714
53715@@ -1064,7 +1066,7 @@ cifs_init_request_bufs(void)
53716 efficient to alloc 1 per page off the slab compared to 17K (5page)
53717 alloc of large cifs buffers even when page debugging is on */
53718 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
53719- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
53720+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
53721 NULL);
53722 if (cifs_sm_req_cachep == NULL) {
53723 mempool_destroy(cifs_req_poolp);
53724@@ -1149,8 +1151,8 @@ init_cifs(void)
53725 atomic_set(&bufAllocCount, 0);
53726 atomic_set(&smBufAllocCount, 0);
53727 #ifdef CONFIG_CIFS_STATS2
53728- atomic_set(&totBufAllocCount, 0);
53729- atomic_set(&totSmBufAllocCount, 0);
53730+ atomic_set_unchecked(&totBufAllocCount, 0);
53731+ atomic_set_unchecked(&totSmBufAllocCount, 0);
53732 #endif /* CONFIG_CIFS_STATS2 */
53733
53734 atomic_set(&midCount, 0);
53735diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
53736index 52ca861..47f309c 100644
53737--- a/fs/cifs/cifsglob.h
53738+++ b/fs/cifs/cifsglob.h
53739@@ -756,35 +756,35 @@ struct cifs_tcon {
53740 __u16 Flags; /* optional support bits */
53741 enum statusEnum tidStatus;
53742 #ifdef CONFIG_CIFS_STATS
53743- atomic_t num_smbs_sent;
53744+ atomic_unchecked_t num_smbs_sent;
53745 union {
53746 struct {
53747- atomic_t num_writes;
53748- atomic_t num_reads;
53749- atomic_t num_flushes;
53750- atomic_t num_oplock_brks;
53751- atomic_t num_opens;
53752- atomic_t num_closes;
53753- atomic_t num_deletes;
53754- atomic_t num_mkdirs;
53755- atomic_t num_posixopens;
53756- atomic_t num_posixmkdirs;
53757- atomic_t num_rmdirs;
53758- atomic_t num_renames;
53759- atomic_t num_t2renames;
53760- atomic_t num_ffirst;
53761- atomic_t num_fnext;
53762- atomic_t num_fclose;
53763- atomic_t num_hardlinks;
53764- atomic_t num_symlinks;
53765- atomic_t num_locks;
53766- atomic_t num_acl_get;
53767- atomic_t num_acl_set;
53768+ atomic_unchecked_t num_writes;
53769+ atomic_unchecked_t num_reads;
53770+ atomic_unchecked_t num_flushes;
53771+ atomic_unchecked_t num_oplock_brks;
53772+ atomic_unchecked_t num_opens;
53773+ atomic_unchecked_t num_closes;
53774+ atomic_unchecked_t num_deletes;
53775+ atomic_unchecked_t num_mkdirs;
53776+ atomic_unchecked_t num_posixopens;
53777+ atomic_unchecked_t num_posixmkdirs;
53778+ atomic_unchecked_t num_rmdirs;
53779+ atomic_unchecked_t num_renames;
53780+ atomic_unchecked_t num_t2renames;
53781+ atomic_unchecked_t num_ffirst;
53782+ atomic_unchecked_t num_fnext;
53783+ atomic_unchecked_t num_fclose;
53784+ atomic_unchecked_t num_hardlinks;
53785+ atomic_unchecked_t num_symlinks;
53786+ atomic_unchecked_t num_locks;
53787+ atomic_unchecked_t num_acl_get;
53788+ atomic_unchecked_t num_acl_set;
53789 } cifs_stats;
53790 #ifdef CONFIG_CIFS_SMB2
53791 struct {
53792- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
53793- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
53794+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
53795+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
53796 } smb2_stats;
53797 #endif /* CONFIG_CIFS_SMB2 */
53798 } stats;
53799@@ -1096,7 +1096,7 @@ convert_delimiter(char *path, char delim)
53800 }
53801
53802 #ifdef CONFIG_CIFS_STATS
53803-#define cifs_stats_inc atomic_inc
53804+#define cifs_stats_inc atomic_inc_unchecked
53805
53806 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
53807 unsigned int bytes)
53808@@ -1461,8 +1461,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
53809 /* Various Debug counters */
53810 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
53811 #ifdef CONFIG_CIFS_STATS2
53812-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
53813-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
53814+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
53815+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
53816 #endif
53817 GLOBAL_EXTERN atomic_t smBufAllocCount;
53818 GLOBAL_EXTERN atomic_t midCount;
53819diff --git a/fs/cifs/link.c b/fs/cifs/link.c
53820index 562044f..4af6a17 100644
53821--- a/fs/cifs/link.c
53822+++ b/fs/cifs/link.c
53823@@ -638,7 +638,7 @@ symlink_exit:
53824
53825 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
53826 {
53827- char *p = nd_get_link(nd);
53828+ const char *p = nd_get_link(nd);
53829 if (!IS_ERR(p))
53830 kfree(p);
53831 }
53832diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
53833index f7d4b22..1254377 100644
53834--- a/fs/cifs/misc.c
53835+++ b/fs/cifs/misc.c
53836@@ -169,7 +169,7 @@ cifs_buf_get(void)
53837 memset(ret_buf, 0, buf_size + 3);
53838 atomic_inc(&bufAllocCount);
53839 #ifdef CONFIG_CIFS_STATS2
53840- atomic_inc(&totBufAllocCount);
53841+ atomic_inc_unchecked(&totBufAllocCount);
53842 #endif /* CONFIG_CIFS_STATS2 */
53843 }
53844
53845@@ -204,7 +204,7 @@ cifs_small_buf_get(void)
53846 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
53847 atomic_inc(&smBufAllocCount);
53848 #ifdef CONFIG_CIFS_STATS2
53849- atomic_inc(&totSmBufAllocCount);
53850+ atomic_inc_unchecked(&totSmBufAllocCount);
53851 #endif /* CONFIG_CIFS_STATS2 */
53852
53853 }
53854diff --git a/fs/cifs/netmisc.c b/fs/cifs/netmisc.c
53855index af847e1..651a527 100644
53856--- a/fs/cifs/netmisc.c
53857+++ b/fs/cifs/netmisc.c
53858@@ -780,7 +780,9 @@ static const struct {
53859 ERRDOS, ERRnoaccess, 0xc0000290}, {
53860 ERRDOS, ERRbadfunc, 0xc000029c}, {
53861 ERRDOS, ERRsymlink, NT_STATUS_STOPPED_ON_SYMLINK}, {
53862- ERRDOS, ERRinvlevel, 0x007c0001}, };
53863+ ERRDOS, ERRinvlevel, 0x007c0001}, {
53864+ 0, 0, 0 }
53865+};
53866
53867 /*****************************************************************************
53868 Print an error message from the status code
53869diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
53870index 6094397..51e576f 100644
53871--- a/fs/cifs/smb1ops.c
53872+++ b/fs/cifs/smb1ops.c
53873@@ -590,27 +590,27 @@ static void
53874 cifs_clear_stats(struct cifs_tcon *tcon)
53875 {
53876 #ifdef CONFIG_CIFS_STATS
53877- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
53878- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
53879- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
53880- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
53881- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
53882- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
53883- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
53884- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
53885- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
53886- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
53887- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
53888- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
53889- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
53890- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
53891- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
53892- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
53893- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
53894- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
53895- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
53896- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
53897- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
53898+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
53899+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
53900+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
53901+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
53902+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
53903+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
53904+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
53905+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
53906+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
53907+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
53908+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
53909+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
53910+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
53911+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
53912+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
53913+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
53914+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
53915+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
53916+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
53917+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
53918+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
53919 #endif
53920 }
53921
53922@@ -619,36 +619,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
53923 {
53924 #ifdef CONFIG_CIFS_STATS
53925 seq_printf(m, " Oplocks breaks: %d",
53926- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
53927+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
53928 seq_printf(m, "\nReads: %d Bytes: %llu",
53929- atomic_read(&tcon->stats.cifs_stats.num_reads),
53930+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
53931 (long long)(tcon->bytes_read));
53932 seq_printf(m, "\nWrites: %d Bytes: %llu",
53933- atomic_read(&tcon->stats.cifs_stats.num_writes),
53934+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
53935 (long long)(tcon->bytes_written));
53936 seq_printf(m, "\nFlushes: %d",
53937- atomic_read(&tcon->stats.cifs_stats.num_flushes));
53938+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
53939 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
53940- atomic_read(&tcon->stats.cifs_stats.num_locks),
53941- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
53942- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
53943+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
53944+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
53945+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
53946 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
53947- atomic_read(&tcon->stats.cifs_stats.num_opens),
53948- atomic_read(&tcon->stats.cifs_stats.num_closes),
53949- atomic_read(&tcon->stats.cifs_stats.num_deletes));
53950+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
53951+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
53952+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
53953 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
53954- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
53955- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
53956+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
53957+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
53958 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
53959- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
53960- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
53961+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
53962+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
53963 seq_printf(m, "\nRenames: %d T2 Renames %d",
53964- atomic_read(&tcon->stats.cifs_stats.num_renames),
53965- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
53966+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
53967+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
53968 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
53969- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
53970- atomic_read(&tcon->stats.cifs_stats.num_fnext),
53971- atomic_read(&tcon->stats.cifs_stats.num_fclose));
53972+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
53973+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
53974+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
53975 #endif
53976 }
53977
53978diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
53979index f259e6c..ca948ff 100644
53980--- a/fs/cifs/smb2ops.c
53981+++ b/fs/cifs/smb2ops.c
53982@@ -281,8 +281,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
53983 #ifdef CONFIG_CIFS_STATS
53984 int i;
53985 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
53986- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
53987- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
53988+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
53989+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
53990 }
53991 #endif
53992 }
53993@@ -310,65 +310,65 @@ static void
53994 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
53995 {
53996 #ifdef CONFIG_CIFS_STATS
53997- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
53998- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
53999+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
54000+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
54001 seq_printf(m, "\nNegotiates: %d sent %d failed",
54002- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
54003- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
54004+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
54005+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
54006 seq_printf(m, "\nSessionSetups: %d sent %d failed",
54007- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
54008- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
54009+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
54010+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
54011 seq_printf(m, "\nLogoffs: %d sent %d failed",
54012- atomic_read(&sent[SMB2_LOGOFF_HE]),
54013- atomic_read(&failed[SMB2_LOGOFF_HE]));
54014+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
54015+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
54016 seq_printf(m, "\nTreeConnects: %d sent %d failed",
54017- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
54018- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
54019+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
54020+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
54021 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
54022- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
54023- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
54024+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
54025+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
54026 seq_printf(m, "\nCreates: %d sent %d failed",
54027- atomic_read(&sent[SMB2_CREATE_HE]),
54028- atomic_read(&failed[SMB2_CREATE_HE]));
54029+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
54030+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
54031 seq_printf(m, "\nCloses: %d sent %d failed",
54032- atomic_read(&sent[SMB2_CLOSE_HE]),
54033- atomic_read(&failed[SMB2_CLOSE_HE]));
54034+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
54035+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
54036 seq_printf(m, "\nFlushes: %d sent %d failed",
54037- atomic_read(&sent[SMB2_FLUSH_HE]),
54038- atomic_read(&failed[SMB2_FLUSH_HE]));
54039+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
54040+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
54041 seq_printf(m, "\nReads: %d sent %d failed",
54042- atomic_read(&sent[SMB2_READ_HE]),
54043- atomic_read(&failed[SMB2_READ_HE]));
54044+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
54045+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
54046 seq_printf(m, "\nWrites: %d sent %d failed",
54047- atomic_read(&sent[SMB2_WRITE_HE]),
54048- atomic_read(&failed[SMB2_WRITE_HE]));
54049+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
54050+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
54051 seq_printf(m, "\nLocks: %d sent %d failed",
54052- atomic_read(&sent[SMB2_LOCK_HE]),
54053- atomic_read(&failed[SMB2_LOCK_HE]));
54054+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
54055+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
54056 seq_printf(m, "\nIOCTLs: %d sent %d failed",
54057- atomic_read(&sent[SMB2_IOCTL_HE]),
54058- atomic_read(&failed[SMB2_IOCTL_HE]));
54059+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
54060+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
54061 seq_printf(m, "\nCancels: %d sent %d failed",
54062- atomic_read(&sent[SMB2_CANCEL_HE]),
54063- atomic_read(&failed[SMB2_CANCEL_HE]));
54064+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
54065+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
54066 seq_printf(m, "\nEchos: %d sent %d failed",
54067- atomic_read(&sent[SMB2_ECHO_HE]),
54068- atomic_read(&failed[SMB2_ECHO_HE]));
54069+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
54070+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
54071 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
54072- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
54073- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
54074+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
54075+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
54076 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
54077- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
54078- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
54079+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
54080+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
54081 seq_printf(m, "\nQueryInfos: %d sent %d failed",
54082- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
54083- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
54084+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
54085+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
54086 seq_printf(m, "\nSetInfos: %d sent %d failed",
54087- atomic_read(&sent[SMB2_SET_INFO_HE]),
54088- atomic_read(&failed[SMB2_SET_INFO_HE]));
54089+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
54090+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
54091 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
54092- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
54093- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
54094+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
54095+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
54096 #endif
54097 }
54098
54099diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
54100index abc9c28..3fdae28 100644
54101--- a/fs/cifs/smb2pdu.c
54102+++ b/fs/cifs/smb2pdu.c
54103@@ -1946,8 +1946,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
54104 default:
54105 cifs_dbg(VFS, "info level %u isn't supported\n",
54106 srch_inf->info_level);
54107- rc = -EINVAL;
54108- goto qdir_exit;
54109+ return -EINVAL;
54110 }
54111
54112 req->FileIndex = cpu_to_le32(index);
54113diff --git a/fs/coda/cache.c b/fs/coda/cache.c
54114index 1da168c..8bc7ff6 100644
54115--- a/fs/coda/cache.c
54116+++ b/fs/coda/cache.c
54117@@ -24,7 +24,7 @@
54118 #include "coda_linux.h"
54119 #include "coda_cache.h"
54120
54121-static atomic_t permission_epoch = ATOMIC_INIT(0);
54122+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
54123
54124 /* replace or extend an acl cache hit */
54125 void coda_cache_enter(struct inode *inode, int mask)
54126@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
54127 struct coda_inode_info *cii = ITOC(inode);
54128
54129 spin_lock(&cii->c_lock);
54130- cii->c_cached_epoch = atomic_read(&permission_epoch);
54131+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
54132 if (!uid_eq(cii->c_uid, current_fsuid())) {
54133 cii->c_uid = current_fsuid();
54134 cii->c_cached_perm = mask;
54135@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
54136 {
54137 struct coda_inode_info *cii = ITOC(inode);
54138 spin_lock(&cii->c_lock);
54139- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
54140+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
54141 spin_unlock(&cii->c_lock);
54142 }
54143
54144 /* remove all acl caches */
54145 void coda_cache_clear_all(struct super_block *sb)
54146 {
54147- atomic_inc(&permission_epoch);
54148+ atomic_inc_unchecked(&permission_epoch);
54149 }
54150
54151
54152@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
54153 spin_lock(&cii->c_lock);
54154 hit = (mask & cii->c_cached_perm) == mask &&
54155 uid_eq(cii->c_uid, current_fsuid()) &&
54156- cii->c_cached_epoch == atomic_read(&permission_epoch);
54157+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
54158 spin_unlock(&cii->c_lock);
54159
54160 return hit;
54161diff --git a/fs/compat.c b/fs/compat.c
54162index 6af20de..fec3fbb 100644
54163--- a/fs/compat.c
54164+++ b/fs/compat.c
54165@@ -54,7 +54,7 @@
54166 #include <asm/ioctls.h>
54167 #include "internal.h"
54168
54169-int compat_log = 1;
54170+int compat_log = 0;
54171
54172 int compat_printk(const char *fmt, ...)
54173 {
54174@@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
54175
54176 set_fs(KERNEL_DS);
54177 /* The __user pointer cast is valid because of the set_fs() */
54178- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
54179+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
54180 set_fs(oldfs);
54181 /* truncating is ok because it's a user address */
54182 if (!ret)
54183@@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
54184 goto out;
54185
54186 ret = -EINVAL;
54187- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
54188+ if (nr_segs > UIO_MAXIOV)
54189 goto out;
54190 if (nr_segs > fast_segs) {
54191 ret = -ENOMEM;
54192@@ -834,6 +834,7 @@ struct compat_old_linux_dirent {
54193 struct compat_readdir_callback {
54194 struct dir_context ctx;
54195 struct compat_old_linux_dirent __user *dirent;
54196+ struct file * file;
54197 int result;
54198 };
54199
54200@@ -851,6 +852,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
54201 buf->result = -EOVERFLOW;
54202 return -EOVERFLOW;
54203 }
54204+
54205+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
54206+ return 0;
54207+
54208 buf->result++;
54209 dirent = buf->dirent;
54210 if (!access_ok(VERIFY_WRITE, dirent,
54211@@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
54212 if (!f.file)
54213 return -EBADF;
54214
54215+ buf.file = f.file;
54216 error = iterate_dir(f.file, &buf.ctx);
54217 if (buf.result)
54218 error = buf.result;
54219@@ -901,6 +907,7 @@ struct compat_getdents_callback {
54220 struct dir_context ctx;
54221 struct compat_linux_dirent __user *current_dir;
54222 struct compat_linux_dirent __user *previous;
54223+ struct file * file;
54224 int count;
54225 int error;
54226 };
54227@@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
54228 buf->error = -EOVERFLOW;
54229 return -EOVERFLOW;
54230 }
54231+
54232+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
54233+ return 0;
54234+
54235 dirent = buf->previous;
54236 if (dirent) {
54237 if (__put_user(offset, &dirent->d_off))
54238@@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
54239 if (!f.file)
54240 return -EBADF;
54241
54242+ buf.file = f.file;
54243 error = iterate_dir(f.file, &buf.ctx);
54244 if (error >= 0)
54245 error = buf.error;
54246@@ -987,6 +999,7 @@ struct compat_getdents_callback64 {
54247 struct dir_context ctx;
54248 struct linux_dirent64 __user *current_dir;
54249 struct linux_dirent64 __user *previous;
54250+ struct file * file;
54251 int count;
54252 int error;
54253 };
54254@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
54255 buf->error = -EINVAL; /* only used if we fail.. */
54256 if (reclen > buf->count)
54257 return -EINVAL;
54258+
54259+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
54260+ return 0;
54261+
54262 dirent = buf->previous;
54263
54264 if (dirent) {
54265@@ -1052,6 +1069,7 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
54266 if (!f.file)
54267 return -EBADF;
54268
54269+ buf.file = f.file;
54270 error = iterate_dir(f.file, &buf.ctx);
54271 if (error >= 0)
54272 error = buf.error;
54273diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
54274index a81147e..20bf2b5 100644
54275--- a/fs/compat_binfmt_elf.c
54276+++ b/fs/compat_binfmt_elf.c
54277@@ -30,11 +30,13 @@
54278 #undef elf_phdr
54279 #undef elf_shdr
54280 #undef elf_note
54281+#undef elf_dyn
54282 #undef elf_addr_t
54283 #define elfhdr elf32_hdr
54284 #define elf_phdr elf32_phdr
54285 #define elf_shdr elf32_shdr
54286 #define elf_note elf32_note
54287+#define elf_dyn Elf32_Dyn
54288 #define elf_addr_t Elf32_Addr
54289
54290 /*
54291diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
54292index 5d19acf..9ab093b 100644
54293--- a/fs/compat_ioctl.c
54294+++ b/fs/compat_ioctl.c
54295@@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
54296 return -EFAULT;
54297 if (__get_user(udata, &ss32->iomem_base))
54298 return -EFAULT;
54299- ss.iomem_base = compat_ptr(udata);
54300+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
54301 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
54302 __get_user(ss.port_high, &ss32->port_high))
54303 return -EFAULT;
54304@@ -702,8 +702,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
54305 for (i = 0; i < nmsgs; i++) {
54306 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
54307 return -EFAULT;
54308- if (get_user(datap, &umsgs[i].buf) ||
54309- put_user(compat_ptr(datap), &tmsgs[i].buf))
54310+ if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
54311+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
54312 return -EFAULT;
54313 }
54314 return sys_ioctl(fd, cmd, (unsigned long)tdata);
54315@@ -796,7 +796,7 @@ static int compat_ioctl_preallocate(struct file *file,
54316 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
54317 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
54318 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
54319- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
54320+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
54321 return -EFAULT;
54322
54323 return ioctl_preallocate(file, p);
54324@@ -1616,8 +1616,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
54325 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
54326 {
54327 unsigned int a, b;
54328- a = *(unsigned int *)p;
54329- b = *(unsigned int *)q;
54330+ a = *(const unsigned int *)p;
54331+ b = *(const unsigned int *)q;
54332 if (a > b)
54333 return 1;
54334 if (a < b)
54335diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
54336index 277bd1b..f312c9e 100644
54337--- a/fs/configfs/dir.c
54338+++ b/fs/configfs/dir.c
54339@@ -1546,7 +1546,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
54340 }
54341 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
54342 struct configfs_dirent *next;
54343- const char *name;
54344+ const unsigned char * name;
54345+ char d_name[sizeof(next->s_dentry->d_iname)];
54346 int len;
54347 struct inode *inode = NULL;
54348
54349@@ -1555,7 +1556,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
54350 continue;
54351
54352 name = configfs_get_name(next);
54353- len = strlen(name);
54354+ if (next->s_dentry && name == next->s_dentry->d_iname) {
54355+ len = next->s_dentry->d_name.len;
54356+ memcpy(d_name, name, len);
54357+ name = d_name;
54358+ } else
54359+ len = strlen(name);
54360
54361 /*
54362 * We'll have a dentry and an inode for
54363diff --git a/fs/coredump.c b/fs/coredump.c
54364index 72f816d..1ba8eff 100644
54365--- a/fs/coredump.c
54366+++ b/fs/coredump.c
54367@@ -433,8 +433,8 @@ static void wait_for_dump_helpers(struct file *file)
54368 struct pipe_inode_info *pipe = file->private_data;
54369
54370 pipe_lock(pipe);
54371- pipe->readers++;
54372- pipe->writers--;
54373+ atomic_inc(&pipe->readers);
54374+ atomic_dec(&pipe->writers);
54375 wake_up_interruptible_sync(&pipe->wait);
54376 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
54377 pipe_unlock(pipe);
54378@@ -443,11 +443,11 @@ static void wait_for_dump_helpers(struct file *file)
54379 * We actually want wait_event_freezable() but then we need
54380 * to clear TIF_SIGPENDING and improve dump_interrupted().
54381 */
54382- wait_event_interruptible(pipe->wait, pipe->readers == 1);
54383+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
54384
54385 pipe_lock(pipe);
54386- pipe->readers--;
54387- pipe->writers++;
54388+ atomic_dec(&pipe->readers);
54389+ atomic_inc(&pipe->writers);
54390 pipe_unlock(pipe);
54391 }
54392
54393@@ -494,7 +494,8 @@ void do_coredump(siginfo_t *siginfo)
54394 struct files_struct *displaced;
54395 bool need_nonrelative = false;
54396 bool core_dumped = false;
54397- static atomic_t core_dump_count = ATOMIC_INIT(0);
54398+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
54399+ long signr = siginfo->si_signo;
54400 struct coredump_params cprm = {
54401 .siginfo = siginfo,
54402 .regs = signal_pt_regs(),
54403@@ -507,7 +508,10 @@ void do_coredump(siginfo_t *siginfo)
54404 .mm_flags = mm->flags,
54405 };
54406
54407- audit_core_dumps(siginfo->si_signo);
54408+ audit_core_dumps(signr);
54409+
54410+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
54411+ gr_handle_brute_attach(cprm.mm_flags);
54412
54413 binfmt = mm->binfmt;
54414 if (!binfmt || !binfmt->core_dump)
54415@@ -531,7 +535,7 @@ void do_coredump(siginfo_t *siginfo)
54416 need_nonrelative = true;
54417 }
54418
54419- retval = coredump_wait(siginfo->si_signo, &core_state);
54420+ retval = coredump_wait(signr, &core_state);
54421 if (retval < 0)
54422 goto fail_creds;
54423
54424@@ -574,7 +578,7 @@ void do_coredump(siginfo_t *siginfo)
54425 }
54426 cprm.limit = RLIM_INFINITY;
54427
54428- dump_count = atomic_inc_return(&core_dump_count);
54429+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
54430 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
54431 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
54432 task_tgid_vnr(current), current->comm);
54433@@ -606,6 +610,8 @@ void do_coredump(siginfo_t *siginfo)
54434 } else {
54435 struct inode *inode;
54436
54437+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
54438+
54439 if (cprm.limit < binfmt->min_coredump)
54440 goto fail_unlock;
54441
54442@@ -664,7 +670,7 @@ close_fail:
54443 filp_close(cprm.file, NULL);
54444 fail_dropcount:
54445 if (ispipe)
54446- atomic_dec(&core_dump_count);
54447+ atomic_dec_unchecked(&core_dump_count);
54448 fail_unlock:
54449 kfree(cn.corename);
54450 coredump_finish(mm, core_dumped);
54451@@ -684,7 +690,7 @@ int dump_write(struct file *file, const void *addr, int nr)
54452 {
54453 return !dump_interrupted() &&
54454 access_ok(VERIFY_READ, addr, nr) &&
54455- file->f_op->write(file, addr, nr, &file->f_pos) == nr;
54456+ file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
54457 }
54458 EXPORT_SYMBOL(dump_write);
54459
54460diff --git a/fs/dcache.c b/fs/dcache.c
54461index b949af8..5978926 100644
54462--- a/fs/dcache.c
54463+++ b/fs/dcache.c
54464@@ -3073,7 +3073,8 @@ void __init vfs_caches_init(unsigned long mempages)
54465 mempages -= reserve;
54466
54467 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
54468- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
54469+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
54470+ SLAB_NO_SANITIZE, NULL);
54471
54472 dcache_init();
54473 inode_init();
54474diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
54475index c7c83ff..bda9461 100644
54476--- a/fs/debugfs/inode.c
54477+++ b/fs/debugfs/inode.c
54478@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
54479 */
54480 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
54481 {
54482+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
54483+ return __create_file(name, S_IFDIR | S_IRWXU,
54484+#else
54485 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
54486+#endif
54487 parent, NULL, NULL);
54488 }
54489 EXPORT_SYMBOL_GPL(debugfs_create_dir);
54490diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c
54491index d107576..40db688 100644
54492--- a/fs/ecryptfs/crypto.c
54493+++ b/fs/ecryptfs/crypto.c
54494@@ -408,7 +408,7 @@ static loff_t lower_offset_for_page(struct ecryptfs_crypt_stat *crypt_stat,
54495 struct page *page)
54496 {
54497 return ecryptfs_lower_header_size(crypt_stat) +
54498- (page->index << PAGE_CACHE_SHIFT);
54499+ ((loff_t)page->index << PAGE_CACHE_SHIFT);
54500 }
54501
54502 /**
54503diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
54504index 67e9b63..a9adb68 100644
54505--- a/fs/ecryptfs/inode.c
54506+++ b/fs/ecryptfs/inode.c
54507@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
54508 old_fs = get_fs();
54509 set_fs(get_ds());
54510 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
54511- (char __user *)lower_buf,
54512+ (char __force_user *)lower_buf,
54513 PATH_MAX);
54514 set_fs(old_fs);
54515 if (rc < 0)
54516@@ -706,7 +706,7 @@ out:
54517 static void
54518 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
54519 {
54520- char *buf = nd_get_link(nd);
54521+ const char *buf = nd_get_link(nd);
54522 if (!IS_ERR(buf)) {
54523 /* Free the char* */
54524 kfree(buf);
54525diff --git a/fs/ecryptfs/keystore.c b/fs/ecryptfs/keystore.c
54526index 7d52806..4725a07 100644
54527--- a/fs/ecryptfs/keystore.c
54528+++ b/fs/ecryptfs/keystore.c
54529@@ -1149,7 +1149,7 @@ decrypt_pki_encrypted_session_key(struct ecryptfs_auth_tok *auth_tok,
54530 struct ecryptfs_msg_ctx *msg_ctx;
54531 struct ecryptfs_message *msg = NULL;
54532 char *auth_tok_sig;
54533- char *payload;
54534+ char *payload = NULL;
54535 size_t payload_len = 0;
54536 int rc;
54537
54538@@ -1203,6 +1203,7 @@ decrypt_pki_encrypted_session_key(struct ecryptfs_auth_tok *auth_tok,
54539 }
54540 out:
54541 kfree(msg);
54542+ kfree(payload);
54543 return rc;
54544 }
54545
54546diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
54547index e4141f2..d8263e8 100644
54548--- a/fs/ecryptfs/miscdev.c
54549+++ b/fs/ecryptfs/miscdev.c
54550@@ -304,7 +304,7 @@ check_list:
54551 goto out_unlock_msg_ctx;
54552 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
54553 if (msg_ctx->msg) {
54554- if (copy_to_user(&buf[i], packet_length, packet_length_size))
54555+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
54556 goto out_unlock_msg_ctx;
54557 i += packet_length_size;
54558 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
54559diff --git a/fs/exec.c b/fs/exec.c
54560index fd774c7..1c6a7bf 100644
54561--- a/fs/exec.c
54562+++ b/fs/exec.c
54563@@ -55,8 +55,20 @@
54564 #include <linux/pipe_fs_i.h>
54565 #include <linux/oom.h>
54566 #include <linux/compat.h>
54567+#include <linux/random.h>
54568+#include <linux/seq_file.h>
54569+#include <linux/coredump.h>
54570+#include <linux/mman.h>
54571+
54572+#ifdef CONFIG_PAX_REFCOUNT
54573+#include <linux/kallsyms.h>
54574+#include <linux/kdebug.h>
54575+#endif
54576+
54577+#include <trace/events/fs.h>
54578
54579 #include <asm/uaccess.h>
54580+#include <asm/sections.h>
54581 #include <asm/mmu_context.h>
54582 #include <asm/tlb.h>
54583
54584@@ -66,17 +78,32 @@
54585
54586 #include <trace/events/sched.h>
54587
54588+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
54589+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
54590+{
54591+ 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");
54592+}
54593+#endif
54594+
54595+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
54596+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
54597+EXPORT_SYMBOL(pax_set_initial_flags_func);
54598+#endif
54599+
54600 int suid_dumpable = 0;
54601
54602 static LIST_HEAD(formats);
54603 static DEFINE_RWLOCK(binfmt_lock);
54604
54605+extern int gr_process_kernel_exec_ban(void);
54606+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
54607+
54608 void __register_binfmt(struct linux_binfmt * fmt, int insert)
54609 {
54610 BUG_ON(!fmt);
54611 write_lock(&binfmt_lock);
54612- insert ? list_add(&fmt->lh, &formats) :
54613- list_add_tail(&fmt->lh, &formats);
54614+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
54615+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
54616 write_unlock(&binfmt_lock);
54617 }
54618
54619@@ -85,7 +112,7 @@ EXPORT_SYMBOL(__register_binfmt);
54620 void unregister_binfmt(struct linux_binfmt * fmt)
54621 {
54622 write_lock(&binfmt_lock);
54623- list_del(&fmt->lh);
54624+ pax_list_del((struct list_head *)&fmt->lh);
54625 write_unlock(&binfmt_lock);
54626 }
54627
54628@@ -181,18 +208,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
54629 int write)
54630 {
54631 struct page *page;
54632- int ret;
54633
54634-#ifdef CONFIG_STACK_GROWSUP
54635- if (write) {
54636- ret = expand_downwards(bprm->vma, pos);
54637- if (ret < 0)
54638- return NULL;
54639- }
54640-#endif
54641- ret = get_user_pages(current, bprm->mm, pos,
54642- 1, write, 1, &page, NULL);
54643- if (ret <= 0)
54644+ if (0 > expand_downwards(bprm->vma, pos))
54645+ return NULL;
54646+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
54647 return NULL;
54648
54649 if (write) {
54650@@ -208,6 +227,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
54651 if (size <= ARG_MAX)
54652 return page;
54653
54654+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54655+ // only allow 512KB for argv+env on suid/sgid binaries
54656+ // to prevent easy ASLR exhaustion
54657+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
54658+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
54659+ (size > (512 * 1024))) {
54660+ put_page(page);
54661+ return NULL;
54662+ }
54663+#endif
54664+
54665 /*
54666 * Limit to 1/4-th the stack size for the argv+env strings.
54667 * This ensures that:
54668@@ -267,6 +297,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
54669 vma->vm_end = STACK_TOP_MAX;
54670 vma->vm_start = vma->vm_end - PAGE_SIZE;
54671 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
54672+
54673+#ifdef CONFIG_PAX_SEGMEXEC
54674+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
54675+#endif
54676+
54677 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
54678 INIT_LIST_HEAD(&vma->anon_vma_chain);
54679
54680@@ -277,6 +312,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
54681 mm->stack_vm = mm->total_vm = 1;
54682 up_write(&mm->mmap_sem);
54683 bprm->p = vma->vm_end - sizeof(void *);
54684+
54685+#ifdef CONFIG_PAX_RANDUSTACK
54686+ if (randomize_va_space)
54687+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
54688+#endif
54689+
54690 return 0;
54691 err:
54692 up_write(&mm->mmap_sem);
54693@@ -397,7 +438,7 @@ struct user_arg_ptr {
54694 } ptr;
54695 };
54696
54697-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
54698+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
54699 {
54700 const char __user *native;
54701
54702@@ -406,14 +447,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
54703 compat_uptr_t compat;
54704
54705 if (get_user(compat, argv.ptr.compat + nr))
54706- return ERR_PTR(-EFAULT);
54707+ return (const char __force_user *)ERR_PTR(-EFAULT);
54708
54709 return compat_ptr(compat);
54710 }
54711 #endif
54712
54713 if (get_user(native, argv.ptr.native + nr))
54714- return ERR_PTR(-EFAULT);
54715+ return (const char __force_user *)ERR_PTR(-EFAULT);
54716
54717 return native;
54718 }
54719@@ -432,7 +473,7 @@ static int count(struct user_arg_ptr argv, int max)
54720 if (!p)
54721 break;
54722
54723- if (IS_ERR(p))
54724+ if (IS_ERR((const char __force_kernel *)p))
54725 return -EFAULT;
54726
54727 if (i >= max)
54728@@ -467,7 +508,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
54729
54730 ret = -EFAULT;
54731 str = get_user_arg_ptr(argv, argc);
54732- if (IS_ERR(str))
54733+ if (IS_ERR((const char __force_kernel *)str))
54734 goto out;
54735
54736 len = strnlen_user(str, MAX_ARG_STRLEN);
54737@@ -549,7 +590,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
54738 int r;
54739 mm_segment_t oldfs = get_fs();
54740 struct user_arg_ptr argv = {
54741- .ptr.native = (const char __user *const __user *)__argv,
54742+ .ptr.native = (const char __force_user * const __force_user *)__argv,
54743 };
54744
54745 set_fs(KERNEL_DS);
54746@@ -584,7 +625,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
54747 unsigned long new_end = old_end - shift;
54748 struct mmu_gather tlb;
54749
54750- BUG_ON(new_start > new_end);
54751+ if (new_start >= new_end || new_start < mmap_min_addr)
54752+ return -ENOMEM;
54753
54754 /*
54755 * ensure there are no vmas between where we want to go
54756@@ -593,6 +635,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
54757 if (vma != find_vma(mm, new_start))
54758 return -EFAULT;
54759
54760+#ifdef CONFIG_PAX_SEGMEXEC
54761+ BUG_ON(pax_find_mirror_vma(vma));
54762+#endif
54763+
54764 /*
54765 * cover the whole range: [new_start, old_end)
54766 */
54767@@ -673,10 +719,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
54768 stack_top = arch_align_stack(stack_top);
54769 stack_top = PAGE_ALIGN(stack_top);
54770
54771- if (unlikely(stack_top < mmap_min_addr) ||
54772- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
54773- return -ENOMEM;
54774-
54775 stack_shift = vma->vm_end - stack_top;
54776
54777 bprm->p -= stack_shift;
54778@@ -688,8 +730,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
54779 bprm->exec -= stack_shift;
54780
54781 down_write(&mm->mmap_sem);
54782+
54783+ /* Move stack pages down in memory. */
54784+ if (stack_shift) {
54785+ ret = shift_arg_pages(vma, stack_shift);
54786+ if (ret)
54787+ goto out_unlock;
54788+ }
54789+
54790 vm_flags = VM_STACK_FLAGS;
54791
54792+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
54793+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
54794+ vm_flags &= ~VM_EXEC;
54795+
54796+#ifdef CONFIG_PAX_MPROTECT
54797+ if (mm->pax_flags & MF_PAX_MPROTECT)
54798+ vm_flags &= ~VM_MAYEXEC;
54799+#endif
54800+
54801+ }
54802+#endif
54803+
54804 /*
54805 * Adjust stack execute permissions; explicitly enable for
54806 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
54807@@ -708,13 +770,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
54808 goto out_unlock;
54809 BUG_ON(prev != vma);
54810
54811- /* Move stack pages down in memory. */
54812- if (stack_shift) {
54813- ret = shift_arg_pages(vma, stack_shift);
54814- if (ret)
54815- goto out_unlock;
54816- }
54817-
54818 /* mprotect_fixup is overkill to remove the temporary stack flags */
54819 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
54820
54821@@ -738,6 +793,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
54822 #endif
54823 current->mm->start_stack = bprm->p;
54824 ret = expand_stack(vma, stack_base);
54825+
54826+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
54827+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
54828+ unsigned long size;
54829+ vm_flags_t vm_flags;
54830+
54831+ size = STACK_TOP - vma->vm_end;
54832+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
54833+
54834+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
54835+
54836+#ifdef CONFIG_X86
54837+ if (!ret) {
54838+ size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
54839+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
54840+ }
54841+#endif
54842+
54843+ }
54844+#endif
54845+
54846 if (ret)
54847 ret = -EFAULT;
54848
54849@@ -774,6 +850,8 @@ struct file *open_exec(const char *name)
54850
54851 fsnotify_open(file);
54852
54853+ trace_open_exec(name);
54854+
54855 err = deny_write_access(file);
54856 if (err)
54857 goto exit;
54858@@ -797,7 +875,7 @@ int kernel_read(struct file *file, loff_t offset,
54859 old_fs = get_fs();
54860 set_fs(get_ds());
54861 /* The cast to a user pointer is valid due to the set_fs() */
54862- result = vfs_read(file, (void __user *)addr, count, &pos);
54863+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
54864 set_fs(old_fs);
54865 return result;
54866 }
54867@@ -1253,7 +1331,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
54868 }
54869 rcu_read_unlock();
54870
54871- if (p->fs->users > n_fs) {
54872+ if (atomic_read(&p->fs->users) > n_fs) {
54873 bprm->unsafe |= LSM_UNSAFE_SHARE;
54874 } else {
54875 res = -EAGAIN;
54876@@ -1453,6 +1531,31 @@ int search_binary_handler(struct linux_binprm *bprm)
54877
54878 EXPORT_SYMBOL(search_binary_handler);
54879
54880+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54881+static DEFINE_PER_CPU(u64, exec_counter);
54882+static int __init init_exec_counters(void)
54883+{
54884+ unsigned int cpu;
54885+
54886+ for_each_possible_cpu(cpu) {
54887+ per_cpu(exec_counter, cpu) = (u64)cpu;
54888+ }
54889+
54890+ return 0;
54891+}
54892+early_initcall(init_exec_counters);
54893+static inline void increment_exec_counter(void)
54894+{
54895+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
54896+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
54897+}
54898+#else
54899+static inline void increment_exec_counter(void) {}
54900+#endif
54901+
54902+extern void gr_handle_exec_args(struct linux_binprm *bprm,
54903+ struct user_arg_ptr argv);
54904+
54905 /*
54906 * sys_execve() executes a new program.
54907 */
54908@@ -1460,12 +1563,19 @@ static int do_execve_common(const char *filename,
54909 struct user_arg_ptr argv,
54910 struct user_arg_ptr envp)
54911 {
54912+#ifdef CONFIG_GRKERNSEC
54913+ struct file *old_exec_file;
54914+ struct acl_subject_label *old_acl;
54915+ struct rlimit old_rlim[RLIM_NLIMITS];
54916+#endif
54917 struct linux_binprm *bprm;
54918 struct file *file;
54919 struct files_struct *displaced;
54920 bool clear_in_exec;
54921 int retval;
54922
54923+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
54924+
54925 /*
54926 * We move the actual failure in case of RLIMIT_NPROC excess from
54927 * set*uid() to execve() because too many poorly written programs
54928@@ -1506,12 +1616,22 @@ static int do_execve_common(const char *filename,
54929 if (IS_ERR(file))
54930 goto out_unmark;
54931
54932+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
54933+ retval = -EPERM;
54934+ goto out_file;
54935+ }
54936+
54937 sched_exec();
54938
54939 bprm->file = file;
54940 bprm->filename = filename;
54941 bprm->interp = filename;
54942
54943+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
54944+ retval = -EACCES;
54945+ goto out_file;
54946+ }
54947+
54948 retval = bprm_mm_init(bprm);
54949 if (retval)
54950 goto out_file;
54951@@ -1528,24 +1648,70 @@ static int do_execve_common(const char *filename,
54952 if (retval < 0)
54953 goto out;
54954
54955+#ifdef CONFIG_GRKERNSEC
54956+ old_acl = current->acl;
54957+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
54958+ old_exec_file = current->exec_file;
54959+ get_file(file);
54960+ current->exec_file = file;
54961+#endif
54962+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54963+ /* limit suid stack to 8MB
54964+ * we saved the old limits above and will restore them if this exec fails
54965+ */
54966+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
54967+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
54968+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
54969+#endif
54970+
54971+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
54972+ retval = -EPERM;
54973+ goto out_fail;
54974+ }
54975+
54976+ if (!gr_tpe_allow(file)) {
54977+ retval = -EACCES;
54978+ goto out_fail;
54979+ }
54980+
54981+ if (gr_check_crash_exec(file)) {
54982+ retval = -EACCES;
54983+ goto out_fail;
54984+ }
54985+
54986+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
54987+ bprm->unsafe);
54988+ if (retval < 0)
54989+ goto out_fail;
54990+
54991 retval = copy_strings_kernel(1, &bprm->filename, bprm);
54992 if (retval < 0)
54993- goto out;
54994+ goto out_fail;
54995
54996 bprm->exec = bprm->p;
54997 retval = copy_strings(bprm->envc, envp, bprm);
54998 if (retval < 0)
54999- goto out;
55000+ goto out_fail;
55001
55002 retval = copy_strings(bprm->argc, argv, bprm);
55003 if (retval < 0)
55004- goto out;
55005+ goto out_fail;
55006+
55007+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
55008+
55009+ gr_handle_exec_args(bprm, argv);
55010
55011 retval = search_binary_handler(bprm);
55012 if (retval < 0)
55013- goto out;
55014+ goto out_fail;
55015+#ifdef CONFIG_GRKERNSEC
55016+ if (old_exec_file)
55017+ fput(old_exec_file);
55018+#endif
55019
55020 /* execve succeeded */
55021+
55022+ increment_exec_counter();
55023 current->fs->in_exec = 0;
55024 current->in_execve = 0;
55025 acct_update_integrals(current);
55026@@ -1554,6 +1720,14 @@ static int do_execve_common(const char *filename,
55027 put_files_struct(displaced);
55028 return retval;
55029
55030+out_fail:
55031+#ifdef CONFIG_GRKERNSEC
55032+ current->acl = old_acl;
55033+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
55034+ fput(current->exec_file);
55035+ current->exec_file = old_exec_file;
55036+#endif
55037+
55038 out:
55039 if (bprm->mm) {
55040 acct_arg_size(bprm, 0);
55041@@ -1702,3 +1876,287 @@ asmlinkage long compat_sys_execve(const char __user * filename,
55042 return error;
55043 }
55044 #endif
55045+
55046+int pax_check_flags(unsigned long *flags)
55047+{
55048+ int retval = 0;
55049+
55050+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
55051+ if (*flags & MF_PAX_SEGMEXEC)
55052+ {
55053+ *flags &= ~MF_PAX_SEGMEXEC;
55054+ retval = -EINVAL;
55055+ }
55056+#endif
55057+
55058+ if ((*flags & MF_PAX_PAGEEXEC)
55059+
55060+#ifdef CONFIG_PAX_PAGEEXEC
55061+ && (*flags & MF_PAX_SEGMEXEC)
55062+#endif
55063+
55064+ )
55065+ {
55066+ *flags &= ~MF_PAX_PAGEEXEC;
55067+ retval = -EINVAL;
55068+ }
55069+
55070+ if ((*flags & MF_PAX_MPROTECT)
55071+
55072+#ifdef CONFIG_PAX_MPROTECT
55073+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
55074+#endif
55075+
55076+ )
55077+ {
55078+ *flags &= ~MF_PAX_MPROTECT;
55079+ retval = -EINVAL;
55080+ }
55081+
55082+ if ((*flags & MF_PAX_EMUTRAMP)
55083+
55084+#ifdef CONFIG_PAX_EMUTRAMP
55085+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
55086+#endif
55087+
55088+ )
55089+ {
55090+ *flags &= ~MF_PAX_EMUTRAMP;
55091+ retval = -EINVAL;
55092+ }
55093+
55094+ return retval;
55095+}
55096+
55097+EXPORT_SYMBOL(pax_check_flags);
55098+
55099+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
55100+char *pax_get_path(const struct path *path, char *buf, int buflen)
55101+{
55102+ char *pathname = d_path(path, buf, buflen);
55103+
55104+ if (IS_ERR(pathname))
55105+ goto toolong;
55106+
55107+ pathname = mangle_path(buf, pathname, "\t\n\\");
55108+ if (!pathname)
55109+ goto toolong;
55110+
55111+ *pathname = 0;
55112+ return buf;
55113+
55114+toolong:
55115+ return "<path too long>";
55116+}
55117+EXPORT_SYMBOL(pax_get_path);
55118+
55119+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
55120+{
55121+ struct task_struct *tsk = current;
55122+ struct mm_struct *mm = current->mm;
55123+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
55124+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
55125+ char *path_exec = NULL;
55126+ char *path_fault = NULL;
55127+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
55128+ siginfo_t info = { };
55129+
55130+ if (buffer_exec && buffer_fault) {
55131+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
55132+
55133+ down_read(&mm->mmap_sem);
55134+ vma = mm->mmap;
55135+ while (vma && (!vma_exec || !vma_fault)) {
55136+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
55137+ vma_exec = vma;
55138+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
55139+ vma_fault = vma;
55140+ vma = vma->vm_next;
55141+ }
55142+ if (vma_exec)
55143+ path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
55144+ if (vma_fault) {
55145+ start = vma_fault->vm_start;
55146+ end = vma_fault->vm_end;
55147+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
55148+ if (vma_fault->vm_file)
55149+ path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
55150+ else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
55151+ path_fault = "<heap>";
55152+ else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
55153+ path_fault = "<stack>";
55154+ else
55155+ path_fault = "<anonymous mapping>";
55156+ }
55157+ up_read(&mm->mmap_sem);
55158+ }
55159+ if (tsk->signal->curr_ip)
55160+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
55161+ else
55162+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
55163+ 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),
55164+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
55165+ free_page((unsigned long)buffer_exec);
55166+ free_page((unsigned long)buffer_fault);
55167+ pax_report_insns(regs, pc, sp);
55168+ info.si_signo = SIGKILL;
55169+ info.si_errno = 0;
55170+ info.si_code = SI_KERNEL;
55171+ info.si_pid = 0;
55172+ info.si_uid = 0;
55173+ do_coredump(&info);
55174+}
55175+#endif
55176+
55177+#ifdef CONFIG_PAX_REFCOUNT
55178+void pax_report_refcount_overflow(struct pt_regs *regs)
55179+{
55180+ if (current->signal->curr_ip)
55181+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
55182+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
55183+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
55184+ else
55185+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
55186+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
55187+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
55188+ preempt_disable();
55189+ show_regs(regs);
55190+ preempt_enable();
55191+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
55192+}
55193+#endif
55194+
55195+#ifdef CONFIG_PAX_USERCOPY
55196+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
55197+static noinline int check_stack_object(const void *obj, unsigned long len)
55198+{
55199+ const void * const stack = task_stack_page(current);
55200+ const void * const stackend = stack + THREAD_SIZE;
55201+
55202+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
55203+ const void *frame = NULL;
55204+ const void *oldframe;
55205+#endif
55206+
55207+ if (obj + len < obj)
55208+ return -1;
55209+
55210+ if (obj + len <= stack || stackend <= obj)
55211+ return 0;
55212+
55213+ if (obj < stack || stackend < obj + len)
55214+ return -1;
55215+
55216+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
55217+ oldframe = __builtin_frame_address(1);
55218+ if (oldframe)
55219+ frame = __builtin_frame_address(2);
55220+ /*
55221+ low ----------------------------------------------> high
55222+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
55223+ ^----------------^
55224+ allow copies only within here
55225+ */
55226+ while (stack <= frame && frame < stackend) {
55227+ /* if obj + len extends past the last frame, this
55228+ check won't pass and the next frame will be 0,
55229+ causing us to bail out and correctly report
55230+ the copy as invalid
55231+ */
55232+ if (obj + len <= frame)
55233+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
55234+ oldframe = frame;
55235+ frame = *(const void * const *)frame;
55236+ }
55237+ return -1;
55238+#else
55239+ return 1;
55240+#endif
55241+}
55242+
55243+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
55244+{
55245+ if (current->signal->curr_ip)
55246+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
55247+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
55248+ else
55249+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
55250+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
55251+ dump_stack();
55252+ gr_handle_kernel_exploit();
55253+ do_group_exit(SIGKILL);
55254+}
55255+#endif
55256+
55257+#ifdef CONFIG_PAX_USERCOPY
55258+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
55259+{
55260+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
55261+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
55262+#ifdef CONFIG_MODULES
55263+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
55264+#else
55265+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
55266+#endif
55267+
55268+#else
55269+ unsigned long textlow = (unsigned long)_stext;
55270+ unsigned long texthigh = (unsigned long)_etext;
55271+#endif
55272+
55273+ if (high <= textlow || low > texthigh)
55274+ return false;
55275+ else
55276+ return true;
55277+}
55278+#endif
55279+
55280+void __check_object_size(const void *ptr, unsigned long n, bool to_user)
55281+{
55282+
55283+#ifdef CONFIG_PAX_USERCOPY
55284+ const char *type;
55285+
55286+ if (!n)
55287+ return;
55288+
55289+ type = check_heap_object(ptr, n);
55290+ if (!type) {
55291+ int ret = check_stack_object(ptr, n);
55292+ if (ret == 1 || ret == 2)
55293+ return;
55294+ if (ret == 0) {
55295+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
55296+ type = "<kernel text>";
55297+ else
55298+ return;
55299+ } else
55300+ type = "<process stack>";
55301+ }
55302+
55303+ pax_report_usercopy(ptr, n, to_user, type);
55304+#endif
55305+
55306+}
55307+EXPORT_SYMBOL(__check_object_size);
55308+
55309+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
55310+void pax_track_stack(void)
55311+{
55312+ unsigned long sp = (unsigned long)&sp;
55313+ if (sp < current_thread_info()->lowest_stack &&
55314+ sp > (unsigned long)task_stack_page(current))
55315+ current_thread_info()->lowest_stack = sp;
55316+}
55317+EXPORT_SYMBOL(pax_track_stack);
55318+#endif
55319+
55320+#ifdef CONFIG_PAX_SIZE_OVERFLOW
55321+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
55322+{
55323+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
55324+ dump_stack();
55325+ do_group_exit(SIGKILL);
55326+}
55327+EXPORT_SYMBOL(report_size_overflow);
55328+#endif
55329diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
55330index 9f9992b..8b59411 100644
55331--- a/fs/ext2/balloc.c
55332+++ b/fs/ext2/balloc.c
55333@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
55334
55335 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
55336 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
55337- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
55338+ if (free_blocks < root_blocks + 1 &&
55339 !uid_eq(sbi->s_resuid, current_fsuid()) &&
55340 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
55341- !in_group_p (sbi->s_resgid))) {
55342+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
55343 return 0;
55344 }
55345 return 1;
55346diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
55347index 22548f5..41521d8 100644
55348--- a/fs/ext3/balloc.c
55349+++ b/fs/ext3/balloc.c
55350@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
55351
55352 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
55353 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
55354- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
55355+ if (free_blocks < root_blocks + 1 &&
55356 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
55357 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
55358- !in_group_p (sbi->s_resgid))) {
55359+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
55360 return 0;
55361 }
55362 return 1;
55363diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
55364index ddd715e..c772f88 100644
55365--- a/fs/ext4/balloc.c
55366+++ b/fs/ext4/balloc.c
55367@@ -528,8 +528,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
55368 /* Hm, nope. Are (enough) root reserved clusters available? */
55369 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
55370 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
55371- capable(CAP_SYS_RESOURCE) ||
55372- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
55373+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
55374+ capable_nolog(CAP_SYS_RESOURCE)) {
55375
55376 if (free_clusters >= (nclusters + dirty_clusters +
55377 resv_clusters))
55378diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
55379index 0ab26fb..b6ecb39 100644
55380--- a/fs/ext4/ext4.h
55381+++ b/fs/ext4/ext4.h
55382@@ -1247,19 +1247,19 @@ struct ext4_sb_info {
55383 unsigned long s_mb_last_start;
55384
55385 /* stats for buddy allocator */
55386- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
55387- atomic_t s_bal_success; /* we found long enough chunks */
55388- atomic_t s_bal_allocated; /* in blocks */
55389- atomic_t s_bal_ex_scanned; /* total extents scanned */
55390- atomic_t s_bal_goals; /* goal hits */
55391- atomic_t s_bal_breaks; /* too long searches */
55392- atomic_t s_bal_2orders; /* 2^order hits */
55393+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
55394+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
55395+ atomic_unchecked_t s_bal_allocated; /* in blocks */
55396+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
55397+ atomic_unchecked_t s_bal_goals; /* goal hits */
55398+ atomic_unchecked_t s_bal_breaks; /* too long searches */
55399+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
55400 spinlock_t s_bal_lock;
55401 unsigned long s_mb_buddies_generated;
55402 unsigned long long s_mb_generation_time;
55403- atomic_t s_mb_lost_chunks;
55404- atomic_t s_mb_preallocated;
55405- atomic_t s_mb_discarded;
55406+ atomic_unchecked_t s_mb_lost_chunks;
55407+ atomic_unchecked_t s_mb_preallocated;
55408+ atomic_unchecked_t s_mb_discarded;
55409 atomic_t s_lock_busy;
55410
55411 /* locality groups */
55412diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
55413index 4bbbf13b..dcceaeb 100644
55414--- a/fs/ext4/mballoc.c
55415+++ b/fs/ext4/mballoc.c
55416@@ -1865,7 +1865,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
55417 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
55418
55419 if (EXT4_SB(sb)->s_mb_stats)
55420- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
55421+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
55422
55423 break;
55424 }
55425@@ -2171,7 +2171,7 @@ repeat:
55426 ac->ac_status = AC_STATUS_CONTINUE;
55427 ac->ac_flags |= EXT4_MB_HINT_FIRST;
55428 cr = 3;
55429- atomic_inc(&sbi->s_mb_lost_chunks);
55430+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
55431 goto repeat;
55432 }
55433 }
55434@@ -2679,25 +2679,25 @@ int ext4_mb_release(struct super_block *sb)
55435 if (sbi->s_mb_stats) {
55436 ext4_msg(sb, KERN_INFO,
55437 "mballoc: %u blocks %u reqs (%u success)",
55438- atomic_read(&sbi->s_bal_allocated),
55439- atomic_read(&sbi->s_bal_reqs),
55440- atomic_read(&sbi->s_bal_success));
55441+ atomic_read_unchecked(&sbi->s_bal_allocated),
55442+ atomic_read_unchecked(&sbi->s_bal_reqs),
55443+ atomic_read_unchecked(&sbi->s_bal_success));
55444 ext4_msg(sb, KERN_INFO,
55445 "mballoc: %u extents scanned, %u goal hits, "
55446 "%u 2^N hits, %u breaks, %u lost",
55447- atomic_read(&sbi->s_bal_ex_scanned),
55448- atomic_read(&sbi->s_bal_goals),
55449- atomic_read(&sbi->s_bal_2orders),
55450- atomic_read(&sbi->s_bal_breaks),
55451- atomic_read(&sbi->s_mb_lost_chunks));
55452+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
55453+ atomic_read_unchecked(&sbi->s_bal_goals),
55454+ atomic_read_unchecked(&sbi->s_bal_2orders),
55455+ atomic_read_unchecked(&sbi->s_bal_breaks),
55456+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
55457 ext4_msg(sb, KERN_INFO,
55458 "mballoc: %lu generated and it took %Lu",
55459 sbi->s_mb_buddies_generated,
55460 sbi->s_mb_generation_time);
55461 ext4_msg(sb, KERN_INFO,
55462 "mballoc: %u preallocated, %u discarded",
55463- atomic_read(&sbi->s_mb_preallocated),
55464- atomic_read(&sbi->s_mb_discarded));
55465+ atomic_read_unchecked(&sbi->s_mb_preallocated),
55466+ atomic_read_unchecked(&sbi->s_mb_discarded));
55467 }
55468
55469 free_percpu(sbi->s_locality_groups);
55470@@ -3151,16 +3151,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
55471 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
55472
55473 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
55474- atomic_inc(&sbi->s_bal_reqs);
55475- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
55476+ atomic_inc_unchecked(&sbi->s_bal_reqs);
55477+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
55478 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
55479- atomic_inc(&sbi->s_bal_success);
55480- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
55481+ atomic_inc_unchecked(&sbi->s_bal_success);
55482+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
55483 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
55484 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
55485- atomic_inc(&sbi->s_bal_goals);
55486+ atomic_inc_unchecked(&sbi->s_bal_goals);
55487 if (ac->ac_found > sbi->s_mb_max_to_scan)
55488- atomic_inc(&sbi->s_bal_breaks);
55489+ atomic_inc_unchecked(&sbi->s_bal_breaks);
55490 }
55491
55492 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
55493@@ -3560,7 +3560,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
55494 trace_ext4_mb_new_inode_pa(ac, pa);
55495
55496 ext4_mb_use_inode_pa(ac, pa);
55497- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
55498+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
55499
55500 ei = EXT4_I(ac->ac_inode);
55501 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
55502@@ -3620,7 +3620,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
55503 trace_ext4_mb_new_group_pa(ac, pa);
55504
55505 ext4_mb_use_group_pa(ac, pa);
55506- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
55507+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
55508
55509 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
55510 lg = ac->ac_lg;
55511@@ -3709,7 +3709,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
55512 * from the bitmap and continue.
55513 */
55514 }
55515- atomic_add(free, &sbi->s_mb_discarded);
55516+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
55517
55518 return err;
55519 }
55520@@ -3727,7 +3727,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
55521 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
55522 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
55523 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
55524- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
55525+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
55526 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
55527
55528 return 0;
55529diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
55530index 214461e..3614c89 100644
55531--- a/fs/ext4/mmp.c
55532+++ b/fs/ext4/mmp.c
55533@@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
55534 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
55535 const char *function, unsigned int line, const char *msg)
55536 {
55537- __ext4_warning(sb, function, line, msg);
55538+ __ext4_warning(sb, function, line, "%s", msg);
55539 __ext4_warning(sb, function, line,
55540 "MMP failure info: last update time: %llu, last update "
55541 "node: %s, last update device: %s\n",
55542diff --git a/fs/ext4/super.c b/fs/ext4/super.c
55543index b59373b..f41c2b5 100644
55544--- a/fs/ext4/super.c
55545+++ b/fs/ext4/super.c
55546@@ -1254,7 +1254,7 @@ static ext4_fsblk_t get_sb_block(void **data)
55547 }
55548
55549 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
55550-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
55551+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
55552 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
55553
55554 #ifdef CONFIG_QUOTA
55555@@ -2394,7 +2394,7 @@ struct ext4_attr {
55556 int offset;
55557 int deprecated_val;
55558 } u;
55559-};
55560+} __do_const;
55561
55562 static int parse_strtoull(const char *buf,
55563 unsigned long long max, unsigned long long *value)
55564diff --git a/fs/fcntl.c b/fs/fcntl.c
55565index 65343c3..9969dcf 100644
55566--- a/fs/fcntl.c
55567+++ b/fs/fcntl.c
55568@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
55569 if (err)
55570 return err;
55571
55572+ if (gr_handle_chroot_fowner(pid, type))
55573+ return -ENOENT;
55574+ if (gr_check_protected_task_fowner(pid, type))
55575+ return -EACCES;
55576+
55577 f_modown(filp, pid, type, force);
55578 return 0;
55579 }
55580diff --git a/fs/fhandle.c b/fs/fhandle.c
55581index 999ff5c..41f4109 100644
55582--- a/fs/fhandle.c
55583+++ b/fs/fhandle.c
55584@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
55585 } else
55586 retval = 0;
55587 /* copy the mount id */
55588- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
55589- sizeof(*mnt_id)) ||
55590+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
55591 copy_to_user(ufh, handle,
55592 sizeof(struct file_handle) + handle_bytes))
55593 retval = -EFAULT;
55594diff --git a/fs/file.c b/fs/file.c
55595index 4a78f98..9447397 100644
55596--- a/fs/file.c
55597+++ b/fs/file.c
55598@@ -16,6 +16,7 @@
55599 #include <linux/slab.h>
55600 #include <linux/vmalloc.h>
55601 #include <linux/file.h>
55602+#include <linux/security.h>
55603 #include <linux/fdtable.h>
55604 #include <linux/bitops.h>
55605 #include <linux/interrupt.h>
55606@@ -828,6 +829,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
55607 if (!file)
55608 return __close_fd(files, fd);
55609
55610+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
55611 if (fd >= rlimit(RLIMIT_NOFILE))
55612 return -EBADF;
55613
55614@@ -854,6 +856,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
55615 if (unlikely(oldfd == newfd))
55616 return -EINVAL;
55617
55618+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
55619 if (newfd >= rlimit(RLIMIT_NOFILE))
55620 return -EBADF;
55621
55622@@ -909,6 +912,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
55623 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
55624 {
55625 int err;
55626+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
55627 if (from >= rlimit(RLIMIT_NOFILE))
55628 return -EINVAL;
55629 err = alloc_fd(from, flags);
55630diff --git a/fs/filesystems.c b/fs/filesystems.c
55631index 92567d9..fcd8cbf 100644
55632--- a/fs/filesystems.c
55633+++ b/fs/filesystems.c
55634@@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
55635 int len = dot ? dot - name : strlen(name);
55636
55637 fs = __get_fs_type(name, len);
55638+#ifdef CONFIG_GRKERNSEC_MODHARDEN
55639+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
55640+#else
55641 if (!fs && (request_module("fs-%.*s", len, name) == 0))
55642+#endif
55643 fs = __get_fs_type(name, len);
55644
55645 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
55646diff --git a/fs/fs_struct.c b/fs/fs_struct.c
55647index d8ac61d..79a36f0 100644
55648--- a/fs/fs_struct.c
55649+++ b/fs/fs_struct.c
55650@@ -4,6 +4,7 @@
55651 #include <linux/path.h>
55652 #include <linux/slab.h>
55653 #include <linux/fs_struct.h>
55654+#include <linux/grsecurity.h>
55655 #include "internal.h"
55656
55657 /*
55658@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
55659 write_seqcount_begin(&fs->seq);
55660 old_root = fs->root;
55661 fs->root = *path;
55662+ gr_set_chroot_entries(current, path);
55663 write_seqcount_end(&fs->seq);
55664 spin_unlock(&fs->lock);
55665 if (old_root.dentry)
55666@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
55667 int hits = 0;
55668 spin_lock(&fs->lock);
55669 write_seqcount_begin(&fs->seq);
55670+ /* this root replacement is only done by pivot_root,
55671+ leave grsec's chroot tagging alone for this task
55672+ so that a pivoted root isn't treated as a chroot
55673+ */
55674 hits += replace_path(&fs->root, old_root, new_root);
55675 hits += replace_path(&fs->pwd, old_root, new_root);
55676 write_seqcount_end(&fs->seq);
55677@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
55678 task_lock(tsk);
55679 spin_lock(&fs->lock);
55680 tsk->fs = NULL;
55681- kill = !--fs->users;
55682+ gr_clear_chroot_entries(tsk);
55683+ kill = !atomic_dec_return(&fs->users);
55684 spin_unlock(&fs->lock);
55685 task_unlock(tsk);
55686 if (kill)
55687@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
55688 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
55689 /* We don't need to lock fs - think why ;-) */
55690 if (fs) {
55691- fs->users = 1;
55692+ atomic_set(&fs->users, 1);
55693 fs->in_exec = 0;
55694 spin_lock_init(&fs->lock);
55695 seqcount_init(&fs->seq);
55696@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
55697 spin_lock(&old->lock);
55698 fs->root = old->root;
55699 path_get(&fs->root);
55700+ /* instead of calling gr_set_chroot_entries here,
55701+ we call it from every caller of this function
55702+ */
55703 fs->pwd = old->pwd;
55704 path_get(&fs->pwd);
55705 spin_unlock(&old->lock);
55706@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
55707
55708 task_lock(current);
55709 spin_lock(&fs->lock);
55710- kill = !--fs->users;
55711+ kill = !atomic_dec_return(&fs->users);
55712 current->fs = new_fs;
55713+ gr_set_chroot_entries(current, &new_fs->root);
55714 spin_unlock(&fs->lock);
55715 task_unlock(current);
55716
55717@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
55718
55719 int current_umask(void)
55720 {
55721- return current->fs->umask;
55722+ return current->fs->umask | gr_acl_umask();
55723 }
55724 EXPORT_SYMBOL(current_umask);
55725
55726 /* to be mentioned only in INIT_TASK */
55727 struct fs_struct init_fs = {
55728- .users = 1,
55729+ .users = ATOMIC_INIT(1),
55730 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
55731 .seq = SEQCNT_ZERO,
55732 .umask = 0022,
55733diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
55734index 0e91a3c..6c6d2e0 100644
55735--- a/fs/fscache/cookie.c
55736+++ b/fs/fscache/cookie.c
55737@@ -19,7 +19,7 @@
55738
55739 struct kmem_cache *fscache_cookie_jar;
55740
55741-static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
55742+static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
55743
55744 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
55745 static int fscache_alloc_object(struct fscache_cache *cache,
55746@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
55747 parent ? (char *) parent->def->name : "<no-parent>",
55748 def->name, netfs_data);
55749
55750- fscache_stat(&fscache_n_acquires);
55751+ fscache_stat_unchecked(&fscache_n_acquires);
55752
55753 /* if there's no parent cookie, then we don't create one here either */
55754 if (!parent) {
55755- fscache_stat(&fscache_n_acquires_null);
55756+ fscache_stat_unchecked(&fscache_n_acquires_null);
55757 _leave(" [no parent]");
55758 return NULL;
55759 }
55760@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
55761 /* allocate and initialise a cookie */
55762 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
55763 if (!cookie) {
55764- fscache_stat(&fscache_n_acquires_oom);
55765+ fscache_stat_unchecked(&fscache_n_acquires_oom);
55766 _leave(" [ENOMEM]");
55767 return NULL;
55768 }
55769@@ -114,13 +114,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
55770
55771 switch (cookie->def->type) {
55772 case FSCACHE_COOKIE_TYPE_INDEX:
55773- fscache_stat(&fscache_n_cookie_index);
55774+ fscache_stat_unchecked(&fscache_n_cookie_index);
55775 break;
55776 case FSCACHE_COOKIE_TYPE_DATAFILE:
55777- fscache_stat(&fscache_n_cookie_data);
55778+ fscache_stat_unchecked(&fscache_n_cookie_data);
55779 break;
55780 default:
55781- fscache_stat(&fscache_n_cookie_special);
55782+ fscache_stat_unchecked(&fscache_n_cookie_special);
55783 break;
55784 }
55785
55786@@ -131,13 +131,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
55787 if (fscache_acquire_non_index_cookie(cookie) < 0) {
55788 atomic_dec(&parent->n_children);
55789 __fscache_cookie_put(cookie);
55790- fscache_stat(&fscache_n_acquires_nobufs);
55791+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
55792 _leave(" = NULL");
55793 return NULL;
55794 }
55795 }
55796
55797- fscache_stat(&fscache_n_acquires_ok);
55798+ fscache_stat_unchecked(&fscache_n_acquires_ok);
55799 _leave(" = %p", cookie);
55800 return cookie;
55801 }
55802@@ -173,7 +173,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
55803 cache = fscache_select_cache_for_object(cookie->parent);
55804 if (!cache) {
55805 up_read(&fscache_addremove_sem);
55806- fscache_stat(&fscache_n_acquires_no_cache);
55807+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
55808 _leave(" = -ENOMEDIUM [no cache]");
55809 return -ENOMEDIUM;
55810 }
55811@@ -259,14 +259,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
55812 object = cache->ops->alloc_object(cache, cookie);
55813 fscache_stat_d(&fscache_n_cop_alloc_object);
55814 if (IS_ERR(object)) {
55815- fscache_stat(&fscache_n_object_no_alloc);
55816+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
55817 ret = PTR_ERR(object);
55818 goto error;
55819 }
55820
55821- fscache_stat(&fscache_n_object_alloc);
55822+ fscache_stat_unchecked(&fscache_n_object_alloc);
55823
55824- object->debug_id = atomic_inc_return(&fscache_object_debug_id);
55825+ object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
55826
55827 _debug("ALLOC OBJ%x: %s {%lx}",
55828 object->debug_id, cookie->def->name, object->events);
55829@@ -380,7 +380,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
55830
55831 _enter("{%s}", cookie->def->name);
55832
55833- fscache_stat(&fscache_n_invalidates);
55834+ fscache_stat_unchecked(&fscache_n_invalidates);
55835
55836 /* Only permit invalidation of data files. Invalidating an index will
55837 * require the caller to release all its attachments to the tree rooted
55838@@ -438,10 +438,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
55839 {
55840 struct fscache_object *object;
55841
55842- fscache_stat(&fscache_n_updates);
55843+ fscache_stat_unchecked(&fscache_n_updates);
55844
55845 if (!cookie) {
55846- fscache_stat(&fscache_n_updates_null);
55847+ fscache_stat_unchecked(&fscache_n_updates_null);
55848 _leave(" [no cookie]");
55849 return;
55850 }
55851@@ -473,12 +473,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
55852 {
55853 struct fscache_object *object;
55854
55855- fscache_stat(&fscache_n_relinquishes);
55856+ fscache_stat_unchecked(&fscache_n_relinquishes);
55857 if (retire)
55858- fscache_stat(&fscache_n_relinquishes_retire);
55859+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
55860
55861 if (!cookie) {
55862- fscache_stat(&fscache_n_relinquishes_null);
55863+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
55864 _leave(" [no cookie]");
55865 return;
55866 }
55867diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
55868index 12d505b..86473a3 100644
55869--- a/fs/fscache/internal.h
55870+++ b/fs/fscache/internal.h
55871@@ -147,101 +147,101 @@ extern void fscache_proc_cleanup(void);
55872 * stats.c
55873 */
55874 #ifdef CONFIG_FSCACHE_STATS
55875-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
55876-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
55877+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
55878+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
55879
55880-extern atomic_t fscache_n_op_pend;
55881-extern atomic_t fscache_n_op_run;
55882-extern atomic_t fscache_n_op_enqueue;
55883-extern atomic_t fscache_n_op_deferred_release;
55884-extern atomic_t fscache_n_op_release;
55885-extern atomic_t fscache_n_op_gc;
55886-extern atomic_t fscache_n_op_cancelled;
55887-extern atomic_t fscache_n_op_rejected;
55888+extern atomic_unchecked_t fscache_n_op_pend;
55889+extern atomic_unchecked_t fscache_n_op_run;
55890+extern atomic_unchecked_t fscache_n_op_enqueue;
55891+extern atomic_unchecked_t fscache_n_op_deferred_release;
55892+extern atomic_unchecked_t fscache_n_op_release;
55893+extern atomic_unchecked_t fscache_n_op_gc;
55894+extern atomic_unchecked_t fscache_n_op_cancelled;
55895+extern atomic_unchecked_t fscache_n_op_rejected;
55896
55897-extern atomic_t fscache_n_attr_changed;
55898-extern atomic_t fscache_n_attr_changed_ok;
55899-extern atomic_t fscache_n_attr_changed_nobufs;
55900-extern atomic_t fscache_n_attr_changed_nomem;
55901-extern atomic_t fscache_n_attr_changed_calls;
55902+extern atomic_unchecked_t fscache_n_attr_changed;
55903+extern atomic_unchecked_t fscache_n_attr_changed_ok;
55904+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
55905+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
55906+extern atomic_unchecked_t fscache_n_attr_changed_calls;
55907
55908-extern atomic_t fscache_n_allocs;
55909-extern atomic_t fscache_n_allocs_ok;
55910-extern atomic_t fscache_n_allocs_wait;
55911-extern atomic_t fscache_n_allocs_nobufs;
55912-extern atomic_t fscache_n_allocs_intr;
55913-extern atomic_t fscache_n_allocs_object_dead;
55914-extern atomic_t fscache_n_alloc_ops;
55915-extern atomic_t fscache_n_alloc_op_waits;
55916+extern atomic_unchecked_t fscache_n_allocs;
55917+extern atomic_unchecked_t fscache_n_allocs_ok;
55918+extern atomic_unchecked_t fscache_n_allocs_wait;
55919+extern atomic_unchecked_t fscache_n_allocs_nobufs;
55920+extern atomic_unchecked_t fscache_n_allocs_intr;
55921+extern atomic_unchecked_t fscache_n_allocs_object_dead;
55922+extern atomic_unchecked_t fscache_n_alloc_ops;
55923+extern atomic_unchecked_t fscache_n_alloc_op_waits;
55924
55925-extern atomic_t fscache_n_retrievals;
55926-extern atomic_t fscache_n_retrievals_ok;
55927-extern atomic_t fscache_n_retrievals_wait;
55928-extern atomic_t fscache_n_retrievals_nodata;
55929-extern atomic_t fscache_n_retrievals_nobufs;
55930-extern atomic_t fscache_n_retrievals_intr;
55931-extern atomic_t fscache_n_retrievals_nomem;
55932-extern atomic_t fscache_n_retrievals_object_dead;
55933-extern atomic_t fscache_n_retrieval_ops;
55934-extern atomic_t fscache_n_retrieval_op_waits;
55935+extern atomic_unchecked_t fscache_n_retrievals;
55936+extern atomic_unchecked_t fscache_n_retrievals_ok;
55937+extern atomic_unchecked_t fscache_n_retrievals_wait;
55938+extern atomic_unchecked_t fscache_n_retrievals_nodata;
55939+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
55940+extern atomic_unchecked_t fscache_n_retrievals_intr;
55941+extern atomic_unchecked_t fscache_n_retrievals_nomem;
55942+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
55943+extern atomic_unchecked_t fscache_n_retrieval_ops;
55944+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
55945
55946-extern atomic_t fscache_n_stores;
55947-extern atomic_t fscache_n_stores_ok;
55948-extern atomic_t fscache_n_stores_again;
55949-extern atomic_t fscache_n_stores_nobufs;
55950-extern atomic_t fscache_n_stores_oom;
55951-extern atomic_t fscache_n_store_ops;
55952-extern atomic_t fscache_n_store_calls;
55953-extern atomic_t fscache_n_store_pages;
55954-extern atomic_t fscache_n_store_radix_deletes;
55955-extern atomic_t fscache_n_store_pages_over_limit;
55956+extern atomic_unchecked_t fscache_n_stores;
55957+extern atomic_unchecked_t fscache_n_stores_ok;
55958+extern atomic_unchecked_t fscache_n_stores_again;
55959+extern atomic_unchecked_t fscache_n_stores_nobufs;
55960+extern atomic_unchecked_t fscache_n_stores_oom;
55961+extern atomic_unchecked_t fscache_n_store_ops;
55962+extern atomic_unchecked_t fscache_n_store_calls;
55963+extern atomic_unchecked_t fscache_n_store_pages;
55964+extern atomic_unchecked_t fscache_n_store_radix_deletes;
55965+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
55966
55967-extern atomic_t fscache_n_store_vmscan_not_storing;
55968-extern atomic_t fscache_n_store_vmscan_gone;
55969-extern atomic_t fscache_n_store_vmscan_busy;
55970-extern atomic_t fscache_n_store_vmscan_cancelled;
55971-extern atomic_t fscache_n_store_vmscan_wait;
55972+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
55973+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
55974+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
55975+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
55976+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
55977
55978-extern atomic_t fscache_n_marks;
55979-extern atomic_t fscache_n_uncaches;
55980+extern atomic_unchecked_t fscache_n_marks;
55981+extern atomic_unchecked_t fscache_n_uncaches;
55982
55983-extern atomic_t fscache_n_acquires;
55984-extern atomic_t fscache_n_acquires_null;
55985-extern atomic_t fscache_n_acquires_no_cache;
55986-extern atomic_t fscache_n_acquires_ok;
55987-extern atomic_t fscache_n_acquires_nobufs;
55988-extern atomic_t fscache_n_acquires_oom;
55989+extern atomic_unchecked_t fscache_n_acquires;
55990+extern atomic_unchecked_t fscache_n_acquires_null;
55991+extern atomic_unchecked_t fscache_n_acquires_no_cache;
55992+extern atomic_unchecked_t fscache_n_acquires_ok;
55993+extern atomic_unchecked_t fscache_n_acquires_nobufs;
55994+extern atomic_unchecked_t fscache_n_acquires_oom;
55995
55996-extern atomic_t fscache_n_invalidates;
55997-extern atomic_t fscache_n_invalidates_run;
55998+extern atomic_unchecked_t fscache_n_invalidates;
55999+extern atomic_unchecked_t fscache_n_invalidates_run;
56000
56001-extern atomic_t fscache_n_updates;
56002-extern atomic_t fscache_n_updates_null;
56003-extern atomic_t fscache_n_updates_run;
56004+extern atomic_unchecked_t fscache_n_updates;
56005+extern atomic_unchecked_t fscache_n_updates_null;
56006+extern atomic_unchecked_t fscache_n_updates_run;
56007
56008-extern atomic_t fscache_n_relinquishes;
56009-extern atomic_t fscache_n_relinquishes_null;
56010-extern atomic_t fscache_n_relinquishes_waitcrt;
56011-extern atomic_t fscache_n_relinquishes_retire;
56012+extern atomic_unchecked_t fscache_n_relinquishes;
56013+extern atomic_unchecked_t fscache_n_relinquishes_null;
56014+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
56015+extern atomic_unchecked_t fscache_n_relinquishes_retire;
56016
56017-extern atomic_t fscache_n_cookie_index;
56018-extern atomic_t fscache_n_cookie_data;
56019-extern atomic_t fscache_n_cookie_special;
56020+extern atomic_unchecked_t fscache_n_cookie_index;
56021+extern atomic_unchecked_t fscache_n_cookie_data;
56022+extern atomic_unchecked_t fscache_n_cookie_special;
56023
56024-extern atomic_t fscache_n_object_alloc;
56025-extern atomic_t fscache_n_object_no_alloc;
56026-extern atomic_t fscache_n_object_lookups;
56027-extern atomic_t fscache_n_object_lookups_negative;
56028-extern atomic_t fscache_n_object_lookups_positive;
56029-extern atomic_t fscache_n_object_lookups_timed_out;
56030-extern atomic_t fscache_n_object_created;
56031-extern atomic_t fscache_n_object_avail;
56032-extern atomic_t fscache_n_object_dead;
56033+extern atomic_unchecked_t fscache_n_object_alloc;
56034+extern atomic_unchecked_t fscache_n_object_no_alloc;
56035+extern atomic_unchecked_t fscache_n_object_lookups;
56036+extern atomic_unchecked_t fscache_n_object_lookups_negative;
56037+extern atomic_unchecked_t fscache_n_object_lookups_positive;
56038+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
56039+extern atomic_unchecked_t fscache_n_object_created;
56040+extern atomic_unchecked_t fscache_n_object_avail;
56041+extern atomic_unchecked_t fscache_n_object_dead;
56042
56043-extern atomic_t fscache_n_checkaux_none;
56044-extern atomic_t fscache_n_checkaux_okay;
56045-extern atomic_t fscache_n_checkaux_update;
56046-extern atomic_t fscache_n_checkaux_obsolete;
56047+extern atomic_unchecked_t fscache_n_checkaux_none;
56048+extern atomic_unchecked_t fscache_n_checkaux_okay;
56049+extern atomic_unchecked_t fscache_n_checkaux_update;
56050+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
56051
56052 extern atomic_t fscache_n_cop_alloc_object;
56053 extern atomic_t fscache_n_cop_lookup_object;
56054@@ -266,6 +266,11 @@ static inline void fscache_stat(atomic_t *stat)
56055 atomic_inc(stat);
56056 }
56057
56058+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
56059+{
56060+ atomic_inc_unchecked(stat);
56061+}
56062+
56063 static inline void fscache_stat_d(atomic_t *stat)
56064 {
56065 atomic_dec(stat);
56066@@ -278,6 +283,7 @@ extern const struct file_operations fscache_stats_fops;
56067
56068 #define __fscache_stat(stat) (NULL)
56069 #define fscache_stat(stat) do {} while (0)
56070+#define fscache_stat_unchecked(stat) do {} while (0)
56071 #define fscache_stat_d(stat) do {} while (0)
56072 #endif
56073
56074diff --git a/fs/fscache/object.c b/fs/fscache/object.c
56075index 86d75a6..5f3d7a0 100644
56076--- a/fs/fscache/object.c
56077+++ b/fs/fscache/object.c
56078@@ -451,7 +451,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
56079 _debug("LOOKUP \"%s\" in \"%s\"",
56080 cookie->def->name, object->cache->tag->name);
56081
56082- fscache_stat(&fscache_n_object_lookups);
56083+ fscache_stat_unchecked(&fscache_n_object_lookups);
56084 fscache_stat(&fscache_n_cop_lookup_object);
56085 ret = object->cache->ops->lookup_object(object);
56086 fscache_stat_d(&fscache_n_cop_lookup_object);
56087@@ -461,7 +461,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
56088 if (ret == -ETIMEDOUT) {
56089 /* probably stuck behind another object, so move this one to
56090 * the back of the queue */
56091- fscache_stat(&fscache_n_object_lookups_timed_out);
56092+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
56093 _leave(" [timeout]");
56094 return NO_TRANSIT;
56095 }
56096@@ -489,7 +489,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
56097 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
56098
56099 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
56100- fscache_stat(&fscache_n_object_lookups_negative);
56101+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
56102
56103 /* Allow write requests to begin stacking up and read requests to begin
56104 * returning ENODATA.
56105@@ -523,7 +523,7 @@ void fscache_obtained_object(struct fscache_object *object)
56106 /* if we were still looking up, then we must have a positive lookup
56107 * result, in which case there may be data available */
56108 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
56109- fscache_stat(&fscache_n_object_lookups_positive);
56110+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
56111
56112 /* We do (presumably) have data */
56113 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
56114@@ -534,7 +534,7 @@ void fscache_obtained_object(struct fscache_object *object)
56115 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
56116 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
56117 } else {
56118- fscache_stat(&fscache_n_object_created);
56119+ fscache_stat_unchecked(&fscache_n_object_created);
56120 }
56121
56122 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
56123@@ -570,7 +570,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
56124 fscache_stat_d(&fscache_n_cop_lookup_complete);
56125
56126 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
56127- fscache_stat(&fscache_n_object_avail);
56128+ fscache_stat_unchecked(&fscache_n_object_avail);
56129
56130 _leave("");
56131 return transit_to(JUMPSTART_DEPS);
56132@@ -716,7 +716,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
56133
56134 /* this just shifts the object release to the work processor */
56135 fscache_put_object(object);
56136- fscache_stat(&fscache_n_object_dead);
56137+ fscache_stat_unchecked(&fscache_n_object_dead);
56138
56139 _leave("");
56140 return transit_to(OBJECT_DEAD);
56141@@ -881,7 +881,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
56142 enum fscache_checkaux result;
56143
56144 if (!object->cookie->def->check_aux) {
56145- fscache_stat(&fscache_n_checkaux_none);
56146+ fscache_stat_unchecked(&fscache_n_checkaux_none);
56147 return FSCACHE_CHECKAUX_OKAY;
56148 }
56149
56150@@ -890,17 +890,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
56151 switch (result) {
56152 /* entry okay as is */
56153 case FSCACHE_CHECKAUX_OKAY:
56154- fscache_stat(&fscache_n_checkaux_okay);
56155+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
56156 break;
56157
56158 /* entry requires update */
56159 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
56160- fscache_stat(&fscache_n_checkaux_update);
56161+ fscache_stat_unchecked(&fscache_n_checkaux_update);
56162 break;
56163
56164 /* entry requires deletion */
56165 case FSCACHE_CHECKAUX_OBSOLETE:
56166- fscache_stat(&fscache_n_checkaux_obsolete);
56167+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
56168 break;
56169
56170 default:
56171@@ -986,7 +986,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
56172 {
56173 const struct fscache_state *s;
56174
56175- fscache_stat(&fscache_n_invalidates_run);
56176+ fscache_stat_unchecked(&fscache_n_invalidates_run);
56177 fscache_stat(&fscache_n_cop_invalidate_object);
56178 s = _fscache_invalidate_object(object, event);
56179 fscache_stat_d(&fscache_n_cop_invalidate_object);
56180@@ -1001,7 +1001,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
56181 {
56182 _enter("{OBJ%x},%d", object->debug_id, event);
56183
56184- fscache_stat(&fscache_n_updates_run);
56185+ fscache_stat_unchecked(&fscache_n_updates_run);
56186 fscache_stat(&fscache_n_cop_update_object);
56187 object->cache->ops->update_object(object);
56188 fscache_stat_d(&fscache_n_cop_update_object);
56189diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
56190index 318071a..379938b 100644
56191--- a/fs/fscache/operation.c
56192+++ b/fs/fscache/operation.c
56193@@ -17,7 +17,7 @@
56194 #include <linux/slab.h>
56195 #include "internal.h"
56196
56197-atomic_t fscache_op_debug_id;
56198+atomic_unchecked_t fscache_op_debug_id;
56199 EXPORT_SYMBOL(fscache_op_debug_id);
56200
56201 /**
56202@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
56203 ASSERTCMP(atomic_read(&op->usage), >, 0);
56204 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
56205
56206- fscache_stat(&fscache_n_op_enqueue);
56207+ fscache_stat_unchecked(&fscache_n_op_enqueue);
56208 switch (op->flags & FSCACHE_OP_TYPE) {
56209 case FSCACHE_OP_ASYNC:
56210 _debug("queue async");
56211@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
56212 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
56213 if (op->processor)
56214 fscache_enqueue_operation(op);
56215- fscache_stat(&fscache_n_op_run);
56216+ fscache_stat_unchecked(&fscache_n_op_run);
56217 }
56218
56219 /*
56220@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
56221 if (object->n_in_progress > 0) {
56222 atomic_inc(&op->usage);
56223 list_add_tail(&op->pend_link, &object->pending_ops);
56224- fscache_stat(&fscache_n_op_pend);
56225+ fscache_stat_unchecked(&fscache_n_op_pend);
56226 } else if (!list_empty(&object->pending_ops)) {
56227 atomic_inc(&op->usage);
56228 list_add_tail(&op->pend_link, &object->pending_ops);
56229- fscache_stat(&fscache_n_op_pend);
56230+ fscache_stat_unchecked(&fscache_n_op_pend);
56231 fscache_start_operations(object);
56232 } else {
56233 ASSERTCMP(object->n_in_progress, ==, 0);
56234@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
56235 object->n_exclusive++; /* reads and writes must wait */
56236 atomic_inc(&op->usage);
56237 list_add_tail(&op->pend_link, &object->pending_ops);
56238- fscache_stat(&fscache_n_op_pend);
56239+ fscache_stat_unchecked(&fscache_n_op_pend);
56240 ret = 0;
56241 } else {
56242 /* If we're in any other state, there must have been an I/O
56243@@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
56244 if (object->n_exclusive > 0) {
56245 atomic_inc(&op->usage);
56246 list_add_tail(&op->pend_link, &object->pending_ops);
56247- fscache_stat(&fscache_n_op_pend);
56248+ fscache_stat_unchecked(&fscache_n_op_pend);
56249 } else if (!list_empty(&object->pending_ops)) {
56250 atomic_inc(&op->usage);
56251 list_add_tail(&op->pend_link, &object->pending_ops);
56252- fscache_stat(&fscache_n_op_pend);
56253+ fscache_stat_unchecked(&fscache_n_op_pend);
56254 fscache_start_operations(object);
56255 } else {
56256 ASSERTCMP(object->n_exclusive, ==, 0);
56257@@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
56258 object->n_ops++;
56259 atomic_inc(&op->usage);
56260 list_add_tail(&op->pend_link, &object->pending_ops);
56261- fscache_stat(&fscache_n_op_pend);
56262+ fscache_stat_unchecked(&fscache_n_op_pend);
56263 ret = 0;
56264 } else if (fscache_object_is_dying(object)) {
56265- fscache_stat(&fscache_n_op_rejected);
56266+ fscache_stat_unchecked(&fscache_n_op_rejected);
56267 op->state = FSCACHE_OP_ST_CANCELLED;
56268 ret = -ENOBUFS;
56269 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
56270@@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
56271 ret = -EBUSY;
56272 if (op->state == FSCACHE_OP_ST_PENDING) {
56273 ASSERT(!list_empty(&op->pend_link));
56274- fscache_stat(&fscache_n_op_cancelled);
56275+ fscache_stat_unchecked(&fscache_n_op_cancelled);
56276 list_del_init(&op->pend_link);
56277 if (do_cancel)
56278 do_cancel(op);
56279@@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
56280 while (!list_empty(&object->pending_ops)) {
56281 op = list_entry(object->pending_ops.next,
56282 struct fscache_operation, pend_link);
56283- fscache_stat(&fscache_n_op_cancelled);
56284+ fscache_stat_unchecked(&fscache_n_op_cancelled);
56285 list_del_init(&op->pend_link);
56286
56287 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
56288@@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
56289 op->state, ==, FSCACHE_OP_ST_CANCELLED);
56290 op->state = FSCACHE_OP_ST_DEAD;
56291
56292- fscache_stat(&fscache_n_op_release);
56293+ fscache_stat_unchecked(&fscache_n_op_release);
56294
56295 if (op->release) {
56296 op->release(op);
56297@@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
56298 * lock, and defer it otherwise */
56299 if (!spin_trylock(&object->lock)) {
56300 _debug("defer put");
56301- fscache_stat(&fscache_n_op_deferred_release);
56302+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
56303
56304 cache = object->cache;
56305 spin_lock(&cache->op_gc_list_lock);
56306@@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
56307
56308 _debug("GC DEFERRED REL OBJ%x OP%x",
56309 object->debug_id, op->debug_id);
56310- fscache_stat(&fscache_n_op_gc);
56311+ fscache_stat_unchecked(&fscache_n_op_gc);
56312
56313 ASSERTCMP(atomic_read(&op->usage), ==, 0);
56314 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
56315diff --git a/fs/fscache/page.c b/fs/fscache/page.c
56316index d479ab3..727a7f2 100644
56317--- a/fs/fscache/page.c
56318+++ b/fs/fscache/page.c
56319@@ -61,7 +61,7 @@ try_again:
56320 val = radix_tree_lookup(&cookie->stores, page->index);
56321 if (!val) {
56322 rcu_read_unlock();
56323- fscache_stat(&fscache_n_store_vmscan_not_storing);
56324+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
56325 __fscache_uncache_page(cookie, page);
56326 return true;
56327 }
56328@@ -91,11 +91,11 @@ try_again:
56329 spin_unlock(&cookie->stores_lock);
56330
56331 if (xpage) {
56332- fscache_stat(&fscache_n_store_vmscan_cancelled);
56333- fscache_stat(&fscache_n_store_radix_deletes);
56334+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
56335+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
56336 ASSERTCMP(xpage, ==, page);
56337 } else {
56338- fscache_stat(&fscache_n_store_vmscan_gone);
56339+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
56340 }
56341
56342 wake_up_bit(&cookie->flags, 0);
56343@@ -110,11 +110,11 @@ page_busy:
56344 * sleeping on memory allocation, so we may need to impose a timeout
56345 * too. */
56346 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
56347- fscache_stat(&fscache_n_store_vmscan_busy);
56348+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
56349 return false;
56350 }
56351
56352- fscache_stat(&fscache_n_store_vmscan_wait);
56353+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
56354 __fscache_wait_on_page_write(cookie, page);
56355 gfp &= ~__GFP_WAIT;
56356 goto try_again;
56357@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
56358 FSCACHE_COOKIE_STORING_TAG);
56359 if (!radix_tree_tag_get(&cookie->stores, page->index,
56360 FSCACHE_COOKIE_PENDING_TAG)) {
56361- fscache_stat(&fscache_n_store_radix_deletes);
56362+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
56363 xpage = radix_tree_delete(&cookie->stores, page->index);
56364 }
56365 spin_unlock(&cookie->stores_lock);
56366@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
56367
56368 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
56369
56370- fscache_stat(&fscache_n_attr_changed_calls);
56371+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
56372
56373 if (fscache_object_is_active(object) &&
56374 fscache_use_cookie(object)) {
56375@@ -189,11 +189,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
56376
56377 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
56378
56379- fscache_stat(&fscache_n_attr_changed);
56380+ fscache_stat_unchecked(&fscache_n_attr_changed);
56381
56382 op = kzalloc(sizeof(*op), GFP_KERNEL);
56383 if (!op) {
56384- fscache_stat(&fscache_n_attr_changed_nomem);
56385+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
56386 _leave(" = -ENOMEM");
56387 return -ENOMEM;
56388 }
56389@@ -211,7 +211,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
56390 if (fscache_submit_exclusive_op(object, op) < 0)
56391 goto nobufs;
56392 spin_unlock(&cookie->lock);
56393- fscache_stat(&fscache_n_attr_changed_ok);
56394+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
56395 fscache_put_operation(op);
56396 _leave(" = 0");
56397 return 0;
56398@@ -219,7 +219,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
56399 nobufs:
56400 spin_unlock(&cookie->lock);
56401 kfree(op);
56402- fscache_stat(&fscache_n_attr_changed_nobufs);
56403+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
56404 _leave(" = %d", -ENOBUFS);
56405 return -ENOBUFS;
56406 }
56407@@ -258,7 +258,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
56408 /* allocate a retrieval operation and attempt to submit it */
56409 op = kzalloc(sizeof(*op), GFP_NOIO);
56410 if (!op) {
56411- fscache_stat(&fscache_n_retrievals_nomem);
56412+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
56413 return NULL;
56414 }
56415
56416@@ -289,13 +289,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
56417 return 0;
56418 }
56419
56420- fscache_stat(&fscache_n_retrievals_wait);
56421+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
56422
56423 jif = jiffies;
56424 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
56425 fscache_wait_bit_interruptible,
56426 TASK_INTERRUPTIBLE) != 0) {
56427- fscache_stat(&fscache_n_retrievals_intr);
56428+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
56429 _leave(" = -ERESTARTSYS");
56430 return -ERESTARTSYS;
56431 }
56432@@ -324,8 +324,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
56433 */
56434 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
56435 struct fscache_retrieval *op,
56436- atomic_t *stat_op_waits,
56437- atomic_t *stat_object_dead)
56438+ atomic_unchecked_t *stat_op_waits,
56439+ atomic_unchecked_t *stat_object_dead)
56440 {
56441 int ret;
56442
56443@@ -333,7 +333,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
56444 goto check_if_dead;
56445
56446 _debug(">>> WT");
56447- fscache_stat(stat_op_waits);
56448+ fscache_stat_unchecked(stat_op_waits);
56449 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
56450 fscache_wait_bit_interruptible,
56451 TASK_INTERRUPTIBLE) != 0) {
56452@@ -350,14 +350,14 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
56453
56454 check_if_dead:
56455 if (op->op.state == FSCACHE_OP_ST_CANCELLED) {
56456- fscache_stat(stat_object_dead);
56457+ fscache_stat_unchecked(stat_object_dead);
56458 _leave(" = -ENOBUFS [cancelled]");
56459 return -ENOBUFS;
56460 }
56461 if (unlikely(fscache_object_is_dead(object))) {
56462 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->op.state);
56463 fscache_cancel_op(&op->op, fscache_do_cancel_retrieval);
56464- fscache_stat(stat_object_dead);
56465+ fscache_stat_unchecked(stat_object_dead);
56466 return -ENOBUFS;
56467 }
56468 return 0;
56469@@ -384,7 +384,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
56470
56471 _enter("%p,%p,,,", cookie, page);
56472
56473- fscache_stat(&fscache_n_retrievals);
56474+ fscache_stat_unchecked(&fscache_n_retrievals);
56475
56476 if (hlist_empty(&cookie->backing_objects))
56477 goto nobufs;
56478@@ -424,7 +424,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
56479 goto nobufs_unlock_dec;
56480 spin_unlock(&cookie->lock);
56481
56482- fscache_stat(&fscache_n_retrieval_ops);
56483+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
56484
56485 /* pin the netfs read context in case we need to do the actual netfs
56486 * read because we've encountered a cache read failure */
56487@@ -454,15 +454,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
56488
56489 error:
56490 if (ret == -ENOMEM)
56491- fscache_stat(&fscache_n_retrievals_nomem);
56492+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
56493 else if (ret == -ERESTARTSYS)
56494- fscache_stat(&fscache_n_retrievals_intr);
56495+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
56496 else if (ret == -ENODATA)
56497- fscache_stat(&fscache_n_retrievals_nodata);
56498+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
56499 else if (ret < 0)
56500- fscache_stat(&fscache_n_retrievals_nobufs);
56501+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
56502 else
56503- fscache_stat(&fscache_n_retrievals_ok);
56504+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
56505
56506 fscache_put_retrieval(op);
56507 _leave(" = %d", ret);
56508@@ -475,7 +475,7 @@ nobufs_unlock:
56509 atomic_dec(&cookie->n_active);
56510 kfree(op);
56511 nobufs:
56512- fscache_stat(&fscache_n_retrievals_nobufs);
56513+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
56514 _leave(" = -ENOBUFS");
56515 return -ENOBUFS;
56516 }
56517@@ -513,7 +513,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
56518
56519 _enter("%p,,%d,,,", cookie, *nr_pages);
56520
56521- fscache_stat(&fscache_n_retrievals);
56522+ fscache_stat_unchecked(&fscache_n_retrievals);
56523
56524 if (hlist_empty(&cookie->backing_objects))
56525 goto nobufs;
56526@@ -549,7 +549,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
56527 goto nobufs_unlock_dec;
56528 spin_unlock(&cookie->lock);
56529
56530- fscache_stat(&fscache_n_retrieval_ops);
56531+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
56532
56533 /* pin the netfs read context in case we need to do the actual netfs
56534 * read because we've encountered a cache read failure */
56535@@ -579,15 +579,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
56536
56537 error:
56538 if (ret == -ENOMEM)
56539- fscache_stat(&fscache_n_retrievals_nomem);
56540+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
56541 else if (ret == -ERESTARTSYS)
56542- fscache_stat(&fscache_n_retrievals_intr);
56543+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
56544 else if (ret == -ENODATA)
56545- fscache_stat(&fscache_n_retrievals_nodata);
56546+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
56547 else if (ret < 0)
56548- fscache_stat(&fscache_n_retrievals_nobufs);
56549+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
56550 else
56551- fscache_stat(&fscache_n_retrievals_ok);
56552+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
56553
56554 fscache_put_retrieval(op);
56555 _leave(" = %d", ret);
56556@@ -600,7 +600,7 @@ nobufs_unlock:
56557 atomic_dec(&cookie->n_active);
56558 kfree(op);
56559 nobufs:
56560- fscache_stat(&fscache_n_retrievals_nobufs);
56561+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
56562 _leave(" = -ENOBUFS");
56563 return -ENOBUFS;
56564 }
56565@@ -624,7 +624,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
56566
56567 _enter("%p,%p,,,", cookie, page);
56568
56569- fscache_stat(&fscache_n_allocs);
56570+ fscache_stat_unchecked(&fscache_n_allocs);
56571
56572 if (hlist_empty(&cookie->backing_objects))
56573 goto nobufs;
56574@@ -656,7 +656,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
56575 goto nobufs_unlock;
56576 spin_unlock(&cookie->lock);
56577
56578- fscache_stat(&fscache_n_alloc_ops);
56579+ fscache_stat_unchecked(&fscache_n_alloc_ops);
56580
56581 ret = fscache_wait_for_retrieval_activation(
56582 object, op,
56583@@ -672,11 +672,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
56584
56585 error:
56586 if (ret == -ERESTARTSYS)
56587- fscache_stat(&fscache_n_allocs_intr);
56588+ fscache_stat_unchecked(&fscache_n_allocs_intr);
56589 else if (ret < 0)
56590- fscache_stat(&fscache_n_allocs_nobufs);
56591+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
56592 else
56593- fscache_stat(&fscache_n_allocs_ok);
56594+ fscache_stat_unchecked(&fscache_n_allocs_ok);
56595
56596 fscache_put_retrieval(op);
56597 _leave(" = %d", ret);
56598@@ -687,7 +687,7 @@ nobufs_unlock:
56599 atomic_dec(&cookie->n_active);
56600 kfree(op);
56601 nobufs:
56602- fscache_stat(&fscache_n_allocs_nobufs);
56603+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
56604 _leave(" = -ENOBUFS");
56605 return -ENOBUFS;
56606 }
56607@@ -747,7 +747,7 @@ static void fscache_write_op(struct fscache_operation *_op)
56608
56609 spin_lock(&cookie->stores_lock);
56610
56611- fscache_stat(&fscache_n_store_calls);
56612+ fscache_stat_unchecked(&fscache_n_store_calls);
56613
56614 /* find a page to store */
56615 page = NULL;
56616@@ -758,7 +758,7 @@ static void fscache_write_op(struct fscache_operation *_op)
56617 page = results[0];
56618 _debug("gang %d [%lx]", n, page->index);
56619 if (page->index > op->store_limit) {
56620- fscache_stat(&fscache_n_store_pages_over_limit);
56621+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
56622 goto superseded;
56623 }
56624
56625@@ -770,7 +770,7 @@ static void fscache_write_op(struct fscache_operation *_op)
56626 spin_unlock(&cookie->stores_lock);
56627 spin_unlock(&object->lock);
56628
56629- fscache_stat(&fscache_n_store_pages);
56630+ fscache_stat_unchecked(&fscache_n_store_pages);
56631 fscache_stat(&fscache_n_cop_write_page);
56632 ret = object->cache->ops->write_page(op, page);
56633 fscache_stat_d(&fscache_n_cop_write_page);
56634@@ -873,7 +873,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
56635 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
56636 ASSERT(PageFsCache(page));
56637
56638- fscache_stat(&fscache_n_stores);
56639+ fscache_stat_unchecked(&fscache_n_stores);
56640
56641 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
56642 _leave(" = -ENOBUFS [invalidating]");
56643@@ -931,7 +931,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
56644 spin_unlock(&cookie->stores_lock);
56645 spin_unlock(&object->lock);
56646
56647- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
56648+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
56649 op->store_limit = object->store_limit;
56650
56651 atomic_inc(&cookie->n_active);
56652@@ -940,8 +940,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
56653
56654 spin_unlock(&cookie->lock);
56655 radix_tree_preload_end();
56656- fscache_stat(&fscache_n_store_ops);
56657- fscache_stat(&fscache_n_stores_ok);
56658+ fscache_stat_unchecked(&fscache_n_store_ops);
56659+ fscache_stat_unchecked(&fscache_n_stores_ok);
56660
56661 /* the work queue now carries its own ref on the object */
56662 fscache_put_operation(&op->op);
56663@@ -949,14 +949,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
56664 return 0;
56665
56666 already_queued:
56667- fscache_stat(&fscache_n_stores_again);
56668+ fscache_stat_unchecked(&fscache_n_stores_again);
56669 already_pending:
56670 spin_unlock(&cookie->stores_lock);
56671 spin_unlock(&object->lock);
56672 spin_unlock(&cookie->lock);
56673 radix_tree_preload_end();
56674 kfree(op);
56675- fscache_stat(&fscache_n_stores_ok);
56676+ fscache_stat_unchecked(&fscache_n_stores_ok);
56677 _leave(" = 0");
56678 return 0;
56679
56680@@ -976,14 +976,14 @@ nobufs:
56681 spin_unlock(&cookie->lock);
56682 radix_tree_preload_end();
56683 kfree(op);
56684- fscache_stat(&fscache_n_stores_nobufs);
56685+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
56686 _leave(" = -ENOBUFS");
56687 return -ENOBUFS;
56688
56689 nomem_free:
56690 kfree(op);
56691 nomem:
56692- fscache_stat(&fscache_n_stores_oom);
56693+ fscache_stat_unchecked(&fscache_n_stores_oom);
56694 _leave(" = -ENOMEM");
56695 return -ENOMEM;
56696 }
56697@@ -1001,7 +1001,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
56698 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
56699 ASSERTCMP(page, !=, NULL);
56700
56701- fscache_stat(&fscache_n_uncaches);
56702+ fscache_stat_unchecked(&fscache_n_uncaches);
56703
56704 /* cache withdrawal may beat us to it */
56705 if (!PageFsCache(page))
56706@@ -1052,7 +1052,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
56707 struct fscache_cookie *cookie = op->op.object->cookie;
56708
56709 #ifdef CONFIG_FSCACHE_STATS
56710- atomic_inc(&fscache_n_marks);
56711+ atomic_inc_unchecked(&fscache_n_marks);
56712 #endif
56713
56714 _debug("- mark %p{%lx}", page, page->index);
56715diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
56716index 40d13c7..ddf52b9 100644
56717--- a/fs/fscache/stats.c
56718+++ b/fs/fscache/stats.c
56719@@ -18,99 +18,99 @@
56720 /*
56721 * operation counters
56722 */
56723-atomic_t fscache_n_op_pend;
56724-atomic_t fscache_n_op_run;
56725-atomic_t fscache_n_op_enqueue;
56726-atomic_t fscache_n_op_requeue;
56727-atomic_t fscache_n_op_deferred_release;
56728-atomic_t fscache_n_op_release;
56729-atomic_t fscache_n_op_gc;
56730-atomic_t fscache_n_op_cancelled;
56731-atomic_t fscache_n_op_rejected;
56732+atomic_unchecked_t fscache_n_op_pend;
56733+atomic_unchecked_t fscache_n_op_run;
56734+atomic_unchecked_t fscache_n_op_enqueue;
56735+atomic_unchecked_t fscache_n_op_requeue;
56736+atomic_unchecked_t fscache_n_op_deferred_release;
56737+atomic_unchecked_t fscache_n_op_release;
56738+atomic_unchecked_t fscache_n_op_gc;
56739+atomic_unchecked_t fscache_n_op_cancelled;
56740+atomic_unchecked_t fscache_n_op_rejected;
56741
56742-atomic_t fscache_n_attr_changed;
56743-atomic_t fscache_n_attr_changed_ok;
56744-atomic_t fscache_n_attr_changed_nobufs;
56745-atomic_t fscache_n_attr_changed_nomem;
56746-atomic_t fscache_n_attr_changed_calls;
56747+atomic_unchecked_t fscache_n_attr_changed;
56748+atomic_unchecked_t fscache_n_attr_changed_ok;
56749+atomic_unchecked_t fscache_n_attr_changed_nobufs;
56750+atomic_unchecked_t fscache_n_attr_changed_nomem;
56751+atomic_unchecked_t fscache_n_attr_changed_calls;
56752
56753-atomic_t fscache_n_allocs;
56754-atomic_t fscache_n_allocs_ok;
56755-atomic_t fscache_n_allocs_wait;
56756-atomic_t fscache_n_allocs_nobufs;
56757-atomic_t fscache_n_allocs_intr;
56758-atomic_t fscache_n_allocs_object_dead;
56759-atomic_t fscache_n_alloc_ops;
56760-atomic_t fscache_n_alloc_op_waits;
56761+atomic_unchecked_t fscache_n_allocs;
56762+atomic_unchecked_t fscache_n_allocs_ok;
56763+atomic_unchecked_t fscache_n_allocs_wait;
56764+atomic_unchecked_t fscache_n_allocs_nobufs;
56765+atomic_unchecked_t fscache_n_allocs_intr;
56766+atomic_unchecked_t fscache_n_allocs_object_dead;
56767+atomic_unchecked_t fscache_n_alloc_ops;
56768+atomic_unchecked_t fscache_n_alloc_op_waits;
56769
56770-atomic_t fscache_n_retrievals;
56771-atomic_t fscache_n_retrievals_ok;
56772-atomic_t fscache_n_retrievals_wait;
56773-atomic_t fscache_n_retrievals_nodata;
56774-atomic_t fscache_n_retrievals_nobufs;
56775-atomic_t fscache_n_retrievals_intr;
56776-atomic_t fscache_n_retrievals_nomem;
56777-atomic_t fscache_n_retrievals_object_dead;
56778-atomic_t fscache_n_retrieval_ops;
56779-atomic_t fscache_n_retrieval_op_waits;
56780+atomic_unchecked_t fscache_n_retrievals;
56781+atomic_unchecked_t fscache_n_retrievals_ok;
56782+atomic_unchecked_t fscache_n_retrievals_wait;
56783+atomic_unchecked_t fscache_n_retrievals_nodata;
56784+atomic_unchecked_t fscache_n_retrievals_nobufs;
56785+atomic_unchecked_t fscache_n_retrievals_intr;
56786+atomic_unchecked_t fscache_n_retrievals_nomem;
56787+atomic_unchecked_t fscache_n_retrievals_object_dead;
56788+atomic_unchecked_t fscache_n_retrieval_ops;
56789+atomic_unchecked_t fscache_n_retrieval_op_waits;
56790
56791-atomic_t fscache_n_stores;
56792-atomic_t fscache_n_stores_ok;
56793-atomic_t fscache_n_stores_again;
56794-atomic_t fscache_n_stores_nobufs;
56795-atomic_t fscache_n_stores_oom;
56796-atomic_t fscache_n_store_ops;
56797-atomic_t fscache_n_store_calls;
56798-atomic_t fscache_n_store_pages;
56799-atomic_t fscache_n_store_radix_deletes;
56800-atomic_t fscache_n_store_pages_over_limit;
56801+atomic_unchecked_t fscache_n_stores;
56802+atomic_unchecked_t fscache_n_stores_ok;
56803+atomic_unchecked_t fscache_n_stores_again;
56804+atomic_unchecked_t fscache_n_stores_nobufs;
56805+atomic_unchecked_t fscache_n_stores_oom;
56806+atomic_unchecked_t fscache_n_store_ops;
56807+atomic_unchecked_t fscache_n_store_calls;
56808+atomic_unchecked_t fscache_n_store_pages;
56809+atomic_unchecked_t fscache_n_store_radix_deletes;
56810+atomic_unchecked_t fscache_n_store_pages_over_limit;
56811
56812-atomic_t fscache_n_store_vmscan_not_storing;
56813-atomic_t fscache_n_store_vmscan_gone;
56814-atomic_t fscache_n_store_vmscan_busy;
56815-atomic_t fscache_n_store_vmscan_cancelled;
56816-atomic_t fscache_n_store_vmscan_wait;
56817+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
56818+atomic_unchecked_t fscache_n_store_vmscan_gone;
56819+atomic_unchecked_t fscache_n_store_vmscan_busy;
56820+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
56821+atomic_unchecked_t fscache_n_store_vmscan_wait;
56822
56823-atomic_t fscache_n_marks;
56824-atomic_t fscache_n_uncaches;
56825+atomic_unchecked_t fscache_n_marks;
56826+atomic_unchecked_t fscache_n_uncaches;
56827
56828-atomic_t fscache_n_acquires;
56829-atomic_t fscache_n_acquires_null;
56830-atomic_t fscache_n_acquires_no_cache;
56831-atomic_t fscache_n_acquires_ok;
56832-atomic_t fscache_n_acquires_nobufs;
56833-atomic_t fscache_n_acquires_oom;
56834+atomic_unchecked_t fscache_n_acquires;
56835+atomic_unchecked_t fscache_n_acquires_null;
56836+atomic_unchecked_t fscache_n_acquires_no_cache;
56837+atomic_unchecked_t fscache_n_acquires_ok;
56838+atomic_unchecked_t fscache_n_acquires_nobufs;
56839+atomic_unchecked_t fscache_n_acquires_oom;
56840
56841-atomic_t fscache_n_invalidates;
56842-atomic_t fscache_n_invalidates_run;
56843+atomic_unchecked_t fscache_n_invalidates;
56844+atomic_unchecked_t fscache_n_invalidates_run;
56845
56846-atomic_t fscache_n_updates;
56847-atomic_t fscache_n_updates_null;
56848-atomic_t fscache_n_updates_run;
56849+atomic_unchecked_t fscache_n_updates;
56850+atomic_unchecked_t fscache_n_updates_null;
56851+atomic_unchecked_t fscache_n_updates_run;
56852
56853-atomic_t fscache_n_relinquishes;
56854-atomic_t fscache_n_relinquishes_null;
56855-atomic_t fscache_n_relinquishes_waitcrt;
56856-atomic_t fscache_n_relinquishes_retire;
56857+atomic_unchecked_t fscache_n_relinquishes;
56858+atomic_unchecked_t fscache_n_relinquishes_null;
56859+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
56860+atomic_unchecked_t fscache_n_relinquishes_retire;
56861
56862-atomic_t fscache_n_cookie_index;
56863-atomic_t fscache_n_cookie_data;
56864-atomic_t fscache_n_cookie_special;
56865+atomic_unchecked_t fscache_n_cookie_index;
56866+atomic_unchecked_t fscache_n_cookie_data;
56867+atomic_unchecked_t fscache_n_cookie_special;
56868
56869-atomic_t fscache_n_object_alloc;
56870-atomic_t fscache_n_object_no_alloc;
56871-atomic_t fscache_n_object_lookups;
56872-atomic_t fscache_n_object_lookups_negative;
56873-atomic_t fscache_n_object_lookups_positive;
56874-atomic_t fscache_n_object_lookups_timed_out;
56875-atomic_t fscache_n_object_created;
56876-atomic_t fscache_n_object_avail;
56877-atomic_t fscache_n_object_dead;
56878+atomic_unchecked_t fscache_n_object_alloc;
56879+atomic_unchecked_t fscache_n_object_no_alloc;
56880+atomic_unchecked_t fscache_n_object_lookups;
56881+atomic_unchecked_t fscache_n_object_lookups_negative;
56882+atomic_unchecked_t fscache_n_object_lookups_positive;
56883+atomic_unchecked_t fscache_n_object_lookups_timed_out;
56884+atomic_unchecked_t fscache_n_object_created;
56885+atomic_unchecked_t fscache_n_object_avail;
56886+atomic_unchecked_t fscache_n_object_dead;
56887
56888-atomic_t fscache_n_checkaux_none;
56889-atomic_t fscache_n_checkaux_okay;
56890-atomic_t fscache_n_checkaux_update;
56891-atomic_t fscache_n_checkaux_obsolete;
56892+atomic_unchecked_t fscache_n_checkaux_none;
56893+atomic_unchecked_t fscache_n_checkaux_okay;
56894+atomic_unchecked_t fscache_n_checkaux_update;
56895+atomic_unchecked_t fscache_n_checkaux_obsolete;
56896
56897 atomic_t fscache_n_cop_alloc_object;
56898 atomic_t fscache_n_cop_lookup_object;
56899@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
56900 seq_puts(m, "FS-Cache statistics\n");
56901
56902 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
56903- atomic_read(&fscache_n_cookie_index),
56904- atomic_read(&fscache_n_cookie_data),
56905- atomic_read(&fscache_n_cookie_special));
56906+ atomic_read_unchecked(&fscache_n_cookie_index),
56907+ atomic_read_unchecked(&fscache_n_cookie_data),
56908+ atomic_read_unchecked(&fscache_n_cookie_special));
56909
56910 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
56911- atomic_read(&fscache_n_object_alloc),
56912- atomic_read(&fscache_n_object_no_alloc),
56913- atomic_read(&fscache_n_object_avail),
56914- atomic_read(&fscache_n_object_dead));
56915+ atomic_read_unchecked(&fscache_n_object_alloc),
56916+ atomic_read_unchecked(&fscache_n_object_no_alloc),
56917+ atomic_read_unchecked(&fscache_n_object_avail),
56918+ atomic_read_unchecked(&fscache_n_object_dead));
56919 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
56920- atomic_read(&fscache_n_checkaux_none),
56921- atomic_read(&fscache_n_checkaux_okay),
56922- atomic_read(&fscache_n_checkaux_update),
56923- atomic_read(&fscache_n_checkaux_obsolete));
56924+ atomic_read_unchecked(&fscache_n_checkaux_none),
56925+ atomic_read_unchecked(&fscache_n_checkaux_okay),
56926+ atomic_read_unchecked(&fscache_n_checkaux_update),
56927+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
56928
56929 seq_printf(m, "Pages : mrk=%u unc=%u\n",
56930- atomic_read(&fscache_n_marks),
56931- atomic_read(&fscache_n_uncaches));
56932+ atomic_read_unchecked(&fscache_n_marks),
56933+ atomic_read_unchecked(&fscache_n_uncaches));
56934
56935 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
56936 " oom=%u\n",
56937- atomic_read(&fscache_n_acquires),
56938- atomic_read(&fscache_n_acquires_null),
56939- atomic_read(&fscache_n_acquires_no_cache),
56940- atomic_read(&fscache_n_acquires_ok),
56941- atomic_read(&fscache_n_acquires_nobufs),
56942- atomic_read(&fscache_n_acquires_oom));
56943+ atomic_read_unchecked(&fscache_n_acquires),
56944+ atomic_read_unchecked(&fscache_n_acquires_null),
56945+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
56946+ atomic_read_unchecked(&fscache_n_acquires_ok),
56947+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
56948+ atomic_read_unchecked(&fscache_n_acquires_oom));
56949
56950 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
56951- atomic_read(&fscache_n_object_lookups),
56952- atomic_read(&fscache_n_object_lookups_negative),
56953- atomic_read(&fscache_n_object_lookups_positive),
56954- atomic_read(&fscache_n_object_created),
56955- atomic_read(&fscache_n_object_lookups_timed_out));
56956+ atomic_read_unchecked(&fscache_n_object_lookups),
56957+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
56958+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
56959+ atomic_read_unchecked(&fscache_n_object_created),
56960+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
56961
56962 seq_printf(m, "Invals : n=%u run=%u\n",
56963- atomic_read(&fscache_n_invalidates),
56964- atomic_read(&fscache_n_invalidates_run));
56965+ atomic_read_unchecked(&fscache_n_invalidates),
56966+ atomic_read_unchecked(&fscache_n_invalidates_run));
56967
56968 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
56969- atomic_read(&fscache_n_updates),
56970- atomic_read(&fscache_n_updates_null),
56971- atomic_read(&fscache_n_updates_run));
56972+ atomic_read_unchecked(&fscache_n_updates),
56973+ atomic_read_unchecked(&fscache_n_updates_null),
56974+ atomic_read_unchecked(&fscache_n_updates_run));
56975
56976 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
56977- atomic_read(&fscache_n_relinquishes),
56978- atomic_read(&fscache_n_relinquishes_null),
56979- atomic_read(&fscache_n_relinquishes_waitcrt),
56980- atomic_read(&fscache_n_relinquishes_retire));
56981+ atomic_read_unchecked(&fscache_n_relinquishes),
56982+ atomic_read_unchecked(&fscache_n_relinquishes_null),
56983+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
56984+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
56985
56986 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
56987- atomic_read(&fscache_n_attr_changed),
56988- atomic_read(&fscache_n_attr_changed_ok),
56989- atomic_read(&fscache_n_attr_changed_nobufs),
56990- atomic_read(&fscache_n_attr_changed_nomem),
56991- atomic_read(&fscache_n_attr_changed_calls));
56992+ atomic_read_unchecked(&fscache_n_attr_changed),
56993+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
56994+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
56995+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
56996+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
56997
56998 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
56999- atomic_read(&fscache_n_allocs),
57000- atomic_read(&fscache_n_allocs_ok),
57001- atomic_read(&fscache_n_allocs_wait),
57002- atomic_read(&fscache_n_allocs_nobufs),
57003- atomic_read(&fscache_n_allocs_intr));
57004+ atomic_read_unchecked(&fscache_n_allocs),
57005+ atomic_read_unchecked(&fscache_n_allocs_ok),
57006+ atomic_read_unchecked(&fscache_n_allocs_wait),
57007+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
57008+ atomic_read_unchecked(&fscache_n_allocs_intr));
57009 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
57010- atomic_read(&fscache_n_alloc_ops),
57011- atomic_read(&fscache_n_alloc_op_waits),
57012- atomic_read(&fscache_n_allocs_object_dead));
57013+ atomic_read_unchecked(&fscache_n_alloc_ops),
57014+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
57015+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
57016
57017 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
57018 " int=%u oom=%u\n",
57019- atomic_read(&fscache_n_retrievals),
57020- atomic_read(&fscache_n_retrievals_ok),
57021- atomic_read(&fscache_n_retrievals_wait),
57022- atomic_read(&fscache_n_retrievals_nodata),
57023- atomic_read(&fscache_n_retrievals_nobufs),
57024- atomic_read(&fscache_n_retrievals_intr),
57025- atomic_read(&fscache_n_retrievals_nomem));
57026+ atomic_read_unchecked(&fscache_n_retrievals),
57027+ atomic_read_unchecked(&fscache_n_retrievals_ok),
57028+ atomic_read_unchecked(&fscache_n_retrievals_wait),
57029+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
57030+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
57031+ atomic_read_unchecked(&fscache_n_retrievals_intr),
57032+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
57033 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
57034- atomic_read(&fscache_n_retrieval_ops),
57035- atomic_read(&fscache_n_retrieval_op_waits),
57036- atomic_read(&fscache_n_retrievals_object_dead));
57037+ atomic_read_unchecked(&fscache_n_retrieval_ops),
57038+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
57039+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
57040
57041 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
57042- atomic_read(&fscache_n_stores),
57043- atomic_read(&fscache_n_stores_ok),
57044- atomic_read(&fscache_n_stores_again),
57045- atomic_read(&fscache_n_stores_nobufs),
57046- atomic_read(&fscache_n_stores_oom));
57047+ atomic_read_unchecked(&fscache_n_stores),
57048+ atomic_read_unchecked(&fscache_n_stores_ok),
57049+ atomic_read_unchecked(&fscache_n_stores_again),
57050+ atomic_read_unchecked(&fscache_n_stores_nobufs),
57051+ atomic_read_unchecked(&fscache_n_stores_oom));
57052 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
57053- atomic_read(&fscache_n_store_ops),
57054- atomic_read(&fscache_n_store_calls),
57055- atomic_read(&fscache_n_store_pages),
57056- atomic_read(&fscache_n_store_radix_deletes),
57057- atomic_read(&fscache_n_store_pages_over_limit));
57058+ atomic_read_unchecked(&fscache_n_store_ops),
57059+ atomic_read_unchecked(&fscache_n_store_calls),
57060+ atomic_read_unchecked(&fscache_n_store_pages),
57061+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
57062+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
57063
57064 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
57065- atomic_read(&fscache_n_store_vmscan_not_storing),
57066- atomic_read(&fscache_n_store_vmscan_gone),
57067- atomic_read(&fscache_n_store_vmscan_busy),
57068- atomic_read(&fscache_n_store_vmscan_cancelled),
57069- atomic_read(&fscache_n_store_vmscan_wait));
57070+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
57071+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
57072+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
57073+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
57074+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
57075
57076 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
57077- atomic_read(&fscache_n_op_pend),
57078- atomic_read(&fscache_n_op_run),
57079- atomic_read(&fscache_n_op_enqueue),
57080- atomic_read(&fscache_n_op_cancelled),
57081- atomic_read(&fscache_n_op_rejected));
57082+ atomic_read_unchecked(&fscache_n_op_pend),
57083+ atomic_read_unchecked(&fscache_n_op_run),
57084+ atomic_read_unchecked(&fscache_n_op_enqueue),
57085+ atomic_read_unchecked(&fscache_n_op_cancelled),
57086+ atomic_read_unchecked(&fscache_n_op_rejected));
57087 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
57088- atomic_read(&fscache_n_op_deferred_release),
57089- atomic_read(&fscache_n_op_release),
57090- atomic_read(&fscache_n_op_gc));
57091+ atomic_read_unchecked(&fscache_n_op_deferred_release),
57092+ atomic_read_unchecked(&fscache_n_op_release),
57093+ atomic_read_unchecked(&fscache_n_op_gc));
57094
57095 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
57096 atomic_read(&fscache_n_cop_alloc_object),
57097diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
57098index aef34b1..59bfd7b 100644
57099--- a/fs/fuse/cuse.c
57100+++ b/fs/fuse/cuse.c
57101@@ -600,10 +600,12 @@ static int __init cuse_init(void)
57102 INIT_LIST_HEAD(&cuse_conntbl[i]);
57103
57104 /* inherit and extend fuse_dev_operations */
57105- cuse_channel_fops = fuse_dev_operations;
57106- cuse_channel_fops.owner = THIS_MODULE;
57107- cuse_channel_fops.open = cuse_channel_open;
57108- cuse_channel_fops.release = cuse_channel_release;
57109+ pax_open_kernel();
57110+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
57111+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
57112+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
57113+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
57114+ pax_close_kernel();
57115
57116 cuse_class = class_create(THIS_MODULE, "cuse");
57117 if (IS_ERR(cuse_class))
57118diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
57119index 1d55f94..088da65 100644
57120--- a/fs/fuse/dev.c
57121+++ b/fs/fuse/dev.c
57122@@ -1339,7 +1339,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
57123 ret = 0;
57124 pipe_lock(pipe);
57125
57126- if (!pipe->readers) {
57127+ if (!atomic_read(&pipe->readers)) {
57128 send_sig(SIGPIPE, current, 0);
57129 if (!ret)
57130 ret = -EPIPE;
57131@@ -1364,7 +1364,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
57132 page_nr++;
57133 ret += buf->len;
57134
57135- if (pipe->files)
57136+ if (atomic_read(&pipe->files))
57137 do_wakeup = 1;
57138 }
57139
57140diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
57141index 8fec28f..cd40dba 100644
57142--- a/fs/fuse/dir.c
57143+++ b/fs/fuse/dir.c
57144@@ -1437,7 +1437,7 @@ static char *read_link(struct dentry *dentry)
57145 return link;
57146 }
57147
57148-static void free_link(char *link)
57149+static void free_link(const char *link)
57150 {
57151 if (!IS_ERR(link))
57152 free_page((unsigned long) link);
57153diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
57154index 64915ee..6bed500 100644
57155--- a/fs/gfs2/inode.c
57156+++ b/fs/gfs2/inode.c
57157@@ -1506,7 +1506,7 @@ out:
57158
57159 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
57160 {
57161- char *s = nd_get_link(nd);
57162+ const char *s = nd_get_link(nd);
57163 if (!IS_ERR(s))
57164 kfree(s);
57165 }
57166diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
57167index d19b30a..ef89c36 100644
57168--- a/fs/hugetlbfs/inode.c
57169+++ b/fs/hugetlbfs/inode.c
57170@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
57171 struct mm_struct *mm = current->mm;
57172 struct vm_area_struct *vma;
57173 struct hstate *h = hstate_file(file);
57174+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
57175 struct vm_unmapped_area_info info;
57176
57177 if (len & ~huge_page_mask(h))
57178@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
57179 return addr;
57180 }
57181
57182+#ifdef CONFIG_PAX_RANDMMAP
57183+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
57184+#endif
57185+
57186 if (addr) {
57187 addr = ALIGN(addr, huge_page_size(h));
57188 vma = find_vma(mm, addr);
57189- if (TASK_SIZE - len >= addr &&
57190- (!vma || addr + len <= vma->vm_start))
57191+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
57192 return addr;
57193 }
57194
57195 info.flags = 0;
57196 info.length = len;
57197 info.low_limit = TASK_UNMAPPED_BASE;
57198+
57199+#ifdef CONFIG_PAX_RANDMMAP
57200+ if (mm->pax_flags & MF_PAX_RANDMMAP)
57201+ info.low_limit += mm->delta_mmap;
57202+#endif
57203+
57204 info.high_limit = TASK_SIZE;
57205 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
57206 info.align_offset = 0;
57207@@ -908,7 +918,7 @@ static struct file_system_type hugetlbfs_fs_type = {
57208 };
57209 MODULE_ALIAS_FS("hugetlbfs");
57210
57211-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
57212+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
57213
57214 static int can_do_hugetlb_shm(void)
57215 {
57216diff --git a/fs/inode.c b/fs/inode.c
57217index d6dfb09..602e77e 100644
57218--- a/fs/inode.c
57219+++ b/fs/inode.c
57220@@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
57221
57222 #ifdef CONFIG_SMP
57223 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
57224- static atomic_t shared_last_ino;
57225- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
57226+ static atomic_unchecked_t shared_last_ino;
57227+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
57228
57229 res = next - LAST_INO_BATCH;
57230 }
57231diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
57232index 4a6cf28..d3a29d3 100644
57233--- a/fs/jffs2/erase.c
57234+++ b/fs/jffs2/erase.c
57235@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
57236 struct jffs2_unknown_node marker = {
57237 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
57238 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
57239- .totlen = cpu_to_je32(c->cleanmarker_size)
57240+ .totlen = cpu_to_je32(c->cleanmarker_size),
57241+ .hdr_crc = cpu_to_je32(0)
57242 };
57243
57244 jffs2_prealloc_raw_node_refs(c, jeb, 1);
57245diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
57246index a6597d6..41b30ec 100644
57247--- a/fs/jffs2/wbuf.c
57248+++ b/fs/jffs2/wbuf.c
57249@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
57250 {
57251 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
57252 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
57253- .totlen = constant_cpu_to_je32(8)
57254+ .totlen = constant_cpu_to_je32(8),
57255+ .hdr_crc = constant_cpu_to_je32(0)
57256 };
57257
57258 /*
57259diff --git a/fs/jfs/super.c b/fs/jfs/super.c
57260index 6669aa2..36b033d 100644
57261--- a/fs/jfs/super.c
57262+++ b/fs/jfs/super.c
57263@@ -882,7 +882,7 @@ static int __init init_jfs_fs(void)
57264
57265 jfs_inode_cachep =
57266 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
57267- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
57268+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
57269 init_once);
57270 if (jfs_inode_cachep == NULL)
57271 return -ENOMEM;
57272diff --git a/fs/libfs.c b/fs/libfs.c
57273index 3a3a9b5..3a9b074 100644
57274--- a/fs/libfs.c
57275+++ b/fs/libfs.c
57276@@ -150,6 +150,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
57277
57278 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
57279 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
57280+ char d_name[sizeof(next->d_iname)];
57281+ const unsigned char *name;
57282+
57283 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
57284 if (!simple_positive(next)) {
57285 spin_unlock(&next->d_lock);
57286@@ -158,7 +161,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
57287
57288 spin_unlock(&next->d_lock);
57289 spin_unlock(&dentry->d_lock);
57290- if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
57291+ name = next->d_name.name;
57292+ if (name == next->d_iname) {
57293+ memcpy(d_name, name, next->d_name.len);
57294+ name = d_name;
57295+ }
57296+ if (!dir_emit(ctx, name, next->d_name.len,
57297 next->d_inode->i_ino, dt_type(next->d_inode)))
57298 return 0;
57299 spin_lock(&dentry->d_lock);
57300diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
57301index acd3947..1f896e2 100644
57302--- a/fs/lockd/clntproc.c
57303+++ b/fs/lockd/clntproc.c
57304@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
57305 /*
57306 * Cookie counter for NLM requests
57307 */
57308-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
57309+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
57310
57311 void nlmclnt_next_cookie(struct nlm_cookie *c)
57312 {
57313- u32 cookie = atomic_inc_return(&nlm_cookie);
57314+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
57315
57316 memcpy(c->data, &cookie, 4);
57317 c->len=4;
57318diff --git a/fs/locks.c b/fs/locks.c
57319index b27a300..4156d0b 100644
57320--- a/fs/locks.c
57321+++ b/fs/locks.c
57322@@ -2183,16 +2183,16 @@ void locks_remove_flock(struct file *filp)
57323 return;
57324
57325 if (filp->f_op && filp->f_op->flock) {
57326- struct file_lock fl = {
57327+ struct file_lock flock = {
57328 .fl_pid = current->tgid,
57329 .fl_file = filp,
57330 .fl_flags = FL_FLOCK,
57331 .fl_type = F_UNLCK,
57332 .fl_end = OFFSET_MAX,
57333 };
57334- filp->f_op->flock(filp, F_SETLKW, &fl);
57335- if (fl.fl_ops && fl.fl_ops->fl_release_private)
57336- fl.fl_ops->fl_release_private(&fl);
57337+ filp->f_op->flock(filp, F_SETLKW, &flock);
57338+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
57339+ flock.fl_ops->fl_release_private(&flock);
57340 }
57341
57342 spin_lock(&inode->i_lock);
57343diff --git a/fs/namei.c b/fs/namei.c
57344index 7720fbd..7934bb2 100644
57345--- a/fs/namei.c
57346+++ b/fs/namei.c
57347@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
57348 if (ret != -EACCES)
57349 return ret;
57350
57351+#ifdef CONFIG_GRKERNSEC
57352+ /* we'll block if we have to log due to a denied capability use */
57353+ if (mask & MAY_NOT_BLOCK)
57354+ return -ECHILD;
57355+#endif
57356+
57357 if (S_ISDIR(inode->i_mode)) {
57358 /* DACs are overridable for directories */
57359- if (inode_capable(inode, CAP_DAC_OVERRIDE))
57360- return 0;
57361 if (!(mask & MAY_WRITE))
57362- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
57363+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
57364+ inode_capable(inode, CAP_DAC_READ_SEARCH))
57365 return 0;
57366+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
57367+ return 0;
57368 return -EACCES;
57369 }
57370 /*
57371+ * Searching includes executable on directories, else just read.
57372+ */
57373+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
57374+ if (mask == MAY_READ)
57375+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
57376+ inode_capable(inode, CAP_DAC_READ_SEARCH))
57377+ return 0;
57378+
57379+ /*
57380 * Read/write DACs are always overridable.
57381 * Executable DACs are overridable when there is
57382 * at least one exec bit set.
57383@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
57384 if (inode_capable(inode, CAP_DAC_OVERRIDE))
57385 return 0;
57386
57387- /*
57388- * Searching includes executable on directories, else just read.
57389- */
57390- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
57391- if (mask == MAY_READ)
57392- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
57393- return 0;
57394-
57395 return -EACCES;
57396 }
57397
57398@@ -820,7 +828,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
57399 {
57400 struct dentry *dentry = link->dentry;
57401 int error;
57402- char *s;
57403+ const char *s;
57404
57405 BUG_ON(nd->flags & LOOKUP_RCU);
57406
57407@@ -841,6 +849,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
57408 if (error)
57409 goto out_put_nd_path;
57410
57411+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
57412+ dentry->d_inode, dentry, nd->path.mnt)) {
57413+ error = -EACCES;
57414+ goto out_put_nd_path;
57415+ }
57416+
57417 nd->last_type = LAST_BIND;
57418 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
57419 error = PTR_ERR(*p);
57420@@ -1588,6 +1602,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
57421 if (res)
57422 break;
57423 res = walk_component(nd, path, LOOKUP_FOLLOW);
57424+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
57425+ res = -EACCES;
57426 put_link(nd, &link, cookie);
57427 } while (res > 0);
57428
57429@@ -1686,7 +1702,7 @@ EXPORT_SYMBOL(full_name_hash);
57430 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
57431 {
57432 unsigned long a, b, adata, bdata, mask, hash, len;
57433- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
57434+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
57435
57436 hash = a = 0;
57437 len = -sizeof(unsigned long);
57438@@ -1967,6 +1983,8 @@ static int path_lookupat(int dfd, const char *name,
57439 if (err)
57440 break;
57441 err = lookup_last(nd, &path);
57442+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
57443+ err = -EACCES;
57444 put_link(nd, &link, cookie);
57445 }
57446 }
57447@@ -1974,6 +1992,13 @@ static int path_lookupat(int dfd, const char *name,
57448 if (!err)
57449 err = complete_walk(nd);
57450
57451+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
57452+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
57453+ path_put(&nd->path);
57454+ err = -ENOENT;
57455+ }
57456+ }
57457+
57458 if (!err && nd->flags & LOOKUP_DIRECTORY) {
57459 if (!can_lookup(nd->inode)) {
57460 path_put(&nd->path);
57461@@ -2001,8 +2026,15 @@ static int filename_lookup(int dfd, struct filename *name,
57462 retval = path_lookupat(dfd, name->name,
57463 flags | LOOKUP_REVAL, nd);
57464
57465- if (likely(!retval))
57466+ if (likely(!retval)) {
57467 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
57468+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
57469+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
57470+ path_put(&nd->path);
57471+ return -ENOENT;
57472+ }
57473+ }
57474+ }
57475 return retval;
57476 }
57477
57478@@ -2380,6 +2412,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
57479 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
57480 return -EPERM;
57481
57482+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
57483+ return -EPERM;
57484+ if (gr_handle_rawio(inode))
57485+ return -EPERM;
57486+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
57487+ return -EACCES;
57488+
57489 return 0;
57490 }
57491
57492@@ -2601,7 +2640,7 @@ looked_up:
57493 * cleared otherwise prior to returning.
57494 */
57495 static int lookup_open(struct nameidata *nd, struct path *path,
57496- struct file *file,
57497+ struct path *link, struct file *file,
57498 const struct open_flags *op,
57499 bool got_write, int *opened)
57500 {
57501@@ -2636,6 +2675,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
57502 /* Negative dentry, just create the file */
57503 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
57504 umode_t mode = op->mode;
57505+
57506+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
57507+ error = -EACCES;
57508+ goto out_dput;
57509+ }
57510+
57511+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
57512+ error = -EACCES;
57513+ goto out_dput;
57514+ }
57515+
57516 if (!IS_POSIXACL(dir->d_inode))
57517 mode &= ~current_umask();
57518 /*
57519@@ -2657,6 +2707,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
57520 nd->flags & LOOKUP_EXCL);
57521 if (error)
57522 goto out_dput;
57523+ else
57524+ gr_handle_create(dentry, nd->path.mnt);
57525 }
57526 out_no_open:
57527 path->dentry = dentry;
57528@@ -2671,7 +2723,7 @@ out_dput:
57529 /*
57530 * Handle the last step of open()
57531 */
57532-static int do_last(struct nameidata *nd, struct path *path,
57533+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
57534 struct file *file, const struct open_flags *op,
57535 int *opened, struct filename *name)
57536 {
57537@@ -2721,6 +2773,15 @@ static int do_last(struct nameidata *nd, struct path *path,
57538 if (error)
57539 return error;
57540
57541+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
57542+ error = -ENOENT;
57543+ goto out;
57544+ }
57545+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
57546+ error = -EACCES;
57547+ goto out;
57548+ }
57549+
57550 audit_inode(name, dir, LOOKUP_PARENT);
57551 error = -EISDIR;
57552 /* trailing slashes? */
57553@@ -2740,7 +2801,7 @@ retry_lookup:
57554 */
57555 }
57556 mutex_lock(&dir->d_inode->i_mutex);
57557- error = lookup_open(nd, path, file, op, got_write, opened);
57558+ error = lookup_open(nd, path, link, file, op, got_write, opened);
57559 mutex_unlock(&dir->d_inode->i_mutex);
57560
57561 if (error <= 0) {
57562@@ -2764,11 +2825,28 @@ retry_lookup:
57563 goto finish_open_created;
57564 }
57565
57566+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
57567+ error = -ENOENT;
57568+ goto exit_dput;
57569+ }
57570+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
57571+ error = -EACCES;
57572+ goto exit_dput;
57573+ }
57574+
57575 /*
57576 * create/update audit record if it already exists.
57577 */
57578- if (path->dentry->d_inode)
57579+ if (path->dentry->d_inode) {
57580+ /* only check if O_CREAT is specified, all other checks need to go
57581+ into may_open */
57582+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
57583+ error = -EACCES;
57584+ goto exit_dput;
57585+ }
57586+
57587 audit_inode(name, path->dentry, 0);
57588+ }
57589
57590 /*
57591 * If atomic_open() acquired write access it is dropped now due to
57592@@ -2809,6 +2887,11 @@ finish_lookup:
57593 }
57594 }
57595 BUG_ON(inode != path->dentry->d_inode);
57596+ /* if we're resolving a symlink to another symlink */
57597+ if (link && gr_handle_symlink_owner(link, inode)) {
57598+ error = -EACCES;
57599+ goto out;
57600+ }
57601 return 1;
57602 }
57603
57604@@ -2818,7 +2901,6 @@ finish_lookup:
57605 save_parent.dentry = nd->path.dentry;
57606 save_parent.mnt = mntget(path->mnt);
57607 nd->path.dentry = path->dentry;
57608-
57609 }
57610 nd->inode = inode;
57611 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
57612@@ -2828,7 +2910,18 @@ finish_open:
57613 path_put(&save_parent);
57614 return error;
57615 }
57616+
57617+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
57618+ error = -ENOENT;
57619+ goto out;
57620+ }
57621+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
57622+ error = -EACCES;
57623+ goto out;
57624+ }
57625+
57626 audit_inode(name, nd->path.dentry, 0);
57627+
57628 error = -EISDIR;
57629 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
57630 goto out;
57631@@ -2991,7 +3084,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
57632 if (unlikely(error))
57633 goto out;
57634
57635- error = do_last(nd, &path, file, op, &opened, pathname);
57636+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
57637 while (unlikely(error > 0)) { /* trailing symlink */
57638 struct path link = path;
57639 void *cookie;
57640@@ -3009,7 +3102,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
57641 error = follow_link(&link, nd, &cookie);
57642 if (unlikely(error))
57643 break;
57644- error = do_last(nd, &path, file, op, &opened, pathname);
57645+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
57646 put_link(nd, &link, cookie);
57647 }
57648 out:
57649@@ -3109,8 +3202,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
57650 goto unlock;
57651
57652 error = -EEXIST;
57653- if (dentry->d_inode)
57654+ if (dentry->d_inode) {
57655+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
57656+ error = -ENOENT;
57657+ }
57658 goto fail;
57659+ }
57660 /*
57661 * Special case - lookup gave negative, but... we had foo/bar/
57662 * From the vfs_mknod() POV we just have a negative dentry -
57663@@ -3162,6 +3259,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
57664 }
57665 EXPORT_SYMBOL(user_path_create);
57666
57667+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
57668+{
57669+ struct filename *tmp = getname(pathname);
57670+ struct dentry *res;
57671+ if (IS_ERR(tmp))
57672+ return ERR_CAST(tmp);
57673+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
57674+ if (IS_ERR(res))
57675+ putname(tmp);
57676+ else
57677+ *to = tmp;
57678+ return res;
57679+}
57680+
57681 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
57682 {
57683 int error = may_create(dir, dentry);
57684@@ -3224,6 +3335,17 @@ retry:
57685
57686 if (!IS_POSIXACL(path.dentry->d_inode))
57687 mode &= ~current_umask();
57688+
57689+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
57690+ error = -EPERM;
57691+ goto out;
57692+ }
57693+
57694+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
57695+ error = -EACCES;
57696+ goto out;
57697+ }
57698+
57699 error = security_path_mknod(&path, dentry, mode, dev);
57700 if (error)
57701 goto out;
57702@@ -3240,6 +3362,8 @@ retry:
57703 break;
57704 }
57705 out:
57706+ if (!error)
57707+ gr_handle_create(dentry, path.mnt);
57708 done_path_create(&path, dentry);
57709 if (retry_estale(error, lookup_flags)) {
57710 lookup_flags |= LOOKUP_REVAL;
57711@@ -3292,9 +3416,16 @@ retry:
57712
57713 if (!IS_POSIXACL(path.dentry->d_inode))
57714 mode &= ~current_umask();
57715+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
57716+ error = -EACCES;
57717+ goto out;
57718+ }
57719 error = security_path_mkdir(&path, dentry, mode);
57720 if (!error)
57721 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
57722+ if (!error)
57723+ gr_handle_create(dentry, path.mnt);
57724+out:
57725 done_path_create(&path, dentry);
57726 if (retry_estale(error, lookup_flags)) {
57727 lookup_flags |= LOOKUP_REVAL;
57728@@ -3375,6 +3506,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
57729 struct filename *name;
57730 struct dentry *dentry;
57731 struct nameidata nd;
57732+ ino_t saved_ino = 0;
57733+ dev_t saved_dev = 0;
57734 unsigned int lookup_flags = 0;
57735 retry:
57736 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
57737@@ -3407,10 +3540,21 @@ retry:
57738 error = -ENOENT;
57739 goto exit3;
57740 }
57741+
57742+ saved_ino = dentry->d_inode->i_ino;
57743+ saved_dev = gr_get_dev_from_dentry(dentry);
57744+
57745+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
57746+ error = -EACCES;
57747+ goto exit3;
57748+ }
57749+
57750 error = security_path_rmdir(&nd.path, dentry);
57751 if (error)
57752 goto exit3;
57753 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
57754+ if (!error && (saved_dev || saved_ino))
57755+ gr_handle_delete(saved_ino, saved_dev);
57756 exit3:
57757 dput(dentry);
57758 exit2:
57759@@ -3476,6 +3620,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
57760 struct dentry *dentry;
57761 struct nameidata nd;
57762 struct inode *inode = NULL;
57763+ ino_t saved_ino = 0;
57764+ dev_t saved_dev = 0;
57765 unsigned int lookup_flags = 0;
57766 retry:
57767 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
57768@@ -3502,10 +3648,22 @@ retry:
57769 if (!inode)
57770 goto slashes;
57771 ihold(inode);
57772+
57773+ if (inode->i_nlink <= 1) {
57774+ saved_ino = inode->i_ino;
57775+ saved_dev = gr_get_dev_from_dentry(dentry);
57776+ }
57777+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
57778+ error = -EACCES;
57779+ goto exit2;
57780+ }
57781+
57782 error = security_path_unlink(&nd.path, dentry);
57783 if (error)
57784 goto exit2;
57785 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
57786+ if (!error && (saved_ino || saved_dev))
57787+ gr_handle_delete(saved_ino, saved_dev);
57788 exit2:
57789 dput(dentry);
57790 }
57791@@ -3583,9 +3741,17 @@ retry:
57792 if (IS_ERR(dentry))
57793 goto out_putname;
57794
57795+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
57796+ error = -EACCES;
57797+ goto out;
57798+ }
57799+
57800 error = security_path_symlink(&path, dentry, from->name);
57801 if (!error)
57802 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
57803+ if (!error)
57804+ gr_handle_create(dentry, path.mnt);
57805+out:
57806 done_path_create(&path, dentry);
57807 if (retry_estale(error, lookup_flags)) {
57808 lookup_flags |= LOOKUP_REVAL;
57809@@ -3665,6 +3831,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
57810 {
57811 struct dentry *new_dentry;
57812 struct path old_path, new_path;
57813+ struct filename *to = NULL;
57814 int how = 0;
57815 int error;
57816
57817@@ -3688,7 +3855,7 @@ retry:
57818 if (error)
57819 return error;
57820
57821- new_dentry = user_path_create(newdfd, newname, &new_path,
57822+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
57823 (how & LOOKUP_REVAL));
57824 error = PTR_ERR(new_dentry);
57825 if (IS_ERR(new_dentry))
57826@@ -3700,11 +3867,28 @@ retry:
57827 error = may_linkat(&old_path);
57828 if (unlikely(error))
57829 goto out_dput;
57830+
57831+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
57832+ old_path.dentry->d_inode,
57833+ old_path.dentry->d_inode->i_mode, to)) {
57834+ error = -EACCES;
57835+ goto out_dput;
57836+ }
57837+
57838+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
57839+ old_path.dentry, old_path.mnt, to)) {
57840+ error = -EACCES;
57841+ goto out_dput;
57842+ }
57843+
57844 error = security_path_link(old_path.dentry, &new_path, new_dentry);
57845 if (error)
57846 goto out_dput;
57847 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
57848+ if (!error)
57849+ gr_handle_create(new_dentry, new_path.mnt);
57850 out_dput:
57851+ putname(to);
57852 done_path_create(&new_path, new_dentry);
57853 if (retry_estale(error, how)) {
57854 how |= LOOKUP_REVAL;
57855@@ -3950,12 +4134,21 @@ retry:
57856 if (new_dentry == trap)
57857 goto exit5;
57858
57859+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
57860+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
57861+ to);
57862+ if (error)
57863+ goto exit5;
57864+
57865 error = security_path_rename(&oldnd.path, old_dentry,
57866 &newnd.path, new_dentry);
57867 if (error)
57868 goto exit5;
57869 error = vfs_rename(old_dir->d_inode, old_dentry,
57870 new_dir->d_inode, new_dentry);
57871+ if (!error)
57872+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
57873+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
57874 exit5:
57875 dput(new_dentry);
57876 exit4:
57877@@ -3987,6 +4180,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
57878
57879 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
57880 {
57881+ char tmpbuf[64];
57882+ const char *newlink;
57883 int len;
57884
57885 len = PTR_ERR(link);
57886@@ -3996,7 +4191,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
57887 len = strlen(link);
57888 if (len > (unsigned) buflen)
57889 len = buflen;
57890- if (copy_to_user(buffer, link, len))
57891+
57892+ if (len < sizeof(tmpbuf)) {
57893+ memcpy(tmpbuf, link, len);
57894+ newlink = tmpbuf;
57895+ } else
57896+ newlink = link;
57897+
57898+ if (copy_to_user(buffer, newlink, len))
57899 len = -EFAULT;
57900 out:
57901 return len;
57902diff --git a/fs/namespace.c b/fs/namespace.c
57903index a45ba4f..b4c7d07 100644
57904--- a/fs/namespace.c
57905+++ b/fs/namespace.c
57906@@ -1265,6 +1265,9 @@ static int do_umount(struct mount *mnt, int flags)
57907 if (!(sb->s_flags & MS_RDONLY))
57908 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
57909 up_write(&sb->s_umount);
57910+
57911+ gr_log_remount(mnt->mnt_devname, retval);
57912+
57913 return retval;
57914 }
57915
57916@@ -1283,6 +1286,9 @@ static int do_umount(struct mount *mnt, int flags)
57917 }
57918 br_write_unlock(&vfsmount_lock);
57919 namespace_unlock();
57920+
57921+ gr_log_unmount(mnt->mnt_devname, retval);
57922+
57923 return retval;
57924 }
57925
57926@@ -1302,7 +1308,7 @@ static inline bool may_mount(void)
57927 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
57928 */
57929
57930-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
57931+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
57932 {
57933 struct path path;
57934 struct mount *mnt;
57935@@ -1342,7 +1348,7 @@ out:
57936 /*
57937 * The 2.0 compatible umount. No flags.
57938 */
57939-SYSCALL_DEFINE1(oldumount, char __user *, name)
57940+SYSCALL_DEFINE1(oldumount, const char __user *, name)
57941 {
57942 return sys_umount(name, 0);
57943 }
57944@@ -2313,6 +2319,16 @@ long do_mount(const char *dev_name, const char *dir_name,
57945 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
57946 MS_STRICTATIME);
57947
57948+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
57949+ retval = -EPERM;
57950+ goto dput_out;
57951+ }
57952+
57953+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
57954+ retval = -EPERM;
57955+ goto dput_out;
57956+ }
57957+
57958 if (flags & MS_REMOUNT)
57959 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
57960 data_page);
57961@@ -2327,6 +2343,9 @@ long do_mount(const char *dev_name, const char *dir_name,
57962 dev_name, data_page);
57963 dput_out:
57964 path_put(&path);
57965+
57966+ gr_log_mount(dev_name, dir_name, retval);
57967+
57968 return retval;
57969 }
57970
57971@@ -2344,7 +2363,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
57972 * number incrementing at 10Ghz will take 12,427 years to wrap which
57973 * is effectively never, so we can ignore the possibility.
57974 */
57975-static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
57976+static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
57977
57978 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
57979 {
57980@@ -2359,7 +2378,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
57981 kfree(new_ns);
57982 return ERR_PTR(ret);
57983 }
57984- new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
57985+ new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
57986 atomic_set(&new_ns->count, 1);
57987 new_ns->root = NULL;
57988 INIT_LIST_HEAD(&new_ns->list);
57989@@ -2373,7 +2392,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
57990 * Allocate a new namespace structure and populate it with contents
57991 * copied from the namespace of the passed in task structure.
57992 */
57993-static struct mnt_namespace *dup_mnt_ns(struct mnt_namespace *mnt_ns,
57994+static __latent_entropy struct mnt_namespace *dup_mnt_ns(struct mnt_namespace *mnt_ns,
57995 struct user_namespace *user_ns, struct fs_struct *fs)
57996 {
57997 struct mnt_namespace *new_ns;
57998@@ -2500,8 +2519,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
57999 }
58000 EXPORT_SYMBOL(mount_subtree);
58001
58002-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
58003- char __user *, type, unsigned long, flags, void __user *, data)
58004+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
58005+ const char __user *, type, unsigned long, flags, void __user *, data)
58006 {
58007 int ret;
58008 char *kernel_type;
58009@@ -2614,6 +2633,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
58010 if (error)
58011 goto out2;
58012
58013+ if (gr_handle_chroot_pivot()) {
58014+ error = -EPERM;
58015+ goto out2;
58016+ }
58017+
58018 get_fs_root(current->fs, &root);
58019 old_mp = lock_mount(&old);
58020 error = PTR_ERR(old_mp);
58021@@ -2864,7 +2888,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
58022 !nsown_capable(CAP_SYS_ADMIN))
58023 return -EPERM;
58024
58025- if (fs->users != 1)
58026+ if (atomic_read(&fs->users) != 1)
58027 return -EINVAL;
58028
58029 get_mnt_ns(mnt_ns);
58030diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
58031index f4ccfe6..a5cf064 100644
58032--- a/fs/nfs/callback_xdr.c
58033+++ b/fs/nfs/callback_xdr.c
58034@@ -51,7 +51,7 @@ struct callback_op {
58035 callback_decode_arg_t decode_args;
58036 callback_encode_res_t encode_res;
58037 long res_maxsize;
58038-};
58039+} __do_const;
58040
58041 static struct callback_op callback_ops[];
58042
58043diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
58044index 941246f..17d8724 100644
58045--- a/fs/nfs/inode.c
58046+++ b/fs/nfs/inode.c
58047@@ -1138,16 +1138,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
58048 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
58049 }
58050
58051-static atomic_long_t nfs_attr_generation_counter;
58052+static atomic_long_unchecked_t nfs_attr_generation_counter;
58053
58054 static unsigned long nfs_read_attr_generation_counter(void)
58055 {
58056- return atomic_long_read(&nfs_attr_generation_counter);
58057+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
58058 }
58059
58060 unsigned long nfs_inc_attr_generation_counter(void)
58061 {
58062- return atomic_long_inc_return(&nfs_attr_generation_counter);
58063+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
58064 }
58065
58066 void nfs_fattr_init(struct nfs_fattr *fattr)
58067diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
58068index 419572f..5414a23 100644
58069--- a/fs/nfsd/nfs4proc.c
58070+++ b/fs/nfsd/nfs4proc.c
58071@@ -1168,7 +1168,7 @@ struct nfsd4_operation {
58072 nfsd4op_rsize op_rsize_bop;
58073 stateid_getter op_get_currentstateid;
58074 stateid_setter op_set_currentstateid;
58075-};
58076+} __do_const;
58077
58078 static struct nfsd4_operation nfsd4_ops[];
58079
58080diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
58081index c2a4701..fd80e29 100644
58082--- a/fs/nfsd/nfs4xdr.c
58083+++ b/fs/nfsd/nfs4xdr.c
58084@@ -1498,7 +1498,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
58085
58086 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
58087
58088-static nfsd4_dec nfsd4_dec_ops[] = {
58089+static const nfsd4_dec nfsd4_dec_ops[] = {
58090 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
58091 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
58092 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
58093@@ -1538,7 +1538,7 @@ static nfsd4_dec nfsd4_dec_ops[] = {
58094 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
58095 };
58096
58097-static nfsd4_dec nfsd41_dec_ops[] = {
58098+static const nfsd4_dec nfsd41_dec_ops[] = {
58099 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
58100 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
58101 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
58102@@ -1600,7 +1600,7 @@ static nfsd4_dec nfsd41_dec_ops[] = {
58103 };
58104
58105 struct nfsd4_minorversion_ops {
58106- nfsd4_dec *decoders;
58107+ const nfsd4_dec *decoders;
58108 int nops;
58109 };
58110
58111diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
58112index e76244e..9fe8f2f1 100644
58113--- a/fs/nfsd/nfscache.c
58114+++ b/fs/nfsd/nfscache.c
58115@@ -526,14 +526,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
58116 {
58117 struct svc_cacherep *rp = rqstp->rq_cacherep;
58118 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
58119- int len;
58120+ long len;
58121 size_t bufsize = 0;
58122
58123 if (!rp)
58124 return;
58125
58126- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
58127- len >>= 2;
58128+ if (statp) {
58129+ len = (char*)statp - (char*)resv->iov_base;
58130+ len = resv->iov_len - len;
58131+ len >>= 2;
58132+ }
58133
58134 /* Don't cache excessive amounts of data and XDR failures */
58135 if (!statp || len > (256 >> 2)) {
58136diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
58137index c827acb..b253b77 100644
58138--- a/fs/nfsd/vfs.c
58139+++ b/fs/nfsd/vfs.c
58140@@ -968,7 +968,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
58141 } else {
58142 oldfs = get_fs();
58143 set_fs(KERNEL_DS);
58144- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
58145+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
58146 set_fs(oldfs);
58147 }
58148
58149@@ -1055,7 +1055,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
58150
58151 /* Write the data. */
58152 oldfs = get_fs(); set_fs(KERNEL_DS);
58153- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
58154+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
58155 set_fs(oldfs);
58156 if (host_err < 0)
58157 goto out_nfserr;
58158@@ -1601,7 +1601,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
58159 */
58160
58161 oldfs = get_fs(); set_fs(KERNEL_DS);
58162- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
58163+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
58164 set_fs(oldfs);
58165
58166 if (host_err < 0)
58167diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
58168index fea6bd5..8ee9d81 100644
58169--- a/fs/nls/nls_base.c
58170+++ b/fs/nls/nls_base.c
58171@@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
58172
58173 int register_nls(struct nls_table * nls)
58174 {
58175- struct nls_table ** tmp = &tables;
58176+ struct nls_table *tmp = tables;
58177
58178 if (nls->next)
58179 return -EBUSY;
58180
58181 spin_lock(&nls_lock);
58182- while (*tmp) {
58183- if (nls == *tmp) {
58184+ while (tmp) {
58185+ if (nls == tmp) {
58186 spin_unlock(&nls_lock);
58187 return -EBUSY;
58188 }
58189- tmp = &(*tmp)->next;
58190+ tmp = tmp->next;
58191 }
58192- nls->next = tables;
58193+ pax_open_kernel();
58194+ *(struct nls_table **)&nls->next = tables;
58195+ pax_close_kernel();
58196 tables = nls;
58197 spin_unlock(&nls_lock);
58198 return 0;
58199@@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
58200
58201 int unregister_nls(struct nls_table * nls)
58202 {
58203- struct nls_table ** tmp = &tables;
58204+ struct nls_table * const * tmp = &tables;
58205
58206 spin_lock(&nls_lock);
58207 while (*tmp) {
58208 if (nls == *tmp) {
58209- *tmp = nls->next;
58210+ pax_open_kernel();
58211+ *(struct nls_table **)tmp = nls->next;
58212+ pax_close_kernel();
58213 spin_unlock(&nls_lock);
58214 return 0;
58215 }
58216diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
58217index 7424929..35f6be5 100644
58218--- a/fs/nls/nls_euc-jp.c
58219+++ b/fs/nls/nls_euc-jp.c
58220@@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
58221 p_nls = load_nls("cp932");
58222
58223 if (p_nls) {
58224- table.charset2upper = p_nls->charset2upper;
58225- table.charset2lower = p_nls->charset2lower;
58226+ pax_open_kernel();
58227+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
58228+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
58229+ pax_close_kernel();
58230 return register_nls(&table);
58231 }
58232
58233diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
58234index e7bc1d7..06bd4bb 100644
58235--- a/fs/nls/nls_koi8-ru.c
58236+++ b/fs/nls/nls_koi8-ru.c
58237@@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
58238 p_nls = load_nls("koi8-u");
58239
58240 if (p_nls) {
58241- table.charset2upper = p_nls->charset2upper;
58242- table.charset2lower = p_nls->charset2lower;
58243+ pax_open_kernel();
58244+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
58245+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
58246+ pax_close_kernel();
58247 return register_nls(&table);
58248 }
58249
58250diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
58251index e44cb64..4807084 100644
58252--- a/fs/notify/fanotify/fanotify_user.c
58253+++ b/fs/notify/fanotify/fanotify_user.c
58254@@ -253,8 +253,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
58255
58256 fd = fanotify_event_metadata.fd;
58257 ret = -EFAULT;
58258- if (copy_to_user(buf, &fanotify_event_metadata,
58259- fanotify_event_metadata.event_len))
58260+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
58261+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
58262 goto out_close_fd;
58263
58264 ret = prepare_for_access_response(group, event, fd);
58265diff --git a/fs/notify/notification.c b/fs/notify/notification.c
58266index 7b51b05..5ea5ef6 100644
58267--- a/fs/notify/notification.c
58268+++ b/fs/notify/notification.c
58269@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
58270 * get set to 0 so it will never get 'freed'
58271 */
58272 static struct fsnotify_event *q_overflow_event;
58273-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
58274+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
58275
58276 /**
58277 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
58278@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
58279 */
58280 u32 fsnotify_get_cookie(void)
58281 {
58282- return atomic_inc_return(&fsnotify_sync_cookie);
58283+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
58284 }
58285 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
58286
58287diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
58288index 9e38daf..5727cae 100644
58289--- a/fs/ntfs/dir.c
58290+++ b/fs/ntfs/dir.c
58291@@ -1310,7 +1310,7 @@ find_next_index_buffer:
58292 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
58293 ~(s64)(ndir->itype.index.block_size - 1)));
58294 /* Bounds checks. */
58295- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
58296+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
58297 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
58298 "inode 0x%lx or driver bug.", vdir->i_ino);
58299 goto err_out;
58300diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
58301index c5670b8..d590213 100644
58302--- a/fs/ntfs/file.c
58303+++ b/fs/ntfs/file.c
58304@@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
58305 char *addr;
58306 size_t total = 0;
58307 unsigned len;
58308- int left;
58309+ unsigned left;
58310
58311 do {
58312 len = PAGE_CACHE_SIZE - ofs;
58313diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
58314index 82650d5..db37dcf 100644
58315--- a/fs/ntfs/super.c
58316+++ b/fs/ntfs/super.c
58317@@ -685,7 +685,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
58318 if (!silent)
58319 ntfs_error(sb, "Primary boot sector is invalid.");
58320 } else if (!silent)
58321- ntfs_error(sb, read_err_str, "primary");
58322+ ntfs_error(sb, read_err_str, "%s", "primary");
58323 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
58324 if (bh_primary)
58325 brelse(bh_primary);
58326@@ -701,7 +701,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
58327 goto hotfix_primary_boot_sector;
58328 brelse(bh_backup);
58329 } else if (!silent)
58330- ntfs_error(sb, read_err_str, "backup");
58331+ ntfs_error(sb, read_err_str, "%s", "backup");
58332 /* Try to read NT3.51- backup boot sector. */
58333 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
58334 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
58335@@ -712,7 +712,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
58336 "sector.");
58337 brelse(bh_backup);
58338 } else if (!silent)
58339- ntfs_error(sb, read_err_str, "backup");
58340+ ntfs_error(sb, read_err_str, "%s", "backup");
58341 /* We failed. Cleanup and return. */
58342 if (bh_primary)
58343 brelse(bh_primary);
58344diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
58345index aebeacd..0dcdd26 100644
58346--- a/fs/ocfs2/localalloc.c
58347+++ b/fs/ocfs2/localalloc.c
58348@@ -1278,7 +1278,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
58349 goto bail;
58350 }
58351
58352- atomic_inc(&osb->alloc_stats.moves);
58353+ atomic_inc_unchecked(&osb->alloc_stats.moves);
58354
58355 bail:
58356 if (handle)
58357diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
58358index 3a90347..c40bef8 100644
58359--- a/fs/ocfs2/ocfs2.h
58360+++ b/fs/ocfs2/ocfs2.h
58361@@ -235,11 +235,11 @@ enum ocfs2_vol_state
58362
58363 struct ocfs2_alloc_stats
58364 {
58365- atomic_t moves;
58366- atomic_t local_data;
58367- atomic_t bitmap_data;
58368- atomic_t bg_allocs;
58369- atomic_t bg_extends;
58370+ atomic_unchecked_t moves;
58371+ atomic_unchecked_t local_data;
58372+ atomic_unchecked_t bitmap_data;
58373+ atomic_unchecked_t bg_allocs;
58374+ atomic_unchecked_t bg_extends;
58375 };
58376
58377 enum ocfs2_local_alloc_state
58378diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
58379index 5397c07..54afc55 100644
58380--- a/fs/ocfs2/suballoc.c
58381+++ b/fs/ocfs2/suballoc.c
58382@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
58383 mlog_errno(status);
58384 goto bail;
58385 }
58386- atomic_inc(&osb->alloc_stats.bg_extends);
58387+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
58388
58389 /* You should never ask for this much metadata */
58390 BUG_ON(bits_wanted >
58391@@ -2000,7 +2000,7 @@ int ocfs2_claim_metadata(handle_t *handle,
58392 mlog_errno(status);
58393 goto bail;
58394 }
58395- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58396+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58397
58398 *suballoc_loc = res.sr_bg_blkno;
58399 *suballoc_bit_start = res.sr_bit_offset;
58400@@ -2164,7 +2164,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
58401 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
58402 res->sr_bits);
58403
58404- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58405+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58406
58407 BUG_ON(res->sr_bits != 1);
58408
58409@@ -2206,7 +2206,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
58410 mlog_errno(status);
58411 goto bail;
58412 }
58413- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58414+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58415
58416 BUG_ON(res.sr_bits != 1);
58417
58418@@ -2310,7 +2310,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
58419 cluster_start,
58420 num_clusters);
58421 if (!status)
58422- atomic_inc(&osb->alloc_stats.local_data);
58423+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
58424 } else {
58425 if (min_clusters > (osb->bitmap_cpg - 1)) {
58426 /* The only paths asking for contiguousness
58427@@ -2336,7 +2336,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
58428 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
58429 res.sr_bg_blkno,
58430 res.sr_bit_offset);
58431- atomic_inc(&osb->alloc_stats.bitmap_data);
58432+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
58433 *num_clusters = res.sr_bits;
58434 }
58435 }
58436diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
58437index 121da2d..a0232bc 100644
58438--- a/fs/ocfs2/super.c
58439+++ b/fs/ocfs2/super.c
58440@@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
58441 "%10s => GlobalAllocs: %d LocalAllocs: %d "
58442 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
58443 "Stats",
58444- atomic_read(&osb->alloc_stats.bitmap_data),
58445- atomic_read(&osb->alloc_stats.local_data),
58446- atomic_read(&osb->alloc_stats.bg_allocs),
58447- atomic_read(&osb->alloc_stats.moves),
58448- atomic_read(&osb->alloc_stats.bg_extends));
58449+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
58450+ atomic_read_unchecked(&osb->alloc_stats.local_data),
58451+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
58452+ atomic_read_unchecked(&osb->alloc_stats.moves),
58453+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
58454
58455 out += snprintf(buf + out, len - out,
58456 "%10s => State: %u Descriptor: %llu Size: %u bits "
58457@@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
58458 spin_lock_init(&osb->osb_xattr_lock);
58459 ocfs2_init_steal_slots(osb);
58460
58461- atomic_set(&osb->alloc_stats.moves, 0);
58462- atomic_set(&osb->alloc_stats.local_data, 0);
58463- atomic_set(&osb->alloc_stats.bitmap_data, 0);
58464- atomic_set(&osb->alloc_stats.bg_allocs, 0);
58465- atomic_set(&osb->alloc_stats.bg_extends, 0);
58466+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
58467+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
58468+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
58469+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
58470+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
58471
58472 /* Copy the blockcheck stats from the superblock probe */
58473 osb->osb_ecc_stats = *stats;
58474diff --git a/fs/open.c b/fs/open.c
58475index 7931f76..7b03f3b 100644
58476--- a/fs/open.c
58477+++ b/fs/open.c
58478@@ -32,6 +32,8 @@
58479 #include <linux/dnotify.h>
58480 #include <linux/compat.h>
58481
58482+#define CREATE_TRACE_POINTS
58483+#include <trace/events/fs.h>
58484 #include "internal.h"
58485
58486 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
58487@@ -102,6 +104,8 @@ long vfs_truncate(struct path *path, loff_t length)
58488 error = locks_verify_truncate(inode, NULL, length);
58489 if (!error)
58490 error = security_path_truncate(path);
58491+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
58492+ error = -EACCES;
58493 if (!error)
58494 error = do_truncate(path->dentry, length, 0, NULL);
58495
58496@@ -186,6 +190,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
58497 error = locks_verify_truncate(inode, f.file, length);
58498 if (!error)
58499 error = security_path_truncate(&f.file->f_path);
58500+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
58501+ error = -EACCES;
58502 if (!error)
58503 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
58504 sb_end_write(inode->i_sb);
58505@@ -360,6 +366,9 @@ retry:
58506 if (__mnt_is_readonly(path.mnt))
58507 res = -EROFS;
58508
58509+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
58510+ res = -EACCES;
58511+
58512 out_path_release:
58513 path_put(&path);
58514 if (retry_estale(res, lookup_flags)) {
58515@@ -391,6 +400,8 @@ retry:
58516 if (error)
58517 goto dput_and_out;
58518
58519+ gr_log_chdir(path.dentry, path.mnt);
58520+
58521 set_fs_pwd(current->fs, &path);
58522
58523 dput_and_out:
58524@@ -420,6 +431,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
58525 goto out_putf;
58526
58527 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
58528+
58529+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
58530+ error = -EPERM;
58531+
58532+ if (!error)
58533+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
58534+
58535 if (!error)
58536 set_fs_pwd(current->fs, &f.file->f_path);
58537 out_putf:
58538@@ -449,7 +467,13 @@ retry:
58539 if (error)
58540 goto dput_and_out;
58541
58542+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
58543+ goto dput_and_out;
58544+
58545 set_fs_root(current->fs, &path);
58546+
58547+ gr_handle_chroot_chdir(&path);
58548+
58549 error = 0;
58550 dput_and_out:
58551 path_put(&path);
58552@@ -471,6 +495,16 @@ static int chmod_common(struct path *path, umode_t mode)
58553 if (error)
58554 return error;
58555 mutex_lock(&inode->i_mutex);
58556+
58557+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
58558+ error = -EACCES;
58559+ goto out_unlock;
58560+ }
58561+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
58562+ error = -EACCES;
58563+ goto out_unlock;
58564+ }
58565+
58566 error = security_path_chmod(path, mode);
58567 if (error)
58568 goto out_unlock;
58569@@ -531,6 +565,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
58570 uid = make_kuid(current_user_ns(), user);
58571 gid = make_kgid(current_user_ns(), group);
58572
58573+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
58574+ return -EACCES;
58575+
58576 newattrs.ia_valid = ATTR_CTIME;
58577 if (user != (uid_t) -1) {
58578 if (!uid_valid(uid))
58579@@ -960,6 +997,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
58580 } else {
58581 fsnotify_open(f);
58582 fd_install(fd, f);
58583+ trace_do_sys_open(tmp->name, flags, mode);
58584 }
58585 }
58586 putname(tmp);
58587diff --git a/fs/pipe.c b/fs/pipe.c
58588index d2c45e1..009fe1c 100644
58589--- a/fs/pipe.c
58590+++ b/fs/pipe.c
58591@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
58592
58593 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
58594 {
58595- if (pipe->files)
58596+ if (atomic_read(&pipe->files))
58597 mutex_lock_nested(&pipe->mutex, subclass);
58598 }
58599
58600@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
58601
58602 void pipe_unlock(struct pipe_inode_info *pipe)
58603 {
58604- if (pipe->files)
58605+ if (atomic_read(&pipe->files))
58606 mutex_unlock(&pipe->mutex);
58607 }
58608 EXPORT_SYMBOL(pipe_unlock);
58609@@ -449,9 +449,9 @@ redo:
58610 }
58611 if (bufs) /* More to do? */
58612 continue;
58613- if (!pipe->writers)
58614+ if (!atomic_read(&pipe->writers))
58615 break;
58616- if (!pipe->waiting_writers) {
58617+ if (!atomic_read(&pipe->waiting_writers)) {
58618 /* syscall merging: Usually we must not sleep
58619 * if O_NONBLOCK is set, or if we got some data.
58620 * But if a writer sleeps in kernel space, then
58621@@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
58622 ret = 0;
58623 __pipe_lock(pipe);
58624
58625- if (!pipe->readers) {
58626+ if (!atomic_read(&pipe->readers)) {
58627 send_sig(SIGPIPE, current, 0);
58628 ret = -EPIPE;
58629 goto out;
58630@@ -562,7 +562,7 @@ redo1:
58631 for (;;) {
58632 int bufs;
58633
58634- if (!pipe->readers) {
58635+ if (!atomic_read(&pipe->readers)) {
58636 send_sig(SIGPIPE, current, 0);
58637 if (!ret)
58638 ret = -EPIPE;
58639@@ -653,9 +653,9 @@ redo2:
58640 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58641 do_wakeup = 0;
58642 }
58643- pipe->waiting_writers++;
58644+ atomic_inc(&pipe->waiting_writers);
58645 pipe_wait(pipe);
58646- pipe->waiting_writers--;
58647+ atomic_dec(&pipe->waiting_writers);
58648 }
58649 out:
58650 __pipe_unlock(pipe);
58651@@ -709,7 +709,7 @@ pipe_poll(struct file *filp, poll_table *wait)
58652 mask = 0;
58653 if (filp->f_mode & FMODE_READ) {
58654 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
58655- if (!pipe->writers && filp->f_version != pipe->w_counter)
58656+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
58657 mask |= POLLHUP;
58658 }
58659
58660@@ -719,7 +719,7 @@ pipe_poll(struct file *filp, poll_table *wait)
58661 * Most Unices do not set POLLERR for FIFOs but on Linux they
58662 * behave exactly like pipes for poll().
58663 */
58664- if (!pipe->readers)
58665+ if (!atomic_read(&pipe->readers))
58666 mask |= POLLERR;
58667 }
58668
58669@@ -734,17 +734,17 @@ pipe_release(struct inode *inode, struct file *file)
58670
58671 __pipe_lock(pipe);
58672 if (file->f_mode & FMODE_READ)
58673- pipe->readers--;
58674+ atomic_dec(&pipe->readers);
58675 if (file->f_mode & FMODE_WRITE)
58676- pipe->writers--;
58677+ atomic_dec(&pipe->writers);
58678
58679- if (pipe->readers || pipe->writers) {
58680+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
58681 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
58682 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58683 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
58684 }
58685 spin_lock(&inode->i_lock);
58686- if (!--pipe->files) {
58687+ if (atomic_dec_and_test(&pipe->files)) {
58688 inode->i_pipe = NULL;
58689 kill = 1;
58690 }
58691@@ -811,7 +811,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
58692 kfree(pipe);
58693 }
58694
58695-static struct vfsmount *pipe_mnt __read_mostly;
58696+struct vfsmount *pipe_mnt __read_mostly;
58697
58698 /*
58699 * pipefs_dname() is called from d_path().
58700@@ -841,8 +841,9 @@ static struct inode * get_pipe_inode(void)
58701 goto fail_iput;
58702
58703 inode->i_pipe = pipe;
58704- pipe->files = 2;
58705- pipe->readers = pipe->writers = 1;
58706+ atomic_set(&pipe->files, 2);
58707+ atomic_set(&pipe->readers, 1);
58708+ atomic_set(&pipe->writers, 1);
58709 inode->i_fop = &pipefifo_fops;
58710
58711 /*
58712@@ -1022,17 +1023,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
58713 spin_lock(&inode->i_lock);
58714 if (inode->i_pipe) {
58715 pipe = inode->i_pipe;
58716- pipe->files++;
58717+ atomic_inc(&pipe->files);
58718 spin_unlock(&inode->i_lock);
58719 } else {
58720 spin_unlock(&inode->i_lock);
58721 pipe = alloc_pipe_info();
58722 if (!pipe)
58723 return -ENOMEM;
58724- pipe->files = 1;
58725+ atomic_set(&pipe->files, 1);
58726 spin_lock(&inode->i_lock);
58727 if (unlikely(inode->i_pipe)) {
58728- inode->i_pipe->files++;
58729+ atomic_inc(&inode->i_pipe->files);
58730 spin_unlock(&inode->i_lock);
58731 free_pipe_info(pipe);
58732 pipe = inode->i_pipe;
58733@@ -1057,10 +1058,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
58734 * opened, even when there is no process writing the FIFO.
58735 */
58736 pipe->r_counter++;
58737- if (pipe->readers++ == 0)
58738+ if (atomic_inc_return(&pipe->readers) == 1)
58739 wake_up_partner(pipe);
58740
58741- if (!is_pipe && !pipe->writers) {
58742+ if (!is_pipe && !atomic_read(&pipe->writers)) {
58743 if ((filp->f_flags & O_NONBLOCK)) {
58744 /* suppress POLLHUP until we have
58745 * seen a writer */
58746@@ -1079,14 +1080,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
58747 * errno=ENXIO when there is no process reading the FIFO.
58748 */
58749 ret = -ENXIO;
58750- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
58751+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
58752 goto err;
58753
58754 pipe->w_counter++;
58755- if (!pipe->writers++)
58756+ if (atomic_inc_return(&pipe->writers) == 1)
58757 wake_up_partner(pipe);
58758
58759- if (!is_pipe && !pipe->readers) {
58760+ if (!is_pipe && !atomic_read(&pipe->readers)) {
58761 if (wait_for_partner(pipe, &pipe->r_counter))
58762 goto err_wr;
58763 }
58764@@ -1100,11 +1101,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
58765 * the process can at least talk to itself.
58766 */
58767
58768- pipe->readers++;
58769- pipe->writers++;
58770+ atomic_inc(&pipe->readers);
58771+ atomic_inc(&pipe->writers);
58772 pipe->r_counter++;
58773 pipe->w_counter++;
58774- if (pipe->readers == 1 || pipe->writers == 1)
58775+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
58776 wake_up_partner(pipe);
58777 break;
58778
58779@@ -1118,20 +1119,20 @@ static int fifo_open(struct inode *inode, struct file *filp)
58780 return 0;
58781
58782 err_rd:
58783- if (!--pipe->readers)
58784+ if (atomic_dec_and_test(&pipe->readers))
58785 wake_up_interruptible(&pipe->wait);
58786 ret = -ERESTARTSYS;
58787 goto err;
58788
58789 err_wr:
58790- if (!--pipe->writers)
58791+ if (atomic_dec_and_test(&pipe->writers))
58792 wake_up_interruptible(&pipe->wait);
58793 ret = -ERESTARTSYS;
58794 goto err;
58795
58796 err:
58797 spin_lock(&inode->i_lock);
58798- if (!--pipe->files) {
58799+ if (atomic_dec_and_test(&pipe->files)) {
58800 inode->i_pipe = NULL;
58801 kill = 1;
58802 }
58803diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
58804index 15af622..0e9f4467 100644
58805--- a/fs/proc/Kconfig
58806+++ b/fs/proc/Kconfig
58807@@ -30,12 +30,12 @@ config PROC_FS
58808
58809 config PROC_KCORE
58810 bool "/proc/kcore support" if !ARM
58811- depends on PROC_FS && MMU
58812+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
58813
58814 config PROC_VMCORE
58815 bool "/proc/vmcore support"
58816- depends on PROC_FS && CRASH_DUMP
58817- default y
58818+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
58819+ default n
58820 help
58821 Exports the dump image of crashed kernel in ELF format.
58822
58823@@ -59,8 +59,8 @@ config PROC_SYSCTL
58824 limited in memory.
58825
58826 config PROC_PAGE_MONITOR
58827- default y
58828- depends on PROC_FS && MMU
58829+ default n
58830+ depends on PROC_FS && MMU && !GRKERNSEC
58831 bool "Enable /proc page monitoring" if EXPERT
58832 help
58833 Various /proc files exist to monitor process memory utilization:
58834diff --git a/fs/proc/array.c b/fs/proc/array.c
58835index cbd0f1b..adec3f0 100644
58836--- a/fs/proc/array.c
58837+++ b/fs/proc/array.c
58838@@ -60,6 +60,7 @@
58839 #include <linux/tty.h>
58840 #include <linux/string.h>
58841 #include <linux/mman.h>
58842+#include <linux/grsecurity.h>
58843 #include <linux/proc_fs.h>
58844 #include <linux/ioport.h>
58845 #include <linux/uaccess.h>
58846@@ -363,6 +364,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
58847 seq_putc(m, '\n');
58848 }
58849
58850+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58851+static inline void task_pax(struct seq_file *m, struct task_struct *p)
58852+{
58853+ if (p->mm)
58854+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
58855+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
58856+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
58857+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
58858+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
58859+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
58860+ else
58861+ seq_printf(m, "PaX:\t-----\n");
58862+}
58863+#endif
58864+
58865 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
58866 struct pid *pid, struct task_struct *task)
58867 {
58868@@ -381,9 +397,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
58869 task_cpus_allowed(m, task);
58870 cpuset_task_status_allowed(m, task);
58871 task_context_switch_counts(m, task);
58872+
58873+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58874+ task_pax(m, task);
58875+#endif
58876+
58877+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
58878+ task_grsec_rbac(m, task);
58879+#endif
58880+
58881 return 0;
58882 }
58883
58884+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58885+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
58886+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
58887+ _mm->pax_flags & MF_PAX_SEGMEXEC))
58888+#endif
58889+
58890 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
58891 struct pid *pid, struct task_struct *task, int whole)
58892 {
58893@@ -405,6 +436,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
58894 char tcomm[sizeof(task->comm)];
58895 unsigned long flags;
58896
58897+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58898+ if (current->exec_id != m->exec_id) {
58899+ gr_log_badprocpid("stat");
58900+ return 0;
58901+ }
58902+#endif
58903+
58904 state = *get_task_state(task);
58905 vsize = eip = esp = 0;
58906 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
58907@@ -476,6 +514,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
58908 gtime = task_gtime(task);
58909 }
58910
58911+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58912+ if (PAX_RAND_FLAGS(mm)) {
58913+ eip = 0;
58914+ esp = 0;
58915+ wchan = 0;
58916+ }
58917+#endif
58918+#ifdef CONFIG_GRKERNSEC_HIDESYM
58919+ wchan = 0;
58920+ eip =0;
58921+ esp =0;
58922+#endif
58923+
58924 /* scale priority and nice values from timeslices to -20..20 */
58925 /* to make it look like a "normal" Unix priority/nice value */
58926 priority = task_prio(task);
58927@@ -512,9 +563,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
58928 seq_put_decimal_ull(m, ' ', vsize);
58929 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
58930 seq_put_decimal_ull(m, ' ', rsslim);
58931+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58932+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
58933+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
58934+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
58935+#else
58936 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
58937 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
58938 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
58939+#endif
58940 seq_put_decimal_ull(m, ' ', esp);
58941 seq_put_decimal_ull(m, ' ', eip);
58942 /* The signal information here is obsolete.
58943@@ -536,7 +593,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
58944 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
58945 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
58946
58947- if (mm && permitted) {
58948+ if (mm && permitted
58949+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58950+ && !PAX_RAND_FLAGS(mm)
58951+#endif
58952+ ) {
58953 seq_put_decimal_ull(m, ' ', mm->start_data);
58954 seq_put_decimal_ull(m, ' ', mm->end_data);
58955 seq_put_decimal_ull(m, ' ', mm->start_brk);
58956@@ -574,8 +635,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
58957 struct pid *pid, struct task_struct *task)
58958 {
58959 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
58960- struct mm_struct *mm = get_task_mm(task);
58961+ struct mm_struct *mm;
58962
58963+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58964+ if (current->exec_id != m->exec_id) {
58965+ gr_log_badprocpid("statm");
58966+ return 0;
58967+ }
58968+#endif
58969+ mm = get_task_mm(task);
58970 if (mm) {
58971 size = task_statm(mm, &shared, &text, &data, &resident);
58972 mmput(mm);
58973@@ -598,6 +666,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
58974 return 0;
58975 }
58976
58977+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
58978+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
58979+{
58980+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
58981+}
58982+#endif
58983+
58984 #ifdef CONFIG_CHECKPOINT_RESTORE
58985 static struct pid *
58986 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
58987diff --git a/fs/proc/base.c b/fs/proc/base.c
58988index 1485e38..8ad4236 100644
58989--- a/fs/proc/base.c
58990+++ b/fs/proc/base.c
58991@@ -113,6 +113,14 @@ struct pid_entry {
58992 union proc_op op;
58993 };
58994
58995+struct getdents_callback {
58996+ struct linux_dirent __user * current_dir;
58997+ struct linux_dirent __user * previous;
58998+ struct file * file;
58999+ int count;
59000+ int error;
59001+};
59002+
59003 #define NOD(NAME, MODE, IOP, FOP, OP) { \
59004 .name = (NAME), \
59005 .len = sizeof(NAME) - 1, \
59006@@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
59007 if (!mm->arg_end)
59008 goto out_mm; /* Shh! No looking before we're done */
59009
59010+ if (gr_acl_handle_procpidmem(task))
59011+ goto out_mm;
59012+
59013 len = mm->arg_end - mm->arg_start;
59014
59015 if (len > PAGE_SIZE)
59016@@ -237,12 +248,28 @@ out:
59017 return res;
59018 }
59019
59020+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59021+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
59022+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
59023+ _mm->pax_flags & MF_PAX_SEGMEXEC))
59024+#endif
59025+
59026 static int proc_pid_auxv(struct task_struct *task, char *buffer)
59027 {
59028 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
59029 int res = PTR_ERR(mm);
59030 if (mm && !IS_ERR(mm)) {
59031 unsigned int nwords = 0;
59032+
59033+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59034+ /* allow if we're currently ptracing this task */
59035+ if (PAX_RAND_FLAGS(mm) &&
59036+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
59037+ mmput(mm);
59038+ return 0;
59039+ }
59040+#endif
59041+
59042 do {
59043 nwords += 2;
59044 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
59045@@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
59046 }
59047
59048
59049-#ifdef CONFIG_KALLSYMS
59050+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59051 /*
59052 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
59053 * Returns the resolved symbol. If that fails, simply return the address.
59054@@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
59055 mutex_unlock(&task->signal->cred_guard_mutex);
59056 }
59057
59058-#ifdef CONFIG_STACKTRACE
59059+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59060
59061 #define MAX_STACK_TRACE_DEPTH 64
59062
59063@@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
59064 return count;
59065 }
59066
59067-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
59068+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
59069 static int proc_pid_syscall(struct task_struct *task, char *buffer)
59070 {
59071 long nr;
59072@@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
59073 /************************************************************************/
59074
59075 /* permission checks */
59076-static int proc_fd_access_allowed(struct inode *inode)
59077+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
59078 {
59079 struct task_struct *task;
59080 int allowed = 0;
59081@@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
59082 */
59083 task = get_proc_task(inode);
59084 if (task) {
59085- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
59086+ if (log)
59087+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
59088+ else
59089+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
59090 put_task_struct(task);
59091 }
59092 return allowed;
59093@@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
59094 struct task_struct *task,
59095 int hide_pid_min)
59096 {
59097+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59098+ return false;
59099+
59100+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59101+ rcu_read_lock();
59102+ {
59103+ const struct cred *tmpcred = current_cred();
59104+ const struct cred *cred = __task_cred(task);
59105+
59106+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
59107+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59108+ || in_group_p(grsec_proc_gid)
59109+#endif
59110+ ) {
59111+ rcu_read_unlock();
59112+ return true;
59113+ }
59114+ }
59115+ rcu_read_unlock();
59116+
59117+ if (!pid->hide_pid)
59118+ return false;
59119+#endif
59120+
59121 if (pid->hide_pid < hide_pid_min)
59122 return true;
59123 if (in_group_p(pid->pid_gid))
59124 return true;
59125+
59126 return ptrace_may_access(task, PTRACE_MODE_READ);
59127 }
59128
59129@@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
59130 put_task_struct(task);
59131
59132 if (!has_perms) {
59133+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59134+ {
59135+#else
59136 if (pid->hide_pid == 2) {
59137+#endif
59138 /*
59139 * Let's make getdents(), stat(), and open()
59140 * consistent with each other. If a process
59141@@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
59142 if (!task)
59143 return -ESRCH;
59144
59145+ if (gr_acl_handle_procpidmem(task)) {
59146+ put_task_struct(task);
59147+ return -EPERM;
59148+ }
59149+
59150 mm = mm_access(task, mode);
59151 put_task_struct(task);
59152
59153@@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
59154
59155 file->private_data = mm;
59156
59157+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59158+ file->f_version = current->exec_id;
59159+#endif
59160+
59161 return 0;
59162 }
59163
59164@@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
59165 ssize_t copied;
59166 char *page;
59167
59168+#ifdef CONFIG_GRKERNSEC
59169+ if (write)
59170+ return -EPERM;
59171+#endif
59172+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59173+ if (file->f_version != current->exec_id) {
59174+ gr_log_badprocpid("mem");
59175+ return 0;
59176+ }
59177+#endif
59178+
59179 if (!mm)
59180 return 0;
59181
59182@@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
59183 goto free;
59184
59185 while (count > 0) {
59186- int this_len = min_t(int, count, PAGE_SIZE);
59187+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
59188
59189 if (write && copy_from_user(page, buf, this_len)) {
59190 copied = -EFAULT;
59191@@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
59192 if (!mm)
59193 return 0;
59194
59195+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59196+ if (file->f_version != current->exec_id) {
59197+ gr_log_badprocpid("environ");
59198+ return 0;
59199+ }
59200+#endif
59201+
59202 page = (char *)__get_free_page(GFP_TEMPORARY);
59203 if (!page)
59204 return -ENOMEM;
59205@@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
59206 goto free;
59207 while (count > 0) {
59208 size_t this_len, max_len;
59209- int retval;
59210+ ssize_t retval;
59211
59212 if (src >= (mm->env_end - mm->env_start))
59213 break;
59214@@ -1461,7 +1547,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
59215 int error = -EACCES;
59216
59217 /* Are we allowed to snoop on the tasks file descriptors? */
59218- if (!proc_fd_access_allowed(inode))
59219+ if (!proc_fd_access_allowed(inode, 0))
59220 goto out;
59221
59222 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
59223@@ -1505,8 +1591,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
59224 struct path path;
59225
59226 /* Are we allowed to snoop on the tasks file descriptors? */
59227- if (!proc_fd_access_allowed(inode))
59228- goto out;
59229+ /* logging this is needed for learning on chromium to work properly,
59230+ but we don't want to flood the logs from 'ps' which does a readlink
59231+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
59232+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
59233+ */
59234+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
59235+ if (!proc_fd_access_allowed(inode,0))
59236+ goto out;
59237+ } else {
59238+ if (!proc_fd_access_allowed(inode,1))
59239+ goto out;
59240+ }
59241
59242 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
59243 if (error)
59244@@ -1556,7 +1652,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
59245 rcu_read_lock();
59246 cred = __task_cred(task);
59247 inode->i_uid = cred->euid;
59248+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59249+ inode->i_gid = grsec_proc_gid;
59250+#else
59251 inode->i_gid = cred->egid;
59252+#endif
59253 rcu_read_unlock();
59254 }
59255 security_task_to_inode(task, inode);
59256@@ -1592,10 +1692,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
59257 return -ENOENT;
59258 }
59259 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
59260+#ifdef CONFIG_GRKERNSEC_PROC_USER
59261+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
59262+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59263+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
59264+#endif
59265 task_dumpable(task)) {
59266 cred = __task_cred(task);
59267 stat->uid = cred->euid;
59268+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59269+ stat->gid = grsec_proc_gid;
59270+#else
59271 stat->gid = cred->egid;
59272+#endif
59273 }
59274 }
59275 rcu_read_unlock();
59276@@ -1633,11 +1742,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
59277
59278 if (task) {
59279 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
59280+#ifdef CONFIG_GRKERNSEC_PROC_USER
59281+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
59282+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59283+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
59284+#endif
59285 task_dumpable(task)) {
59286 rcu_read_lock();
59287 cred = __task_cred(task);
59288 inode->i_uid = cred->euid;
59289+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59290+ inode->i_gid = grsec_proc_gid;
59291+#else
59292 inode->i_gid = cred->egid;
59293+#endif
59294 rcu_read_unlock();
59295 } else {
59296 inode->i_uid = GLOBAL_ROOT_UID;
59297@@ -2166,6 +2284,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
59298 if (!task)
59299 goto out_no_task;
59300
59301+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59302+ goto out;
59303+
59304 /*
59305 * Yes, it does not scale. And it should not. Don't add
59306 * new entries into /proc/<tgid>/ without very good reasons.
59307@@ -2196,6 +2317,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
59308 if (!task)
59309 return -ENOENT;
59310
59311+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59312+ goto out;
59313+
59314 if (!dir_emit_dots(file, ctx))
59315 goto out;
59316
59317@@ -2585,7 +2709,7 @@ static const struct pid_entry tgid_base_stuff[] = {
59318 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
59319 #endif
59320 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
59321-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
59322+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
59323 INF("syscall", S_IRUGO, proc_pid_syscall),
59324 #endif
59325 INF("cmdline", S_IRUGO, proc_pid_cmdline),
59326@@ -2610,10 +2734,10 @@ static const struct pid_entry tgid_base_stuff[] = {
59327 #ifdef CONFIG_SECURITY
59328 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
59329 #endif
59330-#ifdef CONFIG_KALLSYMS
59331+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59332 INF("wchan", S_IRUGO, proc_pid_wchan),
59333 #endif
59334-#ifdef CONFIG_STACKTRACE
59335+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59336 ONE("stack", S_IRUGO, proc_pid_stack),
59337 #endif
59338 #ifdef CONFIG_SCHEDSTATS
59339@@ -2647,6 +2771,9 @@ static const struct pid_entry tgid_base_stuff[] = {
59340 #ifdef CONFIG_HARDWALL
59341 INF("hardwall", S_IRUGO, proc_pid_hardwall),
59342 #endif
59343+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
59344+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
59345+#endif
59346 #ifdef CONFIG_USER_NS
59347 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
59348 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
59349@@ -2777,7 +2904,14 @@ static int proc_pid_instantiate(struct inode *dir,
59350 if (!inode)
59351 goto out;
59352
59353+#ifdef CONFIG_GRKERNSEC_PROC_USER
59354+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
59355+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59356+ inode->i_gid = grsec_proc_gid;
59357+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
59358+#else
59359 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
59360+#endif
59361 inode->i_op = &proc_tgid_base_inode_operations;
59362 inode->i_fop = &proc_tgid_base_operations;
59363 inode->i_flags|=S_IMMUTABLE;
59364@@ -2815,7 +2949,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
59365 if (!task)
59366 goto out;
59367
59368+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59369+ goto out_put_task;
59370+
59371 result = proc_pid_instantiate(dir, dentry, task, NULL);
59372+out_put_task:
59373 put_task_struct(task);
59374 out:
59375 return ERR_PTR(result);
59376@@ -2921,7 +3059,7 @@ static const struct pid_entry tid_base_stuff[] = {
59377 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
59378 #endif
59379 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
59380-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
59381+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
59382 INF("syscall", S_IRUGO, proc_pid_syscall),
59383 #endif
59384 INF("cmdline", S_IRUGO, proc_pid_cmdline),
59385@@ -2948,10 +3086,10 @@ static const struct pid_entry tid_base_stuff[] = {
59386 #ifdef CONFIG_SECURITY
59387 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
59388 #endif
59389-#ifdef CONFIG_KALLSYMS
59390+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59391 INF("wchan", S_IRUGO, proc_pid_wchan),
59392 #endif
59393-#ifdef CONFIG_STACKTRACE
59394+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59395 ONE("stack", S_IRUGO, proc_pid_stack),
59396 #endif
59397 #ifdef CONFIG_SCHEDSTATS
59398diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
59399index 82676e3..5f8518a 100644
59400--- a/fs/proc/cmdline.c
59401+++ b/fs/proc/cmdline.c
59402@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
59403
59404 static int __init proc_cmdline_init(void)
59405 {
59406+#ifdef CONFIG_GRKERNSEC_PROC_ADD
59407+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
59408+#else
59409 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
59410+#endif
59411 return 0;
59412 }
59413 module_init(proc_cmdline_init);
59414diff --git a/fs/proc/devices.c b/fs/proc/devices.c
59415index b143471..bb105e5 100644
59416--- a/fs/proc/devices.c
59417+++ b/fs/proc/devices.c
59418@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
59419
59420 static int __init proc_devices_init(void)
59421 {
59422+#ifdef CONFIG_GRKERNSEC_PROC_ADD
59423+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
59424+#else
59425 proc_create("devices", 0, NULL, &proc_devinfo_operations);
59426+#endif
59427 return 0;
59428 }
59429 module_init(proc_devices_init);
59430diff --git a/fs/proc/fd.c b/fs/proc/fd.c
59431index 0ff80f9..a1d7500 100644
59432--- a/fs/proc/fd.c
59433+++ b/fs/proc/fd.c
59434@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
59435 if (!task)
59436 return -ENOENT;
59437
59438- files = get_files_struct(task);
59439+ if (!gr_acl_handle_procpidmem(task))
59440+ files = get_files_struct(task);
59441 put_task_struct(task);
59442
59443 if (files) {
59444@@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
59445 */
59446 int proc_fd_permission(struct inode *inode, int mask)
59447 {
59448+ struct task_struct *task;
59449 int rv = generic_permission(inode, mask);
59450- if (rv == 0)
59451- return 0;
59452+
59453 if (task_pid(current) == proc_pid(inode))
59454 rv = 0;
59455+
59456+ task = get_proc_task(inode);
59457+ if (task == NULL)
59458+ return rv;
59459+
59460+ if (gr_acl_handle_procpidmem(task))
59461+ rv = -EACCES;
59462+
59463+ put_task_struct(task);
59464+
59465 return rv;
59466 }
59467
59468diff --git a/fs/proc/inode.c b/fs/proc/inode.c
59469index 073aea6..0630370 100644
59470--- a/fs/proc/inode.c
59471+++ b/fs/proc/inode.c
59472@@ -23,11 +23,17 @@
59473 #include <linux/slab.h>
59474 #include <linux/mount.h>
59475 #include <linux/magic.h>
59476+#include <linux/grsecurity.h>
59477
59478 #include <asm/uaccess.h>
59479
59480 #include "internal.h"
59481
59482+#ifdef CONFIG_PROC_SYSCTL
59483+extern const struct inode_operations proc_sys_inode_operations;
59484+extern const struct inode_operations proc_sys_dir_operations;
59485+#endif
59486+
59487 static void proc_evict_inode(struct inode *inode)
59488 {
59489 struct proc_dir_entry *de;
59490@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
59491 ns = PROC_I(inode)->ns.ns;
59492 if (ns_ops && ns)
59493 ns_ops->put(ns);
59494+
59495+#ifdef CONFIG_PROC_SYSCTL
59496+ if (inode->i_op == &proc_sys_inode_operations ||
59497+ inode->i_op == &proc_sys_dir_operations)
59498+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
59499+#endif
59500+
59501 }
59502
59503 static struct kmem_cache * proc_inode_cachep;
59504@@ -385,7 +398,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
59505 if (de->mode) {
59506 inode->i_mode = de->mode;
59507 inode->i_uid = de->uid;
59508+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59509+ inode->i_gid = grsec_proc_gid;
59510+#else
59511 inode->i_gid = de->gid;
59512+#endif
59513 }
59514 if (de->size)
59515 inode->i_size = de->size;
59516diff --git a/fs/proc/internal.h b/fs/proc/internal.h
59517index 651d09a..60c73ae 100644
59518--- a/fs/proc/internal.h
59519+++ b/fs/proc/internal.h
59520@@ -155,6 +155,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
59521 struct pid *, struct task_struct *);
59522 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
59523 struct pid *, struct task_struct *);
59524+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
59525+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
59526+#endif
59527
59528 /*
59529 * base.c
59530diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
59531index 06ea155..9a798c7 100644
59532--- a/fs/proc/kcore.c
59533+++ b/fs/proc/kcore.c
59534@@ -484,9 +484,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
59535 * the addresses in the elf_phdr on our list.
59536 */
59537 start = kc_offset_to_vaddr(*fpos - elf_buflen);
59538- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
59539+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
59540+ if (tsz > buflen)
59541 tsz = buflen;
59542-
59543+
59544 while (buflen) {
59545 struct kcore_list *m;
59546
59547@@ -515,20 +516,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
59548 kfree(elf_buf);
59549 } else {
59550 if (kern_addr_valid(start)) {
59551- unsigned long n;
59552+ char *elf_buf;
59553+ mm_segment_t oldfs;
59554
59555- n = copy_to_user(buffer, (char *)start, tsz);
59556- /*
59557- * We cannot distinguish between fault on source
59558- * and fault on destination. When this happens
59559- * we clear too and hope it will trigger the
59560- * EFAULT again.
59561- */
59562- if (n) {
59563- if (clear_user(buffer + tsz - n,
59564- n))
59565+ elf_buf = kmalloc(tsz, GFP_KERNEL);
59566+ if (!elf_buf)
59567+ return -ENOMEM;
59568+ oldfs = get_fs();
59569+ set_fs(KERNEL_DS);
59570+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
59571+ set_fs(oldfs);
59572+ if (copy_to_user(buffer, elf_buf, tsz)) {
59573+ kfree(elf_buf);
59574 return -EFAULT;
59575+ }
59576 }
59577+ set_fs(oldfs);
59578+ kfree(elf_buf);
59579 } else {
59580 if (clear_user(buffer, tsz))
59581 return -EFAULT;
59582@@ -548,6 +552,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
59583
59584 static int open_kcore(struct inode *inode, struct file *filp)
59585 {
59586+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
59587+ return -EPERM;
59588+#endif
59589 if (!capable(CAP_SYS_RAWIO))
59590 return -EPERM;
59591 if (kcore_need_update)
59592diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
59593index 5aa847a..f77c8d4 100644
59594--- a/fs/proc/meminfo.c
59595+++ b/fs/proc/meminfo.c
59596@@ -159,7 +159,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
59597 vmi.used >> 10,
59598 vmi.largest_chunk >> 10
59599 #ifdef CONFIG_MEMORY_FAILURE
59600- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
59601+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
59602 #endif
59603 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
59604 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
59605diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
59606index ccfd99b..1b7e255 100644
59607--- a/fs/proc/nommu.c
59608+++ b/fs/proc/nommu.c
59609@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
59610 if (len < 1)
59611 len = 1;
59612 seq_printf(m, "%*c", len, ' ');
59613- seq_path(m, &file->f_path, "");
59614+ seq_path(m, &file->f_path, "\n\\");
59615 }
59616
59617 seq_putc(m, '\n');
59618diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
59619index 4677bb7..408e936 100644
59620--- a/fs/proc/proc_net.c
59621+++ b/fs/proc/proc_net.c
59622@@ -23,6 +23,7 @@
59623 #include <linux/nsproxy.h>
59624 #include <net/net_namespace.h>
59625 #include <linux/seq_file.h>
59626+#include <linux/grsecurity.h>
59627
59628 #include "internal.h"
59629
59630@@ -109,6 +110,17 @@ static struct net *get_proc_task_net(struct inode *dir)
59631 struct task_struct *task;
59632 struct nsproxy *ns;
59633 struct net *net = NULL;
59634+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59635+ const struct cred *cred = current_cred();
59636+#endif
59637+
59638+#ifdef CONFIG_GRKERNSEC_PROC_USER
59639+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
59640+ return net;
59641+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59642+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
59643+ return net;
59644+#endif
59645
59646 rcu_read_lock();
59647 task = pid_task(proc_pid(dir), PIDTYPE_PID);
59648diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
59649index 7129046..f2779c6 100644
59650--- a/fs/proc/proc_sysctl.c
59651+++ b/fs/proc/proc_sysctl.c
59652@@ -13,11 +13,15 @@
59653 #include <linux/module.h>
59654 #include "internal.h"
59655
59656+extern int gr_handle_chroot_sysctl(const int op);
59657+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
59658+ const int op);
59659+
59660 static const struct dentry_operations proc_sys_dentry_operations;
59661 static const struct file_operations proc_sys_file_operations;
59662-static const struct inode_operations proc_sys_inode_operations;
59663+const struct inode_operations proc_sys_inode_operations;
59664 static const struct file_operations proc_sys_dir_file_operations;
59665-static const struct inode_operations proc_sys_dir_operations;
59666+const struct inode_operations proc_sys_dir_operations;
59667
59668 void proc_sys_poll_notify(struct ctl_table_poll *poll)
59669 {
59670@@ -467,6 +471,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
59671
59672 err = NULL;
59673 d_set_d_op(dentry, &proc_sys_dentry_operations);
59674+
59675+ gr_handle_proc_create(dentry, inode);
59676+
59677 d_add(dentry, inode);
59678
59679 out:
59680@@ -482,6 +489,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
59681 struct inode *inode = file_inode(filp);
59682 struct ctl_table_header *head = grab_header(inode);
59683 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
59684+ int op = write ? MAY_WRITE : MAY_READ;
59685 ssize_t error;
59686 size_t res;
59687
59688@@ -493,7 +501,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
59689 * and won't be until we finish.
59690 */
59691 error = -EPERM;
59692- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
59693+ if (sysctl_perm(head, table, op))
59694 goto out;
59695
59696 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
59697@@ -501,6 +509,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
59698 if (!table->proc_handler)
59699 goto out;
59700
59701+#ifdef CONFIG_GRKERNSEC
59702+ error = -EPERM;
59703+ if (gr_handle_chroot_sysctl(op))
59704+ goto out;
59705+ dget(filp->f_path.dentry);
59706+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
59707+ dput(filp->f_path.dentry);
59708+ goto out;
59709+ }
59710+ dput(filp->f_path.dentry);
59711+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
59712+ goto out;
59713+ if (write && !capable(CAP_SYS_ADMIN))
59714+ goto out;
59715+#endif
59716+
59717 /* careful: calling conventions are nasty here */
59718 res = count;
59719 error = table->proc_handler(table, write, buf, &res, ppos);
59720@@ -598,6 +622,9 @@ static bool proc_sys_fill_cache(struct file *file,
59721 return false;
59722 } else {
59723 d_set_d_op(child, &proc_sys_dentry_operations);
59724+
59725+ gr_handle_proc_create(child, inode);
59726+
59727 d_add(child, inode);
59728 }
59729 } else {
59730@@ -641,6 +668,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
59731 if ((*pos)++ < ctx->pos)
59732 return true;
59733
59734+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
59735+ return 0;
59736+
59737 if (unlikely(S_ISLNK(table->mode)))
59738 res = proc_sys_link_fill_cache(file, ctx, head, table);
59739 else
59740@@ -734,6 +764,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
59741 if (IS_ERR(head))
59742 return PTR_ERR(head);
59743
59744+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
59745+ return -ENOENT;
59746+
59747 generic_fillattr(inode, stat);
59748 if (table)
59749 stat->mode = (stat->mode & S_IFMT) | table->mode;
59750@@ -756,13 +789,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
59751 .llseek = generic_file_llseek,
59752 };
59753
59754-static const struct inode_operations proc_sys_inode_operations = {
59755+const struct inode_operations proc_sys_inode_operations = {
59756 .permission = proc_sys_permission,
59757 .setattr = proc_sys_setattr,
59758 .getattr = proc_sys_getattr,
59759 };
59760
59761-static const struct inode_operations proc_sys_dir_operations = {
59762+const struct inode_operations proc_sys_dir_operations = {
59763 .lookup = proc_sys_lookup,
59764 .permission = proc_sys_permission,
59765 .setattr = proc_sys_setattr,
59766@@ -839,7 +872,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
59767 static struct ctl_dir *new_dir(struct ctl_table_set *set,
59768 const char *name, int namelen)
59769 {
59770- struct ctl_table *table;
59771+ ctl_table_no_const *table;
59772 struct ctl_dir *new;
59773 struct ctl_node *node;
59774 char *new_name;
59775@@ -851,7 +884,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
59776 return NULL;
59777
59778 node = (struct ctl_node *)(new + 1);
59779- table = (struct ctl_table *)(node + 1);
59780+ table = (ctl_table_no_const *)(node + 1);
59781 new_name = (char *)(table + 2);
59782 memcpy(new_name, name, namelen);
59783 new_name[namelen] = '\0';
59784@@ -1020,7 +1053,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
59785 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
59786 struct ctl_table_root *link_root)
59787 {
59788- struct ctl_table *link_table, *entry, *link;
59789+ ctl_table_no_const *link_table, *link;
59790+ struct ctl_table *entry;
59791 struct ctl_table_header *links;
59792 struct ctl_node *node;
59793 char *link_name;
59794@@ -1043,7 +1077,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
59795 return NULL;
59796
59797 node = (struct ctl_node *)(links + 1);
59798- link_table = (struct ctl_table *)(node + nr_entries);
59799+ link_table = (ctl_table_no_const *)(node + nr_entries);
59800 link_name = (char *)&link_table[nr_entries + 1];
59801
59802 for (link = link_table, entry = table; entry->procname; link++, entry++) {
59803@@ -1291,8 +1325,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
59804 struct ctl_table_header ***subheader, struct ctl_table_set *set,
59805 struct ctl_table *table)
59806 {
59807- struct ctl_table *ctl_table_arg = NULL;
59808- struct ctl_table *entry, *files;
59809+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
59810+ struct ctl_table *entry;
59811 int nr_files = 0;
59812 int nr_dirs = 0;
59813 int err = -ENOMEM;
59814@@ -1304,10 +1338,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
59815 nr_files++;
59816 }
59817
59818- files = table;
59819 /* If there are mixed files and directories we need a new table */
59820 if (nr_dirs && nr_files) {
59821- struct ctl_table *new;
59822+ ctl_table_no_const *new;
59823 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
59824 GFP_KERNEL);
59825 if (!files)
59826@@ -1325,7 +1358,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
59827 /* Register everything except a directory full of subdirectories */
59828 if (nr_files || !nr_dirs) {
59829 struct ctl_table_header *header;
59830- header = __register_sysctl_table(set, path, files);
59831+ header = __register_sysctl_table(set, path, files ? files : table);
59832 if (!header) {
59833 kfree(ctl_table_arg);
59834 goto out;
59835diff --git a/fs/proc/root.c b/fs/proc/root.c
59836index 0e0e83c..005ba6a 100644
59837--- a/fs/proc/root.c
59838+++ b/fs/proc/root.c
59839@@ -183,7 +183,15 @@ void __init proc_root_init(void)
59840 #ifdef CONFIG_PROC_DEVICETREE
59841 proc_device_tree_init();
59842 #endif
59843+#ifdef CONFIG_GRKERNSEC_PROC_ADD
59844+#ifdef CONFIG_GRKERNSEC_PROC_USER
59845+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
59846+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59847+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
59848+#endif
59849+#else
59850 proc_mkdir("bus", NULL);
59851+#endif
59852 proc_sys_init();
59853 }
59854
59855diff --git a/fs/proc/self.c b/fs/proc/self.c
59856index 6b6a993..807cccc 100644
59857--- a/fs/proc/self.c
59858+++ b/fs/proc/self.c
59859@@ -39,7 +39,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
59860 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
59861 void *cookie)
59862 {
59863- char *s = nd_get_link(nd);
59864+ const char *s = nd_get_link(nd);
59865 if (!IS_ERR(s))
59866 kfree(s);
59867 }
59868diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
59869index 107d026..c715aeb 100644
59870--- a/fs/proc/task_mmu.c
59871+++ b/fs/proc/task_mmu.c
59872@@ -12,12 +12,19 @@
59873 #include <linux/swap.h>
59874 #include <linux/swapops.h>
59875 #include <linux/mmu_notifier.h>
59876+#include <linux/grsecurity.h>
59877
59878 #include <asm/elf.h>
59879 #include <asm/uaccess.h>
59880 #include <asm/tlbflush.h>
59881 #include "internal.h"
59882
59883+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59884+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
59885+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
59886+ _mm->pax_flags & MF_PAX_SEGMEXEC))
59887+#endif
59888+
59889 void task_mem(struct seq_file *m, struct mm_struct *mm)
59890 {
59891 unsigned long data, text, lib, swap;
59892@@ -53,8 +60,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
59893 "VmExe:\t%8lu kB\n"
59894 "VmLib:\t%8lu kB\n"
59895 "VmPTE:\t%8lu kB\n"
59896- "VmSwap:\t%8lu kB\n",
59897- hiwater_vm << (PAGE_SHIFT-10),
59898+ "VmSwap:\t%8lu kB\n"
59899+
59900+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
59901+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
59902+#endif
59903+
59904+ ,hiwater_vm << (PAGE_SHIFT-10),
59905 total_vm << (PAGE_SHIFT-10),
59906 mm->locked_vm << (PAGE_SHIFT-10),
59907 mm->pinned_vm << (PAGE_SHIFT-10),
59908@@ -63,7 +75,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
59909 data << (PAGE_SHIFT-10),
59910 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
59911 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
59912- swap << (PAGE_SHIFT-10));
59913+ swap << (PAGE_SHIFT-10)
59914+
59915+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
59916+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59917+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
59918+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
59919+#else
59920+ , mm->context.user_cs_base
59921+ , mm->context.user_cs_limit
59922+#endif
59923+#endif
59924+
59925+ );
59926 }
59927
59928 unsigned long task_vsize(struct mm_struct *mm)
59929@@ -278,13 +302,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
59930 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
59931 }
59932
59933- /* We don't show the stack guard page in /proc/maps */
59934+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59935+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
59936+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
59937+#else
59938 start = vma->vm_start;
59939- if (stack_guard_page_start(vma, start))
59940- start += PAGE_SIZE;
59941 end = vma->vm_end;
59942- if (stack_guard_page_end(vma, end))
59943- end -= PAGE_SIZE;
59944+#endif
59945
59946 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
59947 start,
59948@@ -293,7 +317,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
59949 flags & VM_WRITE ? 'w' : '-',
59950 flags & VM_EXEC ? 'x' : '-',
59951 flags & VM_MAYSHARE ? 's' : 'p',
59952+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59953+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
59954+#else
59955 pgoff,
59956+#endif
59957 MAJOR(dev), MINOR(dev), ino, &len);
59958
59959 /*
59960@@ -302,7 +330,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
59961 */
59962 if (file) {
59963 pad_len_spaces(m, len);
59964- seq_path(m, &file->f_path, "\n");
59965+ seq_path(m, &file->f_path, "\n\\");
59966 goto done;
59967 }
59968
59969@@ -328,8 +356,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
59970 * Thread stack in /proc/PID/task/TID/maps or
59971 * the main process stack.
59972 */
59973- if (!is_pid || (vma->vm_start <= mm->start_stack &&
59974- vma->vm_end >= mm->start_stack)) {
59975+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
59976+ (vma->vm_start <= mm->start_stack &&
59977+ vma->vm_end >= mm->start_stack)) {
59978 name = "[stack]";
59979 } else {
59980 /* Thread stack in /proc/PID/maps */
59981@@ -353,6 +382,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
59982 struct proc_maps_private *priv = m->private;
59983 struct task_struct *task = priv->task;
59984
59985+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59986+ if (current->exec_id != m->exec_id) {
59987+ gr_log_badprocpid("maps");
59988+ return 0;
59989+ }
59990+#endif
59991+
59992 show_map_vma(m, vma, is_pid);
59993
59994 if (m->count < m->size) /* vma is copied successfully */
59995@@ -590,12 +626,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
59996 .private = &mss,
59997 };
59998
59999+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60000+ if (current->exec_id != m->exec_id) {
60001+ gr_log_badprocpid("smaps");
60002+ return 0;
60003+ }
60004+#endif
60005 memset(&mss, 0, sizeof mss);
60006- mss.vma = vma;
60007- /* mmap_sem is held in m_start */
60008- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
60009- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
60010-
60011+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60012+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
60013+#endif
60014+ mss.vma = vma;
60015+ /* mmap_sem is held in m_start */
60016+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
60017+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
60018+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60019+ }
60020+#endif
60021 show_map_vma(m, vma, is_pid);
60022
60023 seq_printf(m,
60024@@ -613,7 +660,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
60025 "KernelPageSize: %8lu kB\n"
60026 "MMUPageSize: %8lu kB\n"
60027 "Locked: %8lu kB\n",
60028+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60029+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
60030+#else
60031 (vma->vm_end - vma->vm_start) >> 10,
60032+#endif
60033 mss.resident >> 10,
60034 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
60035 mss.shared_clean >> 10,
60036@@ -1362,6 +1413,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
60037 int n;
60038 char buffer[50];
60039
60040+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60041+ if (current->exec_id != m->exec_id) {
60042+ gr_log_badprocpid("numa_maps");
60043+ return 0;
60044+ }
60045+#endif
60046+
60047 if (!mm)
60048 return 0;
60049
60050@@ -1379,11 +1437,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
60051 mpol_to_str(buffer, sizeof(buffer), pol);
60052 mpol_cond_put(pol);
60053
60054+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60055+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
60056+#else
60057 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
60058+#endif
60059
60060 if (file) {
60061 seq_printf(m, " file=");
60062- seq_path(m, &file->f_path, "\n\t= ");
60063+ seq_path(m, &file->f_path, "\n\t\\= ");
60064 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
60065 seq_printf(m, " heap");
60066 } else {
60067diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
60068index 56123a6..5a2f6ec 100644
60069--- a/fs/proc/task_nommu.c
60070+++ b/fs/proc/task_nommu.c
60071@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
60072 else
60073 bytes += kobjsize(mm);
60074
60075- if (current->fs && current->fs->users > 1)
60076+ if (current->fs && atomic_read(&current->fs->users) > 1)
60077 sbytes += kobjsize(current->fs);
60078 else
60079 bytes += kobjsize(current->fs);
60080@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
60081
60082 if (file) {
60083 pad_len_spaces(m, len);
60084- seq_path(m, &file->f_path, "");
60085+ seq_path(m, &file->f_path, "\n\\");
60086 } else if (mm) {
60087 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
60088
60089diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
60090index a1a16eb..6be46ed 100644
60091--- a/fs/proc/vmcore.c
60092+++ b/fs/proc/vmcore.c
60093@@ -104,9 +104,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
60094 nr_bytes = count;
60095
60096 /* If pfn is not ram, return zeros for sparse dump files */
60097- if (pfn_is_ram(pfn) == 0)
60098- memset(buf, 0, nr_bytes);
60099- else {
60100+ if (pfn_is_ram(pfn) == 0) {
60101+ if (userbuf) {
60102+ if (clear_user((char __force_user *)buf, nr_bytes))
60103+ return -EFAULT;
60104+ } else
60105+ memset(buf, 0, nr_bytes);
60106+ } else {
60107 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
60108 offset, userbuf);
60109 if (tmp < 0)
60110@@ -178,7 +182,7 @@ static ssize_t read_vmcore(struct file *file, char __user *buffer,
60111 if (*fpos < m->offset + m->size) {
60112 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
60113 start = m->paddr + *fpos - m->offset;
60114- tmp = read_from_oldmem(buffer, tsz, &start, 1);
60115+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, 1);
60116 if (tmp < 0)
60117 return tmp;
60118 buflen -= tsz;
60119diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
60120index b00fcc9..e0c6381 100644
60121--- a/fs/qnx6/qnx6.h
60122+++ b/fs/qnx6/qnx6.h
60123@@ -74,7 +74,7 @@ enum {
60124 BYTESEX_BE,
60125 };
60126
60127-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
60128+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
60129 {
60130 if (sbi->s_bytesex == BYTESEX_LE)
60131 return le64_to_cpu((__force __le64)n);
60132@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
60133 return (__force __fs64)cpu_to_be64(n);
60134 }
60135
60136-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
60137+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
60138 {
60139 if (sbi->s_bytesex == BYTESEX_LE)
60140 return le32_to_cpu((__force __le32)n);
60141diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
60142index 16e8abb..2dcf914 100644
60143--- a/fs/quota/netlink.c
60144+++ b/fs/quota/netlink.c
60145@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
60146 void quota_send_warning(struct kqid qid, dev_t dev,
60147 const char warntype)
60148 {
60149- static atomic_t seq;
60150+ static atomic_unchecked_t seq;
60151 struct sk_buff *skb;
60152 void *msg_head;
60153 int ret;
60154@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
60155 "VFS: Not enough memory to send quota warning.\n");
60156 return;
60157 }
60158- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
60159+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
60160 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
60161 if (!msg_head) {
60162 printk(KERN_ERR
60163diff --git a/fs/read_write.c b/fs/read_write.c
60164index 122a384..0b7ecf2 100644
60165--- a/fs/read_write.c
60166+++ b/fs/read_write.c
60167@@ -440,7 +440,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
60168
60169 old_fs = get_fs();
60170 set_fs(get_ds());
60171- p = (__force const char __user *)buf;
60172+ p = (const char __force_user *)buf;
60173 if (count > MAX_RW_COUNT)
60174 count = MAX_RW_COUNT;
60175 if (file->f_op->write)
60176diff --git a/fs/readdir.c b/fs/readdir.c
60177index 93d71e5..6a14be8 100644
60178--- a/fs/readdir.c
60179+++ b/fs/readdir.c
60180@@ -17,6 +17,7 @@
60181 #include <linux/security.h>
60182 #include <linux/syscalls.h>
60183 #include <linux/unistd.h>
60184+#include <linux/namei.h>
60185
60186 #include <asm/uaccess.h>
60187
60188@@ -69,6 +70,7 @@ struct old_linux_dirent {
60189 struct readdir_callback {
60190 struct dir_context ctx;
60191 struct old_linux_dirent __user * dirent;
60192+ struct file * file;
60193 int result;
60194 };
60195
60196@@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
60197 buf->result = -EOVERFLOW;
60198 return -EOVERFLOW;
60199 }
60200+
60201+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60202+ return 0;
60203+
60204 buf->result++;
60205 dirent = buf->dirent;
60206 if (!access_ok(VERIFY_WRITE, dirent,
60207@@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
60208 if (!f.file)
60209 return -EBADF;
60210
60211+ buf.file = f.file;
60212 error = iterate_dir(f.file, &buf.ctx);
60213 if (buf.result)
60214 error = buf.result;
60215@@ -142,6 +149,7 @@ struct getdents_callback {
60216 struct dir_context ctx;
60217 struct linux_dirent __user * current_dir;
60218 struct linux_dirent __user * previous;
60219+ struct file * file;
60220 int count;
60221 int error;
60222 };
60223@@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
60224 buf->error = -EOVERFLOW;
60225 return -EOVERFLOW;
60226 }
60227+
60228+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60229+ return 0;
60230+
60231 dirent = buf->previous;
60232 if (dirent) {
60233 if (__put_user(offset, &dirent->d_off))
60234@@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
60235 if (!f.file)
60236 return -EBADF;
60237
60238+ buf.file = f.file;
60239 error = iterate_dir(f.file, &buf.ctx);
60240 if (error >= 0)
60241 error = buf.error;
60242@@ -226,6 +239,7 @@ struct getdents_callback64 {
60243 struct dir_context ctx;
60244 struct linux_dirent64 __user * current_dir;
60245 struct linux_dirent64 __user * previous;
60246+ struct file *file;
60247 int count;
60248 int error;
60249 };
60250@@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
60251 buf->error = -EINVAL; /* only used if we fail.. */
60252 if (reclen > buf->count)
60253 return -EINVAL;
60254+
60255+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60256+ return 0;
60257+
60258 dirent = buf->previous;
60259 if (dirent) {
60260 if (__put_user(offset, &dirent->d_off))
60261@@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
60262 if (!f.file)
60263 return -EBADF;
60264
60265+ buf.file = f.file;
60266 error = iterate_dir(f.file, &buf.ctx);
60267 if (error >= 0)
60268 error = buf.error;
60269diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
60270index 2b7882b..1c5ef48 100644
60271--- a/fs/reiserfs/do_balan.c
60272+++ b/fs/reiserfs/do_balan.c
60273@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
60274 return;
60275 }
60276
60277- atomic_inc(&(fs_generation(tb->tb_sb)));
60278+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
60279 do_balance_starts(tb);
60280
60281 /* balance leaf returns 0 except if combining L R and S into
60282diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
60283index a958444..42b2323 100644
60284--- a/fs/reiserfs/procfs.c
60285+++ b/fs/reiserfs/procfs.c
60286@@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
60287 "SMALL_TAILS " : "NO_TAILS ",
60288 replay_only(sb) ? "REPLAY_ONLY " : "",
60289 convert_reiserfs(sb) ? "CONV " : "",
60290- atomic_read(&r->s_generation_counter),
60291+ atomic_read_unchecked(&r->s_generation_counter),
60292 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
60293 SF(s_do_balance), SF(s_unneeded_left_neighbor),
60294 SF(s_good_search_by_key_reada), SF(s_bmaps),
60295diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
60296index 3df5ce6..8c0f4b0 100644
60297--- a/fs/reiserfs/reiserfs.h
60298+++ b/fs/reiserfs/reiserfs.h
60299@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
60300 /* Comment? -Hans */
60301 wait_queue_head_t s_wait;
60302 /* To be obsoleted soon by per buffer seals.. -Hans */
60303- atomic_t s_generation_counter; // increased by one every time the
60304+ atomic_unchecked_t s_generation_counter; // increased by one every time the
60305 // tree gets re-balanced
60306 unsigned long s_properties; /* File system properties. Currently holds
60307 on-disk FS format */
60308@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
60309 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
60310
60311 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
60312-#define get_generation(s) atomic_read (&fs_generation(s))
60313+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
60314 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
60315 #define __fs_changed(gen,s) (gen != get_generation (s))
60316 #define fs_changed(gen,s) \
60317diff --git a/fs/select.c b/fs/select.c
60318index 35d4adc7..d6c60db 100644
60319--- a/fs/select.c
60320+++ b/fs/select.c
60321@@ -20,6 +20,7 @@
60322 #include <linux/export.h>
60323 #include <linux/slab.h>
60324 #include <linux/poll.h>
60325+#include <linux/security.h>
60326 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
60327 #include <linux/file.h>
60328 #include <linux/fdtable.h>
60329@@ -881,6 +882,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
60330 struct poll_list *walk = head;
60331 unsigned long todo = nfds;
60332
60333+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
60334 if (nfds > rlimit(RLIMIT_NOFILE))
60335 return -EINVAL;
60336
60337diff --git a/fs/seq_file.c b/fs/seq_file.c
60338index 3135c25..d0395dd 100644
60339--- a/fs/seq_file.c
60340+++ b/fs/seq_file.c
60341@@ -10,6 +10,7 @@
60342 #include <linux/seq_file.h>
60343 #include <linux/slab.h>
60344 #include <linux/cred.h>
60345+#include <linux/sched.h>
60346
60347 #include <asm/uaccess.h>
60348 #include <asm/page.h>
60349@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
60350 #ifdef CONFIG_USER_NS
60351 p->user_ns = file->f_cred->user_ns;
60352 #endif
60353+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60354+ p->exec_id = current->exec_id;
60355+#endif
60356
60357 /*
60358 * Wrappers around seq_open(e.g. swaps_open) need to be
60359@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
60360 return 0;
60361 }
60362 if (!m->buf) {
60363- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
60364+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
60365 if (!m->buf)
60366 return -ENOMEM;
60367 }
60368@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
60369 Eoverflow:
60370 m->op->stop(m, p);
60371 kfree(m->buf);
60372- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
60373+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
60374 return !m->buf ? -ENOMEM : -EAGAIN;
60375 }
60376
60377@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
60378
60379 /* grab buffer if we didn't have one */
60380 if (!m->buf) {
60381- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
60382+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
60383 if (!m->buf)
60384 goto Enomem;
60385 }
60386@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
60387 goto Fill;
60388 m->op->stop(m, p);
60389 kfree(m->buf);
60390- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
60391+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
60392 if (!m->buf)
60393 goto Enomem;
60394 m->count = 0;
60395@@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
60396 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
60397 void *data)
60398 {
60399- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
60400+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
60401 int res = -ENOMEM;
60402
60403 if (op) {
60404diff --git a/fs/splice.c b/fs/splice.c
60405index 3b7ee65..87fc2e4 100644
60406--- a/fs/splice.c
60407+++ b/fs/splice.c
60408@@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
60409 pipe_lock(pipe);
60410
60411 for (;;) {
60412- if (!pipe->readers) {
60413+ if (!atomic_read(&pipe->readers)) {
60414 send_sig(SIGPIPE, current, 0);
60415 if (!ret)
60416 ret = -EPIPE;
60417@@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
60418 page_nr++;
60419 ret += buf->len;
60420
60421- if (pipe->files)
60422+ if (atomic_read(&pipe->files))
60423 do_wakeup = 1;
60424
60425 if (!--spd->nr_pages)
60426@@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
60427 do_wakeup = 0;
60428 }
60429
60430- pipe->waiting_writers++;
60431+ atomic_inc(&pipe->waiting_writers);
60432 pipe_wait(pipe);
60433- pipe->waiting_writers--;
60434+ atomic_dec(&pipe->waiting_writers);
60435 }
60436
60437 pipe_unlock(pipe);
60438@@ -565,7 +565,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
60439 old_fs = get_fs();
60440 set_fs(get_ds());
60441 /* The cast to a user pointer is valid due to the set_fs() */
60442- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
60443+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
60444 set_fs(old_fs);
60445
60446 return res;
60447@@ -580,7 +580,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
60448 old_fs = get_fs();
60449 set_fs(get_ds());
60450 /* The cast to a user pointer is valid due to the set_fs() */
60451- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
60452+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
60453 set_fs(old_fs);
60454
60455 return res;
60456@@ -633,7 +633,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
60457 goto err;
60458
60459 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
60460- vec[i].iov_base = (void __user *) page_address(page);
60461+ vec[i].iov_base = (void __force_user *) page_address(page);
60462 vec[i].iov_len = this_len;
60463 spd.pages[i] = page;
60464 spd.nr_pages++;
60465@@ -829,7 +829,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
60466 ops->release(pipe, buf);
60467 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
60468 pipe->nrbufs--;
60469- if (pipe->files)
60470+ if (atomic_read(&pipe->files))
60471 sd->need_wakeup = true;
60472 }
60473
60474@@ -854,10 +854,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
60475 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
60476 {
60477 while (!pipe->nrbufs) {
60478- if (!pipe->writers)
60479+ if (!atomic_read(&pipe->writers))
60480 return 0;
60481
60482- if (!pipe->waiting_writers && sd->num_spliced)
60483+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
60484 return 0;
60485
60486 if (sd->flags & SPLICE_F_NONBLOCK)
60487@@ -1179,7 +1179,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
60488 * out of the pipe right after the splice_to_pipe(). So set
60489 * PIPE_READERS appropriately.
60490 */
60491- pipe->readers = 1;
60492+ atomic_set(&pipe->readers, 1);
60493
60494 current->splice_pipe = pipe;
60495 }
60496@@ -1475,6 +1475,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
60497
60498 partial[buffers].offset = off;
60499 partial[buffers].len = plen;
60500+ partial[buffers].private = 0;
60501
60502 off = 0;
60503 len -= plen;
60504@@ -1777,9 +1778,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
60505 ret = -ERESTARTSYS;
60506 break;
60507 }
60508- if (!pipe->writers)
60509+ if (!atomic_read(&pipe->writers))
60510 break;
60511- if (!pipe->waiting_writers) {
60512+ if (!atomic_read(&pipe->waiting_writers)) {
60513 if (flags & SPLICE_F_NONBLOCK) {
60514 ret = -EAGAIN;
60515 break;
60516@@ -1811,7 +1812,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
60517 pipe_lock(pipe);
60518
60519 while (pipe->nrbufs >= pipe->buffers) {
60520- if (!pipe->readers) {
60521+ if (!atomic_read(&pipe->readers)) {
60522 send_sig(SIGPIPE, current, 0);
60523 ret = -EPIPE;
60524 break;
60525@@ -1824,9 +1825,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
60526 ret = -ERESTARTSYS;
60527 break;
60528 }
60529- pipe->waiting_writers++;
60530+ atomic_inc(&pipe->waiting_writers);
60531 pipe_wait(pipe);
60532- pipe->waiting_writers--;
60533+ atomic_dec(&pipe->waiting_writers);
60534 }
60535
60536 pipe_unlock(pipe);
60537@@ -1862,14 +1863,14 @@ retry:
60538 pipe_double_lock(ipipe, opipe);
60539
60540 do {
60541- if (!opipe->readers) {
60542+ if (!atomic_read(&opipe->readers)) {
60543 send_sig(SIGPIPE, current, 0);
60544 if (!ret)
60545 ret = -EPIPE;
60546 break;
60547 }
60548
60549- if (!ipipe->nrbufs && !ipipe->writers)
60550+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
60551 break;
60552
60553 /*
60554@@ -1966,7 +1967,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
60555 pipe_double_lock(ipipe, opipe);
60556
60557 do {
60558- if (!opipe->readers) {
60559+ if (!atomic_read(&opipe->readers)) {
60560 send_sig(SIGPIPE, current, 0);
60561 if (!ret)
60562 ret = -EPIPE;
60563@@ -2011,7 +2012,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
60564 * return EAGAIN if we have the potential of some data in the
60565 * future, otherwise just return 0
60566 */
60567- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
60568+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
60569 ret = -EAGAIN;
60570
60571 pipe_unlock(ipipe);
60572diff --git a/fs/stat.c b/fs/stat.c
60573index 04ce1ac..a13dd1e 100644
60574--- a/fs/stat.c
60575+++ b/fs/stat.c
60576@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
60577 stat->gid = inode->i_gid;
60578 stat->rdev = inode->i_rdev;
60579 stat->size = i_size_read(inode);
60580- stat->atime = inode->i_atime;
60581- stat->mtime = inode->i_mtime;
60582+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
60583+ stat->atime = inode->i_ctime;
60584+ stat->mtime = inode->i_ctime;
60585+ } else {
60586+ stat->atime = inode->i_atime;
60587+ stat->mtime = inode->i_mtime;
60588+ }
60589 stat->ctime = inode->i_ctime;
60590 stat->blksize = (1 << inode->i_blkbits);
60591 stat->blocks = inode->i_blocks;
60592@@ -46,8 +51,14 @@ int vfs_getattr(struct path *path, struct kstat *stat)
60593 if (retval)
60594 return retval;
60595
60596- if (inode->i_op->getattr)
60597- return inode->i_op->getattr(path->mnt, path->dentry, stat);
60598+ if (inode->i_op->getattr) {
60599+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
60600+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
60601+ stat->atime = stat->ctime;
60602+ stat->mtime = stat->ctime;
60603+ }
60604+ return retval;
60605+ }
60606
60607 generic_fillattr(inode, stat);
60608 return 0;
60609diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
60610index 15c68f9..36a8b3e 100644
60611--- a/fs/sysfs/bin.c
60612+++ b/fs/sysfs/bin.c
60613@@ -235,13 +235,13 @@ static int bin_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
60614 return ret;
60615 }
60616
60617-static int bin_access(struct vm_area_struct *vma, unsigned long addr,
60618- void *buf, int len, int write)
60619+static ssize_t bin_access(struct vm_area_struct *vma, unsigned long addr,
60620+ void *buf, size_t len, int write)
60621 {
60622 struct file *file = vma->vm_file;
60623 struct bin_buffer *bb = file->private_data;
60624 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
60625- int ret;
60626+ ssize_t ret;
60627
60628 if (!bb->vm_ops)
60629 return -EINVAL;
60630diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
60631index e068e74..92edeb8 100644
60632--- a/fs/sysfs/dir.c
60633+++ b/fs/sysfs/dir.c
60634@@ -40,7 +40,7 @@ static DEFINE_IDA(sysfs_ino_ida);
60635 *
60636 * Returns 31 bit hash of ns + name (so it fits in an off_t )
60637 */
60638-static unsigned int sysfs_name_hash(const void *ns, const char *name)
60639+static unsigned int sysfs_name_hash(const void *ns, const unsigned char *name)
60640 {
60641 unsigned long hash = init_name_hash();
60642 unsigned int len = strlen(name);
60643@@ -679,6 +679,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
60644 struct sysfs_dirent *sd;
60645 int rc;
60646
60647+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
60648+ const char *parent_name = parent_sd->s_name;
60649+
60650+ mode = S_IFDIR | S_IRWXU;
60651+
60652+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
60653+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
60654+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
60655+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
60656+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
60657+#endif
60658+
60659 /* allocate */
60660 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
60661 if (!sd)
60662diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
60663index d2bb7ed..fe8c331 100644
60664--- a/fs/sysfs/file.c
60665+++ b/fs/sysfs/file.c
60666@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
60667
60668 struct sysfs_open_dirent {
60669 atomic_t refcnt;
60670- atomic_t event;
60671+ atomic_unchecked_t event;
60672 wait_queue_head_t poll;
60673 struct list_head buffers; /* goes through sysfs_buffer.list */
60674 };
60675@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
60676 if (!sysfs_get_active(attr_sd))
60677 return -ENODEV;
60678
60679- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
60680+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
60681 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
60682
60683 sysfs_put_active(attr_sd);
60684@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
60685 return -ENOMEM;
60686
60687 atomic_set(&new_od->refcnt, 0);
60688- atomic_set(&new_od->event, 1);
60689+ atomic_set_unchecked(&new_od->event, 1);
60690 init_waitqueue_head(&new_od->poll);
60691 INIT_LIST_HEAD(&new_od->buffers);
60692 goto retry;
60693@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
60694
60695 sysfs_put_active(attr_sd);
60696
60697- if (buffer->event != atomic_read(&od->event))
60698+ if (buffer->event != atomic_read_unchecked(&od->event))
60699 goto trigger;
60700
60701 return DEFAULT_POLLMASK;
60702@@ -452,7 +452,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
60703 if (!WARN_ON(sysfs_type(sd) != SYSFS_KOBJ_ATTR)) {
60704 od = sd->s_attr.open;
60705 if (od) {
60706- atomic_inc(&od->event);
60707+ atomic_inc_unchecked(&od->event);
60708 wake_up_interruptible(&od->poll);
60709 }
60710 }
60711diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
60712index 8c940df..25b733e 100644
60713--- a/fs/sysfs/symlink.c
60714+++ b/fs/sysfs/symlink.c
60715@@ -305,7 +305,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
60716
60717 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
60718 {
60719- char *page = nd_get_link(nd);
60720+ const char *page = nd_get_link(nd);
60721 if (!IS_ERR(page))
60722 free_page((unsigned long)page);
60723 }
60724diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
60725index 69d4889..a810bd4 100644
60726--- a/fs/sysv/sysv.h
60727+++ b/fs/sysv/sysv.h
60728@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
60729 #endif
60730 }
60731
60732-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
60733+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
60734 {
60735 if (sbi->s_bytesex == BYTESEX_PDP)
60736 return PDP_swab((__force __u32)n);
60737diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
60738index e18b988..f1d4ad0f 100644
60739--- a/fs/ubifs/io.c
60740+++ b/fs/ubifs/io.c
60741@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
60742 return err;
60743 }
60744
60745-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
60746+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
60747 {
60748 int err;
60749
60750diff --git a/fs/udf/misc.c b/fs/udf/misc.c
60751index c175b4d..8f36a16 100644
60752--- a/fs/udf/misc.c
60753+++ b/fs/udf/misc.c
60754@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
60755
60756 u8 udf_tag_checksum(const struct tag *t)
60757 {
60758- u8 *data = (u8 *)t;
60759+ const u8 *data = (const u8 *)t;
60760 u8 checksum = 0;
60761 int i;
60762 for (i = 0; i < sizeof(struct tag); ++i)
60763diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
60764index 8d974c4..b82f6ec 100644
60765--- a/fs/ufs/swab.h
60766+++ b/fs/ufs/swab.h
60767@@ -22,7 +22,7 @@ enum {
60768 BYTESEX_BE
60769 };
60770
60771-static inline u64
60772+static inline u64 __intentional_overflow(-1)
60773 fs64_to_cpu(struct super_block *sbp, __fs64 n)
60774 {
60775 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
60776@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
60777 return (__force __fs64)cpu_to_be64(n);
60778 }
60779
60780-static inline u32
60781+static inline u32 __intentional_overflow(-1)
60782 fs32_to_cpu(struct super_block *sbp, __fs32 n)
60783 {
60784 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
60785diff --git a/fs/utimes.c b/fs/utimes.c
60786index f4fb7ec..3fe03c0 100644
60787--- a/fs/utimes.c
60788+++ b/fs/utimes.c
60789@@ -1,6 +1,7 @@
60790 #include <linux/compiler.h>
60791 #include <linux/file.h>
60792 #include <linux/fs.h>
60793+#include <linux/security.h>
60794 #include <linux/linkage.h>
60795 #include <linux/mount.h>
60796 #include <linux/namei.h>
60797@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
60798 goto mnt_drop_write_and_out;
60799 }
60800 }
60801+
60802+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
60803+ error = -EACCES;
60804+ goto mnt_drop_write_and_out;
60805+ }
60806+
60807 mutex_lock(&inode->i_mutex);
60808 error = notify_change(path->dentry, &newattrs);
60809 mutex_unlock(&inode->i_mutex);
60810diff --git a/fs/xattr.c b/fs/xattr.c
60811index 3377dff..4d074d9 100644
60812--- a/fs/xattr.c
60813+++ b/fs/xattr.c
60814@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
60815 return rc;
60816 }
60817
60818+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
60819+ssize_t
60820+pax_getxattr(struct dentry *dentry, void *value, size_t size)
60821+{
60822+ struct inode *inode = dentry->d_inode;
60823+ ssize_t error;
60824+
60825+ error = inode_permission(inode, MAY_EXEC);
60826+ if (error)
60827+ return error;
60828+
60829+ if (inode->i_op->getxattr)
60830+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
60831+ else
60832+ error = -EOPNOTSUPP;
60833+
60834+ return error;
60835+}
60836+EXPORT_SYMBOL(pax_getxattr);
60837+#endif
60838+
60839 ssize_t
60840 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
60841 {
60842@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
60843 * Extended attribute SET operations
60844 */
60845 static long
60846-setxattr(struct dentry *d, const char __user *name, const void __user *value,
60847+setxattr(struct path *path, const char __user *name, const void __user *value,
60848 size_t size, int flags)
60849 {
60850 int error;
60851@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
60852 posix_acl_fix_xattr_from_user(kvalue, size);
60853 }
60854
60855- error = vfs_setxattr(d, kname, kvalue, size, flags);
60856+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
60857+ error = -EACCES;
60858+ goto out;
60859+ }
60860+
60861+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
60862 out:
60863 if (vvalue)
60864 vfree(vvalue);
60865@@ -377,7 +403,7 @@ retry:
60866 return error;
60867 error = mnt_want_write(path.mnt);
60868 if (!error) {
60869- error = setxattr(path.dentry, name, value, size, flags);
60870+ error = setxattr(&path, name, value, size, flags);
60871 mnt_drop_write(path.mnt);
60872 }
60873 path_put(&path);
60874@@ -401,7 +427,7 @@ retry:
60875 return error;
60876 error = mnt_want_write(path.mnt);
60877 if (!error) {
60878- error = setxattr(path.dentry, name, value, size, flags);
60879+ error = setxattr(&path, name, value, size, flags);
60880 mnt_drop_write(path.mnt);
60881 }
60882 path_put(&path);
60883@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
60884 const void __user *,value, size_t, size, int, flags)
60885 {
60886 struct fd f = fdget(fd);
60887- struct dentry *dentry;
60888 int error = -EBADF;
60889
60890 if (!f.file)
60891 return error;
60892- dentry = f.file->f_path.dentry;
60893- audit_inode(NULL, dentry, 0);
60894+ audit_inode(NULL, f.file->f_path.dentry, 0);
60895 error = mnt_want_write_file(f.file);
60896 if (!error) {
60897- error = setxattr(dentry, name, value, size, flags);
60898+ error = setxattr(&f.file->f_path, name, value, size, flags);
60899 mnt_drop_write_file(f.file);
60900 }
60901 fdput(f);
60902diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
60903index 9fbea87..6b19972 100644
60904--- a/fs/xattr_acl.c
60905+++ b/fs/xattr_acl.c
60906@@ -76,8 +76,8 @@ struct posix_acl *
60907 posix_acl_from_xattr(struct user_namespace *user_ns,
60908 const void *value, size_t size)
60909 {
60910- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
60911- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
60912+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
60913+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
60914 int count;
60915 struct posix_acl *acl;
60916 struct posix_acl_entry *acl_e;
60917diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
60918index 05c698c..6b918af 100644
60919--- a/fs/xfs/xfs_bmap.c
60920+++ b/fs/xfs/xfs_bmap.c
60921@@ -765,7 +765,7 @@ xfs_bmap_validate_ret(
60922
60923 #else
60924 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
60925-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
60926+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
60927 #endif /* DEBUG */
60928
60929 /*
60930diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
60931index 97676a3..399a75d 100644
60932--- a/fs/xfs/xfs_dir2_sf.c
60933+++ b/fs/xfs/xfs_dir2_sf.c
60934@@ -848,7 +848,12 @@ xfs_dir2_sf_getdents(
60935
60936 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
60937 ctx->pos = off & 0x7fffffff;
60938- if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen,
60939+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
60940+ char name[sfep->namelen];
60941+ memcpy(name, sfep->name, sfep->namelen);
60942+ if (!dir_emit(ctx, name, sfep->namelen, ino, DT_UNKNOWN))
60943+ return 0;
60944+ } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen,
60945 ino, DT_UNKNOWN))
60946 return 0;
60947 sfep = xfs_dir2_sf_nextentry(sfp, sfep);
60948diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
60949index 6e2bca5..6ce80d3 100644
60950--- a/fs/xfs/xfs_ioctl.c
60951+++ b/fs/xfs/xfs_ioctl.c
60952@@ -127,7 +127,7 @@ xfs_find_handle(
60953 }
60954
60955 error = -EFAULT;
60956- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
60957+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
60958 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
60959 goto out_put;
60960
60961diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
60962index 96dda62..d6c6a52 100644
60963--- a/fs/xfs/xfs_iops.c
60964+++ b/fs/xfs/xfs_iops.c
60965@@ -395,7 +395,7 @@ xfs_vn_put_link(
60966 struct nameidata *nd,
60967 void *p)
60968 {
60969- char *s = nd_get_link(nd);
60970+ const char *s = nd_get_link(nd);
60971
60972 if (!IS_ERR(s))
60973 kfree(s);
60974diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
60975new file mode 100644
60976index 0000000..0fd7c82
60977--- /dev/null
60978+++ b/grsecurity/Kconfig
60979@@ -0,0 +1,1080 @@
60980+#
60981+# grecurity configuration
60982+#
60983+menu "Memory Protections"
60984+depends on GRKERNSEC
60985+
60986+config GRKERNSEC_KMEM
60987+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
60988+ default y if GRKERNSEC_CONFIG_AUTO
60989+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
60990+ help
60991+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
60992+ be written to or read from to modify or leak the contents of the running
60993+ kernel. /dev/port will also not be allowed to be opened and support
60994+ for /dev/cpu/*/msr will be removed. If you have module
60995+ support disabled, enabling this will close up five ways that are
60996+ currently used to insert malicious code into the running kernel.
60997+
60998+ Even with all these features enabled, we still highly recommend that
60999+ you use the RBAC system, as it is still possible for an attacker to
61000+ modify the running kernel through privileged I/O granted by ioperm/iopl.
61001+
61002+ If you are not using XFree86, you may be able to stop this additional
61003+ case by enabling the 'Disable privileged I/O' option. Though nothing
61004+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
61005+ but only to video memory, which is the only writing we allow in this
61006+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
61007+ not be allowed to mprotect it with PROT_WRITE later.
61008+ Enabling this feature will prevent the "cpupower" and "powertop" tools
61009+ from working.
61010+
61011+ It is highly recommended that you say Y here if you meet all the
61012+ conditions above.
61013+
61014+config GRKERNSEC_VM86
61015+ bool "Restrict VM86 mode"
61016+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
61017+ depends on X86_32
61018+
61019+ help
61020+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
61021+ make use of a special execution mode on 32bit x86 processors called
61022+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
61023+ video cards and will still work with this option enabled. The purpose
61024+ of the option is to prevent exploitation of emulation errors in
61025+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
61026+ Nearly all users should be able to enable this option.
61027+
61028+config GRKERNSEC_IO
61029+ bool "Disable privileged I/O"
61030+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
61031+ depends on X86
61032+ select RTC_CLASS
61033+ select RTC_INTF_DEV
61034+ select RTC_DRV_CMOS
61035+
61036+ help
61037+ If you say Y here, all ioperm and iopl calls will return an error.
61038+ Ioperm and iopl can be used to modify the running kernel.
61039+ Unfortunately, some programs need this access to operate properly,
61040+ the most notable of which are XFree86 and hwclock. hwclock can be
61041+ remedied by having RTC support in the kernel, so real-time
61042+ clock support is enabled if this option is enabled, to ensure
61043+ that hwclock operates correctly. XFree86 still will not
61044+ operate correctly with this option enabled, so DO NOT CHOOSE Y
61045+ IF YOU USE XFree86. If you use XFree86 and you still want to
61046+ protect your kernel against modification, use the RBAC system.
61047+
61048+config GRKERNSEC_JIT_HARDEN
61049+ bool "Harden BPF JIT against spray attacks"
61050+ default y if GRKERNSEC_CONFIG_AUTO
61051+ depends on BPF_JIT
61052+ help
61053+ If you say Y here, the native code generated by the kernel's Berkeley
61054+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
61055+ attacks that attempt to fit attacker-beneficial instructions in
61056+ 32bit immediate fields of JIT-generated native instructions. The
61057+ attacker will generally aim to cause an unintended instruction sequence
61058+ of JIT-generated native code to execute by jumping into the middle of
61059+ a generated instruction. This feature effectively randomizes the 32bit
61060+ immediate constants present in the generated code to thwart such attacks.
61061+
61062+ If you're using KERNEXEC, it's recommended that you enable this option
61063+ to supplement the hardening of the kernel.
61064+
61065+config GRKERNSEC_PERF_HARDEN
61066+ bool "Disable unprivileged PERF_EVENTS usage by default"
61067+ default y if GRKERNSEC_CONFIG_AUTO
61068+ depends on PERF_EVENTS
61069+ help
61070+ If you say Y here, the range of acceptable values for the
61071+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
61072+ default to a new value: 3. When the sysctl is set to this value, no
61073+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
61074+
61075+ Though PERF_EVENTS can be used legitimately for performance monitoring
61076+ and low-level application profiling, it is forced on regardless of
61077+ configuration, has been at fault for several vulnerabilities, and
61078+ creates new opportunities for side channels and other information leaks.
61079+
61080+ This feature puts PERF_EVENTS into a secure default state and permits
61081+ the administrator to change out of it temporarily if unprivileged
61082+ application profiling is needed.
61083+
61084+config GRKERNSEC_RAND_THREADSTACK
61085+ bool "Insert random gaps between thread stacks"
61086+ default y if GRKERNSEC_CONFIG_AUTO
61087+ depends on PAX_RANDMMAP && !PPC
61088+ help
61089+ If you say Y here, a random-sized gap will be enforced between allocated
61090+ thread stacks. Glibc's NPTL and other threading libraries that
61091+ pass MAP_STACK to the kernel for thread stack allocation are supported.
61092+ The implementation currently provides 8 bits of entropy for the gap.
61093+
61094+ Many distributions do not compile threaded remote services with the
61095+ -fstack-check argument to GCC, causing the variable-sized stack-based
61096+ allocator, alloca(), to not probe the stack on allocation. This
61097+ permits an unbounded alloca() to skip over any guard page and potentially
61098+ modify another thread's stack reliably. An enforced random gap
61099+ reduces the reliability of such an attack and increases the chance
61100+ that such a read/write to another thread's stack instead lands in
61101+ an unmapped area, causing a crash and triggering grsecurity's
61102+ anti-bruteforcing logic.
61103+
61104+config GRKERNSEC_PROC_MEMMAP
61105+ bool "Harden ASLR against information leaks and entropy reduction"
61106+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
61107+ depends on PAX_NOEXEC || PAX_ASLR
61108+ help
61109+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
61110+ give no information about the addresses of its mappings if
61111+ PaX features that rely on random addresses are enabled on the task.
61112+ In addition to sanitizing this information and disabling other
61113+ dangerous sources of information, this option causes reads of sensitive
61114+ /proc/<pid> entries where the file descriptor was opened in a different
61115+ task than the one performing the read. Such attempts are logged.
61116+ This option also limits argv/env strings for suid/sgid binaries
61117+ to 512KB to prevent a complete exhaustion of the stack entropy provided
61118+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
61119+ binaries to prevent alternative mmap layouts from being abused.
61120+
61121+ If you use PaX it is essential that you say Y here as it closes up
61122+ several holes that make full ASLR useless locally.
61123+
61124+config GRKERNSEC_BRUTE
61125+ bool "Deter exploit bruteforcing"
61126+ default y if GRKERNSEC_CONFIG_AUTO
61127+ help
61128+ If you say Y here, attempts to bruteforce exploits against forking
61129+ daemons such as apache or sshd, as well as against suid/sgid binaries
61130+ will be deterred. When a child of a forking daemon is killed by PaX
61131+ or crashes due to an illegal instruction or other suspicious signal,
61132+ the parent process will be delayed 30 seconds upon every subsequent
61133+ fork until the administrator is able to assess the situation and
61134+ restart the daemon.
61135+ In the suid/sgid case, the attempt is logged, the user has all their
61136+ existing instances of the suid/sgid binary terminated and will
61137+ be unable to execute any suid/sgid binaries for 15 minutes.
61138+
61139+ It is recommended that you also enable signal logging in the auditing
61140+ section so that logs are generated when a process triggers a suspicious
61141+ signal.
61142+ If the sysctl option is enabled, a sysctl option with name
61143+ "deter_bruteforce" is created.
61144+
61145+
61146+config GRKERNSEC_MODHARDEN
61147+ bool "Harden module auto-loading"
61148+ default y if GRKERNSEC_CONFIG_AUTO
61149+ depends on MODULES
61150+ help
61151+ If you say Y here, module auto-loading in response to use of some
61152+ feature implemented by an unloaded module will be restricted to
61153+ root users. Enabling this option helps defend against attacks
61154+ by unprivileged users who abuse the auto-loading behavior to
61155+ cause a vulnerable module to load that is then exploited.
61156+
61157+ If this option prevents a legitimate use of auto-loading for a
61158+ non-root user, the administrator can execute modprobe manually
61159+ with the exact name of the module mentioned in the alert log.
61160+ Alternatively, the administrator can add the module to the list
61161+ of modules loaded at boot by modifying init scripts.
61162+
61163+ Modification of init scripts will most likely be needed on
61164+ Ubuntu servers with encrypted home directory support enabled,
61165+ as the first non-root user logging in will cause the ecb(aes),
61166+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
61167+
61168+config GRKERNSEC_HIDESYM
61169+ bool "Hide kernel symbols"
61170+ default y if GRKERNSEC_CONFIG_AUTO
61171+ select PAX_USERCOPY_SLABS
61172+ help
61173+ If you say Y here, getting information on loaded modules, and
61174+ displaying all kernel symbols through a syscall will be restricted
61175+ to users with CAP_SYS_MODULE. For software compatibility reasons,
61176+ /proc/kallsyms will be restricted to the root user. The RBAC
61177+ system can hide that entry even from root.
61178+
61179+ This option also prevents leaking of kernel addresses through
61180+ several /proc entries.
61181+
61182+ Note that this option is only effective provided the following
61183+ conditions are met:
61184+ 1) The kernel using grsecurity is not precompiled by some distribution
61185+ 2) You have also enabled GRKERNSEC_DMESG
61186+ 3) You are using the RBAC system and hiding other files such as your
61187+ kernel image and System.map. Alternatively, enabling this option
61188+ causes the permissions on /boot, /lib/modules, and the kernel
61189+ source directory to change at compile time to prevent
61190+ reading by non-root users.
61191+ If the above conditions are met, this option will aid in providing a
61192+ useful protection against local kernel exploitation of overflows
61193+ and arbitrary read/write vulnerabilities.
61194+
61195+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
61196+ in addition to this feature.
61197+
61198+config GRKERNSEC_KERN_LOCKOUT
61199+ bool "Active kernel exploit response"
61200+ default y if GRKERNSEC_CONFIG_AUTO
61201+ depends on X86 || ARM || PPC || SPARC
61202+ help
61203+ If you say Y here, when a PaX alert is triggered due to suspicious
61204+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
61205+ or an OOPS occurs due to bad memory accesses, instead of just
61206+ terminating the offending process (and potentially allowing
61207+ a subsequent exploit from the same user), we will take one of two
61208+ actions:
61209+ If the user was root, we will panic the system
61210+ If the user was non-root, we will log the attempt, terminate
61211+ all processes owned by the user, then prevent them from creating
61212+ any new processes until the system is restarted
61213+ This deters repeated kernel exploitation/bruteforcing attempts
61214+ and is useful for later forensics.
61215+
61216+endmenu
61217+menu "Role Based Access Control Options"
61218+depends on GRKERNSEC
61219+
61220+config GRKERNSEC_RBAC_DEBUG
61221+ bool
61222+
61223+config GRKERNSEC_NO_RBAC
61224+ bool "Disable RBAC system"
61225+ help
61226+ If you say Y here, the /dev/grsec device will be removed from the kernel,
61227+ preventing the RBAC system from being enabled. You should only say Y
61228+ here if you have no intention of using the RBAC system, so as to prevent
61229+ an attacker with root access from misusing the RBAC system to hide files
61230+ and processes when loadable module support and /dev/[k]mem have been
61231+ locked down.
61232+
61233+config GRKERNSEC_ACL_HIDEKERN
61234+ bool "Hide kernel processes"
61235+ help
61236+ If you say Y here, all kernel threads will be hidden to all
61237+ processes but those whose subject has the "view hidden processes"
61238+ flag.
61239+
61240+config GRKERNSEC_ACL_MAXTRIES
61241+ int "Maximum tries before password lockout"
61242+ default 3
61243+ help
61244+ This option enforces the maximum number of times a user can attempt
61245+ to authorize themselves with the grsecurity RBAC system before being
61246+ denied the ability to attempt authorization again for a specified time.
61247+ The lower the number, the harder it will be to brute-force a password.
61248+
61249+config GRKERNSEC_ACL_TIMEOUT
61250+ int "Time to wait after max password tries, in seconds"
61251+ default 30
61252+ help
61253+ This option specifies the time the user must wait after attempting to
61254+ authorize to the RBAC system with the maximum number of invalid
61255+ passwords. The higher the number, the harder it will be to brute-force
61256+ a password.
61257+
61258+endmenu
61259+menu "Filesystem Protections"
61260+depends on GRKERNSEC
61261+
61262+config GRKERNSEC_PROC
61263+ bool "Proc restrictions"
61264+ default y if GRKERNSEC_CONFIG_AUTO
61265+ help
61266+ If you say Y here, the permissions of the /proc filesystem
61267+ will be altered to enhance system security and privacy. You MUST
61268+ choose either a user only restriction or a user and group restriction.
61269+ Depending upon the option you choose, you can either restrict users to
61270+ see only the processes they themselves run, or choose a group that can
61271+ view all processes and files normally restricted to root if you choose
61272+ the "restrict to user only" option. NOTE: If you're running identd or
61273+ ntpd as a non-root user, you will have to run it as the group you
61274+ specify here.
61275+
61276+config GRKERNSEC_PROC_USER
61277+ bool "Restrict /proc to user only"
61278+ depends on GRKERNSEC_PROC
61279+ help
61280+ If you say Y here, non-root users will only be able to view their own
61281+ processes, and restricts them from viewing network-related information,
61282+ and viewing kernel symbol and module information.
61283+
61284+config GRKERNSEC_PROC_USERGROUP
61285+ bool "Allow special group"
61286+ default y if GRKERNSEC_CONFIG_AUTO
61287+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
61288+ help
61289+ If you say Y here, you will be able to select a group that will be
61290+ able to view all processes and network-related information. If you've
61291+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
61292+ remain hidden. This option is useful if you want to run identd as
61293+ a non-root user. The group you select may also be chosen at boot time
61294+ via "grsec_proc_gid=" on the kernel commandline.
61295+
61296+config GRKERNSEC_PROC_GID
61297+ int "GID for special group"
61298+ depends on GRKERNSEC_PROC_USERGROUP
61299+ default 1001
61300+
61301+config GRKERNSEC_PROC_ADD
61302+ bool "Additional restrictions"
61303+ default y if GRKERNSEC_CONFIG_AUTO
61304+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
61305+ help
61306+ If you say Y here, additional restrictions will be placed on
61307+ /proc that keep normal users from viewing device information and
61308+ slabinfo information that could be useful for exploits.
61309+
61310+config GRKERNSEC_LINK
61311+ bool "Linking restrictions"
61312+ default y if GRKERNSEC_CONFIG_AUTO
61313+ help
61314+ If you say Y here, /tmp race exploits will be prevented, since users
61315+ will no longer be able to follow symlinks owned by other users in
61316+ world-writable +t directories (e.g. /tmp), unless the owner of the
61317+ symlink is the owner of the directory. users will also not be
61318+ able to hardlink to files they do not own. If the sysctl option is
61319+ enabled, a sysctl option with name "linking_restrictions" is created.
61320+
61321+config GRKERNSEC_SYMLINKOWN
61322+ bool "Kernel-enforced SymlinksIfOwnerMatch"
61323+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
61324+ help
61325+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
61326+ that prevents it from being used as a security feature. As Apache
61327+ verifies the symlink by performing a stat() against the target of
61328+ the symlink before it is followed, an attacker can setup a symlink
61329+ to point to a same-owned file, then replace the symlink with one
61330+ that targets another user's file just after Apache "validates" the
61331+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
61332+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
61333+ will be in place for the group you specify. If the sysctl option
61334+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
61335+ created.
61336+
61337+config GRKERNSEC_SYMLINKOWN_GID
61338+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
61339+ depends on GRKERNSEC_SYMLINKOWN
61340+ default 1006
61341+ help
61342+ Setting this GID determines what group kernel-enforced
61343+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
61344+ is enabled, a sysctl option with name "symlinkown_gid" is created.
61345+
61346+config GRKERNSEC_FIFO
61347+ bool "FIFO restrictions"
61348+ default y if GRKERNSEC_CONFIG_AUTO
61349+ help
61350+ If you say Y here, users will not be able to write to FIFOs they don't
61351+ own in world-writable +t directories (e.g. /tmp), unless the owner of
61352+ the FIFO is the same owner of the directory it's held in. If the sysctl
61353+ option is enabled, a sysctl option with name "fifo_restrictions" is
61354+ created.
61355+
61356+config GRKERNSEC_SYSFS_RESTRICT
61357+ bool "Sysfs/debugfs restriction"
61358+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
61359+ depends on SYSFS
61360+ help
61361+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
61362+ any filesystem normally mounted under it (e.g. debugfs) will be
61363+ mostly accessible only by root. These filesystems generally provide access
61364+ to hardware and debug information that isn't appropriate for unprivileged
61365+ users of the system. Sysfs and debugfs have also become a large source
61366+ of new vulnerabilities, ranging from infoleaks to local compromise.
61367+ There has been very little oversight with an eye toward security involved
61368+ in adding new exporters of information to these filesystems, so their
61369+ use is discouraged.
61370+ For reasons of compatibility, a few directories have been whitelisted
61371+ for access by non-root users:
61372+ /sys/fs/selinux
61373+ /sys/fs/fuse
61374+ /sys/devices/system/cpu
61375+
61376+config GRKERNSEC_ROFS
61377+ bool "Runtime read-only mount protection"
61378+ depends on SYSCTL
61379+ help
61380+ If you say Y here, a sysctl option with name "romount_protect" will
61381+ be created. By setting this option to 1 at runtime, filesystems
61382+ will be protected in the following ways:
61383+ * No new writable mounts will be allowed
61384+ * Existing read-only mounts won't be able to be remounted read/write
61385+ * Write operations will be denied on all block devices
61386+ This option acts independently of grsec_lock: once it is set to 1,
61387+ it cannot be turned off. Therefore, please be mindful of the resulting
61388+ behavior if this option is enabled in an init script on a read-only
61389+ filesystem. This feature is mainly intended for secure embedded systems.
61390+
61391+config GRKERNSEC_DEVICE_SIDECHANNEL
61392+ bool "Eliminate stat/notify-based device sidechannels"
61393+ default y if GRKERNSEC_CONFIG_AUTO
61394+ help
61395+ If you say Y here, timing analyses on block or character
61396+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
61397+ will be thwarted for unprivileged users. If a process without
61398+ CAP_MKNOD stats such a device, the last access and last modify times
61399+ will match the device's create time. No access or modify events
61400+ will be triggered through inotify/dnotify/fanotify for such devices.
61401+ This feature will prevent attacks that may at a minimum
61402+ allow an attacker to determine the administrator's password length.
61403+
61404+config GRKERNSEC_CHROOT
61405+ bool "Chroot jail restrictions"
61406+ default y if GRKERNSEC_CONFIG_AUTO
61407+ help
61408+ If you say Y here, you will be able to choose several options that will
61409+ make breaking out of a chrooted jail much more difficult. If you
61410+ encounter no software incompatibilities with the following options, it
61411+ is recommended that you enable each one.
61412+
61413+config GRKERNSEC_CHROOT_MOUNT
61414+ bool "Deny mounts"
61415+ default y if GRKERNSEC_CONFIG_AUTO
61416+ depends on GRKERNSEC_CHROOT
61417+ help
61418+ If you say Y here, processes inside a chroot will not be able to
61419+ mount or remount filesystems. If the sysctl option is enabled, a
61420+ sysctl option with name "chroot_deny_mount" is created.
61421+
61422+config GRKERNSEC_CHROOT_DOUBLE
61423+ bool "Deny double-chroots"
61424+ default y if GRKERNSEC_CONFIG_AUTO
61425+ depends on GRKERNSEC_CHROOT
61426+ help
61427+ If you say Y here, processes inside a chroot will not be able to chroot
61428+ again outside the chroot. This is a widely used method of breaking
61429+ out of a chroot jail and should not be allowed. If the sysctl
61430+ option is enabled, a sysctl option with name
61431+ "chroot_deny_chroot" is created.
61432+
61433+config GRKERNSEC_CHROOT_PIVOT
61434+ bool "Deny pivot_root in chroot"
61435+ default y if GRKERNSEC_CONFIG_AUTO
61436+ depends on GRKERNSEC_CHROOT
61437+ help
61438+ If you say Y here, processes inside a chroot will not be able to use
61439+ a function called pivot_root() that was introduced in Linux 2.3.41. It
61440+ works similar to chroot in that it changes the root filesystem. This
61441+ function could be misused in a chrooted process to attempt to break out
61442+ of the chroot, and therefore should not be allowed. If the sysctl
61443+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
61444+ created.
61445+
61446+config GRKERNSEC_CHROOT_CHDIR
61447+ bool "Enforce chdir(\"/\") on all chroots"
61448+ default y if GRKERNSEC_CONFIG_AUTO
61449+ depends on GRKERNSEC_CHROOT
61450+ help
61451+ If you say Y here, the current working directory of all newly-chrooted
61452+ applications will be set to the the root directory of the chroot.
61453+ The man page on chroot(2) states:
61454+ Note that this call does not change the current working
61455+ directory, so that `.' can be outside the tree rooted at
61456+ `/'. In particular, the super-user can escape from a
61457+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
61458+
61459+ It is recommended that you say Y here, since it's not known to break
61460+ any software. If the sysctl option is enabled, a sysctl option with
61461+ name "chroot_enforce_chdir" is created.
61462+
61463+config GRKERNSEC_CHROOT_CHMOD
61464+ bool "Deny (f)chmod +s"
61465+ default y if GRKERNSEC_CONFIG_AUTO
61466+ depends on GRKERNSEC_CHROOT
61467+ help
61468+ If you say Y here, processes inside a chroot will not be able to chmod
61469+ or fchmod files to make them have suid or sgid bits. This protects
61470+ against another published method of breaking a chroot. If the sysctl
61471+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
61472+ created.
61473+
61474+config GRKERNSEC_CHROOT_FCHDIR
61475+ bool "Deny fchdir out of chroot"
61476+ default y if GRKERNSEC_CONFIG_AUTO
61477+ depends on GRKERNSEC_CHROOT
61478+ help
61479+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
61480+ to a file descriptor of the chrooting process that points to a directory
61481+ outside the filesystem will be stopped. If the sysctl option
61482+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
61483+
61484+config GRKERNSEC_CHROOT_MKNOD
61485+ bool "Deny mknod"
61486+ default y if GRKERNSEC_CONFIG_AUTO
61487+ depends on GRKERNSEC_CHROOT
61488+ help
61489+ If you say Y here, processes inside a chroot will not be allowed to
61490+ mknod. The problem with using mknod inside a chroot is that it
61491+ would allow an attacker to create a device entry that is the same
61492+ as one on the physical root of your system, which could range from
61493+ anything from the console device to a device for your harddrive (which
61494+ they could then use to wipe the drive or steal data). It is recommended
61495+ that you say Y here, unless you run into software incompatibilities.
61496+ If the sysctl option is enabled, a sysctl option with name
61497+ "chroot_deny_mknod" is created.
61498+
61499+config GRKERNSEC_CHROOT_SHMAT
61500+ bool "Deny shmat() out of chroot"
61501+ default y if GRKERNSEC_CONFIG_AUTO
61502+ depends on GRKERNSEC_CHROOT
61503+ help
61504+ If you say Y here, processes inside a chroot will not be able to attach
61505+ to shared memory segments that were created outside of the chroot jail.
61506+ It is recommended that you say Y here. If the sysctl option is enabled,
61507+ a sysctl option with name "chroot_deny_shmat" is created.
61508+
61509+config GRKERNSEC_CHROOT_UNIX
61510+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
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
61515+ connect to abstract (meaning not belonging to a filesystem) Unix
61516+ domain sockets that were bound outside of a chroot. It is recommended
61517+ that you say Y here. If the sysctl option is enabled, a sysctl option
61518+ with name "chroot_deny_unix" is created.
61519+
61520+config GRKERNSEC_CHROOT_FINDTASK
61521+ bool "Protect outside processes"
61522+ default y if GRKERNSEC_CONFIG_AUTO
61523+ depends on GRKERNSEC_CHROOT
61524+ help
61525+ If you say Y here, processes inside a chroot will not be able to
61526+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
61527+ getsid, or view any process outside of the chroot. If the sysctl
61528+ option is enabled, a sysctl option with name "chroot_findtask" is
61529+ created.
61530+
61531+config GRKERNSEC_CHROOT_NICE
61532+ bool "Restrict priority changes"
61533+ default y if GRKERNSEC_CONFIG_AUTO
61534+ depends on GRKERNSEC_CHROOT
61535+ help
61536+ If you say Y here, processes inside a chroot will not be able to raise
61537+ the priority of processes in the chroot, or alter the priority of
61538+ processes outside the chroot. This provides more security than simply
61539+ removing CAP_SYS_NICE from the process' capability set. If the
61540+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
61541+ is created.
61542+
61543+config GRKERNSEC_CHROOT_SYSCTL
61544+ bool "Deny sysctl writes"
61545+ default y if GRKERNSEC_CONFIG_AUTO
61546+ depends on GRKERNSEC_CHROOT
61547+ help
61548+ If you say Y here, an attacker in a chroot will not be able to
61549+ write to sysctl entries, either by sysctl(2) or through a /proc
61550+ interface. It is strongly recommended that you say Y here. If the
61551+ sysctl option is enabled, a sysctl option with name
61552+ "chroot_deny_sysctl" is created.
61553+
61554+config GRKERNSEC_CHROOT_CAPS
61555+ bool "Capability restrictions"
61556+ default y if GRKERNSEC_CONFIG_AUTO
61557+ depends on GRKERNSEC_CHROOT
61558+ help
61559+ If you say Y here, the capabilities on all processes within a
61560+ chroot jail will be lowered to stop module insertion, raw i/o,
61561+ system and net admin tasks, rebooting the system, modifying immutable
61562+ files, modifying IPC owned by another, and changing the system time.
61563+ This is left an option because it can break some apps. Disable this
61564+ if your chrooted apps are having problems performing those kinds of
61565+ tasks. If the sysctl option is enabled, a sysctl option with
61566+ name "chroot_caps" is created.
61567+
61568+config GRKERNSEC_CHROOT_INITRD
61569+ bool "Exempt initrd tasks from restrictions"
61570+ default y if GRKERNSEC_CONFIG_AUTO
61571+ depends on GRKERNSEC_CHROOT && BLK_DEV_RAM
61572+ help
61573+ If you say Y here, tasks started prior to init will be exempted from
61574+ grsecurity's chroot restrictions. This option is mainly meant to
61575+ resolve Plymouth's performing privileged operations unnecessarily
61576+ in a chroot.
61577+
61578+endmenu
61579+menu "Kernel Auditing"
61580+depends on GRKERNSEC
61581+
61582+config GRKERNSEC_AUDIT_GROUP
61583+ bool "Single group for auditing"
61584+ help
61585+ If you say Y here, the exec and chdir logging features will only operate
61586+ on a group you specify. This option is recommended if you only want to
61587+ watch certain users instead of having a large amount of logs from the
61588+ entire system. If the sysctl option is enabled, a sysctl option with
61589+ name "audit_group" is created.
61590+
61591+config GRKERNSEC_AUDIT_GID
61592+ int "GID for auditing"
61593+ depends on GRKERNSEC_AUDIT_GROUP
61594+ default 1007
61595+
61596+config GRKERNSEC_EXECLOG
61597+ bool "Exec logging"
61598+ help
61599+ If you say Y here, all execve() calls will be logged (since the
61600+ other exec*() calls are frontends to execve(), all execution
61601+ will be logged). Useful for shell-servers that like to keep track
61602+ of their users. If the sysctl option is enabled, a sysctl option with
61603+ name "exec_logging" is created.
61604+ WARNING: This option when enabled will produce a LOT of logs, especially
61605+ on an active system.
61606+
61607+config GRKERNSEC_RESLOG
61608+ bool "Resource logging"
61609+ default y if GRKERNSEC_CONFIG_AUTO
61610+ help
61611+ If you say Y here, all attempts to overstep resource limits will
61612+ be logged with the resource name, the requested size, and the current
61613+ limit. It is highly recommended that you say Y here. If the sysctl
61614+ option is enabled, a sysctl option with name "resource_logging" is
61615+ created. If the RBAC system is enabled, the sysctl value is ignored.
61616+
61617+config GRKERNSEC_CHROOT_EXECLOG
61618+ bool "Log execs within chroot"
61619+ help
61620+ If you say Y here, all executions inside a chroot jail will be logged
61621+ to syslog. This can cause a large amount of logs if certain
61622+ applications (eg. djb's daemontools) are installed on the system, and
61623+ is therefore left as an option. If the sysctl option is enabled, a
61624+ sysctl option with name "chroot_execlog" is created.
61625+
61626+config GRKERNSEC_AUDIT_PTRACE
61627+ bool "Ptrace logging"
61628+ help
61629+ If you say Y here, all attempts to attach to a process via ptrace
61630+ will be logged. If the sysctl option is enabled, a sysctl option
61631+ with name "audit_ptrace" is created.
61632+
61633+config GRKERNSEC_AUDIT_CHDIR
61634+ bool "Chdir logging"
61635+ help
61636+ If you say Y here, all chdir() calls will be logged. If the sysctl
61637+ option is enabled, a sysctl option with name "audit_chdir" is created.
61638+
61639+config GRKERNSEC_AUDIT_MOUNT
61640+ bool "(Un)Mount logging"
61641+ help
61642+ If you say Y here, all mounts and unmounts will be logged. If the
61643+ sysctl option is enabled, a sysctl option with name "audit_mount" is
61644+ created.
61645+
61646+config GRKERNSEC_SIGNAL
61647+ bool "Signal logging"
61648+ default y if GRKERNSEC_CONFIG_AUTO
61649+ help
61650+ If you say Y here, certain important signals will be logged, such as
61651+ SIGSEGV, which will as a result inform you of when a error in a program
61652+ occurred, which in some cases could mean a possible exploit attempt.
61653+ If the sysctl option is enabled, a sysctl option with name
61654+ "signal_logging" is created.
61655+
61656+config GRKERNSEC_FORKFAIL
61657+ bool "Fork failure logging"
61658+ help
61659+ If you say Y here, all failed fork() attempts will be logged.
61660+ This could suggest a fork bomb, or someone attempting to overstep
61661+ their process limit. If the sysctl option is enabled, a sysctl option
61662+ with name "forkfail_logging" is created.
61663+
61664+config GRKERNSEC_TIME
61665+ bool "Time change logging"
61666+ default y if GRKERNSEC_CONFIG_AUTO
61667+ help
61668+ If you say Y here, any changes of the system clock will be logged.
61669+ If the sysctl option is enabled, a sysctl option with name
61670+ "timechange_logging" is created.
61671+
61672+config GRKERNSEC_PROC_IPADDR
61673+ bool "/proc/<pid>/ipaddr support"
61674+ default y if GRKERNSEC_CONFIG_AUTO
61675+ help
61676+ If you say Y here, a new entry will be added to each /proc/<pid>
61677+ directory that contains the IP address of the person using the task.
61678+ The IP is carried across local TCP and AF_UNIX stream sockets.
61679+ This information can be useful for IDS/IPSes to perform remote response
61680+ to a local attack. The entry is readable by only the owner of the
61681+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
61682+ the RBAC system), and thus does not create privacy concerns.
61683+
61684+config GRKERNSEC_RWXMAP_LOG
61685+ bool 'Denied RWX mmap/mprotect logging'
61686+ default y if GRKERNSEC_CONFIG_AUTO
61687+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
61688+ help
61689+ If you say Y here, calls to mmap() and mprotect() with explicit
61690+ usage of PROT_WRITE and PROT_EXEC together will be logged when
61691+ denied by the PAX_MPROTECT feature. This feature will also
61692+ log other problematic scenarios that can occur when PAX_MPROTECT
61693+ is enabled on a binary, like textrels and PT_GNU_STACK. If the
61694+ sysctl option is enabled, a sysctl option with name "rwxmap_logging"
61695+ is created.
61696+
61697+endmenu
61698+
61699+menu "Executable Protections"
61700+depends on GRKERNSEC
61701+
61702+config GRKERNSEC_DMESG
61703+ bool "Dmesg(8) restriction"
61704+ default y if GRKERNSEC_CONFIG_AUTO
61705+ help
61706+ If you say Y here, non-root users will not be able to use dmesg(8)
61707+ to view the contents of the kernel's circular log buffer.
61708+ The kernel's log buffer often contains kernel addresses and other
61709+ identifying information useful to an attacker in fingerprinting a
61710+ system for a targeted exploit.
61711+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
61712+ created.
61713+
61714+config GRKERNSEC_HARDEN_PTRACE
61715+ bool "Deter ptrace-based process snooping"
61716+ default y if GRKERNSEC_CONFIG_AUTO
61717+ help
61718+ If you say Y here, TTY sniffers and other malicious monitoring
61719+ programs implemented through ptrace will be defeated. If you
61720+ have been using the RBAC system, this option has already been
61721+ enabled for several years for all users, with the ability to make
61722+ fine-grained exceptions.
61723+
61724+ This option only affects the ability of non-root users to ptrace
61725+ processes that are not a descendent of the ptracing process.
61726+ This means that strace ./binary and gdb ./binary will still work,
61727+ but attaching to arbitrary processes will not. If the sysctl
61728+ option is enabled, a sysctl option with name "harden_ptrace" is
61729+ created.
61730+
61731+config GRKERNSEC_PTRACE_READEXEC
61732+ bool "Require read access to ptrace sensitive binaries"
61733+ default y if GRKERNSEC_CONFIG_AUTO
61734+ help
61735+ If you say Y here, unprivileged users will not be able to ptrace unreadable
61736+ binaries. This option is useful in environments that
61737+ remove the read bits (e.g. file mode 4711) from suid binaries to
61738+ prevent infoleaking of their contents. This option adds
61739+ consistency to the use of that file mode, as the binary could normally
61740+ be read out when run without privileges while ptracing.
61741+
61742+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
61743+ is created.
61744+
61745+config GRKERNSEC_SETXID
61746+ bool "Enforce consistent multithreaded privileges"
61747+ default y if GRKERNSEC_CONFIG_AUTO
61748+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
61749+ help
61750+ If you say Y here, a change from a root uid to a non-root uid
61751+ in a multithreaded application will cause the resulting uids,
61752+ gids, supplementary groups, and capabilities in that thread
61753+ to be propagated to the other threads of the process. In most
61754+ cases this is unnecessary, as glibc will emulate this behavior
61755+ on behalf of the application. Other libcs do not act in the
61756+ same way, allowing the other threads of the process to continue
61757+ running with root privileges. If the sysctl option is enabled,
61758+ a sysctl option with name "consistent_setxid" is created.
61759+
61760+config GRKERNSEC_TPE
61761+ bool "Trusted Path Execution (TPE)"
61762+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
61763+ help
61764+ If you say Y here, you will be able to choose a gid to add to the
61765+ supplementary groups of users you want to mark as "untrusted."
61766+ These users will not be able to execute any files that are not in
61767+ root-owned directories writable only by root. If the sysctl option
61768+ is enabled, a sysctl option with name "tpe" is created.
61769+
61770+config GRKERNSEC_TPE_ALL
61771+ bool "Partially restrict all non-root users"
61772+ depends on GRKERNSEC_TPE
61773+ help
61774+ If you say Y here, all non-root users will be covered under
61775+ a weaker TPE restriction. This is separate from, and in addition to,
61776+ the main TPE options that you have selected elsewhere. Thus, if a
61777+ "trusted" GID is chosen, this restriction applies to even that GID.
61778+ Under this restriction, all non-root users will only be allowed to
61779+ execute files in directories they own that are not group or
61780+ world-writable, or in directories owned by root and writable only by
61781+ root. If the sysctl option is enabled, a sysctl option with name
61782+ "tpe_restrict_all" is created.
61783+
61784+config GRKERNSEC_TPE_INVERT
61785+ bool "Invert GID option"
61786+ depends on GRKERNSEC_TPE
61787+ help
61788+ If you say Y here, the group you specify in the TPE configuration will
61789+ decide what group TPE restrictions will be *disabled* for. This
61790+ option is useful if you want TPE restrictions to be applied to most
61791+ users on the system. If the sysctl option is enabled, a sysctl option
61792+ with name "tpe_invert" is created. Unlike other sysctl options, this
61793+ entry will default to on for backward-compatibility.
61794+
61795+config GRKERNSEC_TPE_GID
61796+ int
61797+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
61798+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
61799+
61800+config GRKERNSEC_TPE_UNTRUSTED_GID
61801+ int "GID for TPE-untrusted users"
61802+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
61803+ default 1005
61804+ help
61805+ Setting this GID determines what group TPE restrictions will be
61806+ *enabled* for. If the sysctl option is enabled, a sysctl option
61807+ with name "tpe_gid" is created.
61808+
61809+config GRKERNSEC_TPE_TRUSTED_GID
61810+ int "GID for TPE-trusted users"
61811+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
61812+ default 1005
61813+ help
61814+ Setting this GID determines what group TPE restrictions will be
61815+ *disabled* for. If the sysctl option is enabled, a sysctl option
61816+ with name "tpe_gid" is created.
61817+
61818+endmenu
61819+menu "Network Protections"
61820+depends on GRKERNSEC
61821+
61822+config GRKERNSEC_RANDNET
61823+ bool "Larger entropy pools"
61824+ default y if GRKERNSEC_CONFIG_AUTO
61825+ help
61826+ If you say Y here, the entropy pools used for many features of Linux
61827+ and grsecurity will be doubled in size. Since several grsecurity
61828+ features use additional randomness, it is recommended that you say Y
61829+ here. Saying Y here has a similar effect as modifying
61830+ /proc/sys/kernel/random/poolsize.
61831+
61832+config GRKERNSEC_BLACKHOLE
61833+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
61834+ default y if GRKERNSEC_CONFIG_AUTO
61835+ depends on NET
61836+ help
61837+ If you say Y here, neither TCP resets nor ICMP
61838+ destination-unreachable packets will be sent in response to packets
61839+ sent to ports for which no associated listening process exists.
61840+ This feature supports both IPV4 and IPV6 and exempts the
61841+ loopback interface from blackholing. Enabling this feature
61842+ makes a host more resilient to DoS attacks and reduces network
61843+ visibility against scanners.
61844+
61845+ The blackhole feature as-implemented is equivalent to the FreeBSD
61846+ blackhole feature, as it prevents RST responses to all packets, not
61847+ just SYNs. Under most application behavior this causes no
61848+ problems, but applications (like haproxy) may not close certain
61849+ connections in a way that cleanly terminates them on the remote
61850+ end, leaving the remote host in LAST_ACK state. Because of this
61851+ side-effect and to prevent intentional LAST_ACK DoSes, this
61852+ feature also adds automatic mitigation against such attacks.
61853+ The mitigation drastically reduces the amount of time a socket
61854+ can spend in LAST_ACK state. If you're using haproxy and not
61855+ all servers it connects to have this option enabled, consider
61856+ disabling this feature on the haproxy host.
61857+
61858+ If the sysctl option is enabled, two sysctl options with names
61859+ "ip_blackhole" and "lastack_retries" will be created.
61860+ While "ip_blackhole" takes the standard zero/non-zero on/off
61861+ toggle, "lastack_retries" uses the same kinds of values as
61862+ "tcp_retries1" and "tcp_retries2". The default value of 4
61863+ prevents a socket from lasting more than 45 seconds in LAST_ACK
61864+ state.
61865+
61866+config GRKERNSEC_NO_SIMULT_CONNECT
61867+ bool "Disable TCP Simultaneous Connect"
61868+ default y if GRKERNSEC_CONFIG_AUTO
61869+ depends on NET
61870+ help
61871+ If you say Y here, a feature by Willy Tarreau will be enabled that
61872+ removes a weakness in Linux's strict implementation of TCP that
61873+ allows two clients to connect to each other without either entering
61874+ a listening state. The weakness allows an attacker to easily prevent
61875+ a client from connecting to a known server provided the source port
61876+ for the connection is guessed correctly.
61877+
61878+ As the weakness could be used to prevent an antivirus or IPS from
61879+ fetching updates, or prevent an SSL gateway from fetching a CRL,
61880+ it should be eliminated by enabling this option. Though Linux is
61881+ one of few operating systems supporting simultaneous connect, it
61882+ has no legitimate use in practice and is rarely supported by firewalls.
61883+
61884+config GRKERNSEC_SOCKET
61885+ bool "Socket restrictions"
61886+ depends on NET
61887+ help
61888+ If you say Y here, you will be able to choose from several options.
61889+ If you assign a GID on your system and add it to the supplementary
61890+ groups of users you want to restrict socket access to, this patch
61891+ will perform up to three things, based on the option(s) you choose.
61892+
61893+config GRKERNSEC_SOCKET_ALL
61894+ bool "Deny any sockets to group"
61895+ depends on GRKERNSEC_SOCKET
61896+ help
61897+ If you say Y here, you will be able to choose a GID of whose users will
61898+ be unable to connect to other hosts from your machine or run server
61899+ applications from your machine. If the sysctl option is enabled, a
61900+ sysctl option with name "socket_all" is created.
61901+
61902+config GRKERNSEC_SOCKET_ALL_GID
61903+ int "GID to deny all sockets for"
61904+ depends on GRKERNSEC_SOCKET_ALL
61905+ default 1004
61906+ help
61907+ Here you can choose the GID to disable socket access for. Remember to
61908+ add the users you want socket access disabled for to the GID
61909+ specified here. If the sysctl option is enabled, a sysctl option
61910+ with name "socket_all_gid" is created.
61911+
61912+config GRKERNSEC_SOCKET_CLIENT
61913+ bool "Deny client sockets to group"
61914+ depends on GRKERNSEC_SOCKET
61915+ help
61916+ If you say Y here, you will be able to choose a GID of whose users will
61917+ be unable to connect to other hosts from your machine, but will be
61918+ able to run servers. If this option is enabled, all users in the group
61919+ you specify will have to use passive mode when initiating ftp transfers
61920+ from the shell on your machine. If the sysctl option is enabled, a
61921+ sysctl option with name "socket_client" is created.
61922+
61923+config GRKERNSEC_SOCKET_CLIENT_GID
61924+ int "GID to deny client sockets for"
61925+ depends on GRKERNSEC_SOCKET_CLIENT
61926+ default 1003
61927+ help
61928+ Here you can choose the GID to disable client socket access for.
61929+ Remember to add the users you want client socket access disabled for to
61930+ the GID specified here. If the sysctl option is enabled, a sysctl
61931+ option with name "socket_client_gid" is created.
61932+
61933+config GRKERNSEC_SOCKET_SERVER
61934+ bool "Deny server sockets to group"
61935+ depends on GRKERNSEC_SOCKET
61936+ help
61937+ If you say Y here, you will be able to choose a GID of whose users will
61938+ be unable to run server applications from your machine. If the sysctl
61939+ option is enabled, a sysctl option with name "socket_server" is created.
61940+
61941+config GRKERNSEC_SOCKET_SERVER_GID
61942+ int "GID to deny server sockets for"
61943+ depends on GRKERNSEC_SOCKET_SERVER
61944+ default 1002
61945+ help
61946+ Here you can choose the GID to disable server socket access for.
61947+ Remember to add the users you want server socket access disabled for to
61948+ the GID specified here. If the sysctl option is enabled, a sysctl
61949+ option with name "socket_server_gid" is created.
61950+
61951+endmenu
61952+
61953+menu "Physical Protections"
61954+depends on GRKERNSEC
61955+
61956+config GRKERNSEC_DENYUSB
61957+ bool "Deny new USB connections after toggle"
61958+ default y if GRKERNSEC_CONFIG_AUTO
61959+ depends on SYSCTL && USB_SUPPORT
61960+ help
61961+ If you say Y here, a new sysctl option with name "deny_new_usb"
61962+ will be created. Setting its value to 1 will prevent any new
61963+ USB devices from being recognized by the OS. Any attempted USB
61964+ device insertion will be logged. This option is intended to be
61965+ used against custom USB devices designed to exploit vulnerabilities
61966+ in various USB device drivers.
61967+
61968+ For greatest effectiveness, this sysctl should be set after any
61969+ relevant init scripts. This option is safe to enable in distros
61970+ as each user can choose whether or not to toggle the sysctl.
61971+
61972+config GRKERNSEC_DENYUSB_FORCE
61973+ bool "Reject all USB devices not connected at boot"
61974+ select USB
61975+ depends on GRKERNSEC_DENYUSB
61976+ help
61977+ If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
61978+ that doesn't involve a sysctl entry. This option should only be
61979+ enabled if you're sure you want to deny all new USB connections
61980+ at runtime and don't want to modify init scripts. This should not
61981+ be enabled by distros. It forces the core USB code to be built
61982+ into the kernel image so that all devices connected at boot time
61983+ can be recognized and new USB device connections can be prevented
61984+ prior to init running.
61985+
61986+endmenu
61987+
61988+menu "Sysctl Support"
61989+depends on GRKERNSEC && SYSCTL
61990+
61991+config GRKERNSEC_SYSCTL
61992+ bool "Sysctl support"
61993+ default y if GRKERNSEC_CONFIG_AUTO
61994+ help
61995+ If you say Y here, you will be able to change the options that
61996+ grsecurity runs with at bootup, without having to recompile your
61997+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
61998+ to enable (1) or disable (0) various features. All the sysctl entries
61999+ are mutable until the "grsec_lock" entry is set to a non-zero value.
62000+ All features enabled in the kernel configuration are disabled at boot
62001+ if you do not say Y to the "Turn on features by default" option.
62002+ All options should be set at startup, and the grsec_lock entry should
62003+ be set to a non-zero value after all the options are set.
62004+ *THIS IS EXTREMELY IMPORTANT*
62005+
62006+config GRKERNSEC_SYSCTL_DISTRO
62007+ bool "Extra sysctl support for distro makers (READ HELP)"
62008+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
62009+ help
62010+ If you say Y here, additional sysctl options will be created
62011+ for features that affect processes running as root. Therefore,
62012+ it is critical when using this option that the grsec_lock entry be
62013+ enabled after boot. Only distros with prebuilt kernel packages
62014+ with this option enabled that can ensure grsec_lock is enabled
62015+ after boot should use this option.
62016+ *Failure to set grsec_lock after boot makes all grsec features
62017+ this option covers useless*
62018+
62019+ Currently this option creates the following sysctl entries:
62020+ "Disable Privileged I/O": "disable_priv_io"
62021+
62022+config GRKERNSEC_SYSCTL_ON
62023+ bool "Turn on features by default"
62024+ default y if GRKERNSEC_CONFIG_AUTO
62025+ depends on GRKERNSEC_SYSCTL
62026+ help
62027+ If you say Y here, instead of having all features enabled in the
62028+ kernel configuration disabled at boot time, the features will be
62029+ enabled at boot time. It is recommended you say Y here unless
62030+ there is some reason you would want all sysctl-tunable features to
62031+ be disabled by default. As mentioned elsewhere, it is important
62032+ to enable the grsec_lock entry once you have finished modifying
62033+ the sysctl entries.
62034+
62035+endmenu
62036+menu "Logging Options"
62037+depends on GRKERNSEC
62038+
62039+config GRKERNSEC_FLOODTIME
62040+ int "Seconds in between log messages (minimum)"
62041+ default 10
62042+ help
62043+ This option allows you to enforce the number of seconds between
62044+ grsecurity log messages. The default should be suitable for most
62045+ people, however, if you choose to change it, choose a value small enough
62046+ to allow informative logs to be produced, but large enough to
62047+ prevent flooding.
62048+
62049+config GRKERNSEC_FLOODBURST
62050+ int "Number of messages in a burst (maximum)"
62051+ default 6
62052+ help
62053+ This option allows you to choose the maximum number of messages allowed
62054+ within the flood time interval you chose in a separate option. The
62055+ default should be suitable for most people, however if you find that
62056+ many of your logs are being interpreted as flooding, you may want to
62057+ raise this value.
62058+
62059+endmenu
62060diff --git a/grsecurity/Makefile b/grsecurity/Makefile
62061new file mode 100644
62062index 0000000..b0b77d5
62063--- /dev/null
62064+++ b/grsecurity/Makefile
62065@@ -0,0 +1,43 @@
62066+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
62067+# during 2001-2009 it has been completely redesigned by Brad Spengler
62068+# into an RBAC system
62069+#
62070+# All code in this directory and various hooks inserted throughout the kernel
62071+# are copyright Brad Spengler - Open Source Security, Inc., and released
62072+# under the GPL v2 or higher
62073+
62074+KBUILD_CFLAGS += -Werror
62075+
62076+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
62077+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
62078+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
62079+ grsec_usb.o
62080+
62081+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
62082+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
62083+ gracl_learn.o grsec_log.o
62084+ifdef CONFIG_COMPAT
62085+obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
62086+endif
62087+
62088+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
62089+
62090+ifdef CONFIG_NET
62091+obj-y += grsec_sock.o
62092+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
62093+endif
62094+
62095+ifndef CONFIG_GRKERNSEC
62096+obj-y += grsec_disabled.o
62097+endif
62098+
62099+ifdef CONFIG_GRKERNSEC_HIDESYM
62100+extra-y := grsec_hidesym.o
62101+$(obj)/grsec_hidesym.o:
62102+ @-chmod -f 500 /boot
62103+ @-chmod -f 500 /lib/modules
62104+ @-chmod -f 500 /lib64/modules
62105+ @-chmod -f 500 /lib32/modules
62106+ @-chmod -f 700 .
62107+ @echo ' grsec: protected kernel image paths'
62108+endif
62109diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
62110new file mode 100644
62111index 0000000..c0793fd
62112--- /dev/null
62113+++ b/grsecurity/gracl.c
62114@@ -0,0 +1,4178 @@
62115+#include <linux/kernel.h>
62116+#include <linux/module.h>
62117+#include <linux/sched.h>
62118+#include <linux/mm.h>
62119+#include <linux/file.h>
62120+#include <linux/fs.h>
62121+#include <linux/namei.h>
62122+#include <linux/mount.h>
62123+#include <linux/tty.h>
62124+#include <linux/proc_fs.h>
62125+#include <linux/lglock.h>
62126+#include <linux/slab.h>
62127+#include <linux/vmalloc.h>
62128+#include <linux/types.h>
62129+#include <linux/sysctl.h>
62130+#include <linux/netdevice.h>
62131+#include <linux/ptrace.h>
62132+#include <linux/gracl.h>
62133+#include <linux/gralloc.h>
62134+#include <linux/security.h>
62135+#include <linux/grinternal.h>
62136+#include <linux/pid_namespace.h>
62137+#include <linux/stop_machine.h>
62138+#include <linux/fdtable.h>
62139+#include <linux/percpu.h>
62140+#include <linux/lglock.h>
62141+#include <linux/hugetlb.h>
62142+#include <linux/posix-timers.h>
62143+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
62144+#include <linux/magic.h>
62145+#include <linux/pagemap.h>
62146+#include "../fs/btrfs/async-thread.h"
62147+#include "../fs/btrfs/ctree.h"
62148+#include "../fs/btrfs/btrfs_inode.h"
62149+#endif
62150+#include "../fs/mount.h"
62151+
62152+#include <asm/uaccess.h>
62153+#include <asm/errno.h>
62154+#include <asm/mman.h>
62155+
62156+extern struct lglock vfsmount_lock;
62157+
62158+static struct acl_role_db acl_role_set;
62159+static struct name_db name_set;
62160+static struct inodev_db inodev_set;
62161+
62162+/* for keeping track of userspace pointers used for subjects, so we
62163+ can share references in the kernel as well
62164+*/
62165+
62166+static struct path real_root;
62167+
62168+static struct acl_subj_map_db subj_map_set;
62169+
62170+static struct acl_role_label *default_role;
62171+
62172+static struct acl_role_label *role_list;
62173+
62174+static u16 acl_sp_role_value;
62175+
62176+extern char *gr_shared_page[4];
62177+static DEFINE_MUTEX(gr_dev_mutex);
62178+DEFINE_RWLOCK(gr_inode_lock);
62179+
62180+struct gr_arg *gr_usermode;
62181+
62182+static unsigned int gr_status __read_only = GR_STATUS_INIT;
62183+
62184+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
62185+extern void gr_clear_learn_entries(void);
62186+
62187+unsigned char *gr_system_salt;
62188+unsigned char *gr_system_sum;
62189+
62190+static struct sprole_pw **acl_special_roles = NULL;
62191+static __u16 num_sprole_pws = 0;
62192+
62193+static struct acl_role_label *kernel_role = NULL;
62194+
62195+static unsigned int gr_auth_attempts = 0;
62196+static unsigned long gr_auth_expires = 0UL;
62197+
62198+#ifdef CONFIG_NET
62199+extern struct vfsmount *sock_mnt;
62200+#endif
62201+
62202+extern struct vfsmount *pipe_mnt;
62203+extern struct vfsmount *shm_mnt;
62204+
62205+#ifdef CONFIG_HUGETLBFS
62206+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
62207+#endif
62208+
62209+static struct acl_object_label *fakefs_obj_rw;
62210+static struct acl_object_label *fakefs_obj_rwx;
62211+
62212+extern int gr_init_uidset(void);
62213+extern void gr_free_uidset(void);
62214+extern void gr_remove_uid(uid_t uid);
62215+extern int gr_find_uid(uid_t uid);
62216+
62217+static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
62218+{
62219+ if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
62220+ return -EFAULT;
62221+
62222+ return 0;
62223+}
62224+
62225+static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
62226+{
62227+ if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
62228+ return -EFAULT;
62229+
62230+ return 0;
62231+}
62232+
62233+static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
62234+{
62235+ if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
62236+ return -EFAULT;
62237+
62238+ return 0;
62239+}
62240+
62241+static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
62242+{
62243+ if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
62244+ return -EFAULT;
62245+
62246+ return 0;
62247+}
62248+
62249+static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
62250+{
62251+ if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
62252+ return -EFAULT;
62253+
62254+ return 0;
62255+}
62256+
62257+static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
62258+{
62259+ if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
62260+ return -EFAULT;
62261+
62262+ return 0;
62263+}
62264+
62265+static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
62266+{
62267+ if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
62268+ return -EFAULT;
62269+
62270+ return 0;
62271+}
62272+
62273+static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
62274+{
62275+ if (copy_from_user(trans, userp, sizeof(struct role_transition)))
62276+ return -EFAULT;
62277+
62278+ return 0;
62279+}
62280+
62281+int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
62282+{
62283+ if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
62284+ return -EFAULT;
62285+
62286+ return 0;
62287+}
62288+
62289+static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
62290+{
62291+ if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
62292+ return -EFAULT;
62293+
62294+ if ((uwrap->version != GRSECURITY_VERSION) || (uwrap->size != sizeof(struct gr_arg)))
62295+ return -EINVAL;
62296+
62297+ return 0;
62298+}
62299+
62300+static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
62301+{
62302+ if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
62303+ return -EFAULT;
62304+
62305+ return 0;
62306+}
62307+
62308+static size_t get_gr_arg_wrapper_size_normal(void)
62309+{
62310+ return sizeof(struct gr_arg_wrapper);
62311+}
62312+
62313+#ifdef CONFIG_COMPAT
62314+extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
62315+extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
62316+extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
62317+extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
62318+extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
62319+extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
62320+extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
62321+extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
62322+extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
62323+extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
62324+extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
62325+extern size_t get_gr_arg_wrapper_size_compat(void);
62326+
62327+int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
62328+int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
62329+int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
62330+int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
62331+int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
62332+int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
62333+int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
62334+int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
62335+int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
62336+int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
62337+int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
62338+size_t (* get_gr_arg_wrapper_size)(void) __read_only;
62339+
62340+#else
62341+#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
62342+#define copy_gr_arg copy_gr_arg_normal
62343+#define copy_gr_hash_struct copy_gr_hash_struct_normal
62344+#define copy_acl_object_label copy_acl_object_label_normal
62345+#define copy_acl_subject_label copy_acl_subject_label_normal
62346+#define copy_acl_role_label copy_acl_role_label_normal
62347+#define copy_acl_ip_label copy_acl_ip_label_normal
62348+#define copy_pointer_from_array copy_pointer_from_array_normal
62349+#define copy_sprole_pw copy_sprole_pw_normal
62350+#define copy_role_transition copy_role_transition_normal
62351+#define copy_role_allowed_ip copy_role_allowed_ip_normal
62352+#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
62353+#endif
62354+
62355+__inline__ int
62356+gr_acl_is_enabled(void)
62357+{
62358+ return (gr_status & GR_READY);
62359+}
62360+
62361+static inline dev_t __get_dev(const struct dentry *dentry)
62362+{
62363+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
62364+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
62365+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
62366+ else
62367+#endif
62368+ return dentry->d_sb->s_dev;
62369+}
62370+
62371+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
62372+{
62373+ return __get_dev(dentry);
62374+}
62375+
62376+static char gr_task_roletype_to_char(struct task_struct *task)
62377+{
62378+ switch (task->role->roletype &
62379+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
62380+ GR_ROLE_SPECIAL)) {
62381+ case GR_ROLE_DEFAULT:
62382+ return 'D';
62383+ case GR_ROLE_USER:
62384+ return 'U';
62385+ case GR_ROLE_GROUP:
62386+ return 'G';
62387+ case GR_ROLE_SPECIAL:
62388+ return 'S';
62389+ }
62390+
62391+ return 'X';
62392+}
62393+
62394+char gr_roletype_to_char(void)
62395+{
62396+ return gr_task_roletype_to_char(current);
62397+}
62398+
62399+__inline__ int
62400+gr_acl_tpe_check(void)
62401+{
62402+ if (unlikely(!(gr_status & GR_READY)))
62403+ return 0;
62404+ if (current->role->roletype & GR_ROLE_TPE)
62405+ return 1;
62406+ else
62407+ return 0;
62408+}
62409+
62410+int
62411+gr_handle_rawio(const struct inode *inode)
62412+{
62413+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62414+ if (inode && S_ISBLK(inode->i_mode) &&
62415+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
62416+ !capable(CAP_SYS_RAWIO))
62417+ return 1;
62418+#endif
62419+ return 0;
62420+}
62421+
62422+static int
62423+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
62424+{
62425+ if (likely(lena != lenb))
62426+ return 0;
62427+
62428+ return !memcmp(a, b, lena);
62429+}
62430+
62431+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
62432+{
62433+ *buflen -= namelen;
62434+ if (*buflen < 0)
62435+ return -ENAMETOOLONG;
62436+ *buffer -= namelen;
62437+ memcpy(*buffer, str, namelen);
62438+ return 0;
62439+}
62440+
62441+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
62442+{
62443+ return prepend(buffer, buflen, name->name, name->len);
62444+}
62445+
62446+static int prepend_path(const struct path *path, struct path *root,
62447+ char **buffer, int *buflen)
62448+{
62449+ struct dentry *dentry = path->dentry;
62450+ struct vfsmount *vfsmnt = path->mnt;
62451+ struct mount *mnt = real_mount(vfsmnt);
62452+ bool slash = false;
62453+ int error = 0;
62454+
62455+ while (dentry != root->dentry || vfsmnt != root->mnt) {
62456+ struct dentry * parent;
62457+
62458+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
62459+ /* Global root? */
62460+ if (!mnt_has_parent(mnt)) {
62461+ goto out;
62462+ }
62463+ dentry = mnt->mnt_mountpoint;
62464+ mnt = mnt->mnt_parent;
62465+ vfsmnt = &mnt->mnt;
62466+ continue;
62467+ }
62468+ parent = dentry->d_parent;
62469+ prefetch(parent);
62470+ spin_lock(&dentry->d_lock);
62471+ error = prepend_name(buffer, buflen, &dentry->d_name);
62472+ spin_unlock(&dentry->d_lock);
62473+ if (!error)
62474+ error = prepend(buffer, buflen, "/", 1);
62475+ if (error)
62476+ break;
62477+
62478+ slash = true;
62479+ dentry = parent;
62480+ }
62481+
62482+out:
62483+ if (!error && !slash)
62484+ error = prepend(buffer, buflen, "/", 1);
62485+
62486+ return error;
62487+}
62488+
62489+/* this must be called with vfsmount_lock and rename_lock held */
62490+
62491+static char *__our_d_path(const struct path *path, struct path *root,
62492+ char *buf, int buflen)
62493+{
62494+ char *res = buf + buflen;
62495+ int error;
62496+
62497+ prepend(&res, &buflen, "\0", 1);
62498+ error = prepend_path(path, root, &res, &buflen);
62499+ if (error)
62500+ return ERR_PTR(error);
62501+
62502+ return res;
62503+}
62504+
62505+static char *
62506+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
62507+{
62508+ char *retval;
62509+
62510+ retval = __our_d_path(path, root, buf, buflen);
62511+ if (unlikely(IS_ERR(retval)))
62512+ retval = strcpy(buf, "<path too long>");
62513+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
62514+ retval[1] = '\0';
62515+
62516+ return retval;
62517+}
62518+
62519+static char *
62520+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
62521+ char *buf, int buflen)
62522+{
62523+ struct path path;
62524+ char *res;
62525+
62526+ path.dentry = (struct dentry *)dentry;
62527+ path.mnt = (struct vfsmount *)vfsmnt;
62528+
62529+ /* we can use real_root.dentry, real_root.mnt, because this is only called
62530+ by the RBAC system */
62531+ res = gen_full_path(&path, &real_root, buf, buflen);
62532+
62533+ return res;
62534+}
62535+
62536+static char *
62537+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
62538+ char *buf, int buflen)
62539+{
62540+ char *res;
62541+ struct path path;
62542+ struct path root;
62543+ struct task_struct *reaper = init_pid_ns.child_reaper;
62544+
62545+ path.dentry = (struct dentry *)dentry;
62546+ path.mnt = (struct vfsmount *)vfsmnt;
62547+
62548+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
62549+ get_fs_root(reaper->fs, &root);
62550+
62551+ br_read_lock(&vfsmount_lock);
62552+ write_seqlock(&rename_lock);
62553+ res = gen_full_path(&path, &root, buf, buflen);
62554+ write_sequnlock(&rename_lock);
62555+ br_read_unlock(&vfsmount_lock);
62556+
62557+ path_put(&root);
62558+ return res;
62559+}
62560+
62561+static char *
62562+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
62563+{
62564+ char *ret;
62565+ br_read_lock(&vfsmount_lock);
62566+ write_seqlock(&rename_lock);
62567+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
62568+ PAGE_SIZE);
62569+ write_sequnlock(&rename_lock);
62570+ br_read_unlock(&vfsmount_lock);
62571+ return ret;
62572+}
62573+
62574+static char *
62575+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
62576+{
62577+ char *ret;
62578+ char *buf;
62579+ int buflen;
62580+
62581+ br_read_lock(&vfsmount_lock);
62582+ write_seqlock(&rename_lock);
62583+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
62584+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
62585+ buflen = (int)(ret - buf);
62586+ if (buflen >= 5)
62587+ prepend(&ret, &buflen, "/proc", 5);
62588+ else
62589+ ret = strcpy(buf, "<path too long>");
62590+ write_sequnlock(&rename_lock);
62591+ br_read_unlock(&vfsmount_lock);
62592+ return ret;
62593+}
62594+
62595+char *
62596+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
62597+{
62598+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
62599+ PAGE_SIZE);
62600+}
62601+
62602+char *
62603+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
62604+{
62605+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
62606+ PAGE_SIZE);
62607+}
62608+
62609+char *
62610+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
62611+{
62612+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
62613+ PAGE_SIZE);
62614+}
62615+
62616+char *
62617+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
62618+{
62619+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
62620+ PAGE_SIZE);
62621+}
62622+
62623+char *
62624+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
62625+{
62626+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
62627+ PAGE_SIZE);
62628+}
62629+
62630+__inline__ __u32
62631+to_gr_audit(const __u32 reqmode)
62632+{
62633+ /* masks off auditable permission flags, then shifts them to create
62634+ auditing flags, and adds the special case of append auditing if
62635+ we're requesting write */
62636+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
62637+}
62638+
62639+struct acl_subject_label *
62640+lookup_subject_map(const struct acl_subject_label *userp)
62641+{
62642+ unsigned int index = gr_shash(userp, subj_map_set.s_size);
62643+ struct subject_map *match;
62644+
62645+ match = subj_map_set.s_hash[index];
62646+
62647+ while (match && match->user != userp)
62648+ match = match->next;
62649+
62650+ if (match != NULL)
62651+ return match->kernel;
62652+ else
62653+ return NULL;
62654+}
62655+
62656+static void
62657+insert_subj_map_entry(struct subject_map *subjmap)
62658+{
62659+ unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
62660+ struct subject_map **curr;
62661+
62662+ subjmap->prev = NULL;
62663+
62664+ curr = &subj_map_set.s_hash[index];
62665+ if (*curr != NULL)
62666+ (*curr)->prev = subjmap;
62667+
62668+ subjmap->next = *curr;
62669+ *curr = subjmap;
62670+
62671+ return;
62672+}
62673+
62674+static struct acl_role_label *
62675+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
62676+ const gid_t gid)
62677+{
62678+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
62679+ struct acl_role_label *match;
62680+ struct role_allowed_ip *ipp;
62681+ unsigned int x;
62682+ u32 curr_ip = task->signal->curr_ip;
62683+
62684+ task->signal->saved_ip = curr_ip;
62685+
62686+ match = acl_role_set.r_hash[index];
62687+
62688+ while (match) {
62689+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
62690+ for (x = 0; x < match->domain_child_num; x++) {
62691+ if (match->domain_children[x] == uid)
62692+ goto found;
62693+ }
62694+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
62695+ break;
62696+ match = match->next;
62697+ }
62698+found:
62699+ if (match == NULL) {
62700+ try_group:
62701+ index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
62702+ match = acl_role_set.r_hash[index];
62703+
62704+ while (match) {
62705+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
62706+ for (x = 0; x < match->domain_child_num; x++) {
62707+ if (match->domain_children[x] == gid)
62708+ goto found2;
62709+ }
62710+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
62711+ break;
62712+ match = match->next;
62713+ }
62714+found2:
62715+ if (match == NULL)
62716+ match = default_role;
62717+ if (match->allowed_ips == NULL)
62718+ return match;
62719+ else {
62720+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
62721+ if (likely
62722+ ((ntohl(curr_ip) & ipp->netmask) ==
62723+ (ntohl(ipp->addr) & ipp->netmask)))
62724+ return match;
62725+ }
62726+ match = default_role;
62727+ }
62728+ } else if (match->allowed_ips == NULL) {
62729+ return match;
62730+ } else {
62731+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
62732+ if (likely
62733+ ((ntohl(curr_ip) & ipp->netmask) ==
62734+ (ntohl(ipp->addr) & ipp->netmask)))
62735+ return match;
62736+ }
62737+ goto try_group;
62738+ }
62739+
62740+ return match;
62741+}
62742+
62743+struct acl_subject_label *
62744+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
62745+ const struct acl_role_label *role)
62746+{
62747+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
62748+ struct acl_subject_label *match;
62749+
62750+ match = role->subj_hash[index];
62751+
62752+ while (match && (match->inode != ino || match->device != dev ||
62753+ (match->mode & GR_DELETED))) {
62754+ match = match->next;
62755+ }
62756+
62757+ if (match && !(match->mode & GR_DELETED))
62758+ return match;
62759+ else
62760+ return NULL;
62761+}
62762+
62763+struct acl_subject_label *
62764+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
62765+ const struct acl_role_label *role)
62766+{
62767+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
62768+ struct acl_subject_label *match;
62769+
62770+ match = role->subj_hash[index];
62771+
62772+ while (match && (match->inode != ino || match->device != dev ||
62773+ !(match->mode & GR_DELETED))) {
62774+ match = match->next;
62775+ }
62776+
62777+ if (match && (match->mode & GR_DELETED))
62778+ return match;
62779+ else
62780+ return NULL;
62781+}
62782+
62783+static struct acl_object_label *
62784+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
62785+ const struct acl_subject_label *subj)
62786+{
62787+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
62788+ struct acl_object_label *match;
62789+
62790+ match = subj->obj_hash[index];
62791+
62792+ while (match && (match->inode != ino || match->device != dev ||
62793+ (match->mode & GR_DELETED))) {
62794+ match = match->next;
62795+ }
62796+
62797+ if (match && !(match->mode & GR_DELETED))
62798+ return match;
62799+ else
62800+ return NULL;
62801+}
62802+
62803+static struct acl_object_label *
62804+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
62805+ const struct acl_subject_label *subj)
62806+{
62807+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
62808+ struct acl_object_label *match;
62809+
62810+ match = subj->obj_hash[index];
62811+
62812+ while (match && (match->inode != ino || match->device != dev ||
62813+ !(match->mode & GR_DELETED))) {
62814+ match = match->next;
62815+ }
62816+
62817+ if (match && (match->mode & GR_DELETED))
62818+ return match;
62819+
62820+ match = subj->obj_hash[index];
62821+
62822+ while (match && (match->inode != ino || match->device != dev ||
62823+ (match->mode & GR_DELETED))) {
62824+ match = match->next;
62825+ }
62826+
62827+ if (match && !(match->mode & GR_DELETED))
62828+ return match;
62829+ else
62830+ return NULL;
62831+}
62832+
62833+static struct name_entry *
62834+lookup_name_entry(const char *name)
62835+{
62836+ unsigned int len = strlen(name);
62837+ unsigned int key = full_name_hash(name, len);
62838+ unsigned int index = key % name_set.n_size;
62839+ struct name_entry *match;
62840+
62841+ match = name_set.n_hash[index];
62842+
62843+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
62844+ match = match->next;
62845+
62846+ return match;
62847+}
62848+
62849+static struct name_entry *
62850+lookup_name_entry_create(const char *name)
62851+{
62852+ unsigned int len = strlen(name);
62853+ unsigned int key = full_name_hash(name, len);
62854+ unsigned int index = key % name_set.n_size;
62855+ struct name_entry *match;
62856+
62857+ match = name_set.n_hash[index];
62858+
62859+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
62860+ !match->deleted))
62861+ match = match->next;
62862+
62863+ if (match && match->deleted)
62864+ return match;
62865+
62866+ match = name_set.n_hash[index];
62867+
62868+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
62869+ match->deleted))
62870+ match = match->next;
62871+
62872+ if (match && !match->deleted)
62873+ return match;
62874+ else
62875+ return NULL;
62876+}
62877+
62878+static struct inodev_entry *
62879+lookup_inodev_entry(const ino_t ino, const dev_t dev)
62880+{
62881+ unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
62882+ struct inodev_entry *match;
62883+
62884+ match = inodev_set.i_hash[index];
62885+
62886+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
62887+ match = match->next;
62888+
62889+ return match;
62890+}
62891+
62892+static void
62893+insert_inodev_entry(struct inodev_entry *entry)
62894+{
62895+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
62896+ inodev_set.i_size);
62897+ struct inodev_entry **curr;
62898+
62899+ entry->prev = NULL;
62900+
62901+ curr = &inodev_set.i_hash[index];
62902+ if (*curr != NULL)
62903+ (*curr)->prev = entry;
62904+
62905+ entry->next = *curr;
62906+ *curr = entry;
62907+
62908+ return;
62909+}
62910+
62911+static void
62912+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
62913+{
62914+ unsigned int index =
62915+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
62916+ struct acl_role_label **curr;
62917+ struct acl_role_label *tmp, *tmp2;
62918+
62919+ curr = &acl_role_set.r_hash[index];
62920+
62921+ /* simple case, slot is empty, just set it to our role */
62922+ if (*curr == NULL) {
62923+ *curr = role;
62924+ } else {
62925+ /* example:
62926+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
62927+ 2 -> 3
62928+ */
62929+ /* first check to see if we can already be reached via this slot */
62930+ tmp = *curr;
62931+ while (tmp && tmp != role)
62932+ tmp = tmp->next;
62933+ if (tmp == role) {
62934+ /* we don't need to add ourselves to this slot's chain */
62935+ return;
62936+ }
62937+ /* we need to add ourselves to this chain, two cases */
62938+ if (role->next == NULL) {
62939+ /* simple case, append the current chain to our role */
62940+ role->next = *curr;
62941+ *curr = role;
62942+ } else {
62943+ /* 1 -> 2 -> 3 -> 4
62944+ 2 -> 3 -> 4
62945+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
62946+ */
62947+ /* trickier case: walk our role's chain until we find
62948+ the role for the start of the current slot's chain */
62949+ tmp = role;
62950+ tmp2 = *curr;
62951+ while (tmp->next && tmp->next != tmp2)
62952+ tmp = tmp->next;
62953+ if (tmp->next == tmp2) {
62954+ /* from example above, we found 3, so just
62955+ replace this slot's chain with ours */
62956+ *curr = role;
62957+ } else {
62958+ /* we didn't find a subset of our role's chain
62959+ in the current slot's chain, so append their
62960+ chain to ours, and set us as the first role in
62961+ the slot's chain
62962+
62963+ we could fold this case with the case above,
62964+ but making it explicit for clarity
62965+ */
62966+ tmp->next = tmp2;
62967+ *curr = role;
62968+ }
62969+ }
62970+ }
62971+
62972+ return;
62973+}
62974+
62975+static void
62976+insert_acl_role_label(struct acl_role_label *role)
62977+{
62978+ int i;
62979+
62980+ if (role_list == NULL) {
62981+ role_list = role;
62982+ role->prev = NULL;
62983+ } else {
62984+ role->prev = role_list;
62985+ role_list = role;
62986+ }
62987+
62988+ /* used for hash chains */
62989+ role->next = NULL;
62990+
62991+ if (role->roletype & GR_ROLE_DOMAIN) {
62992+ for (i = 0; i < role->domain_child_num; i++)
62993+ __insert_acl_role_label(role, role->domain_children[i]);
62994+ } else
62995+ __insert_acl_role_label(role, role->uidgid);
62996+}
62997+
62998+static int
62999+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
63000+{
63001+ struct name_entry **curr, *nentry;
63002+ struct inodev_entry *ientry;
63003+ unsigned int len = strlen(name);
63004+ unsigned int key = full_name_hash(name, len);
63005+ unsigned int index = key % name_set.n_size;
63006+
63007+ curr = &name_set.n_hash[index];
63008+
63009+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
63010+ curr = &((*curr)->next);
63011+
63012+ if (*curr != NULL)
63013+ return 1;
63014+
63015+ nentry = acl_alloc(sizeof (struct name_entry));
63016+ if (nentry == NULL)
63017+ return 0;
63018+ ientry = acl_alloc(sizeof (struct inodev_entry));
63019+ if (ientry == NULL)
63020+ return 0;
63021+ ientry->nentry = nentry;
63022+
63023+ nentry->key = key;
63024+ nentry->name = name;
63025+ nentry->inode = inode;
63026+ nentry->device = device;
63027+ nentry->len = len;
63028+ nentry->deleted = deleted;
63029+
63030+ nentry->prev = NULL;
63031+ curr = &name_set.n_hash[index];
63032+ if (*curr != NULL)
63033+ (*curr)->prev = nentry;
63034+ nentry->next = *curr;
63035+ *curr = nentry;
63036+
63037+ /* insert us into the table searchable by inode/dev */
63038+ insert_inodev_entry(ientry);
63039+
63040+ return 1;
63041+}
63042+
63043+static void
63044+insert_acl_obj_label(struct acl_object_label *obj,
63045+ struct acl_subject_label *subj)
63046+{
63047+ unsigned int index =
63048+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
63049+ struct acl_object_label **curr;
63050+
63051+
63052+ obj->prev = NULL;
63053+
63054+ curr = &subj->obj_hash[index];
63055+ if (*curr != NULL)
63056+ (*curr)->prev = obj;
63057+
63058+ obj->next = *curr;
63059+ *curr = obj;
63060+
63061+ return;
63062+}
63063+
63064+static void
63065+insert_acl_subj_label(struct acl_subject_label *obj,
63066+ struct acl_role_label *role)
63067+{
63068+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
63069+ struct acl_subject_label **curr;
63070+
63071+ obj->prev = NULL;
63072+
63073+ curr = &role->subj_hash[index];
63074+ if (*curr != NULL)
63075+ (*curr)->prev = obj;
63076+
63077+ obj->next = *curr;
63078+ *curr = obj;
63079+
63080+ return;
63081+}
63082+
63083+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
63084+
63085+static void *
63086+create_table(__u32 * len, int elementsize)
63087+{
63088+ unsigned int table_sizes[] = {
63089+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
63090+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
63091+ 4194301, 8388593, 16777213, 33554393, 67108859
63092+ };
63093+ void *newtable = NULL;
63094+ unsigned int pwr = 0;
63095+
63096+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
63097+ table_sizes[pwr] <= *len)
63098+ pwr++;
63099+
63100+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
63101+ return newtable;
63102+
63103+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
63104+ newtable =
63105+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
63106+ else
63107+ newtable = vmalloc(table_sizes[pwr] * elementsize);
63108+
63109+ *len = table_sizes[pwr];
63110+
63111+ return newtable;
63112+}
63113+
63114+static int
63115+init_variables(const struct gr_arg *arg)
63116+{
63117+ struct task_struct *reaper = init_pid_ns.child_reaper;
63118+ unsigned int stacksize;
63119+
63120+ subj_map_set.s_size = arg->role_db.num_subjects;
63121+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
63122+ name_set.n_size = arg->role_db.num_objects;
63123+ inodev_set.i_size = arg->role_db.num_objects;
63124+
63125+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
63126+ !name_set.n_size || !inodev_set.i_size)
63127+ return 1;
63128+
63129+ if (!gr_init_uidset())
63130+ return 1;
63131+
63132+ /* set up the stack that holds allocation info */
63133+
63134+ stacksize = arg->role_db.num_pointers + 5;
63135+
63136+ if (!acl_alloc_stack_init(stacksize))
63137+ return 1;
63138+
63139+ /* grab reference for the real root dentry and vfsmount */
63140+ get_fs_root(reaper->fs, &real_root);
63141+
63142+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
63143+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
63144+#endif
63145+
63146+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
63147+ if (fakefs_obj_rw == NULL)
63148+ return 1;
63149+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
63150+
63151+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
63152+ if (fakefs_obj_rwx == NULL)
63153+ return 1;
63154+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
63155+
63156+ subj_map_set.s_hash =
63157+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
63158+ acl_role_set.r_hash =
63159+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
63160+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
63161+ inodev_set.i_hash =
63162+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
63163+
63164+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
63165+ !name_set.n_hash || !inodev_set.i_hash)
63166+ return 1;
63167+
63168+ memset(subj_map_set.s_hash, 0,
63169+ sizeof(struct subject_map *) * subj_map_set.s_size);
63170+ memset(acl_role_set.r_hash, 0,
63171+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
63172+ memset(name_set.n_hash, 0,
63173+ sizeof (struct name_entry *) * name_set.n_size);
63174+ memset(inodev_set.i_hash, 0,
63175+ sizeof (struct inodev_entry *) * inodev_set.i_size);
63176+
63177+ return 0;
63178+}
63179+
63180+/* free information not needed after startup
63181+ currently contains user->kernel pointer mappings for subjects
63182+*/
63183+
63184+static void
63185+free_init_variables(void)
63186+{
63187+ __u32 i;
63188+
63189+ if (subj_map_set.s_hash) {
63190+ for (i = 0; i < subj_map_set.s_size; i++) {
63191+ if (subj_map_set.s_hash[i]) {
63192+ kfree(subj_map_set.s_hash[i]);
63193+ subj_map_set.s_hash[i] = NULL;
63194+ }
63195+ }
63196+
63197+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
63198+ PAGE_SIZE)
63199+ kfree(subj_map_set.s_hash);
63200+ else
63201+ vfree(subj_map_set.s_hash);
63202+ }
63203+
63204+ return;
63205+}
63206+
63207+static void
63208+free_variables(void)
63209+{
63210+ struct acl_subject_label *s;
63211+ struct acl_role_label *r;
63212+ struct task_struct *task, *task2;
63213+ unsigned int x;
63214+
63215+ gr_clear_learn_entries();
63216+
63217+ read_lock(&tasklist_lock);
63218+ do_each_thread(task2, task) {
63219+ task->acl_sp_role = 0;
63220+ task->acl_role_id = 0;
63221+ task->acl = NULL;
63222+ task->role = NULL;
63223+ } while_each_thread(task2, task);
63224+ read_unlock(&tasklist_lock);
63225+
63226+ /* release the reference to the real root dentry and vfsmount */
63227+ path_put(&real_root);
63228+ memset(&real_root, 0, sizeof(real_root));
63229+
63230+ /* free all object hash tables */
63231+
63232+ FOR_EACH_ROLE_START(r)
63233+ if (r->subj_hash == NULL)
63234+ goto next_role;
63235+ FOR_EACH_SUBJECT_START(r, s, x)
63236+ if (s->obj_hash == NULL)
63237+ break;
63238+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
63239+ kfree(s->obj_hash);
63240+ else
63241+ vfree(s->obj_hash);
63242+ FOR_EACH_SUBJECT_END(s, x)
63243+ FOR_EACH_NESTED_SUBJECT_START(r, s)
63244+ if (s->obj_hash == NULL)
63245+ break;
63246+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
63247+ kfree(s->obj_hash);
63248+ else
63249+ vfree(s->obj_hash);
63250+ FOR_EACH_NESTED_SUBJECT_END(s)
63251+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
63252+ kfree(r->subj_hash);
63253+ else
63254+ vfree(r->subj_hash);
63255+ r->subj_hash = NULL;
63256+next_role:
63257+ FOR_EACH_ROLE_END(r)
63258+
63259+ acl_free_all();
63260+
63261+ if (acl_role_set.r_hash) {
63262+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
63263+ PAGE_SIZE)
63264+ kfree(acl_role_set.r_hash);
63265+ else
63266+ vfree(acl_role_set.r_hash);
63267+ }
63268+ if (name_set.n_hash) {
63269+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
63270+ PAGE_SIZE)
63271+ kfree(name_set.n_hash);
63272+ else
63273+ vfree(name_set.n_hash);
63274+ }
63275+
63276+ if (inodev_set.i_hash) {
63277+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
63278+ PAGE_SIZE)
63279+ kfree(inodev_set.i_hash);
63280+ else
63281+ vfree(inodev_set.i_hash);
63282+ }
63283+
63284+ gr_free_uidset();
63285+
63286+ memset(&name_set, 0, sizeof (struct name_db));
63287+ memset(&inodev_set, 0, sizeof (struct inodev_db));
63288+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
63289+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
63290+
63291+ default_role = NULL;
63292+ kernel_role = NULL;
63293+ role_list = NULL;
63294+
63295+ return;
63296+}
63297+
63298+static struct acl_subject_label *
63299+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
63300+
63301+static int alloc_and_copy_string(char **name, unsigned int maxlen)
63302+{
63303+ unsigned int len = strnlen_user(*name, maxlen);
63304+ char *tmp;
63305+
63306+ if (!len || len >= maxlen)
63307+ return -EINVAL;
63308+
63309+ if ((tmp = (char *) acl_alloc(len)) == NULL)
63310+ return -ENOMEM;
63311+
63312+ if (copy_from_user(tmp, *name, len))
63313+ return -EFAULT;
63314+
63315+ tmp[len-1] = '\0';
63316+ *name = tmp;
63317+
63318+ return 0;
63319+}
63320+
63321+static int
63322+copy_user_glob(struct acl_object_label *obj)
63323+{
63324+ struct acl_object_label *g_tmp, **guser;
63325+ int error;
63326+
63327+ if (obj->globbed == NULL)
63328+ return 0;
63329+
63330+ guser = &obj->globbed;
63331+ while (*guser) {
63332+ g_tmp = (struct acl_object_label *)
63333+ acl_alloc(sizeof (struct acl_object_label));
63334+ if (g_tmp == NULL)
63335+ return -ENOMEM;
63336+
63337+ if (copy_acl_object_label(g_tmp, *guser))
63338+ return -EFAULT;
63339+
63340+ error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
63341+ if (error)
63342+ return error;
63343+
63344+ *guser = g_tmp;
63345+ guser = &(g_tmp->next);
63346+ }
63347+
63348+ return 0;
63349+}
63350+
63351+static int
63352+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
63353+ struct acl_role_label *role)
63354+{
63355+ struct acl_object_label *o_tmp;
63356+ int ret;
63357+
63358+ while (userp) {
63359+ if ((o_tmp = (struct acl_object_label *)
63360+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
63361+ return -ENOMEM;
63362+
63363+ if (copy_acl_object_label(o_tmp, userp))
63364+ return -EFAULT;
63365+
63366+ userp = o_tmp->prev;
63367+
63368+ ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
63369+ if (ret)
63370+ return ret;
63371+
63372+ insert_acl_obj_label(o_tmp, subj);
63373+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
63374+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
63375+ return -ENOMEM;
63376+
63377+ ret = copy_user_glob(o_tmp);
63378+ if (ret)
63379+ return ret;
63380+
63381+ if (o_tmp->nested) {
63382+ int already_copied;
63383+
63384+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
63385+ if (IS_ERR(o_tmp->nested))
63386+ return PTR_ERR(o_tmp->nested);
63387+
63388+ /* insert into nested subject list if we haven't copied this one yet
63389+ to prevent duplicate entries */
63390+ if (!already_copied) {
63391+ o_tmp->nested->next = role->hash->first;
63392+ role->hash->first = o_tmp->nested;
63393+ }
63394+ }
63395+ }
63396+
63397+ return 0;
63398+}
63399+
63400+static __u32
63401+count_user_subjs(struct acl_subject_label *userp)
63402+{
63403+ struct acl_subject_label s_tmp;
63404+ __u32 num = 0;
63405+
63406+ while (userp) {
63407+ if (copy_acl_subject_label(&s_tmp, userp))
63408+ break;
63409+
63410+ userp = s_tmp.prev;
63411+ }
63412+
63413+ return num;
63414+}
63415+
63416+static int
63417+copy_user_allowedips(struct acl_role_label *rolep)
63418+{
63419+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
63420+
63421+ ruserip = rolep->allowed_ips;
63422+
63423+ while (ruserip) {
63424+ rlast = rtmp;
63425+
63426+ if ((rtmp = (struct role_allowed_ip *)
63427+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
63428+ return -ENOMEM;
63429+
63430+ if (copy_role_allowed_ip(rtmp, ruserip))
63431+ return -EFAULT;
63432+
63433+ ruserip = rtmp->prev;
63434+
63435+ if (!rlast) {
63436+ rtmp->prev = NULL;
63437+ rolep->allowed_ips = rtmp;
63438+ } else {
63439+ rlast->next = rtmp;
63440+ rtmp->prev = rlast;
63441+ }
63442+
63443+ if (!ruserip)
63444+ rtmp->next = NULL;
63445+ }
63446+
63447+ return 0;
63448+}
63449+
63450+static int
63451+copy_user_transitions(struct acl_role_label *rolep)
63452+{
63453+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
63454+ int error;
63455+
63456+ rusertp = rolep->transitions;
63457+
63458+ while (rusertp) {
63459+ rlast = rtmp;
63460+
63461+ if ((rtmp = (struct role_transition *)
63462+ acl_alloc(sizeof (struct role_transition))) == NULL)
63463+ return -ENOMEM;
63464+
63465+ if (copy_role_transition(rtmp, rusertp))
63466+ return -EFAULT;
63467+
63468+ rusertp = rtmp->prev;
63469+
63470+ error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
63471+ if (error)
63472+ return error;
63473+
63474+ if (!rlast) {
63475+ rtmp->prev = NULL;
63476+ rolep->transitions = rtmp;
63477+ } else {
63478+ rlast->next = rtmp;
63479+ rtmp->prev = rlast;
63480+ }
63481+
63482+ if (!rusertp)
63483+ rtmp->next = NULL;
63484+ }
63485+
63486+ return 0;
63487+}
63488+
63489+static __u32 count_user_objs(const struct acl_object_label __user *userp)
63490+{
63491+ struct acl_object_label o_tmp;
63492+ __u32 num = 0;
63493+
63494+ while (userp) {
63495+ if (copy_acl_object_label(&o_tmp, userp))
63496+ break;
63497+
63498+ userp = o_tmp.prev;
63499+ num++;
63500+ }
63501+
63502+ return num;
63503+}
63504+
63505+static struct acl_subject_label *
63506+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
63507+{
63508+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
63509+ __u32 num_objs;
63510+ struct acl_ip_label **i_tmp, *i_utmp2;
63511+ struct gr_hash_struct ghash;
63512+ struct subject_map *subjmap;
63513+ unsigned int i_num;
63514+ int err;
63515+
63516+ if (already_copied != NULL)
63517+ *already_copied = 0;
63518+
63519+ s_tmp = lookup_subject_map(userp);
63520+
63521+ /* we've already copied this subject into the kernel, just return
63522+ the reference to it, and don't copy it over again
63523+ */
63524+ if (s_tmp) {
63525+ if (already_copied != NULL)
63526+ *already_copied = 1;
63527+ return(s_tmp);
63528+ }
63529+
63530+ if ((s_tmp = (struct acl_subject_label *)
63531+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
63532+ return ERR_PTR(-ENOMEM);
63533+
63534+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
63535+ if (subjmap == NULL)
63536+ return ERR_PTR(-ENOMEM);
63537+
63538+ subjmap->user = userp;
63539+ subjmap->kernel = s_tmp;
63540+ insert_subj_map_entry(subjmap);
63541+
63542+ if (copy_acl_subject_label(s_tmp, userp))
63543+ return ERR_PTR(-EFAULT);
63544+
63545+ err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
63546+ if (err)
63547+ return ERR_PTR(err);
63548+
63549+ if (!strcmp(s_tmp->filename, "/"))
63550+ role->root_label = s_tmp;
63551+
63552+ if (copy_gr_hash_struct(&ghash, s_tmp->hash))
63553+ return ERR_PTR(-EFAULT);
63554+
63555+ /* copy user and group transition tables */
63556+
63557+ if (s_tmp->user_trans_num) {
63558+ uid_t *uidlist;
63559+
63560+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
63561+ if (uidlist == NULL)
63562+ return ERR_PTR(-ENOMEM);
63563+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
63564+ return ERR_PTR(-EFAULT);
63565+
63566+ s_tmp->user_transitions = uidlist;
63567+ }
63568+
63569+ if (s_tmp->group_trans_num) {
63570+ gid_t *gidlist;
63571+
63572+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
63573+ if (gidlist == NULL)
63574+ return ERR_PTR(-ENOMEM);
63575+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
63576+ return ERR_PTR(-EFAULT);
63577+
63578+ s_tmp->group_transitions = gidlist;
63579+ }
63580+
63581+ /* set up object hash table */
63582+ num_objs = count_user_objs(ghash.first);
63583+
63584+ s_tmp->obj_hash_size = num_objs;
63585+ s_tmp->obj_hash =
63586+ (struct acl_object_label **)
63587+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
63588+
63589+ if (!s_tmp->obj_hash)
63590+ return ERR_PTR(-ENOMEM);
63591+
63592+ memset(s_tmp->obj_hash, 0,
63593+ s_tmp->obj_hash_size *
63594+ sizeof (struct acl_object_label *));
63595+
63596+ /* add in objects */
63597+ err = copy_user_objs(ghash.first, s_tmp, role);
63598+
63599+ if (err)
63600+ return ERR_PTR(err);
63601+
63602+ /* set pointer for parent subject */
63603+ if (s_tmp->parent_subject) {
63604+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
63605+
63606+ if (IS_ERR(s_tmp2))
63607+ return s_tmp2;
63608+
63609+ s_tmp->parent_subject = s_tmp2;
63610+ }
63611+
63612+ /* add in ip acls */
63613+
63614+ if (!s_tmp->ip_num) {
63615+ s_tmp->ips = NULL;
63616+ goto insert;
63617+ }
63618+
63619+ i_tmp =
63620+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
63621+ sizeof (struct acl_ip_label *));
63622+
63623+ if (!i_tmp)
63624+ return ERR_PTR(-ENOMEM);
63625+
63626+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
63627+ *(i_tmp + i_num) =
63628+ (struct acl_ip_label *)
63629+ acl_alloc(sizeof (struct acl_ip_label));
63630+ if (!*(i_tmp + i_num))
63631+ return ERR_PTR(-ENOMEM);
63632+
63633+ if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
63634+ return ERR_PTR(-EFAULT);
63635+
63636+ if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
63637+ return ERR_PTR(-EFAULT);
63638+
63639+ if ((*(i_tmp + i_num))->iface == NULL)
63640+ continue;
63641+
63642+ err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
63643+ if (err)
63644+ return ERR_PTR(err);
63645+ }
63646+
63647+ s_tmp->ips = i_tmp;
63648+
63649+insert:
63650+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
63651+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
63652+ return ERR_PTR(-ENOMEM);
63653+
63654+ return s_tmp;
63655+}
63656+
63657+static int
63658+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
63659+{
63660+ struct acl_subject_label s_pre;
63661+ struct acl_subject_label * ret;
63662+ int err;
63663+
63664+ while (userp) {
63665+ if (copy_acl_subject_label(&s_pre, userp))
63666+ return -EFAULT;
63667+
63668+ ret = do_copy_user_subj(userp, role, NULL);
63669+
63670+ err = PTR_ERR(ret);
63671+ if (IS_ERR(ret))
63672+ return err;
63673+
63674+ insert_acl_subj_label(ret, role);
63675+
63676+ userp = s_pre.prev;
63677+ }
63678+
63679+ return 0;
63680+}
63681+
63682+static int
63683+copy_user_acl(struct gr_arg *arg)
63684+{
63685+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
63686+ struct acl_subject_label *subj_list;
63687+ struct sprole_pw *sptmp;
63688+ struct gr_hash_struct *ghash;
63689+ uid_t *domainlist;
63690+ unsigned int r_num;
63691+ int err = 0;
63692+ __u16 i;
63693+ __u32 num_subjs;
63694+
63695+ /* we need a default and kernel role */
63696+ if (arg->role_db.num_roles < 2)
63697+ return -EINVAL;
63698+
63699+ /* copy special role authentication info from userspace */
63700+
63701+ num_sprole_pws = arg->num_sprole_pws;
63702+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
63703+
63704+ if (!acl_special_roles && num_sprole_pws)
63705+ return -ENOMEM;
63706+
63707+ for (i = 0; i < num_sprole_pws; i++) {
63708+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
63709+ if (!sptmp)
63710+ return -ENOMEM;
63711+ if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
63712+ return -EFAULT;
63713+
63714+ err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
63715+ if (err)
63716+ return err;
63717+
63718+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
63719+ printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
63720+#endif
63721+
63722+ acl_special_roles[i] = sptmp;
63723+ }
63724+
63725+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
63726+
63727+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
63728+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
63729+
63730+ if (!r_tmp)
63731+ return -ENOMEM;
63732+
63733+ if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
63734+ return -EFAULT;
63735+
63736+ if (copy_acl_role_label(r_tmp, r_utmp2))
63737+ return -EFAULT;
63738+
63739+ err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
63740+ if (err)
63741+ return err;
63742+
63743+ if (!strcmp(r_tmp->rolename, "default")
63744+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
63745+ default_role = r_tmp;
63746+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
63747+ kernel_role = r_tmp;
63748+ }
63749+
63750+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
63751+ return -ENOMEM;
63752+
63753+ if (copy_gr_hash_struct(ghash, r_tmp->hash))
63754+ return -EFAULT;
63755+
63756+ r_tmp->hash = ghash;
63757+
63758+ num_subjs = count_user_subjs(r_tmp->hash->first);
63759+
63760+ r_tmp->subj_hash_size = num_subjs;
63761+ r_tmp->subj_hash =
63762+ (struct acl_subject_label **)
63763+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
63764+
63765+ if (!r_tmp->subj_hash)
63766+ return -ENOMEM;
63767+
63768+ err = copy_user_allowedips(r_tmp);
63769+ if (err)
63770+ return err;
63771+
63772+ /* copy domain info */
63773+ if (r_tmp->domain_children != NULL) {
63774+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
63775+ if (domainlist == NULL)
63776+ return -ENOMEM;
63777+
63778+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
63779+ return -EFAULT;
63780+
63781+ r_tmp->domain_children = domainlist;
63782+ }
63783+
63784+ err = copy_user_transitions(r_tmp);
63785+ if (err)
63786+ return err;
63787+
63788+ memset(r_tmp->subj_hash, 0,
63789+ r_tmp->subj_hash_size *
63790+ sizeof (struct acl_subject_label *));
63791+
63792+ /* acquire the list of subjects, then NULL out
63793+ the list prior to parsing the subjects for this role,
63794+ as during this parsing the list is replaced with a list
63795+ of *nested* subjects for the role
63796+ */
63797+ subj_list = r_tmp->hash->first;
63798+
63799+ /* set nested subject list to null */
63800+ r_tmp->hash->first = NULL;
63801+
63802+ err = copy_user_subjs(subj_list, r_tmp);
63803+
63804+ if (err)
63805+ return err;
63806+
63807+ insert_acl_role_label(r_tmp);
63808+ }
63809+
63810+ if (default_role == NULL || kernel_role == NULL)
63811+ return -EINVAL;
63812+
63813+ return err;
63814+}
63815+
63816+static int
63817+gracl_init(struct gr_arg *args)
63818+{
63819+ int error = 0;
63820+
63821+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
63822+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
63823+
63824+ if (init_variables(args)) {
63825+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
63826+ error = -ENOMEM;
63827+ free_variables();
63828+ goto out;
63829+ }
63830+
63831+ error = copy_user_acl(args);
63832+ free_init_variables();
63833+ if (error) {
63834+ free_variables();
63835+ goto out;
63836+ }
63837+
63838+ if ((error = gr_set_acls(0))) {
63839+ free_variables();
63840+ goto out;
63841+ }
63842+
63843+ pax_open_kernel();
63844+ gr_status |= GR_READY;
63845+ pax_close_kernel();
63846+
63847+ out:
63848+ return error;
63849+}
63850+
63851+/* derived from glibc fnmatch() 0: match, 1: no match*/
63852+
63853+static int
63854+glob_match(const char *p, const char *n)
63855+{
63856+ char c;
63857+
63858+ while ((c = *p++) != '\0') {
63859+ switch (c) {
63860+ case '?':
63861+ if (*n == '\0')
63862+ return 1;
63863+ else if (*n == '/')
63864+ return 1;
63865+ break;
63866+ case '\\':
63867+ if (*n != c)
63868+ return 1;
63869+ break;
63870+ case '*':
63871+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
63872+ if (*n == '/')
63873+ return 1;
63874+ else if (c == '?') {
63875+ if (*n == '\0')
63876+ return 1;
63877+ else
63878+ ++n;
63879+ }
63880+ }
63881+ if (c == '\0') {
63882+ return 0;
63883+ } else {
63884+ const char *endp;
63885+
63886+ if ((endp = strchr(n, '/')) == NULL)
63887+ endp = n + strlen(n);
63888+
63889+ if (c == '[') {
63890+ for (--p; n < endp; ++n)
63891+ if (!glob_match(p, n))
63892+ return 0;
63893+ } else if (c == '/') {
63894+ while (*n != '\0' && *n != '/')
63895+ ++n;
63896+ if (*n == '/' && !glob_match(p, n + 1))
63897+ return 0;
63898+ } else {
63899+ for (--p; n < endp; ++n)
63900+ if (*n == c && !glob_match(p, n))
63901+ return 0;
63902+ }
63903+
63904+ return 1;
63905+ }
63906+ case '[':
63907+ {
63908+ int not;
63909+ char cold;
63910+
63911+ if (*n == '\0' || *n == '/')
63912+ return 1;
63913+
63914+ not = (*p == '!' || *p == '^');
63915+ if (not)
63916+ ++p;
63917+
63918+ c = *p++;
63919+ for (;;) {
63920+ unsigned char fn = (unsigned char)*n;
63921+
63922+ if (c == '\0')
63923+ return 1;
63924+ else {
63925+ if (c == fn)
63926+ goto matched;
63927+ cold = c;
63928+ c = *p++;
63929+
63930+ if (c == '-' && *p != ']') {
63931+ unsigned char cend = *p++;
63932+
63933+ if (cend == '\0')
63934+ return 1;
63935+
63936+ if (cold <= fn && fn <= cend)
63937+ goto matched;
63938+
63939+ c = *p++;
63940+ }
63941+ }
63942+
63943+ if (c == ']')
63944+ break;
63945+ }
63946+ if (!not)
63947+ return 1;
63948+ break;
63949+ matched:
63950+ while (c != ']') {
63951+ if (c == '\0')
63952+ return 1;
63953+
63954+ c = *p++;
63955+ }
63956+ if (not)
63957+ return 1;
63958+ }
63959+ break;
63960+ default:
63961+ if (c != *n)
63962+ return 1;
63963+ }
63964+
63965+ ++n;
63966+ }
63967+
63968+ if (*n == '\0')
63969+ return 0;
63970+
63971+ if (*n == '/')
63972+ return 0;
63973+
63974+ return 1;
63975+}
63976+
63977+static struct acl_object_label *
63978+chk_glob_label(struct acl_object_label *globbed,
63979+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
63980+{
63981+ struct acl_object_label *tmp;
63982+
63983+ if (*path == NULL)
63984+ *path = gr_to_filename_nolock(dentry, mnt);
63985+
63986+ tmp = globbed;
63987+
63988+ while (tmp) {
63989+ if (!glob_match(tmp->filename, *path))
63990+ return tmp;
63991+ tmp = tmp->next;
63992+ }
63993+
63994+ return NULL;
63995+}
63996+
63997+static struct acl_object_label *
63998+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
63999+ const ino_t curr_ino, const dev_t curr_dev,
64000+ const struct acl_subject_label *subj, char **path, const int checkglob)
64001+{
64002+ struct acl_subject_label *tmpsubj;
64003+ struct acl_object_label *retval;
64004+ struct acl_object_label *retval2;
64005+
64006+ tmpsubj = (struct acl_subject_label *) subj;
64007+ read_lock(&gr_inode_lock);
64008+ do {
64009+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
64010+ if (retval) {
64011+ if (checkglob && retval->globbed) {
64012+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
64013+ if (retval2)
64014+ retval = retval2;
64015+ }
64016+ break;
64017+ }
64018+ } while ((tmpsubj = tmpsubj->parent_subject));
64019+ read_unlock(&gr_inode_lock);
64020+
64021+ return retval;
64022+}
64023+
64024+static __inline__ struct acl_object_label *
64025+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
64026+ struct dentry *curr_dentry,
64027+ const struct acl_subject_label *subj, char **path, const int checkglob)
64028+{
64029+ int newglob = checkglob;
64030+ ino_t inode;
64031+ dev_t device;
64032+
64033+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
64034+ as we don't want a / * rule to match instead of the / object
64035+ don't do this for create lookups that call this function though, since they're looking up
64036+ on the parent and thus need globbing checks on all paths
64037+ */
64038+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
64039+ newglob = GR_NO_GLOB;
64040+
64041+ spin_lock(&curr_dentry->d_lock);
64042+ inode = curr_dentry->d_inode->i_ino;
64043+ device = __get_dev(curr_dentry);
64044+ spin_unlock(&curr_dentry->d_lock);
64045+
64046+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
64047+}
64048+
64049+#ifdef CONFIG_HUGETLBFS
64050+static inline bool
64051+is_hugetlbfs_mnt(const struct vfsmount *mnt)
64052+{
64053+ int i;
64054+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
64055+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
64056+ return true;
64057+ }
64058+
64059+ return false;
64060+}
64061+#endif
64062+
64063+static struct acl_object_label *
64064+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64065+ const struct acl_subject_label *subj, char *path, const int checkglob)
64066+{
64067+ struct dentry *dentry = (struct dentry *) l_dentry;
64068+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
64069+ struct mount *real_mnt = real_mount(mnt);
64070+ struct acl_object_label *retval;
64071+ struct dentry *parent;
64072+
64073+ br_read_lock(&vfsmount_lock);
64074+ write_seqlock(&rename_lock);
64075+
64076+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
64077+#ifdef CONFIG_NET
64078+ mnt == sock_mnt ||
64079+#endif
64080+#ifdef CONFIG_HUGETLBFS
64081+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
64082+#endif
64083+ /* ignore Eric Biederman */
64084+ IS_PRIVATE(l_dentry->d_inode))) {
64085+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
64086+ goto out;
64087+ }
64088+
64089+ for (;;) {
64090+ if (dentry == real_root.dentry && mnt == real_root.mnt)
64091+ break;
64092+
64093+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
64094+ if (!mnt_has_parent(real_mnt))
64095+ break;
64096+
64097+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
64098+ if (retval != NULL)
64099+ goto out;
64100+
64101+ dentry = real_mnt->mnt_mountpoint;
64102+ real_mnt = real_mnt->mnt_parent;
64103+ mnt = &real_mnt->mnt;
64104+ continue;
64105+ }
64106+
64107+ parent = dentry->d_parent;
64108+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
64109+ if (retval != NULL)
64110+ goto out;
64111+
64112+ dentry = parent;
64113+ }
64114+
64115+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
64116+
64117+ /* real_root is pinned so we don't have to hold a reference */
64118+ if (retval == NULL)
64119+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
64120+out:
64121+ write_sequnlock(&rename_lock);
64122+ br_read_unlock(&vfsmount_lock);
64123+
64124+ BUG_ON(retval == NULL);
64125+
64126+ return retval;
64127+}
64128+
64129+static __inline__ struct acl_object_label *
64130+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64131+ const struct acl_subject_label *subj)
64132+{
64133+ char *path = NULL;
64134+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
64135+}
64136+
64137+static __inline__ struct acl_object_label *
64138+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64139+ const struct acl_subject_label *subj)
64140+{
64141+ char *path = NULL;
64142+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
64143+}
64144+
64145+static __inline__ struct acl_object_label *
64146+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64147+ const struct acl_subject_label *subj, char *path)
64148+{
64149+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
64150+}
64151+
64152+static struct acl_subject_label *
64153+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64154+ const struct acl_role_label *role)
64155+{
64156+ struct dentry *dentry = (struct dentry *) l_dentry;
64157+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
64158+ struct mount *real_mnt = real_mount(mnt);
64159+ struct acl_subject_label *retval;
64160+ struct dentry *parent;
64161+
64162+ br_read_lock(&vfsmount_lock);
64163+ write_seqlock(&rename_lock);
64164+
64165+ for (;;) {
64166+ if (dentry == real_root.dentry && mnt == real_root.mnt)
64167+ break;
64168+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
64169+ if (!mnt_has_parent(real_mnt))
64170+ break;
64171+
64172+ spin_lock(&dentry->d_lock);
64173+ read_lock(&gr_inode_lock);
64174+ retval =
64175+ lookup_acl_subj_label(dentry->d_inode->i_ino,
64176+ __get_dev(dentry), role);
64177+ read_unlock(&gr_inode_lock);
64178+ spin_unlock(&dentry->d_lock);
64179+ if (retval != NULL)
64180+ goto out;
64181+
64182+ dentry = real_mnt->mnt_mountpoint;
64183+ real_mnt = real_mnt->mnt_parent;
64184+ mnt = &real_mnt->mnt;
64185+ continue;
64186+ }
64187+
64188+ spin_lock(&dentry->d_lock);
64189+ read_lock(&gr_inode_lock);
64190+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
64191+ __get_dev(dentry), role);
64192+ read_unlock(&gr_inode_lock);
64193+ parent = dentry->d_parent;
64194+ spin_unlock(&dentry->d_lock);
64195+
64196+ if (retval != NULL)
64197+ goto out;
64198+
64199+ dentry = parent;
64200+ }
64201+
64202+ spin_lock(&dentry->d_lock);
64203+ read_lock(&gr_inode_lock);
64204+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
64205+ __get_dev(dentry), role);
64206+ read_unlock(&gr_inode_lock);
64207+ spin_unlock(&dentry->d_lock);
64208+
64209+ if (unlikely(retval == NULL)) {
64210+ /* real_root is pinned, we don't need to hold a reference */
64211+ read_lock(&gr_inode_lock);
64212+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
64213+ __get_dev(real_root.dentry), role);
64214+ read_unlock(&gr_inode_lock);
64215+ }
64216+out:
64217+ write_sequnlock(&rename_lock);
64218+ br_read_unlock(&vfsmount_lock);
64219+
64220+ BUG_ON(retval == NULL);
64221+
64222+ return retval;
64223+}
64224+
64225+static void
64226+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
64227+{
64228+ struct task_struct *task = current;
64229+ const struct cred *cred = current_cred();
64230+
64231+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
64232+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
64233+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
64234+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
64235+
64236+ return;
64237+}
64238+
64239+static void
64240+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
64241+{
64242+ struct task_struct *task = current;
64243+ const struct cred *cred = current_cred();
64244+
64245+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
64246+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
64247+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
64248+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
64249+
64250+ return;
64251+}
64252+
64253+static void
64254+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
64255+{
64256+ struct task_struct *task = current;
64257+ const struct cred *cred = current_cred();
64258+
64259+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
64260+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
64261+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
64262+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
64263+
64264+ return;
64265+}
64266+
64267+__u32
64268+gr_search_file(const struct dentry * dentry, const __u32 mode,
64269+ const struct vfsmount * mnt)
64270+{
64271+ __u32 retval = mode;
64272+ struct acl_subject_label *curracl;
64273+ struct acl_object_label *currobj;
64274+
64275+ if (unlikely(!(gr_status & GR_READY)))
64276+ return (mode & ~GR_AUDITS);
64277+
64278+ curracl = current->acl;
64279+
64280+ currobj = chk_obj_label(dentry, mnt, curracl);
64281+ retval = currobj->mode & mode;
64282+
64283+ /* if we're opening a specified transfer file for writing
64284+ (e.g. /dev/initctl), then transfer our role to init
64285+ */
64286+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
64287+ current->role->roletype & GR_ROLE_PERSIST)) {
64288+ struct task_struct *task = init_pid_ns.child_reaper;
64289+
64290+ if (task->role != current->role) {
64291+ task->acl_sp_role = 0;
64292+ task->acl_role_id = current->acl_role_id;
64293+ task->role = current->role;
64294+ rcu_read_lock();
64295+ read_lock(&grsec_exec_file_lock);
64296+ gr_apply_subject_to_task(task);
64297+ read_unlock(&grsec_exec_file_lock);
64298+ rcu_read_unlock();
64299+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
64300+ }
64301+ }
64302+
64303+ if (unlikely
64304+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
64305+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
64306+ __u32 new_mode = mode;
64307+
64308+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
64309+
64310+ retval = new_mode;
64311+
64312+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
64313+ new_mode |= GR_INHERIT;
64314+
64315+ if (!(mode & GR_NOLEARN))
64316+ gr_log_learn(dentry, mnt, new_mode);
64317+ }
64318+
64319+ return retval;
64320+}
64321+
64322+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
64323+ const struct dentry *parent,
64324+ const struct vfsmount *mnt)
64325+{
64326+ struct name_entry *match;
64327+ struct acl_object_label *matchpo;
64328+ struct acl_subject_label *curracl;
64329+ char *path;
64330+
64331+ if (unlikely(!(gr_status & GR_READY)))
64332+ return NULL;
64333+
64334+ preempt_disable();
64335+ path = gr_to_filename_rbac(new_dentry, mnt);
64336+ match = lookup_name_entry_create(path);
64337+
64338+ curracl = current->acl;
64339+
64340+ if (match) {
64341+ read_lock(&gr_inode_lock);
64342+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
64343+ read_unlock(&gr_inode_lock);
64344+
64345+ if (matchpo) {
64346+ preempt_enable();
64347+ return matchpo;
64348+ }
64349+ }
64350+
64351+ // lookup parent
64352+
64353+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
64354+
64355+ preempt_enable();
64356+ return matchpo;
64357+}
64358+
64359+__u32
64360+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
64361+ const struct vfsmount * mnt, const __u32 mode)
64362+{
64363+ struct acl_object_label *matchpo;
64364+ __u32 retval;
64365+
64366+ if (unlikely(!(gr_status & GR_READY)))
64367+ return (mode & ~GR_AUDITS);
64368+
64369+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
64370+
64371+ retval = matchpo->mode & mode;
64372+
64373+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
64374+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
64375+ __u32 new_mode = mode;
64376+
64377+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
64378+
64379+ gr_log_learn(new_dentry, mnt, new_mode);
64380+ return new_mode;
64381+ }
64382+
64383+ return retval;
64384+}
64385+
64386+__u32
64387+gr_check_link(const struct dentry * new_dentry,
64388+ const struct dentry * parent_dentry,
64389+ const struct vfsmount * parent_mnt,
64390+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
64391+{
64392+ struct acl_object_label *obj;
64393+ __u32 oldmode, newmode;
64394+ __u32 needmode;
64395+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
64396+ GR_DELETE | GR_INHERIT;
64397+
64398+ if (unlikely(!(gr_status & GR_READY)))
64399+ return (GR_CREATE | GR_LINK);
64400+
64401+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
64402+ oldmode = obj->mode;
64403+
64404+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
64405+ newmode = obj->mode;
64406+
64407+ needmode = newmode & checkmodes;
64408+
64409+ // old name for hardlink must have at least the permissions of the new name
64410+ if ((oldmode & needmode) != needmode)
64411+ goto bad;
64412+
64413+ // if old name had restrictions/auditing, make sure the new name does as well
64414+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
64415+
64416+ // don't allow hardlinking of suid/sgid/fcapped files without permission
64417+ if (is_privileged_binary(old_dentry))
64418+ needmode |= GR_SETID;
64419+
64420+ if ((newmode & needmode) != needmode)
64421+ goto bad;
64422+
64423+ // enforce minimum permissions
64424+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
64425+ return newmode;
64426+bad:
64427+ needmode = oldmode;
64428+ if (is_privileged_binary(old_dentry))
64429+ needmode |= GR_SETID;
64430+
64431+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
64432+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
64433+ return (GR_CREATE | GR_LINK);
64434+ } else if (newmode & GR_SUPPRESS)
64435+ return GR_SUPPRESS;
64436+ else
64437+ return 0;
64438+}
64439+
64440+int
64441+gr_check_hidden_task(const struct task_struct *task)
64442+{
64443+ if (unlikely(!(gr_status & GR_READY)))
64444+ return 0;
64445+
64446+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
64447+ return 1;
64448+
64449+ return 0;
64450+}
64451+
64452+int
64453+gr_check_protected_task(const struct task_struct *task)
64454+{
64455+ if (unlikely(!(gr_status & GR_READY) || !task))
64456+ return 0;
64457+
64458+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
64459+ task->acl != current->acl)
64460+ return 1;
64461+
64462+ return 0;
64463+}
64464+
64465+int
64466+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
64467+{
64468+ struct task_struct *p;
64469+ int ret = 0;
64470+
64471+ if (unlikely(!(gr_status & GR_READY) || !pid))
64472+ return ret;
64473+
64474+ read_lock(&tasklist_lock);
64475+ do_each_pid_task(pid, type, p) {
64476+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
64477+ p->acl != current->acl) {
64478+ ret = 1;
64479+ goto out;
64480+ }
64481+ } while_each_pid_task(pid, type, p);
64482+out:
64483+ read_unlock(&tasklist_lock);
64484+
64485+ return ret;
64486+}
64487+
64488+void
64489+gr_copy_label(struct task_struct *tsk)
64490+{
64491+ tsk->signal->used_accept = 0;
64492+ tsk->acl_sp_role = 0;
64493+ tsk->acl_role_id = current->acl_role_id;
64494+ tsk->acl = current->acl;
64495+ tsk->role = current->role;
64496+ tsk->signal->curr_ip = current->signal->curr_ip;
64497+ tsk->signal->saved_ip = current->signal->saved_ip;
64498+ if (current->exec_file)
64499+ get_file(current->exec_file);
64500+ tsk->exec_file = current->exec_file;
64501+ tsk->is_writable = current->is_writable;
64502+ if (unlikely(current->signal->used_accept)) {
64503+ current->signal->curr_ip = 0;
64504+ current->signal->saved_ip = 0;
64505+ }
64506+
64507+ return;
64508+}
64509+
64510+static void
64511+gr_set_proc_res(struct task_struct *task)
64512+{
64513+ struct acl_subject_label *proc;
64514+ unsigned short i;
64515+
64516+ proc = task->acl;
64517+
64518+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
64519+ return;
64520+
64521+ for (i = 0; i < RLIM_NLIMITS; i++) {
64522+ if (!(proc->resmask & (1U << i)))
64523+ continue;
64524+
64525+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
64526+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
64527+
64528+ if (i == RLIMIT_CPU)
64529+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
64530+ }
64531+
64532+ return;
64533+}
64534+
64535+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
64536+
64537+int
64538+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
64539+{
64540+ unsigned int i;
64541+ __u16 num;
64542+ uid_t *uidlist;
64543+ uid_t curuid;
64544+ int realok = 0;
64545+ int effectiveok = 0;
64546+ int fsok = 0;
64547+ uid_t globalreal, globaleffective, globalfs;
64548+
64549+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
64550+ struct user_struct *user;
64551+
64552+ if (!uid_valid(real))
64553+ goto skipit;
64554+
64555+ /* find user based on global namespace */
64556+
64557+ globalreal = GR_GLOBAL_UID(real);
64558+
64559+ user = find_user(make_kuid(&init_user_ns, globalreal));
64560+ if (user == NULL)
64561+ goto skipit;
64562+
64563+ if (gr_process_kernel_setuid_ban(user)) {
64564+ /* for find_user */
64565+ free_uid(user);
64566+ return 1;
64567+ }
64568+
64569+ /* for find_user */
64570+ free_uid(user);
64571+
64572+skipit:
64573+#endif
64574+
64575+ if (unlikely(!(gr_status & GR_READY)))
64576+ return 0;
64577+
64578+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
64579+ gr_log_learn_uid_change(real, effective, fs);
64580+
64581+ num = current->acl->user_trans_num;
64582+ uidlist = current->acl->user_transitions;
64583+
64584+ if (uidlist == NULL)
64585+ return 0;
64586+
64587+ if (!uid_valid(real)) {
64588+ realok = 1;
64589+ globalreal = (uid_t)-1;
64590+ } else {
64591+ globalreal = GR_GLOBAL_UID(real);
64592+ }
64593+ if (!uid_valid(effective)) {
64594+ effectiveok = 1;
64595+ globaleffective = (uid_t)-1;
64596+ } else {
64597+ globaleffective = GR_GLOBAL_UID(effective);
64598+ }
64599+ if (!uid_valid(fs)) {
64600+ fsok = 1;
64601+ globalfs = (uid_t)-1;
64602+ } else {
64603+ globalfs = GR_GLOBAL_UID(fs);
64604+ }
64605+
64606+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
64607+ for (i = 0; i < num; i++) {
64608+ curuid = uidlist[i];
64609+ if (globalreal == curuid)
64610+ realok = 1;
64611+ if (globaleffective == curuid)
64612+ effectiveok = 1;
64613+ if (globalfs == curuid)
64614+ fsok = 1;
64615+ }
64616+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
64617+ for (i = 0; i < num; i++) {
64618+ curuid = uidlist[i];
64619+ if (globalreal == curuid)
64620+ break;
64621+ if (globaleffective == curuid)
64622+ break;
64623+ if (globalfs == curuid)
64624+ break;
64625+ }
64626+ /* not in deny list */
64627+ if (i == num) {
64628+ realok = 1;
64629+ effectiveok = 1;
64630+ fsok = 1;
64631+ }
64632+ }
64633+
64634+ if (realok && effectiveok && fsok)
64635+ return 0;
64636+ else {
64637+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
64638+ return 1;
64639+ }
64640+}
64641+
64642+int
64643+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
64644+{
64645+ unsigned int i;
64646+ __u16 num;
64647+ gid_t *gidlist;
64648+ gid_t curgid;
64649+ int realok = 0;
64650+ int effectiveok = 0;
64651+ int fsok = 0;
64652+ gid_t globalreal, globaleffective, globalfs;
64653+
64654+ if (unlikely(!(gr_status & GR_READY)))
64655+ return 0;
64656+
64657+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
64658+ gr_log_learn_gid_change(real, effective, fs);
64659+
64660+ num = current->acl->group_trans_num;
64661+ gidlist = current->acl->group_transitions;
64662+
64663+ if (gidlist == NULL)
64664+ return 0;
64665+
64666+ if (!gid_valid(real)) {
64667+ realok = 1;
64668+ globalreal = (gid_t)-1;
64669+ } else {
64670+ globalreal = GR_GLOBAL_GID(real);
64671+ }
64672+ if (!gid_valid(effective)) {
64673+ effectiveok = 1;
64674+ globaleffective = (gid_t)-1;
64675+ } else {
64676+ globaleffective = GR_GLOBAL_GID(effective);
64677+ }
64678+ if (!gid_valid(fs)) {
64679+ fsok = 1;
64680+ globalfs = (gid_t)-1;
64681+ } else {
64682+ globalfs = GR_GLOBAL_GID(fs);
64683+ }
64684+
64685+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
64686+ for (i = 0; i < num; i++) {
64687+ curgid = gidlist[i];
64688+ if (globalreal == curgid)
64689+ realok = 1;
64690+ if (globaleffective == curgid)
64691+ effectiveok = 1;
64692+ if (globalfs == curgid)
64693+ fsok = 1;
64694+ }
64695+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
64696+ for (i = 0; i < num; i++) {
64697+ curgid = gidlist[i];
64698+ if (globalreal == curgid)
64699+ break;
64700+ if (globaleffective == curgid)
64701+ break;
64702+ if (globalfs == curgid)
64703+ break;
64704+ }
64705+ /* not in deny list */
64706+ if (i == num) {
64707+ realok = 1;
64708+ effectiveok = 1;
64709+ fsok = 1;
64710+ }
64711+ }
64712+
64713+ if (realok && effectiveok && fsok)
64714+ return 0;
64715+ else {
64716+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
64717+ return 1;
64718+ }
64719+}
64720+
64721+extern int gr_acl_is_capable(const int cap);
64722+
64723+void
64724+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
64725+{
64726+ struct acl_role_label *role = task->role;
64727+ struct acl_subject_label *subj = NULL;
64728+ struct acl_object_label *obj;
64729+ struct file *filp;
64730+ uid_t uid;
64731+ gid_t gid;
64732+
64733+ if (unlikely(!(gr_status & GR_READY)))
64734+ return;
64735+
64736+ uid = GR_GLOBAL_UID(kuid);
64737+ gid = GR_GLOBAL_GID(kgid);
64738+
64739+ filp = task->exec_file;
64740+
64741+ /* kernel process, we'll give them the kernel role */
64742+ if (unlikely(!filp)) {
64743+ task->role = kernel_role;
64744+ task->acl = kernel_role->root_label;
64745+ return;
64746+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
64747+ role = lookup_acl_role_label(task, uid, gid);
64748+
64749+ /* don't change the role if we're not a privileged process */
64750+ if (role && task->role != role &&
64751+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
64752+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
64753+ return;
64754+
64755+ /* perform subject lookup in possibly new role
64756+ we can use this result below in the case where role == task->role
64757+ */
64758+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
64759+
64760+ /* if we changed uid/gid, but result in the same role
64761+ and are using inheritance, don't lose the inherited subject
64762+ if current subject is other than what normal lookup
64763+ would result in, we arrived via inheritance, don't
64764+ lose subject
64765+ */
64766+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
64767+ (subj == task->acl)))
64768+ task->acl = subj;
64769+
64770+ task->role = role;
64771+
64772+ task->is_writable = 0;
64773+
64774+ /* ignore additional mmap checks for processes that are writable
64775+ by the default ACL */
64776+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
64777+ if (unlikely(obj->mode & GR_WRITE))
64778+ task->is_writable = 1;
64779+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
64780+ if (unlikely(obj->mode & GR_WRITE))
64781+ task->is_writable = 1;
64782+
64783+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
64784+ 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);
64785+#endif
64786+
64787+ gr_set_proc_res(task);
64788+
64789+ return;
64790+}
64791+
64792+int
64793+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
64794+ const int unsafe_flags)
64795+{
64796+ struct task_struct *task = current;
64797+ struct acl_subject_label *newacl;
64798+ struct acl_object_label *obj;
64799+ __u32 retmode;
64800+
64801+ if (unlikely(!(gr_status & GR_READY)))
64802+ return 0;
64803+
64804+ newacl = chk_subj_label(dentry, mnt, task->role);
64805+
64806+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
64807+ did an exec
64808+ */
64809+ rcu_read_lock();
64810+ read_lock(&tasklist_lock);
64811+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
64812+ (task->parent->acl->mode & GR_POVERRIDE))) {
64813+ read_unlock(&tasklist_lock);
64814+ rcu_read_unlock();
64815+ goto skip_check;
64816+ }
64817+ read_unlock(&tasklist_lock);
64818+ rcu_read_unlock();
64819+
64820+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
64821+ !(task->role->roletype & GR_ROLE_GOD) &&
64822+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
64823+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
64824+ if (unsafe_flags & LSM_UNSAFE_SHARE)
64825+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
64826+ else
64827+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
64828+ return -EACCES;
64829+ }
64830+
64831+skip_check:
64832+
64833+ obj = chk_obj_label(dentry, mnt, task->acl);
64834+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
64835+
64836+ if (!(task->acl->mode & GR_INHERITLEARN) &&
64837+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
64838+ if (obj->nested)
64839+ task->acl = obj->nested;
64840+ else
64841+ task->acl = newacl;
64842+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
64843+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
64844+
64845+ task->is_writable = 0;
64846+
64847+ /* ignore additional mmap checks for processes that are writable
64848+ by the default ACL */
64849+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
64850+ if (unlikely(obj->mode & GR_WRITE))
64851+ task->is_writable = 1;
64852+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
64853+ if (unlikely(obj->mode & GR_WRITE))
64854+ task->is_writable = 1;
64855+
64856+ gr_set_proc_res(task);
64857+
64858+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
64859+ 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);
64860+#endif
64861+ return 0;
64862+}
64863+
64864+/* always called with valid inodev ptr */
64865+static void
64866+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
64867+{
64868+ struct acl_object_label *matchpo;
64869+ struct acl_subject_label *matchps;
64870+ struct acl_subject_label *subj;
64871+ struct acl_role_label *role;
64872+ unsigned int x;
64873+
64874+ FOR_EACH_ROLE_START(role)
64875+ FOR_EACH_SUBJECT_START(role, subj, x)
64876+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
64877+ matchpo->mode |= GR_DELETED;
64878+ FOR_EACH_SUBJECT_END(subj,x)
64879+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
64880+ /* nested subjects aren't in the role's subj_hash table */
64881+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
64882+ matchpo->mode |= GR_DELETED;
64883+ FOR_EACH_NESTED_SUBJECT_END(subj)
64884+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
64885+ matchps->mode |= GR_DELETED;
64886+ FOR_EACH_ROLE_END(role)
64887+
64888+ inodev->nentry->deleted = 1;
64889+
64890+ return;
64891+}
64892+
64893+void
64894+gr_handle_delete(const ino_t ino, const dev_t dev)
64895+{
64896+ struct inodev_entry *inodev;
64897+
64898+ if (unlikely(!(gr_status & GR_READY)))
64899+ return;
64900+
64901+ write_lock(&gr_inode_lock);
64902+ inodev = lookup_inodev_entry(ino, dev);
64903+ if (inodev != NULL)
64904+ do_handle_delete(inodev, ino, dev);
64905+ write_unlock(&gr_inode_lock);
64906+
64907+ return;
64908+}
64909+
64910+static void
64911+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
64912+ const ino_t newinode, const dev_t newdevice,
64913+ struct acl_subject_label *subj)
64914+{
64915+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
64916+ struct acl_object_label *match;
64917+
64918+ match = subj->obj_hash[index];
64919+
64920+ while (match && (match->inode != oldinode ||
64921+ match->device != olddevice ||
64922+ !(match->mode & GR_DELETED)))
64923+ match = match->next;
64924+
64925+ if (match && (match->inode == oldinode)
64926+ && (match->device == olddevice)
64927+ && (match->mode & GR_DELETED)) {
64928+ if (match->prev == NULL) {
64929+ subj->obj_hash[index] = match->next;
64930+ if (match->next != NULL)
64931+ match->next->prev = NULL;
64932+ } else {
64933+ match->prev->next = match->next;
64934+ if (match->next != NULL)
64935+ match->next->prev = match->prev;
64936+ }
64937+ match->prev = NULL;
64938+ match->next = NULL;
64939+ match->inode = newinode;
64940+ match->device = newdevice;
64941+ match->mode &= ~GR_DELETED;
64942+
64943+ insert_acl_obj_label(match, subj);
64944+ }
64945+
64946+ return;
64947+}
64948+
64949+static void
64950+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
64951+ const ino_t newinode, const dev_t newdevice,
64952+ struct acl_role_label *role)
64953+{
64954+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
64955+ struct acl_subject_label *match;
64956+
64957+ match = role->subj_hash[index];
64958+
64959+ while (match && (match->inode != oldinode ||
64960+ match->device != olddevice ||
64961+ !(match->mode & GR_DELETED)))
64962+ match = match->next;
64963+
64964+ if (match && (match->inode == oldinode)
64965+ && (match->device == olddevice)
64966+ && (match->mode & GR_DELETED)) {
64967+ if (match->prev == NULL) {
64968+ role->subj_hash[index] = match->next;
64969+ if (match->next != NULL)
64970+ match->next->prev = NULL;
64971+ } else {
64972+ match->prev->next = match->next;
64973+ if (match->next != NULL)
64974+ match->next->prev = match->prev;
64975+ }
64976+ match->prev = NULL;
64977+ match->next = NULL;
64978+ match->inode = newinode;
64979+ match->device = newdevice;
64980+ match->mode &= ~GR_DELETED;
64981+
64982+ insert_acl_subj_label(match, role);
64983+ }
64984+
64985+ return;
64986+}
64987+
64988+static void
64989+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
64990+ const ino_t newinode, const dev_t newdevice)
64991+{
64992+ unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
64993+ struct inodev_entry *match;
64994+
64995+ match = inodev_set.i_hash[index];
64996+
64997+ while (match && (match->nentry->inode != oldinode ||
64998+ match->nentry->device != olddevice || !match->nentry->deleted))
64999+ match = match->next;
65000+
65001+ if (match && (match->nentry->inode == oldinode)
65002+ && (match->nentry->device == olddevice) &&
65003+ match->nentry->deleted) {
65004+ if (match->prev == NULL) {
65005+ inodev_set.i_hash[index] = match->next;
65006+ if (match->next != NULL)
65007+ match->next->prev = NULL;
65008+ } else {
65009+ match->prev->next = match->next;
65010+ if (match->next != NULL)
65011+ match->next->prev = match->prev;
65012+ }
65013+ match->prev = NULL;
65014+ match->next = NULL;
65015+ match->nentry->inode = newinode;
65016+ match->nentry->device = newdevice;
65017+ match->nentry->deleted = 0;
65018+
65019+ insert_inodev_entry(match);
65020+ }
65021+
65022+ return;
65023+}
65024+
65025+static void
65026+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
65027+{
65028+ struct acl_subject_label *subj;
65029+ struct acl_role_label *role;
65030+ unsigned int x;
65031+
65032+ FOR_EACH_ROLE_START(role)
65033+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
65034+
65035+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
65036+ if ((subj->inode == ino) && (subj->device == dev)) {
65037+ subj->inode = ino;
65038+ subj->device = dev;
65039+ }
65040+ /* nested subjects aren't in the role's subj_hash table */
65041+ update_acl_obj_label(matchn->inode, matchn->device,
65042+ ino, dev, subj);
65043+ FOR_EACH_NESTED_SUBJECT_END(subj)
65044+ FOR_EACH_SUBJECT_START(role, subj, x)
65045+ update_acl_obj_label(matchn->inode, matchn->device,
65046+ ino, dev, subj);
65047+ FOR_EACH_SUBJECT_END(subj,x)
65048+ FOR_EACH_ROLE_END(role)
65049+
65050+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
65051+
65052+ return;
65053+}
65054+
65055+static void
65056+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
65057+ const struct vfsmount *mnt)
65058+{
65059+ ino_t ino = dentry->d_inode->i_ino;
65060+ dev_t dev = __get_dev(dentry);
65061+
65062+ __do_handle_create(matchn, ino, dev);
65063+
65064+ return;
65065+}
65066+
65067+void
65068+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
65069+{
65070+ struct name_entry *matchn;
65071+
65072+ if (unlikely(!(gr_status & GR_READY)))
65073+ return;
65074+
65075+ preempt_disable();
65076+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
65077+
65078+ if (unlikely((unsigned long)matchn)) {
65079+ write_lock(&gr_inode_lock);
65080+ do_handle_create(matchn, dentry, mnt);
65081+ write_unlock(&gr_inode_lock);
65082+ }
65083+ preempt_enable();
65084+
65085+ return;
65086+}
65087+
65088+void
65089+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
65090+{
65091+ struct name_entry *matchn;
65092+
65093+ if (unlikely(!(gr_status & GR_READY)))
65094+ return;
65095+
65096+ preempt_disable();
65097+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
65098+
65099+ if (unlikely((unsigned long)matchn)) {
65100+ write_lock(&gr_inode_lock);
65101+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
65102+ write_unlock(&gr_inode_lock);
65103+ }
65104+ preempt_enable();
65105+
65106+ return;
65107+}
65108+
65109+void
65110+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
65111+ struct dentry *old_dentry,
65112+ struct dentry *new_dentry,
65113+ struct vfsmount *mnt, const __u8 replace)
65114+{
65115+ struct name_entry *matchn;
65116+ struct inodev_entry *inodev;
65117+ struct inode *inode = new_dentry->d_inode;
65118+ ino_t old_ino = old_dentry->d_inode->i_ino;
65119+ dev_t old_dev = __get_dev(old_dentry);
65120+
65121+ /* vfs_rename swaps the name and parent link for old_dentry and
65122+ new_dentry
65123+ at this point, old_dentry has the new name, parent link, and inode
65124+ for the renamed file
65125+ if a file is being replaced by a rename, new_dentry has the inode
65126+ and name for the replaced file
65127+ */
65128+
65129+ if (unlikely(!(gr_status & GR_READY)))
65130+ return;
65131+
65132+ preempt_disable();
65133+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
65134+
65135+ /* we wouldn't have to check d_inode if it weren't for
65136+ NFS silly-renaming
65137+ */
65138+
65139+ write_lock(&gr_inode_lock);
65140+ if (unlikely(replace && inode)) {
65141+ ino_t new_ino = inode->i_ino;
65142+ dev_t new_dev = __get_dev(new_dentry);
65143+
65144+ inodev = lookup_inodev_entry(new_ino, new_dev);
65145+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
65146+ do_handle_delete(inodev, new_ino, new_dev);
65147+ }
65148+
65149+ inodev = lookup_inodev_entry(old_ino, old_dev);
65150+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
65151+ do_handle_delete(inodev, old_ino, old_dev);
65152+
65153+ if (unlikely((unsigned long)matchn))
65154+ do_handle_create(matchn, old_dentry, mnt);
65155+
65156+ write_unlock(&gr_inode_lock);
65157+ preempt_enable();
65158+
65159+ return;
65160+}
65161+
65162+static int
65163+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
65164+ unsigned char **sum)
65165+{
65166+ struct acl_role_label *r;
65167+ struct role_allowed_ip *ipp;
65168+ struct role_transition *trans;
65169+ unsigned int i;
65170+ int found = 0;
65171+ u32 curr_ip = current->signal->curr_ip;
65172+
65173+ current->signal->saved_ip = curr_ip;
65174+
65175+ /* check transition table */
65176+
65177+ for (trans = current->role->transitions; trans; trans = trans->next) {
65178+ if (!strcmp(rolename, trans->rolename)) {
65179+ found = 1;
65180+ break;
65181+ }
65182+ }
65183+
65184+ if (!found)
65185+ return 0;
65186+
65187+ /* handle special roles that do not require authentication
65188+ and check ip */
65189+
65190+ FOR_EACH_ROLE_START(r)
65191+ if (!strcmp(rolename, r->rolename) &&
65192+ (r->roletype & GR_ROLE_SPECIAL)) {
65193+ found = 0;
65194+ if (r->allowed_ips != NULL) {
65195+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
65196+ if ((ntohl(curr_ip) & ipp->netmask) ==
65197+ (ntohl(ipp->addr) & ipp->netmask))
65198+ found = 1;
65199+ }
65200+ } else
65201+ found = 2;
65202+ if (!found)
65203+ return 0;
65204+
65205+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
65206+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
65207+ *salt = NULL;
65208+ *sum = NULL;
65209+ return 1;
65210+ }
65211+ }
65212+ FOR_EACH_ROLE_END(r)
65213+
65214+ for (i = 0; i < num_sprole_pws; i++) {
65215+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
65216+ *salt = acl_special_roles[i]->salt;
65217+ *sum = acl_special_roles[i]->sum;
65218+ return 1;
65219+ }
65220+ }
65221+
65222+ return 0;
65223+}
65224+
65225+static void
65226+assign_special_role(char *rolename)
65227+{
65228+ struct acl_object_label *obj;
65229+ struct acl_role_label *r;
65230+ struct acl_role_label *assigned = NULL;
65231+ struct task_struct *tsk;
65232+ struct file *filp;
65233+
65234+ FOR_EACH_ROLE_START(r)
65235+ if (!strcmp(rolename, r->rolename) &&
65236+ (r->roletype & GR_ROLE_SPECIAL)) {
65237+ assigned = r;
65238+ break;
65239+ }
65240+ FOR_EACH_ROLE_END(r)
65241+
65242+ if (!assigned)
65243+ return;
65244+
65245+ read_lock(&tasklist_lock);
65246+ read_lock(&grsec_exec_file_lock);
65247+
65248+ tsk = current->real_parent;
65249+ if (tsk == NULL)
65250+ goto out_unlock;
65251+
65252+ filp = tsk->exec_file;
65253+ if (filp == NULL)
65254+ goto out_unlock;
65255+
65256+ tsk->is_writable = 0;
65257+
65258+ tsk->acl_sp_role = 1;
65259+ tsk->acl_role_id = ++acl_sp_role_value;
65260+ tsk->role = assigned;
65261+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
65262+
65263+ /* ignore additional mmap checks for processes that are writable
65264+ by the default ACL */
65265+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
65266+ if (unlikely(obj->mode & GR_WRITE))
65267+ tsk->is_writable = 1;
65268+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
65269+ if (unlikely(obj->mode & GR_WRITE))
65270+ tsk->is_writable = 1;
65271+
65272+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
65273+ 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));
65274+#endif
65275+
65276+out_unlock:
65277+ read_unlock(&grsec_exec_file_lock);
65278+ read_unlock(&tasklist_lock);
65279+ return;
65280+}
65281+
65282+int gr_check_secure_terminal(struct task_struct *task)
65283+{
65284+ struct task_struct *p, *p2, *p3;
65285+ struct files_struct *files;
65286+ struct fdtable *fdt;
65287+ struct file *our_file = NULL, *file;
65288+ int i;
65289+
65290+ if (task->signal->tty == NULL)
65291+ return 1;
65292+
65293+ files = get_files_struct(task);
65294+ if (files != NULL) {
65295+ rcu_read_lock();
65296+ fdt = files_fdtable(files);
65297+ for (i=0; i < fdt->max_fds; i++) {
65298+ file = fcheck_files(files, i);
65299+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
65300+ get_file(file);
65301+ our_file = file;
65302+ }
65303+ }
65304+ rcu_read_unlock();
65305+ put_files_struct(files);
65306+ }
65307+
65308+ if (our_file == NULL)
65309+ return 1;
65310+
65311+ read_lock(&tasklist_lock);
65312+ do_each_thread(p2, p) {
65313+ files = get_files_struct(p);
65314+ if (files == NULL ||
65315+ (p->signal && p->signal->tty == task->signal->tty)) {
65316+ if (files != NULL)
65317+ put_files_struct(files);
65318+ continue;
65319+ }
65320+ rcu_read_lock();
65321+ fdt = files_fdtable(files);
65322+ for (i=0; i < fdt->max_fds; i++) {
65323+ file = fcheck_files(files, i);
65324+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
65325+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
65326+ p3 = task;
65327+ while (task_pid_nr(p3) > 0) {
65328+ if (p3 == p)
65329+ break;
65330+ p3 = p3->real_parent;
65331+ }
65332+ if (p3 == p)
65333+ break;
65334+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
65335+ gr_handle_alertkill(p);
65336+ rcu_read_unlock();
65337+ put_files_struct(files);
65338+ read_unlock(&tasklist_lock);
65339+ fput(our_file);
65340+ return 0;
65341+ }
65342+ }
65343+ rcu_read_unlock();
65344+ put_files_struct(files);
65345+ } while_each_thread(p2, p);
65346+ read_unlock(&tasklist_lock);
65347+
65348+ fput(our_file);
65349+ return 1;
65350+}
65351+
65352+static int gr_rbac_disable(void *unused)
65353+{
65354+ pax_open_kernel();
65355+ gr_status &= ~GR_READY;
65356+ pax_close_kernel();
65357+
65358+ return 0;
65359+}
65360+
65361+ssize_t
65362+write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
65363+{
65364+ struct gr_arg_wrapper uwrap;
65365+ unsigned char *sprole_salt = NULL;
65366+ unsigned char *sprole_sum = NULL;
65367+ int error = 0;
65368+ int error2 = 0;
65369+ size_t req_count = 0;
65370+
65371+ mutex_lock(&gr_dev_mutex);
65372+
65373+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
65374+ error = -EPERM;
65375+ goto out;
65376+ }
65377+
65378+#ifdef CONFIG_COMPAT
65379+ pax_open_kernel();
65380+ if (is_compat_task()) {
65381+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
65382+ copy_gr_arg = &copy_gr_arg_compat;
65383+ copy_acl_object_label = &copy_acl_object_label_compat;
65384+ copy_acl_subject_label = &copy_acl_subject_label_compat;
65385+ copy_acl_role_label = &copy_acl_role_label_compat;
65386+ copy_acl_ip_label = &copy_acl_ip_label_compat;
65387+ copy_role_allowed_ip = &copy_role_allowed_ip_compat;
65388+ copy_role_transition = &copy_role_transition_compat;
65389+ copy_sprole_pw = &copy_sprole_pw_compat;
65390+ copy_gr_hash_struct = &copy_gr_hash_struct_compat;
65391+ copy_pointer_from_array = &copy_pointer_from_array_compat;
65392+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
65393+ } else {
65394+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
65395+ copy_gr_arg = &copy_gr_arg_normal;
65396+ copy_acl_object_label = &copy_acl_object_label_normal;
65397+ copy_acl_subject_label = &copy_acl_subject_label_normal;
65398+ copy_acl_role_label = &copy_acl_role_label_normal;
65399+ copy_acl_ip_label = &copy_acl_ip_label_normal;
65400+ copy_role_allowed_ip = &copy_role_allowed_ip_normal;
65401+ copy_role_transition = &copy_role_transition_normal;
65402+ copy_sprole_pw = &copy_sprole_pw_normal;
65403+ copy_gr_hash_struct = &copy_gr_hash_struct_normal;
65404+ copy_pointer_from_array = &copy_pointer_from_array_normal;
65405+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
65406+ }
65407+ pax_close_kernel();
65408+#endif
65409+
65410+ req_count = get_gr_arg_wrapper_size();
65411+
65412+ if (count != req_count) {
65413+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
65414+ error = -EINVAL;
65415+ goto out;
65416+ }
65417+
65418+
65419+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
65420+ gr_auth_expires = 0;
65421+ gr_auth_attempts = 0;
65422+ }
65423+
65424+ error = copy_gr_arg_wrapper(buf, &uwrap);
65425+ if (error)
65426+ goto out;
65427+
65428+ error = copy_gr_arg(uwrap.arg, gr_usermode);
65429+ if (error)
65430+ goto out;
65431+
65432+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
65433+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
65434+ time_after(gr_auth_expires, get_seconds())) {
65435+ error = -EBUSY;
65436+ goto out;
65437+ }
65438+
65439+ /* if non-root trying to do anything other than use a special role,
65440+ do not attempt authentication, do not count towards authentication
65441+ locking
65442+ */
65443+
65444+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
65445+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
65446+ gr_is_global_nonroot(current_uid())) {
65447+ error = -EPERM;
65448+ goto out;
65449+ }
65450+
65451+ /* ensure pw and special role name are null terminated */
65452+
65453+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
65454+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
65455+
65456+ /* Okay.
65457+ * We have our enough of the argument structure..(we have yet
65458+ * to copy_from_user the tables themselves) . Copy the tables
65459+ * only if we need them, i.e. for loading operations. */
65460+
65461+ switch (gr_usermode->mode) {
65462+ case GR_STATUS:
65463+ if (gr_status & GR_READY) {
65464+ error = 1;
65465+ if (!gr_check_secure_terminal(current))
65466+ error = 3;
65467+ } else
65468+ error = 2;
65469+ goto out;
65470+ case GR_SHUTDOWN:
65471+ if ((gr_status & GR_READY)
65472+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
65473+ stop_machine(gr_rbac_disable, NULL, NULL);
65474+ free_variables();
65475+ memset(gr_usermode, 0, sizeof (struct gr_arg));
65476+ memset(gr_system_salt, 0, GR_SALT_LEN);
65477+ memset(gr_system_sum, 0, GR_SHA_LEN);
65478+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
65479+ } else if (gr_status & GR_READY) {
65480+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
65481+ error = -EPERM;
65482+ } else {
65483+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
65484+ error = -EAGAIN;
65485+ }
65486+ break;
65487+ case GR_ENABLE:
65488+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
65489+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
65490+ else {
65491+ if (gr_status & GR_READY)
65492+ error = -EAGAIN;
65493+ else
65494+ error = error2;
65495+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
65496+ }
65497+ break;
65498+ case GR_RELOAD:
65499+ if (!(gr_status & GR_READY)) {
65500+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
65501+ error = -EAGAIN;
65502+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
65503+ stop_machine(gr_rbac_disable, NULL, NULL);
65504+ free_variables();
65505+ error2 = gracl_init(gr_usermode);
65506+ if (!error2)
65507+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
65508+ else {
65509+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
65510+ error = error2;
65511+ }
65512+ } else {
65513+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
65514+ error = -EPERM;
65515+ }
65516+ break;
65517+ case GR_SEGVMOD:
65518+ if (unlikely(!(gr_status & GR_READY))) {
65519+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
65520+ error = -EAGAIN;
65521+ break;
65522+ }
65523+
65524+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
65525+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
65526+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
65527+ struct acl_subject_label *segvacl;
65528+ segvacl =
65529+ lookup_acl_subj_label(gr_usermode->segv_inode,
65530+ gr_usermode->segv_device,
65531+ current->role);
65532+ if (segvacl) {
65533+ segvacl->crashes = 0;
65534+ segvacl->expires = 0;
65535+ }
65536+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
65537+ gr_remove_uid(gr_usermode->segv_uid);
65538+ }
65539+ } else {
65540+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
65541+ error = -EPERM;
65542+ }
65543+ break;
65544+ case GR_SPROLE:
65545+ case GR_SPROLEPAM:
65546+ if (unlikely(!(gr_status & GR_READY))) {
65547+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
65548+ error = -EAGAIN;
65549+ break;
65550+ }
65551+
65552+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
65553+ current->role->expires = 0;
65554+ current->role->auth_attempts = 0;
65555+ }
65556+
65557+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
65558+ time_after(current->role->expires, get_seconds())) {
65559+ error = -EBUSY;
65560+ goto out;
65561+ }
65562+
65563+ if (lookup_special_role_auth
65564+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
65565+ && ((!sprole_salt && !sprole_sum)
65566+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
65567+ char *p = "";
65568+ assign_special_role(gr_usermode->sp_role);
65569+ read_lock(&tasklist_lock);
65570+ if (current->real_parent)
65571+ p = current->real_parent->role->rolename;
65572+ read_unlock(&tasklist_lock);
65573+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
65574+ p, acl_sp_role_value);
65575+ } else {
65576+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
65577+ error = -EPERM;
65578+ if(!(current->role->auth_attempts++))
65579+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
65580+
65581+ goto out;
65582+ }
65583+ break;
65584+ case GR_UNSPROLE:
65585+ if (unlikely(!(gr_status & GR_READY))) {
65586+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
65587+ error = -EAGAIN;
65588+ break;
65589+ }
65590+
65591+ if (current->role->roletype & GR_ROLE_SPECIAL) {
65592+ char *p = "";
65593+ int i = 0;
65594+
65595+ read_lock(&tasklist_lock);
65596+ if (current->real_parent) {
65597+ p = current->real_parent->role->rolename;
65598+ i = current->real_parent->acl_role_id;
65599+ }
65600+ read_unlock(&tasklist_lock);
65601+
65602+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
65603+ gr_set_acls(1);
65604+ } else {
65605+ error = -EPERM;
65606+ goto out;
65607+ }
65608+ break;
65609+ default:
65610+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
65611+ error = -EINVAL;
65612+ break;
65613+ }
65614+
65615+ if (error != -EPERM)
65616+ goto out;
65617+
65618+ if(!(gr_auth_attempts++))
65619+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
65620+
65621+ out:
65622+ mutex_unlock(&gr_dev_mutex);
65623+
65624+ if (!error)
65625+ error = req_count;
65626+
65627+ return error;
65628+}
65629+
65630+/* must be called with
65631+ rcu_read_lock();
65632+ read_lock(&tasklist_lock);
65633+ read_lock(&grsec_exec_file_lock);
65634+*/
65635+int gr_apply_subject_to_task(struct task_struct *task)
65636+{
65637+ struct acl_object_label *obj;
65638+ char *tmpname;
65639+ struct acl_subject_label *tmpsubj;
65640+ struct file *filp;
65641+ struct name_entry *nmatch;
65642+
65643+ filp = task->exec_file;
65644+ if (filp == NULL)
65645+ return 0;
65646+
65647+ /* the following is to apply the correct subject
65648+ on binaries running when the RBAC system
65649+ is enabled, when the binaries have been
65650+ replaced or deleted since their execution
65651+ -----
65652+ when the RBAC system starts, the inode/dev
65653+ from exec_file will be one the RBAC system
65654+ is unaware of. It only knows the inode/dev
65655+ of the present file on disk, or the absence
65656+ of it.
65657+ */
65658+ preempt_disable();
65659+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
65660+
65661+ nmatch = lookup_name_entry(tmpname);
65662+ preempt_enable();
65663+ tmpsubj = NULL;
65664+ if (nmatch) {
65665+ if (nmatch->deleted)
65666+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
65667+ else
65668+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
65669+ if (tmpsubj != NULL)
65670+ task->acl = tmpsubj;
65671+ }
65672+ if (tmpsubj == NULL)
65673+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
65674+ task->role);
65675+ if (task->acl) {
65676+ task->is_writable = 0;
65677+ /* ignore additional mmap checks for processes that are writable
65678+ by the default ACL */
65679+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
65680+ if (unlikely(obj->mode & GR_WRITE))
65681+ task->is_writable = 1;
65682+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
65683+ if (unlikely(obj->mode & GR_WRITE))
65684+ task->is_writable = 1;
65685+
65686+ gr_set_proc_res(task);
65687+
65688+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
65689+ 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);
65690+#endif
65691+ } else {
65692+ return 1;
65693+ }
65694+
65695+ return 0;
65696+}
65697+
65698+int
65699+gr_set_acls(const int type)
65700+{
65701+ struct task_struct *task, *task2;
65702+ struct acl_role_label *role = current->role;
65703+ __u16 acl_role_id = current->acl_role_id;
65704+ const struct cred *cred;
65705+ int ret;
65706+
65707+ rcu_read_lock();
65708+ read_lock(&tasklist_lock);
65709+ read_lock(&grsec_exec_file_lock);
65710+ do_each_thread(task2, task) {
65711+ /* check to see if we're called from the exit handler,
65712+ if so, only replace ACLs that have inherited the admin
65713+ ACL */
65714+
65715+ if (type && (task->role != role ||
65716+ task->acl_role_id != acl_role_id))
65717+ continue;
65718+
65719+ task->acl_role_id = 0;
65720+ task->acl_sp_role = 0;
65721+
65722+ if (task->exec_file) {
65723+ cred = __task_cred(task);
65724+ task->role = lookup_acl_role_label(task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
65725+ ret = gr_apply_subject_to_task(task);
65726+ if (ret) {
65727+ read_unlock(&grsec_exec_file_lock);
65728+ read_unlock(&tasklist_lock);
65729+ rcu_read_unlock();
65730+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
65731+ return ret;
65732+ }
65733+ } else {
65734+ // it's a kernel process
65735+ task->role = kernel_role;
65736+ task->acl = kernel_role->root_label;
65737+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
65738+ task->acl->mode &= ~GR_PROCFIND;
65739+#endif
65740+ }
65741+ } while_each_thread(task2, task);
65742+ read_unlock(&grsec_exec_file_lock);
65743+ read_unlock(&tasklist_lock);
65744+ rcu_read_unlock();
65745+
65746+ return 0;
65747+}
65748+
65749+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
65750+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
65751+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
65752+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
65753+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
65754+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
65755+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
65756+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
65757+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
65758+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
65759+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
65760+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
65761+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
65762+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
65763+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
65764+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
65765+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
65766+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
65767+};
65768+
65769+void
65770+gr_learn_resource(const struct task_struct *task,
65771+ const int res, const unsigned long wanted, const int gt)
65772+{
65773+ struct acl_subject_label *acl;
65774+ const struct cred *cred;
65775+
65776+ if (unlikely((gr_status & GR_READY) &&
65777+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
65778+ goto skip_reslog;
65779+
65780+ gr_log_resource(task, res, wanted, gt);
65781+skip_reslog:
65782+
65783+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
65784+ return;
65785+
65786+ acl = task->acl;
65787+
65788+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
65789+ !(acl->resmask & (1U << (unsigned short) res))))
65790+ return;
65791+
65792+ if (wanted >= acl->res[res].rlim_cur) {
65793+ unsigned long res_add;
65794+
65795+ res_add = wanted + res_learn_bumps[res];
65796+
65797+ acl->res[res].rlim_cur = res_add;
65798+
65799+ if (wanted > acl->res[res].rlim_max)
65800+ acl->res[res].rlim_max = res_add;
65801+
65802+ /* only log the subject filename, since resource logging is supported for
65803+ single-subject learning only */
65804+ rcu_read_lock();
65805+ cred = __task_cred(task);
65806+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
65807+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
65808+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
65809+ "", (unsigned long) res, &task->signal->saved_ip);
65810+ rcu_read_unlock();
65811+ }
65812+
65813+ return;
65814+}
65815+EXPORT_SYMBOL(gr_learn_resource);
65816+#endif
65817+
65818+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
65819+void
65820+pax_set_initial_flags(struct linux_binprm *bprm)
65821+{
65822+ struct task_struct *task = current;
65823+ struct acl_subject_label *proc;
65824+ unsigned long flags;
65825+
65826+ if (unlikely(!(gr_status & GR_READY)))
65827+ return;
65828+
65829+ flags = pax_get_flags(task);
65830+
65831+ proc = task->acl;
65832+
65833+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
65834+ flags &= ~MF_PAX_PAGEEXEC;
65835+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
65836+ flags &= ~MF_PAX_SEGMEXEC;
65837+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
65838+ flags &= ~MF_PAX_RANDMMAP;
65839+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
65840+ flags &= ~MF_PAX_EMUTRAMP;
65841+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
65842+ flags &= ~MF_PAX_MPROTECT;
65843+
65844+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
65845+ flags |= MF_PAX_PAGEEXEC;
65846+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
65847+ flags |= MF_PAX_SEGMEXEC;
65848+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
65849+ flags |= MF_PAX_RANDMMAP;
65850+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
65851+ flags |= MF_PAX_EMUTRAMP;
65852+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
65853+ flags |= MF_PAX_MPROTECT;
65854+
65855+ pax_set_flags(task, flags);
65856+
65857+ return;
65858+}
65859+#endif
65860+
65861+int
65862+gr_handle_proc_ptrace(struct task_struct *task)
65863+{
65864+ struct file *filp;
65865+ struct task_struct *tmp = task;
65866+ struct task_struct *curtemp = current;
65867+ __u32 retmode;
65868+
65869+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
65870+ if (unlikely(!(gr_status & GR_READY)))
65871+ return 0;
65872+#endif
65873+
65874+ read_lock(&tasklist_lock);
65875+ read_lock(&grsec_exec_file_lock);
65876+ filp = task->exec_file;
65877+
65878+ while (task_pid_nr(tmp) > 0) {
65879+ if (tmp == curtemp)
65880+ break;
65881+ tmp = tmp->real_parent;
65882+ }
65883+
65884+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
65885+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
65886+ read_unlock(&grsec_exec_file_lock);
65887+ read_unlock(&tasklist_lock);
65888+ return 1;
65889+ }
65890+
65891+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
65892+ if (!(gr_status & GR_READY)) {
65893+ read_unlock(&grsec_exec_file_lock);
65894+ read_unlock(&tasklist_lock);
65895+ return 0;
65896+ }
65897+#endif
65898+
65899+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
65900+ read_unlock(&grsec_exec_file_lock);
65901+ read_unlock(&tasklist_lock);
65902+
65903+ if (retmode & GR_NOPTRACE)
65904+ return 1;
65905+
65906+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
65907+ && (current->acl != task->acl || (current->acl != current->role->root_label
65908+ && task_pid_nr(current) != task_pid_nr(task))))
65909+ return 1;
65910+
65911+ return 0;
65912+}
65913+
65914+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
65915+{
65916+ if (unlikely(!(gr_status & GR_READY)))
65917+ return;
65918+
65919+ if (!(current->role->roletype & GR_ROLE_GOD))
65920+ return;
65921+
65922+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
65923+ p->role->rolename, gr_task_roletype_to_char(p),
65924+ p->acl->filename);
65925+}
65926+
65927+int
65928+gr_handle_ptrace(struct task_struct *task, const long request)
65929+{
65930+ struct task_struct *tmp = task;
65931+ struct task_struct *curtemp = current;
65932+ __u32 retmode;
65933+
65934+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
65935+ if (unlikely(!(gr_status & GR_READY)))
65936+ return 0;
65937+#endif
65938+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
65939+ read_lock(&tasklist_lock);
65940+ while (task_pid_nr(tmp) > 0) {
65941+ if (tmp == curtemp)
65942+ break;
65943+ tmp = tmp->real_parent;
65944+ }
65945+
65946+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
65947+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
65948+ read_unlock(&tasklist_lock);
65949+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
65950+ return 1;
65951+ }
65952+ read_unlock(&tasklist_lock);
65953+ }
65954+
65955+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
65956+ if (!(gr_status & GR_READY))
65957+ return 0;
65958+#endif
65959+
65960+ read_lock(&grsec_exec_file_lock);
65961+ if (unlikely(!task->exec_file)) {
65962+ read_unlock(&grsec_exec_file_lock);
65963+ return 0;
65964+ }
65965+
65966+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
65967+ read_unlock(&grsec_exec_file_lock);
65968+
65969+ if (retmode & GR_NOPTRACE) {
65970+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
65971+ return 1;
65972+ }
65973+
65974+ if (retmode & GR_PTRACERD) {
65975+ switch (request) {
65976+ case PTRACE_SEIZE:
65977+ case PTRACE_POKETEXT:
65978+ case PTRACE_POKEDATA:
65979+ case PTRACE_POKEUSR:
65980+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
65981+ case PTRACE_SETREGS:
65982+ case PTRACE_SETFPREGS:
65983+#endif
65984+#ifdef CONFIG_X86
65985+ case PTRACE_SETFPXREGS:
65986+#endif
65987+#ifdef CONFIG_ALTIVEC
65988+ case PTRACE_SETVRREGS:
65989+#endif
65990+ return 1;
65991+ default:
65992+ return 0;
65993+ }
65994+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
65995+ !(current->role->roletype & GR_ROLE_GOD) &&
65996+ (current->acl != task->acl)) {
65997+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
65998+ return 1;
65999+ }
66000+
66001+ return 0;
66002+}
66003+
66004+static int is_writable_mmap(const struct file *filp)
66005+{
66006+ struct task_struct *task = current;
66007+ struct acl_object_label *obj, *obj2;
66008+
66009+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
66010+ !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))) {
66011+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
66012+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
66013+ task->role->root_label);
66014+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
66015+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
66016+ return 1;
66017+ }
66018+ }
66019+ return 0;
66020+}
66021+
66022+int
66023+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
66024+{
66025+ __u32 mode;
66026+
66027+ if (unlikely(!file || !(prot & PROT_EXEC)))
66028+ return 1;
66029+
66030+ if (is_writable_mmap(file))
66031+ return 0;
66032+
66033+ mode =
66034+ gr_search_file(file->f_path.dentry,
66035+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
66036+ file->f_path.mnt);
66037+
66038+ if (!gr_tpe_allow(file))
66039+ return 0;
66040+
66041+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
66042+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66043+ return 0;
66044+ } else if (unlikely(!(mode & GR_EXEC))) {
66045+ return 0;
66046+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
66047+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66048+ return 1;
66049+ }
66050+
66051+ return 1;
66052+}
66053+
66054+int
66055+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
66056+{
66057+ __u32 mode;
66058+
66059+ if (unlikely(!file || !(prot & PROT_EXEC)))
66060+ return 1;
66061+
66062+ if (is_writable_mmap(file))
66063+ return 0;
66064+
66065+ mode =
66066+ gr_search_file(file->f_path.dentry,
66067+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
66068+ file->f_path.mnt);
66069+
66070+ if (!gr_tpe_allow(file))
66071+ return 0;
66072+
66073+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
66074+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66075+ return 0;
66076+ } else if (unlikely(!(mode & GR_EXEC))) {
66077+ return 0;
66078+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
66079+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66080+ return 1;
66081+ }
66082+
66083+ return 1;
66084+}
66085+
66086+void
66087+gr_acl_handle_psacct(struct task_struct *task, const long code)
66088+{
66089+ unsigned long runtime;
66090+ unsigned long cputime;
66091+ unsigned int wday, cday;
66092+ __u8 whr, chr;
66093+ __u8 wmin, cmin;
66094+ __u8 wsec, csec;
66095+ struct timespec timeval;
66096+
66097+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
66098+ !(task->acl->mode & GR_PROCACCT)))
66099+ return;
66100+
66101+ do_posix_clock_monotonic_gettime(&timeval);
66102+ runtime = timeval.tv_sec - task->start_time.tv_sec;
66103+ wday = runtime / (3600 * 24);
66104+ runtime -= wday * (3600 * 24);
66105+ whr = runtime / 3600;
66106+ runtime -= whr * 3600;
66107+ wmin = runtime / 60;
66108+ runtime -= wmin * 60;
66109+ wsec = runtime;
66110+
66111+ cputime = (task->utime + task->stime) / HZ;
66112+ cday = cputime / (3600 * 24);
66113+ cputime -= cday * (3600 * 24);
66114+ chr = cputime / 3600;
66115+ cputime -= chr * 3600;
66116+ cmin = cputime / 60;
66117+ cputime -= cmin * 60;
66118+ csec = cputime;
66119+
66120+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
66121+
66122+ return;
66123+}
66124+
66125+void gr_set_kernel_label(struct task_struct *task)
66126+{
66127+ if (gr_status & GR_READY) {
66128+ task->role = kernel_role;
66129+ task->acl = kernel_role->root_label;
66130+ }
66131+ return;
66132+}
66133+
66134+#ifdef CONFIG_TASKSTATS
66135+int gr_is_taskstats_denied(int pid)
66136+{
66137+ struct task_struct *task;
66138+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66139+ const struct cred *cred;
66140+#endif
66141+ int ret = 0;
66142+
66143+ /* restrict taskstats viewing to un-chrooted root users
66144+ who have the 'view' subject flag if the RBAC system is enabled
66145+ */
66146+
66147+ rcu_read_lock();
66148+ read_lock(&tasklist_lock);
66149+ task = find_task_by_vpid(pid);
66150+ if (task) {
66151+#ifdef CONFIG_GRKERNSEC_CHROOT
66152+ if (proc_is_chrooted(task))
66153+ ret = -EACCES;
66154+#endif
66155+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66156+ cred = __task_cred(task);
66157+#ifdef CONFIG_GRKERNSEC_PROC_USER
66158+ if (gr_is_global_nonroot(cred->uid))
66159+ ret = -EACCES;
66160+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66161+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
66162+ ret = -EACCES;
66163+#endif
66164+#endif
66165+ if (gr_status & GR_READY) {
66166+ if (!(task->acl->mode & GR_VIEW))
66167+ ret = -EACCES;
66168+ }
66169+ } else
66170+ ret = -ENOENT;
66171+
66172+ read_unlock(&tasklist_lock);
66173+ rcu_read_unlock();
66174+
66175+ return ret;
66176+}
66177+#endif
66178+
66179+/* AUXV entries are filled via a descendant of search_binary_handler
66180+ after we've already applied the subject for the target
66181+*/
66182+int gr_acl_enable_at_secure(void)
66183+{
66184+ if (unlikely(!(gr_status & GR_READY)))
66185+ return 0;
66186+
66187+ if (current->acl->mode & GR_ATSECURE)
66188+ return 1;
66189+
66190+ return 0;
66191+}
66192+
66193+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
66194+{
66195+ struct task_struct *task = current;
66196+ struct dentry *dentry = file->f_path.dentry;
66197+ struct vfsmount *mnt = file->f_path.mnt;
66198+ struct acl_object_label *obj, *tmp;
66199+ struct acl_subject_label *subj;
66200+ unsigned int bufsize;
66201+ int is_not_root;
66202+ char *path;
66203+ dev_t dev = __get_dev(dentry);
66204+
66205+ if (unlikely(!(gr_status & GR_READY)))
66206+ return 1;
66207+
66208+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
66209+ return 1;
66210+
66211+ /* ignore Eric Biederman */
66212+ if (IS_PRIVATE(dentry->d_inode))
66213+ return 1;
66214+
66215+ subj = task->acl;
66216+ read_lock(&gr_inode_lock);
66217+ do {
66218+ obj = lookup_acl_obj_label(ino, dev, subj);
66219+ if (obj != NULL) {
66220+ read_unlock(&gr_inode_lock);
66221+ return (obj->mode & GR_FIND) ? 1 : 0;
66222+ }
66223+ } while ((subj = subj->parent_subject));
66224+ read_unlock(&gr_inode_lock);
66225+
66226+ /* this is purely an optimization since we're looking for an object
66227+ for the directory we're doing a readdir on
66228+ if it's possible for any globbed object to match the entry we're
66229+ filling into the directory, then the object we find here will be
66230+ an anchor point with attached globbed objects
66231+ */
66232+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
66233+ if (obj->globbed == NULL)
66234+ return (obj->mode & GR_FIND) ? 1 : 0;
66235+
66236+ is_not_root = ((obj->filename[0] == '/') &&
66237+ (obj->filename[1] == '\0')) ? 0 : 1;
66238+ bufsize = PAGE_SIZE - namelen - is_not_root;
66239+
66240+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
66241+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
66242+ return 1;
66243+
66244+ preempt_disable();
66245+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
66246+ bufsize);
66247+
66248+ bufsize = strlen(path);
66249+
66250+ /* if base is "/", don't append an additional slash */
66251+ if (is_not_root)
66252+ *(path + bufsize) = '/';
66253+ memcpy(path + bufsize + is_not_root, name, namelen);
66254+ *(path + bufsize + namelen + is_not_root) = '\0';
66255+
66256+ tmp = obj->globbed;
66257+ while (tmp) {
66258+ if (!glob_match(tmp->filename, path)) {
66259+ preempt_enable();
66260+ return (tmp->mode & GR_FIND) ? 1 : 0;
66261+ }
66262+ tmp = tmp->next;
66263+ }
66264+ preempt_enable();
66265+ return (obj->mode & GR_FIND) ? 1 : 0;
66266+}
66267+
66268+void gr_put_exec_file(struct task_struct *task)
66269+{
66270+ struct file *filp;
66271+
66272+ write_lock(&grsec_exec_file_lock);
66273+ filp = task->exec_file;
66274+ task->exec_file = NULL;
66275+ write_unlock(&grsec_exec_file_lock);
66276+
66277+ if (filp)
66278+ fput(filp);
66279+
66280+ return;
66281+}
66282+
66283+
66284+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
66285+EXPORT_SYMBOL(gr_acl_is_enabled);
66286+#endif
66287+EXPORT_SYMBOL(gr_set_kernel_label);
66288+#ifdef CONFIG_SECURITY
66289+EXPORT_SYMBOL(gr_check_user_change);
66290+EXPORT_SYMBOL(gr_check_group_change);
66291+#endif
66292+
66293diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
66294new file mode 100644
66295index 0000000..34fefda
66296--- /dev/null
66297+++ b/grsecurity/gracl_alloc.c
66298@@ -0,0 +1,105 @@
66299+#include <linux/kernel.h>
66300+#include <linux/mm.h>
66301+#include <linux/slab.h>
66302+#include <linux/vmalloc.h>
66303+#include <linux/gracl.h>
66304+#include <linux/grsecurity.h>
66305+
66306+static unsigned long alloc_stack_next = 1;
66307+static unsigned long alloc_stack_size = 1;
66308+static void **alloc_stack;
66309+
66310+static __inline__ int
66311+alloc_pop(void)
66312+{
66313+ if (alloc_stack_next == 1)
66314+ return 0;
66315+
66316+ kfree(alloc_stack[alloc_stack_next - 2]);
66317+
66318+ alloc_stack_next--;
66319+
66320+ return 1;
66321+}
66322+
66323+static __inline__ int
66324+alloc_push(void *buf)
66325+{
66326+ if (alloc_stack_next >= alloc_stack_size)
66327+ return 1;
66328+
66329+ alloc_stack[alloc_stack_next - 1] = buf;
66330+
66331+ alloc_stack_next++;
66332+
66333+ return 0;
66334+}
66335+
66336+void *
66337+acl_alloc(unsigned long len)
66338+{
66339+ void *ret = NULL;
66340+
66341+ if (!len || len > PAGE_SIZE)
66342+ goto out;
66343+
66344+ ret = kmalloc(len, GFP_KERNEL);
66345+
66346+ if (ret) {
66347+ if (alloc_push(ret)) {
66348+ kfree(ret);
66349+ ret = NULL;
66350+ }
66351+ }
66352+
66353+out:
66354+ return ret;
66355+}
66356+
66357+void *
66358+acl_alloc_num(unsigned long num, unsigned long len)
66359+{
66360+ if (!len || (num > (PAGE_SIZE / len)))
66361+ return NULL;
66362+
66363+ return acl_alloc(num * len);
66364+}
66365+
66366+void
66367+acl_free_all(void)
66368+{
66369+ if (gr_acl_is_enabled() || !alloc_stack)
66370+ return;
66371+
66372+ while (alloc_pop()) ;
66373+
66374+ if (alloc_stack) {
66375+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
66376+ kfree(alloc_stack);
66377+ else
66378+ vfree(alloc_stack);
66379+ }
66380+
66381+ alloc_stack = NULL;
66382+ alloc_stack_size = 1;
66383+ alloc_stack_next = 1;
66384+
66385+ return;
66386+}
66387+
66388+int
66389+acl_alloc_stack_init(unsigned long size)
66390+{
66391+ if ((size * sizeof (void *)) <= PAGE_SIZE)
66392+ alloc_stack =
66393+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
66394+ else
66395+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
66396+
66397+ alloc_stack_size = size;
66398+
66399+ if (!alloc_stack)
66400+ return 0;
66401+ else
66402+ return 1;
66403+}
66404diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
66405new file mode 100644
66406index 0000000..bdd51ea
66407--- /dev/null
66408+++ b/grsecurity/gracl_cap.c
66409@@ -0,0 +1,110 @@
66410+#include <linux/kernel.h>
66411+#include <linux/module.h>
66412+#include <linux/sched.h>
66413+#include <linux/gracl.h>
66414+#include <linux/grsecurity.h>
66415+#include <linux/grinternal.h>
66416+
66417+extern const char *captab_log[];
66418+extern int captab_log_entries;
66419+
66420+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
66421+{
66422+ struct acl_subject_label *curracl;
66423+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
66424+ kernel_cap_t cap_audit = __cap_empty_set;
66425+
66426+ if (!gr_acl_is_enabled())
66427+ return 1;
66428+
66429+ curracl = task->acl;
66430+
66431+ cap_drop = curracl->cap_lower;
66432+ cap_mask = curracl->cap_mask;
66433+ cap_audit = curracl->cap_invert_audit;
66434+
66435+ while ((curracl = curracl->parent_subject)) {
66436+ /* if the cap isn't specified in the current computed mask but is specified in the
66437+ current level subject, and is lowered in the current level subject, then add
66438+ it to the set of dropped capabilities
66439+ otherwise, add the current level subject's mask to the current computed mask
66440+ */
66441+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
66442+ cap_raise(cap_mask, cap);
66443+ if (cap_raised(curracl->cap_lower, cap))
66444+ cap_raise(cap_drop, cap);
66445+ if (cap_raised(curracl->cap_invert_audit, cap))
66446+ cap_raise(cap_audit, cap);
66447+ }
66448+ }
66449+
66450+ if (!cap_raised(cap_drop, cap)) {
66451+ if (cap_raised(cap_audit, cap))
66452+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
66453+ return 1;
66454+ }
66455+
66456+ curracl = task->acl;
66457+
66458+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
66459+ && cap_raised(cred->cap_effective, cap)) {
66460+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
66461+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
66462+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
66463+ gr_to_filename(task->exec_file->f_path.dentry,
66464+ task->exec_file->f_path.mnt) : curracl->filename,
66465+ curracl->filename, 0UL,
66466+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
66467+ return 1;
66468+ }
66469+
66470+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
66471+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
66472+
66473+ return 0;
66474+}
66475+
66476+int
66477+gr_acl_is_capable(const int cap)
66478+{
66479+ return gr_task_acl_is_capable(current, current_cred(), cap);
66480+}
66481+
66482+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
66483+{
66484+ struct acl_subject_label *curracl;
66485+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
66486+
66487+ if (!gr_acl_is_enabled())
66488+ return 1;
66489+
66490+ curracl = task->acl;
66491+
66492+ cap_drop = curracl->cap_lower;
66493+ cap_mask = curracl->cap_mask;
66494+
66495+ while ((curracl = curracl->parent_subject)) {
66496+ /* if the cap isn't specified in the current computed mask but is specified in the
66497+ current level subject, and is lowered in the current level subject, then add
66498+ it to the set of dropped capabilities
66499+ otherwise, add the current level subject's mask to the current computed mask
66500+ */
66501+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
66502+ cap_raise(cap_mask, cap);
66503+ if (cap_raised(curracl->cap_lower, cap))
66504+ cap_raise(cap_drop, cap);
66505+ }
66506+ }
66507+
66508+ if (!cap_raised(cap_drop, cap))
66509+ return 1;
66510+
66511+ return 0;
66512+}
66513+
66514+int
66515+gr_acl_is_capable_nolog(const int cap)
66516+{
66517+ return gr_task_acl_is_capable_nolog(current, cap);
66518+}
66519+
66520diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
66521new file mode 100644
66522index 0000000..a43dd06
66523--- /dev/null
66524+++ b/grsecurity/gracl_compat.c
66525@@ -0,0 +1,269 @@
66526+#include <linux/kernel.h>
66527+#include <linux/gracl.h>
66528+#include <linux/compat.h>
66529+#include <linux/gracl_compat.h>
66530+
66531+#include <asm/uaccess.h>
66532+
66533+int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
66534+{
66535+ struct gr_arg_wrapper_compat uwrapcompat;
66536+
66537+ if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
66538+ return -EFAULT;
66539+
66540+ if ((uwrapcompat.version != GRSECURITY_VERSION) ||
66541+ (uwrapcompat.size != sizeof(struct gr_arg_compat)))
66542+ return -EINVAL;
66543+
66544+ uwrap->arg = compat_ptr(uwrapcompat.arg);
66545+ uwrap->version = uwrapcompat.version;
66546+ uwrap->size = sizeof(struct gr_arg);
66547+
66548+ return 0;
66549+}
66550+
66551+int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
66552+{
66553+ struct gr_arg_compat argcompat;
66554+
66555+ if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
66556+ return -EFAULT;
66557+
66558+ arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
66559+ arg->role_db.num_pointers = argcompat.role_db.num_pointers;
66560+ arg->role_db.num_roles = argcompat.role_db.num_roles;
66561+ arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
66562+ arg->role_db.num_subjects = argcompat.role_db.num_subjects;
66563+ arg->role_db.num_objects = argcompat.role_db.num_objects;
66564+
66565+ memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
66566+ memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
66567+ memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
66568+ memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
66569+ arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
66570+ arg->segv_device = argcompat.segv_device;
66571+ arg->segv_inode = argcompat.segv_inode;
66572+ arg->segv_uid = argcompat.segv_uid;
66573+ arg->num_sprole_pws = argcompat.num_sprole_pws;
66574+ arg->mode = argcompat.mode;
66575+
66576+ return 0;
66577+}
66578+
66579+int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
66580+{
66581+ struct acl_object_label_compat objcompat;
66582+
66583+ if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
66584+ return -EFAULT;
66585+
66586+ obj->filename = compat_ptr(objcompat.filename);
66587+ obj->inode = objcompat.inode;
66588+ obj->device = objcompat.device;
66589+ obj->mode = objcompat.mode;
66590+
66591+ obj->nested = compat_ptr(objcompat.nested);
66592+ obj->globbed = compat_ptr(objcompat.globbed);
66593+
66594+ obj->prev = compat_ptr(objcompat.prev);
66595+ obj->next = compat_ptr(objcompat.next);
66596+
66597+ return 0;
66598+}
66599+
66600+int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
66601+{
66602+ unsigned int i;
66603+ struct acl_subject_label_compat subjcompat;
66604+
66605+ if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
66606+ return -EFAULT;
66607+
66608+ subj->filename = compat_ptr(subjcompat.filename);
66609+ subj->inode = subjcompat.inode;
66610+ subj->device = subjcompat.device;
66611+ subj->mode = subjcompat.mode;
66612+ subj->cap_mask = subjcompat.cap_mask;
66613+ subj->cap_lower = subjcompat.cap_lower;
66614+ subj->cap_invert_audit = subjcompat.cap_invert_audit;
66615+
66616+ for (i = 0; i < GR_NLIMITS; i++) {
66617+ if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
66618+ subj->res[i].rlim_cur = RLIM_INFINITY;
66619+ else
66620+ subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
66621+ if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
66622+ subj->res[i].rlim_max = RLIM_INFINITY;
66623+ else
66624+ subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
66625+ }
66626+ subj->resmask = subjcompat.resmask;
66627+
66628+ subj->user_trans_type = subjcompat.user_trans_type;
66629+ subj->group_trans_type = subjcompat.group_trans_type;
66630+ subj->user_transitions = compat_ptr(subjcompat.user_transitions);
66631+ subj->group_transitions = compat_ptr(subjcompat.group_transitions);
66632+ subj->user_trans_num = subjcompat.user_trans_num;
66633+ subj->group_trans_num = subjcompat.group_trans_num;
66634+
66635+ memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
66636+ memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
66637+ subj->ip_type = subjcompat.ip_type;
66638+ subj->ips = compat_ptr(subjcompat.ips);
66639+ subj->ip_num = subjcompat.ip_num;
66640+ subj->inaddr_any_override = subjcompat.inaddr_any_override;
66641+
66642+ subj->crashes = subjcompat.crashes;
66643+ subj->expires = subjcompat.expires;
66644+
66645+ subj->parent_subject = compat_ptr(subjcompat.parent_subject);
66646+ subj->hash = compat_ptr(subjcompat.hash);
66647+ subj->prev = compat_ptr(subjcompat.prev);
66648+ subj->next = compat_ptr(subjcompat.next);
66649+
66650+ subj->obj_hash = compat_ptr(subjcompat.obj_hash);
66651+ subj->obj_hash_size = subjcompat.obj_hash_size;
66652+ subj->pax_flags = subjcompat.pax_flags;
66653+
66654+ return 0;
66655+}
66656+
66657+int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
66658+{
66659+ struct acl_role_label_compat rolecompat;
66660+
66661+ if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
66662+ return -EFAULT;
66663+
66664+ role->rolename = compat_ptr(rolecompat.rolename);
66665+ role->uidgid = rolecompat.uidgid;
66666+ role->roletype = rolecompat.roletype;
66667+
66668+ role->auth_attempts = rolecompat.auth_attempts;
66669+ role->expires = rolecompat.expires;
66670+
66671+ role->root_label = compat_ptr(rolecompat.root_label);
66672+ role->hash = compat_ptr(rolecompat.hash);
66673+
66674+ role->prev = compat_ptr(rolecompat.prev);
66675+ role->next = compat_ptr(rolecompat.next);
66676+
66677+ role->transitions = compat_ptr(rolecompat.transitions);
66678+ role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
66679+ role->domain_children = compat_ptr(rolecompat.domain_children);
66680+ role->domain_child_num = rolecompat.domain_child_num;
66681+
66682+ role->umask = rolecompat.umask;
66683+
66684+ role->subj_hash = compat_ptr(rolecompat.subj_hash);
66685+ role->subj_hash_size = rolecompat.subj_hash_size;
66686+
66687+ return 0;
66688+}
66689+
66690+int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
66691+{
66692+ struct role_allowed_ip_compat roleip_compat;
66693+
66694+ if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
66695+ return -EFAULT;
66696+
66697+ roleip->addr = roleip_compat.addr;
66698+ roleip->netmask = roleip_compat.netmask;
66699+
66700+ roleip->prev = compat_ptr(roleip_compat.prev);
66701+ roleip->next = compat_ptr(roleip_compat.next);
66702+
66703+ return 0;
66704+}
66705+
66706+int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
66707+{
66708+ struct role_transition_compat trans_compat;
66709+
66710+ if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
66711+ return -EFAULT;
66712+
66713+ trans->rolename = compat_ptr(trans_compat.rolename);
66714+
66715+ trans->prev = compat_ptr(trans_compat.prev);
66716+ trans->next = compat_ptr(trans_compat.next);
66717+
66718+ return 0;
66719+
66720+}
66721+
66722+int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
66723+{
66724+ struct gr_hash_struct_compat hash_compat;
66725+
66726+ if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
66727+ return -EFAULT;
66728+
66729+ hash->table = compat_ptr(hash_compat.table);
66730+ hash->nametable = compat_ptr(hash_compat.nametable);
66731+ hash->first = compat_ptr(hash_compat.first);
66732+
66733+ hash->table_size = hash_compat.table_size;
66734+ hash->used_size = hash_compat.used_size;
66735+
66736+ hash->type = hash_compat.type;
66737+
66738+ return 0;
66739+}
66740+
66741+int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
66742+{
66743+ compat_uptr_t ptrcompat;
66744+
66745+ if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
66746+ return -EFAULT;
66747+
66748+ *(void **)ptr = compat_ptr(ptrcompat);
66749+
66750+ return 0;
66751+}
66752+
66753+int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
66754+{
66755+ struct acl_ip_label_compat ip_compat;
66756+
66757+ if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
66758+ return -EFAULT;
66759+
66760+ ip->iface = compat_ptr(ip_compat.iface);
66761+ ip->addr = ip_compat.addr;
66762+ ip->netmask = ip_compat.netmask;
66763+ ip->low = ip_compat.low;
66764+ ip->high = ip_compat.high;
66765+ ip->mode = ip_compat.mode;
66766+ ip->type = ip_compat.type;
66767+
66768+ memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
66769+
66770+ ip->prev = compat_ptr(ip_compat.prev);
66771+ ip->next = compat_ptr(ip_compat.next);
66772+
66773+ return 0;
66774+}
66775+
66776+int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
66777+{
66778+ struct sprole_pw_compat pw_compat;
66779+
66780+ if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
66781+ return -EFAULT;
66782+
66783+ pw->rolename = compat_ptr(pw_compat.rolename);
66784+ memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
66785+ memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
66786+
66787+ return 0;
66788+}
66789+
66790+size_t get_gr_arg_wrapper_size_compat(void)
66791+{
66792+ return sizeof(struct gr_arg_wrapper_compat);
66793+}
66794+
66795diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
66796new file mode 100644
66797index 0000000..a340c17
66798--- /dev/null
66799+++ b/grsecurity/gracl_fs.c
66800@@ -0,0 +1,431 @@
66801+#include <linux/kernel.h>
66802+#include <linux/sched.h>
66803+#include <linux/types.h>
66804+#include <linux/fs.h>
66805+#include <linux/file.h>
66806+#include <linux/stat.h>
66807+#include <linux/grsecurity.h>
66808+#include <linux/grinternal.h>
66809+#include <linux/gracl.h>
66810+
66811+umode_t
66812+gr_acl_umask(void)
66813+{
66814+ if (unlikely(!gr_acl_is_enabled()))
66815+ return 0;
66816+
66817+ return current->role->umask;
66818+}
66819+
66820+__u32
66821+gr_acl_handle_hidden_file(const struct dentry * dentry,
66822+ const struct vfsmount * mnt)
66823+{
66824+ __u32 mode;
66825+
66826+ if (unlikely(!dentry->d_inode))
66827+ return GR_FIND;
66828+
66829+ mode =
66830+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
66831+
66832+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
66833+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
66834+ return mode;
66835+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
66836+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
66837+ return 0;
66838+ } else if (unlikely(!(mode & GR_FIND)))
66839+ return 0;
66840+
66841+ return GR_FIND;
66842+}
66843+
66844+__u32
66845+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
66846+ int acc_mode)
66847+{
66848+ __u32 reqmode = GR_FIND;
66849+ __u32 mode;
66850+
66851+ if (unlikely(!dentry->d_inode))
66852+ return reqmode;
66853+
66854+ if (acc_mode & MAY_APPEND)
66855+ reqmode |= GR_APPEND;
66856+ else if (acc_mode & MAY_WRITE)
66857+ reqmode |= GR_WRITE;
66858+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
66859+ reqmode |= GR_READ;
66860+
66861+ mode =
66862+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
66863+ mnt);
66864+
66865+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
66866+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
66867+ reqmode & GR_READ ? " reading" : "",
66868+ reqmode & GR_WRITE ? " writing" : reqmode &
66869+ GR_APPEND ? " appending" : "");
66870+ return reqmode;
66871+ } else
66872+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
66873+ {
66874+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
66875+ reqmode & GR_READ ? " reading" : "",
66876+ reqmode & GR_WRITE ? " writing" : reqmode &
66877+ GR_APPEND ? " appending" : "");
66878+ return 0;
66879+ } else if (unlikely((mode & reqmode) != reqmode))
66880+ return 0;
66881+
66882+ return reqmode;
66883+}
66884+
66885+__u32
66886+gr_acl_handle_creat(const struct dentry * dentry,
66887+ const struct dentry * p_dentry,
66888+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
66889+ const int imode)
66890+{
66891+ __u32 reqmode = GR_WRITE | GR_CREATE;
66892+ __u32 mode;
66893+
66894+ if (acc_mode & MAY_APPEND)
66895+ reqmode |= GR_APPEND;
66896+ // if a directory was required or the directory already exists, then
66897+ // don't count this open as a read
66898+ if ((acc_mode & MAY_READ) &&
66899+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
66900+ reqmode |= GR_READ;
66901+ if ((open_flags & O_CREAT) &&
66902+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
66903+ reqmode |= GR_SETID;
66904+
66905+ mode =
66906+ gr_check_create(dentry, p_dentry, p_mnt,
66907+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
66908+
66909+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
66910+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
66911+ reqmode & GR_READ ? " reading" : "",
66912+ reqmode & GR_WRITE ? " writing" : reqmode &
66913+ GR_APPEND ? " appending" : "");
66914+ return reqmode;
66915+ } else
66916+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
66917+ {
66918+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
66919+ reqmode & GR_READ ? " reading" : "",
66920+ reqmode & GR_WRITE ? " writing" : reqmode &
66921+ GR_APPEND ? " appending" : "");
66922+ return 0;
66923+ } else if (unlikely((mode & reqmode) != reqmode))
66924+ return 0;
66925+
66926+ return reqmode;
66927+}
66928+
66929+__u32
66930+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
66931+ const int fmode)
66932+{
66933+ __u32 mode, reqmode = GR_FIND;
66934+
66935+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
66936+ reqmode |= GR_EXEC;
66937+ if (fmode & S_IWOTH)
66938+ reqmode |= GR_WRITE;
66939+ if (fmode & S_IROTH)
66940+ reqmode |= GR_READ;
66941+
66942+ mode =
66943+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
66944+ mnt);
66945+
66946+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
66947+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
66948+ reqmode & GR_READ ? " reading" : "",
66949+ reqmode & GR_WRITE ? " writing" : "",
66950+ reqmode & GR_EXEC ? " executing" : "");
66951+ return reqmode;
66952+ } else
66953+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
66954+ {
66955+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
66956+ reqmode & GR_READ ? " reading" : "",
66957+ reqmode & GR_WRITE ? " writing" : "",
66958+ reqmode & GR_EXEC ? " executing" : "");
66959+ return 0;
66960+ } else if (unlikely((mode & reqmode) != reqmode))
66961+ return 0;
66962+
66963+ return reqmode;
66964+}
66965+
66966+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
66967+{
66968+ __u32 mode;
66969+
66970+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
66971+
66972+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
66973+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
66974+ return mode;
66975+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
66976+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
66977+ return 0;
66978+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
66979+ return 0;
66980+
66981+ return (reqmode);
66982+}
66983+
66984+__u32
66985+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
66986+{
66987+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
66988+}
66989+
66990+__u32
66991+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
66992+{
66993+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
66994+}
66995+
66996+__u32
66997+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
66998+{
66999+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
67000+}
67001+
67002+__u32
67003+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
67004+{
67005+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
67006+}
67007+
67008+__u32
67009+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
67010+ umode_t *modeptr)
67011+{
67012+ umode_t mode;
67013+
67014+ *modeptr &= ~gr_acl_umask();
67015+ mode = *modeptr;
67016+
67017+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
67018+ return 1;
67019+
67020+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
67021+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
67022+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
67023+ GR_CHMOD_ACL_MSG);
67024+ } else {
67025+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
67026+ }
67027+}
67028+
67029+__u32
67030+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
67031+{
67032+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
67033+}
67034+
67035+__u32
67036+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
67037+{
67038+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
67039+}
67040+
67041+__u32
67042+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
67043+{
67044+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
67045+}
67046+
67047+__u32
67048+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
67049+{
67050+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
67051+ GR_UNIXCONNECT_ACL_MSG);
67052+}
67053+
67054+/* hardlinks require at minimum create and link permission,
67055+ any additional privilege required is based on the
67056+ privilege of the file being linked to
67057+*/
67058+__u32
67059+gr_acl_handle_link(const struct dentry * new_dentry,
67060+ const struct dentry * parent_dentry,
67061+ const struct vfsmount * parent_mnt,
67062+ const struct dentry * old_dentry,
67063+ const struct vfsmount * old_mnt, const struct filename *to)
67064+{
67065+ __u32 mode;
67066+ __u32 needmode = GR_CREATE | GR_LINK;
67067+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
67068+
67069+ mode =
67070+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
67071+ old_mnt);
67072+
67073+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
67074+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
67075+ return mode;
67076+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
67077+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
67078+ return 0;
67079+ } else if (unlikely((mode & needmode) != needmode))
67080+ return 0;
67081+
67082+ return 1;
67083+}
67084+
67085+__u32
67086+gr_acl_handle_symlink(const struct dentry * new_dentry,
67087+ const struct dentry * parent_dentry,
67088+ const struct vfsmount * parent_mnt, const struct filename *from)
67089+{
67090+ __u32 needmode = GR_WRITE | GR_CREATE;
67091+ __u32 mode;
67092+
67093+ mode =
67094+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
67095+ GR_CREATE | GR_AUDIT_CREATE |
67096+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
67097+
67098+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
67099+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
67100+ return mode;
67101+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
67102+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
67103+ return 0;
67104+ } else if (unlikely((mode & needmode) != needmode))
67105+ return 0;
67106+
67107+ return (GR_WRITE | GR_CREATE);
67108+}
67109+
67110+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)
67111+{
67112+ __u32 mode;
67113+
67114+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
67115+
67116+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
67117+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
67118+ return mode;
67119+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
67120+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
67121+ return 0;
67122+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
67123+ return 0;
67124+
67125+ return (reqmode);
67126+}
67127+
67128+__u32
67129+gr_acl_handle_mknod(const struct dentry * new_dentry,
67130+ const struct dentry * parent_dentry,
67131+ const struct vfsmount * parent_mnt,
67132+ const int mode)
67133+{
67134+ __u32 reqmode = GR_WRITE | GR_CREATE;
67135+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
67136+ reqmode |= GR_SETID;
67137+
67138+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
67139+ reqmode, GR_MKNOD_ACL_MSG);
67140+}
67141+
67142+__u32
67143+gr_acl_handle_mkdir(const struct dentry *new_dentry,
67144+ const struct dentry *parent_dentry,
67145+ const struct vfsmount *parent_mnt)
67146+{
67147+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
67148+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
67149+}
67150+
67151+#define RENAME_CHECK_SUCCESS(old, new) \
67152+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
67153+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
67154+
67155+int
67156+gr_acl_handle_rename(struct dentry *new_dentry,
67157+ struct dentry *parent_dentry,
67158+ const struct vfsmount *parent_mnt,
67159+ struct dentry *old_dentry,
67160+ struct inode *old_parent_inode,
67161+ struct vfsmount *old_mnt, const struct filename *newname)
67162+{
67163+ __u32 comp1, comp2;
67164+ int error = 0;
67165+
67166+ if (unlikely(!gr_acl_is_enabled()))
67167+ return 0;
67168+
67169+ if (!new_dentry->d_inode) {
67170+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
67171+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
67172+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
67173+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
67174+ GR_DELETE | GR_AUDIT_DELETE |
67175+ GR_AUDIT_READ | GR_AUDIT_WRITE |
67176+ GR_SUPPRESS, old_mnt);
67177+ } else {
67178+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
67179+ GR_CREATE | GR_DELETE |
67180+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
67181+ GR_AUDIT_READ | GR_AUDIT_WRITE |
67182+ GR_SUPPRESS, parent_mnt);
67183+ comp2 =
67184+ gr_search_file(old_dentry,
67185+ GR_READ | GR_WRITE | GR_AUDIT_READ |
67186+ GR_DELETE | GR_AUDIT_DELETE |
67187+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
67188+ }
67189+
67190+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
67191+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
67192+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
67193+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
67194+ && !(comp2 & GR_SUPPRESS)) {
67195+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
67196+ error = -EACCES;
67197+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
67198+ error = -EACCES;
67199+
67200+ return error;
67201+}
67202+
67203+void
67204+gr_acl_handle_exit(void)
67205+{
67206+ u16 id;
67207+ char *rolename;
67208+
67209+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
67210+ !(current->role->roletype & GR_ROLE_PERSIST))) {
67211+ id = current->acl_role_id;
67212+ rolename = current->role->rolename;
67213+ gr_set_acls(1);
67214+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
67215+ }
67216+
67217+ gr_put_exec_file(current);
67218+ return;
67219+}
67220+
67221+int
67222+gr_acl_handle_procpidmem(const struct task_struct *task)
67223+{
67224+ if (unlikely(!gr_acl_is_enabled()))
67225+ return 0;
67226+
67227+ if (task != current && task->acl->mode & GR_PROTPROCFD)
67228+ return -EACCES;
67229+
67230+ return 0;
67231+}
67232diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
67233new file mode 100644
67234index 0000000..f056b81
67235--- /dev/null
67236+++ b/grsecurity/gracl_ip.c
67237@@ -0,0 +1,386 @@
67238+#include <linux/kernel.h>
67239+#include <asm/uaccess.h>
67240+#include <asm/errno.h>
67241+#include <net/sock.h>
67242+#include <linux/file.h>
67243+#include <linux/fs.h>
67244+#include <linux/net.h>
67245+#include <linux/in.h>
67246+#include <linux/skbuff.h>
67247+#include <linux/ip.h>
67248+#include <linux/udp.h>
67249+#include <linux/types.h>
67250+#include <linux/sched.h>
67251+#include <linux/netdevice.h>
67252+#include <linux/inetdevice.h>
67253+#include <linux/gracl.h>
67254+#include <linux/grsecurity.h>
67255+#include <linux/grinternal.h>
67256+
67257+#define GR_BIND 0x01
67258+#define GR_CONNECT 0x02
67259+#define GR_INVERT 0x04
67260+#define GR_BINDOVERRIDE 0x08
67261+#define GR_CONNECTOVERRIDE 0x10
67262+#define GR_SOCK_FAMILY 0x20
67263+
67264+static const char * gr_protocols[IPPROTO_MAX] = {
67265+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
67266+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
67267+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
67268+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
67269+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
67270+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
67271+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
67272+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
67273+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
67274+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
67275+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
67276+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
67277+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
67278+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
67279+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
67280+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
67281+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
67282+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
67283+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
67284+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
67285+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
67286+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
67287+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
67288+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
67289+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
67290+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
67291+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
67292+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
67293+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
67294+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
67295+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
67296+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
67297+ };
67298+
67299+static const char * gr_socktypes[SOCK_MAX] = {
67300+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
67301+ "unknown:7", "unknown:8", "unknown:9", "packet"
67302+ };
67303+
67304+static const char * gr_sockfamilies[AF_MAX+1] = {
67305+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
67306+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
67307+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
67308+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
67309+ };
67310+
67311+const char *
67312+gr_proto_to_name(unsigned char proto)
67313+{
67314+ return gr_protocols[proto];
67315+}
67316+
67317+const char *
67318+gr_socktype_to_name(unsigned char type)
67319+{
67320+ return gr_socktypes[type];
67321+}
67322+
67323+const char *
67324+gr_sockfamily_to_name(unsigned char family)
67325+{
67326+ return gr_sockfamilies[family];
67327+}
67328+
67329+extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
67330+
67331+int
67332+gr_search_socket(const int domain, const int type, const int protocol)
67333+{
67334+ struct acl_subject_label *curr;
67335+ const struct cred *cred = current_cred();
67336+
67337+ if (unlikely(!gr_acl_is_enabled()))
67338+ goto exit;
67339+
67340+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
67341+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
67342+ goto exit; // let the kernel handle it
67343+
67344+ curr = current->acl;
67345+
67346+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
67347+ /* the family is allowed, if this is PF_INET allow it only if
67348+ the extra sock type/protocol checks pass */
67349+ if (domain == PF_INET)
67350+ goto inet_check;
67351+ goto exit;
67352+ } else {
67353+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
67354+ __u32 fakeip = 0;
67355+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67356+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67357+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67358+ gr_to_filename(current->exec_file->f_path.dentry,
67359+ current->exec_file->f_path.mnt) :
67360+ curr->filename, curr->filename,
67361+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
67362+ &current->signal->saved_ip);
67363+ goto exit;
67364+ }
67365+ goto exit_fail;
67366+ }
67367+
67368+inet_check:
67369+ /* the rest of this checking is for IPv4 only */
67370+ if (!curr->ips)
67371+ goto exit;
67372+
67373+ if ((curr->ip_type & (1U << type)) &&
67374+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
67375+ goto exit;
67376+
67377+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
67378+ /* we don't place acls on raw sockets , and sometimes
67379+ dgram/ip sockets are opened for ioctl and not
67380+ bind/connect, so we'll fake a bind learn log */
67381+ if (type == SOCK_RAW || type == SOCK_PACKET) {
67382+ __u32 fakeip = 0;
67383+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67384+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67385+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67386+ gr_to_filename(current->exec_file->f_path.dentry,
67387+ current->exec_file->f_path.mnt) :
67388+ curr->filename, curr->filename,
67389+ &fakeip, 0, type,
67390+ protocol, GR_CONNECT, &current->signal->saved_ip);
67391+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
67392+ __u32 fakeip = 0;
67393+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67394+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67395+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67396+ gr_to_filename(current->exec_file->f_path.dentry,
67397+ current->exec_file->f_path.mnt) :
67398+ curr->filename, curr->filename,
67399+ &fakeip, 0, type,
67400+ protocol, GR_BIND, &current->signal->saved_ip);
67401+ }
67402+ /* we'll log when they use connect or bind */
67403+ goto exit;
67404+ }
67405+
67406+exit_fail:
67407+ if (domain == PF_INET)
67408+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
67409+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
67410+ else if (rcu_access_pointer(net_families[domain]) != NULL)
67411+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
67412+ gr_socktype_to_name(type), protocol);
67413+
67414+ return 0;
67415+exit:
67416+ return 1;
67417+}
67418+
67419+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)
67420+{
67421+ if ((ip->mode & mode) &&
67422+ (ip_port >= ip->low) &&
67423+ (ip_port <= ip->high) &&
67424+ ((ntohl(ip_addr) & our_netmask) ==
67425+ (ntohl(our_addr) & our_netmask))
67426+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
67427+ && (ip->type & (1U << type))) {
67428+ if (ip->mode & GR_INVERT)
67429+ return 2; // specifically denied
67430+ else
67431+ return 1; // allowed
67432+ }
67433+
67434+ return 0; // not specifically allowed, may continue parsing
67435+}
67436+
67437+static int
67438+gr_search_connectbind(const int full_mode, struct sock *sk,
67439+ struct sockaddr_in *addr, const int type)
67440+{
67441+ char iface[IFNAMSIZ] = {0};
67442+ struct acl_subject_label *curr;
67443+ struct acl_ip_label *ip;
67444+ struct inet_sock *isk;
67445+ struct net_device *dev;
67446+ struct in_device *idev;
67447+ unsigned long i;
67448+ int ret;
67449+ int mode = full_mode & (GR_BIND | GR_CONNECT);
67450+ __u32 ip_addr = 0;
67451+ __u32 our_addr;
67452+ __u32 our_netmask;
67453+ char *p;
67454+ __u16 ip_port = 0;
67455+ const struct cred *cred = current_cred();
67456+
67457+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
67458+ return 0;
67459+
67460+ curr = current->acl;
67461+ isk = inet_sk(sk);
67462+
67463+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
67464+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
67465+ addr->sin_addr.s_addr = curr->inaddr_any_override;
67466+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
67467+ struct sockaddr_in saddr;
67468+ int err;
67469+
67470+ saddr.sin_family = AF_INET;
67471+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
67472+ saddr.sin_port = isk->inet_sport;
67473+
67474+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
67475+ if (err)
67476+ return err;
67477+
67478+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
67479+ if (err)
67480+ return err;
67481+ }
67482+
67483+ if (!curr->ips)
67484+ return 0;
67485+
67486+ ip_addr = addr->sin_addr.s_addr;
67487+ ip_port = ntohs(addr->sin_port);
67488+
67489+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
67490+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67491+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67492+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67493+ gr_to_filename(current->exec_file->f_path.dentry,
67494+ current->exec_file->f_path.mnt) :
67495+ curr->filename, curr->filename,
67496+ &ip_addr, ip_port, type,
67497+ sk->sk_protocol, mode, &current->signal->saved_ip);
67498+ return 0;
67499+ }
67500+
67501+ for (i = 0; i < curr->ip_num; i++) {
67502+ ip = *(curr->ips + i);
67503+ if (ip->iface != NULL) {
67504+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
67505+ p = strchr(iface, ':');
67506+ if (p != NULL)
67507+ *p = '\0';
67508+ dev = dev_get_by_name(sock_net(sk), iface);
67509+ if (dev == NULL)
67510+ continue;
67511+ idev = in_dev_get(dev);
67512+ if (idev == NULL) {
67513+ dev_put(dev);
67514+ continue;
67515+ }
67516+ rcu_read_lock();
67517+ for_ifa(idev) {
67518+ if (!strcmp(ip->iface, ifa->ifa_label)) {
67519+ our_addr = ifa->ifa_address;
67520+ our_netmask = 0xffffffff;
67521+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
67522+ if (ret == 1) {
67523+ rcu_read_unlock();
67524+ in_dev_put(idev);
67525+ dev_put(dev);
67526+ return 0;
67527+ } else if (ret == 2) {
67528+ rcu_read_unlock();
67529+ in_dev_put(idev);
67530+ dev_put(dev);
67531+ goto denied;
67532+ }
67533+ }
67534+ } endfor_ifa(idev);
67535+ rcu_read_unlock();
67536+ in_dev_put(idev);
67537+ dev_put(dev);
67538+ } else {
67539+ our_addr = ip->addr;
67540+ our_netmask = ip->netmask;
67541+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
67542+ if (ret == 1)
67543+ return 0;
67544+ else if (ret == 2)
67545+ goto denied;
67546+ }
67547+ }
67548+
67549+denied:
67550+ if (mode == GR_BIND)
67551+ 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));
67552+ else if (mode == GR_CONNECT)
67553+ 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));
67554+
67555+ return -EACCES;
67556+}
67557+
67558+int
67559+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
67560+{
67561+ /* always allow disconnection of dgram sockets with connect */
67562+ if (addr->sin_family == AF_UNSPEC)
67563+ return 0;
67564+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
67565+}
67566+
67567+int
67568+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
67569+{
67570+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
67571+}
67572+
67573+int gr_search_listen(struct socket *sock)
67574+{
67575+ struct sock *sk = sock->sk;
67576+ struct sockaddr_in addr;
67577+
67578+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
67579+ addr.sin_port = inet_sk(sk)->inet_sport;
67580+
67581+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
67582+}
67583+
67584+int gr_search_accept(struct socket *sock)
67585+{
67586+ struct sock *sk = sock->sk;
67587+ struct sockaddr_in addr;
67588+
67589+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
67590+ addr.sin_port = inet_sk(sk)->inet_sport;
67591+
67592+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
67593+}
67594+
67595+int
67596+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
67597+{
67598+ if (addr)
67599+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
67600+ else {
67601+ struct sockaddr_in sin;
67602+ const struct inet_sock *inet = inet_sk(sk);
67603+
67604+ sin.sin_addr.s_addr = inet->inet_daddr;
67605+ sin.sin_port = inet->inet_dport;
67606+
67607+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
67608+ }
67609+}
67610+
67611+int
67612+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
67613+{
67614+ struct sockaddr_in sin;
67615+
67616+ if (unlikely(skb->len < sizeof (struct udphdr)))
67617+ return 0; // skip this packet
67618+
67619+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
67620+ sin.sin_port = udp_hdr(skb)->source;
67621+
67622+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
67623+}
67624diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
67625new file mode 100644
67626index 0000000..25f54ef
67627--- /dev/null
67628+++ b/grsecurity/gracl_learn.c
67629@@ -0,0 +1,207 @@
67630+#include <linux/kernel.h>
67631+#include <linux/mm.h>
67632+#include <linux/sched.h>
67633+#include <linux/poll.h>
67634+#include <linux/string.h>
67635+#include <linux/file.h>
67636+#include <linux/types.h>
67637+#include <linux/vmalloc.h>
67638+#include <linux/grinternal.h>
67639+
67640+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
67641+ size_t count, loff_t *ppos);
67642+extern int gr_acl_is_enabled(void);
67643+
67644+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
67645+static int gr_learn_attached;
67646+
67647+/* use a 512k buffer */
67648+#define LEARN_BUFFER_SIZE (512 * 1024)
67649+
67650+static DEFINE_SPINLOCK(gr_learn_lock);
67651+static DEFINE_MUTEX(gr_learn_user_mutex);
67652+
67653+/* we need to maintain two buffers, so that the kernel context of grlearn
67654+ uses a semaphore around the userspace copying, and the other kernel contexts
67655+ use a spinlock when copying into the buffer, since they cannot sleep
67656+*/
67657+static char *learn_buffer;
67658+static char *learn_buffer_user;
67659+static int learn_buffer_len;
67660+static int learn_buffer_user_len;
67661+
67662+static ssize_t
67663+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
67664+{
67665+ DECLARE_WAITQUEUE(wait, current);
67666+ ssize_t retval = 0;
67667+
67668+ add_wait_queue(&learn_wait, &wait);
67669+ set_current_state(TASK_INTERRUPTIBLE);
67670+ do {
67671+ mutex_lock(&gr_learn_user_mutex);
67672+ spin_lock(&gr_learn_lock);
67673+ if (learn_buffer_len)
67674+ break;
67675+ spin_unlock(&gr_learn_lock);
67676+ mutex_unlock(&gr_learn_user_mutex);
67677+ if (file->f_flags & O_NONBLOCK) {
67678+ retval = -EAGAIN;
67679+ goto out;
67680+ }
67681+ if (signal_pending(current)) {
67682+ retval = -ERESTARTSYS;
67683+ goto out;
67684+ }
67685+
67686+ schedule();
67687+ } while (1);
67688+
67689+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
67690+ learn_buffer_user_len = learn_buffer_len;
67691+ retval = learn_buffer_len;
67692+ learn_buffer_len = 0;
67693+
67694+ spin_unlock(&gr_learn_lock);
67695+
67696+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
67697+ retval = -EFAULT;
67698+
67699+ mutex_unlock(&gr_learn_user_mutex);
67700+out:
67701+ set_current_state(TASK_RUNNING);
67702+ remove_wait_queue(&learn_wait, &wait);
67703+ return retval;
67704+}
67705+
67706+static unsigned int
67707+poll_learn(struct file * file, poll_table * wait)
67708+{
67709+ poll_wait(file, &learn_wait, wait);
67710+
67711+ if (learn_buffer_len)
67712+ return (POLLIN | POLLRDNORM);
67713+
67714+ return 0;
67715+}
67716+
67717+void
67718+gr_clear_learn_entries(void)
67719+{
67720+ char *tmp;
67721+
67722+ mutex_lock(&gr_learn_user_mutex);
67723+ spin_lock(&gr_learn_lock);
67724+ tmp = learn_buffer;
67725+ learn_buffer = NULL;
67726+ spin_unlock(&gr_learn_lock);
67727+ if (tmp)
67728+ vfree(tmp);
67729+ if (learn_buffer_user != NULL) {
67730+ vfree(learn_buffer_user);
67731+ learn_buffer_user = NULL;
67732+ }
67733+ learn_buffer_len = 0;
67734+ mutex_unlock(&gr_learn_user_mutex);
67735+
67736+ return;
67737+}
67738+
67739+void
67740+gr_add_learn_entry(const char *fmt, ...)
67741+{
67742+ va_list args;
67743+ unsigned int len;
67744+
67745+ if (!gr_learn_attached)
67746+ return;
67747+
67748+ spin_lock(&gr_learn_lock);
67749+
67750+ /* leave a gap at the end so we know when it's "full" but don't have to
67751+ compute the exact length of the string we're trying to append
67752+ */
67753+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
67754+ spin_unlock(&gr_learn_lock);
67755+ wake_up_interruptible(&learn_wait);
67756+ return;
67757+ }
67758+ if (learn_buffer == NULL) {
67759+ spin_unlock(&gr_learn_lock);
67760+ return;
67761+ }
67762+
67763+ va_start(args, fmt);
67764+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
67765+ va_end(args);
67766+
67767+ learn_buffer_len += len + 1;
67768+
67769+ spin_unlock(&gr_learn_lock);
67770+ wake_up_interruptible(&learn_wait);
67771+
67772+ return;
67773+}
67774+
67775+static int
67776+open_learn(struct inode *inode, struct file *file)
67777+{
67778+ if (file->f_mode & FMODE_READ && gr_learn_attached)
67779+ return -EBUSY;
67780+ if (file->f_mode & FMODE_READ) {
67781+ int retval = 0;
67782+ mutex_lock(&gr_learn_user_mutex);
67783+ if (learn_buffer == NULL)
67784+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
67785+ if (learn_buffer_user == NULL)
67786+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
67787+ if (learn_buffer == NULL) {
67788+ retval = -ENOMEM;
67789+ goto out_error;
67790+ }
67791+ if (learn_buffer_user == NULL) {
67792+ retval = -ENOMEM;
67793+ goto out_error;
67794+ }
67795+ learn_buffer_len = 0;
67796+ learn_buffer_user_len = 0;
67797+ gr_learn_attached = 1;
67798+out_error:
67799+ mutex_unlock(&gr_learn_user_mutex);
67800+ return retval;
67801+ }
67802+ return 0;
67803+}
67804+
67805+static int
67806+close_learn(struct inode *inode, struct file *file)
67807+{
67808+ if (file->f_mode & FMODE_READ) {
67809+ char *tmp = NULL;
67810+ mutex_lock(&gr_learn_user_mutex);
67811+ spin_lock(&gr_learn_lock);
67812+ tmp = learn_buffer;
67813+ learn_buffer = NULL;
67814+ spin_unlock(&gr_learn_lock);
67815+ if (tmp)
67816+ vfree(tmp);
67817+ if (learn_buffer_user != NULL) {
67818+ vfree(learn_buffer_user);
67819+ learn_buffer_user = NULL;
67820+ }
67821+ learn_buffer_len = 0;
67822+ learn_buffer_user_len = 0;
67823+ gr_learn_attached = 0;
67824+ mutex_unlock(&gr_learn_user_mutex);
67825+ }
67826+
67827+ return 0;
67828+}
67829+
67830+const struct file_operations grsec_fops = {
67831+ .read = read_learn,
67832+ .write = write_grsec_handler,
67833+ .open = open_learn,
67834+ .release = close_learn,
67835+ .poll = poll_learn,
67836+};
67837diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
67838new file mode 100644
67839index 0000000..39645c9
67840--- /dev/null
67841+++ b/grsecurity/gracl_res.c
67842@@ -0,0 +1,68 @@
67843+#include <linux/kernel.h>
67844+#include <linux/sched.h>
67845+#include <linux/gracl.h>
67846+#include <linux/grinternal.h>
67847+
67848+static const char *restab_log[] = {
67849+ [RLIMIT_CPU] = "RLIMIT_CPU",
67850+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
67851+ [RLIMIT_DATA] = "RLIMIT_DATA",
67852+ [RLIMIT_STACK] = "RLIMIT_STACK",
67853+ [RLIMIT_CORE] = "RLIMIT_CORE",
67854+ [RLIMIT_RSS] = "RLIMIT_RSS",
67855+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
67856+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
67857+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
67858+ [RLIMIT_AS] = "RLIMIT_AS",
67859+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
67860+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
67861+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
67862+ [RLIMIT_NICE] = "RLIMIT_NICE",
67863+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
67864+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
67865+ [GR_CRASH_RES] = "RLIMIT_CRASH"
67866+};
67867+
67868+void
67869+gr_log_resource(const struct task_struct *task,
67870+ const int res, const unsigned long wanted, const int gt)
67871+{
67872+ const struct cred *cred;
67873+ unsigned long rlim;
67874+
67875+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
67876+ return;
67877+
67878+ // not yet supported resource
67879+ if (unlikely(!restab_log[res]))
67880+ return;
67881+
67882+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
67883+ rlim = task_rlimit_max(task, res);
67884+ else
67885+ rlim = task_rlimit(task, res);
67886+
67887+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
67888+ return;
67889+
67890+ rcu_read_lock();
67891+ cred = __task_cred(task);
67892+
67893+ if (res == RLIMIT_NPROC &&
67894+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
67895+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
67896+ goto out_rcu_unlock;
67897+ else if (res == RLIMIT_MEMLOCK &&
67898+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
67899+ goto out_rcu_unlock;
67900+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
67901+ goto out_rcu_unlock;
67902+ rcu_read_unlock();
67903+
67904+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
67905+
67906+ return;
67907+out_rcu_unlock:
67908+ rcu_read_unlock();
67909+ return;
67910+}
67911diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
67912new file mode 100644
67913index 0000000..3c38bfe
67914--- /dev/null
67915+++ b/grsecurity/gracl_segv.c
67916@@ -0,0 +1,305 @@
67917+#include <linux/kernel.h>
67918+#include <linux/mm.h>
67919+#include <asm/uaccess.h>
67920+#include <asm/errno.h>
67921+#include <asm/mman.h>
67922+#include <net/sock.h>
67923+#include <linux/file.h>
67924+#include <linux/fs.h>
67925+#include <linux/net.h>
67926+#include <linux/in.h>
67927+#include <linux/slab.h>
67928+#include <linux/types.h>
67929+#include <linux/sched.h>
67930+#include <linux/timer.h>
67931+#include <linux/gracl.h>
67932+#include <linux/grsecurity.h>
67933+#include <linux/grinternal.h>
67934+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
67935+#include <linux/magic.h>
67936+#include <linux/pagemap.h>
67937+#include "../fs/btrfs/async-thread.h"
67938+#include "../fs/btrfs/ctree.h"
67939+#include "../fs/btrfs/btrfs_inode.h"
67940+#endif
67941+
67942+static struct crash_uid *uid_set;
67943+static unsigned short uid_used;
67944+static DEFINE_SPINLOCK(gr_uid_lock);
67945+extern rwlock_t gr_inode_lock;
67946+extern struct acl_subject_label *
67947+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
67948+ struct acl_role_label *role);
67949+
67950+static inline dev_t __get_dev(const struct dentry *dentry)
67951+{
67952+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
67953+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
67954+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
67955+ else
67956+#endif
67957+ return dentry->d_sb->s_dev;
67958+}
67959+
67960+int
67961+gr_init_uidset(void)
67962+{
67963+ uid_set =
67964+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
67965+ uid_used = 0;
67966+
67967+ return uid_set ? 1 : 0;
67968+}
67969+
67970+void
67971+gr_free_uidset(void)
67972+{
67973+ if (uid_set)
67974+ kfree(uid_set);
67975+
67976+ return;
67977+}
67978+
67979+int
67980+gr_find_uid(const uid_t uid)
67981+{
67982+ struct crash_uid *tmp = uid_set;
67983+ uid_t buid;
67984+ int low = 0, high = uid_used - 1, mid;
67985+
67986+ while (high >= low) {
67987+ mid = (low + high) >> 1;
67988+ buid = tmp[mid].uid;
67989+ if (buid == uid)
67990+ return mid;
67991+ if (buid > uid)
67992+ high = mid - 1;
67993+ if (buid < uid)
67994+ low = mid + 1;
67995+ }
67996+
67997+ return -1;
67998+}
67999+
68000+static __inline__ void
68001+gr_insertsort(void)
68002+{
68003+ unsigned short i, j;
68004+ struct crash_uid index;
68005+
68006+ for (i = 1; i < uid_used; i++) {
68007+ index = uid_set[i];
68008+ j = i;
68009+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
68010+ uid_set[j] = uid_set[j - 1];
68011+ j--;
68012+ }
68013+ uid_set[j] = index;
68014+ }
68015+
68016+ return;
68017+}
68018+
68019+static __inline__ void
68020+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
68021+{
68022+ int loc;
68023+ uid_t uid = GR_GLOBAL_UID(kuid);
68024+
68025+ if (uid_used == GR_UIDTABLE_MAX)
68026+ return;
68027+
68028+ loc = gr_find_uid(uid);
68029+
68030+ if (loc >= 0) {
68031+ uid_set[loc].expires = expires;
68032+ return;
68033+ }
68034+
68035+ uid_set[uid_used].uid = uid;
68036+ uid_set[uid_used].expires = expires;
68037+ uid_used++;
68038+
68039+ gr_insertsort();
68040+
68041+ return;
68042+}
68043+
68044+void
68045+gr_remove_uid(const unsigned short loc)
68046+{
68047+ unsigned short i;
68048+
68049+ for (i = loc + 1; i < uid_used; i++)
68050+ uid_set[i - 1] = uid_set[i];
68051+
68052+ uid_used--;
68053+
68054+ return;
68055+}
68056+
68057+int
68058+gr_check_crash_uid(const kuid_t kuid)
68059+{
68060+ int loc;
68061+ int ret = 0;
68062+ uid_t uid;
68063+
68064+ if (unlikely(!gr_acl_is_enabled()))
68065+ return 0;
68066+
68067+ uid = GR_GLOBAL_UID(kuid);
68068+
68069+ spin_lock(&gr_uid_lock);
68070+ loc = gr_find_uid(uid);
68071+
68072+ if (loc < 0)
68073+ goto out_unlock;
68074+
68075+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
68076+ gr_remove_uid(loc);
68077+ else
68078+ ret = 1;
68079+
68080+out_unlock:
68081+ spin_unlock(&gr_uid_lock);
68082+ return ret;
68083+}
68084+
68085+static __inline__ int
68086+proc_is_setxid(const struct cred *cred)
68087+{
68088+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
68089+ !uid_eq(cred->uid, cred->fsuid))
68090+ return 1;
68091+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
68092+ !gid_eq(cred->gid, cred->fsgid))
68093+ return 1;
68094+
68095+ return 0;
68096+}
68097+
68098+extern int gr_fake_force_sig(int sig, struct task_struct *t);
68099+
68100+void
68101+gr_handle_crash(struct task_struct *task, const int sig)
68102+{
68103+ struct acl_subject_label *curr;
68104+ struct task_struct *tsk, *tsk2;
68105+ const struct cred *cred;
68106+ const struct cred *cred2;
68107+
68108+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
68109+ return;
68110+
68111+ if (unlikely(!gr_acl_is_enabled()))
68112+ return;
68113+
68114+ curr = task->acl;
68115+
68116+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
68117+ return;
68118+
68119+ if (time_before_eq(curr->expires, get_seconds())) {
68120+ curr->expires = 0;
68121+ curr->crashes = 0;
68122+ }
68123+
68124+ curr->crashes++;
68125+
68126+ if (!curr->expires)
68127+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
68128+
68129+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
68130+ time_after(curr->expires, get_seconds())) {
68131+ rcu_read_lock();
68132+ cred = __task_cred(task);
68133+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
68134+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
68135+ spin_lock(&gr_uid_lock);
68136+ gr_insert_uid(cred->uid, curr->expires);
68137+ spin_unlock(&gr_uid_lock);
68138+ curr->expires = 0;
68139+ curr->crashes = 0;
68140+ read_lock(&tasklist_lock);
68141+ do_each_thread(tsk2, tsk) {
68142+ cred2 = __task_cred(tsk);
68143+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
68144+ gr_fake_force_sig(SIGKILL, tsk);
68145+ } while_each_thread(tsk2, tsk);
68146+ read_unlock(&tasklist_lock);
68147+ } else {
68148+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
68149+ read_lock(&tasklist_lock);
68150+ read_lock(&grsec_exec_file_lock);
68151+ do_each_thread(tsk2, tsk) {
68152+ if (likely(tsk != task)) {
68153+ // if this thread has the same subject as the one that triggered
68154+ // RES_CRASH and it's the same binary, kill it
68155+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
68156+ gr_fake_force_sig(SIGKILL, tsk);
68157+ }
68158+ } while_each_thread(tsk2, tsk);
68159+ read_unlock(&grsec_exec_file_lock);
68160+ read_unlock(&tasklist_lock);
68161+ }
68162+ rcu_read_unlock();
68163+ }
68164+
68165+ return;
68166+}
68167+
68168+int
68169+gr_check_crash_exec(const struct file *filp)
68170+{
68171+ struct acl_subject_label *curr;
68172+
68173+ if (unlikely(!gr_acl_is_enabled()))
68174+ return 0;
68175+
68176+ read_lock(&gr_inode_lock);
68177+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
68178+ __get_dev(filp->f_path.dentry),
68179+ current->role);
68180+ read_unlock(&gr_inode_lock);
68181+
68182+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
68183+ (!curr->crashes && !curr->expires))
68184+ return 0;
68185+
68186+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
68187+ time_after(curr->expires, get_seconds()))
68188+ return 1;
68189+ else if (time_before_eq(curr->expires, get_seconds())) {
68190+ curr->crashes = 0;
68191+ curr->expires = 0;
68192+ }
68193+
68194+ return 0;
68195+}
68196+
68197+void
68198+gr_handle_alertkill(struct task_struct *task)
68199+{
68200+ struct acl_subject_label *curracl;
68201+ __u32 curr_ip;
68202+ struct task_struct *p, *p2;
68203+
68204+ if (unlikely(!gr_acl_is_enabled()))
68205+ return;
68206+
68207+ curracl = task->acl;
68208+ curr_ip = task->signal->curr_ip;
68209+
68210+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
68211+ read_lock(&tasklist_lock);
68212+ do_each_thread(p2, p) {
68213+ if (p->signal->curr_ip == curr_ip)
68214+ gr_fake_force_sig(SIGKILL, p);
68215+ } while_each_thread(p2, p);
68216+ read_unlock(&tasklist_lock);
68217+ } else if (curracl->mode & GR_KILLPROC)
68218+ gr_fake_force_sig(SIGKILL, task);
68219+
68220+ return;
68221+}
68222diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
68223new file mode 100644
68224index 0000000..98011b0
68225--- /dev/null
68226+++ b/grsecurity/gracl_shm.c
68227@@ -0,0 +1,40 @@
68228+#include <linux/kernel.h>
68229+#include <linux/mm.h>
68230+#include <linux/sched.h>
68231+#include <linux/file.h>
68232+#include <linux/ipc.h>
68233+#include <linux/gracl.h>
68234+#include <linux/grsecurity.h>
68235+#include <linux/grinternal.h>
68236+
68237+int
68238+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68239+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
68240+{
68241+ struct task_struct *task;
68242+
68243+ if (!gr_acl_is_enabled())
68244+ return 1;
68245+
68246+ rcu_read_lock();
68247+ read_lock(&tasklist_lock);
68248+
68249+ task = find_task_by_vpid(shm_cprid);
68250+
68251+ if (unlikely(!task))
68252+ task = find_task_by_vpid(shm_lapid);
68253+
68254+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
68255+ (task_pid_nr(task) == shm_lapid)) &&
68256+ (task->acl->mode & GR_PROTSHM) &&
68257+ (task->acl != current->acl))) {
68258+ read_unlock(&tasklist_lock);
68259+ rcu_read_unlock();
68260+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
68261+ return 0;
68262+ }
68263+ read_unlock(&tasklist_lock);
68264+ rcu_read_unlock();
68265+
68266+ return 1;
68267+}
68268diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
68269new file mode 100644
68270index 0000000..bc0be01
68271--- /dev/null
68272+++ b/grsecurity/grsec_chdir.c
68273@@ -0,0 +1,19 @@
68274+#include <linux/kernel.h>
68275+#include <linux/sched.h>
68276+#include <linux/fs.h>
68277+#include <linux/file.h>
68278+#include <linux/grsecurity.h>
68279+#include <linux/grinternal.h>
68280+
68281+void
68282+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
68283+{
68284+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
68285+ if ((grsec_enable_chdir && grsec_enable_group &&
68286+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
68287+ !grsec_enable_group)) {
68288+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
68289+ }
68290+#endif
68291+ return;
68292+}
68293diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
68294new file mode 100644
68295index 0000000..bd6e105
68296--- /dev/null
68297+++ b/grsecurity/grsec_chroot.c
68298@@ -0,0 +1,370 @@
68299+#include <linux/kernel.h>
68300+#include <linux/module.h>
68301+#include <linux/sched.h>
68302+#include <linux/file.h>
68303+#include <linux/fs.h>
68304+#include <linux/mount.h>
68305+#include <linux/types.h>
68306+#include "../fs/mount.h"
68307+#include <linux/grsecurity.h>
68308+#include <linux/grinternal.h>
68309+
68310+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
68311+static int gr_init_ran;
68312+#endif
68313+
68314+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
68315+{
68316+#ifdef CONFIG_GRKERNSEC
68317+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
68318+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
68319+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
68320+ && gr_init_ran
68321+#endif
68322+ )
68323+ task->gr_is_chrooted = 1;
68324+ else {
68325+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
68326+ if (task_pid_nr(task) == 1 && !gr_init_ran)
68327+ gr_init_ran = 1;
68328+#endif
68329+ task->gr_is_chrooted = 0;
68330+ }
68331+
68332+ task->gr_chroot_dentry = path->dentry;
68333+#endif
68334+ return;
68335+}
68336+
68337+void gr_clear_chroot_entries(struct task_struct *task)
68338+{
68339+#ifdef CONFIG_GRKERNSEC
68340+ task->gr_is_chrooted = 0;
68341+ task->gr_chroot_dentry = NULL;
68342+#endif
68343+ return;
68344+}
68345+
68346+int
68347+gr_handle_chroot_unix(const pid_t pid)
68348+{
68349+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
68350+ struct task_struct *p;
68351+
68352+ if (unlikely(!grsec_enable_chroot_unix))
68353+ return 1;
68354+
68355+ if (likely(!proc_is_chrooted(current)))
68356+ return 1;
68357+
68358+ rcu_read_lock();
68359+ read_lock(&tasklist_lock);
68360+ p = find_task_by_vpid_unrestricted(pid);
68361+ if (unlikely(p && !have_same_root(current, p))) {
68362+ read_unlock(&tasklist_lock);
68363+ rcu_read_unlock();
68364+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
68365+ return 0;
68366+ }
68367+ read_unlock(&tasklist_lock);
68368+ rcu_read_unlock();
68369+#endif
68370+ return 1;
68371+}
68372+
68373+int
68374+gr_handle_chroot_nice(void)
68375+{
68376+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
68377+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
68378+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
68379+ return -EPERM;
68380+ }
68381+#endif
68382+ return 0;
68383+}
68384+
68385+int
68386+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
68387+{
68388+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
68389+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
68390+ && proc_is_chrooted(current)) {
68391+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
68392+ return -EACCES;
68393+ }
68394+#endif
68395+ return 0;
68396+}
68397+
68398+int
68399+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
68400+{
68401+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68402+ struct task_struct *p;
68403+ int ret = 0;
68404+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
68405+ return ret;
68406+
68407+ read_lock(&tasklist_lock);
68408+ do_each_pid_task(pid, type, p) {
68409+ if (!have_same_root(current, p)) {
68410+ ret = 1;
68411+ goto out;
68412+ }
68413+ } while_each_pid_task(pid, type, p);
68414+out:
68415+ read_unlock(&tasklist_lock);
68416+ return ret;
68417+#endif
68418+ return 0;
68419+}
68420+
68421+int
68422+gr_pid_is_chrooted(struct task_struct *p)
68423+{
68424+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68425+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
68426+ return 0;
68427+
68428+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
68429+ !have_same_root(current, p)) {
68430+ return 1;
68431+ }
68432+#endif
68433+ return 0;
68434+}
68435+
68436+EXPORT_SYMBOL(gr_pid_is_chrooted);
68437+
68438+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
68439+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
68440+{
68441+ struct path path, currentroot;
68442+ int ret = 0;
68443+
68444+ path.dentry = (struct dentry *)u_dentry;
68445+ path.mnt = (struct vfsmount *)u_mnt;
68446+ get_fs_root(current->fs, &currentroot);
68447+ if (path_is_under(&path, &currentroot))
68448+ ret = 1;
68449+ path_put(&currentroot);
68450+
68451+ return ret;
68452+}
68453+#endif
68454+
68455+int
68456+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
68457+{
68458+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
68459+ if (!grsec_enable_chroot_fchdir)
68460+ return 1;
68461+
68462+ if (!proc_is_chrooted(current))
68463+ return 1;
68464+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
68465+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
68466+ return 0;
68467+ }
68468+#endif
68469+ return 1;
68470+}
68471+
68472+int
68473+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68474+ const time_t shm_createtime)
68475+{
68476+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
68477+ struct task_struct *p;
68478+ time_t starttime;
68479+
68480+ if (unlikely(!grsec_enable_chroot_shmat))
68481+ return 1;
68482+
68483+ if (likely(!proc_is_chrooted(current)))
68484+ return 1;
68485+
68486+ rcu_read_lock();
68487+ read_lock(&tasklist_lock);
68488+
68489+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
68490+ starttime = p->start_time.tv_sec;
68491+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
68492+ if (have_same_root(current, p)) {
68493+ goto allow;
68494+ } else {
68495+ read_unlock(&tasklist_lock);
68496+ rcu_read_unlock();
68497+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
68498+ return 0;
68499+ }
68500+ }
68501+ /* creator exited, pid reuse, fall through to next check */
68502+ }
68503+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
68504+ if (unlikely(!have_same_root(current, p))) {
68505+ read_unlock(&tasklist_lock);
68506+ rcu_read_unlock();
68507+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
68508+ return 0;
68509+ }
68510+ }
68511+
68512+allow:
68513+ read_unlock(&tasklist_lock);
68514+ rcu_read_unlock();
68515+#endif
68516+ return 1;
68517+}
68518+
68519+void
68520+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
68521+{
68522+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
68523+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
68524+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
68525+#endif
68526+ return;
68527+}
68528+
68529+int
68530+gr_handle_chroot_mknod(const struct dentry *dentry,
68531+ const struct vfsmount *mnt, const int mode)
68532+{
68533+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
68534+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
68535+ proc_is_chrooted(current)) {
68536+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
68537+ return -EPERM;
68538+ }
68539+#endif
68540+ return 0;
68541+}
68542+
68543+int
68544+gr_handle_chroot_mount(const struct dentry *dentry,
68545+ const struct vfsmount *mnt, const char *dev_name)
68546+{
68547+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
68548+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
68549+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
68550+ return -EPERM;
68551+ }
68552+#endif
68553+ return 0;
68554+}
68555+
68556+int
68557+gr_handle_chroot_pivot(void)
68558+{
68559+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
68560+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
68561+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
68562+ return -EPERM;
68563+ }
68564+#endif
68565+ return 0;
68566+}
68567+
68568+int
68569+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
68570+{
68571+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
68572+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
68573+ !gr_is_outside_chroot(dentry, mnt)) {
68574+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
68575+ return -EPERM;
68576+ }
68577+#endif
68578+ return 0;
68579+}
68580+
68581+extern const char *captab_log[];
68582+extern int captab_log_entries;
68583+
68584+int
68585+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
68586+{
68587+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68588+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
68589+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
68590+ if (cap_raised(chroot_caps, cap)) {
68591+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
68592+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
68593+ }
68594+ return 0;
68595+ }
68596+ }
68597+#endif
68598+ return 1;
68599+}
68600+
68601+int
68602+gr_chroot_is_capable(const int cap)
68603+{
68604+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68605+ return gr_task_chroot_is_capable(current, current_cred(), cap);
68606+#endif
68607+ return 1;
68608+}
68609+
68610+int
68611+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
68612+{
68613+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68614+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
68615+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
68616+ if (cap_raised(chroot_caps, cap)) {
68617+ return 0;
68618+ }
68619+ }
68620+#endif
68621+ return 1;
68622+}
68623+
68624+int
68625+gr_chroot_is_capable_nolog(const int cap)
68626+{
68627+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68628+ return gr_task_chroot_is_capable_nolog(current, cap);
68629+#endif
68630+ return 1;
68631+}
68632+
68633+int
68634+gr_handle_chroot_sysctl(const int op)
68635+{
68636+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
68637+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
68638+ proc_is_chrooted(current))
68639+ return -EACCES;
68640+#endif
68641+ return 0;
68642+}
68643+
68644+void
68645+gr_handle_chroot_chdir(const struct path *path)
68646+{
68647+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
68648+ if (grsec_enable_chroot_chdir)
68649+ set_fs_pwd(current->fs, path);
68650+#endif
68651+ return;
68652+}
68653+
68654+int
68655+gr_handle_chroot_chmod(const struct dentry *dentry,
68656+ const struct vfsmount *mnt, const int mode)
68657+{
68658+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
68659+ /* allow chmod +s on directories, but not files */
68660+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
68661+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
68662+ proc_is_chrooted(current)) {
68663+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
68664+ return -EPERM;
68665+ }
68666+#endif
68667+ return 0;
68668+}
68669diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
68670new file mode 100644
68671index 0000000..ce65ceb
68672--- /dev/null
68673+++ b/grsecurity/grsec_disabled.c
68674@@ -0,0 +1,434 @@
68675+#include <linux/kernel.h>
68676+#include <linux/module.h>
68677+#include <linux/sched.h>
68678+#include <linux/file.h>
68679+#include <linux/fs.h>
68680+#include <linux/kdev_t.h>
68681+#include <linux/net.h>
68682+#include <linux/in.h>
68683+#include <linux/ip.h>
68684+#include <linux/skbuff.h>
68685+#include <linux/sysctl.h>
68686+
68687+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
68688+void
68689+pax_set_initial_flags(struct linux_binprm *bprm)
68690+{
68691+ return;
68692+}
68693+#endif
68694+
68695+#ifdef CONFIG_SYSCTL
68696+__u32
68697+gr_handle_sysctl(const struct ctl_table * table, const int op)
68698+{
68699+ return 0;
68700+}
68701+#endif
68702+
68703+#ifdef CONFIG_TASKSTATS
68704+int gr_is_taskstats_denied(int pid)
68705+{
68706+ return 0;
68707+}
68708+#endif
68709+
68710+int
68711+gr_acl_is_enabled(void)
68712+{
68713+ return 0;
68714+}
68715+
68716+void
68717+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
68718+{
68719+ return;
68720+}
68721+
68722+int
68723+gr_handle_rawio(const struct inode *inode)
68724+{
68725+ return 0;
68726+}
68727+
68728+void
68729+gr_acl_handle_psacct(struct task_struct *task, const long code)
68730+{
68731+ return;
68732+}
68733+
68734+int
68735+gr_handle_ptrace(struct task_struct *task, const long request)
68736+{
68737+ return 0;
68738+}
68739+
68740+int
68741+gr_handle_proc_ptrace(struct task_struct *task)
68742+{
68743+ return 0;
68744+}
68745+
68746+int
68747+gr_set_acls(const int type)
68748+{
68749+ return 0;
68750+}
68751+
68752+int
68753+gr_check_hidden_task(const struct task_struct *tsk)
68754+{
68755+ return 0;
68756+}
68757+
68758+int
68759+gr_check_protected_task(const struct task_struct *task)
68760+{
68761+ return 0;
68762+}
68763+
68764+int
68765+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
68766+{
68767+ return 0;
68768+}
68769+
68770+void
68771+gr_copy_label(struct task_struct *tsk)
68772+{
68773+ return;
68774+}
68775+
68776+void
68777+gr_set_pax_flags(struct task_struct *task)
68778+{
68779+ return;
68780+}
68781+
68782+int
68783+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
68784+ const int unsafe_share)
68785+{
68786+ return 0;
68787+}
68788+
68789+void
68790+gr_handle_delete(const ino_t ino, const dev_t dev)
68791+{
68792+ return;
68793+}
68794+
68795+void
68796+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
68797+{
68798+ return;
68799+}
68800+
68801+void
68802+gr_handle_crash(struct task_struct *task, const int sig)
68803+{
68804+ return;
68805+}
68806+
68807+int
68808+gr_check_crash_exec(const struct file *filp)
68809+{
68810+ return 0;
68811+}
68812+
68813+int
68814+gr_check_crash_uid(const kuid_t uid)
68815+{
68816+ return 0;
68817+}
68818+
68819+void
68820+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
68821+ struct dentry *old_dentry,
68822+ struct dentry *new_dentry,
68823+ struct vfsmount *mnt, const __u8 replace)
68824+{
68825+ return;
68826+}
68827+
68828+int
68829+gr_search_socket(const int family, const int type, const int protocol)
68830+{
68831+ return 1;
68832+}
68833+
68834+int
68835+gr_search_connectbind(const int mode, const struct socket *sock,
68836+ const struct sockaddr_in *addr)
68837+{
68838+ return 0;
68839+}
68840+
68841+void
68842+gr_handle_alertkill(struct task_struct *task)
68843+{
68844+ return;
68845+}
68846+
68847+__u32
68848+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
68849+{
68850+ return 1;
68851+}
68852+
68853+__u32
68854+gr_acl_handle_hidden_file(const struct dentry * dentry,
68855+ const struct vfsmount * mnt)
68856+{
68857+ return 1;
68858+}
68859+
68860+__u32
68861+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
68862+ int acc_mode)
68863+{
68864+ return 1;
68865+}
68866+
68867+__u32
68868+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
68869+{
68870+ return 1;
68871+}
68872+
68873+__u32
68874+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
68875+{
68876+ return 1;
68877+}
68878+
68879+int
68880+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
68881+ unsigned int *vm_flags)
68882+{
68883+ return 1;
68884+}
68885+
68886+__u32
68887+gr_acl_handle_truncate(const struct dentry * dentry,
68888+ const struct vfsmount * mnt)
68889+{
68890+ return 1;
68891+}
68892+
68893+__u32
68894+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
68895+{
68896+ return 1;
68897+}
68898+
68899+__u32
68900+gr_acl_handle_access(const struct dentry * dentry,
68901+ const struct vfsmount * mnt, const int fmode)
68902+{
68903+ return 1;
68904+}
68905+
68906+__u32
68907+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
68908+ umode_t *mode)
68909+{
68910+ return 1;
68911+}
68912+
68913+__u32
68914+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
68915+{
68916+ return 1;
68917+}
68918+
68919+__u32
68920+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
68921+{
68922+ return 1;
68923+}
68924+
68925+void
68926+grsecurity_init(void)
68927+{
68928+ return;
68929+}
68930+
68931+umode_t gr_acl_umask(void)
68932+{
68933+ return 0;
68934+}
68935+
68936+__u32
68937+gr_acl_handle_mknod(const struct dentry * new_dentry,
68938+ const struct dentry * parent_dentry,
68939+ const struct vfsmount * parent_mnt,
68940+ const int mode)
68941+{
68942+ return 1;
68943+}
68944+
68945+__u32
68946+gr_acl_handle_mkdir(const struct dentry * new_dentry,
68947+ const struct dentry * parent_dentry,
68948+ const struct vfsmount * parent_mnt)
68949+{
68950+ return 1;
68951+}
68952+
68953+__u32
68954+gr_acl_handle_symlink(const struct dentry * new_dentry,
68955+ const struct dentry * parent_dentry,
68956+ const struct vfsmount * parent_mnt, const struct filename *from)
68957+{
68958+ return 1;
68959+}
68960+
68961+__u32
68962+gr_acl_handle_link(const struct dentry * new_dentry,
68963+ const struct dentry * parent_dentry,
68964+ const struct vfsmount * parent_mnt,
68965+ const struct dentry * old_dentry,
68966+ const struct vfsmount * old_mnt, const struct filename *to)
68967+{
68968+ return 1;
68969+}
68970+
68971+int
68972+gr_acl_handle_rename(const struct dentry *new_dentry,
68973+ const struct dentry *parent_dentry,
68974+ const struct vfsmount *parent_mnt,
68975+ const struct dentry *old_dentry,
68976+ const struct inode *old_parent_inode,
68977+ const struct vfsmount *old_mnt, const struct filename *newname)
68978+{
68979+ return 0;
68980+}
68981+
68982+int
68983+gr_acl_handle_filldir(const struct file *file, const char *name,
68984+ const int namelen, const ino_t ino)
68985+{
68986+ return 1;
68987+}
68988+
68989+int
68990+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68991+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
68992+{
68993+ return 1;
68994+}
68995+
68996+int
68997+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
68998+{
68999+ return 0;
69000+}
69001+
69002+int
69003+gr_search_accept(const struct socket *sock)
69004+{
69005+ return 0;
69006+}
69007+
69008+int
69009+gr_search_listen(const struct socket *sock)
69010+{
69011+ return 0;
69012+}
69013+
69014+int
69015+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
69016+{
69017+ return 0;
69018+}
69019+
69020+__u32
69021+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
69022+{
69023+ return 1;
69024+}
69025+
69026+__u32
69027+gr_acl_handle_creat(const struct dentry * dentry,
69028+ const struct dentry * p_dentry,
69029+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
69030+ const int imode)
69031+{
69032+ return 1;
69033+}
69034+
69035+void
69036+gr_acl_handle_exit(void)
69037+{
69038+ return;
69039+}
69040+
69041+int
69042+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
69043+{
69044+ return 1;
69045+}
69046+
69047+void
69048+gr_set_role_label(const kuid_t uid, const kgid_t gid)
69049+{
69050+ return;
69051+}
69052+
69053+int
69054+gr_acl_handle_procpidmem(const struct task_struct *task)
69055+{
69056+ return 0;
69057+}
69058+
69059+int
69060+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
69061+{
69062+ return 0;
69063+}
69064+
69065+int
69066+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
69067+{
69068+ return 0;
69069+}
69070+
69071+void
69072+gr_set_kernel_label(struct task_struct *task)
69073+{
69074+ return;
69075+}
69076+
69077+int
69078+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
69079+{
69080+ return 0;
69081+}
69082+
69083+int
69084+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
69085+{
69086+ return 0;
69087+}
69088+
69089+int gr_acl_enable_at_secure(void)
69090+{
69091+ return 0;
69092+}
69093+
69094+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
69095+{
69096+ return dentry->d_sb->s_dev;
69097+}
69098+
69099+void gr_put_exec_file(struct task_struct *task)
69100+{
69101+ return;
69102+}
69103+
69104+EXPORT_SYMBOL(gr_set_kernel_label);
69105+#ifdef CONFIG_SECURITY
69106+EXPORT_SYMBOL(gr_check_user_change);
69107+EXPORT_SYMBOL(gr_check_group_change);
69108+#endif
69109diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
69110new file mode 100644
69111index 0000000..387032b
69112--- /dev/null
69113+++ b/grsecurity/grsec_exec.c
69114@@ -0,0 +1,187 @@
69115+#include <linux/kernel.h>
69116+#include <linux/sched.h>
69117+#include <linux/file.h>
69118+#include <linux/binfmts.h>
69119+#include <linux/fs.h>
69120+#include <linux/types.h>
69121+#include <linux/grdefs.h>
69122+#include <linux/grsecurity.h>
69123+#include <linux/grinternal.h>
69124+#include <linux/capability.h>
69125+#include <linux/module.h>
69126+#include <linux/compat.h>
69127+
69128+#include <asm/uaccess.h>
69129+
69130+#ifdef CONFIG_GRKERNSEC_EXECLOG
69131+static char gr_exec_arg_buf[132];
69132+static DEFINE_MUTEX(gr_exec_arg_mutex);
69133+#endif
69134+
69135+struct user_arg_ptr {
69136+#ifdef CONFIG_COMPAT
69137+ bool is_compat;
69138+#endif
69139+ union {
69140+ const char __user *const __user *native;
69141+#ifdef CONFIG_COMPAT
69142+ const compat_uptr_t __user *compat;
69143+#endif
69144+ } ptr;
69145+};
69146+
69147+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
69148+
69149+void
69150+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
69151+{
69152+#ifdef CONFIG_GRKERNSEC_EXECLOG
69153+ char *grarg = gr_exec_arg_buf;
69154+ unsigned int i, x, execlen = 0;
69155+ char c;
69156+
69157+ if (!((grsec_enable_execlog && grsec_enable_group &&
69158+ in_group_p(grsec_audit_gid))
69159+ || (grsec_enable_execlog && !grsec_enable_group)))
69160+ return;
69161+
69162+ mutex_lock(&gr_exec_arg_mutex);
69163+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
69164+
69165+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
69166+ const char __user *p;
69167+ unsigned int len;
69168+
69169+ p = get_user_arg_ptr(argv, i);
69170+ if (IS_ERR(p))
69171+ goto log;
69172+
69173+ len = strnlen_user(p, 128 - execlen);
69174+ if (len > 128 - execlen)
69175+ len = 128 - execlen;
69176+ else if (len > 0)
69177+ len--;
69178+ if (copy_from_user(grarg + execlen, p, len))
69179+ goto log;
69180+
69181+ /* rewrite unprintable characters */
69182+ for (x = 0; x < len; x++) {
69183+ c = *(grarg + execlen + x);
69184+ if (c < 32 || c > 126)
69185+ *(grarg + execlen + x) = ' ';
69186+ }
69187+
69188+ execlen += len;
69189+ *(grarg + execlen) = ' ';
69190+ *(grarg + execlen + 1) = '\0';
69191+ execlen++;
69192+ }
69193+
69194+ log:
69195+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
69196+ bprm->file->f_path.mnt, grarg);
69197+ mutex_unlock(&gr_exec_arg_mutex);
69198+#endif
69199+ return;
69200+}
69201+
69202+#ifdef CONFIG_GRKERNSEC
69203+extern int gr_acl_is_capable(const int cap);
69204+extern int gr_acl_is_capable_nolog(const int cap);
69205+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
69206+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
69207+extern int gr_chroot_is_capable(const int cap);
69208+extern int gr_chroot_is_capable_nolog(const int cap);
69209+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
69210+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
69211+#endif
69212+
69213+const char *captab_log[] = {
69214+ "CAP_CHOWN",
69215+ "CAP_DAC_OVERRIDE",
69216+ "CAP_DAC_READ_SEARCH",
69217+ "CAP_FOWNER",
69218+ "CAP_FSETID",
69219+ "CAP_KILL",
69220+ "CAP_SETGID",
69221+ "CAP_SETUID",
69222+ "CAP_SETPCAP",
69223+ "CAP_LINUX_IMMUTABLE",
69224+ "CAP_NET_BIND_SERVICE",
69225+ "CAP_NET_BROADCAST",
69226+ "CAP_NET_ADMIN",
69227+ "CAP_NET_RAW",
69228+ "CAP_IPC_LOCK",
69229+ "CAP_IPC_OWNER",
69230+ "CAP_SYS_MODULE",
69231+ "CAP_SYS_RAWIO",
69232+ "CAP_SYS_CHROOT",
69233+ "CAP_SYS_PTRACE",
69234+ "CAP_SYS_PACCT",
69235+ "CAP_SYS_ADMIN",
69236+ "CAP_SYS_BOOT",
69237+ "CAP_SYS_NICE",
69238+ "CAP_SYS_RESOURCE",
69239+ "CAP_SYS_TIME",
69240+ "CAP_SYS_TTY_CONFIG",
69241+ "CAP_MKNOD",
69242+ "CAP_LEASE",
69243+ "CAP_AUDIT_WRITE",
69244+ "CAP_AUDIT_CONTROL",
69245+ "CAP_SETFCAP",
69246+ "CAP_MAC_OVERRIDE",
69247+ "CAP_MAC_ADMIN",
69248+ "CAP_SYSLOG",
69249+ "CAP_WAKE_ALARM"
69250+};
69251+
69252+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
69253+
69254+int gr_is_capable(const int cap)
69255+{
69256+#ifdef CONFIG_GRKERNSEC
69257+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
69258+ return 1;
69259+ return 0;
69260+#else
69261+ return 1;
69262+#endif
69263+}
69264+
69265+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
69266+{
69267+#ifdef CONFIG_GRKERNSEC
69268+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
69269+ return 1;
69270+ return 0;
69271+#else
69272+ return 1;
69273+#endif
69274+}
69275+
69276+int gr_is_capable_nolog(const int cap)
69277+{
69278+#ifdef CONFIG_GRKERNSEC
69279+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
69280+ return 1;
69281+ return 0;
69282+#else
69283+ return 1;
69284+#endif
69285+}
69286+
69287+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
69288+{
69289+#ifdef CONFIG_GRKERNSEC
69290+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
69291+ return 1;
69292+ return 0;
69293+#else
69294+ return 1;
69295+#endif
69296+}
69297+
69298+EXPORT_SYMBOL(gr_is_capable);
69299+EXPORT_SYMBOL(gr_is_capable_nolog);
69300+EXPORT_SYMBOL(gr_task_is_capable);
69301+EXPORT_SYMBOL(gr_task_is_capable_nolog);
69302diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
69303new file mode 100644
69304index 0000000..06cc6ea
69305--- /dev/null
69306+++ b/grsecurity/grsec_fifo.c
69307@@ -0,0 +1,24 @@
69308+#include <linux/kernel.h>
69309+#include <linux/sched.h>
69310+#include <linux/fs.h>
69311+#include <linux/file.h>
69312+#include <linux/grinternal.h>
69313+
69314+int
69315+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
69316+ const struct dentry *dir, const int flag, const int acc_mode)
69317+{
69318+#ifdef CONFIG_GRKERNSEC_FIFO
69319+ const struct cred *cred = current_cred();
69320+
69321+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
69322+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
69323+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
69324+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
69325+ if (!inode_permission(dentry->d_inode, acc_mode))
69326+ 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));
69327+ return -EACCES;
69328+ }
69329+#endif
69330+ return 0;
69331+}
69332diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
69333new file mode 100644
69334index 0000000..8ca18bf
69335--- /dev/null
69336+++ b/grsecurity/grsec_fork.c
69337@@ -0,0 +1,23 @@
69338+#include <linux/kernel.h>
69339+#include <linux/sched.h>
69340+#include <linux/grsecurity.h>
69341+#include <linux/grinternal.h>
69342+#include <linux/errno.h>
69343+
69344+void
69345+gr_log_forkfail(const int retval)
69346+{
69347+#ifdef CONFIG_GRKERNSEC_FORKFAIL
69348+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
69349+ switch (retval) {
69350+ case -EAGAIN:
69351+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
69352+ break;
69353+ case -ENOMEM:
69354+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
69355+ break;
69356+ }
69357+ }
69358+#endif
69359+ return;
69360+}
69361diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
69362new file mode 100644
69363index 0000000..99a0cb9
69364--- /dev/null
69365+++ b/grsecurity/grsec_init.c
69366@@ -0,0 +1,283 @@
69367+#include <linux/kernel.h>
69368+#include <linux/sched.h>
69369+#include <linux/mm.h>
69370+#include <linux/gracl.h>
69371+#include <linux/slab.h>
69372+#include <linux/vmalloc.h>
69373+#include <linux/percpu.h>
69374+#include <linux/module.h>
69375+
69376+int grsec_enable_ptrace_readexec;
69377+int grsec_enable_setxid;
69378+int grsec_enable_symlinkown;
69379+kgid_t grsec_symlinkown_gid;
69380+int grsec_enable_brute;
69381+int grsec_enable_link;
69382+int grsec_enable_dmesg;
69383+int grsec_enable_harden_ptrace;
69384+int grsec_enable_fifo;
69385+int grsec_enable_execlog;
69386+int grsec_enable_signal;
69387+int grsec_enable_forkfail;
69388+int grsec_enable_audit_ptrace;
69389+int grsec_enable_time;
69390+int grsec_enable_group;
69391+kgid_t grsec_audit_gid;
69392+int grsec_enable_chdir;
69393+int grsec_enable_mount;
69394+int grsec_enable_rofs;
69395+int grsec_deny_new_usb;
69396+int grsec_enable_chroot_findtask;
69397+int grsec_enable_chroot_mount;
69398+int grsec_enable_chroot_shmat;
69399+int grsec_enable_chroot_fchdir;
69400+int grsec_enable_chroot_double;
69401+int grsec_enable_chroot_pivot;
69402+int grsec_enable_chroot_chdir;
69403+int grsec_enable_chroot_chmod;
69404+int grsec_enable_chroot_mknod;
69405+int grsec_enable_chroot_nice;
69406+int grsec_enable_chroot_execlog;
69407+int grsec_enable_chroot_caps;
69408+int grsec_enable_chroot_sysctl;
69409+int grsec_enable_chroot_unix;
69410+int grsec_enable_tpe;
69411+kgid_t grsec_tpe_gid;
69412+int grsec_enable_blackhole;
69413+#ifdef CONFIG_IPV6_MODULE
69414+EXPORT_SYMBOL(grsec_enable_blackhole);
69415+#endif
69416+int grsec_lastack_retries;
69417+int grsec_enable_tpe_all;
69418+int grsec_enable_tpe_invert;
69419+int grsec_enable_socket_all;
69420+kgid_t grsec_socket_all_gid;
69421+int grsec_enable_socket_client;
69422+kgid_t grsec_socket_client_gid;
69423+int grsec_enable_socket_server;
69424+kgid_t grsec_socket_server_gid;
69425+int grsec_resource_logging;
69426+int grsec_disable_privio;
69427+int grsec_enable_log_rwxmaps;
69428+int grsec_lock;
69429+
69430+DEFINE_SPINLOCK(grsec_alert_lock);
69431+unsigned long grsec_alert_wtime = 0;
69432+unsigned long grsec_alert_fyet = 0;
69433+
69434+DEFINE_SPINLOCK(grsec_audit_lock);
69435+
69436+DEFINE_RWLOCK(grsec_exec_file_lock);
69437+
69438+char *gr_shared_page[4];
69439+
69440+char *gr_alert_log_fmt;
69441+char *gr_audit_log_fmt;
69442+char *gr_alert_log_buf;
69443+char *gr_audit_log_buf;
69444+
69445+extern struct gr_arg *gr_usermode;
69446+extern unsigned char *gr_system_salt;
69447+extern unsigned char *gr_system_sum;
69448+
69449+void __init
69450+grsecurity_init(void)
69451+{
69452+ int j;
69453+ /* create the per-cpu shared pages */
69454+
69455+#ifdef CONFIG_X86
69456+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
69457+#endif
69458+
69459+ for (j = 0; j < 4; j++) {
69460+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
69461+ if (gr_shared_page[j] == NULL) {
69462+ panic("Unable to allocate grsecurity shared page");
69463+ return;
69464+ }
69465+ }
69466+
69467+ /* allocate log buffers */
69468+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
69469+ if (!gr_alert_log_fmt) {
69470+ panic("Unable to allocate grsecurity alert log format buffer");
69471+ return;
69472+ }
69473+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
69474+ if (!gr_audit_log_fmt) {
69475+ panic("Unable to allocate grsecurity audit log format buffer");
69476+ return;
69477+ }
69478+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
69479+ if (!gr_alert_log_buf) {
69480+ panic("Unable to allocate grsecurity alert log buffer");
69481+ return;
69482+ }
69483+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
69484+ if (!gr_audit_log_buf) {
69485+ panic("Unable to allocate grsecurity audit log buffer");
69486+ return;
69487+ }
69488+
69489+ /* allocate memory for authentication structure */
69490+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
69491+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
69492+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
69493+
69494+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
69495+ panic("Unable to allocate grsecurity authentication structure");
69496+ return;
69497+ }
69498+
69499+
69500+#ifdef CONFIG_GRKERNSEC_IO
69501+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
69502+ grsec_disable_privio = 1;
69503+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
69504+ grsec_disable_privio = 1;
69505+#else
69506+ grsec_disable_privio = 0;
69507+#endif
69508+#endif
69509+
69510+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
69511+ /* for backward compatibility, tpe_invert always defaults to on if
69512+ enabled in the kernel
69513+ */
69514+ grsec_enable_tpe_invert = 1;
69515+#endif
69516+
69517+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
69518+#ifndef CONFIG_GRKERNSEC_SYSCTL
69519+ grsec_lock = 1;
69520+#endif
69521+
69522+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
69523+ grsec_enable_log_rwxmaps = 1;
69524+#endif
69525+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
69526+ grsec_enable_group = 1;
69527+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
69528+#endif
69529+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
69530+ grsec_enable_ptrace_readexec = 1;
69531+#endif
69532+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
69533+ grsec_enable_chdir = 1;
69534+#endif
69535+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69536+ grsec_enable_harden_ptrace = 1;
69537+#endif
69538+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
69539+ grsec_enable_mount = 1;
69540+#endif
69541+#ifdef CONFIG_GRKERNSEC_LINK
69542+ grsec_enable_link = 1;
69543+#endif
69544+#ifdef CONFIG_GRKERNSEC_BRUTE
69545+ grsec_enable_brute = 1;
69546+#endif
69547+#ifdef CONFIG_GRKERNSEC_DMESG
69548+ grsec_enable_dmesg = 1;
69549+#endif
69550+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
69551+ grsec_enable_blackhole = 1;
69552+ grsec_lastack_retries = 4;
69553+#endif
69554+#ifdef CONFIG_GRKERNSEC_FIFO
69555+ grsec_enable_fifo = 1;
69556+#endif
69557+#ifdef CONFIG_GRKERNSEC_EXECLOG
69558+ grsec_enable_execlog = 1;
69559+#endif
69560+#ifdef CONFIG_GRKERNSEC_SETXID
69561+ grsec_enable_setxid = 1;
69562+#endif
69563+#ifdef CONFIG_GRKERNSEC_SIGNAL
69564+ grsec_enable_signal = 1;
69565+#endif
69566+#ifdef CONFIG_GRKERNSEC_FORKFAIL
69567+ grsec_enable_forkfail = 1;
69568+#endif
69569+#ifdef CONFIG_GRKERNSEC_TIME
69570+ grsec_enable_time = 1;
69571+#endif
69572+#ifdef CONFIG_GRKERNSEC_RESLOG
69573+ grsec_resource_logging = 1;
69574+#endif
69575+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69576+ grsec_enable_chroot_findtask = 1;
69577+#endif
69578+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
69579+ grsec_enable_chroot_unix = 1;
69580+#endif
69581+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
69582+ grsec_enable_chroot_mount = 1;
69583+#endif
69584+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
69585+ grsec_enable_chroot_fchdir = 1;
69586+#endif
69587+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
69588+ grsec_enable_chroot_shmat = 1;
69589+#endif
69590+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
69591+ grsec_enable_audit_ptrace = 1;
69592+#endif
69593+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
69594+ grsec_enable_chroot_double = 1;
69595+#endif
69596+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
69597+ grsec_enable_chroot_pivot = 1;
69598+#endif
69599+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
69600+ grsec_enable_chroot_chdir = 1;
69601+#endif
69602+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
69603+ grsec_enable_chroot_chmod = 1;
69604+#endif
69605+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
69606+ grsec_enable_chroot_mknod = 1;
69607+#endif
69608+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
69609+ grsec_enable_chroot_nice = 1;
69610+#endif
69611+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
69612+ grsec_enable_chroot_execlog = 1;
69613+#endif
69614+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
69615+ grsec_enable_chroot_caps = 1;
69616+#endif
69617+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
69618+ grsec_enable_chroot_sysctl = 1;
69619+#endif
69620+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
69621+ grsec_enable_symlinkown = 1;
69622+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
69623+#endif
69624+#ifdef CONFIG_GRKERNSEC_TPE
69625+ grsec_enable_tpe = 1;
69626+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
69627+#ifdef CONFIG_GRKERNSEC_TPE_ALL
69628+ grsec_enable_tpe_all = 1;
69629+#endif
69630+#endif
69631+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
69632+ grsec_enable_socket_all = 1;
69633+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
69634+#endif
69635+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
69636+ grsec_enable_socket_client = 1;
69637+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
69638+#endif
69639+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
69640+ grsec_enable_socket_server = 1;
69641+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
69642+#endif
69643+#endif
69644+#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
69645+ grsec_deny_new_usb = 1;
69646+#endif
69647+
69648+ return;
69649+}
69650diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
69651new file mode 100644
69652index 0000000..5e05e20
69653--- /dev/null
69654+++ b/grsecurity/grsec_link.c
69655@@ -0,0 +1,58 @@
69656+#include <linux/kernel.h>
69657+#include <linux/sched.h>
69658+#include <linux/fs.h>
69659+#include <linux/file.h>
69660+#include <linux/grinternal.h>
69661+
69662+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
69663+{
69664+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
69665+ const struct inode *link_inode = link->dentry->d_inode;
69666+
69667+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
69668+ /* ignore root-owned links, e.g. /proc/self */
69669+ gr_is_global_nonroot(link_inode->i_uid) && target &&
69670+ !uid_eq(link_inode->i_uid, target->i_uid)) {
69671+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
69672+ return 1;
69673+ }
69674+#endif
69675+ return 0;
69676+}
69677+
69678+int
69679+gr_handle_follow_link(const struct inode *parent,
69680+ const struct inode *inode,
69681+ const struct dentry *dentry, const struct vfsmount *mnt)
69682+{
69683+#ifdef CONFIG_GRKERNSEC_LINK
69684+ const struct cred *cred = current_cred();
69685+
69686+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
69687+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
69688+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
69689+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
69690+ return -EACCES;
69691+ }
69692+#endif
69693+ return 0;
69694+}
69695+
69696+int
69697+gr_handle_hardlink(const struct dentry *dentry,
69698+ const struct vfsmount *mnt,
69699+ struct inode *inode, const int mode, const struct filename *to)
69700+{
69701+#ifdef CONFIG_GRKERNSEC_LINK
69702+ const struct cred *cred = current_cred();
69703+
69704+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
69705+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
69706+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
69707+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
69708+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
69709+ return -EPERM;
69710+ }
69711+#endif
69712+ return 0;
69713+}
69714diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
69715new file mode 100644
69716index 0000000..dbe0a6b
69717--- /dev/null
69718+++ b/grsecurity/grsec_log.c
69719@@ -0,0 +1,341 @@
69720+#include <linux/kernel.h>
69721+#include <linux/sched.h>
69722+#include <linux/file.h>
69723+#include <linux/tty.h>
69724+#include <linux/fs.h>
69725+#include <linux/mm.h>
69726+#include <linux/grinternal.h>
69727+
69728+#ifdef CONFIG_TREE_PREEMPT_RCU
69729+#define DISABLE_PREEMPT() preempt_disable()
69730+#define ENABLE_PREEMPT() preempt_enable()
69731+#else
69732+#define DISABLE_PREEMPT()
69733+#define ENABLE_PREEMPT()
69734+#endif
69735+
69736+#define BEGIN_LOCKS(x) \
69737+ DISABLE_PREEMPT(); \
69738+ rcu_read_lock(); \
69739+ read_lock(&tasklist_lock); \
69740+ read_lock(&grsec_exec_file_lock); \
69741+ if (x != GR_DO_AUDIT) \
69742+ spin_lock(&grsec_alert_lock); \
69743+ else \
69744+ spin_lock(&grsec_audit_lock)
69745+
69746+#define END_LOCKS(x) \
69747+ if (x != GR_DO_AUDIT) \
69748+ spin_unlock(&grsec_alert_lock); \
69749+ else \
69750+ spin_unlock(&grsec_audit_lock); \
69751+ read_unlock(&grsec_exec_file_lock); \
69752+ read_unlock(&tasklist_lock); \
69753+ rcu_read_unlock(); \
69754+ ENABLE_PREEMPT(); \
69755+ if (x == GR_DONT_AUDIT) \
69756+ gr_handle_alertkill(current)
69757+
69758+enum {
69759+ FLOODING,
69760+ NO_FLOODING
69761+};
69762+
69763+extern char *gr_alert_log_fmt;
69764+extern char *gr_audit_log_fmt;
69765+extern char *gr_alert_log_buf;
69766+extern char *gr_audit_log_buf;
69767+
69768+static int gr_log_start(int audit)
69769+{
69770+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
69771+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
69772+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
69773+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
69774+ unsigned long curr_secs = get_seconds();
69775+
69776+ if (audit == GR_DO_AUDIT)
69777+ goto set_fmt;
69778+
69779+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
69780+ grsec_alert_wtime = curr_secs;
69781+ grsec_alert_fyet = 0;
69782+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
69783+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
69784+ grsec_alert_fyet++;
69785+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
69786+ grsec_alert_wtime = curr_secs;
69787+ grsec_alert_fyet++;
69788+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
69789+ return FLOODING;
69790+ }
69791+ else return FLOODING;
69792+
69793+set_fmt:
69794+#endif
69795+ memset(buf, 0, PAGE_SIZE);
69796+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
69797+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
69798+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
69799+ } else if (current->signal->curr_ip) {
69800+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
69801+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
69802+ } else if (gr_acl_is_enabled()) {
69803+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
69804+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
69805+ } else {
69806+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
69807+ strcpy(buf, fmt);
69808+ }
69809+
69810+ return NO_FLOODING;
69811+}
69812+
69813+static void gr_log_middle(int audit, const char *msg, va_list ap)
69814+ __attribute__ ((format (printf, 2, 0)));
69815+
69816+static void gr_log_middle(int audit, const char *msg, va_list ap)
69817+{
69818+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
69819+ unsigned int len = strlen(buf);
69820+
69821+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
69822+
69823+ return;
69824+}
69825+
69826+static void gr_log_middle_varargs(int audit, const char *msg, ...)
69827+ __attribute__ ((format (printf, 2, 3)));
69828+
69829+static void gr_log_middle_varargs(int audit, const char *msg, ...)
69830+{
69831+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
69832+ unsigned int len = strlen(buf);
69833+ va_list ap;
69834+
69835+ va_start(ap, msg);
69836+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
69837+ va_end(ap);
69838+
69839+ return;
69840+}
69841+
69842+static void gr_log_end(int audit, int append_default)
69843+{
69844+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
69845+ if (append_default) {
69846+ struct task_struct *task = current;
69847+ struct task_struct *parent = task->real_parent;
69848+ const struct cred *cred = __task_cred(task);
69849+ const struct cred *pcred = __task_cred(parent);
69850+ unsigned int len = strlen(buf);
69851+
69852+ 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));
69853+ }
69854+
69855+ printk("%s\n", buf);
69856+
69857+ return;
69858+}
69859+
69860+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
69861+{
69862+ int logtype;
69863+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
69864+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
69865+ void *voidptr = NULL;
69866+ int num1 = 0, num2 = 0;
69867+ unsigned long ulong1 = 0, ulong2 = 0;
69868+ struct dentry *dentry = NULL;
69869+ struct vfsmount *mnt = NULL;
69870+ struct file *file = NULL;
69871+ struct task_struct *task = NULL;
69872+ struct vm_area_struct *vma = NULL;
69873+ const struct cred *cred, *pcred;
69874+ va_list ap;
69875+
69876+ BEGIN_LOCKS(audit);
69877+ logtype = gr_log_start(audit);
69878+ if (logtype == FLOODING) {
69879+ END_LOCKS(audit);
69880+ return;
69881+ }
69882+ va_start(ap, argtypes);
69883+ switch (argtypes) {
69884+ case GR_TTYSNIFF:
69885+ task = va_arg(ap, struct task_struct *);
69886+ 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));
69887+ break;
69888+ case GR_SYSCTL_HIDDEN:
69889+ str1 = va_arg(ap, char *);
69890+ gr_log_middle_varargs(audit, msg, result, str1);
69891+ break;
69892+ case GR_RBAC:
69893+ dentry = va_arg(ap, struct dentry *);
69894+ mnt = va_arg(ap, struct vfsmount *);
69895+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
69896+ break;
69897+ case GR_RBAC_STR:
69898+ dentry = va_arg(ap, struct dentry *);
69899+ mnt = va_arg(ap, struct vfsmount *);
69900+ str1 = va_arg(ap, char *);
69901+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
69902+ break;
69903+ case GR_STR_RBAC:
69904+ str1 = va_arg(ap, char *);
69905+ dentry = va_arg(ap, struct dentry *);
69906+ mnt = va_arg(ap, struct vfsmount *);
69907+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
69908+ break;
69909+ case GR_RBAC_MODE2:
69910+ dentry = va_arg(ap, struct dentry *);
69911+ mnt = va_arg(ap, struct vfsmount *);
69912+ str1 = va_arg(ap, char *);
69913+ str2 = va_arg(ap, char *);
69914+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
69915+ break;
69916+ case GR_RBAC_MODE3:
69917+ dentry = va_arg(ap, struct dentry *);
69918+ mnt = va_arg(ap, struct vfsmount *);
69919+ str1 = va_arg(ap, char *);
69920+ str2 = va_arg(ap, char *);
69921+ str3 = va_arg(ap, char *);
69922+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
69923+ break;
69924+ case GR_FILENAME:
69925+ dentry = va_arg(ap, struct dentry *);
69926+ mnt = va_arg(ap, struct vfsmount *);
69927+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
69928+ break;
69929+ case GR_STR_FILENAME:
69930+ str1 = va_arg(ap, char *);
69931+ dentry = va_arg(ap, struct dentry *);
69932+ mnt = va_arg(ap, struct vfsmount *);
69933+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
69934+ break;
69935+ case GR_FILENAME_STR:
69936+ dentry = va_arg(ap, struct dentry *);
69937+ mnt = va_arg(ap, struct vfsmount *);
69938+ str1 = va_arg(ap, char *);
69939+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
69940+ break;
69941+ case GR_FILENAME_TWO_INT:
69942+ dentry = va_arg(ap, struct dentry *);
69943+ mnt = va_arg(ap, struct vfsmount *);
69944+ num1 = va_arg(ap, int);
69945+ num2 = va_arg(ap, int);
69946+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
69947+ break;
69948+ case GR_FILENAME_TWO_INT_STR:
69949+ dentry = va_arg(ap, struct dentry *);
69950+ mnt = va_arg(ap, struct vfsmount *);
69951+ num1 = va_arg(ap, int);
69952+ num2 = va_arg(ap, int);
69953+ str1 = va_arg(ap, char *);
69954+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
69955+ break;
69956+ case GR_TEXTREL:
69957+ file = va_arg(ap, struct file *);
69958+ ulong1 = va_arg(ap, unsigned long);
69959+ ulong2 = va_arg(ap, unsigned long);
69960+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
69961+ break;
69962+ case GR_PTRACE:
69963+ task = va_arg(ap, struct task_struct *);
69964+ 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));
69965+ break;
69966+ case GR_RESOURCE:
69967+ task = va_arg(ap, struct task_struct *);
69968+ cred = __task_cred(task);
69969+ pcred = __task_cred(task->real_parent);
69970+ ulong1 = va_arg(ap, unsigned long);
69971+ str1 = va_arg(ap, char *);
69972+ ulong2 = va_arg(ap, unsigned long);
69973+ 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));
69974+ break;
69975+ case GR_CAP:
69976+ task = va_arg(ap, struct task_struct *);
69977+ cred = __task_cred(task);
69978+ pcred = __task_cred(task->real_parent);
69979+ str1 = va_arg(ap, char *);
69980+ 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));
69981+ break;
69982+ case GR_SIG:
69983+ str1 = va_arg(ap, char *);
69984+ voidptr = va_arg(ap, void *);
69985+ gr_log_middle_varargs(audit, msg, str1, voidptr);
69986+ break;
69987+ case GR_SIG2:
69988+ task = va_arg(ap, struct task_struct *);
69989+ cred = __task_cred(task);
69990+ pcred = __task_cred(task->real_parent);
69991+ num1 = va_arg(ap, int);
69992+ 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));
69993+ break;
69994+ case GR_CRASH1:
69995+ task = va_arg(ap, struct task_struct *);
69996+ cred = __task_cred(task);
69997+ pcred = __task_cred(task->real_parent);
69998+ ulong1 = va_arg(ap, unsigned long);
69999+ 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);
70000+ break;
70001+ case GR_CRASH2:
70002+ task = va_arg(ap, struct task_struct *);
70003+ cred = __task_cred(task);
70004+ pcred = __task_cred(task->real_parent);
70005+ ulong1 = va_arg(ap, unsigned long);
70006+ 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);
70007+ break;
70008+ case GR_RWXMAP:
70009+ file = va_arg(ap, struct file *);
70010+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
70011+ break;
70012+ case GR_RWXMAPVMA:
70013+ vma = va_arg(ap, struct vm_area_struct *);
70014+ if (vma->vm_file)
70015+ str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
70016+ else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
70017+ str1 = "<stack>";
70018+ else if (vma->vm_start <= current->mm->brk &&
70019+ vma->vm_end >= current->mm->start_brk)
70020+ str1 = "<heap>";
70021+ else
70022+ str1 = "<anonymous mapping>";
70023+ gr_log_middle_varargs(audit, msg, str1);
70024+ break;
70025+ case GR_PSACCT:
70026+ {
70027+ unsigned int wday, cday;
70028+ __u8 whr, chr;
70029+ __u8 wmin, cmin;
70030+ __u8 wsec, csec;
70031+ char cur_tty[64] = { 0 };
70032+ char parent_tty[64] = { 0 };
70033+
70034+ task = va_arg(ap, struct task_struct *);
70035+ wday = va_arg(ap, unsigned int);
70036+ cday = va_arg(ap, unsigned int);
70037+ whr = va_arg(ap, int);
70038+ chr = va_arg(ap, int);
70039+ wmin = va_arg(ap, int);
70040+ cmin = va_arg(ap, int);
70041+ wsec = va_arg(ap, int);
70042+ csec = va_arg(ap, int);
70043+ ulong1 = va_arg(ap, unsigned long);
70044+ cred = __task_cred(task);
70045+ pcred = __task_cred(task->real_parent);
70046+
70047+ 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));
70048+ }
70049+ break;
70050+ default:
70051+ gr_log_middle(audit, msg, ap);
70052+ }
70053+ va_end(ap);
70054+ // these don't need DEFAULTSECARGS printed on the end
70055+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
70056+ gr_log_end(audit, 0);
70057+ else
70058+ gr_log_end(audit, 1);
70059+ END_LOCKS(audit);
70060+}
70061diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
70062new file mode 100644
70063index 0000000..f536303
70064--- /dev/null
70065+++ b/grsecurity/grsec_mem.c
70066@@ -0,0 +1,40 @@
70067+#include <linux/kernel.h>
70068+#include <linux/sched.h>
70069+#include <linux/mm.h>
70070+#include <linux/mman.h>
70071+#include <linux/grinternal.h>
70072+
70073+void
70074+gr_handle_ioperm(void)
70075+{
70076+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
70077+ return;
70078+}
70079+
70080+void
70081+gr_handle_iopl(void)
70082+{
70083+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
70084+ return;
70085+}
70086+
70087+void
70088+gr_handle_mem_readwrite(u64 from, u64 to)
70089+{
70090+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
70091+ return;
70092+}
70093+
70094+void
70095+gr_handle_vm86(void)
70096+{
70097+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
70098+ return;
70099+}
70100+
70101+void
70102+gr_log_badprocpid(const char *entry)
70103+{
70104+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
70105+ return;
70106+}
70107diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
70108new file mode 100644
70109index 0000000..2131422
70110--- /dev/null
70111+++ b/grsecurity/grsec_mount.c
70112@@ -0,0 +1,62 @@
70113+#include <linux/kernel.h>
70114+#include <linux/sched.h>
70115+#include <linux/mount.h>
70116+#include <linux/grsecurity.h>
70117+#include <linux/grinternal.h>
70118+
70119+void
70120+gr_log_remount(const char *devname, const int retval)
70121+{
70122+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
70123+ if (grsec_enable_mount && (retval >= 0))
70124+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
70125+#endif
70126+ return;
70127+}
70128+
70129+void
70130+gr_log_unmount(const char *devname, const int retval)
70131+{
70132+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
70133+ if (grsec_enable_mount && (retval >= 0))
70134+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
70135+#endif
70136+ return;
70137+}
70138+
70139+void
70140+gr_log_mount(const char *from, const char *to, const int retval)
70141+{
70142+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
70143+ if (grsec_enable_mount && (retval >= 0))
70144+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
70145+#endif
70146+ return;
70147+}
70148+
70149+int
70150+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
70151+{
70152+#ifdef CONFIG_GRKERNSEC_ROFS
70153+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
70154+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
70155+ return -EPERM;
70156+ } else
70157+ return 0;
70158+#endif
70159+ return 0;
70160+}
70161+
70162+int
70163+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
70164+{
70165+#ifdef CONFIG_GRKERNSEC_ROFS
70166+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
70167+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
70168+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
70169+ return -EPERM;
70170+ } else
70171+ return 0;
70172+#endif
70173+ return 0;
70174+}
70175diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
70176new file mode 100644
70177index 0000000..6ee9d50
70178--- /dev/null
70179+++ b/grsecurity/grsec_pax.c
70180@@ -0,0 +1,45 @@
70181+#include <linux/kernel.h>
70182+#include <linux/sched.h>
70183+#include <linux/mm.h>
70184+#include <linux/file.h>
70185+#include <linux/grinternal.h>
70186+#include <linux/grsecurity.h>
70187+
70188+void
70189+gr_log_textrel(struct vm_area_struct * vma)
70190+{
70191+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70192+ if (grsec_enable_log_rwxmaps)
70193+ gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
70194+#endif
70195+ return;
70196+}
70197+
70198+void gr_log_ptgnustack(struct file *file)
70199+{
70200+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70201+ if (grsec_enable_log_rwxmaps)
70202+ gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
70203+#endif
70204+ return;
70205+}
70206+
70207+void
70208+gr_log_rwxmmap(struct file *file)
70209+{
70210+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70211+ if (grsec_enable_log_rwxmaps)
70212+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
70213+#endif
70214+ return;
70215+}
70216+
70217+void
70218+gr_log_rwxmprotect(struct vm_area_struct *vma)
70219+{
70220+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70221+ if (grsec_enable_log_rwxmaps)
70222+ gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
70223+#endif
70224+ return;
70225+}
70226diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
70227new file mode 100644
70228index 0000000..f7f29aa
70229--- /dev/null
70230+++ b/grsecurity/grsec_ptrace.c
70231@@ -0,0 +1,30 @@
70232+#include <linux/kernel.h>
70233+#include <linux/sched.h>
70234+#include <linux/grinternal.h>
70235+#include <linux/security.h>
70236+
70237+void
70238+gr_audit_ptrace(struct task_struct *task)
70239+{
70240+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
70241+ if (grsec_enable_audit_ptrace)
70242+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
70243+#endif
70244+ return;
70245+}
70246+
70247+int
70248+gr_ptrace_readexec(struct file *file, int unsafe_flags)
70249+{
70250+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
70251+ const struct dentry *dentry = file->f_path.dentry;
70252+ const struct vfsmount *mnt = file->f_path.mnt;
70253+
70254+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
70255+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
70256+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
70257+ return -EACCES;
70258+ }
70259+#endif
70260+ return 0;
70261+}
70262diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
70263new file mode 100644
70264index 0000000..4e29cc7
70265--- /dev/null
70266+++ b/grsecurity/grsec_sig.c
70267@@ -0,0 +1,246 @@
70268+#include <linux/kernel.h>
70269+#include <linux/sched.h>
70270+#include <linux/fs.h>
70271+#include <linux/delay.h>
70272+#include <linux/grsecurity.h>
70273+#include <linux/grinternal.h>
70274+#include <linux/hardirq.h>
70275+
70276+char *signames[] = {
70277+ [SIGSEGV] = "Segmentation fault",
70278+ [SIGILL] = "Illegal instruction",
70279+ [SIGABRT] = "Abort",
70280+ [SIGBUS] = "Invalid alignment/Bus error"
70281+};
70282+
70283+void
70284+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
70285+{
70286+#ifdef CONFIG_GRKERNSEC_SIGNAL
70287+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
70288+ (sig == SIGABRT) || (sig == SIGBUS))) {
70289+ if (task_pid_nr(t) == task_pid_nr(current)) {
70290+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
70291+ } else {
70292+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
70293+ }
70294+ }
70295+#endif
70296+ return;
70297+}
70298+
70299+int
70300+gr_handle_signal(const struct task_struct *p, const int sig)
70301+{
70302+#ifdef CONFIG_GRKERNSEC
70303+ /* ignore the 0 signal for protected task checks */
70304+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
70305+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
70306+ return -EPERM;
70307+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
70308+ return -EPERM;
70309+ }
70310+#endif
70311+ return 0;
70312+}
70313+
70314+#ifdef CONFIG_GRKERNSEC
70315+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
70316+
70317+int gr_fake_force_sig(int sig, struct task_struct *t)
70318+{
70319+ unsigned long int flags;
70320+ int ret, blocked, ignored;
70321+ struct k_sigaction *action;
70322+
70323+ spin_lock_irqsave(&t->sighand->siglock, flags);
70324+ action = &t->sighand->action[sig-1];
70325+ ignored = action->sa.sa_handler == SIG_IGN;
70326+ blocked = sigismember(&t->blocked, sig);
70327+ if (blocked || ignored) {
70328+ action->sa.sa_handler = SIG_DFL;
70329+ if (blocked) {
70330+ sigdelset(&t->blocked, sig);
70331+ recalc_sigpending_and_wake(t);
70332+ }
70333+ }
70334+ if (action->sa.sa_handler == SIG_DFL)
70335+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
70336+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
70337+
70338+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
70339+
70340+ return ret;
70341+}
70342+#endif
70343+
70344+#ifdef CONFIG_GRKERNSEC_BRUTE
70345+#define GR_USER_BAN_TIME (15 * 60)
70346+#define GR_DAEMON_BRUTE_TIME (30 * 60)
70347+
70348+static int __get_dumpable(unsigned long mm_flags)
70349+{
70350+ int ret;
70351+
70352+ ret = mm_flags & MMF_DUMPABLE_MASK;
70353+ return (ret >= 2) ? 2 : ret;
70354+}
70355+#endif
70356+
70357+void gr_handle_brute_attach(unsigned long mm_flags)
70358+{
70359+#ifdef CONFIG_GRKERNSEC_BRUTE
70360+ struct task_struct *p = current;
70361+ kuid_t uid = GLOBAL_ROOT_UID;
70362+ int daemon = 0;
70363+
70364+ if (!grsec_enable_brute)
70365+ return;
70366+
70367+ rcu_read_lock();
70368+ read_lock(&tasklist_lock);
70369+ read_lock(&grsec_exec_file_lock);
70370+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
70371+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
70372+ p->real_parent->brute = 1;
70373+ daemon = 1;
70374+ } else {
70375+ const struct cred *cred = __task_cred(p), *cred2;
70376+ struct task_struct *tsk, *tsk2;
70377+
70378+ if (!__get_dumpable(mm_flags) && gr_is_global_nonroot(cred->uid)) {
70379+ struct user_struct *user;
70380+
70381+ uid = cred->uid;
70382+
70383+ /* this is put upon execution past expiration */
70384+ user = find_user(uid);
70385+ if (user == NULL)
70386+ goto unlock;
70387+ user->suid_banned = 1;
70388+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
70389+ if (user->suid_ban_expires == ~0UL)
70390+ user->suid_ban_expires--;
70391+
70392+ /* only kill other threads of the same binary, from the same user */
70393+ do_each_thread(tsk2, tsk) {
70394+ cred2 = __task_cred(tsk);
70395+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
70396+ gr_fake_force_sig(SIGKILL, tsk);
70397+ } while_each_thread(tsk2, tsk);
70398+ }
70399+ }
70400+unlock:
70401+ read_unlock(&grsec_exec_file_lock);
70402+ read_unlock(&tasklist_lock);
70403+ rcu_read_unlock();
70404+
70405+ if (gr_is_global_nonroot(uid))
70406+ 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);
70407+ else if (daemon)
70408+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
70409+
70410+#endif
70411+ return;
70412+}
70413+
70414+void gr_handle_brute_check(void)
70415+{
70416+#ifdef CONFIG_GRKERNSEC_BRUTE
70417+ struct task_struct *p = current;
70418+
70419+ if (unlikely(p->brute)) {
70420+ if (!grsec_enable_brute)
70421+ p->brute = 0;
70422+ else if (time_before(get_seconds(), p->brute_expires))
70423+ msleep(30 * 1000);
70424+ }
70425+#endif
70426+ return;
70427+}
70428+
70429+void gr_handle_kernel_exploit(void)
70430+{
70431+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
70432+ const struct cred *cred;
70433+ struct task_struct *tsk, *tsk2;
70434+ struct user_struct *user;
70435+ kuid_t uid;
70436+
70437+ if (in_irq() || in_serving_softirq() || in_nmi())
70438+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
70439+
70440+ uid = current_uid();
70441+
70442+ if (gr_is_global_root(uid))
70443+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
70444+ else {
70445+ /* kill all the processes of this user, hold a reference
70446+ to their creds struct, and prevent them from creating
70447+ another process until system reset
70448+ */
70449+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
70450+ GR_GLOBAL_UID(uid));
70451+ /* we intentionally leak this ref */
70452+ user = get_uid(current->cred->user);
70453+ if (user)
70454+ user->kernel_banned = 1;
70455+
70456+ /* kill all processes of this user */
70457+ read_lock(&tasklist_lock);
70458+ do_each_thread(tsk2, tsk) {
70459+ cred = __task_cred(tsk);
70460+ if (uid_eq(cred->uid, uid))
70461+ gr_fake_force_sig(SIGKILL, tsk);
70462+ } while_each_thread(tsk2, tsk);
70463+ read_unlock(&tasklist_lock);
70464+ }
70465+#endif
70466+}
70467+
70468+#ifdef CONFIG_GRKERNSEC_BRUTE
70469+static bool suid_ban_expired(struct user_struct *user)
70470+{
70471+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
70472+ user->suid_banned = 0;
70473+ user->suid_ban_expires = 0;
70474+ free_uid(user);
70475+ return true;
70476+ }
70477+
70478+ return false;
70479+}
70480+#endif
70481+
70482+int gr_process_kernel_exec_ban(void)
70483+{
70484+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
70485+ if (unlikely(current->cred->user->kernel_banned))
70486+ return -EPERM;
70487+#endif
70488+ return 0;
70489+}
70490+
70491+int gr_process_kernel_setuid_ban(struct user_struct *user)
70492+{
70493+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
70494+ if (unlikely(user->kernel_banned))
70495+ gr_fake_force_sig(SIGKILL, current);
70496+#endif
70497+ return 0;
70498+}
70499+
70500+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
70501+{
70502+#ifdef CONFIG_GRKERNSEC_BRUTE
70503+ struct user_struct *user = current->cred->user;
70504+ if (unlikely(user->suid_banned)) {
70505+ if (suid_ban_expired(user))
70506+ return 0;
70507+ /* disallow execution of suid binaries only */
70508+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
70509+ return -EPERM;
70510+ }
70511+#endif
70512+ return 0;
70513+}
70514diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
70515new file mode 100644
70516index 0000000..4030d57
70517--- /dev/null
70518+++ b/grsecurity/grsec_sock.c
70519@@ -0,0 +1,244 @@
70520+#include <linux/kernel.h>
70521+#include <linux/module.h>
70522+#include <linux/sched.h>
70523+#include <linux/file.h>
70524+#include <linux/net.h>
70525+#include <linux/in.h>
70526+#include <linux/ip.h>
70527+#include <net/sock.h>
70528+#include <net/inet_sock.h>
70529+#include <linux/grsecurity.h>
70530+#include <linux/grinternal.h>
70531+#include <linux/gracl.h>
70532+
70533+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
70534+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
70535+
70536+EXPORT_SYMBOL(gr_search_udp_recvmsg);
70537+EXPORT_SYMBOL(gr_search_udp_sendmsg);
70538+
70539+#ifdef CONFIG_UNIX_MODULE
70540+EXPORT_SYMBOL(gr_acl_handle_unix);
70541+EXPORT_SYMBOL(gr_acl_handle_mknod);
70542+EXPORT_SYMBOL(gr_handle_chroot_unix);
70543+EXPORT_SYMBOL(gr_handle_create);
70544+#endif
70545+
70546+#ifdef CONFIG_GRKERNSEC
70547+#define gr_conn_table_size 32749
70548+struct conn_table_entry {
70549+ struct conn_table_entry *next;
70550+ struct signal_struct *sig;
70551+};
70552+
70553+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
70554+DEFINE_SPINLOCK(gr_conn_table_lock);
70555+
70556+extern const char * gr_socktype_to_name(unsigned char type);
70557+extern const char * gr_proto_to_name(unsigned char proto);
70558+extern const char * gr_sockfamily_to_name(unsigned char family);
70559+
70560+static __inline__ int
70561+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
70562+{
70563+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
70564+}
70565+
70566+static __inline__ int
70567+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
70568+ __u16 sport, __u16 dport)
70569+{
70570+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
70571+ sig->gr_sport == sport && sig->gr_dport == dport))
70572+ return 1;
70573+ else
70574+ return 0;
70575+}
70576+
70577+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
70578+{
70579+ struct conn_table_entry **match;
70580+ unsigned int index;
70581+
70582+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
70583+ sig->gr_sport, sig->gr_dport,
70584+ gr_conn_table_size);
70585+
70586+ newent->sig = sig;
70587+
70588+ match = &gr_conn_table[index];
70589+ newent->next = *match;
70590+ *match = newent;
70591+
70592+ return;
70593+}
70594+
70595+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
70596+{
70597+ struct conn_table_entry *match, *last = NULL;
70598+ unsigned int index;
70599+
70600+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
70601+ sig->gr_sport, sig->gr_dport,
70602+ gr_conn_table_size);
70603+
70604+ match = gr_conn_table[index];
70605+ while (match && !conn_match(match->sig,
70606+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
70607+ sig->gr_dport)) {
70608+ last = match;
70609+ match = match->next;
70610+ }
70611+
70612+ if (match) {
70613+ if (last)
70614+ last->next = match->next;
70615+ else
70616+ gr_conn_table[index] = NULL;
70617+ kfree(match);
70618+ }
70619+
70620+ return;
70621+}
70622+
70623+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
70624+ __u16 sport, __u16 dport)
70625+{
70626+ struct conn_table_entry *match;
70627+ unsigned int index;
70628+
70629+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
70630+
70631+ match = gr_conn_table[index];
70632+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
70633+ match = match->next;
70634+
70635+ if (match)
70636+ return match->sig;
70637+ else
70638+ return NULL;
70639+}
70640+
70641+#endif
70642+
70643+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
70644+{
70645+#ifdef CONFIG_GRKERNSEC
70646+ struct signal_struct *sig = task->signal;
70647+ struct conn_table_entry *newent;
70648+
70649+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
70650+ if (newent == NULL)
70651+ return;
70652+ /* no bh lock needed since we are called with bh disabled */
70653+ spin_lock(&gr_conn_table_lock);
70654+ gr_del_task_from_ip_table_nolock(sig);
70655+ sig->gr_saddr = inet->inet_rcv_saddr;
70656+ sig->gr_daddr = inet->inet_daddr;
70657+ sig->gr_sport = inet->inet_sport;
70658+ sig->gr_dport = inet->inet_dport;
70659+ gr_add_to_task_ip_table_nolock(sig, newent);
70660+ spin_unlock(&gr_conn_table_lock);
70661+#endif
70662+ return;
70663+}
70664+
70665+void gr_del_task_from_ip_table(struct task_struct *task)
70666+{
70667+#ifdef CONFIG_GRKERNSEC
70668+ spin_lock_bh(&gr_conn_table_lock);
70669+ gr_del_task_from_ip_table_nolock(task->signal);
70670+ spin_unlock_bh(&gr_conn_table_lock);
70671+#endif
70672+ return;
70673+}
70674+
70675+void
70676+gr_attach_curr_ip(const struct sock *sk)
70677+{
70678+#ifdef CONFIG_GRKERNSEC
70679+ struct signal_struct *p, *set;
70680+ const struct inet_sock *inet = inet_sk(sk);
70681+
70682+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
70683+ return;
70684+
70685+ set = current->signal;
70686+
70687+ spin_lock_bh(&gr_conn_table_lock);
70688+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
70689+ inet->inet_dport, inet->inet_sport);
70690+ if (unlikely(p != NULL)) {
70691+ set->curr_ip = p->curr_ip;
70692+ set->used_accept = 1;
70693+ gr_del_task_from_ip_table_nolock(p);
70694+ spin_unlock_bh(&gr_conn_table_lock);
70695+ return;
70696+ }
70697+ spin_unlock_bh(&gr_conn_table_lock);
70698+
70699+ set->curr_ip = inet->inet_daddr;
70700+ set->used_accept = 1;
70701+#endif
70702+ return;
70703+}
70704+
70705+int
70706+gr_handle_sock_all(const int family, const int type, const int protocol)
70707+{
70708+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
70709+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
70710+ (family != AF_UNIX)) {
70711+ if (family == AF_INET)
70712+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
70713+ else
70714+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
70715+ return -EACCES;
70716+ }
70717+#endif
70718+ return 0;
70719+}
70720+
70721+int
70722+gr_handle_sock_server(const struct sockaddr *sck)
70723+{
70724+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
70725+ if (grsec_enable_socket_server &&
70726+ in_group_p(grsec_socket_server_gid) &&
70727+ sck && (sck->sa_family != AF_UNIX) &&
70728+ (sck->sa_family != AF_LOCAL)) {
70729+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
70730+ return -EACCES;
70731+ }
70732+#endif
70733+ return 0;
70734+}
70735+
70736+int
70737+gr_handle_sock_server_other(const struct sock *sck)
70738+{
70739+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
70740+ if (grsec_enable_socket_server &&
70741+ in_group_p(grsec_socket_server_gid) &&
70742+ sck && (sck->sk_family != AF_UNIX) &&
70743+ (sck->sk_family != AF_LOCAL)) {
70744+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
70745+ return -EACCES;
70746+ }
70747+#endif
70748+ return 0;
70749+}
70750+
70751+int
70752+gr_handle_sock_client(const struct sockaddr *sck)
70753+{
70754+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
70755+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
70756+ sck && (sck->sa_family != AF_UNIX) &&
70757+ (sck->sa_family != AF_LOCAL)) {
70758+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
70759+ return -EACCES;
70760+ }
70761+#endif
70762+ return 0;
70763+}
70764diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
70765new file mode 100644
70766index 0000000..a147ae7
70767--- /dev/null
70768+++ b/grsecurity/grsec_sysctl.c
70769@@ -0,0 +1,470 @@
70770+#include <linux/kernel.h>
70771+#include <linux/sched.h>
70772+#include <linux/sysctl.h>
70773+#include <linux/grsecurity.h>
70774+#include <linux/grinternal.h>
70775+
70776+int
70777+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
70778+{
70779+#ifdef CONFIG_GRKERNSEC_SYSCTL
70780+ if (dirname == NULL || name == NULL)
70781+ return 0;
70782+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
70783+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
70784+ return -EACCES;
70785+ }
70786+#endif
70787+ return 0;
70788+}
70789+
70790+#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
70791+static int __maybe_unused __read_only one = 1;
70792+#endif
70793+
70794+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
70795+ defined(CONFIG_GRKERNSEC_DENYUSB)
70796+struct ctl_table grsecurity_table[] = {
70797+#ifdef CONFIG_GRKERNSEC_SYSCTL
70798+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
70799+#ifdef CONFIG_GRKERNSEC_IO
70800+ {
70801+ .procname = "disable_priv_io",
70802+ .data = &grsec_disable_privio,
70803+ .maxlen = sizeof(int),
70804+ .mode = 0600,
70805+ .proc_handler = &proc_dointvec,
70806+ },
70807+#endif
70808+#endif
70809+#ifdef CONFIG_GRKERNSEC_LINK
70810+ {
70811+ .procname = "linking_restrictions",
70812+ .data = &grsec_enable_link,
70813+ .maxlen = sizeof(int),
70814+ .mode = 0600,
70815+ .proc_handler = &proc_dointvec,
70816+ },
70817+#endif
70818+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
70819+ {
70820+ .procname = "enforce_symlinksifowner",
70821+ .data = &grsec_enable_symlinkown,
70822+ .maxlen = sizeof(int),
70823+ .mode = 0600,
70824+ .proc_handler = &proc_dointvec,
70825+ },
70826+ {
70827+ .procname = "symlinkown_gid",
70828+ .data = &grsec_symlinkown_gid,
70829+ .maxlen = sizeof(int),
70830+ .mode = 0600,
70831+ .proc_handler = &proc_dointvec,
70832+ },
70833+#endif
70834+#ifdef CONFIG_GRKERNSEC_BRUTE
70835+ {
70836+ .procname = "deter_bruteforce",
70837+ .data = &grsec_enable_brute,
70838+ .maxlen = sizeof(int),
70839+ .mode = 0600,
70840+ .proc_handler = &proc_dointvec,
70841+ },
70842+#endif
70843+#ifdef CONFIG_GRKERNSEC_FIFO
70844+ {
70845+ .procname = "fifo_restrictions",
70846+ .data = &grsec_enable_fifo,
70847+ .maxlen = sizeof(int),
70848+ .mode = 0600,
70849+ .proc_handler = &proc_dointvec,
70850+ },
70851+#endif
70852+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
70853+ {
70854+ .procname = "ptrace_readexec",
70855+ .data = &grsec_enable_ptrace_readexec,
70856+ .maxlen = sizeof(int),
70857+ .mode = 0600,
70858+ .proc_handler = &proc_dointvec,
70859+ },
70860+#endif
70861+#ifdef CONFIG_GRKERNSEC_SETXID
70862+ {
70863+ .procname = "consistent_setxid",
70864+ .data = &grsec_enable_setxid,
70865+ .maxlen = sizeof(int),
70866+ .mode = 0600,
70867+ .proc_handler = &proc_dointvec,
70868+ },
70869+#endif
70870+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
70871+ {
70872+ .procname = "ip_blackhole",
70873+ .data = &grsec_enable_blackhole,
70874+ .maxlen = sizeof(int),
70875+ .mode = 0600,
70876+ .proc_handler = &proc_dointvec,
70877+ },
70878+ {
70879+ .procname = "lastack_retries",
70880+ .data = &grsec_lastack_retries,
70881+ .maxlen = sizeof(int),
70882+ .mode = 0600,
70883+ .proc_handler = &proc_dointvec,
70884+ },
70885+#endif
70886+#ifdef CONFIG_GRKERNSEC_EXECLOG
70887+ {
70888+ .procname = "exec_logging",
70889+ .data = &grsec_enable_execlog,
70890+ .maxlen = sizeof(int),
70891+ .mode = 0600,
70892+ .proc_handler = &proc_dointvec,
70893+ },
70894+#endif
70895+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70896+ {
70897+ .procname = "rwxmap_logging",
70898+ .data = &grsec_enable_log_rwxmaps,
70899+ .maxlen = sizeof(int),
70900+ .mode = 0600,
70901+ .proc_handler = &proc_dointvec,
70902+ },
70903+#endif
70904+#ifdef CONFIG_GRKERNSEC_SIGNAL
70905+ {
70906+ .procname = "signal_logging",
70907+ .data = &grsec_enable_signal,
70908+ .maxlen = sizeof(int),
70909+ .mode = 0600,
70910+ .proc_handler = &proc_dointvec,
70911+ },
70912+#endif
70913+#ifdef CONFIG_GRKERNSEC_FORKFAIL
70914+ {
70915+ .procname = "forkfail_logging",
70916+ .data = &grsec_enable_forkfail,
70917+ .maxlen = sizeof(int),
70918+ .mode = 0600,
70919+ .proc_handler = &proc_dointvec,
70920+ },
70921+#endif
70922+#ifdef CONFIG_GRKERNSEC_TIME
70923+ {
70924+ .procname = "timechange_logging",
70925+ .data = &grsec_enable_time,
70926+ .maxlen = sizeof(int),
70927+ .mode = 0600,
70928+ .proc_handler = &proc_dointvec,
70929+ },
70930+#endif
70931+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
70932+ {
70933+ .procname = "chroot_deny_shmat",
70934+ .data = &grsec_enable_chroot_shmat,
70935+ .maxlen = sizeof(int),
70936+ .mode = 0600,
70937+ .proc_handler = &proc_dointvec,
70938+ },
70939+#endif
70940+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
70941+ {
70942+ .procname = "chroot_deny_unix",
70943+ .data = &grsec_enable_chroot_unix,
70944+ .maxlen = sizeof(int),
70945+ .mode = 0600,
70946+ .proc_handler = &proc_dointvec,
70947+ },
70948+#endif
70949+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
70950+ {
70951+ .procname = "chroot_deny_mount",
70952+ .data = &grsec_enable_chroot_mount,
70953+ .maxlen = sizeof(int),
70954+ .mode = 0600,
70955+ .proc_handler = &proc_dointvec,
70956+ },
70957+#endif
70958+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
70959+ {
70960+ .procname = "chroot_deny_fchdir",
70961+ .data = &grsec_enable_chroot_fchdir,
70962+ .maxlen = sizeof(int),
70963+ .mode = 0600,
70964+ .proc_handler = &proc_dointvec,
70965+ },
70966+#endif
70967+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
70968+ {
70969+ .procname = "chroot_deny_chroot",
70970+ .data = &grsec_enable_chroot_double,
70971+ .maxlen = sizeof(int),
70972+ .mode = 0600,
70973+ .proc_handler = &proc_dointvec,
70974+ },
70975+#endif
70976+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
70977+ {
70978+ .procname = "chroot_deny_pivot",
70979+ .data = &grsec_enable_chroot_pivot,
70980+ .maxlen = sizeof(int),
70981+ .mode = 0600,
70982+ .proc_handler = &proc_dointvec,
70983+ },
70984+#endif
70985+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
70986+ {
70987+ .procname = "chroot_enforce_chdir",
70988+ .data = &grsec_enable_chroot_chdir,
70989+ .maxlen = sizeof(int),
70990+ .mode = 0600,
70991+ .proc_handler = &proc_dointvec,
70992+ },
70993+#endif
70994+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
70995+ {
70996+ .procname = "chroot_deny_chmod",
70997+ .data = &grsec_enable_chroot_chmod,
70998+ .maxlen = sizeof(int),
70999+ .mode = 0600,
71000+ .proc_handler = &proc_dointvec,
71001+ },
71002+#endif
71003+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
71004+ {
71005+ .procname = "chroot_deny_mknod",
71006+ .data = &grsec_enable_chroot_mknod,
71007+ .maxlen = sizeof(int),
71008+ .mode = 0600,
71009+ .proc_handler = &proc_dointvec,
71010+ },
71011+#endif
71012+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
71013+ {
71014+ .procname = "chroot_restrict_nice",
71015+ .data = &grsec_enable_chroot_nice,
71016+ .maxlen = sizeof(int),
71017+ .mode = 0600,
71018+ .proc_handler = &proc_dointvec,
71019+ },
71020+#endif
71021+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
71022+ {
71023+ .procname = "chroot_execlog",
71024+ .data = &grsec_enable_chroot_execlog,
71025+ .maxlen = sizeof(int),
71026+ .mode = 0600,
71027+ .proc_handler = &proc_dointvec,
71028+ },
71029+#endif
71030+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
71031+ {
71032+ .procname = "chroot_caps",
71033+ .data = &grsec_enable_chroot_caps,
71034+ .maxlen = sizeof(int),
71035+ .mode = 0600,
71036+ .proc_handler = &proc_dointvec,
71037+ },
71038+#endif
71039+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
71040+ {
71041+ .procname = "chroot_deny_sysctl",
71042+ .data = &grsec_enable_chroot_sysctl,
71043+ .maxlen = sizeof(int),
71044+ .mode = 0600,
71045+ .proc_handler = &proc_dointvec,
71046+ },
71047+#endif
71048+#ifdef CONFIG_GRKERNSEC_TPE
71049+ {
71050+ .procname = "tpe",
71051+ .data = &grsec_enable_tpe,
71052+ .maxlen = sizeof(int),
71053+ .mode = 0600,
71054+ .proc_handler = &proc_dointvec,
71055+ },
71056+ {
71057+ .procname = "tpe_gid",
71058+ .data = &grsec_tpe_gid,
71059+ .maxlen = sizeof(int),
71060+ .mode = 0600,
71061+ .proc_handler = &proc_dointvec,
71062+ },
71063+#endif
71064+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
71065+ {
71066+ .procname = "tpe_invert",
71067+ .data = &grsec_enable_tpe_invert,
71068+ .maxlen = sizeof(int),
71069+ .mode = 0600,
71070+ .proc_handler = &proc_dointvec,
71071+ },
71072+#endif
71073+#ifdef CONFIG_GRKERNSEC_TPE_ALL
71074+ {
71075+ .procname = "tpe_restrict_all",
71076+ .data = &grsec_enable_tpe_all,
71077+ .maxlen = sizeof(int),
71078+ .mode = 0600,
71079+ .proc_handler = &proc_dointvec,
71080+ },
71081+#endif
71082+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
71083+ {
71084+ .procname = "socket_all",
71085+ .data = &grsec_enable_socket_all,
71086+ .maxlen = sizeof(int),
71087+ .mode = 0600,
71088+ .proc_handler = &proc_dointvec,
71089+ },
71090+ {
71091+ .procname = "socket_all_gid",
71092+ .data = &grsec_socket_all_gid,
71093+ .maxlen = sizeof(int),
71094+ .mode = 0600,
71095+ .proc_handler = &proc_dointvec,
71096+ },
71097+#endif
71098+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
71099+ {
71100+ .procname = "socket_client",
71101+ .data = &grsec_enable_socket_client,
71102+ .maxlen = sizeof(int),
71103+ .mode = 0600,
71104+ .proc_handler = &proc_dointvec,
71105+ },
71106+ {
71107+ .procname = "socket_client_gid",
71108+ .data = &grsec_socket_client_gid,
71109+ .maxlen = sizeof(int),
71110+ .mode = 0600,
71111+ .proc_handler = &proc_dointvec,
71112+ },
71113+#endif
71114+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
71115+ {
71116+ .procname = "socket_server",
71117+ .data = &grsec_enable_socket_server,
71118+ .maxlen = sizeof(int),
71119+ .mode = 0600,
71120+ .proc_handler = &proc_dointvec,
71121+ },
71122+ {
71123+ .procname = "socket_server_gid",
71124+ .data = &grsec_socket_server_gid,
71125+ .maxlen = sizeof(int),
71126+ .mode = 0600,
71127+ .proc_handler = &proc_dointvec,
71128+ },
71129+#endif
71130+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
71131+ {
71132+ .procname = "audit_group",
71133+ .data = &grsec_enable_group,
71134+ .maxlen = sizeof(int),
71135+ .mode = 0600,
71136+ .proc_handler = &proc_dointvec,
71137+ },
71138+ {
71139+ .procname = "audit_gid",
71140+ .data = &grsec_audit_gid,
71141+ .maxlen = sizeof(int),
71142+ .mode = 0600,
71143+ .proc_handler = &proc_dointvec,
71144+ },
71145+#endif
71146+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
71147+ {
71148+ .procname = "audit_chdir",
71149+ .data = &grsec_enable_chdir,
71150+ .maxlen = sizeof(int),
71151+ .mode = 0600,
71152+ .proc_handler = &proc_dointvec,
71153+ },
71154+#endif
71155+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
71156+ {
71157+ .procname = "audit_mount",
71158+ .data = &grsec_enable_mount,
71159+ .maxlen = sizeof(int),
71160+ .mode = 0600,
71161+ .proc_handler = &proc_dointvec,
71162+ },
71163+#endif
71164+#ifdef CONFIG_GRKERNSEC_DMESG
71165+ {
71166+ .procname = "dmesg",
71167+ .data = &grsec_enable_dmesg,
71168+ .maxlen = sizeof(int),
71169+ .mode = 0600,
71170+ .proc_handler = &proc_dointvec,
71171+ },
71172+#endif
71173+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
71174+ {
71175+ .procname = "chroot_findtask",
71176+ .data = &grsec_enable_chroot_findtask,
71177+ .maxlen = sizeof(int),
71178+ .mode = 0600,
71179+ .proc_handler = &proc_dointvec,
71180+ },
71181+#endif
71182+#ifdef CONFIG_GRKERNSEC_RESLOG
71183+ {
71184+ .procname = "resource_logging",
71185+ .data = &grsec_resource_logging,
71186+ .maxlen = sizeof(int),
71187+ .mode = 0600,
71188+ .proc_handler = &proc_dointvec,
71189+ },
71190+#endif
71191+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
71192+ {
71193+ .procname = "audit_ptrace",
71194+ .data = &grsec_enable_audit_ptrace,
71195+ .maxlen = sizeof(int),
71196+ .mode = 0600,
71197+ .proc_handler = &proc_dointvec,
71198+ },
71199+#endif
71200+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
71201+ {
71202+ .procname = "harden_ptrace",
71203+ .data = &grsec_enable_harden_ptrace,
71204+ .maxlen = sizeof(int),
71205+ .mode = 0600,
71206+ .proc_handler = &proc_dointvec,
71207+ },
71208+#endif
71209+ {
71210+ .procname = "grsec_lock",
71211+ .data = &grsec_lock,
71212+ .maxlen = sizeof(int),
71213+ .mode = 0600,
71214+ .proc_handler = &proc_dointvec,
71215+ },
71216+#endif
71217+#ifdef CONFIG_GRKERNSEC_ROFS
71218+ {
71219+ .procname = "romount_protect",
71220+ .data = &grsec_enable_rofs,
71221+ .maxlen = sizeof(int),
71222+ .mode = 0600,
71223+ .proc_handler = &proc_dointvec_minmax,
71224+ .extra1 = &one,
71225+ .extra2 = &one,
71226+ },
71227+#endif
71228+#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
71229+ {
71230+ .procname = "deny_new_usb",
71231+ .data = &grsec_deny_new_usb,
71232+ .maxlen = sizeof(int),
71233+ .mode = 0600,
71234+ .proc_handler = &proc_dointvec,
71235+ },
71236+#endif
71237+ { }
71238+};
71239+#endif
71240diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
71241new file mode 100644
71242index 0000000..0dc13c3
71243--- /dev/null
71244+++ b/grsecurity/grsec_time.c
71245@@ -0,0 +1,16 @@
71246+#include <linux/kernel.h>
71247+#include <linux/sched.h>
71248+#include <linux/grinternal.h>
71249+#include <linux/module.h>
71250+
71251+void
71252+gr_log_timechange(void)
71253+{
71254+#ifdef CONFIG_GRKERNSEC_TIME
71255+ if (grsec_enable_time)
71256+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
71257+#endif
71258+ return;
71259+}
71260+
71261+EXPORT_SYMBOL(gr_log_timechange);
71262diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
71263new file mode 100644
71264index 0000000..ee57dcf
71265--- /dev/null
71266+++ b/grsecurity/grsec_tpe.c
71267@@ -0,0 +1,73 @@
71268+#include <linux/kernel.h>
71269+#include <linux/sched.h>
71270+#include <linux/file.h>
71271+#include <linux/fs.h>
71272+#include <linux/grinternal.h>
71273+
71274+extern int gr_acl_tpe_check(void);
71275+
71276+int
71277+gr_tpe_allow(const struct file *file)
71278+{
71279+#ifdef CONFIG_GRKERNSEC
71280+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
71281+ const struct cred *cred = current_cred();
71282+ char *msg = NULL;
71283+ char *msg2 = NULL;
71284+
71285+ // never restrict root
71286+ if (gr_is_global_root(cred->uid))
71287+ return 1;
71288+
71289+ if (grsec_enable_tpe) {
71290+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
71291+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
71292+ msg = "not being in trusted group";
71293+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
71294+ msg = "being in untrusted group";
71295+#else
71296+ if (in_group_p(grsec_tpe_gid))
71297+ msg = "being in untrusted group";
71298+#endif
71299+ }
71300+ if (!msg && gr_acl_tpe_check())
71301+ msg = "being in untrusted role";
71302+
71303+ // not in any affected group/role
71304+ if (!msg)
71305+ goto next_check;
71306+
71307+ if (gr_is_global_nonroot(inode->i_uid))
71308+ msg2 = "file in non-root-owned directory";
71309+ else if (inode->i_mode & S_IWOTH)
71310+ msg2 = "file in world-writable directory";
71311+ else if (inode->i_mode & S_IWGRP)
71312+ msg2 = "file in group-writable directory";
71313+
71314+ if (msg && msg2) {
71315+ char fullmsg[70] = {0};
71316+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
71317+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
71318+ return 0;
71319+ }
71320+ msg = NULL;
71321+next_check:
71322+#ifdef CONFIG_GRKERNSEC_TPE_ALL
71323+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
71324+ return 1;
71325+
71326+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
71327+ msg = "directory not owned by user";
71328+ else if (inode->i_mode & S_IWOTH)
71329+ msg = "file in world-writable directory";
71330+ else if (inode->i_mode & S_IWGRP)
71331+ msg = "file in group-writable directory";
71332+
71333+ if (msg) {
71334+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
71335+ return 0;
71336+ }
71337+#endif
71338+#endif
71339+ return 1;
71340+}
71341diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
71342new file mode 100644
71343index 0000000..ae02d8e
71344--- /dev/null
71345+++ b/grsecurity/grsec_usb.c
71346@@ -0,0 +1,15 @@
71347+#include <linux/kernel.h>
71348+#include <linux/grinternal.h>
71349+#include <linux/module.h>
71350+
71351+int gr_handle_new_usb(void)
71352+{
71353+#ifdef CONFIG_GRKERNSEC_DENYUSB
71354+ if (grsec_deny_new_usb) {
71355+ printk(KERN_ALERT "grsec: denied insert of new USB device\n");
71356+ return 1;
71357+ }
71358+#endif
71359+ return 0;
71360+}
71361+EXPORT_SYMBOL_GPL(gr_handle_new_usb);
71362diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
71363new file mode 100644
71364index 0000000..9f7b1ac
71365--- /dev/null
71366+++ b/grsecurity/grsum.c
71367@@ -0,0 +1,61 @@
71368+#include <linux/err.h>
71369+#include <linux/kernel.h>
71370+#include <linux/sched.h>
71371+#include <linux/mm.h>
71372+#include <linux/scatterlist.h>
71373+#include <linux/crypto.h>
71374+#include <linux/gracl.h>
71375+
71376+
71377+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
71378+#error "crypto and sha256 must be built into the kernel"
71379+#endif
71380+
71381+int
71382+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
71383+{
71384+ char *p;
71385+ struct crypto_hash *tfm;
71386+ struct hash_desc desc;
71387+ struct scatterlist sg;
71388+ unsigned char temp_sum[GR_SHA_LEN];
71389+ volatile int retval = 0;
71390+ volatile int dummy = 0;
71391+ unsigned int i;
71392+
71393+ sg_init_table(&sg, 1);
71394+
71395+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
71396+ if (IS_ERR(tfm)) {
71397+ /* should never happen, since sha256 should be built in */
71398+ return 1;
71399+ }
71400+
71401+ desc.tfm = tfm;
71402+ desc.flags = 0;
71403+
71404+ crypto_hash_init(&desc);
71405+
71406+ p = salt;
71407+ sg_set_buf(&sg, p, GR_SALT_LEN);
71408+ crypto_hash_update(&desc, &sg, sg.length);
71409+
71410+ p = entry->pw;
71411+ sg_set_buf(&sg, p, strlen(p));
71412+
71413+ crypto_hash_update(&desc, &sg, sg.length);
71414+
71415+ crypto_hash_final(&desc, temp_sum);
71416+
71417+ memset(entry->pw, 0, GR_PW_LEN);
71418+
71419+ for (i = 0; i < GR_SHA_LEN; i++)
71420+ if (sum[i] != temp_sum[i])
71421+ retval = 1;
71422+ else
71423+ dummy = 1; // waste a cycle
71424+
71425+ crypto_free_hash(tfm);
71426+
71427+ return retval;
71428+}
71429diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
71430index 77ff547..181834f 100644
71431--- a/include/asm-generic/4level-fixup.h
71432+++ b/include/asm-generic/4level-fixup.h
71433@@ -13,8 +13,10 @@
71434 #define pmd_alloc(mm, pud, address) \
71435 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
71436 NULL: pmd_offset(pud, address))
71437+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
71438
71439 #define pud_alloc(mm, pgd, address) (pgd)
71440+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
71441 #define pud_offset(pgd, start) (pgd)
71442 #define pud_none(pud) 0
71443 #define pud_bad(pud) 0
71444diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
71445index b7babf0..04ad282 100644
71446--- a/include/asm-generic/atomic-long.h
71447+++ b/include/asm-generic/atomic-long.h
71448@@ -22,6 +22,12 @@
71449
71450 typedef atomic64_t atomic_long_t;
71451
71452+#ifdef CONFIG_PAX_REFCOUNT
71453+typedef atomic64_unchecked_t atomic_long_unchecked_t;
71454+#else
71455+typedef atomic64_t atomic_long_unchecked_t;
71456+#endif
71457+
71458 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
71459
71460 static inline long atomic_long_read(atomic_long_t *l)
71461@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
71462 return (long)atomic64_read(v);
71463 }
71464
71465+#ifdef CONFIG_PAX_REFCOUNT
71466+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
71467+{
71468+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71469+
71470+ return (long)atomic64_read_unchecked(v);
71471+}
71472+#endif
71473+
71474 static inline void atomic_long_set(atomic_long_t *l, long i)
71475 {
71476 atomic64_t *v = (atomic64_t *)l;
71477@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
71478 atomic64_set(v, i);
71479 }
71480
71481+#ifdef CONFIG_PAX_REFCOUNT
71482+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
71483+{
71484+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71485+
71486+ atomic64_set_unchecked(v, i);
71487+}
71488+#endif
71489+
71490 static inline void atomic_long_inc(atomic_long_t *l)
71491 {
71492 atomic64_t *v = (atomic64_t *)l;
71493@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
71494 atomic64_inc(v);
71495 }
71496
71497+#ifdef CONFIG_PAX_REFCOUNT
71498+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
71499+{
71500+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71501+
71502+ atomic64_inc_unchecked(v);
71503+}
71504+#endif
71505+
71506 static inline void atomic_long_dec(atomic_long_t *l)
71507 {
71508 atomic64_t *v = (atomic64_t *)l;
71509@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
71510 atomic64_dec(v);
71511 }
71512
71513+#ifdef CONFIG_PAX_REFCOUNT
71514+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
71515+{
71516+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71517+
71518+ atomic64_dec_unchecked(v);
71519+}
71520+#endif
71521+
71522 static inline void atomic_long_add(long i, atomic_long_t *l)
71523 {
71524 atomic64_t *v = (atomic64_t *)l;
71525@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
71526 atomic64_add(i, v);
71527 }
71528
71529+#ifdef CONFIG_PAX_REFCOUNT
71530+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
71531+{
71532+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71533+
71534+ atomic64_add_unchecked(i, v);
71535+}
71536+#endif
71537+
71538 static inline void atomic_long_sub(long i, atomic_long_t *l)
71539 {
71540 atomic64_t *v = (atomic64_t *)l;
71541@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
71542 atomic64_sub(i, v);
71543 }
71544
71545+#ifdef CONFIG_PAX_REFCOUNT
71546+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
71547+{
71548+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71549+
71550+ atomic64_sub_unchecked(i, v);
71551+}
71552+#endif
71553+
71554 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
71555 {
71556 atomic64_t *v = (atomic64_t *)l;
71557@@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
71558 return (long)atomic64_add_return(i, v);
71559 }
71560
71561+#ifdef CONFIG_PAX_REFCOUNT
71562+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
71563+{
71564+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71565+
71566+ return (long)atomic64_add_return_unchecked(i, v);
71567+}
71568+#endif
71569+
71570 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
71571 {
71572 atomic64_t *v = (atomic64_t *)l;
71573@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
71574 return (long)atomic64_inc_return(v);
71575 }
71576
71577+#ifdef CONFIG_PAX_REFCOUNT
71578+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
71579+{
71580+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71581+
71582+ return (long)atomic64_inc_return_unchecked(v);
71583+}
71584+#endif
71585+
71586 static inline long atomic_long_dec_return(atomic_long_t *l)
71587 {
71588 atomic64_t *v = (atomic64_t *)l;
71589@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
71590
71591 typedef atomic_t atomic_long_t;
71592
71593+#ifdef CONFIG_PAX_REFCOUNT
71594+typedef atomic_unchecked_t atomic_long_unchecked_t;
71595+#else
71596+typedef atomic_t atomic_long_unchecked_t;
71597+#endif
71598+
71599 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
71600 static inline long atomic_long_read(atomic_long_t *l)
71601 {
71602@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
71603 return (long)atomic_read(v);
71604 }
71605
71606+#ifdef CONFIG_PAX_REFCOUNT
71607+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
71608+{
71609+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71610+
71611+ return (long)atomic_read_unchecked(v);
71612+}
71613+#endif
71614+
71615 static inline void atomic_long_set(atomic_long_t *l, long i)
71616 {
71617 atomic_t *v = (atomic_t *)l;
71618@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
71619 atomic_set(v, i);
71620 }
71621
71622+#ifdef CONFIG_PAX_REFCOUNT
71623+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
71624+{
71625+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71626+
71627+ atomic_set_unchecked(v, i);
71628+}
71629+#endif
71630+
71631 static inline void atomic_long_inc(atomic_long_t *l)
71632 {
71633 atomic_t *v = (atomic_t *)l;
71634@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
71635 atomic_inc(v);
71636 }
71637
71638+#ifdef CONFIG_PAX_REFCOUNT
71639+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
71640+{
71641+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71642+
71643+ atomic_inc_unchecked(v);
71644+}
71645+#endif
71646+
71647 static inline void atomic_long_dec(atomic_long_t *l)
71648 {
71649 atomic_t *v = (atomic_t *)l;
71650@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
71651 atomic_dec(v);
71652 }
71653
71654+#ifdef CONFIG_PAX_REFCOUNT
71655+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
71656+{
71657+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71658+
71659+ atomic_dec_unchecked(v);
71660+}
71661+#endif
71662+
71663 static inline void atomic_long_add(long i, atomic_long_t *l)
71664 {
71665 atomic_t *v = (atomic_t *)l;
71666@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
71667 atomic_add(i, v);
71668 }
71669
71670+#ifdef CONFIG_PAX_REFCOUNT
71671+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
71672+{
71673+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71674+
71675+ atomic_add_unchecked(i, v);
71676+}
71677+#endif
71678+
71679 static inline void atomic_long_sub(long i, atomic_long_t *l)
71680 {
71681 atomic_t *v = (atomic_t *)l;
71682@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
71683 atomic_sub(i, v);
71684 }
71685
71686+#ifdef CONFIG_PAX_REFCOUNT
71687+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
71688+{
71689+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71690+
71691+ atomic_sub_unchecked(i, v);
71692+}
71693+#endif
71694+
71695 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
71696 {
71697 atomic_t *v = (atomic_t *)l;
71698@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
71699 return (long)atomic_add_return(i, v);
71700 }
71701
71702+#ifdef CONFIG_PAX_REFCOUNT
71703+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
71704+{
71705+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71706+
71707+ return (long)atomic_add_return_unchecked(i, v);
71708+}
71709+
71710+#endif
71711+
71712 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
71713 {
71714 atomic_t *v = (atomic_t *)l;
71715@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
71716 return (long)atomic_inc_return(v);
71717 }
71718
71719+#ifdef CONFIG_PAX_REFCOUNT
71720+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
71721+{
71722+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71723+
71724+ return (long)atomic_inc_return_unchecked(v);
71725+}
71726+#endif
71727+
71728 static inline long atomic_long_dec_return(atomic_long_t *l)
71729 {
71730 atomic_t *v = (atomic_t *)l;
71731@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
71732
71733 #endif /* BITS_PER_LONG == 64 */
71734
71735+#ifdef CONFIG_PAX_REFCOUNT
71736+static inline void pax_refcount_needs_these_functions(void)
71737+{
71738+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
71739+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
71740+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
71741+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
71742+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
71743+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
71744+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
71745+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
71746+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
71747+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
71748+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
71749+#ifdef CONFIG_X86
71750+ atomic_clear_mask_unchecked(0, NULL);
71751+ atomic_set_mask_unchecked(0, NULL);
71752+#endif
71753+
71754+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
71755+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
71756+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
71757+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
71758+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
71759+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
71760+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
71761+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
71762+}
71763+#else
71764+#define atomic_read_unchecked(v) atomic_read(v)
71765+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
71766+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
71767+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
71768+#define atomic_inc_unchecked(v) atomic_inc(v)
71769+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
71770+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
71771+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
71772+#define atomic_dec_unchecked(v) atomic_dec(v)
71773+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
71774+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
71775+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
71776+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
71777+
71778+#define atomic_long_read_unchecked(v) atomic_long_read(v)
71779+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
71780+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
71781+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
71782+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
71783+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
71784+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
71785+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
71786+#endif
71787+
71788 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
71789diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
71790index 33bd2de..f31bff97 100644
71791--- a/include/asm-generic/atomic.h
71792+++ b/include/asm-generic/atomic.h
71793@@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
71794 * Atomically clears the bits set in @mask from @v
71795 */
71796 #ifndef atomic_clear_mask
71797-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
71798+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
71799 {
71800 unsigned long flags;
71801
71802diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
71803index b18ce4f..2ee2843 100644
71804--- a/include/asm-generic/atomic64.h
71805+++ b/include/asm-generic/atomic64.h
71806@@ -16,6 +16,8 @@ typedef struct {
71807 long long counter;
71808 } atomic64_t;
71809
71810+typedef atomic64_t atomic64_unchecked_t;
71811+
71812 #define ATOMIC64_INIT(i) { (i) }
71813
71814 extern long long atomic64_read(const atomic64_t *v);
71815@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
71816 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
71817 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
71818
71819+#define atomic64_read_unchecked(v) atomic64_read(v)
71820+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
71821+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
71822+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
71823+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
71824+#define atomic64_inc_unchecked(v) atomic64_inc(v)
71825+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
71826+#define atomic64_dec_unchecked(v) atomic64_dec(v)
71827+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
71828+
71829 #endif /* _ASM_GENERIC_ATOMIC64_H */
71830diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
71831index 1bfcfe5..e04c5c9 100644
71832--- a/include/asm-generic/cache.h
71833+++ b/include/asm-generic/cache.h
71834@@ -6,7 +6,7 @@
71835 * cache lines need to provide their own cache.h.
71836 */
71837
71838-#define L1_CACHE_SHIFT 5
71839-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
71840+#define L1_CACHE_SHIFT 5UL
71841+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
71842
71843 #endif /* __ASM_GENERIC_CACHE_H */
71844diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
71845index 0d68a1e..b74a761 100644
71846--- a/include/asm-generic/emergency-restart.h
71847+++ b/include/asm-generic/emergency-restart.h
71848@@ -1,7 +1,7 @@
71849 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
71850 #define _ASM_GENERIC_EMERGENCY_RESTART_H
71851
71852-static inline void machine_emergency_restart(void)
71853+static inline __noreturn void machine_emergency_restart(void)
71854 {
71855 machine_restart(NULL);
71856 }
71857diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
71858index 90f99c7..00ce236 100644
71859--- a/include/asm-generic/kmap_types.h
71860+++ b/include/asm-generic/kmap_types.h
71861@@ -2,9 +2,9 @@
71862 #define _ASM_GENERIC_KMAP_TYPES_H
71863
71864 #ifdef __WITH_KM_FENCE
71865-# define KM_TYPE_NR 41
71866+# define KM_TYPE_NR 42
71867 #else
71868-# define KM_TYPE_NR 20
71869+# define KM_TYPE_NR 21
71870 #endif
71871
71872 #endif
71873diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
71874index 9ceb03b..62b0b8f 100644
71875--- a/include/asm-generic/local.h
71876+++ b/include/asm-generic/local.h
71877@@ -23,24 +23,37 @@ typedef struct
71878 atomic_long_t a;
71879 } local_t;
71880
71881+typedef struct {
71882+ atomic_long_unchecked_t a;
71883+} local_unchecked_t;
71884+
71885 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
71886
71887 #define local_read(l) atomic_long_read(&(l)->a)
71888+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
71889 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
71890+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
71891 #define local_inc(l) atomic_long_inc(&(l)->a)
71892+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
71893 #define local_dec(l) atomic_long_dec(&(l)->a)
71894+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
71895 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
71896+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
71897 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
71898+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
71899
71900 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
71901 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
71902 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
71903 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
71904 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
71905+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
71906 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
71907 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
71908+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
71909
71910 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
71911+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
71912 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
71913 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
71914 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
71915diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
71916index 725612b..9cc513a 100644
71917--- a/include/asm-generic/pgtable-nopmd.h
71918+++ b/include/asm-generic/pgtable-nopmd.h
71919@@ -1,14 +1,19 @@
71920 #ifndef _PGTABLE_NOPMD_H
71921 #define _PGTABLE_NOPMD_H
71922
71923-#ifndef __ASSEMBLY__
71924-
71925 #include <asm-generic/pgtable-nopud.h>
71926
71927-struct mm_struct;
71928-
71929 #define __PAGETABLE_PMD_FOLDED
71930
71931+#define PMD_SHIFT PUD_SHIFT
71932+#define PTRS_PER_PMD 1
71933+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
71934+#define PMD_MASK (~(PMD_SIZE-1))
71935+
71936+#ifndef __ASSEMBLY__
71937+
71938+struct mm_struct;
71939+
71940 /*
71941 * Having the pmd type consist of a pud gets the size right, and allows
71942 * us to conceptually access the pud entry that this pmd is folded into
71943@@ -16,11 +21,6 @@ struct mm_struct;
71944 */
71945 typedef struct { pud_t pud; } pmd_t;
71946
71947-#define PMD_SHIFT PUD_SHIFT
71948-#define PTRS_PER_PMD 1
71949-#define PMD_SIZE (1UL << PMD_SHIFT)
71950-#define PMD_MASK (~(PMD_SIZE-1))
71951-
71952 /*
71953 * The "pud_xxx()" functions here are trivial for a folded two-level
71954 * setup: the pmd is never bad, and a pmd always exists (as it's folded
71955diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
71956index 810431d..0ec4804f 100644
71957--- a/include/asm-generic/pgtable-nopud.h
71958+++ b/include/asm-generic/pgtable-nopud.h
71959@@ -1,10 +1,15 @@
71960 #ifndef _PGTABLE_NOPUD_H
71961 #define _PGTABLE_NOPUD_H
71962
71963-#ifndef __ASSEMBLY__
71964-
71965 #define __PAGETABLE_PUD_FOLDED
71966
71967+#define PUD_SHIFT PGDIR_SHIFT
71968+#define PTRS_PER_PUD 1
71969+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
71970+#define PUD_MASK (~(PUD_SIZE-1))
71971+
71972+#ifndef __ASSEMBLY__
71973+
71974 /*
71975 * Having the pud type consist of a pgd gets the size right, and allows
71976 * us to conceptually access the pgd entry that this pud is folded into
71977@@ -12,11 +17,6 @@
71978 */
71979 typedef struct { pgd_t pgd; } pud_t;
71980
71981-#define PUD_SHIFT PGDIR_SHIFT
71982-#define PTRS_PER_PUD 1
71983-#define PUD_SIZE (1UL << PUD_SHIFT)
71984-#define PUD_MASK (~(PUD_SIZE-1))
71985-
71986 /*
71987 * The "pgd_xxx()" functions here are trivial for a folded two-level
71988 * setup: the pud is never bad, and a pud always exists (as it's folded
71989@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
71990 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
71991
71992 #define pgd_populate(mm, pgd, pud) do { } while (0)
71993+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
71994 /*
71995 * (puds are folded into pgds so this doesn't get actually called,
71996 * but the define is needed for a generic inline function.)
71997diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
71998index 0807ddf..cd67747 100644
71999--- a/include/asm-generic/pgtable.h
72000+++ b/include/asm-generic/pgtable.h
72001@@ -741,6 +741,22 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
72002 }
72003 #endif /* CONFIG_NUMA_BALANCING */
72004
72005+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
72006+#ifdef CONFIG_PAX_KERNEXEC
72007+#error KERNEXEC requires pax_open_kernel
72008+#else
72009+static inline unsigned long pax_open_kernel(void) { return 0; }
72010+#endif
72011+#endif
72012+
72013+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
72014+#ifdef CONFIG_PAX_KERNEXEC
72015+#error KERNEXEC requires pax_close_kernel
72016+#else
72017+static inline unsigned long pax_close_kernel(void) { return 0; }
72018+#endif
72019+#endif
72020+
72021 #endif /* CONFIG_MMU */
72022
72023 #endif /* !__ASSEMBLY__ */
72024diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
72025index dc1269c..48a4f51 100644
72026--- a/include/asm-generic/uaccess.h
72027+++ b/include/asm-generic/uaccess.h
72028@@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
72029 return __clear_user(to, n);
72030 }
72031
72032+#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
72033+#ifdef CONFIG_PAX_MEMORY_UDEREF
72034+#error UDEREF requires pax_open_userland
72035+#else
72036+static inline unsigned long pax_open_userland(void) { return 0; }
72037+#endif
72038+#endif
72039+
72040+#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
72041+#ifdef CONFIG_PAX_MEMORY_UDEREF
72042+#error UDEREF requires pax_close_userland
72043+#else
72044+static inline unsigned long pax_close_userland(void) { return 0; }
72045+#endif
72046+#endif
72047+
72048 #endif /* __ASM_GENERIC_UACCESS_H */
72049diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
72050index 69732d2..cbe16d9 100644
72051--- a/include/asm-generic/vmlinux.lds.h
72052+++ b/include/asm-generic/vmlinux.lds.h
72053@@ -227,6 +227,7 @@
72054 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
72055 VMLINUX_SYMBOL(__start_rodata) = .; \
72056 *(.rodata) *(.rodata.*) \
72057+ *(.data..read_only) \
72058 *(__vermagic) /* Kernel version magic */ \
72059 . = ALIGN(8); \
72060 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
72061@@ -710,17 +711,18 @@
72062 * section in the linker script will go there too. @phdr should have
72063 * a leading colon.
72064 *
72065- * Note that this macros defines __per_cpu_load as an absolute symbol.
72066+ * Note that this macros defines per_cpu_load as an absolute symbol.
72067 * If there is no need to put the percpu section at a predetermined
72068 * address, use PERCPU_SECTION.
72069 */
72070 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
72071- VMLINUX_SYMBOL(__per_cpu_load) = .; \
72072- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
72073+ per_cpu_load = .; \
72074+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
72075 - LOAD_OFFSET) { \
72076+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
72077 PERCPU_INPUT(cacheline) \
72078 } phdr \
72079- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
72080+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
72081
72082 /**
72083 * PERCPU_SECTION - define output section for percpu area, simple version
72084diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
72085index 418d270..bfd2794 100644
72086--- a/include/crypto/algapi.h
72087+++ b/include/crypto/algapi.h
72088@@ -34,7 +34,7 @@ struct crypto_type {
72089 unsigned int maskclear;
72090 unsigned int maskset;
72091 unsigned int tfmsize;
72092-};
72093+} __do_const;
72094
72095 struct crypto_instance {
72096 struct crypto_alg alg;
72097diff --git a/include/drm/drmP.h b/include/drm/drmP.h
72098index 12083dc..39740ec 100644
72099--- a/include/drm/drmP.h
72100+++ b/include/drm/drmP.h
72101@@ -69,6 +69,7 @@
72102 #include <linux/workqueue.h>
72103 #include <linux/poll.h>
72104 #include <asm/pgalloc.h>
72105+#include <asm/local.h>
72106 #include <drm/drm.h>
72107 #include <drm/drm_sarea.h>
72108
72109@@ -293,10 +294,12 @@ do { \
72110 * \param cmd command.
72111 * \param arg argument.
72112 */
72113-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
72114+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
72115+ struct drm_file *file_priv);
72116+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
72117 struct drm_file *file_priv);
72118
72119-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
72120+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
72121 unsigned long arg);
72122
72123 #define DRM_IOCTL_NR(n) _IOC_NR(n)
72124@@ -311,10 +314,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
72125 struct drm_ioctl_desc {
72126 unsigned int cmd;
72127 int flags;
72128- drm_ioctl_t *func;
72129+ drm_ioctl_t func;
72130 unsigned int cmd_drv;
72131 const char *name;
72132-};
72133+} __do_const;
72134
72135 /**
72136 * Creates a driver or general drm_ioctl_desc array entry for the given
72137@@ -1015,7 +1018,7 @@ struct drm_info_list {
72138 int (*show)(struct seq_file*, void*); /** show callback */
72139 u32 driver_features; /**< Required driver features for this entry */
72140 void *data;
72141-};
72142+} __do_const;
72143
72144 /**
72145 * debugfs node structure. This structure represents a debugfs file.
72146@@ -1088,7 +1091,7 @@ struct drm_device {
72147
72148 /** \name Usage Counters */
72149 /*@{ */
72150- int open_count; /**< Outstanding files open */
72151+ local_t open_count; /**< Outstanding files open */
72152 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
72153 atomic_t vma_count; /**< Outstanding vma areas open */
72154 int buf_use; /**< Buffers in use -- cannot alloc */
72155@@ -1099,7 +1102,7 @@ struct drm_device {
72156 /*@{ */
72157 unsigned long counters;
72158 enum drm_stat_type types[15];
72159- atomic_t counts[15];
72160+ atomic_unchecked_t counts[15];
72161 /*@} */
72162
72163 struct list_head filelist;
72164diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
72165index f43d556..94d9343 100644
72166--- a/include/drm/drm_crtc_helper.h
72167+++ b/include/drm/drm_crtc_helper.h
72168@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
72169 struct drm_connector *connector);
72170 /* disable encoder when not in use - more explicit than dpms off */
72171 void (*disable)(struct drm_encoder *encoder);
72172-};
72173+} __no_const;
72174
72175 /**
72176 * drm_connector_helper_funcs - helper operations for connectors
72177diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
72178index 72dcbe8..8db58d7 100644
72179--- a/include/drm/ttm/ttm_memory.h
72180+++ b/include/drm/ttm/ttm_memory.h
72181@@ -48,7 +48,7 @@
72182
72183 struct ttm_mem_shrink {
72184 int (*do_shrink) (struct ttm_mem_shrink *);
72185-};
72186+} __no_const;
72187
72188 /**
72189 * struct ttm_mem_global - Global memory accounting structure.
72190diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
72191index 4b840e8..155d235 100644
72192--- a/include/keys/asymmetric-subtype.h
72193+++ b/include/keys/asymmetric-subtype.h
72194@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
72195 /* Verify the signature on a key of this subtype (optional) */
72196 int (*verify_signature)(const struct key *key,
72197 const struct public_key_signature *sig);
72198-};
72199+} __do_const;
72200
72201 /**
72202 * asymmetric_key_subtype - Get the subtype from an asymmetric key
72203diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
72204index c1da539..1dcec55 100644
72205--- a/include/linux/atmdev.h
72206+++ b/include/linux/atmdev.h
72207@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
72208 #endif
72209
72210 struct k_atm_aal_stats {
72211-#define __HANDLE_ITEM(i) atomic_t i
72212+#define __HANDLE_ITEM(i) atomic_unchecked_t i
72213 __AAL_STAT_ITEMS
72214 #undef __HANDLE_ITEM
72215 };
72216@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
72217 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
72218 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
72219 struct module *owner;
72220-};
72221+} __do_const ;
72222
72223 struct atmphy_ops {
72224 int (*start)(struct atm_dev *dev);
72225diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
72226index 70cf138..0418ee2 100644
72227--- a/include/linux/binfmts.h
72228+++ b/include/linux/binfmts.h
72229@@ -73,8 +73,10 @@ struct linux_binfmt {
72230 int (*load_binary)(struct linux_binprm *);
72231 int (*load_shlib)(struct file *);
72232 int (*core_dump)(struct coredump_params *cprm);
72233+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
72234+ void (*handle_mmap)(struct file *);
72235 unsigned long min_coredump; /* minimal dump size */
72236-};
72237+} __do_const;
72238
72239 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
72240
72241diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
72242index 2fdb4a4..54aad7e 100644
72243--- a/include/linux/blkdev.h
72244+++ b/include/linux/blkdev.h
72245@@ -1526,7 +1526,7 @@ struct block_device_operations {
72246 /* this callback is with swap_lock and sometimes page table lock held */
72247 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
72248 struct module *owner;
72249-};
72250+} __do_const;
72251
72252 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
72253 unsigned long);
72254diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
72255index 7c2e030..b72475d 100644
72256--- a/include/linux/blktrace_api.h
72257+++ b/include/linux/blktrace_api.h
72258@@ -23,7 +23,7 @@ struct blk_trace {
72259 struct dentry *dir;
72260 struct dentry *dropped_file;
72261 struct dentry *msg_file;
72262- atomic_t dropped;
72263+ atomic_unchecked_t dropped;
72264 };
72265
72266 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
72267diff --git a/include/linux/cache.h b/include/linux/cache.h
72268index 4c57065..40346da 100644
72269--- a/include/linux/cache.h
72270+++ b/include/linux/cache.h
72271@@ -16,6 +16,14 @@
72272 #define __read_mostly
72273 #endif
72274
72275+#ifndef __read_only
72276+#ifdef CONFIG_PAX_KERNEXEC
72277+#error KERNEXEC requires __read_only
72278+#else
72279+#define __read_only __read_mostly
72280+#endif
72281+#endif
72282+
72283 #ifndef ____cacheline_aligned
72284 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
72285 #endif
72286diff --git a/include/linux/capability.h b/include/linux/capability.h
72287index d9a4f7f4..19f77d6 100644
72288--- a/include/linux/capability.h
72289+++ b/include/linux/capability.h
72290@@ -213,8 +213,13 @@ extern bool ns_capable(struct user_namespace *ns, int cap);
72291 extern bool nsown_capable(int cap);
72292 extern bool inode_capable(const struct inode *inode, int cap);
72293 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
72294+extern bool capable_nolog(int cap);
72295+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
72296+extern bool inode_capable_nolog(const struct inode *inode, int cap);
72297
72298 /* audit system wants to get cap info from files as well */
72299 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
72300
72301+extern int is_privileged_binary(const struct dentry *dentry);
72302+
72303 #endif /* !_LINUX_CAPABILITY_H */
72304diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
72305index 8609d57..86e4d79 100644
72306--- a/include/linux/cdrom.h
72307+++ b/include/linux/cdrom.h
72308@@ -87,7 +87,6 @@ struct cdrom_device_ops {
72309
72310 /* driver specifications */
72311 const int capability; /* capability flags */
72312- int n_minors; /* number of active minor devices */
72313 /* handle uniform packets for scsi type devices (scsi,atapi) */
72314 int (*generic_packet) (struct cdrom_device_info *,
72315 struct packet_command *);
72316diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
72317index 4ce9056..86caac6 100644
72318--- a/include/linux/cleancache.h
72319+++ b/include/linux/cleancache.h
72320@@ -31,7 +31,7 @@ struct cleancache_ops {
72321 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
72322 void (*invalidate_inode)(int, struct cleancache_filekey);
72323 void (*invalidate_fs)(int);
72324-};
72325+} __no_const;
72326
72327 extern struct cleancache_ops *
72328 cleancache_register_ops(struct cleancache_ops *ops);
72329diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
72330index 1ec14a7..d0654a2 100644
72331--- a/include/linux/clk-provider.h
72332+++ b/include/linux/clk-provider.h
72333@@ -132,6 +132,7 @@ struct clk_ops {
72334 unsigned long);
72335 void (*init)(struct clk_hw *hw);
72336 };
72337+typedef struct clk_ops __no_const clk_ops_no_const;
72338
72339 /**
72340 * struct clk_init_data - holds init data that's common to all clocks and is
72341diff --git a/include/linux/compat.h b/include/linux/compat.h
72342index ec1aee4..1077986 100644
72343--- a/include/linux/compat.h
72344+++ b/include/linux/compat.h
72345@@ -312,7 +312,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
72346 compat_size_t __user *len_ptr);
72347
72348 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
72349-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
72350+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
72351 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
72352 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
72353 compat_ssize_t msgsz, int msgflg);
72354@@ -419,7 +419,7 @@ extern int compat_ptrace_request(struct task_struct *child,
72355 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
72356 compat_ulong_t addr, compat_ulong_t data);
72357 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
72358- compat_long_t addr, compat_long_t data);
72359+ compat_ulong_t addr, compat_ulong_t data);
72360
72361 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, size_t);
72362 /*
72363diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
72364index ded4299..da50e3b 100644
72365--- a/include/linux/compiler-gcc4.h
72366+++ b/include/linux/compiler-gcc4.h
72367@@ -39,9 +39,29 @@
72368 # define __compiletime_warning(message) __attribute__((warning(message)))
72369 # define __compiletime_error(message) __attribute__((error(message)))
72370 #endif /* __CHECKER__ */
72371+
72372+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
72373+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
72374+#define __bos0(ptr) __bos((ptr), 0)
72375+#define __bos1(ptr) __bos((ptr), 1)
72376 #endif /* GCC_VERSION >= 40300 */
72377
72378 #if GCC_VERSION >= 40500
72379+
72380+#ifdef CONSTIFY_PLUGIN
72381+#define __no_const __attribute__((no_const))
72382+#define __do_const __attribute__((do_const))
72383+#endif
72384+
72385+#ifdef SIZE_OVERFLOW_PLUGIN
72386+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
72387+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
72388+#endif
72389+
72390+#ifdef LATENT_ENTROPY_PLUGIN
72391+#define __latent_entropy __attribute__((latent_entropy))
72392+#endif
72393+
72394 /*
72395 * Mark a position in code as unreachable. This can be used to
72396 * suppress control flow warnings after asm blocks that transfer
72397diff --git a/include/linux/compiler.h b/include/linux/compiler.h
72398index 92669cd..1771a15 100644
72399--- a/include/linux/compiler.h
72400+++ b/include/linux/compiler.h
72401@@ -5,11 +5,14 @@
72402
72403 #ifdef __CHECKER__
72404 # define __user __attribute__((noderef, address_space(1)))
72405+# define __force_user __force __user
72406 # define __kernel __attribute__((address_space(0)))
72407+# define __force_kernel __force __kernel
72408 # define __safe __attribute__((safe))
72409 # define __force __attribute__((force))
72410 # define __nocast __attribute__((nocast))
72411 # define __iomem __attribute__((noderef, address_space(2)))
72412+# define __force_iomem __force __iomem
72413 # define __must_hold(x) __attribute__((context(x,1,1)))
72414 # define __acquires(x) __attribute__((context(x,0,1)))
72415 # define __releases(x) __attribute__((context(x,1,0)))
72416@@ -17,20 +20,37 @@
72417 # define __release(x) __context__(x,-1)
72418 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
72419 # define __percpu __attribute__((noderef, address_space(3)))
72420+# define __force_percpu __force __percpu
72421 #ifdef CONFIG_SPARSE_RCU_POINTER
72422 # define __rcu __attribute__((noderef, address_space(4)))
72423+# define __force_rcu __force __rcu
72424 #else
72425 # define __rcu
72426+# define __force_rcu
72427 #endif
72428 extern void __chk_user_ptr(const volatile void __user *);
72429 extern void __chk_io_ptr(const volatile void __iomem *);
72430 #else
72431-# define __user
72432-# define __kernel
72433+# ifdef CHECKER_PLUGIN
72434+//# define __user
72435+//# define __force_user
72436+//# define __kernel
72437+//# define __force_kernel
72438+# else
72439+# ifdef STRUCTLEAK_PLUGIN
72440+# define __user __attribute__((user))
72441+# else
72442+# define __user
72443+# endif
72444+# define __force_user
72445+# define __kernel
72446+# define __force_kernel
72447+# endif
72448 # define __safe
72449 # define __force
72450 # define __nocast
72451 # define __iomem
72452+# define __force_iomem
72453 # define __chk_user_ptr(x) (void)0
72454 # define __chk_io_ptr(x) (void)0
72455 # define __builtin_warning(x, y...) (1)
72456@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
72457 # define __release(x) (void)0
72458 # define __cond_lock(x,c) (c)
72459 # define __percpu
72460+# define __force_percpu
72461 # define __rcu
72462+# define __force_rcu
72463 #endif
72464
72465 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
72466@@ -275,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
72467 # define __attribute_const__ /* unimplemented */
72468 #endif
72469
72470+#ifndef __no_const
72471+# define __no_const
72472+#endif
72473+
72474+#ifndef __do_const
72475+# define __do_const
72476+#endif
72477+
72478+#ifndef __size_overflow
72479+# define __size_overflow(...)
72480+#endif
72481+
72482+#ifndef __intentional_overflow
72483+# define __intentional_overflow(...)
72484+#endif
72485+
72486+#ifndef __latent_entropy
72487+# define __latent_entropy
72488+#endif
72489+
72490 /*
72491 * Tell gcc if a function is cold. The compiler will assume any path
72492 * directly leading to the call is unlikely.
72493@@ -284,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
72494 #define __cold
72495 #endif
72496
72497+#ifndef __alloc_size
72498+#define __alloc_size(...)
72499+#endif
72500+
72501+#ifndef __bos
72502+#define __bos(ptr, arg)
72503+#endif
72504+
72505+#ifndef __bos0
72506+#define __bos0(ptr)
72507+#endif
72508+
72509+#ifndef __bos1
72510+#define __bos1(ptr)
72511+#endif
72512+
72513 /* Simple shorthand for a section definition */
72514 #ifndef __section
72515 # define __section(S) __attribute__ ((__section__(#S)))
72516@@ -349,7 +407,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
72517 * use is to mediate communication between process-level code and irq/NMI
72518 * handlers, all running on the same CPU.
72519 */
72520-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
72521+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
72522+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
72523
72524 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
72525 #ifdef CONFIG_KPROBES
72526diff --git a/include/linux/completion.h b/include/linux/completion.h
72527index 3cd574d..adce5fa 100644
72528--- a/include/linux/completion.h
72529+++ b/include/linux/completion.h
72530@@ -79,15 +79,15 @@ static inline void init_completion(struct completion *x)
72531 extern void wait_for_completion(struct completion *);
72532 extern void wait_for_completion_io(struct completion *);
72533 extern int wait_for_completion_interruptible(struct completion *x);
72534-extern int wait_for_completion_killable(struct completion *x);
72535+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
72536 extern unsigned long wait_for_completion_timeout(struct completion *x,
72537 unsigned long timeout);
72538 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
72539 unsigned long timeout);
72540 extern long wait_for_completion_interruptible_timeout(
72541- struct completion *x, unsigned long timeout);
72542+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
72543 extern long wait_for_completion_killable_timeout(
72544- struct completion *x, unsigned long timeout);
72545+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
72546 extern bool try_wait_for_completion(struct completion *x);
72547 extern bool completion_done(struct completion *x);
72548
72549diff --git a/include/linux/configfs.h b/include/linux/configfs.h
72550index 34025df..d94bbbc 100644
72551--- a/include/linux/configfs.h
72552+++ b/include/linux/configfs.h
72553@@ -125,7 +125,7 @@ struct configfs_attribute {
72554 const char *ca_name;
72555 struct module *ca_owner;
72556 umode_t ca_mode;
72557-};
72558+} __do_const;
72559
72560 /*
72561 * Users often need to create attribute structures for their configurable
72562diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
72563index 90d5a15..950cb80 100644
72564--- a/include/linux/cpufreq.h
72565+++ b/include/linux/cpufreq.h
72566@@ -266,7 +266,7 @@ struct cpufreq_driver {
72567 int (*suspend) (struct cpufreq_policy *policy);
72568 int (*resume) (struct cpufreq_policy *policy);
72569 struct freq_attr **attr;
72570-};
72571+} __do_const;
72572
72573 /* flags */
72574
72575@@ -325,6 +325,7 @@ struct global_attr {
72576 ssize_t (*store)(struct kobject *a, struct attribute *b,
72577 const char *c, size_t count);
72578 };
72579+typedef struct global_attr __no_const global_attr_no_const;
72580
72581 #define define_one_global_ro(_name) \
72582 static struct global_attr _name = \
72583diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
72584index 0bc4b74..973b368 100644
72585--- a/include/linux/cpuidle.h
72586+++ b/include/linux/cpuidle.h
72587@@ -52,7 +52,8 @@ struct cpuidle_state {
72588 int index);
72589
72590 int (*enter_dead) (struct cpuidle_device *dev, int index);
72591-};
72592+} __do_const;
72593+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
72594
72595 /* Idle State Flags */
72596 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
72597@@ -191,7 +192,7 @@ struct cpuidle_governor {
72598 void (*reflect) (struct cpuidle_device *dev, int index);
72599
72600 struct module *owner;
72601-};
72602+} __do_const;
72603
72604 #ifdef CONFIG_CPU_IDLE
72605
72606diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
72607index d08e4d2..95fad61 100644
72608--- a/include/linux/cpumask.h
72609+++ b/include/linux/cpumask.h
72610@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
72611 }
72612
72613 /* Valid inputs for n are -1 and 0. */
72614-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
72615+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
72616 {
72617 return n+1;
72618 }
72619
72620-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
72621+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
72622 {
72623 return n+1;
72624 }
72625
72626-static inline unsigned int cpumask_next_and(int n,
72627+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
72628 const struct cpumask *srcp,
72629 const struct cpumask *andp)
72630 {
72631@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
72632 *
72633 * Returns >= nr_cpu_ids if no further cpus set.
72634 */
72635-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
72636+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
72637 {
72638 /* -1 is a legal arg here. */
72639 if (n != -1)
72640@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
72641 *
72642 * Returns >= nr_cpu_ids if no further cpus unset.
72643 */
72644-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
72645+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
72646 {
72647 /* -1 is a legal arg here. */
72648 if (n != -1)
72649@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
72650 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
72651 }
72652
72653-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
72654+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
72655 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
72656
72657 /**
72658diff --git a/include/linux/cred.h b/include/linux/cred.h
72659index 04421e8..6bce4ef 100644
72660--- a/include/linux/cred.h
72661+++ b/include/linux/cred.h
72662@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
72663 static inline void validate_process_creds(void)
72664 {
72665 }
72666+static inline void validate_task_creds(struct task_struct *task)
72667+{
72668+}
72669 #endif
72670
72671 /**
72672diff --git a/include/linux/crypto.h b/include/linux/crypto.h
72673index b92eadf..b4ecdc1 100644
72674--- a/include/linux/crypto.h
72675+++ b/include/linux/crypto.h
72676@@ -373,7 +373,7 @@ struct cipher_tfm {
72677 const u8 *key, unsigned int keylen);
72678 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
72679 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
72680-};
72681+} __no_const;
72682
72683 struct hash_tfm {
72684 int (*init)(struct hash_desc *desc);
72685@@ -394,13 +394,13 @@ struct compress_tfm {
72686 int (*cot_decompress)(struct crypto_tfm *tfm,
72687 const u8 *src, unsigned int slen,
72688 u8 *dst, unsigned int *dlen);
72689-};
72690+} __no_const;
72691
72692 struct rng_tfm {
72693 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
72694 unsigned int dlen);
72695 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
72696-};
72697+} __no_const;
72698
72699 #define crt_ablkcipher crt_u.ablkcipher
72700 #define crt_aead crt_u.aead
72701diff --git a/include/linux/ctype.h b/include/linux/ctype.h
72702index 653589e..4ef254a 100644
72703--- a/include/linux/ctype.h
72704+++ b/include/linux/ctype.h
72705@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
72706 * Fast implementation of tolower() for internal usage. Do not use in your
72707 * code.
72708 */
72709-static inline char _tolower(const char c)
72710+static inline unsigned char _tolower(const unsigned char c)
72711 {
72712 return c | 0x20;
72713 }
72714diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
72715index 7925bf0..d5143d2 100644
72716--- a/include/linux/decompress/mm.h
72717+++ b/include/linux/decompress/mm.h
72718@@ -77,7 +77,7 @@ static void free(void *where)
72719 * warnings when not needed (indeed large_malloc / large_free are not
72720 * needed by inflate */
72721
72722-#define malloc(a) kmalloc(a, GFP_KERNEL)
72723+#define malloc(a) kmalloc((a), GFP_KERNEL)
72724 #define free(a) kfree(a)
72725
72726 #define large_malloc(a) vmalloc(a)
72727diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
72728index 5f1ab92..39c35ae 100644
72729--- a/include/linux/devfreq.h
72730+++ b/include/linux/devfreq.h
72731@@ -114,7 +114,7 @@ struct devfreq_governor {
72732 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
72733 int (*event_handler)(struct devfreq *devfreq,
72734 unsigned int event, void *data);
72735-};
72736+} __do_const;
72737
72738 /**
72739 * struct devfreq - Device devfreq structure
72740diff --git a/include/linux/device.h b/include/linux/device.h
72741index 22b546a..a573dc9 100644
72742--- a/include/linux/device.h
72743+++ b/include/linux/device.h
72744@@ -305,7 +305,7 @@ struct subsys_interface {
72745 struct list_head node;
72746 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
72747 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
72748-};
72749+} __do_const;
72750
72751 int subsys_interface_register(struct subsys_interface *sif);
72752 void subsys_interface_unregister(struct subsys_interface *sif);
72753@@ -493,7 +493,7 @@ struct device_type {
72754 void (*release)(struct device *dev);
72755
72756 const struct dev_pm_ops *pm;
72757-};
72758+} __do_const;
72759
72760 /* interface for exporting device attributes */
72761 struct device_attribute {
72762@@ -503,11 +503,12 @@ struct device_attribute {
72763 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
72764 const char *buf, size_t count);
72765 };
72766+typedef struct device_attribute __no_const device_attribute_no_const;
72767
72768 struct dev_ext_attribute {
72769 struct device_attribute attr;
72770 void *var;
72771-};
72772+} __do_const;
72773
72774 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
72775 char *buf);
72776diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
72777index 94af418..b1ca7a2 100644
72778--- a/include/linux/dma-mapping.h
72779+++ b/include/linux/dma-mapping.h
72780@@ -54,7 +54,7 @@ struct dma_map_ops {
72781 u64 (*get_required_mask)(struct device *dev);
72782 #endif
72783 int is_phys;
72784-};
72785+} __do_const;
72786
72787 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
72788
72789diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
72790index cb286b1..923d066 100644
72791--- a/include/linux/dmaengine.h
72792+++ b/include/linux/dmaengine.h
72793@@ -1030,9 +1030,9 @@ struct dma_pinned_list {
72794 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
72795 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
72796
72797-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
72798+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
72799 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
72800-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
72801+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
72802 struct dma_pinned_list *pinned_list, struct page *page,
72803 unsigned int offset, size_t len);
72804
72805diff --git a/include/linux/efi.h b/include/linux/efi.h
72806index 5f8f176..62a0556 100644
72807--- a/include/linux/efi.h
72808+++ b/include/linux/efi.h
72809@@ -745,6 +745,7 @@ struct efivar_operations {
72810 efi_set_variable_t *set_variable;
72811 efi_query_variable_store_t *query_variable_store;
72812 };
72813+typedef struct efivar_operations __no_const efivar_operations_no_const;
72814
72815 struct efivars {
72816 /*
72817diff --git a/include/linux/elf.h b/include/linux/elf.h
72818index 40a3c0e..4c45a38 100644
72819--- a/include/linux/elf.h
72820+++ b/include/linux/elf.h
72821@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
72822 #define elf_note elf32_note
72823 #define elf_addr_t Elf32_Off
72824 #define Elf_Half Elf32_Half
72825+#define elf_dyn Elf32_Dyn
72826
72827 #else
72828
72829@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
72830 #define elf_note elf64_note
72831 #define elf_addr_t Elf64_Off
72832 #define Elf_Half Elf64_Half
72833+#define elf_dyn Elf64_Dyn
72834
72835 #endif
72836
72837diff --git a/include/linux/err.h b/include/linux/err.h
72838index 221fcfb..f29e5e2 100644
72839--- a/include/linux/err.h
72840+++ b/include/linux/err.h
72841@@ -19,12 +19,12 @@
72842
72843 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
72844
72845-static inline void * __must_check ERR_PTR(long error)
72846+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
72847 {
72848 return (void *) error;
72849 }
72850
72851-static inline long __must_check PTR_ERR(__force const void *ptr)
72852+static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
72853 {
72854 return (long) ptr;
72855 }
72856diff --git a/include/linux/extcon.h b/include/linux/extcon.h
72857index fcb51c8..bdafcf6 100644
72858--- a/include/linux/extcon.h
72859+++ b/include/linux/extcon.h
72860@@ -134,7 +134,7 @@ struct extcon_dev {
72861 /* /sys/class/extcon/.../mutually_exclusive/... */
72862 struct attribute_group attr_g_muex;
72863 struct attribute **attrs_muex;
72864- struct device_attribute *d_attrs_muex;
72865+ device_attribute_no_const *d_attrs_muex;
72866 };
72867
72868 /**
72869diff --git a/include/linux/fb.h b/include/linux/fb.h
72870index ffac70a..ca3e711 100644
72871--- a/include/linux/fb.h
72872+++ b/include/linux/fb.h
72873@@ -304,7 +304,7 @@ struct fb_ops {
72874 /* called at KDB enter and leave time to prepare the console */
72875 int (*fb_debug_enter)(struct fb_info *info);
72876 int (*fb_debug_leave)(struct fb_info *info);
72877-};
72878+} __do_const;
72879
72880 #ifdef CONFIG_FB_TILEBLITTING
72881 #define FB_TILE_CURSOR_NONE 0
72882diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
72883index 085197b..0fa6f0b 100644
72884--- a/include/linux/fdtable.h
72885+++ b/include/linux/fdtable.h
72886@@ -95,7 +95,7 @@ struct files_struct *get_files_struct(struct task_struct *);
72887 void put_files_struct(struct files_struct *fs);
72888 void reset_files_struct(struct files_struct *);
72889 int unshare_files(struct files_struct **);
72890-struct files_struct *dup_fd(struct files_struct *, int *);
72891+struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
72892 void do_close_on_exec(struct files_struct *);
72893 int iterate_fd(struct files_struct *, unsigned,
72894 int (*)(const void *, struct file *, unsigned),
72895diff --git a/include/linux/filter.h b/include/linux/filter.h
72896index a6ac848..a104a76 100644
72897--- a/include/linux/filter.h
72898+++ b/include/linux/filter.h
72899@@ -20,6 +20,7 @@ struct compat_sock_fprog {
72900
72901 struct sk_buff;
72902 struct sock;
72903+struct bpf_jit_work;
72904
72905 struct sk_filter
72906 {
72907@@ -27,6 +28,9 @@ struct sk_filter
72908 unsigned int len; /* Number of filter blocks */
72909 unsigned int (*bpf_func)(const struct sk_buff *skb,
72910 const struct sock_filter *filter);
72911+#ifdef CONFIG_BPF_JIT
72912+ struct bpf_jit_work *work;
72913+#endif
72914 struct rcu_head rcu;
72915 struct sock_filter insns[0];
72916 };
72917diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
72918index 8293262..2b3b8bd 100644
72919--- a/include/linux/frontswap.h
72920+++ b/include/linux/frontswap.h
72921@@ -11,7 +11,7 @@ struct frontswap_ops {
72922 int (*load)(unsigned, pgoff_t, struct page *);
72923 void (*invalidate_page)(unsigned, pgoff_t);
72924 void (*invalidate_area)(unsigned);
72925-};
72926+} __no_const;
72927
72928 extern bool frontswap_enabled;
72929 extern struct frontswap_ops *
72930diff --git a/include/linux/fs.h b/include/linux/fs.h
72931index 9818747..788bfbd 100644
72932--- a/include/linux/fs.h
72933+++ b/include/linux/fs.h
72934@@ -1554,7 +1554,8 @@ struct file_operations {
72935 long (*fallocate)(struct file *file, int mode, loff_t offset,
72936 loff_t len);
72937 int (*show_fdinfo)(struct seq_file *m, struct file *f);
72938-};
72939+} __do_const;
72940+typedef struct file_operations __no_const file_operations_no_const;
72941
72942 struct inode_operations {
72943 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
72944@@ -2740,4 +2741,14 @@ static inline bool dir_relax(struct inode *inode)
72945 return !IS_DEADDIR(inode);
72946 }
72947
72948+static inline bool is_sidechannel_device(const struct inode *inode)
72949+{
72950+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
72951+ umode_t mode = inode->i_mode;
72952+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
72953+#else
72954+ return false;
72955+#endif
72956+}
72957+
72958 #endif /* _LINUX_FS_H */
72959diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
72960index 2b93a9a..855d94a 100644
72961--- a/include/linux/fs_struct.h
72962+++ b/include/linux/fs_struct.h
72963@@ -6,7 +6,7 @@
72964 #include <linux/seqlock.h>
72965
72966 struct fs_struct {
72967- int users;
72968+ atomic_t users;
72969 spinlock_t lock;
72970 seqcount_t seq;
72971 int umask;
72972diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
72973index a9ff9a3..1ba1788 100644
72974--- a/include/linux/fscache-cache.h
72975+++ b/include/linux/fscache-cache.h
72976@@ -113,7 +113,7 @@ struct fscache_operation {
72977 fscache_operation_release_t release;
72978 };
72979
72980-extern atomic_t fscache_op_debug_id;
72981+extern atomic_unchecked_t fscache_op_debug_id;
72982 extern void fscache_op_work_func(struct work_struct *work);
72983
72984 extern void fscache_enqueue_operation(struct fscache_operation *);
72985@@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
72986 INIT_WORK(&op->work, fscache_op_work_func);
72987 atomic_set(&op->usage, 1);
72988 op->state = FSCACHE_OP_ST_INITIALISED;
72989- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
72990+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
72991 op->processor = processor;
72992 op->release = release;
72993 INIT_LIST_HEAD(&op->pend_link);
72994diff --git a/include/linux/fscache.h b/include/linux/fscache.h
72995index 7a08623..4c07b0f 100644
72996--- a/include/linux/fscache.h
72997+++ b/include/linux/fscache.h
72998@@ -152,7 +152,7 @@ struct fscache_cookie_def {
72999 * - this is mandatory for any object that may have data
73000 */
73001 void (*now_uncached)(void *cookie_netfs_data);
73002-};
73003+} __do_const;
73004
73005 /*
73006 * fscache cached network filesystem type
73007diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
73008index 1c804b0..1432c2b 100644
73009--- a/include/linux/fsnotify.h
73010+++ b/include/linux/fsnotify.h
73011@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
73012 struct inode *inode = file_inode(file);
73013 __u32 mask = FS_ACCESS;
73014
73015+ if (is_sidechannel_device(inode))
73016+ return;
73017+
73018 if (S_ISDIR(inode->i_mode))
73019 mask |= FS_ISDIR;
73020
73021@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
73022 struct inode *inode = file_inode(file);
73023 __u32 mask = FS_MODIFY;
73024
73025+ if (is_sidechannel_device(inode))
73026+ return;
73027+
73028 if (S_ISDIR(inode->i_mode))
73029 mask |= FS_ISDIR;
73030
73031@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
73032 */
73033 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
73034 {
73035- return kstrdup(name, GFP_KERNEL);
73036+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
73037 }
73038
73039 /*
73040diff --git a/include/linux/genhd.h b/include/linux/genhd.h
73041index 9f3c275..8bdff5d 100644
73042--- a/include/linux/genhd.h
73043+++ b/include/linux/genhd.h
73044@@ -194,7 +194,7 @@ struct gendisk {
73045 struct kobject *slave_dir;
73046
73047 struct timer_rand_state *random;
73048- atomic_t sync_io; /* RAID */
73049+ atomic_unchecked_t sync_io; /* RAID */
73050 struct disk_events *ev;
73051 #ifdef CONFIG_BLK_DEV_INTEGRITY
73052 struct blk_integrity *integrity;
73053@@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
73054 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
73055
73056 /* drivers/char/random.c */
73057-extern void add_disk_randomness(struct gendisk *disk);
73058+extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
73059 extern void rand_initialize_disk(struct gendisk *disk);
73060
73061 static inline sector_t get_start_sect(struct block_device *bdev)
73062diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
73063index 023bc34..b02b46a 100644
73064--- a/include/linux/genl_magic_func.h
73065+++ b/include/linux/genl_magic_func.h
73066@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
73067 },
73068
73069 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
73070-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
73071+static struct genl_ops ZZZ_genl_ops[] = {
73072 #include GENL_MAGIC_INCLUDE_FILE
73073 };
73074
73075diff --git a/include/linux/gfp.h b/include/linux/gfp.h
73076index 9b4dd49..61fd41d 100644
73077--- a/include/linux/gfp.h
73078+++ b/include/linux/gfp.h
73079@@ -35,6 +35,13 @@ struct vm_area_struct;
73080 #define ___GFP_NO_KSWAPD 0x400000u
73081 #define ___GFP_OTHER_NODE 0x800000u
73082 #define ___GFP_WRITE 0x1000000u
73083+
73084+#ifdef CONFIG_PAX_USERCOPY_SLABS
73085+#define ___GFP_USERCOPY 0x2000000u
73086+#else
73087+#define ___GFP_USERCOPY 0
73088+#endif
73089+
73090 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
73091
73092 /*
73093@@ -92,6 +99,7 @@ struct vm_area_struct;
73094 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
73095 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
73096 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
73097+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
73098
73099 /*
73100 * This may seem redundant, but it's a way of annotating false positives vs.
73101@@ -99,7 +107,7 @@ struct vm_area_struct;
73102 */
73103 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
73104
73105-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
73106+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
73107 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
73108
73109 /* This equals 0, but use constants in case they ever change */
73110@@ -153,6 +161,8 @@ struct vm_area_struct;
73111 /* 4GB DMA on some platforms */
73112 #define GFP_DMA32 __GFP_DMA32
73113
73114+#define GFP_USERCOPY __GFP_USERCOPY
73115+
73116 /* Convert GFP flags to their corresponding migrate type */
73117 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
73118 {
73119diff --git a/include/linux/gracl.h b/include/linux/gracl.h
73120new file mode 100644
73121index 0000000..ebe6d72
73122--- /dev/null
73123+++ b/include/linux/gracl.h
73124@@ -0,0 +1,319 @@
73125+#ifndef GR_ACL_H
73126+#define GR_ACL_H
73127+
73128+#include <linux/grdefs.h>
73129+#include <linux/resource.h>
73130+#include <linux/capability.h>
73131+#include <linux/dcache.h>
73132+#include <asm/resource.h>
73133+
73134+/* Major status information */
73135+
73136+#define GR_VERSION "grsecurity 2.9.1"
73137+#define GRSECURITY_VERSION 0x2901
73138+
73139+enum {
73140+ GR_SHUTDOWN = 0,
73141+ GR_ENABLE = 1,
73142+ GR_SPROLE = 2,
73143+ GR_RELOAD = 3,
73144+ GR_SEGVMOD = 4,
73145+ GR_STATUS = 5,
73146+ GR_UNSPROLE = 6,
73147+ GR_PASSSET = 7,
73148+ GR_SPROLEPAM = 8,
73149+};
73150+
73151+/* Password setup definitions
73152+ * kernel/grhash.c */
73153+enum {
73154+ GR_PW_LEN = 128,
73155+ GR_SALT_LEN = 16,
73156+ GR_SHA_LEN = 32,
73157+};
73158+
73159+enum {
73160+ GR_SPROLE_LEN = 64,
73161+};
73162+
73163+enum {
73164+ GR_NO_GLOB = 0,
73165+ GR_REG_GLOB,
73166+ GR_CREATE_GLOB
73167+};
73168+
73169+#define GR_NLIMITS 32
73170+
73171+/* Begin Data Structures */
73172+
73173+struct sprole_pw {
73174+ unsigned char *rolename;
73175+ unsigned char salt[GR_SALT_LEN];
73176+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
73177+};
73178+
73179+struct name_entry {
73180+ __u32 key;
73181+ ino_t inode;
73182+ dev_t device;
73183+ char *name;
73184+ __u16 len;
73185+ __u8 deleted;
73186+ struct name_entry *prev;
73187+ struct name_entry *next;
73188+};
73189+
73190+struct inodev_entry {
73191+ struct name_entry *nentry;
73192+ struct inodev_entry *prev;
73193+ struct inodev_entry *next;
73194+};
73195+
73196+struct acl_role_db {
73197+ struct acl_role_label **r_hash;
73198+ __u32 r_size;
73199+};
73200+
73201+struct inodev_db {
73202+ struct inodev_entry **i_hash;
73203+ __u32 i_size;
73204+};
73205+
73206+struct name_db {
73207+ struct name_entry **n_hash;
73208+ __u32 n_size;
73209+};
73210+
73211+struct crash_uid {
73212+ uid_t uid;
73213+ unsigned long expires;
73214+};
73215+
73216+struct gr_hash_struct {
73217+ void **table;
73218+ void **nametable;
73219+ void *first;
73220+ __u32 table_size;
73221+ __u32 used_size;
73222+ int type;
73223+};
73224+
73225+/* Userspace Grsecurity ACL data structures */
73226+
73227+struct acl_subject_label {
73228+ char *filename;
73229+ ino_t inode;
73230+ dev_t device;
73231+ __u32 mode;
73232+ kernel_cap_t cap_mask;
73233+ kernel_cap_t cap_lower;
73234+ kernel_cap_t cap_invert_audit;
73235+
73236+ struct rlimit res[GR_NLIMITS];
73237+ __u32 resmask;
73238+
73239+ __u8 user_trans_type;
73240+ __u8 group_trans_type;
73241+ uid_t *user_transitions;
73242+ gid_t *group_transitions;
73243+ __u16 user_trans_num;
73244+ __u16 group_trans_num;
73245+
73246+ __u32 sock_families[2];
73247+ __u32 ip_proto[8];
73248+ __u32 ip_type;
73249+ struct acl_ip_label **ips;
73250+ __u32 ip_num;
73251+ __u32 inaddr_any_override;
73252+
73253+ __u32 crashes;
73254+ unsigned long expires;
73255+
73256+ struct acl_subject_label *parent_subject;
73257+ struct gr_hash_struct *hash;
73258+ struct acl_subject_label *prev;
73259+ struct acl_subject_label *next;
73260+
73261+ struct acl_object_label **obj_hash;
73262+ __u32 obj_hash_size;
73263+ __u16 pax_flags;
73264+};
73265+
73266+struct role_allowed_ip {
73267+ __u32 addr;
73268+ __u32 netmask;
73269+
73270+ struct role_allowed_ip *prev;
73271+ struct role_allowed_ip *next;
73272+};
73273+
73274+struct role_transition {
73275+ char *rolename;
73276+
73277+ struct role_transition *prev;
73278+ struct role_transition *next;
73279+};
73280+
73281+struct acl_role_label {
73282+ char *rolename;
73283+ uid_t uidgid;
73284+ __u16 roletype;
73285+
73286+ __u16 auth_attempts;
73287+ unsigned long expires;
73288+
73289+ struct acl_subject_label *root_label;
73290+ struct gr_hash_struct *hash;
73291+
73292+ struct acl_role_label *prev;
73293+ struct acl_role_label *next;
73294+
73295+ struct role_transition *transitions;
73296+ struct role_allowed_ip *allowed_ips;
73297+ uid_t *domain_children;
73298+ __u16 domain_child_num;
73299+
73300+ umode_t umask;
73301+
73302+ struct acl_subject_label **subj_hash;
73303+ __u32 subj_hash_size;
73304+};
73305+
73306+struct user_acl_role_db {
73307+ struct acl_role_label **r_table;
73308+ __u32 num_pointers; /* Number of allocations to track */
73309+ __u32 num_roles; /* Number of roles */
73310+ __u32 num_domain_children; /* Number of domain children */
73311+ __u32 num_subjects; /* Number of subjects */
73312+ __u32 num_objects; /* Number of objects */
73313+};
73314+
73315+struct acl_object_label {
73316+ char *filename;
73317+ ino_t inode;
73318+ dev_t device;
73319+ __u32 mode;
73320+
73321+ struct acl_subject_label *nested;
73322+ struct acl_object_label *globbed;
73323+
73324+ /* next two structures not used */
73325+
73326+ struct acl_object_label *prev;
73327+ struct acl_object_label *next;
73328+};
73329+
73330+struct acl_ip_label {
73331+ char *iface;
73332+ __u32 addr;
73333+ __u32 netmask;
73334+ __u16 low, high;
73335+ __u8 mode;
73336+ __u32 type;
73337+ __u32 proto[8];
73338+
73339+ /* next two structures not used */
73340+
73341+ struct acl_ip_label *prev;
73342+ struct acl_ip_label *next;
73343+};
73344+
73345+struct gr_arg {
73346+ struct user_acl_role_db role_db;
73347+ unsigned char pw[GR_PW_LEN];
73348+ unsigned char salt[GR_SALT_LEN];
73349+ unsigned char sum[GR_SHA_LEN];
73350+ unsigned char sp_role[GR_SPROLE_LEN];
73351+ struct sprole_pw *sprole_pws;
73352+ dev_t segv_device;
73353+ ino_t segv_inode;
73354+ uid_t segv_uid;
73355+ __u16 num_sprole_pws;
73356+ __u16 mode;
73357+};
73358+
73359+struct gr_arg_wrapper {
73360+ struct gr_arg *arg;
73361+ __u32 version;
73362+ __u32 size;
73363+};
73364+
73365+struct subject_map {
73366+ struct acl_subject_label *user;
73367+ struct acl_subject_label *kernel;
73368+ struct subject_map *prev;
73369+ struct subject_map *next;
73370+};
73371+
73372+struct acl_subj_map_db {
73373+ struct subject_map **s_hash;
73374+ __u32 s_size;
73375+};
73376+
73377+/* End Data Structures Section */
73378+
73379+/* Hash functions generated by empirical testing by Brad Spengler
73380+ Makes good use of the low bits of the inode. Generally 0-1 times
73381+ in loop for successful match. 0-3 for unsuccessful match.
73382+ Shift/add algorithm with modulus of table size and an XOR*/
73383+
73384+static __inline__ unsigned int
73385+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
73386+{
73387+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
73388+}
73389+
73390+ static __inline__ unsigned int
73391+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
73392+{
73393+ return ((const unsigned long)userp % sz);
73394+}
73395+
73396+static __inline__ unsigned int
73397+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
73398+{
73399+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
73400+}
73401+
73402+static __inline__ unsigned int
73403+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
73404+{
73405+ return full_name_hash((const unsigned char *)name, len) % sz;
73406+}
73407+
73408+#define FOR_EACH_ROLE_START(role) \
73409+ role = role_list; \
73410+ while (role) {
73411+
73412+#define FOR_EACH_ROLE_END(role) \
73413+ role = role->prev; \
73414+ }
73415+
73416+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
73417+ subj = NULL; \
73418+ iter = 0; \
73419+ while (iter < role->subj_hash_size) { \
73420+ if (subj == NULL) \
73421+ subj = role->subj_hash[iter]; \
73422+ if (subj == NULL) { \
73423+ iter++; \
73424+ continue; \
73425+ }
73426+
73427+#define FOR_EACH_SUBJECT_END(subj,iter) \
73428+ subj = subj->next; \
73429+ if (subj == NULL) \
73430+ iter++; \
73431+ }
73432+
73433+
73434+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
73435+ subj = role->hash->first; \
73436+ while (subj != NULL) {
73437+
73438+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
73439+ subj = subj->next; \
73440+ }
73441+
73442+#endif
73443+
73444diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
73445new file mode 100644
73446index 0000000..33ebd1f
73447--- /dev/null
73448+++ b/include/linux/gracl_compat.h
73449@@ -0,0 +1,156 @@
73450+#ifndef GR_ACL_COMPAT_H
73451+#define GR_ACL_COMPAT_H
73452+
73453+#include <linux/resource.h>
73454+#include <asm/resource.h>
73455+
73456+struct sprole_pw_compat {
73457+ compat_uptr_t rolename;
73458+ unsigned char salt[GR_SALT_LEN];
73459+ unsigned char sum[GR_SHA_LEN];
73460+};
73461+
73462+struct gr_hash_struct_compat {
73463+ compat_uptr_t table;
73464+ compat_uptr_t nametable;
73465+ compat_uptr_t first;
73466+ __u32 table_size;
73467+ __u32 used_size;
73468+ int type;
73469+};
73470+
73471+struct acl_subject_label_compat {
73472+ compat_uptr_t filename;
73473+ compat_ino_t inode;
73474+ __u32 device;
73475+ __u32 mode;
73476+ kernel_cap_t cap_mask;
73477+ kernel_cap_t cap_lower;
73478+ kernel_cap_t cap_invert_audit;
73479+
73480+ struct compat_rlimit res[GR_NLIMITS];
73481+ __u32 resmask;
73482+
73483+ __u8 user_trans_type;
73484+ __u8 group_trans_type;
73485+ compat_uptr_t user_transitions;
73486+ compat_uptr_t group_transitions;
73487+ __u16 user_trans_num;
73488+ __u16 group_trans_num;
73489+
73490+ __u32 sock_families[2];
73491+ __u32 ip_proto[8];
73492+ __u32 ip_type;
73493+ compat_uptr_t ips;
73494+ __u32 ip_num;
73495+ __u32 inaddr_any_override;
73496+
73497+ __u32 crashes;
73498+ compat_ulong_t expires;
73499+
73500+ compat_uptr_t parent_subject;
73501+ compat_uptr_t hash;
73502+ compat_uptr_t prev;
73503+ compat_uptr_t next;
73504+
73505+ compat_uptr_t obj_hash;
73506+ __u32 obj_hash_size;
73507+ __u16 pax_flags;
73508+};
73509+
73510+struct role_allowed_ip_compat {
73511+ __u32 addr;
73512+ __u32 netmask;
73513+
73514+ compat_uptr_t prev;
73515+ compat_uptr_t next;
73516+};
73517+
73518+struct role_transition_compat {
73519+ compat_uptr_t rolename;
73520+
73521+ compat_uptr_t prev;
73522+ compat_uptr_t next;
73523+};
73524+
73525+struct acl_role_label_compat {
73526+ compat_uptr_t rolename;
73527+ uid_t uidgid;
73528+ __u16 roletype;
73529+
73530+ __u16 auth_attempts;
73531+ compat_ulong_t expires;
73532+
73533+ compat_uptr_t root_label;
73534+ compat_uptr_t hash;
73535+
73536+ compat_uptr_t prev;
73537+ compat_uptr_t next;
73538+
73539+ compat_uptr_t transitions;
73540+ compat_uptr_t allowed_ips;
73541+ compat_uptr_t domain_children;
73542+ __u16 domain_child_num;
73543+
73544+ umode_t umask;
73545+
73546+ compat_uptr_t subj_hash;
73547+ __u32 subj_hash_size;
73548+};
73549+
73550+struct user_acl_role_db_compat {
73551+ compat_uptr_t r_table;
73552+ __u32 num_pointers;
73553+ __u32 num_roles;
73554+ __u32 num_domain_children;
73555+ __u32 num_subjects;
73556+ __u32 num_objects;
73557+};
73558+
73559+struct acl_object_label_compat {
73560+ compat_uptr_t filename;
73561+ compat_ino_t inode;
73562+ __u32 device;
73563+ __u32 mode;
73564+
73565+ compat_uptr_t nested;
73566+ compat_uptr_t globbed;
73567+
73568+ compat_uptr_t prev;
73569+ compat_uptr_t next;
73570+};
73571+
73572+struct acl_ip_label_compat {
73573+ compat_uptr_t iface;
73574+ __u32 addr;
73575+ __u32 netmask;
73576+ __u16 low, high;
73577+ __u8 mode;
73578+ __u32 type;
73579+ __u32 proto[8];
73580+
73581+ compat_uptr_t prev;
73582+ compat_uptr_t next;
73583+};
73584+
73585+struct gr_arg_compat {
73586+ struct user_acl_role_db_compat role_db;
73587+ unsigned char pw[GR_PW_LEN];
73588+ unsigned char salt[GR_SALT_LEN];
73589+ unsigned char sum[GR_SHA_LEN];
73590+ unsigned char sp_role[GR_SPROLE_LEN];
73591+ compat_uptr_t sprole_pws;
73592+ __u32 segv_device;
73593+ compat_ino_t segv_inode;
73594+ uid_t segv_uid;
73595+ __u16 num_sprole_pws;
73596+ __u16 mode;
73597+};
73598+
73599+struct gr_arg_wrapper_compat {
73600+ compat_uptr_t arg;
73601+ __u32 version;
73602+ __u32 size;
73603+};
73604+
73605+#endif
73606diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
73607new file mode 100644
73608index 0000000..323ecf2
73609--- /dev/null
73610+++ b/include/linux/gralloc.h
73611@@ -0,0 +1,9 @@
73612+#ifndef __GRALLOC_H
73613+#define __GRALLOC_H
73614+
73615+void acl_free_all(void);
73616+int acl_alloc_stack_init(unsigned long size);
73617+void *acl_alloc(unsigned long len);
73618+void *acl_alloc_num(unsigned long num, unsigned long len);
73619+
73620+#endif
73621diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
73622new file mode 100644
73623index 0000000..be66033
73624--- /dev/null
73625+++ b/include/linux/grdefs.h
73626@@ -0,0 +1,140 @@
73627+#ifndef GRDEFS_H
73628+#define GRDEFS_H
73629+
73630+/* Begin grsecurity status declarations */
73631+
73632+enum {
73633+ GR_READY = 0x01,
73634+ GR_STATUS_INIT = 0x00 // disabled state
73635+};
73636+
73637+/* Begin ACL declarations */
73638+
73639+/* Role flags */
73640+
73641+enum {
73642+ GR_ROLE_USER = 0x0001,
73643+ GR_ROLE_GROUP = 0x0002,
73644+ GR_ROLE_DEFAULT = 0x0004,
73645+ GR_ROLE_SPECIAL = 0x0008,
73646+ GR_ROLE_AUTH = 0x0010,
73647+ GR_ROLE_NOPW = 0x0020,
73648+ GR_ROLE_GOD = 0x0040,
73649+ GR_ROLE_LEARN = 0x0080,
73650+ GR_ROLE_TPE = 0x0100,
73651+ GR_ROLE_DOMAIN = 0x0200,
73652+ GR_ROLE_PAM = 0x0400,
73653+ GR_ROLE_PERSIST = 0x0800
73654+};
73655+
73656+/* ACL Subject and Object mode flags */
73657+enum {
73658+ GR_DELETED = 0x80000000
73659+};
73660+
73661+/* ACL Object-only mode flags */
73662+enum {
73663+ GR_READ = 0x00000001,
73664+ GR_APPEND = 0x00000002,
73665+ GR_WRITE = 0x00000004,
73666+ GR_EXEC = 0x00000008,
73667+ GR_FIND = 0x00000010,
73668+ GR_INHERIT = 0x00000020,
73669+ GR_SETID = 0x00000040,
73670+ GR_CREATE = 0x00000080,
73671+ GR_DELETE = 0x00000100,
73672+ GR_LINK = 0x00000200,
73673+ GR_AUDIT_READ = 0x00000400,
73674+ GR_AUDIT_APPEND = 0x00000800,
73675+ GR_AUDIT_WRITE = 0x00001000,
73676+ GR_AUDIT_EXEC = 0x00002000,
73677+ GR_AUDIT_FIND = 0x00004000,
73678+ GR_AUDIT_INHERIT= 0x00008000,
73679+ GR_AUDIT_SETID = 0x00010000,
73680+ GR_AUDIT_CREATE = 0x00020000,
73681+ GR_AUDIT_DELETE = 0x00040000,
73682+ GR_AUDIT_LINK = 0x00080000,
73683+ GR_PTRACERD = 0x00100000,
73684+ GR_NOPTRACE = 0x00200000,
73685+ GR_SUPPRESS = 0x00400000,
73686+ GR_NOLEARN = 0x00800000,
73687+ GR_INIT_TRANSFER= 0x01000000
73688+};
73689+
73690+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
73691+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
73692+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
73693+
73694+/* ACL subject-only mode flags */
73695+enum {
73696+ GR_KILL = 0x00000001,
73697+ GR_VIEW = 0x00000002,
73698+ GR_PROTECTED = 0x00000004,
73699+ GR_LEARN = 0x00000008,
73700+ GR_OVERRIDE = 0x00000010,
73701+ /* just a placeholder, this mode is only used in userspace */
73702+ GR_DUMMY = 0x00000020,
73703+ GR_PROTSHM = 0x00000040,
73704+ GR_KILLPROC = 0x00000080,
73705+ GR_KILLIPPROC = 0x00000100,
73706+ /* just a placeholder, this mode is only used in userspace */
73707+ GR_NOTROJAN = 0x00000200,
73708+ GR_PROTPROCFD = 0x00000400,
73709+ GR_PROCACCT = 0x00000800,
73710+ GR_RELAXPTRACE = 0x00001000,
73711+ //GR_NESTED = 0x00002000,
73712+ GR_INHERITLEARN = 0x00004000,
73713+ GR_PROCFIND = 0x00008000,
73714+ GR_POVERRIDE = 0x00010000,
73715+ GR_KERNELAUTH = 0x00020000,
73716+ GR_ATSECURE = 0x00040000,
73717+ GR_SHMEXEC = 0x00080000
73718+};
73719+
73720+enum {
73721+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
73722+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
73723+ GR_PAX_ENABLE_MPROTECT = 0x0004,
73724+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
73725+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
73726+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
73727+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
73728+ GR_PAX_DISABLE_MPROTECT = 0x0400,
73729+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
73730+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
73731+};
73732+
73733+enum {
73734+ GR_ID_USER = 0x01,
73735+ GR_ID_GROUP = 0x02,
73736+};
73737+
73738+enum {
73739+ GR_ID_ALLOW = 0x01,
73740+ GR_ID_DENY = 0x02,
73741+};
73742+
73743+#define GR_CRASH_RES 31
73744+#define GR_UIDTABLE_MAX 500
73745+
73746+/* begin resource learning section */
73747+enum {
73748+ GR_RLIM_CPU_BUMP = 60,
73749+ GR_RLIM_FSIZE_BUMP = 50000,
73750+ GR_RLIM_DATA_BUMP = 10000,
73751+ GR_RLIM_STACK_BUMP = 1000,
73752+ GR_RLIM_CORE_BUMP = 10000,
73753+ GR_RLIM_RSS_BUMP = 500000,
73754+ GR_RLIM_NPROC_BUMP = 1,
73755+ GR_RLIM_NOFILE_BUMP = 5,
73756+ GR_RLIM_MEMLOCK_BUMP = 50000,
73757+ GR_RLIM_AS_BUMP = 500000,
73758+ GR_RLIM_LOCKS_BUMP = 2,
73759+ GR_RLIM_SIGPENDING_BUMP = 5,
73760+ GR_RLIM_MSGQUEUE_BUMP = 10000,
73761+ GR_RLIM_NICE_BUMP = 1,
73762+ GR_RLIM_RTPRIO_BUMP = 1,
73763+ GR_RLIM_RTTIME_BUMP = 1000000
73764+};
73765+
73766+#endif
73767diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
73768new file mode 100644
73769index 0000000..e337683
73770--- /dev/null
73771+++ b/include/linux/grinternal.h
73772@@ -0,0 +1,229 @@
73773+#ifndef __GRINTERNAL_H
73774+#define __GRINTERNAL_H
73775+
73776+#ifdef CONFIG_GRKERNSEC
73777+
73778+#include <linux/fs.h>
73779+#include <linux/mnt_namespace.h>
73780+#include <linux/nsproxy.h>
73781+#include <linux/gracl.h>
73782+#include <linux/grdefs.h>
73783+#include <linux/grmsg.h>
73784+
73785+void gr_add_learn_entry(const char *fmt, ...)
73786+ __attribute__ ((format (printf, 1, 2)));
73787+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
73788+ const struct vfsmount *mnt);
73789+__u32 gr_check_create(const struct dentry *new_dentry,
73790+ const struct dentry *parent,
73791+ const struct vfsmount *mnt, const __u32 mode);
73792+int gr_check_protected_task(const struct task_struct *task);
73793+__u32 to_gr_audit(const __u32 reqmode);
73794+int gr_set_acls(const int type);
73795+int gr_apply_subject_to_task(struct task_struct *task);
73796+int gr_acl_is_enabled(void);
73797+char gr_roletype_to_char(void);
73798+
73799+void gr_handle_alertkill(struct task_struct *task);
73800+char *gr_to_filename(const struct dentry *dentry,
73801+ const struct vfsmount *mnt);
73802+char *gr_to_filename1(const struct dentry *dentry,
73803+ const struct vfsmount *mnt);
73804+char *gr_to_filename2(const struct dentry *dentry,
73805+ const struct vfsmount *mnt);
73806+char *gr_to_filename3(const struct dentry *dentry,
73807+ const struct vfsmount *mnt);
73808+
73809+extern int grsec_enable_ptrace_readexec;
73810+extern int grsec_enable_harden_ptrace;
73811+extern int grsec_enable_link;
73812+extern int grsec_enable_fifo;
73813+extern int grsec_enable_execve;
73814+extern int grsec_enable_shm;
73815+extern int grsec_enable_execlog;
73816+extern int grsec_enable_signal;
73817+extern int grsec_enable_audit_ptrace;
73818+extern int grsec_enable_forkfail;
73819+extern int grsec_enable_time;
73820+extern int grsec_enable_rofs;
73821+extern int grsec_deny_new_usb;
73822+extern int grsec_enable_chroot_shmat;
73823+extern int grsec_enable_chroot_mount;
73824+extern int grsec_enable_chroot_double;
73825+extern int grsec_enable_chroot_pivot;
73826+extern int grsec_enable_chroot_chdir;
73827+extern int grsec_enable_chroot_chmod;
73828+extern int grsec_enable_chroot_mknod;
73829+extern int grsec_enable_chroot_fchdir;
73830+extern int grsec_enable_chroot_nice;
73831+extern int grsec_enable_chroot_execlog;
73832+extern int grsec_enable_chroot_caps;
73833+extern int grsec_enable_chroot_sysctl;
73834+extern int grsec_enable_chroot_unix;
73835+extern int grsec_enable_symlinkown;
73836+extern kgid_t grsec_symlinkown_gid;
73837+extern int grsec_enable_tpe;
73838+extern kgid_t grsec_tpe_gid;
73839+extern int grsec_enable_tpe_all;
73840+extern int grsec_enable_tpe_invert;
73841+extern int grsec_enable_socket_all;
73842+extern kgid_t grsec_socket_all_gid;
73843+extern int grsec_enable_socket_client;
73844+extern kgid_t grsec_socket_client_gid;
73845+extern int grsec_enable_socket_server;
73846+extern kgid_t grsec_socket_server_gid;
73847+extern kgid_t grsec_audit_gid;
73848+extern int grsec_enable_group;
73849+extern int grsec_enable_log_rwxmaps;
73850+extern int grsec_enable_mount;
73851+extern int grsec_enable_chdir;
73852+extern int grsec_resource_logging;
73853+extern int grsec_enable_blackhole;
73854+extern int grsec_lastack_retries;
73855+extern int grsec_enable_brute;
73856+extern int grsec_lock;
73857+
73858+extern spinlock_t grsec_alert_lock;
73859+extern unsigned long grsec_alert_wtime;
73860+extern unsigned long grsec_alert_fyet;
73861+
73862+extern spinlock_t grsec_audit_lock;
73863+
73864+extern rwlock_t grsec_exec_file_lock;
73865+
73866+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
73867+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
73868+ (tsk)->exec_file->f_path.mnt) : "/")
73869+
73870+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
73871+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
73872+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
73873+
73874+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
73875+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
73876+ (tsk)->exec_file->f_path.mnt) : "/")
73877+
73878+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
73879+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
73880+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
73881+
73882+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
73883+
73884+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
73885+
73886+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
73887+{
73888+ if (file1 && file2) {
73889+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
73890+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
73891+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
73892+ return true;
73893+ }
73894+
73895+ return false;
73896+}
73897+
73898+#define GR_CHROOT_CAPS {{ \
73899+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
73900+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
73901+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
73902+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
73903+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
73904+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
73905+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
73906+
73907+#define security_learn(normal_msg,args...) \
73908+({ \
73909+ read_lock(&grsec_exec_file_lock); \
73910+ gr_add_learn_entry(normal_msg "\n", ## args); \
73911+ read_unlock(&grsec_exec_file_lock); \
73912+})
73913+
73914+enum {
73915+ GR_DO_AUDIT,
73916+ GR_DONT_AUDIT,
73917+ /* used for non-audit messages that we shouldn't kill the task on */
73918+ GR_DONT_AUDIT_GOOD
73919+};
73920+
73921+enum {
73922+ GR_TTYSNIFF,
73923+ GR_RBAC,
73924+ GR_RBAC_STR,
73925+ GR_STR_RBAC,
73926+ GR_RBAC_MODE2,
73927+ GR_RBAC_MODE3,
73928+ GR_FILENAME,
73929+ GR_SYSCTL_HIDDEN,
73930+ GR_NOARGS,
73931+ GR_ONE_INT,
73932+ GR_ONE_INT_TWO_STR,
73933+ GR_ONE_STR,
73934+ GR_STR_INT,
73935+ GR_TWO_STR_INT,
73936+ GR_TWO_INT,
73937+ GR_TWO_U64,
73938+ GR_THREE_INT,
73939+ GR_FIVE_INT_TWO_STR,
73940+ GR_TWO_STR,
73941+ GR_THREE_STR,
73942+ GR_FOUR_STR,
73943+ GR_STR_FILENAME,
73944+ GR_FILENAME_STR,
73945+ GR_FILENAME_TWO_INT,
73946+ GR_FILENAME_TWO_INT_STR,
73947+ GR_TEXTREL,
73948+ GR_PTRACE,
73949+ GR_RESOURCE,
73950+ GR_CAP,
73951+ GR_SIG,
73952+ GR_SIG2,
73953+ GR_CRASH1,
73954+ GR_CRASH2,
73955+ GR_PSACCT,
73956+ GR_RWXMAP,
73957+ GR_RWXMAPVMA
73958+};
73959+
73960+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
73961+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
73962+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
73963+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
73964+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
73965+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
73966+#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)
73967+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
73968+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
73969+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
73970+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
73971+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
73972+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
73973+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
73974+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
73975+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
73976+#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)
73977+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
73978+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
73979+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
73980+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
73981+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
73982+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
73983+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
73984+#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)
73985+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
73986+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
73987+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
73988+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
73989+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
73990+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
73991+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
73992+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
73993+#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)
73994+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
73995+#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
73996+
73997+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
73998+
73999+#endif
74000+
74001+#endif
74002diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
74003new file mode 100644
74004index 0000000..a4396b5
74005--- /dev/null
74006+++ b/include/linux/grmsg.h
74007@@ -0,0 +1,113 @@
74008+#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"
74009+#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"
74010+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
74011+#define GR_STOPMOD_MSG "denied modification of module state by "
74012+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
74013+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
74014+#define GR_IOPERM_MSG "denied use of ioperm() by "
74015+#define GR_IOPL_MSG "denied use of iopl() by "
74016+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
74017+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
74018+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
74019+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
74020+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
74021+#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"
74022+#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"
74023+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
74024+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
74025+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
74026+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
74027+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
74028+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
74029+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
74030+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
74031+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
74032+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
74033+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
74034+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
74035+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
74036+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
74037+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
74038+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
74039+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
74040+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
74041+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
74042+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
74043+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
74044+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
74045+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
74046+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
74047+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
74048+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
74049+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
74050+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
74051+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
74052+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
74053+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
74054+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
74055+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
74056+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
74057+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
74058+#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"
74059+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
74060+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
74061+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
74062+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
74063+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
74064+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
74065+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
74066+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
74067+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
74068+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
74069+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
74070+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
74071+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
74072+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
74073+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
74074+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
74075+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
74076+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
74077+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
74078+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
74079+#define GR_FAILFORK_MSG "failed fork with errno %s by "
74080+#define GR_NICE_CHROOT_MSG "denied priority change by "
74081+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
74082+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
74083+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
74084+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
74085+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
74086+#define GR_TIME_MSG "time set by "
74087+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
74088+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
74089+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
74090+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
74091+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
74092+#define GR_BIND_MSG "denied bind() by "
74093+#define GR_CONNECT_MSG "denied connect() by "
74094+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
74095+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
74096+#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"
74097+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
74098+#define GR_CAP_ACL_MSG "use of %s denied for "
74099+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
74100+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
74101+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
74102+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
74103+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
74104+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
74105+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
74106+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
74107+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
74108+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
74109+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
74110+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
74111+#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
74112+#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
74113+#define GR_VM86_MSG "denied use of vm86 by "
74114+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
74115+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
74116+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
74117+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
74118+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
74119+#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 "
74120+#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 "
74121diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
74122new file mode 100644
74123index 0000000..d6f5a21
74124--- /dev/null
74125+++ b/include/linux/grsecurity.h
74126@@ -0,0 +1,244 @@
74127+#ifndef GR_SECURITY_H
74128+#define GR_SECURITY_H
74129+#include <linux/fs.h>
74130+#include <linux/fs_struct.h>
74131+#include <linux/binfmts.h>
74132+#include <linux/gracl.h>
74133+
74134+/* notify of brain-dead configs */
74135+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
74136+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
74137+#endif
74138+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
74139+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
74140+#endif
74141+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
74142+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
74143+#endif
74144+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
74145+#error "CONFIG_PAX enabled, but no PaX options are enabled."
74146+#endif
74147+
74148+int gr_handle_new_usb(void);
74149+
74150+void gr_handle_brute_attach(unsigned long mm_flags);
74151+void gr_handle_brute_check(void);
74152+void gr_handle_kernel_exploit(void);
74153+
74154+char gr_roletype_to_char(void);
74155+
74156+int gr_acl_enable_at_secure(void);
74157+
74158+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
74159+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
74160+
74161+void gr_del_task_from_ip_table(struct task_struct *p);
74162+
74163+int gr_pid_is_chrooted(struct task_struct *p);
74164+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
74165+int gr_handle_chroot_nice(void);
74166+int gr_handle_chroot_sysctl(const int op);
74167+int gr_handle_chroot_setpriority(struct task_struct *p,
74168+ const int niceval);
74169+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
74170+int gr_handle_chroot_chroot(const struct dentry *dentry,
74171+ const struct vfsmount *mnt);
74172+void gr_handle_chroot_chdir(const struct path *path);
74173+int gr_handle_chroot_chmod(const struct dentry *dentry,
74174+ const struct vfsmount *mnt, const int mode);
74175+int gr_handle_chroot_mknod(const struct dentry *dentry,
74176+ const struct vfsmount *mnt, const int mode);
74177+int gr_handle_chroot_mount(const struct dentry *dentry,
74178+ const struct vfsmount *mnt,
74179+ const char *dev_name);
74180+int gr_handle_chroot_pivot(void);
74181+int gr_handle_chroot_unix(const pid_t pid);
74182+
74183+int gr_handle_rawio(const struct inode *inode);
74184+
74185+void gr_handle_ioperm(void);
74186+void gr_handle_iopl(void);
74187+
74188+umode_t gr_acl_umask(void);
74189+
74190+int gr_tpe_allow(const struct file *file);
74191+
74192+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
74193+void gr_clear_chroot_entries(struct task_struct *task);
74194+
74195+void gr_log_forkfail(const int retval);
74196+void gr_log_timechange(void);
74197+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
74198+void gr_log_chdir(const struct dentry *dentry,
74199+ const struct vfsmount *mnt);
74200+void gr_log_chroot_exec(const struct dentry *dentry,
74201+ const struct vfsmount *mnt);
74202+void gr_log_remount(const char *devname, const int retval);
74203+void gr_log_unmount(const char *devname, const int retval);
74204+void gr_log_mount(const char *from, const char *to, const int retval);
74205+void gr_log_textrel(struct vm_area_struct *vma);
74206+void gr_log_ptgnustack(struct file *file);
74207+void gr_log_rwxmmap(struct file *file);
74208+void gr_log_rwxmprotect(struct vm_area_struct *vma);
74209+
74210+int gr_handle_follow_link(const struct inode *parent,
74211+ const struct inode *inode,
74212+ const struct dentry *dentry,
74213+ const struct vfsmount *mnt);
74214+int gr_handle_fifo(const struct dentry *dentry,
74215+ const struct vfsmount *mnt,
74216+ const struct dentry *dir, const int flag,
74217+ const int acc_mode);
74218+int gr_handle_hardlink(const struct dentry *dentry,
74219+ const struct vfsmount *mnt,
74220+ struct inode *inode,
74221+ const int mode, const struct filename *to);
74222+
74223+int gr_is_capable(const int cap);
74224+int gr_is_capable_nolog(const int cap);
74225+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74226+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
74227+
74228+void gr_copy_label(struct task_struct *tsk);
74229+void gr_handle_crash(struct task_struct *task, const int sig);
74230+int gr_handle_signal(const struct task_struct *p, const int sig);
74231+int gr_check_crash_uid(const kuid_t uid);
74232+int gr_check_protected_task(const struct task_struct *task);
74233+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
74234+int gr_acl_handle_mmap(const struct file *file,
74235+ const unsigned long prot);
74236+int gr_acl_handle_mprotect(const struct file *file,
74237+ const unsigned long prot);
74238+int gr_check_hidden_task(const struct task_struct *tsk);
74239+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
74240+ const struct vfsmount *mnt);
74241+__u32 gr_acl_handle_utime(const struct dentry *dentry,
74242+ const struct vfsmount *mnt);
74243+__u32 gr_acl_handle_access(const struct dentry *dentry,
74244+ const struct vfsmount *mnt, const int fmode);
74245+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
74246+ const struct vfsmount *mnt, umode_t *mode);
74247+__u32 gr_acl_handle_chown(const struct dentry *dentry,
74248+ const struct vfsmount *mnt);
74249+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
74250+ const struct vfsmount *mnt);
74251+int gr_handle_ptrace(struct task_struct *task, const long request);
74252+int gr_handle_proc_ptrace(struct task_struct *task);
74253+__u32 gr_acl_handle_execve(const struct dentry *dentry,
74254+ const struct vfsmount *mnt);
74255+int gr_check_crash_exec(const struct file *filp);
74256+int gr_acl_is_enabled(void);
74257+void gr_set_kernel_label(struct task_struct *task);
74258+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
74259+ const kgid_t gid);
74260+int gr_set_proc_label(const struct dentry *dentry,
74261+ const struct vfsmount *mnt,
74262+ const int unsafe_flags);
74263+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
74264+ const struct vfsmount *mnt);
74265+__u32 gr_acl_handle_open(const struct dentry *dentry,
74266+ const struct vfsmount *mnt, int acc_mode);
74267+__u32 gr_acl_handle_creat(const struct dentry *dentry,
74268+ const struct dentry *p_dentry,
74269+ const struct vfsmount *p_mnt,
74270+ int open_flags, int acc_mode, const int imode);
74271+void gr_handle_create(const struct dentry *dentry,
74272+ const struct vfsmount *mnt);
74273+void gr_handle_proc_create(const struct dentry *dentry,
74274+ const struct inode *inode);
74275+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
74276+ const struct dentry *parent_dentry,
74277+ const struct vfsmount *parent_mnt,
74278+ const int mode);
74279+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
74280+ const struct dentry *parent_dentry,
74281+ const struct vfsmount *parent_mnt);
74282+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
74283+ const struct vfsmount *mnt);
74284+void gr_handle_delete(const ino_t ino, const dev_t dev);
74285+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
74286+ const struct vfsmount *mnt);
74287+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
74288+ const struct dentry *parent_dentry,
74289+ const struct vfsmount *parent_mnt,
74290+ const struct filename *from);
74291+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
74292+ const struct dentry *parent_dentry,
74293+ const struct vfsmount *parent_mnt,
74294+ const struct dentry *old_dentry,
74295+ const struct vfsmount *old_mnt, const struct filename *to);
74296+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
74297+int gr_acl_handle_rename(struct dentry *new_dentry,
74298+ struct dentry *parent_dentry,
74299+ const struct vfsmount *parent_mnt,
74300+ struct dentry *old_dentry,
74301+ struct inode *old_parent_inode,
74302+ struct vfsmount *old_mnt, const struct filename *newname);
74303+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
74304+ struct dentry *old_dentry,
74305+ struct dentry *new_dentry,
74306+ struct vfsmount *mnt, const __u8 replace);
74307+__u32 gr_check_link(const struct dentry *new_dentry,
74308+ const struct dentry *parent_dentry,
74309+ const struct vfsmount *parent_mnt,
74310+ const struct dentry *old_dentry,
74311+ const struct vfsmount *old_mnt);
74312+int gr_acl_handle_filldir(const struct file *file, const char *name,
74313+ const unsigned int namelen, const ino_t ino);
74314+
74315+__u32 gr_acl_handle_unix(const struct dentry *dentry,
74316+ const struct vfsmount *mnt);
74317+void gr_acl_handle_exit(void);
74318+void gr_acl_handle_psacct(struct task_struct *task, const long code);
74319+int gr_acl_handle_procpidmem(const struct task_struct *task);
74320+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
74321+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
74322+void gr_audit_ptrace(struct task_struct *task);
74323+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
74324+void gr_put_exec_file(struct task_struct *task);
74325+
74326+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
74327+
74328+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
74329+extern void gr_learn_resource(const struct task_struct *task, const int res,
74330+ const unsigned long wanted, const int gt);
74331+#else
74332+static inline void gr_learn_resource(const struct task_struct *task, const int res,
74333+ const unsigned long wanted, const int gt)
74334+{
74335+}
74336+#endif
74337+
74338+#ifdef CONFIG_GRKERNSEC_RESLOG
74339+extern void gr_log_resource(const struct task_struct *task, const int res,
74340+ const unsigned long wanted, const int gt);
74341+#else
74342+static inline void gr_log_resource(const struct task_struct *task, const int res,
74343+ const unsigned long wanted, const int gt)
74344+{
74345+}
74346+#endif
74347+
74348+#ifdef CONFIG_GRKERNSEC
74349+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
74350+void gr_handle_vm86(void);
74351+void gr_handle_mem_readwrite(u64 from, u64 to);
74352+
74353+void gr_log_badprocpid(const char *entry);
74354+
74355+extern int grsec_enable_dmesg;
74356+extern int grsec_disable_privio;
74357+
74358+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
74359+extern kgid_t grsec_proc_gid;
74360+#endif
74361+
74362+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74363+extern int grsec_enable_chroot_findtask;
74364+#endif
74365+#ifdef CONFIG_GRKERNSEC_SETXID
74366+extern int grsec_enable_setxid;
74367+#endif
74368+#endif
74369+
74370+#endif
74371diff --git a/include/linux/grsock.h b/include/linux/grsock.h
74372new file mode 100644
74373index 0000000..e7ffaaf
74374--- /dev/null
74375+++ b/include/linux/grsock.h
74376@@ -0,0 +1,19 @@
74377+#ifndef __GRSOCK_H
74378+#define __GRSOCK_H
74379+
74380+extern void gr_attach_curr_ip(const struct sock *sk);
74381+extern int gr_handle_sock_all(const int family, const int type,
74382+ const int protocol);
74383+extern int gr_handle_sock_server(const struct sockaddr *sck);
74384+extern int gr_handle_sock_server_other(const struct sock *sck);
74385+extern int gr_handle_sock_client(const struct sockaddr *sck);
74386+extern int gr_search_connect(struct socket * sock,
74387+ struct sockaddr_in * addr);
74388+extern int gr_search_bind(struct socket * sock,
74389+ struct sockaddr_in * addr);
74390+extern int gr_search_listen(struct socket * sock);
74391+extern int gr_search_accept(struct socket * sock);
74392+extern int gr_search_socket(const int domain, const int type,
74393+ const int protocol);
74394+
74395+#endif
74396diff --git a/include/linux/highmem.h b/include/linux/highmem.h
74397index 7fb31da..08b5114 100644
74398--- a/include/linux/highmem.h
74399+++ b/include/linux/highmem.h
74400@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
74401 kunmap_atomic(kaddr);
74402 }
74403
74404+static inline void sanitize_highpage(struct page *page)
74405+{
74406+ void *kaddr;
74407+ unsigned long flags;
74408+
74409+ local_irq_save(flags);
74410+ kaddr = kmap_atomic(page);
74411+ clear_page(kaddr);
74412+ kunmap_atomic(kaddr);
74413+ local_irq_restore(flags);
74414+}
74415+
74416 static inline void zero_user_segments(struct page *page,
74417 unsigned start1, unsigned end1,
74418 unsigned start2, unsigned end2)
74419diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
74420index 1c7b89a..7f52502 100644
74421--- a/include/linux/hwmon-sysfs.h
74422+++ b/include/linux/hwmon-sysfs.h
74423@@ -25,7 +25,8 @@
74424 struct sensor_device_attribute{
74425 struct device_attribute dev_attr;
74426 int index;
74427-};
74428+} __do_const;
74429+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
74430 #define to_sensor_dev_attr(_dev_attr) \
74431 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
74432
74433@@ -41,7 +42,7 @@ struct sensor_device_attribute_2 {
74434 struct device_attribute dev_attr;
74435 u8 index;
74436 u8 nr;
74437-};
74438+} __do_const;
74439 #define to_sensor_dev_attr_2(_dev_attr) \
74440 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
74441
74442diff --git a/include/linux/i2c.h b/include/linux/i2c.h
74443index e988fa9..ff9f17e 100644
74444--- a/include/linux/i2c.h
74445+++ b/include/linux/i2c.h
74446@@ -366,6 +366,7 @@ struct i2c_algorithm {
74447 /* To determine what the adapter supports */
74448 u32 (*functionality) (struct i2c_adapter *);
74449 };
74450+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
74451
74452 /**
74453 * struct i2c_bus_recovery_info - I2C bus recovery information
74454diff --git a/include/linux/i2o.h b/include/linux/i2o.h
74455index d23c3c2..eb63c81 100644
74456--- a/include/linux/i2o.h
74457+++ b/include/linux/i2o.h
74458@@ -565,7 +565,7 @@ struct i2o_controller {
74459 struct i2o_device *exec; /* Executive */
74460 #if BITS_PER_LONG == 64
74461 spinlock_t context_list_lock; /* lock for context_list */
74462- atomic_t context_list_counter; /* needed for unique contexts */
74463+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
74464 struct list_head context_list; /* list of context id's
74465 and pointers */
74466 #endif
74467diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
74468index aff7ad8..3942bbd 100644
74469--- a/include/linux/if_pppox.h
74470+++ b/include/linux/if_pppox.h
74471@@ -76,7 +76,7 @@ struct pppox_proto {
74472 int (*ioctl)(struct socket *sock, unsigned int cmd,
74473 unsigned long arg);
74474 struct module *owner;
74475-};
74476+} __do_const;
74477
74478 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
74479 extern void unregister_pppox_proto(int proto_num);
74480diff --git a/include/linux/init.h b/include/linux/init.h
74481index e73f2b7..cc996e0 100644
74482--- a/include/linux/init.h
74483+++ b/include/linux/init.h
74484@@ -39,9 +39,17 @@
74485 * Also note, that this data cannot be "const".
74486 */
74487
74488+#define add_init_latent_entropy __latent_entropy
74489+
74490+#ifdef CONFIG_MEMORY_HOTPLUG
74491+#define add_meminit_latent_entropy
74492+#else
74493+#define add_meminit_latent_entropy __latent_entropy
74494+#endif
74495+
74496 /* These are for everybody (although not all archs will actually
74497 discard it in modules) */
74498-#define __init __section(.init.text) __cold notrace
74499+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
74500 #define __initdata __section(.init.data)
74501 #define __initconst __constsection(.init.rodata)
74502 #define __exitdata __section(.exit.data)
74503@@ -102,7 +110,7 @@
74504 #define __cpuexitconst
74505
74506 /* Used for MEMORY_HOTPLUG */
74507-#define __meminit __section(.meminit.text) __cold notrace
74508+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
74509 #define __meminitdata __section(.meminit.data)
74510 #define __meminitconst __constsection(.meminit.rodata)
74511 #define __memexit __section(.memexit.text) __exitused __cold notrace
74512diff --git a/include/linux/init_task.h b/include/linux/init_task.h
74513index 5cd0f09..c9f67cc 100644
74514--- a/include/linux/init_task.h
74515+++ b/include/linux/init_task.h
74516@@ -154,6 +154,12 @@ extern struct task_group root_task_group;
74517
74518 #define INIT_TASK_COMM "swapper"
74519
74520+#ifdef CONFIG_X86
74521+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
74522+#else
74523+#define INIT_TASK_THREAD_INFO
74524+#endif
74525+
74526 /*
74527 * INIT_TASK is used to set up the first task table, touch at
74528 * your own risk!. Base=0, limit=0x1fffff (=2MB)
74529@@ -193,6 +199,7 @@ extern struct task_group root_task_group;
74530 RCU_POINTER_INITIALIZER(cred, &init_cred), \
74531 .comm = INIT_TASK_COMM, \
74532 .thread = INIT_THREAD, \
74533+ INIT_TASK_THREAD_INFO \
74534 .fs = &init_fs, \
74535 .files = &init_files, \
74536 .signal = &init_signals, \
74537diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
74538index 5fa5afe..ac55b25 100644
74539--- a/include/linux/interrupt.h
74540+++ b/include/linux/interrupt.h
74541@@ -430,7 +430,7 @@ enum
74542 /* map softirq index to softirq name. update 'softirq_to_name' in
74543 * kernel/softirq.c when adding a new softirq.
74544 */
74545-extern char *softirq_to_name[NR_SOFTIRQS];
74546+extern const char * const softirq_to_name[NR_SOFTIRQS];
74547
74548 /* softirq mask and active fields moved to irq_cpustat_t in
74549 * asm/hardirq.h to get better cache usage. KAO
74550@@ -438,12 +438,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
74551
74552 struct softirq_action
74553 {
74554- void (*action)(struct softirq_action *);
74555-};
74556+ void (*action)(void);
74557+} __no_const;
74558
74559 asmlinkage void do_softirq(void);
74560 asmlinkage void __do_softirq(void);
74561-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
74562+extern void open_softirq(int nr, void (*action)(void));
74563 extern void softirq_init(void);
74564 extern void __raise_softirq_irqoff(unsigned int nr);
74565
74566diff --git a/include/linux/iommu.h b/include/linux/iommu.h
74567index 3aeb730..2177f39 100644
74568--- a/include/linux/iommu.h
74569+++ b/include/linux/iommu.h
74570@@ -113,7 +113,7 @@ struct iommu_ops {
74571 u32 (*domain_get_windows)(struct iommu_domain *domain);
74572
74573 unsigned long pgsize_bitmap;
74574-};
74575+} __do_const;
74576
74577 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
74578 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
74579diff --git a/include/linux/ioport.h b/include/linux/ioport.h
74580index 89b7c24..382af74 100644
74581--- a/include/linux/ioport.h
74582+++ b/include/linux/ioport.h
74583@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
74584 int adjust_resource(struct resource *res, resource_size_t start,
74585 resource_size_t size);
74586 resource_size_t resource_alignment(struct resource *res);
74587-static inline resource_size_t resource_size(const struct resource *res)
74588+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
74589 {
74590 return res->end - res->start + 1;
74591 }
74592diff --git a/include/linux/irq.h b/include/linux/irq.h
74593index f04d3ba..bcf2cfb 100644
74594--- a/include/linux/irq.h
74595+++ b/include/linux/irq.h
74596@@ -333,7 +333,8 @@ struct irq_chip {
74597 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
74598
74599 unsigned long flags;
74600-};
74601+} __do_const;
74602+typedef struct irq_chip __no_const irq_chip_no_const;
74603
74604 /*
74605 * irq_chip specific flags
74606diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
74607index 3e203eb..3fe68d0 100644
74608--- a/include/linux/irqchip/arm-gic.h
74609+++ b/include/linux/irqchip/arm-gic.h
74610@@ -59,9 +59,11 @@
74611
74612 #ifndef __ASSEMBLY__
74613
74614+#include <linux/irq.h>
74615+
74616 struct device_node;
74617
74618-extern struct irq_chip gic_arch_extn;
74619+extern irq_chip_no_const gic_arch_extn;
74620
74621 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
74622 u32 offset, struct device_node *);
74623diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
74624index 6883e19..e854fcb 100644
74625--- a/include/linux/kallsyms.h
74626+++ b/include/linux/kallsyms.h
74627@@ -15,7 +15,8 @@
74628
74629 struct module;
74630
74631-#ifdef CONFIG_KALLSYMS
74632+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
74633+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
74634 /* Lookup the address for a symbol. Returns 0 if not found. */
74635 unsigned long kallsyms_lookup_name(const char *name);
74636
74637@@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
74638 /* Stupid that this does nothing, but I didn't create this mess. */
74639 #define __print_symbol(fmt, addr)
74640 #endif /*CONFIG_KALLSYMS*/
74641+#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
74642+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
74643+extern unsigned long kallsyms_lookup_name(const char *name);
74644+extern void __print_symbol(const char *fmt, unsigned long address);
74645+extern int sprint_backtrace(char *buffer, unsigned long address);
74646+extern int sprint_symbol(char *buffer, unsigned long address);
74647+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
74648+const char *kallsyms_lookup(unsigned long addr,
74649+ unsigned long *symbolsize,
74650+ unsigned long *offset,
74651+ char **modname, char *namebuf);
74652+extern int kallsyms_lookup_size_offset(unsigned long addr,
74653+ unsigned long *symbolsize,
74654+ unsigned long *offset);
74655+#endif
74656
74657 /* This macro allows us to keep printk typechecking */
74658 static __printf(1, 2)
74659diff --git a/include/linux/key-type.h b/include/linux/key-type.h
74660index 518a53a..5e28358 100644
74661--- a/include/linux/key-type.h
74662+++ b/include/linux/key-type.h
74663@@ -125,7 +125,7 @@ struct key_type {
74664 /* internal fields */
74665 struct list_head link; /* link in types list */
74666 struct lock_class_key lock_class; /* key->sem lock class */
74667-};
74668+} __do_const;
74669
74670 extern struct key_type key_type_keyring;
74671
74672diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
74673index c6e091b..a940adf 100644
74674--- a/include/linux/kgdb.h
74675+++ b/include/linux/kgdb.h
74676@@ -52,7 +52,7 @@ extern int kgdb_connected;
74677 extern int kgdb_io_module_registered;
74678
74679 extern atomic_t kgdb_setting_breakpoint;
74680-extern atomic_t kgdb_cpu_doing_single_step;
74681+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
74682
74683 extern struct task_struct *kgdb_usethread;
74684 extern struct task_struct *kgdb_contthread;
74685@@ -254,7 +254,7 @@ struct kgdb_arch {
74686 void (*correct_hw_break)(void);
74687
74688 void (*enable_nmi)(bool on);
74689-};
74690+} __do_const;
74691
74692 /**
74693 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
74694@@ -279,7 +279,7 @@ struct kgdb_io {
74695 void (*pre_exception) (void);
74696 void (*post_exception) (void);
74697 int is_console;
74698-};
74699+} __do_const;
74700
74701 extern struct kgdb_arch arch_kgdb_ops;
74702
74703diff --git a/include/linux/kmod.h b/include/linux/kmod.h
74704index 0555cc6..b16a7a4 100644
74705--- a/include/linux/kmod.h
74706+++ b/include/linux/kmod.h
74707@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
74708 * usually useless though. */
74709 extern __printf(2, 3)
74710 int __request_module(bool wait, const char *name, ...);
74711+extern __printf(3, 4)
74712+int ___request_module(bool wait, char *param_name, const char *name, ...);
74713 #define request_module(mod...) __request_module(true, mod)
74714 #define request_module_nowait(mod...) __request_module(false, mod)
74715 #define try_then_request_module(x, mod...) \
74716diff --git a/include/linux/kobject.h b/include/linux/kobject.h
74717index 939b112..ed6ed51 100644
74718--- a/include/linux/kobject.h
74719+++ b/include/linux/kobject.h
74720@@ -111,7 +111,7 @@ struct kobj_type {
74721 struct attribute **default_attrs;
74722 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
74723 const void *(*namespace)(struct kobject *kobj);
74724-};
74725+} __do_const;
74726
74727 struct kobj_uevent_env {
74728 char *envp[UEVENT_NUM_ENVP];
74729@@ -134,6 +134,7 @@ struct kobj_attribute {
74730 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
74731 const char *buf, size_t count);
74732 };
74733+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
74734
74735 extern const struct sysfs_ops kobj_sysfs_ops;
74736
74737diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
74738index f66b065..c2c29b4 100644
74739--- a/include/linux/kobject_ns.h
74740+++ b/include/linux/kobject_ns.h
74741@@ -43,7 +43,7 @@ struct kobj_ns_type_operations {
74742 const void *(*netlink_ns)(struct sock *sk);
74743 const void *(*initial_ns)(void);
74744 void (*drop_ns)(void *);
74745-};
74746+} __do_const;
74747
74748 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
74749 int kobj_ns_type_registered(enum kobj_ns_type type);
74750diff --git a/include/linux/kref.h b/include/linux/kref.h
74751index 484604d..0f6c5b6 100644
74752--- a/include/linux/kref.h
74753+++ b/include/linux/kref.h
74754@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
74755 static inline int kref_sub(struct kref *kref, unsigned int count,
74756 void (*release)(struct kref *kref))
74757 {
74758- WARN_ON(release == NULL);
74759+ BUG_ON(release == NULL);
74760
74761 if (atomic_sub_and_test((int) count, &kref->refcount)) {
74762 release(kref);
74763diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
74764index a63d83e..77fd685 100644
74765--- a/include/linux/kvm_host.h
74766+++ b/include/linux/kvm_host.h
74767@@ -446,7 +446,7 @@ static inline void kvm_irqfd_exit(void)
74768 {
74769 }
74770 #endif
74771-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
74772+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
74773 struct module *module);
74774 void kvm_exit(void);
74775
74776@@ -618,7 +618,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
74777 struct kvm_guest_debug *dbg);
74778 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
74779
74780-int kvm_arch_init(void *opaque);
74781+int kvm_arch_init(const void *opaque);
74782 void kvm_arch_exit(void);
74783
74784 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
74785diff --git a/include/linux/libata.h b/include/linux/libata.h
74786index 4ea55bb..dcd2601 100644
74787--- a/include/linux/libata.h
74788+++ b/include/linux/libata.h
74789@@ -924,7 +924,7 @@ struct ata_port_operations {
74790 * fields must be pointers.
74791 */
74792 const struct ata_port_operations *inherits;
74793-};
74794+} __do_const;
74795
74796 struct ata_port_info {
74797 unsigned long flags;
74798diff --git a/include/linux/linkage.h b/include/linux/linkage.h
74799index d3e8ad2..a949f68 100644
74800--- a/include/linux/linkage.h
74801+++ b/include/linux/linkage.h
74802@@ -31,6 +31,7 @@
74803 #endif
74804
74805 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
74806+#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
74807 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
74808
74809 /*
74810diff --git a/include/linux/list.h b/include/linux/list.h
74811index f4d8a2f..38e6e46 100644
74812--- a/include/linux/list.h
74813+++ b/include/linux/list.h
74814@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
74815 extern void list_del(struct list_head *entry);
74816 #endif
74817
74818+extern void __pax_list_add(struct list_head *new,
74819+ struct list_head *prev,
74820+ struct list_head *next);
74821+static inline void pax_list_add(struct list_head *new, struct list_head *head)
74822+{
74823+ __pax_list_add(new, head, head->next);
74824+}
74825+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
74826+{
74827+ __pax_list_add(new, head->prev, head);
74828+}
74829+extern void pax_list_del(struct list_head *entry);
74830+
74831 /**
74832 * list_replace - replace old entry by new one
74833 * @old : the element to be replaced
74834@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
74835 INIT_LIST_HEAD(entry);
74836 }
74837
74838+extern void pax_list_del_init(struct list_head *entry);
74839+
74840 /**
74841 * list_move - delete from one list and add as another's head
74842 * @list: the entry to move
74843diff --git a/include/linux/math64.h b/include/linux/math64.h
74844index 2913b86..8dcbb1e 100644
74845--- a/include/linux/math64.h
74846+++ b/include/linux/math64.h
74847@@ -15,7 +15,7 @@
74848 * This is commonly provided by 32bit archs to provide an optimized 64bit
74849 * divide.
74850 */
74851-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
74852+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
74853 {
74854 *remainder = dividend % divisor;
74855 return dividend / divisor;
74856@@ -33,7 +33,7 @@ static inline s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
74857 /**
74858 * div64_u64 - unsigned 64bit divide with 64bit divisor
74859 */
74860-static inline u64 div64_u64(u64 dividend, u64 divisor)
74861+static inline u64 __intentional_overflow(0) div64_u64(u64 dividend, u64 divisor)
74862 {
74863 return dividend / divisor;
74864 }
74865@@ -52,7 +52,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
74866 #define div64_ul(x, y) div_u64((x), (y))
74867
74868 #ifndef div_u64_rem
74869-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
74870+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
74871 {
74872 *remainder = do_div(dividend, divisor);
74873 return dividend;
74874@@ -81,7 +81,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
74875 * divide.
74876 */
74877 #ifndef div_u64
74878-static inline u64 div_u64(u64 dividend, u32 divisor)
74879+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
74880 {
74881 u32 remainder;
74882 return div_u64_rem(dividend, divisor, &remainder);
74883diff --git a/include/linux/mm.h b/include/linux/mm.h
74884index f022460..6ecf4f9 100644
74885--- a/include/linux/mm.h
74886+++ b/include/linux/mm.h
74887@@ -113,6 +113,11 @@ extern unsigned int kobjsize(const void *objp);
74888 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
74889 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
74890 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
74891+
74892+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
74893+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
74894+#endif
74895+
74896 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
74897
74898 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
74899@@ -208,8 +213,8 @@ struct vm_operations_struct {
74900 /* called by access_process_vm when get_user_pages() fails, typically
74901 * for use by special VMAs that can switch between memory and hardware
74902 */
74903- int (*access)(struct vm_area_struct *vma, unsigned long addr,
74904- void *buf, int len, int write);
74905+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
74906+ void *buf, size_t len, int write);
74907 #ifdef CONFIG_NUMA
74908 /*
74909 * set_policy() op must add a reference to any non-NULL @new mempolicy
74910@@ -239,6 +244,7 @@ struct vm_operations_struct {
74911 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
74912 unsigned long size, pgoff_t pgoff);
74913 };
74914+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
74915
74916 struct mmu_gather;
74917 struct inode;
74918@@ -983,8 +989,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
74919 unsigned long *pfn);
74920 int follow_phys(struct vm_area_struct *vma, unsigned long address,
74921 unsigned int flags, unsigned long *prot, resource_size_t *phys);
74922-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
74923- void *buf, int len, int write);
74924+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
74925+ void *buf, size_t len, int write);
74926
74927 static inline void unmap_shared_mapping_range(struct address_space *mapping,
74928 loff_t const holebegin, loff_t const holelen)
74929@@ -1023,9 +1029,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
74930 }
74931 #endif
74932
74933-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
74934-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
74935- void *buf, int len, int write);
74936+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
74937+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
74938+ void *buf, size_t len, int write);
74939
74940 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
74941 unsigned long start, unsigned long nr_pages,
74942@@ -1057,34 +1063,6 @@ int set_page_dirty(struct page *page);
74943 int set_page_dirty_lock(struct page *page);
74944 int clear_page_dirty_for_io(struct page *page);
74945
74946-/* Is the vma a continuation of the stack vma above it? */
74947-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
74948-{
74949- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
74950-}
74951-
74952-static inline int stack_guard_page_start(struct vm_area_struct *vma,
74953- unsigned long addr)
74954-{
74955- return (vma->vm_flags & VM_GROWSDOWN) &&
74956- (vma->vm_start == addr) &&
74957- !vma_growsdown(vma->vm_prev, addr);
74958-}
74959-
74960-/* Is the vma a continuation of the stack vma below it? */
74961-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
74962-{
74963- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
74964-}
74965-
74966-static inline int stack_guard_page_end(struct vm_area_struct *vma,
74967- unsigned long addr)
74968-{
74969- return (vma->vm_flags & VM_GROWSUP) &&
74970- (vma->vm_end == addr) &&
74971- !vma_growsup(vma->vm_next, addr);
74972-}
74973-
74974 extern pid_t
74975 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
74976
74977@@ -1184,6 +1162,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
74978 }
74979 #endif
74980
74981+#ifdef CONFIG_MMU
74982+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
74983+#else
74984+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
74985+{
74986+ return __pgprot(0);
74987+}
74988+#endif
74989+
74990 int vma_wants_writenotify(struct vm_area_struct *vma);
74991
74992 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
74993@@ -1202,8 +1189,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
74994 {
74995 return 0;
74996 }
74997+
74998+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
74999+ unsigned long address)
75000+{
75001+ return 0;
75002+}
75003 #else
75004 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
75005+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
75006 #endif
75007
75008 #ifdef __PAGETABLE_PMD_FOLDED
75009@@ -1212,8 +1206,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
75010 {
75011 return 0;
75012 }
75013+
75014+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
75015+ unsigned long address)
75016+{
75017+ return 0;
75018+}
75019 #else
75020 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
75021+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
75022 #endif
75023
75024 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
75025@@ -1231,11 +1232,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
75026 NULL: pud_offset(pgd, address);
75027 }
75028
75029+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
75030+{
75031+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
75032+ NULL: pud_offset(pgd, address);
75033+}
75034+
75035 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
75036 {
75037 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
75038 NULL: pmd_offset(pud, address);
75039 }
75040+
75041+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
75042+{
75043+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
75044+ NULL: pmd_offset(pud, address);
75045+}
75046 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
75047
75048 #if USE_SPLIT_PTLOCKS
75049@@ -1531,6 +1544,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75050 unsigned long len, unsigned long prot, unsigned long flags,
75051 unsigned long pgoff, unsigned long *populate);
75052 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
75053+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
75054
75055 #ifdef CONFIG_MMU
75056 extern int __mm_populate(unsigned long addr, unsigned long len,
75057@@ -1559,10 +1573,11 @@ struct vm_unmapped_area_info {
75058 unsigned long high_limit;
75059 unsigned long align_mask;
75060 unsigned long align_offset;
75061+ unsigned long threadstack_offset;
75062 };
75063
75064-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
75065-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
75066+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
75067+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
75068
75069 /*
75070 * Search for an unmapped address range.
75071@@ -1574,7 +1589,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
75072 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
75073 */
75074 static inline unsigned long
75075-vm_unmapped_area(struct vm_unmapped_area_info *info)
75076+vm_unmapped_area(const struct vm_unmapped_area_info *info)
75077 {
75078 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
75079 return unmapped_area(info);
75080@@ -1637,6 +1652,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
75081 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
75082 struct vm_area_struct **pprev);
75083
75084+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
75085+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
75086+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
75087+
75088 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
75089 NULL if none. Assume start_addr < end_addr. */
75090 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
75091@@ -1665,15 +1684,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
75092 return vma;
75093 }
75094
75095-#ifdef CONFIG_MMU
75096-pgprot_t vm_get_page_prot(unsigned long vm_flags);
75097-#else
75098-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
75099-{
75100- return __pgprot(0);
75101-}
75102-#endif
75103-
75104 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
75105 unsigned long change_prot_numa(struct vm_area_struct *vma,
75106 unsigned long start, unsigned long end);
75107@@ -1725,6 +1735,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
75108 static inline void vm_stat_account(struct mm_struct *mm,
75109 unsigned long flags, struct file *file, long pages)
75110 {
75111+
75112+#ifdef CONFIG_PAX_RANDMMAP
75113+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
75114+#endif
75115+
75116 mm->total_vm += pages;
75117 }
75118 #endif /* CONFIG_PROC_FS */
75119@@ -1805,7 +1820,7 @@ extern int unpoison_memory(unsigned long pfn);
75120 extern int sysctl_memory_failure_early_kill;
75121 extern int sysctl_memory_failure_recovery;
75122 extern void shake_page(struct page *p, int access);
75123-extern atomic_long_t num_poisoned_pages;
75124+extern atomic_long_unchecked_t num_poisoned_pages;
75125 extern int soft_offline_page(struct page *page, int flags);
75126
75127 extern void dump_page(struct page *page);
75128@@ -1842,5 +1857,11 @@ void __init setup_nr_node_ids(void);
75129 static inline void setup_nr_node_ids(void) {}
75130 #endif
75131
75132+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
75133+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
75134+#else
75135+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
75136+#endif
75137+
75138 #endif /* __KERNEL__ */
75139 #endif /* _LINUX_MM_H */
75140diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
75141index faf4b7c..1e70c6e 100644
75142--- a/include/linux/mm_types.h
75143+++ b/include/linux/mm_types.h
75144@@ -289,6 +289,8 @@ struct vm_area_struct {
75145 #ifdef CONFIG_NUMA
75146 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
75147 #endif
75148+
75149+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
75150 };
75151
75152 struct core_thread {
75153@@ -435,6 +437,24 @@ struct mm_struct {
75154 int first_nid;
75155 #endif
75156 struct uprobes_state uprobes_state;
75157+
75158+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
75159+ unsigned long pax_flags;
75160+#endif
75161+
75162+#ifdef CONFIG_PAX_DLRESOLVE
75163+ unsigned long call_dl_resolve;
75164+#endif
75165+
75166+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
75167+ unsigned long call_syscall;
75168+#endif
75169+
75170+#ifdef CONFIG_PAX_ASLR
75171+ unsigned long delta_mmap; /* randomized offset */
75172+ unsigned long delta_stack; /* randomized offset */
75173+#endif
75174+
75175 };
75176
75177 /* first nid will either be a valid NID or one of these values */
75178diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
75179index c5d5278..f0b68c8 100644
75180--- a/include/linux/mmiotrace.h
75181+++ b/include/linux/mmiotrace.h
75182@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
75183 /* Called from ioremap.c */
75184 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
75185 void __iomem *addr);
75186-extern void mmiotrace_iounmap(volatile void __iomem *addr);
75187+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
75188
75189 /* For anyone to insert markers. Remember trailing newline. */
75190 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
75191@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
75192 {
75193 }
75194
75195-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
75196+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
75197 {
75198 }
75199
75200diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
75201index af4a3b7..9ad8889 100644
75202--- a/include/linux/mmzone.h
75203+++ b/include/linux/mmzone.h
75204@@ -396,7 +396,7 @@ struct zone {
75205 unsigned long flags; /* zone flags, see below */
75206
75207 /* Zone statistics */
75208- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
75209+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
75210
75211 /*
75212 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
75213diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
75214index 45e9214..a7227d6 100644
75215--- a/include/linux/mod_devicetable.h
75216+++ b/include/linux/mod_devicetable.h
75217@@ -13,7 +13,7 @@
75218 typedef unsigned long kernel_ulong_t;
75219 #endif
75220
75221-#define PCI_ANY_ID (~0)
75222+#define PCI_ANY_ID ((__u16)~0)
75223
75224 struct pci_device_id {
75225 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
75226@@ -139,7 +139,7 @@ struct usb_device_id {
75227 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
75228 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
75229
75230-#define HID_ANY_ID (~0)
75231+#define HID_ANY_ID (~0U)
75232 #define HID_BUS_ANY 0xffff
75233 #define HID_GROUP_ANY 0x0000
75234
75235@@ -467,7 +467,7 @@ struct dmi_system_id {
75236 const char *ident;
75237 struct dmi_strmatch matches[4];
75238 void *driver_data;
75239-};
75240+} __do_const;
75241 /*
75242 * struct dmi_device_id appears during expansion of
75243 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
75244diff --git a/include/linux/module.h b/include/linux/module.h
75245index 46f1ea0..a34ca37 100644
75246--- a/include/linux/module.h
75247+++ b/include/linux/module.h
75248@@ -17,9 +17,11 @@
75249 #include <linux/moduleparam.h>
75250 #include <linux/tracepoint.h>
75251 #include <linux/export.h>
75252+#include <linux/fs.h>
75253
75254 #include <linux/percpu.h>
75255 #include <asm/module.h>
75256+#include <asm/pgtable.h>
75257
75258 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
75259 #define MODULE_SIG_STRING "~Module signature appended~\n"
75260@@ -54,12 +56,13 @@ struct module_attribute {
75261 int (*test)(struct module *);
75262 void (*free)(struct module *);
75263 };
75264+typedef struct module_attribute __no_const module_attribute_no_const;
75265
75266 struct module_version_attribute {
75267 struct module_attribute mattr;
75268 const char *module_name;
75269 const char *version;
75270-} __attribute__ ((__aligned__(sizeof(void *))));
75271+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
75272
75273 extern ssize_t __modver_version_show(struct module_attribute *,
75274 struct module_kobject *, char *);
75275@@ -232,7 +235,7 @@ struct module
75276
75277 /* Sysfs stuff. */
75278 struct module_kobject mkobj;
75279- struct module_attribute *modinfo_attrs;
75280+ module_attribute_no_const *modinfo_attrs;
75281 const char *version;
75282 const char *srcversion;
75283 struct kobject *holders_dir;
75284@@ -281,19 +284,16 @@ struct module
75285 int (*init)(void);
75286
75287 /* If this is non-NULL, vfree after init() returns */
75288- void *module_init;
75289+ void *module_init_rx, *module_init_rw;
75290
75291 /* Here is the actual code + data, vfree'd on unload. */
75292- void *module_core;
75293+ void *module_core_rx, *module_core_rw;
75294
75295 /* Here are the sizes of the init and core sections */
75296- unsigned int init_size, core_size;
75297+ unsigned int init_size_rw, core_size_rw;
75298
75299 /* The size of the executable code in each section. */
75300- unsigned int init_text_size, core_text_size;
75301-
75302- /* Size of RO sections of the module (text+rodata) */
75303- unsigned int init_ro_size, core_ro_size;
75304+ unsigned int init_size_rx, core_size_rx;
75305
75306 /* Arch-specific module values */
75307 struct mod_arch_specific arch;
75308@@ -349,6 +349,10 @@ struct module
75309 #ifdef CONFIG_EVENT_TRACING
75310 struct ftrace_event_call **trace_events;
75311 unsigned int num_trace_events;
75312+ struct file_operations trace_id;
75313+ struct file_operations trace_enable;
75314+ struct file_operations trace_format;
75315+ struct file_operations trace_filter;
75316 #endif
75317 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
75318 unsigned int num_ftrace_callsites;
75319@@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
75320 bool is_module_percpu_address(unsigned long addr);
75321 bool is_module_text_address(unsigned long addr);
75322
75323+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
75324+{
75325+
75326+#ifdef CONFIG_PAX_KERNEXEC
75327+ if (ktla_ktva(addr) >= (unsigned long)start &&
75328+ ktla_ktva(addr) < (unsigned long)start + size)
75329+ return 1;
75330+#endif
75331+
75332+ return ((void *)addr >= start && (void *)addr < start + size);
75333+}
75334+
75335+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
75336+{
75337+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
75338+}
75339+
75340+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
75341+{
75342+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
75343+}
75344+
75345+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
75346+{
75347+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
75348+}
75349+
75350+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
75351+{
75352+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
75353+}
75354+
75355 static inline int within_module_core(unsigned long addr, const struct module *mod)
75356 {
75357- return (unsigned long)mod->module_core <= addr &&
75358- addr < (unsigned long)mod->module_core + mod->core_size;
75359+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
75360 }
75361
75362 static inline int within_module_init(unsigned long addr, const struct module *mod)
75363 {
75364- return (unsigned long)mod->module_init <= addr &&
75365- addr < (unsigned long)mod->module_init + mod->init_size;
75366+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
75367 }
75368
75369 /* Search for module by name: must hold module_mutex. */
75370diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
75371index 560ca53..ef621ef 100644
75372--- a/include/linux/moduleloader.h
75373+++ b/include/linux/moduleloader.h
75374@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
75375 sections. Returns NULL on failure. */
75376 void *module_alloc(unsigned long size);
75377
75378+#ifdef CONFIG_PAX_KERNEXEC
75379+void *module_alloc_exec(unsigned long size);
75380+#else
75381+#define module_alloc_exec(x) module_alloc(x)
75382+#endif
75383+
75384 /* Free memory returned from module_alloc. */
75385 void module_free(struct module *mod, void *module_region);
75386
75387+#ifdef CONFIG_PAX_KERNEXEC
75388+void module_free_exec(struct module *mod, void *module_region);
75389+#else
75390+#define module_free_exec(x, y) module_free((x), (y))
75391+#endif
75392+
75393 /*
75394 * Apply the given relocation to the (simplified) ELF. Return -error
75395 * or 0.
75396@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
75397 unsigned int relsec,
75398 struct module *me)
75399 {
75400+#ifdef CONFIG_MODULES
75401 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
75402+#endif
75403 return -ENOEXEC;
75404 }
75405 #endif
75406@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
75407 unsigned int relsec,
75408 struct module *me)
75409 {
75410+#ifdef CONFIG_MODULES
75411 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
75412+#endif
75413 return -ENOEXEC;
75414 }
75415 #endif
75416diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
75417index 27d9da3..5d94aa3 100644
75418--- a/include/linux/moduleparam.h
75419+++ b/include/linux/moduleparam.h
75420@@ -284,7 +284,7 @@ static inline void __kernel_param_unlock(void)
75421 * @len is usually just sizeof(string).
75422 */
75423 #define module_param_string(name, string, len, perm) \
75424- static const struct kparam_string __param_string_##name \
75425+ static const struct kparam_string __param_string_##name __used \
75426 = { len, string }; \
75427 __module_param_call(MODULE_PARAM_PREFIX, name, \
75428 &param_ops_string, \
75429@@ -423,7 +423,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
75430 */
75431 #define module_param_array_named(name, array, type, nump, perm) \
75432 param_check_##type(name, &(array)[0]); \
75433- static const struct kparam_array __param_arr_##name \
75434+ static const struct kparam_array __param_arr_##name __used \
75435 = { .max = ARRAY_SIZE(array), .num = nump, \
75436 .ops = &param_ops_##type, \
75437 .elemsize = sizeof(array[0]), .elem = array }; \
75438diff --git a/include/linux/namei.h b/include/linux/namei.h
75439index 5a5ff57..5ae5070 100644
75440--- a/include/linux/namei.h
75441+++ b/include/linux/namei.h
75442@@ -19,7 +19,7 @@ struct nameidata {
75443 unsigned seq;
75444 int last_type;
75445 unsigned depth;
75446- char *saved_names[MAX_NESTED_LINKS + 1];
75447+ const char *saved_names[MAX_NESTED_LINKS + 1];
75448 };
75449
75450 /*
75451@@ -84,12 +84,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
75452
75453 extern void nd_jump_link(struct nameidata *nd, struct path *path);
75454
75455-static inline void nd_set_link(struct nameidata *nd, char *path)
75456+static inline void nd_set_link(struct nameidata *nd, const char *path)
75457 {
75458 nd->saved_names[nd->depth] = path;
75459 }
75460
75461-static inline char *nd_get_link(struct nameidata *nd)
75462+static inline const char *nd_get_link(const struct nameidata *nd)
75463 {
75464 return nd->saved_names[nd->depth];
75465 }
75466diff --git a/include/linux/net.h b/include/linux/net.h
75467index 4f27575..fc8a65f 100644
75468--- a/include/linux/net.h
75469+++ b/include/linux/net.h
75470@@ -183,7 +183,7 @@ struct net_proto_family {
75471 int (*create)(struct net *net, struct socket *sock,
75472 int protocol, int kern);
75473 struct module *owner;
75474-};
75475+} __do_const;
75476
75477 struct iovec;
75478 struct kvec;
75479diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
75480index 9a41568..203d903 100644
75481--- a/include/linux/netdevice.h
75482+++ b/include/linux/netdevice.h
75483@@ -1061,6 +1061,7 @@ struct net_device_ops {
75484 int (*ndo_change_carrier)(struct net_device *dev,
75485 bool new_carrier);
75486 };
75487+typedef struct net_device_ops __no_const net_device_ops_no_const;
75488
75489 /*
75490 * The DEVICE structure.
75491@@ -1131,7 +1132,7 @@ struct net_device {
75492 int iflink;
75493
75494 struct net_device_stats stats;
75495- atomic_long_t rx_dropped; /* dropped packets by core network
75496+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
75497 * Do not use this in drivers.
75498 */
75499
75500diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
75501index de70f7b..2675e91 100644
75502--- a/include/linux/netfilter.h
75503+++ b/include/linux/netfilter.h
75504@@ -82,7 +82,7 @@ struct nf_sockopt_ops {
75505 #endif
75506 /* Use the module struct to lock set/get code in place */
75507 struct module *owner;
75508-};
75509+} __do_const;
75510
75511 /* Function to register/unregister hook points. */
75512 int nf_register_hook(struct nf_hook_ops *reg);
75513diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
75514index d80e275..c3510b8 100644
75515--- a/include/linux/netfilter/ipset/ip_set.h
75516+++ b/include/linux/netfilter/ipset/ip_set.h
75517@@ -124,7 +124,7 @@ struct ip_set_type_variant {
75518 /* Return true if "b" set is the same as "a"
75519 * according to the create set parameters */
75520 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
75521-};
75522+} __do_const;
75523
75524 /* The core set type structure */
75525 struct ip_set_type {
75526diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
75527index cadb740..d7c37c0 100644
75528--- a/include/linux/netfilter/nfnetlink.h
75529+++ b/include/linux/netfilter/nfnetlink.h
75530@@ -16,7 +16,7 @@ struct nfnl_callback {
75531 const struct nlattr * const cda[]);
75532 const struct nla_policy *policy; /* netlink attribute policy */
75533 const u_int16_t attr_count; /* number of nlattr's */
75534-};
75535+} __do_const;
75536
75537 struct nfnetlink_subsystem {
75538 const char *name;
75539diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
75540new file mode 100644
75541index 0000000..33f4af8
75542--- /dev/null
75543+++ b/include/linux/netfilter/xt_gradm.h
75544@@ -0,0 +1,9 @@
75545+#ifndef _LINUX_NETFILTER_XT_GRADM_H
75546+#define _LINUX_NETFILTER_XT_GRADM_H 1
75547+
75548+struct xt_gradm_mtinfo {
75549+ __u16 flags;
75550+ __u16 invflags;
75551+};
75552+
75553+#endif
75554diff --git a/include/linux/nls.h b/include/linux/nls.h
75555index 5dc635f..35f5e11 100644
75556--- a/include/linux/nls.h
75557+++ b/include/linux/nls.h
75558@@ -31,7 +31,7 @@ struct nls_table {
75559 const unsigned char *charset2upper;
75560 struct module *owner;
75561 struct nls_table *next;
75562-};
75563+} __do_const;
75564
75565 /* this value hold the maximum octet of charset */
75566 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
75567diff --git a/include/linux/notifier.h b/include/linux/notifier.h
75568index d14a4c3..a078786 100644
75569--- a/include/linux/notifier.h
75570+++ b/include/linux/notifier.h
75571@@ -54,7 +54,8 @@ struct notifier_block {
75572 notifier_fn_t notifier_call;
75573 struct notifier_block __rcu *next;
75574 int priority;
75575-};
75576+} __do_const;
75577+typedef struct notifier_block __no_const notifier_block_no_const;
75578
75579 struct atomic_notifier_head {
75580 spinlock_t lock;
75581diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
75582index a4c5624..79d6d88 100644
75583--- a/include/linux/oprofile.h
75584+++ b/include/linux/oprofile.h
75585@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
75586 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
75587 char const * name, ulong * val);
75588
75589-/** Create a file for read-only access to an atomic_t. */
75590+/** Create a file for read-only access to an atomic_unchecked_t. */
75591 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
75592- char const * name, atomic_t * val);
75593+ char const * name, atomic_unchecked_t * val);
75594
75595 /** create a directory */
75596 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
75597diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
75598index 8db71dc..a76bf2c 100644
75599--- a/include/linux/pci_hotplug.h
75600+++ b/include/linux/pci_hotplug.h
75601@@ -80,7 +80,8 @@ struct hotplug_slot_ops {
75602 int (*get_attention_status) (struct hotplug_slot *slot, u8 *value);
75603 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
75604 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
75605-};
75606+} __do_const;
75607+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
75608
75609 /**
75610 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
75611diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
75612index c43f6ea..2d4416f 100644
75613--- a/include/linux/perf_event.h
75614+++ b/include/linux/perf_event.h
75615@@ -328,8 +328,8 @@ struct perf_event {
75616
75617 enum perf_event_active_state state;
75618 unsigned int attach_state;
75619- local64_t count;
75620- atomic64_t child_count;
75621+ local64_t count; /* PaX: fix it one day */
75622+ atomic64_unchecked_t child_count;
75623
75624 /*
75625 * These are the total time in nanoseconds that the event
75626@@ -380,8 +380,8 @@ struct perf_event {
75627 * These accumulate total time (in nanoseconds) that children
75628 * events have been enabled and running, respectively.
75629 */
75630- atomic64_t child_total_time_enabled;
75631- atomic64_t child_total_time_running;
75632+ atomic64_unchecked_t child_total_time_enabled;
75633+ atomic64_unchecked_t child_total_time_running;
75634
75635 /*
75636 * Protect attach/detach and child_list:
75637@@ -703,7 +703,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
75638 entry->ip[entry->nr++] = ip;
75639 }
75640
75641-extern int sysctl_perf_event_paranoid;
75642+extern int sysctl_perf_event_legitimately_concerned;
75643 extern int sysctl_perf_event_mlock;
75644 extern int sysctl_perf_event_sample_rate;
75645 extern int sysctl_perf_cpu_time_max_percent;
75646@@ -718,19 +718,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
75647 loff_t *ppos);
75648
75649
75650+static inline bool perf_paranoid_any(void)
75651+{
75652+ return sysctl_perf_event_legitimately_concerned > 2;
75653+}
75654+
75655 static inline bool perf_paranoid_tracepoint_raw(void)
75656 {
75657- return sysctl_perf_event_paranoid > -1;
75658+ return sysctl_perf_event_legitimately_concerned > -1;
75659 }
75660
75661 static inline bool perf_paranoid_cpu(void)
75662 {
75663- return sysctl_perf_event_paranoid > 0;
75664+ return sysctl_perf_event_legitimately_concerned > 0;
75665 }
75666
75667 static inline bool perf_paranoid_kernel(void)
75668 {
75669- return sysctl_perf_event_paranoid > 1;
75670+ return sysctl_perf_event_legitimately_concerned > 1;
75671 }
75672
75673 extern void perf_event_init(void);
75674@@ -846,7 +851,7 @@ struct perf_pmu_events_attr {
75675 struct device_attribute attr;
75676 u64 id;
75677 const char *event_str;
75678-};
75679+} __do_const;
75680
75681 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
75682 static struct perf_pmu_events_attr _var = { \
75683diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
75684index b8809fe..ae4ccd0 100644
75685--- a/include/linux/pipe_fs_i.h
75686+++ b/include/linux/pipe_fs_i.h
75687@@ -47,10 +47,10 @@ struct pipe_inode_info {
75688 struct mutex mutex;
75689 wait_queue_head_t wait;
75690 unsigned int nrbufs, curbuf, buffers;
75691- unsigned int readers;
75692- unsigned int writers;
75693- unsigned int files;
75694- unsigned int waiting_writers;
75695+ atomic_t readers;
75696+ atomic_t writers;
75697+ atomic_t files;
75698+ atomic_t waiting_writers;
75699 unsigned int r_counter;
75700 unsigned int w_counter;
75701 struct page *tmp_page;
75702diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
75703index 5f28cae..3d23723 100644
75704--- a/include/linux/platform_data/usb-ehci-s5p.h
75705+++ b/include/linux/platform_data/usb-ehci-s5p.h
75706@@ -14,7 +14,7 @@
75707 struct s5p_ehci_platdata {
75708 int (*phy_init)(struct platform_device *pdev, int type);
75709 int (*phy_exit)(struct platform_device *pdev, int type);
75710-};
75711+} __no_const;
75712
75713 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
75714
75715diff --git a/include/linux/platform_data/usb-ohci-exynos.h b/include/linux/platform_data/usb-ohci-exynos.h
75716index c256c59..8ea94c7 100644
75717--- a/include/linux/platform_data/usb-ohci-exynos.h
75718+++ b/include/linux/platform_data/usb-ohci-exynos.h
75719@@ -14,7 +14,7 @@
75720 struct exynos4_ohci_platdata {
75721 int (*phy_init)(struct platform_device *pdev, int type);
75722 int (*phy_exit)(struct platform_device *pdev, int type);
75723-};
75724+} __no_const;
75725
75726 extern void exynos4_ohci_set_platdata(struct exynos4_ohci_platdata *pd);
75727
75728diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
75729index 7c1d252..c5c773e 100644
75730--- a/include/linux/pm_domain.h
75731+++ b/include/linux/pm_domain.h
75732@@ -48,7 +48,7 @@ struct gpd_dev_ops {
75733
75734 struct gpd_cpu_data {
75735 unsigned int saved_exit_latency;
75736- struct cpuidle_state *idle_state;
75737+ cpuidle_state_no_const *idle_state;
75738 };
75739
75740 struct generic_pm_domain {
75741diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
75742index 6fa7cea..7bf6415 100644
75743--- a/include/linux/pm_runtime.h
75744+++ b/include/linux/pm_runtime.h
75745@@ -103,7 +103,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
75746
75747 static inline void pm_runtime_mark_last_busy(struct device *dev)
75748 {
75749- ACCESS_ONCE(dev->power.last_busy) = jiffies;
75750+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
75751 }
75752
75753 #else /* !CONFIG_PM_RUNTIME */
75754diff --git a/include/linux/pnp.h b/include/linux/pnp.h
75755index 195aafc..49a7bc2 100644
75756--- a/include/linux/pnp.h
75757+++ b/include/linux/pnp.h
75758@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
75759 struct pnp_fixup {
75760 char id[7];
75761 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
75762-};
75763+} __do_const;
75764
75765 /* config parameters */
75766 #define PNP_CONFIG_NORMAL 0x0001
75767diff --git a/include/linux/poison.h b/include/linux/poison.h
75768index 2110a81..13a11bb 100644
75769--- a/include/linux/poison.h
75770+++ b/include/linux/poison.h
75771@@ -19,8 +19,8 @@
75772 * under normal circumstances, used to verify that nobody uses
75773 * non-initialized list entries.
75774 */
75775-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
75776-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
75777+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
75778+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
75779
75780 /********** include/linux/timer.h **********/
75781 /*
75782diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
75783index d8b187c3..9a9257a 100644
75784--- a/include/linux/power/smartreflex.h
75785+++ b/include/linux/power/smartreflex.h
75786@@ -238,7 +238,7 @@ struct omap_sr_class_data {
75787 int (*notify)(struct omap_sr *sr, u32 status);
75788 u8 notify_flags;
75789 u8 class_type;
75790-};
75791+} __do_const;
75792
75793 /**
75794 * struct omap_sr_nvalue_table - Smartreflex n-target value info
75795diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
75796index 4ea1d37..80f4b33 100644
75797--- a/include/linux/ppp-comp.h
75798+++ b/include/linux/ppp-comp.h
75799@@ -84,7 +84,7 @@ struct compressor {
75800 struct module *owner;
75801 /* Extra skb space needed by the compressor algorithm */
75802 unsigned int comp_extra;
75803-};
75804+} __do_const;
75805
75806 /*
75807 * The return value from decompress routine is the length of the
75808diff --git a/include/linux/preempt.h b/include/linux/preempt.h
75809index f5d4723..a6ea2fa 100644
75810--- a/include/linux/preempt.h
75811+++ b/include/linux/preempt.h
75812@@ -18,8 +18,13 @@
75813 # define sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
75814 #endif
75815
75816+#define raw_add_preempt_count(val) do { preempt_count() += (val); } while (0)
75817+#define raw_sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
75818+
75819 #define inc_preempt_count() add_preempt_count(1)
75820+#define raw_inc_preempt_count() raw_add_preempt_count(1)
75821 #define dec_preempt_count() sub_preempt_count(1)
75822+#define raw_dec_preempt_count() raw_sub_preempt_count(1)
75823
75824 #define preempt_count() (current_thread_info()->preempt_count)
75825
75826@@ -64,6 +69,12 @@ do { \
75827 barrier(); \
75828 } while (0)
75829
75830+#define raw_preempt_disable() \
75831+do { \
75832+ raw_inc_preempt_count(); \
75833+ barrier(); \
75834+} while (0)
75835+
75836 #define sched_preempt_enable_no_resched() \
75837 do { \
75838 barrier(); \
75839@@ -72,6 +83,12 @@ do { \
75840
75841 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
75842
75843+#define raw_preempt_enable_no_resched() \
75844+do { \
75845+ barrier(); \
75846+ raw_dec_preempt_count(); \
75847+} while (0)
75848+
75849 #define preempt_enable() \
75850 do { \
75851 preempt_enable_no_resched(); \
75852@@ -116,8 +133,10 @@ do { \
75853 * region.
75854 */
75855 #define preempt_disable() barrier()
75856+#define raw_preempt_disable() barrier()
75857 #define sched_preempt_enable_no_resched() barrier()
75858 #define preempt_enable_no_resched() barrier()
75859+#define raw_preempt_enable_no_resched() barrier()
75860 #define preempt_enable() barrier()
75861
75862 #define preempt_disable_notrace() barrier()
75863diff --git a/include/linux/printk.h b/include/linux/printk.h
75864index 22c7052..ad3fa0a 100644
75865--- a/include/linux/printk.h
75866+++ b/include/linux/printk.h
75867@@ -106,6 +106,8 @@ static inline __printf(1, 2) __cold
75868 void early_printk(const char *s, ...) { }
75869 #endif
75870
75871+extern int kptr_restrict;
75872+
75873 #ifdef CONFIG_PRINTK
75874 asmlinkage __printf(5, 0)
75875 int vprintk_emit(int facility, int level,
75876@@ -140,7 +142,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
75877
75878 extern int printk_delay_msec;
75879 extern int dmesg_restrict;
75880-extern int kptr_restrict;
75881
75882 extern void wake_up_klogd(void);
75883
75884diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
75885index 608e60a..c26f864 100644
75886--- a/include/linux/proc_fs.h
75887+++ b/include/linux/proc_fs.h
75888@@ -34,6 +34,19 @@ static inline struct proc_dir_entry *proc_create(
75889 return proc_create_data(name, mode, parent, proc_fops, NULL);
75890 }
75891
75892+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
75893+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
75894+{
75895+#ifdef CONFIG_GRKERNSEC_PROC_USER
75896+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
75897+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75898+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
75899+#else
75900+ return proc_create_data(name, mode, parent, proc_fops, NULL);
75901+#endif
75902+}
75903+
75904+
75905 extern void proc_set_size(struct proc_dir_entry *, loff_t);
75906 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
75907 extern void *PDE_DATA(const struct inode *);
75908diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
75909index 34a1e10..03a6d03 100644
75910--- a/include/linux/proc_ns.h
75911+++ b/include/linux/proc_ns.h
75912@@ -14,7 +14,7 @@ struct proc_ns_operations {
75913 void (*put)(void *ns);
75914 int (*install)(struct nsproxy *nsproxy, void *ns);
75915 unsigned int (*inum)(void *ns);
75916-};
75917+} __do_const;
75918
75919 struct proc_ns {
75920 void *ns;
75921diff --git a/include/linux/random.h b/include/linux/random.h
75922index 6312dd9..2561947 100644
75923--- a/include/linux/random.h
75924+++ b/include/linux/random.h
75925@@ -10,9 +10,19 @@
75926
75927
75928 extern void add_device_randomness(const void *, unsigned int);
75929+
75930+static inline void add_latent_entropy(void)
75931+{
75932+
75933+#ifdef LATENT_ENTROPY_PLUGIN
75934+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
75935+#endif
75936+
75937+}
75938+
75939 extern void add_input_randomness(unsigned int type, unsigned int code,
75940- unsigned int value);
75941-extern void add_interrupt_randomness(int irq, int irq_flags);
75942+ unsigned int value) __latent_entropy;
75943+extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
75944
75945 extern void get_random_bytes(void *buf, int nbytes);
75946 extern void get_random_bytes_arch(void *buf, int nbytes);
75947@@ -33,6 +43,11 @@ void prandom_seed(u32 seed);
75948 u32 prandom_u32_state(struct rnd_state *);
75949 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
75950
75951+static inline unsigned long pax_get_random_long(void)
75952+{
75953+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
75954+}
75955+
75956 /*
75957 * Handle minimum values for seeds
75958 */
75959diff --git a/include/linux/rculist.h b/include/linux/rculist.h
75960index 4106721..132d42c 100644
75961--- a/include/linux/rculist.h
75962+++ b/include/linux/rculist.h
75963@@ -44,6 +44,9 @@ extern void __list_add_rcu(struct list_head *new,
75964 struct list_head *prev, struct list_head *next);
75965 #endif
75966
75967+extern void __pax_list_add_rcu(struct list_head *new,
75968+ struct list_head *prev, struct list_head *next);
75969+
75970 /**
75971 * list_add_rcu - add a new entry to rcu-protected list
75972 * @new: new entry to be added
75973@@ -65,6 +68,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
75974 __list_add_rcu(new, head, head->next);
75975 }
75976
75977+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
75978+{
75979+ __pax_list_add_rcu(new, head, head->next);
75980+}
75981+
75982 /**
75983 * list_add_tail_rcu - add a new entry to rcu-protected list
75984 * @new: new entry to be added
75985@@ -87,6 +95,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
75986 __list_add_rcu(new, head->prev, head);
75987 }
75988
75989+static inline void pax_list_add_tail_rcu(struct list_head *new,
75990+ struct list_head *head)
75991+{
75992+ __pax_list_add_rcu(new, head->prev, head);
75993+}
75994+
75995 /**
75996 * list_del_rcu - deletes entry from list without re-initialization
75997 * @entry: the element to delete from the list.
75998@@ -117,6 +131,8 @@ static inline void list_del_rcu(struct list_head *entry)
75999 entry->prev = LIST_POISON2;
76000 }
76001
76002+extern void pax_list_del_rcu(struct list_head *entry);
76003+
76004 /**
76005 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
76006 * @n: the element to delete from the hash list.
76007diff --git a/include/linux/reboot.h b/include/linux/reboot.h
76008index 8e00f9f..9449b55 100644
76009--- a/include/linux/reboot.h
76010+++ b/include/linux/reboot.h
76011@@ -43,9 +43,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
76012 * Architecture-specific implementations of sys_reboot commands.
76013 */
76014
76015-extern void machine_restart(char *cmd);
76016-extern void machine_halt(void);
76017-extern void machine_power_off(void);
76018+extern void machine_restart(char *cmd) __noreturn;
76019+extern void machine_halt(void) __noreturn;
76020+extern void machine_power_off(void) __noreturn;
76021
76022 extern void machine_shutdown(void);
76023 struct pt_regs;
76024@@ -56,9 +56,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
76025 */
76026
76027 extern void kernel_restart_prepare(char *cmd);
76028-extern void kernel_restart(char *cmd);
76029-extern void kernel_halt(void);
76030-extern void kernel_power_off(void);
76031+extern void kernel_restart(char *cmd) __noreturn;
76032+extern void kernel_halt(void) __noreturn;
76033+extern void kernel_power_off(void) __noreturn;
76034
76035 extern int C_A_D; /* for sysctl */
76036 void ctrl_alt_del(void);
76037@@ -72,7 +72,7 @@ extern int orderly_poweroff(bool force);
76038 * Emergency restart, callable from an interrupt handler.
76039 */
76040
76041-extern void emergency_restart(void);
76042+extern void emergency_restart(void) __noreturn;
76043 #include <asm/emergency-restart.h>
76044
76045 #endif /* _LINUX_REBOOT_H */
76046diff --git a/include/linux/regset.h b/include/linux/regset.h
76047index 8e0c9fe..ac4d221 100644
76048--- a/include/linux/regset.h
76049+++ b/include/linux/regset.h
76050@@ -161,7 +161,8 @@ struct user_regset {
76051 unsigned int align;
76052 unsigned int bias;
76053 unsigned int core_note_type;
76054-};
76055+} __do_const;
76056+typedef struct user_regset __no_const user_regset_no_const;
76057
76058 /**
76059 * struct user_regset_view - available regsets
76060diff --git a/include/linux/relay.h b/include/linux/relay.h
76061index d7c8359..818daf5 100644
76062--- a/include/linux/relay.h
76063+++ b/include/linux/relay.h
76064@@ -157,7 +157,7 @@ struct rchan_callbacks
76065 * The callback should return 0 if successful, negative if not.
76066 */
76067 int (*remove_buf_file)(struct dentry *dentry);
76068-};
76069+} __no_const;
76070
76071 /*
76072 * CONFIG_RELAY kernel API, kernel/relay.c
76073diff --git a/include/linux/rio.h b/include/linux/rio.h
76074index b71d573..2f940bd 100644
76075--- a/include/linux/rio.h
76076+++ b/include/linux/rio.h
76077@@ -355,7 +355,7 @@ struct rio_ops {
76078 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
76079 u64 rstart, u32 size, u32 flags);
76080 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
76081-};
76082+} __no_const;
76083
76084 #define RIO_RESOURCE_MEM 0x00000100
76085 #define RIO_RESOURCE_DOORBELL 0x00000200
76086diff --git a/include/linux/rmap.h b/include/linux/rmap.h
76087index 6dacb93..6174423 100644
76088--- a/include/linux/rmap.h
76089+++ b/include/linux/rmap.h
76090@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
76091 void anon_vma_init(void); /* create anon_vma_cachep */
76092 int anon_vma_prepare(struct vm_area_struct *);
76093 void unlink_anon_vmas(struct vm_area_struct *);
76094-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
76095-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
76096+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
76097+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
76098
76099 static inline void anon_vma_merge(struct vm_area_struct *vma,
76100 struct vm_area_struct *next)
76101diff --git a/include/linux/sched.h b/include/linux/sched.h
76102index 078066d..4090b3b 100644
76103--- a/include/linux/sched.h
76104+++ b/include/linux/sched.h
76105@@ -62,6 +62,7 @@ struct bio_list;
76106 struct fs_struct;
76107 struct perf_event_context;
76108 struct blk_plug;
76109+struct linux_binprm;
76110
76111 /*
76112 * List of flags we want to share for kernel threads,
76113@@ -303,7 +304,7 @@ extern char __sched_text_start[], __sched_text_end[];
76114 extern int in_sched_functions(unsigned long addr);
76115
76116 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
76117-extern signed long schedule_timeout(signed long timeout);
76118+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
76119 extern signed long schedule_timeout_interruptible(signed long timeout);
76120 extern signed long schedule_timeout_killable(signed long timeout);
76121 extern signed long schedule_timeout_uninterruptible(signed long timeout);
76122@@ -314,6 +315,19 @@ struct nsproxy;
76123 struct user_namespace;
76124
76125 #ifdef CONFIG_MMU
76126+
76127+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
76128+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
76129+#else
76130+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
76131+{
76132+ return 0;
76133+}
76134+#endif
76135+
76136+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
76137+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
76138+
76139 extern void arch_pick_mmap_layout(struct mm_struct *mm);
76140 extern unsigned long
76141 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
76142@@ -589,6 +603,17 @@ struct signal_struct {
76143 #ifdef CONFIG_TASKSTATS
76144 struct taskstats *stats;
76145 #endif
76146+
76147+#ifdef CONFIG_GRKERNSEC
76148+ u32 curr_ip;
76149+ u32 saved_ip;
76150+ u32 gr_saddr;
76151+ u32 gr_daddr;
76152+ u16 gr_sport;
76153+ u16 gr_dport;
76154+ u8 used_accept:1;
76155+#endif
76156+
76157 #ifdef CONFIG_AUDIT
76158 unsigned audit_tty;
76159 unsigned audit_tty_log_passwd;
76160@@ -669,6 +694,14 @@ struct user_struct {
76161 struct key *session_keyring; /* UID's default session keyring */
76162 #endif
76163
76164+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
76165+ unsigned char kernel_banned;
76166+#endif
76167+#ifdef CONFIG_GRKERNSEC_BRUTE
76168+ unsigned char suid_banned;
76169+ unsigned long suid_ban_expires;
76170+#endif
76171+
76172 /* Hash table maintenance information */
76173 struct hlist_node uidhash_node;
76174 kuid_t uid;
76175@@ -1151,8 +1184,8 @@ struct task_struct {
76176 struct list_head thread_group;
76177
76178 struct completion *vfork_done; /* for vfork() */
76179- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
76180- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
76181+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
76182+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
76183
76184 cputime_t utime, stime, utimescaled, stimescaled;
76185 cputime_t gtime;
76186@@ -1177,11 +1210,6 @@ struct task_struct {
76187 struct task_cputime cputime_expires;
76188 struct list_head cpu_timers[3];
76189
76190-/* process credentials */
76191- const struct cred __rcu *real_cred; /* objective and real subjective task
76192- * credentials (COW) */
76193- const struct cred __rcu *cred; /* effective (overridable) subjective task
76194- * credentials (COW) */
76195 char comm[TASK_COMM_LEN]; /* executable name excluding path
76196 - access with [gs]et_task_comm (which lock
76197 it with task_lock())
76198@@ -1198,6 +1226,10 @@ struct task_struct {
76199 #endif
76200 /* CPU-specific state of this task */
76201 struct thread_struct thread;
76202+/* thread_info moved to task_struct */
76203+#ifdef CONFIG_X86
76204+ struct thread_info tinfo;
76205+#endif
76206 /* filesystem information */
76207 struct fs_struct *fs;
76208 /* open file information */
76209@@ -1271,6 +1303,10 @@ struct task_struct {
76210 gfp_t lockdep_reclaim_gfp;
76211 #endif
76212
76213+/* process credentials */
76214+ const struct cred __rcu *real_cred; /* objective and real subjective task
76215+ * credentials (COW) */
76216+
76217 /* journalling filesystem info */
76218 void *journal_info;
76219
76220@@ -1309,6 +1345,10 @@ struct task_struct {
76221 /* cg_list protected by css_set_lock and tsk->alloc_lock */
76222 struct list_head cg_list;
76223 #endif
76224+
76225+ const struct cred __rcu *cred; /* effective (overridable) subjective task
76226+ * credentials (COW) */
76227+
76228 #ifdef CONFIG_FUTEX
76229 struct robust_list_head __user *robust_list;
76230 #ifdef CONFIG_COMPAT
76231@@ -1406,8 +1446,76 @@ struct task_struct {
76232 unsigned int sequential_io;
76233 unsigned int sequential_io_avg;
76234 #endif
76235+
76236+#ifdef CONFIG_GRKERNSEC
76237+ /* grsecurity */
76238+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
76239+ u64 exec_id;
76240+#endif
76241+#ifdef CONFIG_GRKERNSEC_SETXID
76242+ const struct cred *delayed_cred;
76243+#endif
76244+ struct dentry *gr_chroot_dentry;
76245+ struct acl_subject_label *acl;
76246+ struct acl_role_label *role;
76247+ struct file *exec_file;
76248+ unsigned long brute_expires;
76249+ u16 acl_role_id;
76250+ /* is this the task that authenticated to the special role */
76251+ u8 acl_sp_role;
76252+ u8 is_writable;
76253+ u8 brute;
76254+ u8 gr_is_chrooted;
76255+#endif
76256+
76257 };
76258
76259+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
76260+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
76261+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
76262+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
76263+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
76264+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
76265+
76266+#ifdef CONFIG_PAX_SOFTMODE
76267+extern int pax_softmode;
76268+#endif
76269+
76270+extern int pax_check_flags(unsigned long *);
76271+
76272+/* if tsk != current then task_lock must be held on it */
76273+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
76274+static inline unsigned long pax_get_flags(struct task_struct *tsk)
76275+{
76276+ if (likely(tsk->mm))
76277+ return tsk->mm->pax_flags;
76278+ else
76279+ return 0UL;
76280+}
76281+
76282+/* if tsk != current then task_lock must be held on it */
76283+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
76284+{
76285+ if (likely(tsk->mm)) {
76286+ tsk->mm->pax_flags = flags;
76287+ return 0;
76288+ }
76289+ return -EINVAL;
76290+}
76291+#endif
76292+
76293+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
76294+extern void pax_set_initial_flags(struct linux_binprm *bprm);
76295+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
76296+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
76297+#endif
76298+
76299+struct path;
76300+extern char *pax_get_path(const struct path *path, char *buf, int buflen);
76301+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
76302+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
76303+extern void pax_report_refcount_overflow(struct pt_regs *regs);
76304+
76305 /* Future-safe accessor for struct task_struct's cpus_allowed. */
76306 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
76307
76308@@ -1466,7 +1574,7 @@ struct pid_namespace;
76309 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
76310 struct pid_namespace *ns);
76311
76312-static inline pid_t task_pid_nr(struct task_struct *tsk)
76313+static inline pid_t task_pid_nr(const struct task_struct *tsk)
76314 {
76315 return tsk->pid;
76316 }
76317@@ -1916,7 +2024,9 @@ void yield(void);
76318 extern struct exec_domain default_exec_domain;
76319
76320 union thread_union {
76321+#ifndef CONFIG_X86
76322 struct thread_info thread_info;
76323+#endif
76324 unsigned long stack[THREAD_SIZE/sizeof(long)];
76325 };
76326
76327@@ -1949,6 +2059,7 @@ extern struct pid_namespace init_pid_ns;
76328 */
76329
76330 extern struct task_struct *find_task_by_vpid(pid_t nr);
76331+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
76332 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
76333 struct pid_namespace *ns);
76334
76335@@ -2113,7 +2224,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
76336 extern void exit_itimers(struct signal_struct *);
76337 extern void flush_itimer_signals(void);
76338
76339-extern void do_group_exit(int);
76340+extern __noreturn void do_group_exit(int);
76341
76342 extern int allow_signal(int);
76343 extern int disallow_signal(int);
76344@@ -2304,9 +2415,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
76345
76346 #endif
76347
76348-static inline int object_is_on_stack(void *obj)
76349+static inline int object_starts_on_stack(void *obj)
76350 {
76351- void *stack = task_stack_page(current);
76352+ const void *stack = task_stack_page(current);
76353
76354 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
76355 }
76356diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
76357index bf8086b..962b035 100644
76358--- a/include/linux/sched/sysctl.h
76359+++ b/include/linux/sched/sysctl.h
76360@@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
76361 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
76362
76363 extern int sysctl_max_map_count;
76364+extern unsigned long sysctl_heap_stack_gap;
76365
76366 extern unsigned int sysctl_sched_latency;
76367 extern unsigned int sysctl_sched_min_granularity;
76368diff --git a/include/linux/security.h b/include/linux/security.h
76369index 7ce53ae..8ee24a5 100644
76370--- a/include/linux/security.h
76371+++ b/include/linux/security.h
76372@@ -27,6 +27,7 @@
76373 #include <linux/slab.h>
76374 #include <linux/err.h>
76375 #include <linux/string.h>
76376+#include <linux/grsecurity.h>
76377
76378 struct linux_binprm;
76379 struct cred;
76380@@ -116,8 +117,6 @@ struct seq_file;
76381
76382 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
76383
76384-void reset_security_ops(void);
76385-
76386 #ifdef CONFIG_MMU
76387 extern unsigned long mmap_min_addr;
76388 extern unsigned long dac_mmap_min_addr;
76389diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
76390index 4e32edc..f8f2d18 100644
76391--- a/include/linux/seq_file.h
76392+++ b/include/linux/seq_file.h
76393@@ -26,6 +26,9 @@ struct seq_file {
76394 struct mutex lock;
76395 const struct seq_operations *op;
76396 int poll_event;
76397+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
76398+ u64 exec_id;
76399+#endif
76400 #ifdef CONFIG_USER_NS
76401 struct user_namespace *user_ns;
76402 #endif
76403@@ -38,6 +41,7 @@ struct seq_operations {
76404 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
76405 int (*show) (struct seq_file *m, void *v);
76406 };
76407+typedef struct seq_operations __no_const seq_operations_no_const;
76408
76409 #define SEQ_SKIP 1
76410
76411diff --git a/include/linux/shm.h b/include/linux/shm.h
76412index 429c199..4d42e38 100644
76413--- a/include/linux/shm.h
76414+++ b/include/linux/shm.h
76415@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
76416
76417 /* The task created the shm object. NULL if the task is dead. */
76418 struct task_struct *shm_creator;
76419+#ifdef CONFIG_GRKERNSEC
76420+ time_t shm_createtime;
76421+ pid_t shm_lapid;
76422+#endif
76423 };
76424
76425 /* shm_mode upper byte flags */
76426diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
76427index 6bd165b..4823435 100644
76428--- a/include/linux/skbuff.h
76429+++ b/include/linux/skbuff.h
76430@@ -648,7 +648,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
76431 extern struct sk_buff *__alloc_skb(unsigned int size,
76432 gfp_t priority, int flags, int node);
76433 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
76434-static inline struct sk_buff *alloc_skb(unsigned int size,
76435+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
76436 gfp_t priority)
76437 {
76438 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
76439@@ -764,7 +764,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
76440 */
76441 static inline int skb_queue_empty(const struct sk_buff_head *list)
76442 {
76443- return list->next == (struct sk_buff *)list;
76444+ return list->next == (const struct sk_buff *)list;
76445 }
76446
76447 /**
76448@@ -777,7 +777,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
76449 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
76450 const struct sk_buff *skb)
76451 {
76452- return skb->next == (struct sk_buff *)list;
76453+ return skb->next == (const struct sk_buff *)list;
76454 }
76455
76456 /**
76457@@ -790,7 +790,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
76458 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
76459 const struct sk_buff *skb)
76460 {
76461- return skb->prev == (struct sk_buff *)list;
76462+ return skb->prev == (const struct sk_buff *)list;
76463 }
76464
76465 /**
76466@@ -1755,7 +1755,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
76467 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
76468 */
76469 #ifndef NET_SKB_PAD
76470-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
76471+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
76472 #endif
76473
76474 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
76475@@ -2350,7 +2350,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
76476 int noblock, int *err);
76477 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
76478 struct poll_table_struct *wait);
76479-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
76480+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
76481 int offset, struct iovec *to,
76482 int size);
76483 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
76484@@ -2641,6 +2641,9 @@ static inline void nf_reset(struct sk_buff *skb)
76485 nf_bridge_put(skb->nf_bridge);
76486 skb->nf_bridge = NULL;
76487 #endif
76488+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
76489+ skb->nf_trace = 0;
76490+#endif
76491 }
76492
76493 static inline void nf_reset_trace(struct sk_buff *skb)
76494diff --git a/include/linux/slab.h b/include/linux/slab.h
76495index 6c5cc0e..9ca0fd6 100644
76496--- a/include/linux/slab.h
76497+++ b/include/linux/slab.h
76498@@ -12,15 +12,29 @@
76499 #include <linux/gfp.h>
76500 #include <linux/types.h>
76501 #include <linux/workqueue.h>
76502-
76503+#include <linux/err.h>
76504
76505 /*
76506 * Flags to pass to kmem_cache_create().
76507 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
76508 */
76509 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
76510+
76511+#ifdef CONFIG_PAX_USERCOPY_SLABS
76512+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
76513+#else
76514+#define SLAB_USERCOPY 0x00000000UL
76515+#endif
76516+
76517 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
76518 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
76519+
76520+#ifdef CONFIG_PAX_MEMORY_SANITIZE
76521+#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
76522+#else
76523+#define SLAB_NO_SANITIZE 0x00000000UL
76524+#endif
76525+
76526 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
76527 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
76528 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
76529@@ -89,10 +103,13 @@
76530 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
76531 * Both make kfree a no-op.
76532 */
76533-#define ZERO_SIZE_PTR ((void *)16)
76534+#define ZERO_SIZE_PTR \
76535+({ \
76536+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
76537+ (void *)(-MAX_ERRNO-1L); \
76538+})
76539
76540-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
76541- (unsigned long)ZERO_SIZE_PTR)
76542+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
76543
76544
76545 struct mem_cgroup;
76546@@ -132,6 +149,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
76547 void kfree(const void *);
76548 void kzfree(const void *);
76549 size_t ksize(const void *);
76550+const char *check_heap_object(const void *ptr, unsigned long n);
76551+bool is_usercopy_object(const void *ptr);
76552
76553 /*
76554 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
76555@@ -164,7 +183,7 @@ struct kmem_cache {
76556 unsigned int align; /* Alignment as calculated */
76557 unsigned long flags; /* Active flags on the slab */
76558 const char *name; /* Slab name for sysfs */
76559- int refcount; /* Use counter */
76560+ atomic_t refcount; /* Use counter */
76561 void (*ctor)(void *); /* Called on object slot creation */
76562 struct list_head list; /* List of all slab caches on the system */
76563 };
76564@@ -238,6 +257,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
76565 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
76566 #endif
76567
76568+#ifdef CONFIG_PAX_USERCOPY_SLABS
76569+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
76570+#endif
76571+
76572 /*
76573 * Figure out which kmalloc slab an allocation of a certain size
76574 * belongs to.
76575@@ -246,7 +269,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
76576 * 2 = 120 .. 192 bytes
76577 * n = 2^(n-1) .. 2^n -1
76578 */
76579-static __always_inline int kmalloc_index(size_t size)
76580+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
76581 {
76582 if (!size)
76583 return 0;
76584@@ -492,7 +515,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
76585 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
76586 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
76587 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
76588-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
76589+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
76590 #define kmalloc_track_caller(size, flags) \
76591 __kmalloc_track_caller(size, flags, _RET_IP_)
76592 #else
76593@@ -512,7 +535,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
76594 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
76595 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
76596 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
76597-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
76598+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
76599 #define kmalloc_node_track_caller(size, flags, node) \
76600 __kmalloc_node_track_caller(size, flags, node, \
76601 _RET_IP_)
76602diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
76603index cd40158..4e2f7af 100644
76604--- a/include/linux/slab_def.h
76605+++ b/include/linux/slab_def.h
76606@@ -50,7 +50,7 @@ struct kmem_cache {
76607 /* 4) cache creation/removal */
76608 const char *name;
76609 struct list_head list;
76610- int refcount;
76611+ atomic_t refcount;
76612 int object_size;
76613 int align;
76614
76615@@ -66,10 +66,14 @@ struct kmem_cache {
76616 unsigned long node_allocs;
76617 unsigned long node_frees;
76618 unsigned long node_overflow;
76619- atomic_t allochit;
76620- atomic_t allocmiss;
76621- atomic_t freehit;
76622- atomic_t freemiss;
76623+ atomic_unchecked_t allochit;
76624+ atomic_unchecked_t allocmiss;
76625+ atomic_unchecked_t freehit;
76626+ atomic_unchecked_t freemiss;
76627+#ifdef CONFIG_PAX_MEMORY_SANITIZE
76628+ atomic_unchecked_t sanitized;
76629+ atomic_unchecked_t not_sanitized;
76630+#endif
76631
76632 /*
76633 * If debugging is enabled, then the allocator can add additional
76634@@ -103,7 +107,7 @@ struct kmem_cache {
76635 };
76636
76637 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
76638-void *__kmalloc(size_t size, gfp_t flags);
76639+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
76640
76641 #ifdef CONFIG_TRACING
76642 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
76643@@ -136,6 +140,13 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76644 cachep = kmalloc_dma_caches[i];
76645 else
76646 #endif
76647+
76648+#ifdef CONFIG_PAX_USERCOPY_SLABS
76649+ if (flags & GFP_USERCOPY)
76650+ cachep = kmalloc_usercopy_caches[i];
76651+ else
76652+#endif
76653+
76654 cachep = kmalloc_caches[i];
76655
76656 ret = kmem_cache_alloc_trace(cachep, flags, size);
76657@@ -146,7 +157,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76658 }
76659
76660 #ifdef CONFIG_NUMA
76661-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
76662+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
76663 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
76664
76665 #ifdef CONFIG_TRACING
76666@@ -185,6 +196,13 @@ static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
76667 cachep = kmalloc_dma_caches[i];
76668 else
76669 #endif
76670+
76671+#ifdef CONFIG_PAX_USERCOPY_SLABS
76672+ if (flags & GFP_USERCOPY)
76673+ cachep = kmalloc_usercopy_caches[i];
76674+ else
76675+#endif
76676+
76677 cachep = kmalloc_caches[i];
76678
76679 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
76680diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
76681index 095a5a4..4b82027 100644
76682--- a/include/linux/slob_def.h
76683+++ b/include/linux/slob_def.h
76684@@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
76685 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
76686 }
76687
76688-void *__kmalloc_node(size_t size, gfp_t flags, int node);
76689+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
76690
76691 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
76692 {
76693@@ -23,7 +23,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76694 return __kmalloc_node(size, flags, NUMA_NO_NODE);
76695 }
76696
76697-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
76698+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
76699 {
76700 return kmalloc(size, flags);
76701 }
76702diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
76703index 027276f..092bfe8 100644
76704--- a/include/linux/slub_def.h
76705+++ b/include/linux/slub_def.h
76706@@ -80,7 +80,7 @@ struct kmem_cache {
76707 struct kmem_cache_order_objects max;
76708 struct kmem_cache_order_objects min;
76709 gfp_t allocflags; /* gfp flags to use on each alloc */
76710- int refcount; /* Refcount for slab cache destroy */
76711+ atomic_t refcount; /* Refcount for slab cache destroy */
76712 void (*ctor)(void *);
76713 int inuse; /* Offset to metadata */
76714 int align; /* Alignment */
76715@@ -105,7 +105,7 @@ struct kmem_cache {
76716 };
76717
76718 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
76719-void *__kmalloc(size_t size, gfp_t flags);
76720+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
76721
76722 static __always_inline void *
76723 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
76724@@ -149,7 +149,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
76725 }
76726 #endif
76727
76728-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
76729+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
76730 {
76731 unsigned int order = get_order(size);
76732 return kmalloc_order_trace(size, flags, order);
76733@@ -175,7 +175,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76734 }
76735
76736 #ifdef CONFIG_NUMA
76737-void *__kmalloc_node(size_t size, gfp_t flags, int node);
76738+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
76739 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
76740
76741 #ifdef CONFIG_TRACING
76742diff --git a/include/linux/smp.h b/include/linux/smp.h
76743index c181399..09d7b92 100644
76744--- a/include/linux/smp.h
76745+++ b/include/linux/smp.h
76746@@ -217,7 +217,9 @@ static inline void kick_all_cpus_sync(void) { }
76747 #endif
76748
76749 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
76750+#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
76751 #define put_cpu() preempt_enable()
76752+#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
76753
76754 /*
76755 * Callback to arch code if there's nosmp or maxcpus=0 on the
76756diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
76757index 54f91d3..be2c379 100644
76758--- a/include/linux/sock_diag.h
76759+++ b/include/linux/sock_diag.h
76760@@ -11,7 +11,7 @@ struct sock;
76761 struct sock_diag_handler {
76762 __u8 family;
76763 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
76764-};
76765+} __do_const;
76766
76767 int sock_diag_register(const struct sock_diag_handler *h);
76768 void sock_diag_unregister(const struct sock_diag_handler *h);
76769diff --git a/include/linux/sonet.h b/include/linux/sonet.h
76770index 680f9a3..f13aeb0 100644
76771--- a/include/linux/sonet.h
76772+++ b/include/linux/sonet.h
76773@@ -7,7 +7,7 @@
76774 #include <uapi/linux/sonet.h>
76775
76776 struct k_sonet_stats {
76777-#define __HANDLE_ITEM(i) atomic_t i
76778+#define __HANDLE_ITEM(i) atomic_unchecked_t i
76779 __SONET_ITEMS
76780 #undef __HANDLE_ITEM
76781 };
76782diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
76783index 07d8e53..dc934c9 100644
76784--- a/include/linux/sunrpc/addr.h
76785+++ b/include/linux/sunrpc/addr.h
76786@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
76787 {
76788 switch (sap->sa_family) {
76789 case AF_INET:
76790- return ntohs(((struct sockaddr_in *)sap)->sin_port);
76791+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
76792 case AF_INET6:
76793- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
76794+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
76795 }
76796 return 0;
76797 }
76798@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
76799 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
76800 const struct sockaddr *src)
76801 {
76802- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
76803+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
76804 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
76805
76806 dsin->sin_family = ssin->sin_family;
76807@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
76808 if (sa->sa_family != AF_INET6)
76809 return 0;
76810
76811- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
76812+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
76813 }
76814
76815 #endif /* _LINUX_SUNRPC_ADDR_H */
76816diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
76817index bfe11be..12bc8c4 100644
76818--- a/include/linux/sunrpc/clnt.h
76819+++ b/include/linux/sunrpc/clnt.h
76820@@ -96,7 +96,7 @@ struct rpc_procinfo {
76821 unsigned int p_timer; /* Which RTT timer to use */
76822 u32 p_statidx; /* Which procedure to account */
76823 const char * p_name; /* name of procedure */
76824-};
76825+} __do_const;
76826
76827 #ifdef __KERNEL__
76828
76829diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
76830index 1f0216b..6a4fa50 100644
76831--- a/include/linux/sunrpc/svc.h
76832+++ b/include/linux/sunrpc/svc.h
76833@@ -411,7 +411,7 @@ struct svc_procedure {
76834 unsigned int pc_count; /* call count */
76835 unsigned int pc_cachetype; /* cache info (NFS) */
76836 unsigned int pc_xdrressize; /* maximum size of XDR reply */
76837-};
76838+} __do_const;
76839
76840 /*
76841 * Function prototypes.
76842diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
76843index 0b8e3e6..33e0a01 100644
76844--- a/include/linux/sunrpc/svc_rdma.h
76845+++ b/include/linux/sunrpc/svc_rdma.h
76846@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
76847 extern unsigned int svcrdma_max_requests;
76848 extern unsigned int svcrdma_max_req_size;
76849
76850-extern atomic_t rdma_stat_recv;
76851-extern atomic_t rdma_stat_read;
76852-extern atomic_t rdma_stat_write;
76853-extern atomic_t rdma_stat_sq_starve;
76854-extern atomic_t rdma_stat_rq_starve;
76855-extern atomic_t rdma_stat_rq_poll;
76856-extern atomic_t rdma_stat_rq_prod;
76857-extern atomic_t rdma_stat_sq_poll;
76858-extern atomic_t rdma_stat_sq_prod;
76859+extern atomic_unchecked_t rdma_stat_recv;
76860+extern atomic_unchecked_t rdma_stat_read;
76861+extern atomic_unchecked_t rdma_stat_write;
76862+extern atomic_unchecked_t rdma_stat_sq_starve;
76863+extern atomic_unchecked_t rdma_stat_rq_starve;
76864+extern atomic_unchecked_t rdma_stat_rq_poll;
76865+extern atomic_unchecked_t rdma_stat_rq_prod;
76866+extern atomic_unchecked_t rdma_stat_sq_poll;
76867+extern atomic_unchecked_t rdma_stat_sq_prod;
76868
76869 #define RPCRDMA_VERSION 1
76870
76871diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
76872index 8d71d65..f79586e 100644
76873--- a/include/linux/sunrpc/svcauth.h
76874+++ b/include/linux/sunrpc/svcauth.h
76875@@ -120,7 +120,7 @@ struct auth_ops {
76876 int (*release)(struct svc_rqst *rq);
76877 void (*domain_release)(struct auth_domain *);
76878 int (*set_client)(struct svc_rqst *rq);
76879-};
76880+} __do_const;
76881
76882 #define SVC_GARBAGE 1
76883 #define SVC_SYSERR 2
76884diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
76885index a5ffd32..0935dea 100644
76886--- a/include/linux/swiotlb.h
76887+++ b/include/linux/swiotlb.h
76888@@ -60,7 +60,8 @@ extern void
76889
76890 extern void
76891 swiotlb_free_coherent(struct device *hwdev, size_t size,
76892- void *vaddr, dma_addr_t dma_handle);
76893+ void *vaddr, dma_addr_t dma_handle,
76894+ struct dma_attrs *attrs);
76895
76896 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
76897 unsigned long offset, size_t size,
76898diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
76899index 84662ec..5271947 100644
76900--- a/include/linux/syscalls.h
76901+++ b/include/linux/syscalls.h
76902@@ -97,8 +97,14 @@ struct sigaltstack;
76903 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
76904
76905 #define __SC_DECL(t, a) t a
76906+#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))
76907 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
76908-#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
76909+#define __SC_LONG(t, a) __typeof( \
76910+ __builtin_choose_expr( \
76911+ sizeof(t) > sizeof(int), \
76912+ (t) 0, \
76913+ __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
76914+ )) a
76915 #define __SC_CAST(t, a) (t) a
76916 #define __SC_ARGS(t, a) a
76917 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
76918@@ -362,11 +368,11 @@ asmlinkage long sys_sync(void);
76919 asmlinkage long sys_fsync(unsigned int fd);
76920 asmlinkage long sys_fdatasync(unsigned int fd);
76921 asmlinkage long sys_bdflush(int func, long data);
76922-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
76923- char __user *type, unsigned long flags,
76924+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
76925+ const char __user *type, unsigned long flags,
76926 void __user *data);
76927-asmlinkage long sys_umount(char __user *name, int flags);
76928-asmlinkage long sys_oldumount(char __user *name);
76929+asmlinkage long sys_umount(const char __user *name, int flags);
76930+asmlinkage long sys_oldumount(const char __user *name);
76931 asmlinkage long sys_truncate(const char __user *path, long length);
76932 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
76933 asmlinkage long sys_stat(const char __user *filename,
76934@@ -578,7 +584,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
76935 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
76936 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
76937 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
76938- struct sockaddr __user *, int);
76939+ struct sockaddr __user *, int) __intentional_overflow(0);
76940 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
76941 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
76942 unsigned int vlen, unsigned flags);
76943diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
76944index 27b3b0b..e093dd9 100644
76945--- a/include/linux/syscore_ops.h
76946+++ b/include/linux/syscore_ops.h
76947@@ -16,7 +16,7 @@ struct syscore_ops {
76948 int (*suspend)(void);
76949 void (*resume)(void);
76950 void (*shutdown)(void);
76951-};
76952+} __do_const;
76953
76954 extern void register_syscore_ops(struct syscore_ops *ops);
76955 extern void unregister_syscore_ops(struct syscore_ops *ops);
76956diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
76957index 14a8ff2..af52bad 100644
76958--- a/include/linux/sysctl.h
76959+++ b/include/linux/sysctl.h
76960@@ -34,13 +34,13 @@ struct ctl_table_root;
76961 struct ctl_table_header;
76962 struct ctl_dir;
76963
76964-typedef struct ctl_table ctl_table;
76965-
76966 typedef int proc_handler (struct ctl_table *ctl, int write,
76967 void __user *buffer, size_t *lenp, loff_t *ppos);
76968
76969 extern int proc_dostring(struct ctl_table *, int,
76970 void __user *, size_t *, loff_t *);
76971+extern int proc_dostring_modpriv(struct ctl_table *, int,
76972+ void __user *, size_t *, loff_t *);
76973 extern int proc_dointvec(struct ctl_table *, int,
76974 void __user *, size_t *, loff_t *);
76975 extern int proc_dointvec_minmax(struct ctl_table *, int,
76976@@ -115,7 +115,9 @@ struct ctl_table
76977 struct ctl_table_poll *poll;
76978 void *extra1;
76979 void *extra2;
76980-};
76981+} __do_const;
76982+typedef struct ctl_table __no_const ctl_table_no_const;
76983+typedef struct ctl_table ctl_table;
76984
76985 struct ctl_node {
76986 struct rb_node node;
76987diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
76988index 9e8a9b5..753de68 100644
76989--- a/include/linux/sysfs.h
76990+++ b/include/linux/sysfs.h
76991@@ -33,7 +33,8 @@ struct attribute {
76992 struct lock_class_key *key;
76993 struct lock_class_key skey;
76994 #endif
76995-};
76996+} __do_const;
76997+typedef struct attribute __no_const attribute_no_const;
76998
76999 /**
77000 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
77001@@ -62,7 +63,8 @@ struct attribute_group {
77002 struct attribute *, int);
77003 struct attribute **attrs;
77004 struct bin_attribute **bin_attrs;
77005-};
77006+} __do_const;
77007+typedef struct attribute_group __no_const attribute_group_no_const;
77008
77009 /**
77010 * Use these macros to make defining attributes easier. See include/linux/device.h
77011@@ -123,7 +125,8 @@ struct bin_attribute {
77012 char *, loff_t, size_t);
77013 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
77014 struct vm_area_struct *vma);
77015-};
77016+} __do_const;
77017+typedef struct bin_attribute __no_const bin_attribute_no_const;
77018
77019 /**
77020 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
77021diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
77022index 7faf933..9b85a0c 100644
77023--- a/include/linux/sysrq.h
77024+++ b/include/linux/sysrq.h
77025@@ -16,6 +16,7 @@
77026
77027 #include <linux/errno.h>
77028 #include <linux/types.h>
77029+#include <linux/compiler.h>
77030
77031 /* Enable/disable SYSRQ support by default (0==no, 1==yes). */
77032 #define SYSRQ_DEFAULT_ENABLE 1
77033@@ -36,7 +37,7 @@ struct sysrq_key_op {
77034 char *help_msg;
77035 char *action_msg;
77036 int enable_mask;
77037-};
77038+} __do_const;
77039
77040 #ifdef CONFIG_MAGIC_SYSRQ
77041
77042diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
77043index e7e0473..7989295 100644
77044--- a/include/linux/thread_info.h
77045+++ b/include/linux/thread_info.h
77046@@ -148,6 +148,15 @@ static inline bool test_and_clear_restore_sigmask(void)
77047 #error "no set_restore_sigmask() provided and default one won't work"
77048 #endif
77049
77050+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
77051+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
77052+{
77053+#ifndef CONFIG_PAX_USERCOPY_DEBUG
77054+ if (!__builtin_constant_p(n))
77055+#endif
77056+ __check_object_size(ptr, n, to_user);
77057+}
77058+
77059 #endif /* __KERNEL__ */
77060
77061 #endif /* _LINUX_THREAD_INFO_H */
77062diff --git a/include/linux/tty.h b/include/linux/tty.h
77063index 01ac30e..bf18a71 100644
77064--- a/include/linux/tty.h
77065+++ b/include/linux/tty.h
77066@@ -194,7 +194,7 @@ struct tty_port {
77067 const struct tty_port_operations *ops; /* Port operations */
77068 spinlock_t lock; /* Lock protecting tty field */
77069 int blocked_open; /* Waiting to open */
77070- int count; /* Usage count */
77071+ atomic_t count; /* Usage count */
77072 wait_queue_head_t open_wait; /* Open waiters */
77073 wait_queue_head_t close_wait; /* Close waiters */
77074 wait_queue_head_t delta_msr_wait; /* Modem status change */
77075@@ -547,7 +547,7 @@ extern int tty_port_open(struct tty_port *port,
77076 struct tty_struct *tty, struct file *filp);
77077 static inline int tty_port_users(struct tty_port *port)
77078 {
77079- return port->count + port->blocked_open;
77080+ return atomic_read(&port->count) + port->blocked_open;
77081 }
77082
77083 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
77084diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
77085index 756a609..b302dd6 100644
77086--- a/include/linux/tty_driver.h
77087+++ b/include/linux/tty_driver.h
77088@@ -285,7 +285,7 @@ struct tty_operations {
77089 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
77090 #endif
77091 const struct file_operations *proc_fops;
77092-};
77093+} __do_const;
77094
77095 struct tty_driver {
77096 int magic; /* magic number for this structure */
77097diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
77098index a1b0489..f02e17c 100644
77099--- a/include/linux/tty_ldisc.h
77100+++ b/include/linux/tty_ldisc.h
77101@@ -198,7 +198,7 @@ struct tty_ldisc_ops {
77102
77103 struct module *owner;
77104
77105- int refcount;
77106+ atomic_t refcount;
77107 };
77108
77109 struct tty_ldisc {
77110diff --git a/include/linux/types.h b/include/linux/types.h
77111index 4d118ba..c3ee9bf 100644
77112--- a/include/linux/types.h
77113+++ b/include/linux/types.h
77114@@ -176,10 +176,26 @@ typedef struct {
77115 int counter;
77116 } atomic_t;
77117
77118+#ifdef CONFIG_PAX_REFCOUNT
77119+typedef struct {
77120+ int counter;
77121+} atomic_unchecked_t;
77122+#else
77123+typedef atomic_t atomic_unchecked_t;
77124+#endif
77125+
77126 #ifdef CONFIG_64BIT
77127 typedef struct {
77128 long counter;
77129 } atomic64_t;
77130+
77131+#ifdef CONFIG_PAX_REFCOUNT
77132+typedef struct {
77133+ long counter;
77134+} atomic64_unchecked_t;
77135+#else
77136+typedef atomic64_t atomic64_unchecked_t;
77137+#endif
77138 #endif
77139
77140 struct list_head {
77141diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
77142index 5ca0951..ab496a5 100644
77143--- a/include/linux/uaccess.h
77144+++ b/include/linux/uaccess.h
77145@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
77146 long ret; \
77147 mm_segment_t old_fs = get_fs(); \
77148 \
77149- set_fs(KERNEL_DS); \
77150 pagefault_disable(); \
77151- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
77152- pagefault_enable(); \
77153+ set_fs(KERNEL_DS); \
77154+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
77155 set_fs(old_fs); \
77156+ pagefault_enable(); \
77157 ret; \
77158 })
77159
77160diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
77161index 8e522cbc..aa8572d 100644
77162--- a/include/linux/uidgid.h
77163+++ b/include/linux/uidgid.h
77164@@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
77165
77166 #endif /* CONFIG_USER_NS */
77167
77168+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
77169+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
77170+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
77171+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
77172+
77173 #endif /* _LINUX_UIDGID_H */
77174diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
77175index 99c1b4d..562e6f3 100644
77176--- a/include/linux/unaligned/access_ok.h
77177+++ b/include/linux/unaligned/access_ok.h
77178@@ -4,34 +4,34 @@
77179 #include <linux/kernel.h>
77180 #include <asm/byteorder.h>
77181
77182-static inline u16 get_unaligned_le16(const void *p)
77183+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
77184 {
77185- return le16_to_cpup((__le16 *)p);
77186+ return le16_to_cpup((const __le16 *)p);
77187 }
77188
77189-static inline u32 get_unaligned_le32(const void *p)
77190+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
77191 {
77192- return le32_to_cpup((__le32 *)p);
77193+ return le32_to_cpup((const __le32 *)p);
77194 }
77195
77196-static inline u64 get_unaligned_le64(const void *p)
77197+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
77198 {
77199- return le64_to_cpup((__le64 *)p);
77200+ return le64_to_cpup((const __le64 *)p);
77201 }
77202
77203-static inline u16 get_unaligned_be16(const void *p)
77204+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
77205 {
77206- return be16_to_cpup((__be16 *)p);
77207+ return be16_to_cpup((const __be16 *)p);
77208 }
77209
77210-static inline u32 get_unaligned_be32(const void *p)
77211+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
77212 {
77213- return be32_to_cpup((__be32 *)p);
77214+ return be32_to_cpup((const __be32 *)p);
77215 }
77216
77217-static inline u64 get_unaligned_be64(const void *p)
77218+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
77219 {
77220- return be64_to_cpup((__be64 *)p);
77221+ return be64_to_cpup((const __be64 *)p);
77222 }
77223
77224 static inline void put_unaligned_le16(u16 val, void *p)
77225diff --git a/include/linux/usb.h b/include/linux/usb.h
77226index 0eec268..4496526 100644
77227--- a/include/linux/usb.h
77228+++ b/include/linux/usb.h
77229@@ -560,7 +560,7 @@ struct usb_device {
77230 int maxchild;
77231
77232 u32 quirks;
77233- atomic_t urbnum;
77234+ atomic_unchecked_t urbnum;
77235
77236 unsigned long active_duration;
77237
77238@@ -1617,7 +1617,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
77239
77240 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
77241 __u8 request, __u8 requesttype, __u16 value, __u16 index,
77242- void *data, __u16 size, int timeout);
77243+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
77244 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
77245 void *data, int len, int *actual_length, int timeout);
77246 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
77247diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
77248index e452ba6..78f8e80 100644
77249--- a/include/linux/usb/renesas_usbhs.h
77250+++ b/include/linux/usb/renesas_usbhs.h
77251@@ -39,7 +39,7 @@ enum {
77252 */
77253 struct renesas_usbhs_driver_callback {
77254 int (*notify_hotplug)(struct platform_device *pdev);
77255-};
77256+} __no_const;
77257
77258 /*
77259 * callback functions for platform
77260diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
77261index 6f8fbcf..8259001 100644
77262--- a/include/linux/vermagic.h
77263+++ b/include/linux/vermagic.h
77264@@ -25,9 +25,35 @@
77265 #define MODULE_ARCH_VERMAGIC ""
77266 #endif
77267
77268+#ifdef CONFIG_PAX_REFCOUNT
77269+#define MODULE_PAX_REFCOUNT "REFCOUNT "
77270+#else
77271+#define MODULE_PAX_REFCOUNT ""
77272+#endif
77273+
77274+#ifdef CONSTIFY_PLUGIN
77275+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
77276+#else
77277+#define MODULE_CONSTIFY_PLUGIN ""
77278+#endif
77279+
77280+#ifdef STACKLEAK_PLUGIN
77281+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
77282+#else
77283+#define MODULE_STACKLEAK_PLUGIN ""
77284+#endif
77285+
77286+#ifdef CONFIG_GRKERNSEC
77287+#define MODULE_GRSEC "GRSEC "
77288+#else
77289+#define MODULE_GRSEC ""
77290+#endif
77291+
77292 #define VERMAGIC_STRING \
77293 UTS_RELEASE " " \
77294 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
77295 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
77296- MODULE_ARCH_VERMAGIC
77297+ MODULE_ARCH_VERMAGIC \
77298+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
77299+ MODULE_GRSEC
77300
77301diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
77302index 4b8a891..c20e936 100644
77303--- a/include/linux/vmalloc.h
77304+++ b/include/linux/vmalloc.h
77305@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
77306 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
77307 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
77308 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
77309+
77310+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
77311+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
77312+#endif
77313+
77314 /* bits [20..32] reserved for arch specific ioremap internals */
77315
77316 /*
77317@@ -75,7 +80,7 @@ extern void *vmalloc_32_user(unsigned long size);
77318 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
77319 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
77320 unsigned long start, unsigned long end, gfp_t gfp_mask,
77321- pgprot_t prot, int node, const void *caller);
77322+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
77323 extern void vfree(const void *addr);
77324
77325 extern void *vmap(struct page **pages, unsigned int count,
77326@@ -141,8 +146,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
77327 extern void free_vm_area(struct vm_struct *area);
77328
77329 /* for /dev/kmem */
77330-extern long vread(char *buf, char *addr, unsigned long count);
77331-extern long vwrite(char *buf, char *addr, unsigned long count);
77332+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
77333+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
77334
77335 /*
77336 * Internals. Dont't use..
77337diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
77338index c586679..f06b389 100644
77339--- a/include/linux/vmstat.h
77340+++ b/include/linux/vmstat.h
77341@@ -90,18 +90,18 @@ static inline void vm_events_fold_cpu(int cpu)
77342 /*
77343 * Zone based page accounting with per cpu differentials.
77344 */
77345-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
77346+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
77347
77348 static inline void zone_page_state_add(long x, struct zone *zone,
77349 enum zone_stat_item item)
77350 {
77351- atomic_long_add(x, &zone->vm_stat[item]);
77352- atomic_long_add(x, &vm_stat[item]);
77353+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
77354+ atomic_long_add_unchecked(x, &vm_stat[item]);
77355 }
77356
77357 static inline unsigned long global_page_state(enum zone_stat_item item)
77358 {
77359- long x = atomic_long_read(&vm_stat[item]);
77360+ long x = atomic_long_read_unchecked(&vm_stat[item]);
77361 #ifdef CONFIG_SMP
77362 if (x < 0)
77363 x = 0;
77364@@ -112,7 +112,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
77365 static inline unsigned long zone_page_state(struct zone *zone,
77366 enum zone_stat_item item)
77367 {
77368- long x = atomic_long_read(&zone->vm_stat[item]);
77369+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
77370 #ifdef CONFIG_SMP
77371 if (x < 0)
77372 x = 0;
77373@@ -129,7 +129,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
77374 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
77375 enum zone_stat_item item)
77376 {
77377- long x = atomic_long_read(&zone->vm_stat[item]);
77378+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
77379
77380 #ifdef CONFIG_SMP
77381 int cpu;
77382@@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
77383
77384 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
77385 {
77386- atomic_long_inc(&zone->vm_stat[item]);
77387- atomic_long_inc(&vm_stat[item]);
77388+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
77389+ atomic_long_inc_unchecked(&vm_stat[item]);
77390 }
77391
77392 static inline void __inc_zone_page_state(struct page *page,
77393@@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
77394
77395 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
77396 {
77397- atomic_long_dec(&zone->vm_stat[item]);
77398- atomic_long_dec(&vm_stat[item]);
77399+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
77400+ atomic_long_dec_unchecked(&vm_stat[item]);
77401 }
77402
77403 static inline void __dec_zone_page_state(struct page *page,
77404diff --git a/include/linux/xattr.h b/include/linux/xattr.h
77405index fdbafc6..49dfe4f 100644
77406--- a/include/linux/xattr.h
77407+++ b/include/linux/xattr.h
77408@@ -28,7 +28,7 @@ struct xattr_handler {
77409 size_t size, int handler_flags);
77410 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
77411 size_t size, int flags, int handler_flags);
77412-};
77413+} __do_const;
77414
77415 struct xattr {
77416 char *name;
77417@@ -37,6 +37,9 @@ struct xattr {
77418 };
77419
77420 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
77421+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
77422+ssize_t pax_getxattr(struct dentry *, void *, size_t);
77423+#endif
77424 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
77425 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
77426 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
77427diff --git a/include/linux/yam.h b/include/linux/yam.h
77428index 7fe2822..512cdc2 100644
77429--- a/include/linux/yam.h
77430+++ b/include/linux/yam.h
77431@@ -77,6 +77,6 @@ struct yamdrv_ioctl_cfg {
77432
77433 struct yamdrv_ioctl_mcs {
77434 int cmd;
77435- int bitrate;
77436+ unsigned int bitrate;
77437 unsigned char bits[YAM_FPGA_SIZE];
77438 };
77439diff --git a/include/linux/zlib.h b/include/linux/zlib.h
77440index 9c5a6b4..09c9438 100644
77441--- a/include/linux/zlib.h
77442+++ b/include/linux/zlib.h
77443@@ -31,6 +31,7 @@
77444 #define _ZLIB_H
77445
77446 #include <linux/zconf.h>
77447+#include <linux/compiler.h>
77448
77449 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
77450 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
77451@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
77452
77453 /* basic functions */
77454
77455-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
77456+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
77457 /*
77458 Returns the number of bytes that needs to be allocated for a per-
77459 stream workspace with the specified parameters. A pointer to this
77460diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
77461index c768c9f..bdcaa5a 100644
77462--- a/include/media/v4l2-dev.h
77463+++ b/include/media/v4l2-dev.h
77464@@ -76,7 +76,7 @@ struct v4l2_file_operations {
77465 int (*mmap) (struct file *, struct vm_area_struct *);
77466 int (*open) (struct file *);
77467 int (*release) (struct file *);
77468-};
77469+} __do_const;
77470
77471 /*
77472 * Newer version of video_device, handled by videodev2.c
77473diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
77474index c9b1593..a572459 100644
77475--- a/include/media/v4l2-device.h
77476+++ b/include/media/v4l2-device.h
77477@@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
77478 this function returns 0. If the name ends with a digit (e.g. cx18),
77479 then the name will be set to cx18-0 since cx180 looks really odd. */
77480 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
77481- atomic_t *instance);
77482+ atomic_unchecked_t *instance);
77483
77484 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
77485 Since the parent disappears this ensures that v4l2_dev doesn't have an
77486diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
77487index d9fa68f..45c88d1 100644
77488--- a/include/net/9p/transport.h
77489+++ b/include/net/9p/transport.h
77490@@ -63,7 +63,7 @@ struct p9_trans_module {
77491 int (*cancelled)(struct p9_client *, struct p9_req_t *req);
77492 int (*zc_request)(struct p9_client *, struct p9_req_t *,
77493 char *, char *, int , int, int, int);
77494-};
77495+} __do_const;
77496
77497 void v9fs_register_trans(struct p9_trans_module *m);
77498 void v9fs_unregister_trans(struct p9_trans_module *m);
77499diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
77500index 1a966af..2767cf6 100644
77501--- a/include/net/bluetooth/l2cap.h
77502+++ b/include/net/bluetooth/l2cap.h
77503@@ -551,7 +551,7 @@ struct l2cap_ops {
77504 void (*defer) (struct l2cap_chan *chan);
77505 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
77506 unsigned long len, int nb);
77507-};
77508+} __do_const;
77509
77510 struct l2cap_conn {
77511 struct hci_conn *hcon;
77512diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
77513index f2ae33d..c457cf0 100644
77514--- a/include/net/caif/cfctrl.h
77515+++ b/include/net/caif/cfctrl.h
77516@@ -52,7 +52,7 @@ struct cfctrl_rsp {
77517 void (*radioset_rsp)(void);
77518 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
77519 struct cflayer *client_layer);
77520-};
77521+} __no_const;
77522
77523 /* Link Setup Parameters for CAIF-Links. */
77524 struct cfctrl_link_param {
77525@@ -101,8 +101,8 @@ struct cfctrl_request_info {
77526 struct cfctrl {
77527 struct cfsrvl serv;
77528 struct cfctrl_rsp res;
77529- atomic_t req_seq_no;
77530- atomic_t rsp_seq_no;
77531+ atomic_unchecked_t req_seq_no;
77532+ atomic_unchecked_t rsp_seq_no;
77533 struct list_head list;
77534 /* Protects from simultaneous access to first_req list */
77535 spinlock_t info_list_lock;
77536diff --git a/include/net/flow.h b/include/net/flow.h
77537index 628e11b..4c475df 100644
77538--- a/include/net/flow.h
77539+++ b/include/net/flow.h
77540@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
77541
77542 extern void flow_cache_flush(void);
77543 extern void flow_cache_flush_deferred(void);
77544-extern atomic_t flow_cache_genid;
77545+extern atomic_unchecked_t flow_cache_genid;
77546
77547 #endif
77548diff --git a/include/net/genetlink.h b/include/net/genetlink.h
77549index 8e0b6c8..73cf605 100644
77550--- a/include/net/genetlink.h
77551+++ b/include/net/genetlink.h
77552@@ -120,7 +120,7 @@ struct genl_ops {
77553 struct netlink_callback *cb);
77554 int (*done)(struct netlink_callback *cb);
77555 struct list_head ops_list;
77556-};
77557+} __do_const;
77558
77559 extern int __genl_register_family(struct genl_family *family);
77560
77561diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
77562index 734d9b5..48a9a4b 100644
77563--- a/include/net/gro_cells.h
77564+++ b/include/net/gro_cells.h
77565@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
77566 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
77567
77568 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
77569- atomic_long_inc(&dev->rx_dropped);
77570+ atomic_long_inc_unchecked(&dev->rx_dropped);
77571 kfree_skb(skb);
77572 return;
77573 }
77574diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
77575index de2c785..0588a6b 100644
77576--- a/include/net/inet_connection_sock.h
77577+++ b/include/net/inet_connection_sock.h
77578@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
77579 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
77580 int (*bind_conflict)(const struct sock *sk,
77581 const struct inet_bind_bucket *tb, bool relax);
77582-};
77583+} __do_const;
77584
77585 /** inet_connection_sock - INET connection oriented sock
77586 *
77587diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
77588index 53f464d..0bd0b49 100644
77589--- a/include/net/inetpeer.h
77590+++ b/include/net/inetpeer.h
77591@@ -47,8 +47,8 @@ struct inet_peer {
77592 */
77593 union {
77594 struct {
77595- atomic_t rid; /* Frag reception counter */
77596- atomic_t ip_id_count; /* IP ID for the next packet */
77597+ atomic_unchecked_t rid; /* Frag reception counter */
77598+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
77599 };
77600 struct rcu_head rcu;
77601 struct inet_peer *gc_next;
77602@@ -178,16 +178,13 @@ static inline void inet_peer_refcheck(const struct inet_peer *p)
77603 /* can be called with or without local BH being disabled */
77604 static inline int inet_getid(struct inet_peer *p, int more)
77605 {
77606- int old, new;
77607+ int id;
77608 more++;
77609 inet_peer_refcheck(p);
77610- do {
77611- old = atomic_read(&p->ip_id_count);
77612- new = old + more;
77613- if (!new)
77614- new = 1;
77615- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
77616- return new;
77617+ id = atomic_add_return_unchecked(more, &p->ip_id_count);
77618+ if (!id)
77619+ id = atomic_inc_return_unchecked(&p->ip_id_count);
77620+ return id;
77621 }
77622
77623 #endif /* _NET_INETPEER_H */
77624diff --git a/include/net/ip.h b/include/net/ip.h
77625index edfa591..a643b82 100644
77626--- a/include/net/ip.h
77627+++ b/include/net/ip.h
77628@@ -202,7 +202,7 @@ extern struct local_ports {
77629 } sysctl_local_ports;
77630 extern void inet_get_local_port_range(int *low, int *high);
77631
77632-extern unsigned long *sysctl_local_reserved_ports;
77633+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
77634 static inline int inet_is_reserved_local_port(int port)
77635 {
77636 return test_bit(port, sysctl_local_reserved_ports);
77637diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
77638index cbf2be3..3683f6d 100644
77639--- a/include/net/ip_fib.h
77640+++ b/include/net/ip_fib.h
77641@@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
77642
77643 #define FIB_RES_SADDR(net, res) \
77644 ((FIB_RES_NH(res).nh_saddr_genid == \
77645- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
77646+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
77647 FIB_RES_NH(res).nh_saddr : \
77648 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
77649 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
77650diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
77651index f0d70f0..185f15b 100644
77652--- a/include/net/ip_vs.h
77653+++ b/include/net/ip_vs.h
77654@@ -588,7 +588,7 @@ struct ip_vs_conn {
77655 struct ip_vs_conn *control; /* Master control connection */
77656 atomic_t n_control; /* Number of controlled ones */
77657 struct ip_vs_dest *dest; /* real server */
77658- atomic_t in_pkts; /* incoming packet counter */
77659+ atomic_unchecked_t in_pkts; /* incoming packet counter */
77660
77661 /* packet transmitter for different forwarding methods. If it
77662 mangles the packet, it must return NF_DROP or better NF_STOLEN,
77663@@ -737,7 +737,7 @@ struct ip_vs_dest {
77664 __be16 port; /* port number of the server */
77665 union nf_inet_addr addr; /* IP address of the server */
77666 volatile unsigned int flags; /* dest status flags */
77667- atomic_t conn_flags; /* flags to copy to conn */
77668+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
77669 atomic_t weight; /* server weight */
77670
77671 atomic_t refcnt; /* reference counter */
77672@@ -993,11 +993,11 @@ struct netns_ipvs {
77673 /* ip_vs_lblc */
77674 int sysctl_lblc_expiration;
77675 struct ctl_table_header *lblc_ctl_header;
77676- struct ctl_table *lblc_ctl_table;
77677+ ctl_table_no_const *lblc_ctl_table;
77678 /* ip_vs_lblcr */
77679 int sysctl_lblcr_expiration;
77680 struct ctl_table_header *lblcr_ctl_header;
77681- struct ctl_table *lblcr_ctl_table;
77682+ ctl_table_no_const *lblcr_ctl_table;
77683 /* ip_vs_est */
77684 struct list_head est_list; /* estimator list */
77685 spinlock_t est_lock;
77686diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
77687index 80ffde3..968b0f4 100644
77688--- a/include/net/irda/ircomm_tty.h
77689+++ b/include/net/irda/ircomm_tty.h
77690@@ -35,6 +35,7 @@
77691 #include <linux/termios.h>
77692 #include <linux/timer.h>
77693 #include <linux/tty.h> /* struct tty_struct */
77694+#include <asm/local.h>
77695
77696 #include <net/irda/irias_object.h>
77697 #include <net/irda/ircomm_core.h>
77698diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
77699index 714cc9a..ea05f3e 100644
77700--- a/include/net/iucv/af_iucv.h
77701+++ b/include/net/iucv/af_iucv.h
77702@@ -149,7 +149,7 @@ struct iucv_skb_cb {
77703 struct iucv_sock_list {
77704 struct hlist_head head;
77705 rwlock_t lock;
77706- atomic_t autobind_name;
77707+ atomic_unchecked_t autobind_name;
77708 };
77709
77710 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
77711diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
77712index df83f69..9b640b8 100644
77713--- a/include/net/llc_c_ac.h
77714+++ b/include/net/llc_c_ac.h
77715@@ -87,7 +87,7 @@
77716 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
77717 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
77718
77719-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
77720+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
77721
77722 extern int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
77723 extern int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
77724diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
77725index 6ca3113..f8026dd 100644
77726--- a/include/net/llc_c_ev.h
77727+++ b/include/net/llc_c_ev.h
77728@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
77729 return (struct llc_conn_state_ev *)skb->cb;
77730 }
77731
77732-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
77733-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
77734+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
77735+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
77736
77737 extern int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
77738 extern int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
77739diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
77740index 0e79cfb..f46db31 100644
77741--- a/include/net/llc_c_st.h
77742+++ b/include/net/llc_c_st.h
77743@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
77744 u8 next_state;
77745 llc_conn_ev_qfyr_t *ev_qualifiers;
77746 llc_conn_action_t *ev_actions;
77747-};
77748+} __do_const;
77749
77750 struct llc_conn_state {
77751 u8 current_state;
77752diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
77753index 37a3bbd..55a4241 100644
77754--- a/include/net/llc_s_ac.h
77755+++ b/include/net/llc_s_ac.h
77756@@ -23,7 +23,7 @@
77757 #define SAP_ACT_TEST_IND 9
77758
77759 /* All action functions must look like this */
77760-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
77761+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
77762
77763 extern int llc_sap_action_unitdata_ind(struct llc_sap *sap,
77764 struct sk_buff *skb);
77765diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
77766index 567c681..cd73ac0 100644
77767--- a/include/net/llc_s_st.h
77768+++ b/include/net/llc_s_st.h
77769@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
77770 llc_sap_ev_t ev;
77771 u8 next_state;
77772 llc_sap_action_t *ev_actions;
77773-};
77774+} __do_const;
77775
77776 struct llc_sap_state {
77777 u8 curr_state;
77778diff --git a/include/net/mac80211.h b/include/net/mac80211.h
77779index 551ba6a..11c99c1 100644
77780--- a/include/net/mac80211.h
77781+++ b/include/net/mac80211.h
77782@@ -4221,7 +4221,7 @@ struct rate_control_ops {
77783 void (*add_sta_debugfs)(void *priv, void *priv_sta,
77784 struct dentry *dir);
77785 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
77786-};
77787+} __do_const;
77788
77789 static inline int rate_supported(struct ieee80211_sta *sta,
77790 enum ieee80211_band band,
77791diff --git a/include/net/neighbour.h b/include/net/neighbour.h
77792index 7e748ad..5c6229b 100644
77793--- a/include/net/neighbour.h
77794+++ b/include/net/neighbour.h
77795@@ -123,7 +123,7 @@ struct neigh_ops {
77796 void (*error_report)(struct neighbour *, struct sk_buff *);
77797 int (*output)(struct neighbour *, struct sk_buff *);
77798 int (*connected_output)(struct neighbour *, struct sk_buff *);
77799-};
77800+} __do_const;
77801
77802 struct pneigh_entry {
77803 struct pneigh_entry *next;
77804diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
77805index 84e37b1..8eba19a 100644
77806--- a/include/net/net_namespace.h
77807+++ b/include/net/net_namespace.h
77808@@ -119,8 +119,8 @@ struct net {
77809 struct netns_ipvs *ipvs;
77810 #endif
77811 struct sock *diag_nlsk;
77812- atomic_t rt_genid;
77813- atomic_t fnhe_genid;
77814+ atomic_unchecked_t rt_genid;
77815+ atomic_unchecked_t fnhe_genid;
77816 };
77817
77818 /*
77819@@ -277,7 +277,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
77820 #define __net_init __init
77821 #define __net_exit __exit_refok
77822 #define __net_initdata __initdata
77823+#ifdef CONSTIFY_PLUGIN
77824 #define __net_initconst __initconst
77825+#else
77826+#define __net_initconst __initdata
77827+#endif
77828 #endif
77829
77830 struct pernet_operations {
77831@@ -287,7 +291,7 @@ struct pernet_operations {
77832 void (*exit_batch)(struct list_head *net_exit_list);
77833 int *id;
77834 size_t size;
77835-};
77836+} __do_const;
77837
77838 /*
77839 * Use these carefully. If you implement a network device and it
77840@@ -335,22 +339,22 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
77841
77842 static inline int rt_genid(struct net *net)
77843 {
77844- return atomic_read(&net->rt_genid);
77845+ return atomic_read_unchecked(&net->rt_genid);
77846 }
77847
77848 static inline void rt_genid_bump(struct net *net)
77849 {
77850- atomic_inc(&net->rt_genid);
77851+ atomic_inc_unchecked(&net->rt_genid);
77852 }
77853
77854 static inline int fnhe_genid(struct net *net)
77855 {
77856- return atomic_read(&net->fnhe_genid);
77857+ return atomic_read_unchecked(&net->fnhe_genid);
77858 }
77859
77860 static inline void fnhe_genid_bump(struct net *net)
77861 {
77862- atomic_inc(&net->fnhe_genid);
77863+ atomic_inc_unchecked(&net->fnhe_genid);
77864 }
77865
77866 #endif /* __NET_NET_NAMESPACE_H */
77867diff --git a/include/net/netdma.h b/include/net/netdma.h
77868index 8ba8ce2..99b7fff 100644
77869--- a/include/net/netdma.h
77870+++ b/include/net/netdma.h
77871@@ -24,7 +24,7 @@
77872 #include <linux/dmaengine.h>
77873 #include <linux/skbuff.h>
77874
77875-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
77876+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
77877 struct sk_buff *skb, int offset, struct iovec *to,
77878 size_t len, struct dma_pinned_list *pinned_list);
77879
77880diff --git a/include/net/netlink.h b/include/net/netlink.h
77881index 9690b0f..87aded7 100644
77882--- a/include/net/netlink.h
77883+++ b/include/net/netlink.h
77884@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
77885 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
77886 {
77887 if (mark)
77888- skb_trim(skb, (unsigned char *) mark - skb->data);
77889+ skb_trim(skb, (const unsigned char *) mark - skb->data);
77890 }
77891
77892 /**
77893diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
77894index c9c0c53..53f24c3 100644
77895--- a/include/net/netns/conntrack.h
77896+++ b/include/net/netns/conntrack.h
77897@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
77898 struct nf_proto_net {
77899 #ifdef CONFIG_SYSCTL
77900 struct ctl_table_header *ctl_table_header;
77901- struct ctl_table *ctl_table;
77902+ ctl_table_no_const *ctl_table;
77903 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
77904 struct ctl_table_header *ctl_compat_header;
77905- struct ctl_table *ctl_compat_table;
77906+ ctl_table_no_const *ctl_compat_table;
77907 #endif
77908 #endif
77909 unsigned int users;
77910@@ -58,7 +58,7 @@ struct nf_ip_net {
77911 struct nf_icmp_net icmpv6;
77912 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
77913 struct ctl_table_header *ctl_table_header;
77914- struct ctl_table *ctl_table;
77915+ ctl_table_no_const *ctl_table;
77916 #endif
77917 };
77918
77919diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
77920index 2ba9de8..47bd6c7 100644
77921--- a/include/net/netns/ipv4.h
77922+++ b/include/net/netns/ipv4.h
77923@@ -67,7 +67,7 @@ struct netns_ipv4 {
77924 kgid_t sysctl_ping_group_range[2];
77925 long sysctl_tcp_mem[3];
77926
77927- atomic_t dev_addr_genid;
77928+ atomic_unchecked_t dev_addr_genid;
77929
77930 #ifdef CONFIG_IP_MROUTE
77931 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
77932diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
77933index 005e2c2..023d340 100644
77934--- a/include/net/netns/ipv6.h
77935+++ b/include/net/netns/ipv6.h
77936@@ -71,7 +71,7 @@ struct netns_ipv6 {
77937 struct fib_rules_ops *mr6_rules_ops;
77938 #endif
77939 #endif
77940- atomic_t dev_addr_genid;
77941+ atomic_unchecked_t dev_addr_genid;
77942 };
77943
77944 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
77945diff --git a/include/net/ping.h b/include/net/ping.h
77946index 5db0224..0d65365 100644
77947--- a/include/net/ping.h
77948+++ b/include/net/ping.h
77949@@ -55,7 +55,7 @@ struct ping_iter_state {
77950 extern struct proto ping_prot;
77951 extern struct ping_table ping_table;
77952 #if IS_ENABLED(CONFIG_IPV6)
77953-extern struct pingv6_ops pingv6_ops;
77954+extern struct pingv6_ops *pingv6_ops;
77955 #endif
77956
77957 struct pingfakehdr {
77958diff --git a/include/net/protocol.h b/include/net/protocol.h
77959index 047c047..b9dad15 100644
77960--- a/include/net/protocol.h
77961+++ b/include/net/protocol.h
77962@@ -44,7 +44,7 @@ struct net_protocol {
77963 void (*err_handler)(struct sk_buff *skb, u32 info);
77964 unsigned int no_policy:1,
77965 netns_ok:1;
77966-};
77967+} __do_const;
77968
77969 #if IS_ENABLED(CONFIG_IPV6)
77970 struct inet6_protocol {
77971@@ -57,7 +57,7 @@ struct inet6_protocol {
77972 u8 type, u8 code, int offset,
77973 __be32 info);
77974 unsigned int flags; /* INET6_PROTO_xxx */
77975-};
77976+} __do_const;
77977
77978 #define INET6_PROTO_NOPOLICY 0x1
77979 #define INET6_PROTO_FINAL 0x2
77980diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
77981index 7026648..584cc8c 100644
77982--- a/include/net/rtnetlink.h
77983+++ b/include/net/rtnetlink.h
77984@@ -81,7 +81,7 @@ struct rtnl_link_ops {
77985 const struct net_device *dev);
77986 unsigned int (*get_num_tx_queues)(void);
77987 unsigned int (*get_num_rx_queues)(void);
77988-};
77989+} __do_const;
77990
77991 extern int __rtnl_link_register(struct rtnl_link_ops *ops);
77992 extern void __rtnl_link_unregister(struct rtnl_link_ops *ops);
77993diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
77994index 2a82d13..62a31c2 100644
77995--- a/include/net/sctp/sm.h
77996+++ b/include/net/sctp/sm.h
77997@@ -87,7 +87,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
77998 typedef struct {
77999 sctp_state_fn_t *fn;
78000 const char *name;
78001-} sctp_sm_table_entry_t;
78002+} __do_const sctp_sm_table_entry_t;
78003
78004 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
78005 * currently in use.
78006@@ -299,7 +299,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
78007 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
78008
78009 /* Extern declarations for major data structures. */
78010-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
78011+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
78012
78013
78014 /* Get the size of a DATA chunk payload. */
78015diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
78016index e745c92..3641448 100644
78017--- a/include/net/sctp/structs.h
78018+++ b/include/net/sctp/structs.h
78019@@ -516,7 +516,7 @@ struct sctp_pf {
78020 struct sctp_association *asoc);
78021 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
78022 struct sctp_af *af;
78023-};
78024+} __do_const;
78025
78026
78027 /* Structure to track chunk fragments that have been acked, but peer
78028diff --git a/include/net/sock.h b/include/net/sock.h
78029index 04e148f..3b1c7e0 100644
78030--- a/include/net/sock.h
78031+++ b/include/net/sock.h
78032@@ -332,7 +332,7 @@ struct sock {
78033 unsigned int sk_napi_id;
78034 unsigned int sk_ll_usec;
78035 #endif
78036- atomic_t sk_drops;
78037+ atomic_unchecked_t sk_drops;
78038 int sk_rcvbuf;
78039
78040 struct sk_filter __rcu *sk_filter;
78041@@ -1805,7 +1805,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
78042 }
78043
78044 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
78045- char __user *from, char *to,
78046+ char __user *from, unsigned char *to,
78047 int copy, int offset)
78048 {
78049 if (skb->ip_summed == CHECKSUM_NONE) {
78050@@ -2067,7 +2067,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
78051 }
78052 }
78053
78054-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
78055+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
78056
78057 /**
78058 * sk_page_frag - return an appropriate page_frag
78059diff --git a/include/net/tcp.h b/include/net/tcp.h
78060index 46cb8a4..32b7b4a 100644
78061--- a/include/net/tcp.h
78062+++ b/include/net/tcp.h
78063@@ -522,7 +522,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
78064 extern void tcp_xmit_retransmit_queue(struct sock *);
78065 extern void tcp_simple_retransmit(struct sock *);
78066 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
78067-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
78068+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
78069
78070 extern void tcp_send_probe0(struct sock *);
78071 extern void tcp_send_partial(struct sock *);
78072@@ -695,8 +695,8 @@ struct tcp_skb_cb {
78073 struct inet6_skb_parm h6;
78074 #endif
78075 } header; /* For incoming frames */
78076- __u32 seq; /* Starting sequence number */
78077- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
78078+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
78079+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
78080 __u32 when; /* used to compute rtt's */
78081 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
78082
78083@@ -710,7 +710,7 @@ struct tcp_skb_cb {
78084
78085 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
78086 /* 1 byte hole */
78087- __u32 ack_seq; /* Sequence number ACK'd */
78088+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
78089 };
78090
78091 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
78092diff --git a/include/net/xfrm.h b/include/net/xfrm.h
78093index e823786..53b0608 100644
78094--- a/include/net/xfrm.h
78095+++ b/include/net/xfrm.h
78096@@ -287,7 +287,6 @@ struct xfrm_dst;
78097 struct xfrm_policy_afinfo {
78098 unsigned short family;
78099 struct dst_ops *dst_ops;
78100- void (*garbage_collect)(struct net *net);
78101 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
78102 const xfrm_address_t *saddr,
78103 const xfrm_address_t *daddr);
78104@@ -305,7 +304,7 @@ struct xfrm_policy_afinfo {
78105 struct net_device *dev,
78106 const struct flowi *fl);
78107 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
78108-};
78109+} __do_const;
78110
78111 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
78112 extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
78113@@ -342,7 +341,7 @@ struct xfrm_state_afinfo {
78114 int (*transport_finish)(struct sk_buff *skb,
78115 int async);
78116 void (*local_error)(struct sk_buff *skb, u32 mtu);
78117-};
78118+} __do_const;
78119
78120 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
78121 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
78122@@ -427,7 +426,7 @@ struct xfrm_mode {
78123 struct module *owner;
78124 unsigned int encap;
78125 int flags;
78126-};
78127+} __do_const;
78128
78129 /* Flags for xfrm_mode. */
78130 enum {
78131@@ -524,7 +523,7 @@ struct xfrm_policy {
78132 struct timer_list timer;
78133
78134 struct flow_cache_object flo;
78135- atomic_t genid;
78136+ atomic_unchecked_t genid;
78137 u32 priority;
78138 u32 index;
78139 struct xfrm_mark mark;
78140@@ -1164,6 +1163,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
78141 }
78142
78143 extern void xfrm_garbage_collect(struct net *net);
78144+extern void xfrm_garbage_collect_deferred(struct net *net);
78145
78146 #else
78147
78148@@ -1202,6 +1202,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
78149 static inline void xfrm_garbage_collect(struct net *net)
78150 {
78151 }
78152+static inline void xfrm_garbage_collect_deferred(struct net *net)
78153+{
78154+}
78155 #endif
78156
78157 static __inline__
78158diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
78159index 1a046b1..ee0bef0 100644
78160--- a/include/rdma/iw_cm.h
78161+++ b/include/rdma/iw_cm.h
78162@@ -122,7 +122,7 @@ struct iw_cm_verbs {
78163 int backlog);
78164
78165 int (*destroy_listen)(struct iw_cm_id *cm_id);
78166-};
78167+} __no_const;
78168
78169 /**
78170 * iw_create_cm_id - Create an IW CM identifier.
78171diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
78172index e1379b4..67eafbe 100644
78173--- a/include/scsi/libfc.h
78174+++ b/include/scsi/libfc.h
78175@@ -762,6 +762,7 @@ struct libfc_function_template {
78176 */
78177 void (*disc_stop_final) (struct fc_lport *);
78178 };
78179+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
78180
78181 /**
78182 * struct fc_disc - Discovery context
78183@@ -866,7 +867,7 @@ struct fc_lport {
78184 struct fc_vport *vport;
78185
78186 /* Operational Information */
78187- struct libfc_function_template tt;
78188+ libfc_function_template_no_const tt;
78189 u8 link_up;
78190 u8 qfull;
78191 enum fc_lport_state state;
78192diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
78193index a44954c..5da04b2 100644
78194--- a/include/scsi/scsi_device.h
78195+++ b/include/scsi/scsi_device.h
78196@@ -172,9 +172,9 @@ struct scsi_device {
78197 unsigned int max_device_blocked; /* what device_blocked counts down from */
78198 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
78199
78200- atomic_t iorequest_cnt;
78201- atomic_t iodone_cnt;
78202- atomic_t ioerr_cnt;
78203+ atomic_unchecked_t iorequest_cnt;
78204+ atomic_unchecked_t iodone_cnt;
78205+ atomic_unchecked_t ioerr_cnt;
78206
78207 struct device sdev_gendev,
78208 sdev_dev;
78209diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
78210index b797e8f..8e2c3aa 100644
78211--- a/include/scsi/scsi_transport_fc.h
78212+++ b/include/scsi/scsi_transport_fc.h
78213@@ -751,7 +751,8 @@ struct fc_function_template {
78214 unsigned long show_host_system_hostname:1;
78215
78216 unsigned long disable_target_scan:1;
78217-};
78218+} __do_const;
78219+typedef struct fc_function_template __no_const fc_function_template_no_const;
78220
78221
78222 /**
78223diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
78224index 9031a26..750d592 100644
78225--- a/include/sound/compress_driver.h
78226+++ b/include/sound/compress_driver.h
78227@@ -128,7 +128,7 @@ struct snd_compr_ops {
78228 struct snd_compr_caps *caps);
78229 int (*get_codec_caps) (struct snd_compr_stream *stream,
78230 struct snd_compr_codec_caps *codec);
78231-};
78232+} __no_const;
78233
78234 /**
78235 * struct snd_compr: Compressed device
78236diff --git a/include/sound/soc.h b/include/sound/soc.h
78237index 6eabee7..58afb50 100644
78238--- a/include/sound/soc.h
78239+++ b/include/sound/soc.h
78240@@ -783,7 +783,7 @@ struct snd_soc_codec_driver {
78241 /* probe ordering - for components with runtime dependencies */
78242 int probe_order;
78243 int remove_order;
78244-};
78245+} __do_const;
78246
78247 /* SoC platform interface */
78248 struct snd_soc_platform_driver {
78249@@ -829,7 +829,7 @@ struct snd_soc_platform_driver {
78250 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
78251 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
78252 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
78253-};
78254+} __do_const;
78255
78256 struct snd_soc_platform {
78257 const char *name;
78258diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
78259index e34fc90..ecefa2c 100644
78260--- a/include/target/target_core_base.h
78261+++ b/include/target/target_core_base.h
78262@@ -643,7 +643,7 @@ struct se_device {
78263 spinlock_t stats_lock;
78264 /* Active commands on this virtual SE device */
78265 atomic_t simple_cmds;
78266- atomic_t dev_ordered_id;
78267+ atomic_unchecked_t dev_ordered_id;
78268 atomic_t dev_ordered_sync;
78269 atomic_t dev_qf_count;
78270 int export_count;
78271diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
78272new file mode 100644
78273index 0000000..fb634b7
78274--- /dev/null
78275+++ b/include/trace/events/fs.h
78276@@ -0,0 +1,53 @@
78277+#undef TRACE_SYSTEM
78278+#define TRACE_SYSTEM fs
78279+
78280+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
78281+#define _TRACE_FS_H
78282+
78283+#include <linux/fs.h>
78284+#include <linux/tracepoint.h>
78285+
78286+TRACE_EVENT(do_sys_open,
78287+
78288+ TP_PROTO(const char *filename, int flags, int mode),
78289+
78290+ TP_ARGS(filename, flags, mode),
78291+
78292+ TP_STRUCT__entry(
78293+ __string( filename, filename )
78294+ __field( int, flags )
78295+ __field( int, mode )
78296+ ),
78297+
78298+ TP_fast_assign(
78299+ __assign_str(filename, filename);
78300+ __entry->flags = flags;
78301+ __entry->mode = mode;
78302+ ),
78303+
78304+ TP_printk("\"%s\" %x %o",
78305+ __get_str(filename), __entry->flags, __entry->mode)
78306+);
78307+
78308+TRACE_EVENT(open_exec,
78309+
78310+ TP_PROTO(const char *filename),
78311+
78312+ TP_ARGS(filename),
78313+
78314+ TP_STRUCT__entry(
78315+ __string( filename, filename )
78316+ ),
78317+
78318+ TP_fast_assign(
78319+ __assign_str(filename, filename);
78320+ ),
78321+
78322+ TP_printk("\"%s\"",
78323+ __get_str(filename))
78324+);
78325+
78326+#endif /* _TRACE_FS_H */
78327+
78328+/* This part must be outside protection */
78329+#include <trace/define_trace.h>
78330diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
78331index 1c09820..7f5ec79 100644
78332--- a/include/trace/events/irq.h
78333+++ b/include/trace/events/irq.h
78334@@ -36,7 +36,7 @@ struct softirq_action;
78335 */
78336 TRACE_EVENT(irq_handler_entry,
78337
78338- TP_PROTO(int irq, struct irqaction *action),
78339+ TP_PROTO(int irq, const struct irqaction *action),
78340
78341 TP_ARGS(irq, action),
78342
78343@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
78344 */
78345 TRACE_EVENT(irq_handler_exit,
78346
78347- TP_PROTO(int irq, struct irqaction *action, int ret),
78348+ TP_PROTO(int irq, const struct irqaction *action, int ret),
78349
78350 TP_ARGS(irq, action, ret),
78351
78352diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
78353index 7caf44c..23c6f27 100644
78354--- a/include/uapi/linux/a.out.h
78355+++ b/include/uapi/linux/a.out.h
78356@@ -39,6 +39,14 @@ enum machine_type {
78357 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
78358 };
78359
78360+/* Constants for the N_FLAGS field */
78361+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
78362+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
78363+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
78364+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
78365+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
78366+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
78367+
78368 #if !defined (N_MAGIC)
78369 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
78370 #endif
78371diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
78372index d876736..ccce5c0 100644
78373--- a/include/uapi/linux/byteorder/little_endian.h
78374+++ b/include/uapi/linux/byteorder/little_endian.h
78375@@ -42,51 +42,51 @@
78376
78377 static inline __le64 __cpu_to_le64p(const __u64 *p)
78378 {
78379- return (__force __le64)*p;
78380+ return (__force const __le64)*p;
78381 }
78382-static inline __u64 __le64_to_cpup(const __le64 *p)
78383+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
78384 {
78385- return (__force __u64)*p;
78386+ return (__force const __u64)*p;
78387 }
78388 static inline __le32 __cpu_to_le32p(const __u32 *p)
78389 {
78390- return (__force __le32)*p;
78391+ return (__force const __le32)*p;
78392 }
78393 static inline __u32 __le32_to_cpup(const __le32 *p)
78394 {
78395- return (__force __u32)*p;
78396+ return (__force const __u32)*p;
78397 }
78398 static inline __le16 __cpu_to_le16p(const __u16 *p)
78399 {
78400- return (__force __le16)*p;
78401+ return (__force const __le16)*p;
78402 }
78403 static inline __u16 __le16_to_cpup(const __le16 *p)
78404 {
78405- return (__force __u16)*p;
78406+ return (__force const __u16)*p;
78407 }
78408 static inline __be64 __cpu_to_be64p(const __u64 *p)
78409 {
78410- return (__force __be64)__swab64p(p);
78411+ return (__force const __be64)__swab64p(p);
78412 }
78413 static inline __u64 __be64_to_cpup(const __be64 *p)
78414 {
78415- return __swab64p((__u64 *)p);
78416+ return __swab64p((const __u64 *)p);
78417 }
78418 static inline __be32 __cpu_to_be32p(const __u32 *p)
78419 {
78420- return (__force __be32)__swab32p(p);
78421+ return (__force const __be32)__swab32p(p);
78422 }
78423-static inline __u32 __be32_to_cpup(const __be32 *p)
78424+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
78425 {
78426- return __swab32p((__u32 *)p);
78427+ return __swab32p((const __u32 *)p);
78428 }
78429 static inline __be16 __cpu_to_be16p(const __u16 *p)
78430 {
78431- return (__force __be16)__swab16p(p);
78432+ return (__force const __be16)__swab16p(p);
78433 }
78434 static inline __u16 __be16_to_cpup(const __be16 *p)
78435 {
78436- return __swab16p((__u16 *)p);
78437+ return __swab16p((const __u16 *)p);
78438 }
78439 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
78440 #define __le64_to_cpus(x) do { (void)(x); } while (0)
78441diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
78442index ef6103b..d4e65dd 100644
78443--- a/include/uapi/linux/elf.h
78444+++ b/include/uapi/linux/elf.h
78445@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
78446 #define PT_GNU_EH_FRAME 0x6474e550
78447
78448 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
78449+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
78450+
78451+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
78452+
78453+/* Constants for the e_flags field */
78454+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
78455+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
78456+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
78457+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
78458+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
78459+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
78460
78461 /*
78462 * Extended Numbering
78463@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
78464 #define DT_DEBUG 21
78465 #define DT_TEXTREL 22
78466 #define DT_JMPREL 23
78467+#define DT_FLAGS 30
78468+ #define DF_TEXTREL 0x00000004
78469 #define DT_ENCODING 32
78470 #define OLD_DT_LOOS 0x60000000
78471 #define DT_LOOS 0x6000000d
78472@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
78473 #define PF_W 0x2
78474 #define PF_X 0x1
78475
78476+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
78477+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
78478+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
78479+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
78480+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
78481+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
78482+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
78483+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
78484+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
78485+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
78486+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
78487+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
78488+
78489 typedef struct elf32_phdr{
78490 Elf32_Word p_type;
78491 Elf32_Off p_offset;
78492@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
78493 #define EI_OSABI 7
78494 #define EI_PAD 8
78495
78496+#define EI_PAX 14
78497+
78498 #define ELFMAG0 0x7f /* EI_MAG */
78499 #define ELFMAG1 'E'
78500 #define ELFMAG2 'L'
78501diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
78502index aa169c4..6a2771d 100644
78503--- a/include/uapi/linux/personality.h
78504+++ b/include/uapi/linux/personality.h
78505@@ -30,6 +30,7 @@ enum {
78506 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
78507 ADDR_NO_RANDOMIZE | \
78508 ADDR_COMPAT_LAYOUT | \
78509+ ADDR_LIMIT_3GB | \
78510 MMAP_PAGE_ZERO)
78511
78512 /*
78513diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
78514index 7530e74..e714828 100644
78515--- a/include/uapi/linux/screen_info.h
78516+++ b/include/uapi/linux/screen_info.h
78517@@ -43,7 +43,8 @@ struct screen_info {
78518 __u16 pages; /* 0x32 */
78519 __u16 vesa_attributes; /* 0x34 */
78520 __u32 capabilities; /* 0x36 */
78521- __u8 _reserved[6]; /* 0x3a */
78522+ __u16 vesapm_size; /* 0x3a */
78523+ __u8 _reserved[4]; /* 0x3c */
78524 } __attribute__((packed));
78525
78526 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
78527diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
78528index 0e011eb..82681b1 100644
78529--- a/include/uapi/linux/swab.h
78530+++ b/include/uapi/linux/swab.h
78531@@ -43,7 +43,7 @@
78532 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
78533 */
78534
78535-static inline __attribute_const__ __u16 __fswab16(__u16 val)
78536+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
78537 {
78538 #ifdef __HAVE_BUILTIN_BSWAP16__
78539 return __builtin_bswap16(val);
78540@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
78541 #endif
78542 }
78543
78544-static inline __attribute_const__ __u32 __fswab32(__u32 val)
78545+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
78546 {
78547 #ifdef __HAVE_BUILTIN_BSWAP32__
78548 return __builtin_bswap32(val);
78549@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
78550 #endif
78551 }
78552
78553-static inline __attribute_const__ __u64 __fswab64(__u64 val)
78554+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
78555 {
78556 #ifdef __HAVE_BUILTIN_BSWAP64__
78557 return __builtin_bswap64(val);
78558diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
78559index 6d67213..8dab561 100644
78560--- a/include/uapi/linux/sysctl.h
78561+++ b/include/uapi/linux/sysctl.h
78562@@ -155,7 +155,11 @@ enum
78563 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
78564 };
78565
78566-
78567+#ifdef CONFIG_PAX_SOFTMODE
78568+enum {
78569+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
78570+};
78571+#endif
78572
78573 /* CTL_VM names: */
78574 enum
78575diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
78576index e4629b9..6958086 100644
78577--- a/include/uapi/linux/xattr.h
78578+++ b/include/uapi/linux/xattr.h
78579@@ -63,5 +63,9 @@
78580 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
78581 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
78582
78583+/* User namespace */
78584+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
78585+#define XATTR_PAX_FLAGS_SUFFIX "flags"
78586+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
78587
78588 #endif /* _UAPI_LINUX_XATTR_H */
78589diff --git a/include/video/udlfb.h b/include/video/udlfb.h
78590index f9466fa..f4e2b81 100644
78591--- a/include/video/udlfb.h
78592+++ b/include/video/udlfb.h
78593@@ -53,10 +53,10 @@ struct dlfb_data {
78594 u32 pseudo_palette[256];
78595 int blank_mode; /*one of FB_BLANK_ */
78596 /* blit-only rendering path metrics, exposed through sysfs */
78597- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
78598- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
78599- atomic_t bytes_sent; /* to usb, after compression including overhead */
78600- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
78601+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
78602+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
78603+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
78604+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
78605 };
78606
78607 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
78608diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
78609index 30f5362..8ed8ac9 100644
78610--- a/include/video/uvesafb.h
78611+++ b/include/video/uvesafb.h
78612@@ -122,6 +122,7 @@ struct uvesafb_par {
78613 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
78614 u8 pmi_setpal; /* PMI for palette changes */
78615 u16 *pmi_base; /* protected mode interface location */
78616+ u8 *pmi_code; /* protected mode code location */
78617 void *pmi_start;
78618 void *pmi_pal;
78619 u8 *vbe_state_orig; /*
78620diff --git a/init/Kconfig b/init/Kconfig
78621index fed81b5..0d3b964 100644
78622--- a/init/Kconfig
78623+++ b/init/Kconfig
78624@@ -1069,6 +1069,7 @@ endif # CGROUPS
78625
78626 config CHECKPOINT_RESTORE
78627 bool "Checkpoint/restore support" if EXPERT
78628+ depends on !GRKERNSEC
78629 default n
78630 help
78631 Enables additional kernel features in a sake of checkpoint/restore.
78632@@ -1553,7 +1554,7 @@ config SLUB_DEBUG
78633
78634 config COMPAT_BRK
78635 bool "Disable heap randomization"
78636- default y
78637+ default n
78638 help
78639 Randomizing heap placement makes heap exploits harder, but it
78640 also breaks ancient binaries (including anything libc5 based).
78641@@ -1827,7 +1828,7 @@ config INIT_ALL_POSSIBLE
78642 config STOP_MACHINE
78643 bool
78644 default y
78645- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
78646+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
78647 help
78648 Need stop_machine() primitive.
78649
78650diff --git a/init/Makefile b/init/Makefile
78651index 7bc47ee..6da2dc7 100644
78652--- a/init/Makefile
78653+++ b/init/Makefile
78654@@ -2,6 +2,9 @@
78655 # Makefile for the linux kernel.
78656 #
78657
78658+ccflags-y := $(GCC_PLUGINS_CFLAGS)
78659+asflags-y := $(GCC_PLUGINS_AFLAGS)
78660+
78661 obj-y := main.o version.o mounts.o
78662 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
78663 obj-y += noinitramfs.o
78664diff --git a/init/do_mounts.c b/init/do_mounts.c
78665index 816014c..c2054db 100644
78666--- a/init/do_mounts.c
78667+++ b/init/do_mounts.c
78668@@ -355,11 +355,11 @@ static void __init get_fs_names(char *page)
78669 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
78670 {
78671 struct super_block *s;
78672- int err = sys_mount(name, "/root", fs, flags, data);
78673+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
78674 if (err)
78675 return err;
78676
78677- sys_chdir("/root");
78678+ sys_chdir((const char __force_user *)"/root");
78679 s = current->fs->pwd.dentry->d_sb;
78680 ROOT_DEV = s->s_dev;
78681 printk(KERN_INFO
78682@@ -480,18 +480,18 @@ void __init change_floppy(char *fmt, ...)
78683 va_start(args, fmt);
78684 vsprintf(buf, fmt, args);
78685 va_end(args);
78686- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
78687+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
78688 if (fd >= 0) {
78689 sys_ioctl(fd, FDEJECT, 0);
78690 sys_close(fd);
78691 }
78692 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
78693- fd = sys_open("/dev/console", O_RDWR, 0);
78694+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
78695 if (fd >= 0) {
78696 sys_ioctl(fd, TCGETS, (long)&termios);
78697 termios.c_lflag &= ~ICANON;
78698 sys_ioctl(fd, TCSETSF, (long)&termios);
78699- sys_read(fd, &c, 1);
78700+ sys_read(fd, (char __user *)&c, 1);
78701 termios.c_lflag |= ICANON;
78702 sys_ioctl(fd, TCSETSF, (long)&termios);
78703 sys_close(fd);
78704@@ -585,6 +585,6 @@ void __init prepare_namespace(void)
78705 mount_root();
78706 out:
78707 devtmpfs_mount("dev");
78708- sys_mount(".", "/", NULL, MS_MOVE, NULL);
78709- sys_chroot(".");
78710+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
78711+ sys_chroot((const char __force_user *)".");
78712 }
78713diff --git a/init/do_mounts.h b/init/do_mounts.h
78714index f5b978a..69dbfe8 100644
78715--- a/init/do_mounts.h
78716+++ b/init/do_mounts.h
78717@@ -15,15 +15,15 @@ extern int root_mountflags;
78718
78719 static inline int create_dev(char *name, dev_t dev)
78720 {
78721- sys_unlink(name);
78722- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
78723+ sys_unlink((char __force_user *)name);
78724+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
78725 }
78726
78727 #if BITS_PER_LONG == 32
78728 static inline u32 bstat(char *name)
78729 {
78730 struct stat64 stat;
78731- if (sys_stat64(name, &stat) != 0)
78732+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
78733 return 0;
78734 if (!S_ISBLK(stat.st_mode))
78735 return 0;
78736@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
78737 static inline u32 bstat(char *name)
78738 {
78739 struct stat stat;
78740- if (sys_newstat(name, &stat) != 0)
78741+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
78742 return 0;
78743 if (!S_ISBLK(stat.st_mode))
78744 return 0;
78745diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
78746index 3e0878e..8a9d7a0 100644
78747--- a/init/do_mounts_initrd.c
78748+++ b/init/do_mounts_initrd.c
78749@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
78750 {
78751 sys_unshare(CLONE_FS | CLONE_FILES);
78752 /* stdin/stdout/stderr for /linuxrc */
78753- sys_open("/dev/console", O_RDWR, 0);
78754+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
78755 sys_dup(0);
78756 sys_dup(0);
78757 /* move initrd over / and chdir/chroot in initrd root */
78758- sys_chdir("/root");
78759- sys_mount(".", "/", NULL, MS_MOVE, NULL);
78760- sys_chroot(".");
78761+ sys_chdir((const char __force_user *)"/root");
78762+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
78763+ sys_chroot((const char __force_user *)".");
78764 sys_setsid();
78765 return 0;
78766 }
78767@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
78768 create_dev("/dev/root.old", Root_RAM0);
78769 /* mount initrd on rootfs' /root */
78770 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
78771- sys_mkdir("/old", 0700);
78772- sys_chdir("/old");
78773+ sys_mkdir((const char __force_user *)"/old", 0700);
78774+ sys_chdir((const char __force_user *)"/old");
78775
78776 /* try loading default modules from initrd */
78777 load_default_modules();
78778@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
78779 current->flags &= ~PF_FREEZER_SKIP;
78780
78781 /* move initrd to rootfs' /old */
78782- sys_mount("..", ".", NULL, MS_MOVE, NULL);
78783+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
78784 /* switch root and cwd back to / of rootfs */
78785- sys_chroot("..");
78786+ sys_chroot((const char __force_user *)"..");
78787
78788 if (new_decode_dev(real_root_dev) == Root_RAM0) {
78789- sys_chdir("/old");
78790+ sys_chdir((const char __force_user *)"/old");
78791 return;
78792 }
78793
78794- sys_chdir("/");
78795+ sys_chdir((const char __force_user *)"/");
78796 ROOT_DEV = new_decode_dev(real_root_dev);
78797 mount_root();
78798
78799 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
78800- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
78801+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
78802 if (!error)
78803 printk("okay\n");
78804 else {
78805- int fd = sys_open("/dev/root.old", O_RDWR, 0);
78806+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
78807 if (error == -ENOENT)
78808 printk("/initrd does not exist. Ignored.\n");
78809 else
78810 printk("failed\n");
78811 printk(KERN_NOTICE "Unmounting old root\n");
78812- sys_umount("/old", MNT_DETACH);
78813+ sys_umount((char __force_user *)"/old", MNT_DETACH);
78814 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
78815 if (fd < 0) {
78816 error = fd;
78817@@ -127,11 +127,11 @@ int __init initrd_load(void)
78818 * mounted in the normal path.
78819 */
78820 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
78821- sys_unlink("/initrd.image");
78822+ sys_unlink((const char __force_user *)"/initrd.image");
78823 handle_initrd();
78824 return 1;
78825 }
78826 }
78827- sys_unlink("/initrd.image");
78828+ sys_unlink((const char __force_user *)"/initrd.image");
78829 return 0;
78830 }
78831diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
78832index 8cb6db5..d729f50 100644
78833--- a/init/do_mounts_md.c
78834+++ b/init/do_mounts_md.c
78835@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
78836 partitioned ? "_d" : "", minor,
78837 md_setup_args[ent].device_names);
78838
78839- fd = sys_open(name, 0, 0);
78840+ fd = sys_open((char __force_user *)name, 0, 0);
78841 if (fd < 0) {
78842 printk(KERN_ERR "md: open failed - cannot start "
78843 "array %s\n", name);
78844@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
78845 * array without it
78846 */
78847 sys_close(fd);
78848- fd = sys_open(name, 0, 0);
78849+ fd = sys_open((char __force_user *)name, 0, 0);
78850 sys_ioctl(fd, BLKRRPART, 0);
78851 }
78852 sys_close(fd);
78853@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
78854
78855 wait_for_device_probe();
78856
78857- fd = sys_open("/dev/md0", 0, 0);
78858+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
78859 if (fd >= 0) {
78860 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
78861 sys_close(fd);
78862diff --git a/init/init_task.c b/init/init_task.c
78863index ba0a7f36..2bcf1d5 100644
78864--- a/init/init_task.c
78865+++ b/init/init_task.c
78866@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
78867 * Initial thread structure. Alignment of this is handled by a special
78868 * linker map entry.
78869 */
78870+#ifdef CONFIG_X86
78871+union thread_union init_thread_union __init_task_data;
78872+#else
78873 union thread_union init_thread_union __init_task_data =
78874 { INIT_THREAD_INFO(init_task) };
78875+#endif
78876diff --git a/init/initramfs.c b/init/initramfs.c
78877index a67ef9d..2d17ed9 100644
78878--- a/init/initramfs.c
78879+++ b/init/initramfs.c
78880@@ -84,7 +84,7 @@ static void __init free_hash(void)
78881 }
78882 }
78883
78884-static long __init do_utime(char *filename, time_t mtime)
78885+static long __init do_utime(char __force_user *filename, time_t mtime)
78886 {
78887 struct timespec t[2];
78888
78889@@ -119,7 +119,7 @@ static void __init dir_utime(void)
78890 struct dir_entry *de, *tmp;
78891 list_for_each_entry_safe(de, tmp, &dir_list, list) {
78892 list_del(&de->list);
78893- do_utime(de->name, de->mtime);
78894+ do_utime((char __force_user *)de->name, de->mtime);
78895 kfree(de->name);
78896 kfree(de);
78897 }
78898@@ -281,7 +281,7 @@ static int __init maybe_link(void)
78899 if (nlink >= 2) {
78900 char *old = find_link(major, minor, ino, mode, collected);
78901 if (old)
78902- return (sys_link(old, collected) < 0) ? -1 : 1;
78903+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
78904 }
78905 return 0;
78906 }
78907@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
78908 {
78909 struct stat st;
78910
78911- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
78912+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
78913 if (S_ISDIR(st.st_mode))
78914- sys_rmdir(path);
78915+ sys_rmdir((char __force_user *)path);
78916 else
78917- sys_unlink(path);
78918+ sys_unlink((char __force_user *)path);
78919 }
78920 }
78921
78922@@ -315,7 +315,7 @@ static int __init do_name(void)
78923 int openflags = O_WRONLY|O_CREAT;
78924 if (ml != 1)
78925 openflags |= O_TRUNC;
78926- wfd = sys_open(collected, openflags, mode);
78927+ wfd = sys_open((char __force_user *)collected, openflags, mode);
78928
78929 if (wfd >= 0) {
78930 sys_fchown(wfd, uid, gid);
78931@@ -327,17 +327,17 @@ static int __init do_name(void)
78932 }
78933 }
78934 } else if (S_ISDIR(mode)) {
78935- sys_mkdir(collected, mode);
78936- sys_chown(collected, uid, gid);
78937- sys_chmod(collected, mode);
78938+ sys_mkdir((char __force_user *)collected, mode);
78939+ sys_chown((char __force_user *)collected, uid, gid);
78940+ sys_chmod((char __force_user *)collected, mode);
78941 dir_add(collected, mtime);
78942 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
78943 S_ISFIFO(mode) || S_ISSOCK(mode)) {
78944 if (maybe_link() == 0) {
78945- sys_mknod(collected, mode, rdev);
78946- sys_chown(collected, uid, gid);
78947- sys_chmod(collected, mode);
78948- do_utime(collected, mtime);
78949+ sys_mknod((char __force_user *)collected, mode, rdev);
78950+ sys_chown((char __force_user *)collected, uid, gid);
78951+ sys_chmod((char __force_user *)collected, mode);
78952+ do_utime((char __force_user *)collected, mtime);
78953 }
78954 }
78955 return 0;
78956@@ -346,15 +346,15 @@ static int __init do_name(void)
78957 static int __init do_copy(void)
78958 {
78959 if (count >= body_len) {
78960- sys_write(wfd, victim, body_len);
78961+ sys_write(wfd, (char __force_user *)victim, body_len);
78962 sys_close(wfd);
78963- do_utime(vcollected, mtime);
78964+ do_utime((char __force_user *)vcollected, mtime);
78965 kfree(vcollected);
78966 eat(body_len);
78967 state = SkipIt;
78968 return 0;
78969 } else {
78970- sys_write(wfd, victim, count);
78971+ sys_write(wfd, (char __force_user *)victim, count);
78972 body_len -= count;
78973 eat(count);
78974 return 1;
78975@@ -365,9 +365,9 @@ static int __init do_symlink(void)
78976 {
78977 collected[N_ALIGN(name_len) + body_len] = '\0';
78978 clean_path(collected, 0);
78979- sys_symlink(collected + N_ALIGN(name_len), collected);
78980- sys_lchown(collected, uid, gid);
78981- do_utime(collected, mtime);
78982+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
78983+ sys_lchown((char __force_user *)collected, uid, gid);
78984+ do_utime((char __force_user *)collected, mtime);
78985 state = SkipIt;
78986 next_state = Reset;
78987 return 0;
78988@@ -583,7 +583,7 @@ static int __init populate_rootfs(void)
78989 {
78990 char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
78991 if (err)
78992- panic(err); /* Failed to decompress INTERNAL initramfs */
78993+ panic("%s", err); /* Failed to decompress INTERNAL initramfs */
78994 if (initrd_start) {
78995 #ifdef CONFIG_BLK_DEV_RAM
78996 int fd;
78997diff --git a/init/main.c b/init/main.c
78998index 586cd33..f1af30f 100644
78999--- a/init/main.c
79000+++ b/init/main.c
79001@@ -102,6 +102,8 @@ static inline void mark_rodata_ro(void) { }
79002 extern void tc_init(void);
79003 #endif
79004
79005+extern void grsecurity_init(void);
79006+
79007 /*
79008 * Debug helper: via this flag we know that we are in 'early bootup code'
79009 * where only the boot processor is running with IRQ disabled. This means
79010@@ -155,6 +157,74 @@ static int __init set_reset_devices(char *str)
79011
79012 __setup("reset_devices", set_reset_devices);
79013
79014+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
79015+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
79016+static int __init setup_grsec_proc_gid(char *str)
79017+{
79018+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
79019+ return 1;
79020+}
79021+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
79022+#endif
79023+
79024+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
79025+unsigned long pax_user_shadow_base __read_only;
79026+EXPORT_SYMBOL(pax_user_shadow_base);
79027+extern char pax_enter_kernel_user[];
79028+extern char pax_exit_kernel_user[];
79029+#endif
79030+
79031+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
79032+static int __init setup_pax_nouderef(char *str)
79033+{
79034+#ifdef CONFIG_X86_32
79035+ unsigned int cpu;
79036+ struct desc_struct *gdt;
79037+
79038+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
79039+ gdt = get_cpu_gdt_table(cpu);
79040+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
79041+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
79042+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
79043+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
79044+ }
79045+ loadsegment(ds, __KERNEL_DS);
79046+ loadsegment(es, __KERNEL_DS);
79047+ loadsegment(ss, __KERNEL_DS);
79048+#else
79049+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
79050+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
79051+ clone_pgd_mask = ~(pgdval_t)0UL;
79052+ pax_user_shadow_base = 0UL;
79053+ setup_clear_cpu_cap(X86_FEATURE_PCID);
79054+#endif
79055+
79056+ return 0;
79057+}
79058+early_param("pax_nouderef", setup_pax_nouderef);
79059+
79060+#ifdef CONFIG_X86_64
79061+static int __init setup_pax_weakuderef(char *str)
79062+{
79063+ if (clone_pgd_mask != ~(pgdval_t)0UL)
79064+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
79065+ return 1;
79066+}
79067+__setup("pax_weakuderef", setup_pax_weakuderef);
79068+#endif
79069+#endif
79070+
79071+#ifdef CONFIG_PAX_SOFTMODE
79072+int pax_softmode;
79073+
79074+static int __init setup_pax_softmode(char *str)
79075+{
79076+ get_option(&str, &pax_softmode);
79077+ return 1;
79078+}
79079+__setup("pax_softmode=", setup_pax_softmode);
79080+#endif
79081+
79082 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
79083 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
79084 static const char *panic_later, *panic_param;
79085@@ -680,25 +750,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
79086 {
79087 int count = preempt_count();
79088 int ret;
79089- char msgbuf[64];
79090+ const char *msg1 = "", *msg2 = "";
79091
79092 if (initcall_debug)
79093 ret = do_one_initcall_debug(fn);
79094 else
79095 ret = fn();
79096
79097- msgbuf[0] = 0;
79098-
79099 if (preempt_count() != count) {
79100- sprintf(msgbuf, "preemption imbalance ");
79101+ msg1 = " preemption imbalance";
79102 preempt_count() = count;
79103 }
79104 if (irqs_disabled()) {
79105- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
79106+ msg2 = " disabled interrupts";
79107 local_irq_enable();
79108 }
79109- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
79110+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
79111
79112+ add_latent_entropy();
79113 return ret;
79114 }
79115
79116@@ -805,8 +874,8 @@ static int run_init_process(const char *init_filename)
79117 {
79118 argv_init[0] = init_filename;
79119 return do_execve(init_filename,
79120- (const char __user *const __user *)argv_init,
79121- (const char __user *const __user *)envp_init);
79122+ (const char __user *const __force_user *)argv_init,
79123+ (const char __user *const __force_user *)envp_init);
79124 }
79125
79126 static noinline void __init kernel_init_freeable(void);
79127@@ -883,7 +952,7 @@ static noinline void __init kernel_init_freeable(void)
79128 do_basic_setup();
79129
79130 /* Open the /dev/console on the rootfs, this should never fail */
79131- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
79132+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
79133 pr_err("Warning: unable to open an initial console.\n");
79134
79135 (void) sys_dup(0);
79136@@ -896,11 +965,13 @@ static noinline void __init kernel_init_freeable(void)
79137 if (!ramdisk_execute_command)
79138 ramdisk_execute_command = "/init";
79139
79140- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
79141+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
79142 ramdisk_execute_command = NULL;
79143 prepare_namespace();
79144 }
79145
79146+ grsecurity_init();
79147+
79148 /*
79149 * Ok, we have completed the initial bootup, and
79150 * we're essentially up and running. Get rid of the
79151diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
79152index 130dfec..cc88451 100644
79153--- a/ipc/ipc_sysctl.c
79154+++ b/ipc/ipc_sysctl.c
79155@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
79156 static int proc_ipc_dointvec(ctl_table *table, int write,
79157 void __user *buffer, size_t *lenp, loff_t *ppos)
79158 {
79159- struct ctl_table ipc_table;
79160+ ctl_table_no_const ipc_table;
79161
79162 memcpy(&ipc_table, table, sizeof(ipc_table));
79163 ipc_table.data = get_ipc(table);
79164@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
79165 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
79166 void __user *buffer, size_t *lenp, loff_t *ppos)
79167 {
79168- struct ctl_table ipc_table;
79169+ ctl_table_no_const ipc_table;
79170
79171 memcpy(&ipc_table, table, sizeof(ipc_table));
79172 ipc_table.data = get_ipc(table);
79173@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
79174 static int proc_ipc_callback_dointvec(ctl_table *table, int write,
79175 void __user *buffer, size_t *lenp, loff_t *ppos)
79176 {
79177- struct ctl_table ipc_table;
79178+ ctl_table_no_const ipc_table;
79179 size_t lenp_bef = *lenp;
79180 int rc;
79181
79182@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec(ctl_table *table, int write,
79183 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
79184 void __user *buffer, size_t *lenp, loff_t *ppos)
79185 {
79186- struct ctl_table ipc_table;
79187+ ctl_table_no_const ipc_table;
79188 memcpy(&ipc_table, table, sizeof(ipc_table));
79189 ipc_table.data = get_ipc(table);
79190
79191@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
79192 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
79193 void __user *buffer, size_t *lenp, loff_t *ppos)
79194 {
79195- struct ctl_table ipc_table;
79196+ ctl_table_no_const ipc_table;
79197 size_t lenp_bef = *lenp;
79198 int oldval;
79199 int rc;
79200diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
79201index 383d638..943fdbb 100644
79202--- a/ipc/mq_sysctl.c
79203+++ b/ipc/mq_sysctl.c
79204@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
79205 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
79206 void __user *buffer, size_t *lenp, loff_t *ppos)
79207 {
79208- struct ctl_table mq_table;
79209+ ctl_table_no_const mq_table;
79210 memcpy(&mq_table, table, sizeof(mq_table));
79211 mq_table.data = get_mq(table);
79212
79213diff --git a/ipc/mqueue.c b/ipc/mqueue.c
79214index ae1996d..a35f2cc 100644
79215--- a/ipc/mqueue.c
79216+++ b/ipc/mqueue.c
79217@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
79218 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
79219 info->attr.mq_msgsize);
79220
79221+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
79222 spin_lock(&mq_lock);
79223 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
79224 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
79225diff --git a/ipc/msg.c b/ipc/msg.c
79226index 558aa91..359e718 100644
79227--- a/ipc/msg.c
79228+++ b/ipc/msg.c
79229@@ -297,18 +297,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
79230 return security_msg_queue_associate(msq, msgflg);
79231 }
79232
79233+static struct ipc_ops msg_ops = {
79234+ .getnew = newque,
79235+ .associate = msg_security,
79236+ .more_checks = NULL
79237+};
79238+
79239 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
79240 {
79241 struct ipc_namespace *ns;
79242- struct ipc_ops msg_ops;
79243 struct ipc_params msg_params;
79244
79245 ns = current->nsproxy->ipc_ns;
79246
79247- msg_ops.getnew = newque;
79248- msg_ops.associate = msg_security;
79249- msg_ops.more_checks = NULL;
79250-
79251 msg_params.key = key;
79252 msg_params.flg = msgflg;
79253
79254diff --git a/ipc/sem.c b/ipc/sem.c
79255index 8e2bf30..a711151 100644
79256--- a/ipc/sem.c
79257+++ b/ipc/sem.c
79258@@ -562,10 +562,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
79259 return 0;
79260 }
79261
79262+static struct ipc_ops sem_ops = {
79263+ .getnew = newary,
79264+ .associate = sem_security,
79265+ .more_checks = sem_more_checks
79266+};
79267+
79268 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
79269 {
79270 struct ipc_namespace *ns;
79271- struct ipc_ops sem_ops;
79272 struct ipc_params sem_params;
79273
79274 ns = current->nsproxy->ipc_ns;
79275@@ -573,10 +578,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
79276 if (nsems < 0 || nsems > ns->sc_semmsl)
79277 return -EINVAL;
79278
79279- sem_ops.getnew = newary;
79280- sem_ops.associate = sem_security;
79281- sem_ops.more_checks = sem_more_checks;
79282-
79283 sem_params.key = key;
79284 sem_params.flg = semflg;
79285 sem_params.u.nsems = nsems;
79286diff --git a/ipc/shm.c b/ipc/shm.c
79287index d697396..40e887d 100644
79288--- a/ipc/shm.c
79289+++ b/ipc/shm.c
79290@@ -72,6 +72,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
79291 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
79292 #endif
79293
79294+#ifdef CONFIG_GRKERNSEC
79295+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
79296+ const time_t shm_createtime, const kuid_t cuid,
79297+ const int shmid);
79298+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
79299+ const time_t shm_createtime);
79300+#endif
79301+
79302 void shm_init_ns(struct ipc_namespace *ns)
79303 {
79304 ns->shm_ctlmax = SHMMAX;
79305@@ -551,6 +559,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
79306 shp->shm_lprid = 0;
79307 shp->shm_atim = shp->shm_dtim = 0;
79308 shp->shm_ctim = get_seconds();
79309+#ifdef CONFIG_GRKERNSEC
79310+ {
79311+ struct timespec timeval;
79312+ do_posix_clock_monotonic_gettime(&timeval);
79313+
79314+ shp->shm_createtime = timeval.tv_sec;
79315+ }
79316+#endif
79317 shp->shm_segsz = size;
79318 shp->shm_nattch = 0;
79319 shp->shm_file = file;
79320@@ -604,18 +620,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
79321 return 0;
79322 }
79323
79324+static struct ipc_ops shm_ops = {
79325+ .getnew = newseg,
79326+ .associate = shm_security,
79327+ .more_checks = shm_more_checks
79328+};
79329+
79330 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
79331 {
79332 struct ipc_namespace *ns;
79333- struct ipc_ops shm_ops;
79334 struct ipc_params shm_params;
79335
79336 ns = current->nsproxy->ipc_ns;
79337
79338- shm_ops.getnew = newseg;
79339- shm_ops.associate = shm_security;
79340- shm_ops.more_checks = shm_more_checks;
79341-
79342 shm_params.key = key;
79343 shm_params.flg = shmflg;
79344 shm_params.u.size = size;
79345@@ -1076,6 +1093,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
79346 f_mode = FMODE_READ | FMODE_WRITE;
79347 }
79348 if (shmflg & SHM_EXEC) {
79349+
79350+#ifdef CONFIG_PAX_MPROTECT
79351+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
79352+ goto out;
79353+#endif
79354+
79355 prot |= PROT_EXEC;
79356 acc_mode |= S_IXUGO;
79357 }
79358@@ -1100,10 +1123,22 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
79359 if (err)
79360 goto out_unlock;
79361
79362+#ifdef CONFIG_GRKERNSEC
79363+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
79364+ shp->shm_perm.cuid, shmid) ||
79365+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
79366+ err = -EACCES;
79367+ goto out_unlock;
79368+ }
79369+#endif
79370+
79371 ipc_lock_object(&shp->shm_perm);
79372 path = shp->shm_file->f_path;
79373 path_get(&path);
79374 shp->shm_nattch++;
79375+#ifdef CONFIG_GRKERNSEC
79376+ shp->shm_lapid = current->pid;
79377+#endif
79378 size = i_size_read(path.dentry->d_inode);
79379 ipc_unlock_object(&shp->shm_perm);
79380 rcu_read_unlock();
79381diff --git a/kernel/acct.c b/kernel/acct.c
79382index 8d6e145..33e0b1e 100644
79383--- a/kernel/acct.c
79384+++ b/kernel/acct.c
79385@@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
79386 */
79387 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
79388 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
79389- file->f_op->write(file, (char *)&ac,
79390+ file->f_op->write(file, (char __force_user *)&ac,
79391 sizeof(acct_t), &file->f_pos);
79392 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
79393 set_fs(fs);
79394diff --git a/kernel/audit.c b/kernel/audit.c
79395index 7b0e23a..5b27ab9 100644
79396--- a/kernel/audit.c
79397+++ b/kernel/audit.c
79398@@ -118,7 +118,7 @@ u32 audit_sig_sid = 0;
79399 3) suppressed due to audit_rate_limit
79400 4) suppressed due to audit_backlog_limit
79401 */
79402-static atomic_t audit_lost = ATOMIC_INIT(0);
79403+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
79404
79405 /* The netlink socket. */
79406 static struct sock *audit_sock;
79407@@ -240,7 +240,7 @@ void audit_log_lost(const char *message)
79408 unsigned long now;
79409 int print;
79410
79411- atomic_inc(&audit_lost);
79412+ atomic_inc_unchecked(&audit_lost);
79413
79414 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
79415
79416@@ -259,7 +259,7 @@ void audit_log_lost(const char *message)
79417 printk(KERN_WARNING
79418 "audit: audit_lost=%d audit_rate_limit=%d "
79419 "audit_backlog_limit=%d\n",
79420- atomic_read(&audit_lost),
79421+ atomic_read_unchecked(&audit_lost),
79422 audit_rate_limit,
79423 audit_backlog_limit);
79424 audit_panic(message);
79425@@ -659,18 +659,19 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
79426
79427 switch (msg_type) {
79428 case AUDIT_GET:
79429+ status_set.mask = 0;
79430 status_set.enabled = audit_enabled;
79431 status_set.failure = audit_failure;
79432 status_set.pid = audit_pid;
79433 status_set.rate_limit = audit_rate_limit;
79434 status_set.backlog_limit = audit_backlog_limit;
79435- status_set.lost = atomic_read(&audit_lost);
79436+ status_set.lost = atomic_read_unchecked(&audit_lost);
79437 status_set.backlog = skb_queue_len(&audit_skb_queue);
79438 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
79439 &status_set, sizeof(status_set));
79440 break;
79441 case AUDIT_SET:
79442- if (nlh->nlmsg_len < sizeof(struct audit_status))
79443+ if (nlmsg_len(nlh) < sizeof(struct audit_status))
79444 return -EINVAL;
79445 status_get = (struct audit_status *)data;
79446 if (status_get->mask & AUDIT_STATUS_ENABLED) {
79447@@ -832,7 +833,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
79448
79449 memset(&s, 0, sizeof(s));
79450 /* guard against past and future API changes */
79451- memcpy(&s, data, min(sizeof(s), (size_t)nlh->nlmsg_len));
79452+ memcpy(&s, data, min_t(size_t, sizeof(s), nlmsg_len(nlh)));
79453 if ((s.enabled != 0 && s.enabled != 1) ||
79454 (s.log_passwd != 0 && s.log_passwd != 1))
79455 return -EINVAL;
79456diff --git a/kernel/auditsc.c b/kernel/auditsc.c
79457index 9845cb3..3ec9369 100644
79458--- a/kernel/auditsc.c
79459+++ b/kernel/auditsc.c
79460@@ -1962,7 +1962,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
79461 }
79462
79463 /* global counter which is incremented every time something logs in */
79464-static atomic_t session_id = ATOMIC_INIT(0);
79465+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
79466
79467 /**
79468 * audit_set_loginuid - set current task's audit_context loginuid
79469@@ -1986,7 +1986,7 @@ int audit_set_loginuid(kuid_t loginuid)
79470 return -EPERM;
79471 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
79472
79473- sessionid = atomic_inc_return(&session_id);
79474+ sessionid = atomic_inc_return_unchecked(&session_id);
79475 if (context && context->in_syscall) {
79476 struct audit_buffer *ab;
79477
79478diff --git a/kernel/capability.c b/kernel/capability.c
79479index f6c2ce5..982c0f9 100644
79480--- a/kernel/capability.c
79481+++ b/kernel/capability.c
79482@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
79483 * before modification is attempted and the application
79484 * fails.
79485 */
79486+ if (tocopy > ARRAY_SIZE(kdata))
79487+ return -EFAULT;
79488+
79489 if (copy_to_user(dataptr, kdata, tocopy
79490 * sizeof(struct __user_cap_data_struct))) {
79491 return -EFAULT;
79492@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
79493 int ret;
79494
79495 rcu_read_lock();
79496- ret = security_capable(__task_cred(t), ns, cap);
79497+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
79498+ gr_task_is_capable(t, __task_cred(t), cap);
79499 rcu_read_unlock();
79500
79501- return (ret == 0);
79502+ return ret;
79503 }
79504
79505 /**
79506@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
79507 int ret;
79508
79509 rcu_read_lock();
79510- ret = security_capable_noaudit(__task_cred(t), ns, cap);
79511+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
79512 rcu_read_unlock();
79513
79514- return (ret == 0);
79515+ return ret;
79516 }
79517
79518 /**
79519@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
79520 BUG();
79521 }
79522
79523- if (security_capable(current_cred(), ns, cap) == 0) {
79524+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
79525 current->flags |= PF_SUPERPRIV;
79526 return true;
79527 }
79528@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
79529 }
79530 EXPORT_SYMBOL(ns_capable);
79531
79532+bool ns_capable_nolog(struct user_namespace *ns, int cap)
79533+{
79534+ if (unlikely(!cap_valid(cap))) {
79535+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
79536+ BUG();
79537+ }
79538+
79539+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
79540+ current->flags |= PF_SUPERPRIV;
79541+ return true;
79542+ }
79543+ return false;
79544+}
79545+EXPORT_SYMBOL(ns_capable_nolog);
79546+
79547 /**
79548 * file_ns_capable - Determine if the file's opener had a capability in effect
79549 * @file: The file we want to check
79550@@ -432,6 +451,12 @@ bool capable(int cap)
79551 }
79552 EXPORT_SYMBOL(capable);
79553
79554+bool capable_nolog(int cap)
79555+{
79556+ return ns_capable_nolog(&init_user_ns, cap);
79557+}
79558+EXPORT_SYMBOL(capable_nolog);
79559+
79560 /**
79561 * nsown_capable - Check superior capability to one's own user_ns
79562 * @cap: The capability in question
79563@@ -464,3 +489,10 @@ bool inode_capable(const struct inode *inode, int cap)
79564
79565 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
79566 }
79567+
79568+bool inode_capable_nolog(const struct inode *inode, int cap)
79569+{
79570+ struct user_namespace *ns = current_user_ns();
79571+
79572+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
79573+}
79574diff --git a/kernel/cgroup.c b/kernel/cgroup.c
79575index e919633..f46b08f 100644
79576--- a/kernel/cgroup.c
79577+++ b/kernel/cgroup.c
79578@@ -5623,7 +5623,7 @@ static int cgroup_css_links_read(struct cgroup *cgrp,
79579 struct css_set *cset = link->cset;
79580 struct task_struct *task;
79581 int count = 0;
79582- seq_printf(seq, "css_set %p\n", cset);
79583+ seq_printf(seq, "css_set %pK\n", cset);
79584 list_for_each_entry(task, &cset->tasks, cg_list) {
79585 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
79586 seq_puts(seq, " ...\n");
79587diff --git a/kernel/compat.c b/kernel/compat.c
79588index 0a09e48..f44f3f0 100644
79589--- a/kernel/compat.c
79590+++ b/kernel/compat.c
79591@@ -13,6 +13,7 @@
79592
79593 #include <linux/linkage.h>
79594 #include <linux/compat.h>
79595+#include <linux/module.h>
79596 #include <linux/errno.h>
79597 #include <linux/time.h>
79598 #include <linux/signal.h>
79599@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
79600 mm_segment_t oldfs;
79601 long ret;
79602
79603- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
79604+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
79605 oldfs = get_fs();
79606 set_fs(KERNEL_DS);
79607 ret = hrtimer_nanosleep_restart(restart);
79608@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
79609 oldfs = get_fs();
79610 set_fs(KERNEL_DS);
79611 ret = hrtimer_nanosleep(&tu,
79612- rmtp ? (struct timespec __user *)&rmt : NULL,
79613+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
79614 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
79615 set_fs(oldfs);
79616
79617@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
79618 mm_segment_t old_fs = get_fs();
79619
79620 set_fs(KERNEL_DS);
79621- ret = sys_sigpending((old_sigset_t __user *) &s);
79622+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
79623 set_fs(old_fs);
79624 if (ret == 0)
79625 ret = put_user(s, set);
79626@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
79627 mm_segment_t old_fs = get_fs();
79628
79629 set_fs(KERNEL_DS);
79630- ret = sys_old_getrlimit(resource, &r);
79631+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
79632 set_fs(old_fs);
79633
79634 if (!ret) {
79635@@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
79636 set_fs (KERNEL_DS);
79637 ret = sys_wait4(pid,
79638 (stat_addr ?
79639- (unsigned int __user *) &status : NULL),
79640- options, (struct rusage __user *) &r);
79641+ (unsigned int __force_user *) &status : NULL),
79642+ options, (struct rusage __force_user *) &r);
79643 set_fs (old_fs);
79644
79645 if (ret > 0) {
79646@@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
79647 memset(&info, 0, sizeof(info));
79648
79649 set_fs(KERNEL_DS);
79650- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
79651- uru ? (struct rusage __user *)&ru : NULL);
79652+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
79653+ uru ? (struct rusage __force_user *)&ru : NULL);
79654 set_fs(old_fs);
79655
79656 if ((ret < 0) || (info.si_signo == 0))
79657@@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
79658 oldfs = get_fs();
79659 set_fs(KERNEL_DS);
79660 err = sys_timer_settime(timer_id, flags,
79661- (struct itimerspec __user *) &newts,
79662- (struct itimerspec __user *) &oldts);
79663+ (struct itimerspec __force_user *) &newts,
79664+ (struct itimerspec __force_user *) &oldts);
79665 set_fs(oldfs);
79666 if (!err && old && put_compat_itimerspec(old, &oldts))
79667 return -EFAULT;
79668@@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
79669 oldfs = get_fs();
79670 set_fs(KERNEL_DS);
79671 err = sys_timer_gettime(timer_id,
79672- (struct itimerspec __user *) &ts);
79673+ (struct itimerspec __force_user *) &ts);
79674 set_fs(oldfs);
79675 if (!err && put_compat_itimerspec(setting, &ts))
79676 return -EFAULT;
79677@@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
79678 oldfs = get_fs();
79679 set_fs(KERNEL_DS);
79680 err = sys_clock_settime(which_clock,
79681- (struct timespec __user *) &ts);
79682+ (struct timespec __force_user *) &ts);
79683 set_fs(oldfs);
79684 return err;
79685 }
79686@@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
79687 oldfs = get_fs();
79688 set_fs(KERNEL_DS);
79689 err = sys_clock_gettime(which_clock,
79690- (struct timespec __user *) &ts);
79691+ (struct timespec __force_user *) &ts);
79692 set_fs(oldfs);
79693 if (!err && put_compat_timespec(&ts, tp))
79694 return -EFAULT;
79695@@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
79696
79697 oldfs = get_fs();
79698 set_fs(KERNEL_DS);
79699- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
79700+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
79701 set_fs(oldfs);
79702
79703 err = compat_put_timex(utp, &txc);
79704@@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
79705 oldfs = get_fs();
79706 set_fs(KERNEL_DS);
79707 err = sys_clock_getres(which_clock,
79708- (struct timespec __user *) &ts);
79709+ (struct timespec __force_user *) &ts);
79710 set_fs(oldfs);
79711 if (!err && tp && put_compat_timespec(&ts, tp))
79712 return -EFAULT;
79713@@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
79714 long err;
79715 mm_segment_t oldfs;
79716 struct timespec tu;
79717- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
79718+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
79719
79720- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
79721+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
79722 oldfs = get_fs();
79723 set_fs(KERNEL_DS);
79724 err = clock_nanosleep_restart(restart);
79725@@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
79726 oldfs = get_fs();
79727 set_fs(KERNEL_DS);
79728 err = sys_clock_nanosleep(which_clock, flags,
79729- (struct timespec __user *) &in,
79730- (struct timespec __user *) &out);
79731+ (struct timespec __force_user *) &in,
79732+ (struct timespec __force_user *) &out);
79733 set_fs(oldfs);
79734
79735 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
79736diff --git a/kernel/configs.c b/kernel/configs.c
79737index c18b1f1..b9a0132 100644
79738--- a/kernel/configs.c
79739+++ b/kernel/configs.c
79740@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
79741 struct proc_dir_entry *entry;
79742
79743 /* create the current config file */
79744+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
79745+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
79746+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
79747+ &ikconfig_file_ops);
79748+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
79749+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
79750+ &ikconfig_file_ops);
79751+#endif
79752+#else
79753 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
79754 &ikconfig_file_ops);
79755+#endif
79756+
79757 if (!entry)
79758 return -ENOMEM;
79759
79760diff --git a/kernel/cred.c b/kernel/cred.c
79761index e0573a4..3874e41 100644
79762--- a/kernel/cred.c
79763+++ b/kernel/cred.c
79764@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
79765 validate_creds(cred);
79766 alter_cred_subscribers(cred, -1);
79767 put_cred(cred);
79768+
79769+#ifdef CONFIG_GRKERNSEC_SETXID
79770+ cred = (struct cred *) tsk->delayed_cred;
79771+ if (cred != NULL) {
79772+ tsk->delayed_cred = NULL;
79773+ validate_creds(cred);
79774+ alter_cred_subscribers(cred, -1);
79775+ put_cred(cred);
79776+ }
79777+#endif
79778 }
79779
79780 /**
79781@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
79782 * Always returns 0 thus allowing this function to be tail-called at the end
79783 * of, say, sys_setgid().
79784 */
79785-int commit_creds(struct cred *new)
79786+static int __commit_creds(struct cred *new)
79787 {
79788 struct task_struct *task = current;
79789 const struct cred *old = task->real_cred;
79790@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
79791
79792 get_cred(new); /* we will require a ref for the subj creds too */
79793
79794+ gr_set_role_label(task, new->uid, new->gid);
79795+
79796 /* dumpability changes */
79797 if (!uid_eq(old->euid, new->euid) ||
79798 !gid_eq(old->egid, new->egid) ||
79799@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
79800 put_cred(old);
79801 return 0;
79802 }
79803+#ifdef CONFIG_GRKERNSEC_SETXID
79804+extern int set_user(struct cred *new);
79805+
79806+void gr_delayed_cred_worker(void)
79807+{
79808+ const struct cred *new = current->delayed_cred;
79809+ struct cred *ncred;
79810+
79811+ current->delayed_cred = NULL;
79812+
79813+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
79814+ // from doing get_cred on it when queueing this
79815+ put_cred(new);
79816+ return;
79817+ } else if (new == NULL)
79818+ return;
79819+
79820+ ncred = prepare_creds();
79821+ if (!ncred)
79822+ goto die;
79823+ // uids
79824+ ncred->uid = new->uid;
79825+ ncred->euid = new->euid;
79826+ ncred->suid = new->suid;
79827+ ncred->fsuid = new->fsuid;
79828+ // gids
79829+ ncred->gid = new->gid;
79830+ ncred->egid = new->egid;
79831+ ncred->sgid = new->sgid;
79832+ ncred->fsgid = new->fsgid;
79833+ // groups
79834+ if (set_groups(ncred, new->group_info) < 0) {
79835+ abort_creds(ncred);
79836+ goto die;
79837+ }
79838+ // caps
79839+ ncred->securebits = new->securebits;
79840+ ncred->cap_inheritable = new->cap_inheritable;
79841+ ncred->cap_permitted = new->cap_permitted;
79842+ ncred->cap_effective = new->cap_effective;
79843+ ncred->cap_bset = new->cap_bset;
79844+
79845+ if (set_user(ncred)) {
79846+ abort_creds(ncred);
79847+ goto die;
79848+ }
79849+
79850+ // from doing get_cred on it when queueing this
79851+ put_cred(new);
79852+
79853+ __commit_creds(ncred);
79854+ return;
79855+die:
79856+ // from doing get_cred on it when queueing this
79857+ put_cred(new);
79858+ do_group_exit(SIGKILL);
79859+}
79860+#endif
79861+
79862+int commit_creds(struct cred *new)
79863+{
79864+#ifdef CONFIG_GRKERNSEC_SETXID
79865+ int ret;
79866+ int schedule_it = 0;
79867+ struct task_struct *t;
79868+
79869+ /* we won't get called with tasklist_lock held for writing
79870+ and interrupts disabled as the cred struct in that case is
79871+ init_cred
79872+ */
79873+ if (grsec_enable_setxid && !current_is_single_threaded() &&
79874+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
79875+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
79876+ schedule_it = 1;
79877+ }
79878+ ret = __commit_creds(new);
79879+ if (schedule_it) {
79880+ rcu_read_lock();
79881+ read_lock(&tasklist_lock);
79882+ for (t = next_thread(current); t != current;
79883+ t = next_thread(t)) {
79884+ if (t->delayed_cred == NULL) {
79885+ t->delayed_cred = get_cred(new);
79886+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
79887+ set_tsk_need_resched(t);
79888+ }
79889+ }
79890+ read_unlock(&tasklist_lock);
79891+ rcu_read_unlock();
79892+ }
79893+ return ret;
79894+#else
79895+ return __commit_creds(new);
79896+#endif
79897+}
79898+
79899 EXPORT_SYMBOL(commit_creds);
79900
79901 /**
79902diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
79903index 0506d44..2c20034 100644
79904--- a/kernel/debug/debug_core.c
79905+++ b/kernel/debug/debug_core.c
79906@@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
79907 */
79908 static atomic_t masters_in_kgdb;
79909 static atomic_t slaves_in_kgdb;
79910-static atomic_t kgdb_break_tasklet_var;
79911+static atomic_unchecked_t kgdb_break_tasklet_var;
79912 atomic_t kgdb_setting_breakpoint;
79913
79914 struct task_struct *kgdb_usethread;
79915@@ -133,7 +133,7 @@ int kgdb_single_step;
79916 static pid_t kgdb_sstep_pid;
79917
79918 /* to keep track of the CPU which is doing the single stepping*/
79919-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
79920+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
79921
79922 /*
79923 * If you are debugging a problem where roundup (the collection of
79924@@ -541,7 +541,7 @@ return_normal:
79925 * kernel will only try for the value of sstep_tries before
79926 * giving up and continuing on.
79927 */
79928- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
79929+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
79930 (kgdb_info[cpu].task &&
79931 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
79932 atomic_set(&kgdb_active, -1);
79933@@ -635,8 +635,8 @@ cpu_master_loop:
79934 }
79935
79936 kgdb_restore:
79937- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
79938- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
79939+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
79940+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
79941 if (kgdb_info[sstep_cpu].task)
79942 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
79943 else
79944@@ -888,18 +888,18 @@ static void kgdb_unregister_callbacks(void)
79945 static void kgdb_tasklet_bpt(unsigned long ing)
79946 {
79947 kgdb_breakpoint();
79948- atomic_set(&kgdb_break_tasklet_var, 0);
79949+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
79950 }
79951
79952 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
79953
79954 void kgdb_schedule_breakpoint(void)
79955 {
79956- if (atomic_read(&kgdb_break_tasklet_var) ||
79957+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
79958 atomic_read(&kgdb_active) != -1 ||
79959 atomic_read(&kgdb_setting_breakpoint))
79960 return;
79961- atomic_inc(&kgdb_break_tasklet_var);
79962+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
79963 tasklet_schedule(&kgdb_tasklet_breakpoint);
79964 }
79965 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
79966diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
79967index 00eb8f7..d7e3244 100644
79968--- a/kernel/debug/kdb/kdb_main.c
79969+++ b/kernel/debug/kdb/kdb_main.c
79970@@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
79971 continue;
79972
79973 kdb_printf("%-20s%8u 0x%p ", mod->name,
79974- mod->core_size, (void *)mod);
79975+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
79976 #ifdef CONFIG_MODULE_UNLOAD
79977 kdb_printf("%4ld ", module_refcount(mod));
79978 #endif
79979@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
79980 kdb_printf(" (Loading)");
79981 else
79982 kdb_printf(" (Live)");
79983- kdb_printf(" 0x%p", mod->module_core);
79984+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
79985
79986 #ifdef CONFIG_MODULE_UNLOAD
79987 {
79988diff --git a/kernel/events/core.c b/kernel/events/core.c
79989index f86599e..b18b180 100644
79990--- a/kernel/events/core.c
79991+++ b/kernel/events/core.c
79992@@ -156,8 +156,15 @@ static struct srcu_struct pmus_srcu;
79993 * 0 - disallow raw tracepoint access for unpriv
79994 * 1 - disallow cpu events for unpriv
79995 * 2 - disallow kernel profiling for unpriv
79996+ * 3 - disallow all unpriv perf event use
79997 */
79998-int sysctl_perf_event_paranoid __read_mostly = 1;
79999+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
80000+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
80001+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
80002+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
80003+#else
80004+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
80005+#endif
80006
80007 /* Minimum for 512 kiB + 1 user control page */
80008 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
80009@@ -270,7 +277,7 @@ void perf_sample_event_took(u64 sample_len_ns)
80010 update_perf_cpu_limits();
80011 }
80012
80013-static atomic64_t perf_event_id;
80014+static atomic64_unchecked_t perf_event_id;
80015
80016 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
80017 enum event_type_t event_type);
80018@@ -2936,7 +2943,7 @@ static void __perf_event_read(void *info)
80019
80020 static inline u64 perf_event_count(struct perf_event *event)
80021 {
80022- return local64_read(&event->count) + atomic64_read(&event->child_count);
80023+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
80024 }
80025
80026 static u64 perf_event_read(struct perf_event *event)
80027@@ -3282,9 +3289,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
80028 mutex_lock(&event->child_mutex);
80029 total += perf_event_read(event);
80030 *enabled += event->total_time_enabled +
80031- atomic64_read(&event->child_total_time_enabled);
80032+ atomic64_read_unchecked(&event->child_total_time_enabled);
80033 *running += event->total_time_running +
80034- atomic64_read(&event->child_total_time_running);
80035+ atomic64_read_unchecked(&event->child_total_time_running);
80036
80037 list_for_each_entry(child, &event->child_list, child_list) {
80038 total += perf_event_read(child);
80039@@ -3670,10 +3677,10 @@ void perf_event_update_userpage(struct perf_event *event)
80040 userpg->offset -= local64_read(&event->hw.prev_count);
80041
80042 userpg->time_enabled = enabled +
80043- atomic64_read(&event->child_total_time_enabled);
80044+ atomic64_read_unchecked(&event->child_total_time_enabled);
80045
80046 userpg->time_running = running +
80047- atomic64_read(&event->child_total_time_running);
80048+ atomic64_read_unchecked(&event->child_total_time_running);
80049
80050 arch_perf_update_userpage(userpg, now);
80051
80052@@ -4223,7 +4230,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
80053
80054 /* Data. */
80055 sp = perf_user_stack_pointer(regs);
80056- rem = __output_copy_user(handle, (void *) sp, dump_size);
80057+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
80058 dyn_size = dump_size - rem;
80059
80060 perf_output_skip(handle, rem);
80061@@ -4311,11 +4318,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
80062 values[n++] = perf_event_count(event);
80063 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
80064 values[n++] = enabled +
80065- atomic64_read(&event->child_total_time_enabled);
80066+ atomic64_read_unchecked(&event->child_total_time_enabled);
80067 }
80068 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
80069 values[n++] = running +
80070- atomic64_read(&event->child_total_time_running);
80071+ atomic64_read_unchecked(&event->child_total_time_running);
80072 }
80073 if (read_format & PERF_FORMAT_ID)
80074 values[n++] = primary_event_id(event);
80075@@ -5024,12 +5031,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
80076 * need to add enough zero bytes after the string to handle
80077 * the 64bit alignment we do later.
80078 */
80079- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
80080+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
80081 if (!buf) {
80082 name = strncpy(tmp, "//enomem", sizeof(tmp));
80083 goto got_name;
80084 }
80085- name = d_path(&file->f_path, buf, PATH_MAX);
80086+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
80087 if (IS_ERR(name)) {
80088 name = strncpy(tmp, "//toolong", sizeof(tmp));
80089 goto got_name;
80090@@ -6498,7 +6505,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
80091 event->parent = parent_event;
80092
80093 event->ns = get_pid_ns(task_active_pid_ns(current));
80094- event->id = atomic64_inc_return(&perf_event_id);
80095+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
80096
80097 event->state = PERF_EVENT_STATE_INACTIVE;
80098
80099@@ -6807,6 +6814,11 @@ SYSCALL_DEFINE5(perf_event_open,
80100 if (flags & ~PERF_FLAG_ALL)
80101 return -EINVAL;
80102
80103+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
80104+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
80105+ return -EACCES;
80106+#endif
80107+
80108 err = perf_copy_attr(attr_uptr, &attr);
80109 if (err)
80110 return err;
80111@@ -7139,10 +7151,10 @@ static void sync_child_event(struct perf_event *child_event,
80112 /*
80113 * Add back the child's count to the parent's count:
80114 */
80115- atomic64_add(child_val, &parent_event->child_count);
80116- atomic64_add(child_event->total_time_enabled,
80117+ atomic64_add_unchecked(child_val, &parent_event->child_count);
80118+ atomic64_add_unchecked(child_event->total_time_enabled,
80119 &parent_event->child_total_time_enabled);
80120- atomic64_add(child_event->total_time_running,
80121+ atomic64_add_unchecked(child_event->total_time_running,
80122 &parent_event->child_total_time_running);
80123
80124 /*
80125diff --git a/kernel/events/internal.h b/kernel/events/internal.h
80126index ca65997..60df03d 100644
80127--- a/kernel/events/internal.h
80128+++ b/kernel/events/internal.h
80129@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
80130 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
80131 }
80132
80133-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
80134-static inline unsigned int \
80135+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
80136+static inline unsigned long \
80137 func_name(struct perf_output_handle *handle, \
80138- const void *buf, unsigned int len) \
80139+ const void user *buf, unsigned long len) \
80140 { \
80141 unsigned long size, written; \
80142 \
80143@@ -116,17 +116,17 @@ static inline int memcpy_common(void *dst, const void *src, size_t n)
80144 return n;
80145 }
80146
80147-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
80148+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
80149
80150 #define MEMCPY_SKIP(dst, src, n) (n)
80151
80152-DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP)
80153+DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP, )
80154
80155 #ifndef arch_perf_out_copy_user
80156 #define arch_perf_out_copy_user __copy_from_user_inatomic
80157 #endif
80158
80159-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
80160+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
80161
80162 /* Callchain handling */
80163 extern struct perf_callchain_entry *
80164diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
80165index ad8e1bd..fed7ba9 100644
80166--- a/kernel/events/uprobes.c
80167+++ b/kernel/events/uprobes.c
80168@@ -1556,7 +1556,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
80169 {
80170 struct page *page;
80171 uprobe_opcode_t opcode;
80172- int result;
80173+ long result;
80174
80175 pagefault_disable();
80176 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
80177diff --git a/kernel/exit.c b/kernel/exit.c
80178index a949819..a5f127d 100644
80179--- a/kernel/exit.c
80180+++ b/kernel/exit.c
80181@@ -172,6 +172,10 @@ void release_task(struct task_struct * p)
80182 struct task_struct *leader;
80183 int zap_leader;
80184 repeat:
80185+#ifdef CONFIG_NET
80186+ gr_del_task_from_ip_table(p);
80187+#endif
80188+
80189 /* don't need to get the RCU readlock here - the process is dead and
80190 * can't be modifying its own credentials. But shut RCU-lockdep up */
80191 rcu_read_lock();
80192@@ -329,7 +333,7 @@ int allow_signal(int sig)
80193 * know it'll be handled, so that they don't get converted to
80194 * SIGKILL or just silently dropped.
80195 */
80196- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
80197+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
80198 recalc_sigpending();
80199 spin_unlock_irq(&current->sighand->siglock);
80200 return 0;
80201@@ -698,6 +702,8 @@ void do_exit(long code)
80202 struct task_struct *tsk = current;
80203 int group_dead;
80204
80205+ set_fs(USER_DS);
80206+
80207 profile_task_exit(tsk);
80208
80209 WARN_ON(blk_needs_flush_plug(tsk));
80210@@ -714,7 +720,6 @@ void do_exit(long code)
80211 * mm_release()->clear_child_tid() from writing to a user-controlled
80212 * kernel address.
80213 */
80214- set_fs(USER_DS);
80215
80216 ptrace_event(PTRACE_EVENT_EXIT, code);
80217
80218@@ -773,6 +778,9 @@ void do_exit(long code)
80219 tsk->exit_code = code;
80220 taskstats_exit(tsk, group_dead);
80221
80222+ gr_acl_handle_psacct(tsk, code);
80223+ gr_acl_handle_exit();
80224+
80225 exit_mm(tsk);
80226
80227 if (group_dead)
80228@@ -894,7 +902,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
80229 * Take down every thread in the group. This is called by fatal signals
80230 * as well as by sys_exit_group (below).
80231 */
80232-void
80233+__noreturn void
80234 do_group_exit(int exit_code)
80235 {
80236 struct signal_struct *sig = current->signal;
80237diff --git a/kernel/fork.c b/kernel/fork.c
80238index 200a7a2..43e52da 100644
80239--- a/kernel/fork.c
80240+++ b/kernel/fork.c
80241@@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
80242 *stackend = STACK_END_MAGIC; /* for overflow detection */
80243
80244 #ifdef CONFIG_CC_STACKPROTECTOR
80245- tsk->stack_canary = get_random_int();
80246+ tsk->stack_canary = pax_get_random_long();
80247 #endif
80248
80249 /*
80250@@ -345,13 +345,81 @@ free_tsk:
80251 }
80252
80253 #ifdef CONFIG_MMU
80254-static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80255+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
80256 {
80257- struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
80258- struct rb_node **rb_link, *rb_parent;
80259- int retval;
80260+ struct vm_area_struct *tmp;
80261 unsigned long charge;
80262 struct mempolicy *pol;
80263+ struct file *file;
80264+
80265+ charge = 0;
80266+ if (mpnt->vm_flags & VM_ACCOUNT) {
80267+ unsigned long len = vma_pages(mpnt);
80268+
80269+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
80270+ goto fail_nomem;
80271+ charge = len;
80272+ }
80273+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
80274+ if (!tmp)
80275+ goto fail_nomem;
80276+ *tmp = *mpnt;
80277+ tmp->vm_mm = mm;
80278+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
80279+ pol = mpol_dup(vma_policy(mpnt));
80280+ if (IS_ERR(pol))
80281+ goto fail_nomem_policy;
80282+ vma_set_policy(tmp, pol);
80283+ if (anon_vma_fork(tmp, mpnt))
80284+ goto fail_nomem_anon_vma_fork;
80285+ tmp->vm_flags &= ~VM_LOCKED;
80286+ tmp->vm_next = tmp->vm_prev = NULL;
80287+ tmp->vm_mirror = NULL;
80288+ file = tmp->vm_file;
80289+ if (file) {
80290+ struct inode *inode = file_inode(file);
80291+ struct address_space *mapping = file->f_mapping;
80292+
80293+ get_file(file);
80294+ if (tmp->vm_flags & VM_DENYWRITE)
80295+ atomic_dec(&inode->i_writecount);
80296+ mutex_lock(&mapping->i_mmap_mutex);
80297+ if (tmp->vm_flags & VM_SHARED)
80298+ mapping->i_mmap_writable++;
80299+ flush_dcache_mmap_lock(mapping);
80300+ /* insert tmp into the share list, just after mpnt */
80301+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
80302+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
80303+ else
80304+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
80305+ flush_dcache_mmap_unlock(mapping);
80306+ mutex_unlock(&mapping->i_mmap_mutex);
80307+ }
80308+
80309+ /*
80310+ * Clear hugetlb-related page reserves for children. This only
80311+ * affects MAP_PRIVATE mappings. Faults generated by the child
80312+ * are not guaranteed to succeed, even if read-only
80313+ */
80314+ if (is_vm_hugetlb_page(tmp))
80315+ reset_vma_resv_huge_pages(tmp);
80316+
80317+ return tmp;
80318+
80319+fail_nomem_anon_vma_fork:
80320+ mpol_put(pol);
80321+fail_nomem_policy:
80322+ kmem_cache_free(vm_area_cachep, tmp);
80323+fail_nomem:
80324+ vm_unacct_memory(charge);
80325+ return NULL;
80326+}
80327+
80328+static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80329+{
80330+ struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
80331+ struct rb_node **rb_link, *rb_parent;
80332+ int retval;
80333
80334 uprobe_start_dup_mmap();
80335 down_write(&oldmm->mmap_sem);
80336@@ -380,57 +448,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80337
80338 prev = NULL;
80339 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
80340- struct file *file;
80341-
80342 if (mpnt->vm_flags & VM_DONTCOPY) {
80343 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
80344 -vma_pages(mpnt));
80345 continue;
80346 }
80347- charge = 0;
80348- if (mpnt->vm_flags & VM_ACCOUNT) {
80349- unsigned long len = vma_pages(mpnt);
80350-
80351- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
80352- goto fail_nomem;
80353- charge = len;
80354- }
80355- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
80356- if (!tmp)
80357- goto fail_nomem;
80358- *tmp = *mpnt;
80359- INIT_LIST_HEAD(&tmp->anon_vma_chain);
80360- pol = mpol_dup(vma_policy(mpnt));
80361- retval = PTR_ERR(pol);
80362- if (IS_ERR(pol))
80363- goto fail_nomem_policy;
80364- vma_set_policy(tmp, pol);
80365- tmp->vm_mm = mm;
80366- if (anon_vma_fork(tmp, mpnt))
80367- goto fail_nomem_anon_vma_fork;
80368- tmp->vm_flags &= ~VM_LOCKED;
80369- tmp->vm_next = tmp->vm_prev = NULL;
80370- file = tmp->vm_file;
80371- if (file) {
80372- struct inode *inode = file_inode(file);
80373- struct address_space *mapping = file->f_mapping;
80374-
80375- get_file(file);
80376- if (tmp->vm_flags & VM_DENYWRITE)
80377- atomic_dec(&inode->i_writecount);
80378- mutex_lock(&mapping->i_mmap_mutex);
80379- if (tmp->vm_flags & VM_SHARED)
80380- mapping->i_mmap_writable++;
80381- flush_dcache_mmap_lock(mapping);
80382- /* insert tmp into the share list, just after mpnt */
80383- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
80384- vma_nonlinear_insert(tmp,
80385- &mapping->i_mmap_nonlinear);
80386- else
80387- vma_interval_tree_insert_after(tmp, mpnt,
80388- &mapping->i_mmap);
80389- flush_dcache_mmap_unlock(mapping);
80390- mutex_unlock(&mapping->i_mmap_mutex);
80391+ tmp = dup_vma(mm, oldmm, mpnt);
80392+ if (!tmp) {
80393+ retval = -ENOMEM;
80394+ goto out;
80395 }
80396
80397 /*
80398@@ -462,6 +488,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80399 if (retval)
80400 goto out;
80401 }
80402+
80403+#ifdef CONFIG_PAX_SEGMEXEC
80404+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
80405+ struct vm_area_struct *mpnt_m;
80406+
80407+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
80408+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
80409+
80410+ if (!mpnt->vm_mirror)
80411+ continue;
80412+
80413+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
80414+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
80415+ mpnt->vm_mirror = mpnt_m;
80416+ } else {
80417+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
80418+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
80419+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
80420+ mpnt->vm_mirror->vm_mirror = mpnt;
80421+ }
80422+ }
80423+ BUG_ON(mpnt_m);
80424+ }
80425+#endif
80426+
80427 /* a new mm has just been created */
80428 arch_dup_mmap(oldmm, mm);
80429 retval = 0;
80430@@ -471,14 +522,6 @@ out:
80431 up_write(&oldmm->mmap_sem);
80432 uprobe_end_dup_mmap();
80433 return retval;
80434-fail_nomem_anon_vma_fork:
80435- mpol_put(pol);
80436-fail_nomem_policy:
80437- kmem_cache_free(vm_area_cachep, tmp);
80438-fail_nomem:
80439- retval = -ENOMEM;
80440- vm_unacct_memory(charge);
80441- goto out;
80442 }
80443
80444 static inline int mm_alloc_pgd(struct mm_struct *mm)
80445@@ -691,8 +734,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
80446 return ERR_PTR(err);
80447
80448 mm = get_task_mm(task);
80449- if (mm && mm != current->mm &&
80450- !ptrace_may_access(task, mode)) {
80451+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
80452+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
80453 mmput(mm);
80454 mm = ERR_PTR(-EACCES);
80455 }
80456@@ -914,13 +957,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
80457 spin_unlock(&fs->lock);
80458 return -EAGAIN;
80459 }
80460- fs->users++;
80461+ atomic_inc(&fs->users);
80462 spin_unlock(&fs->lock);
80463 return 0;
80464 }
80465 tsk->fs = copy_fs_struct(fs);
80466 if (!tsk->fs)
80467 return -ENOMEM;
80468+ /* Carry through gr_chroot_dentry and is_chrooted instead
80469+ of recomputing it here. Already copied when the task struct
80470+ is duplicated. This allows pivot_root to not be treated as
80471+ a chroot
80472+ */
80473+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
80474+
80475 return 0;
80476 }
80477
80478@@ -1131,7 +1181,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
80479 * parts of the process environment (as per the clone
80480 * flags). The actual kick-off is left to the caller.
80481 */
80482-static struct task_struct *copy_process(unsigned long clone_flags,
80483+static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
80484 unsigned long stack_start,
80485 unsigned long stack_size,
80486 int __user *child_tidptr,
80487@@ -1201,6 +1251,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
80488 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
80489 #endif
80490 retval = -EAGAIN;
80491+
80492+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
80493+
80494 if (atomic_read(&p->real_cred->user->processes) >=
80495 task_rlimit(p, RLIMIT_NPROC)) {
80496 if (p->real_cred->user != INIT_USER &&
80497@@ -1450,6 +1503,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
80498 goto bad_fork_free_pid;
80499 }
80500
80501+ /* synchronizes with gr_set_acls()
80502+ we need to call this past the point of no return for fork()
80503+ */
80504+ gr_copy_label(p);
80505+
80506 if (likely(p->pid)) {
80507 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
80508
80509@@ -1535,6 +1593,8 @@ bad_fork_cleanup_count:
80510 bad_fork_free:
80511 free_task(p);
80512 fork_out:
80513+ gr_log_forkfail(retval);
80514+
80515 return ERR_PTR(retval);
80516 }
80517
80518@@ -1605,6 +1665,7 @@ long do_fork(unsigned long clone_flags,
80519
80520 p = copy_process(clone_flags, stack_start, stack_size,
80521 child_tidptr, NULL, trace);
80522+ add_latent_entropy();
80523 /*
80524 * Do this prior waking up the new thread - the thread pointer
80525 * might get invalid after that point, if the thread exits quickly.
80526@@ -1619,6 +1680,8 @@ long do_fork(unsigned long clone_flags,
80527 if (clone_flags & CLONE_PARENT_SETTID)
80528 put_user(nr, parent_tidptr);
80529
80530+ gr_handle_brute_check();
80531+
80532 if (clone_flags & CLONE_VFORK) {
80533 p->vfork_done = &vfork;
80534 init_completion(&vfork);
80535@@ -1735,7 +1798,7 @@ void __init proc_caches_init(void)
80536 mm_cachep = kmem_cache_create("mm_struct",
80537 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
80538 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
80539- vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
80540+ vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
80541 mmap_init();
80542 nsproxy_cache_init();
80543 }
80544@@ -1775,7 +1838,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
80545 return 0;
80546
80547 /* don't need lock here; in the worst case we'll do useless copy */
80548- if (fs->users == 1)
80549+ if (atomic_read(&fs->users) == 1)
80550 return 0;
80551
80552 *new_fsp = copy_fs_struct(fs);
80553@@ -1887,7 +1950,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
80554 fs = current->fs;
80555 spin_lock(&fs->lock);
80556 current->fs = new_fs;
80557- if (--fs->users)
80558+ gr_set_chroot_entries(current, &current->fs->root);
80559+ if (atomic_dec_return(&fs->users))
80560 new_fs = NULL;
80561 else
80562 new_fs = fs;
80563diff --git a/kernel/futex.c b/kernel/futex.c
80564index c3a1a55..e32b4a98 100644
80565--- a/kernel/futex.c
80566+++ b/kernel/futex.c
80567@@ -54,6 +54,7 @@
80568 #include <linux/mount.h>
80569 #include <linux/pagemap.h>
80570 #include <linux/syscalls.h>
80571+#include <linux/ptrace.h>
80572 #include <linux/signal.h>
80573 #include <linux/export.h>
80574 #include <linux/magic.h>
80575@@ -243,6 +244,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
80576 struct page *page, *page_head;
80577 int err, ro = 0;
80578
80579+#ifdef CONFIG_PAX_SEGMEXEC
80580+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
80581+ return -EFAULT;
80582+#endif
80583+
80584 /*
80585 * The futex address must be "naturally" aligned.
80586 */
80587@@ -441,7 +447,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
80588
80589 static int get_futex_value_locked(u32 *dest, u32 __user *from)
80590 {
80591- int ret;
80592+ unsigned long ret;
80593
80594 pagefault_disable();
80595 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
80596@@ -2734,6 +2740,7 @@ static int __init futex_init(void)
80597 {
80598 u32 curval;
80599 int i;
80600+ mm_segment_t oldfs;
80601
80602 /*
80603 * This will fail and we want it. Some arch implementations do
80604@@ -2745,8 +2752,11 @@ static int __init futex_init(void)
80605 * implementation, the non-functional ones will return
80606 * -ENOSYS.
80607 */
80608+ oldfs = get_fs();
80609+ set_fs(USER_DS);
80610 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
80611 futex_cmpxchg_enabled = 1;
80612+ set_fs(oldfs);
80613
80614 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
80615 plist_head_init(&futex_queues[i].chain);
80616diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
80617index f9f44fd..29885e4 100644
80618--- a/kernel/futex_compat.c
80619+++ b/kernel/futex_compat.c
80620@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
80621 return 0;
80622 }
80623
80624-static void __user *futex_uaddr(struct robust_list __user *entry,
80625+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
80626 compat_long_t futex_offset)
80627 {
80628 compat_uptr_t base = ptr_to_compat(entry);
80629diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
80630index 9b22d03..6295b62 100644
80631--- a/kernel/gcov/base.c
80632+++ b/kernel/gcov/base.c
80633@@ -102,11 +102,6 @@ void gcov_enable_events(void)
80634 }
80635
80636 #ifdef CONFIG_MODULES
80637-static inline int within(void *addr, void *start, unsigned long size)
80638-{
80639- return ((addr >= start) && (addr < start + size));
80640-}
80641-
80642 /* Update list and generate events when modules are unloaded. */
80643 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
80644 void *data)
80645@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
80646 prev = NULL;
80647 /* Remove entries located in module from linked list. */
80648 for (info = gcov_info_head; info; info = info->next) {
80649- if (within(info, mod->module_core, mod->core_size)) {
80650+ if (within_module_core_rw((unsigned long)info, mod)) {
80651 if (prev)
80652 prev->next = info->next;
80653 else
80654diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
80655index 383319b..56ebb13 100644
80656--- a/kernel/hrtimer.c
80657+++ b/kernel/hrtimer.c
80658@@ -1438,7 +1438,7 @@ void hrtimer_peek_ahead_timers(void)
80659 local_irq_restore(flags);
80660 }
80661
80662-static void run_hrtimer_softirq(struct softirq_action *h)
80663+static __latent_entropy void run_hrtimer_softirq(void)
80664 {
80665 hrtimer_peek_ahead_timers();
80666 }
80667diff --git a/kernel/irq_work.c b/kernel/irq_work.c
80668index 55fcce6..0e4cf34 100644
80669--- a/kernel/irq_work.c
80670+++ b/kernel/irq_work.c
80671@@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
80672 return NOTIFY_OK;
80673 }
80674
80675-static struct notifier_block cpu_notify;
80676+static struct notifier_block cpu_notify = {
80677+ .notifier_call = irq_work_cpu_notify,
80678+ .priority = 0,
80679+};
80680
80681 static __init int irq_work_init_cpu_notifier(void)
80682 {
80683- cpu_notify.notifier_call = irq_work_cpu_notify;
80684- cpu_notify.priority = 0;
80685 register_cpu_notifier(&cpu_notify);
80686 return 0;
80687 }
80688diff --git a/kernel/jump_label.c b/kernel/jump_label.c
80689index 60f48fa..7f3a770 100644
80690--- a/kernel/jump_label.c
80691+++ b/kernel/jump_label.c
80692@@ -13,6 +13,7 @@
80693 #include <linux/sort.h>
80694 #include <linux/err.h>
80695 #include <linux/static_key.h>
80696+#include <linux/mm.h>
80697
80698 #ifdef HAVE_JUMP_LABEL
80699
80700@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
80701
80702 size = (((unsigned long)stop - (unsigned long)start)
80703 / sizeof(struct jump_entry));
80704+ pax_open_kernel();
80705 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
80706+ pax_close_kernel();
80707 }
80708
80709 static void jump_label_update(struct static_key *key, int enable);
80710@@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
80711 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
80712 struct jump_entry *iter;
80713
80714+ pax_open_kernel();
80715 for (iter = iter_start; iter < iter_stop; iter++) {
80716 if (within_module_init(iter->code, mod))
80717 iter->code = 0;
80718 }
80719+ pax_close_kernel();
80720 }
80721
80722 static int
80723diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
80724index 3127ad5..159d880 100644
80725--- a/kernel/kallsyms.c
80726+++ b/kernel/kallsyms.c
80727@@ -11,6 +11,9 @@
80728 * Changed the compression method from stem compression to "table lookup"
80729 * compression (see scripts/kallsyms.c for a more complete description)
80730 */
80731+#ifdef CONFIG_GRKERNSEC_HIDESYM
80732+#define __INCLUDED_BY_HIDESYM 1
80733+#endif
80734 #include <linux/kallsyms.h>
80735 #include <linux/module.h>
80736 #include <linux/init.h>
80737@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
80738
80739 static inline int is_kernel_inittext(unsigned long addr)
80740 {
80741+ if (system_state != SYSTEM_BOOTING)
80742+ return 0;
80743+
80744 if (addr >= (unsigned long)_sinittext
80745 && addr <= (unsigned long)_einittext)
80746 return 1;
80747 return 0;
80748 }
80749
80750+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
80751+#ifdef CONFIG_MODULES
80752+static inline int is_module_text(unsigned long addr)
80753+{
80754+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
80755+ return 1;
80756+
80757+ addr = ktla_ktva(addr);
80758+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
80759+}
80760+#else
80761+static inline int is_module_text(unsigned long addr)
80762+{
80763+ return 0;
80764+}
80765+#endif
80766+#endif
80767+
80768 static inline int is_kernel_text(unsigned long addr)
80769 {
80770 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
80771@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
80772
80773 static inline int is_kernel(unsigned long addr)
80774 {
80775+
80776+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
80777+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
80778+ return 1;
80779+
80780+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
80781+#else
80782 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
80783+#endif
80784+
80785 return 1;
80786 return in_gate_area_no_mm(addr);
80787 }
80788
80789 static int is_ksym_addr(unsigned long addr)
80790 {
80791+
80792+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
80793+ if (is_module_text(addr))
80794+ return 0;
80795+#endif
80796+
80797 if (all_var)
80798 return is_kernel(addr);
80799
80800@@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
80801
80802 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
80803 {
80804- iter->name[0] = '\0';
80805 iter->nameoff = get_symbol_offset(new_pos);
80806 iter->pos = new_pos;
80807 }
80808@@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
80809 {
80810 struct kallsym_iter *iter = m->private;
80811
80812+#ifdef CONFIG_GRKERNSEC_HIDESYM
80813+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
80814+ return 0;
80815+#endif
80816+
80817 /* Some debugging symbols have no name. Ignore them. */
80818 if (!iter->name[0])
80819 return 0;
80820@@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
80821 */
80822 type = iter->exported ? toupper(iter->type) :
80823 tolower(iter->type);
80824+
80825 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
80826 type, iter->name, iter->module_name);
80827 } else
80828@@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
80829 struct kallsym_iter *iter;
80830 int ret;
80831
80832- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
80833+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
80834 if (!iter)
80835 return -ENOMEM;
80836 reset_iter(iter, 0);
80837diff --git a/kernel/kcmp.c b/kernel/kcmp.c
80838index e30ac0f..3528cac 100644
80839--- a/kernel/kcmp.c
80840+++ b/kernel/kcmp.c
80841@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
80842 struct task_struct *task1, *task2;
80843 int ret;
80844
80845+#ifdef CONFIG_GRKERNSEC
80846+ return -ENOSYS;
80847+#endif
80848+
80849 rcu_read_lock();
80850
80851 /*
80852diff --git a/kernel/kexec.c b/kernel/kexec.c
80853index 59f7b55..4022f65 100644
80854--- a/kernel/kexec.c
80855+++ b/kernel/kexec.c
80856@@ -1041,7 +1041,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
80857 unsigned long flags)
80858 {
80859 struct compat_kexec_segment in;
80860- struct kexec_segment out, __user *ksegments;
80861+ struct kexec_segment out;
80862+ struct kexec_segment __user *ksegments;
80863 unsigned long i, result;
80864
80865 /* Don't allow clients that don't understand the native
80866diff --git a/kernel/kmod.c b/kernel/kmod.c
80867index b086006..a27913b 100644
80868--- a/kernel/kmod.c
80869+++ b/kernel/kmod.c
80870@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
80871 kfree(info->argv);
80872 }
80873
80874-static int call_modprobe(char *module_name, int wait)
80875+static int call_modprobe(char *module_name, char *module_param, int wait)
80876 {
80877 struct subprocess_info *info;
80878 static char *envp[] = {
80879@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
80880 NULL
80881 };
80882
80883- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
80884+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
80885 if (!argv)
80886 goto out;
80887
80888@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
80889 argv[1] = "-q";
80890 argv[2] = "--";
80891 argv[3] = module_name; /* check free_modprobe_argv() */
80892- argv[4] = NULL;
80893+ argv[4] = module_param;
80894+ argv[5] = NULL;
80895
80896 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
80897 NULL, free_modprobe_argv, NULL);
80898@@ -129,9 +130,8 @@ out:
80899 * If module auto-loading support is disabled then this function
80900 * becomes a no-operation.
80901 */
80902-int __request_module(bool wait, const char *fmt, ...)
80903+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
80904 {
80905- va_list args;
80906 char module_name[MODULE_NAME_LEN];
80907 unsigned int max_modprobes;
80908 int ret;
80909@@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
80910 if (!modprobe_path[0])
80911 return 0;
80912
80913- va_start(args, fmt);
80914- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
80915- va_end(args);
80916+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
80917 if (ret >= MODULE_NAME_LEN)
80918 return -ENAMETOOLONG;
80919
80920@@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
80921 if (ret)
80922 return ret;
80923
80924+#ifdef CONFIG_GRKERNSEC_MODHARDEN
80925+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
80926+ /* hack to workaround consolekit/udisks stupidity */
80927+ read_lock(&tasklist_lock);
80928+ if (!strcmp(current->comm, "mount") &&
80929+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
80930+ read_unlock(&tasklist_lock);
80931+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
80932+ return -EPERM;
80933+ }
80934+ read_unlock(&tasklist_lock);
80935+ }
80936+#endif
80937+
80938 /* If modprobe needs a service that is in a module, we get a recursive
80939 * loop. Limit the number of running kmod threads to max_threads/2 or
80940 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
80941@@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
80942
80943 trace_module_request(module_name, wait, _RET_IP_);
80944
80945- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
80946+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
80947
80948 atomic_dec(&kmod_concurrent);
80949 return ret;
80950 }
80951+
80952+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
80953+{
80954+ va_list args;
80955+ int ret;
80956+
80957+ va_start(args, fmt);
80958+ ret = ____request_module(wait, module_param, fmt, args);
80959+ va_end(args);
80960+
80961+ return ret;
80962+}
80963+
80964+int __request_module(bool wait, const char *fmt, ...)
80965+{
80966+ va_list args;
80967+ int ret;
80968+
80969+#ifdef CONFIG_GRKERNSEC_MODHARDEN
80970+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
80971+ char module_param[MODULE_NAME_LEN];
80972+
80973+ memset(module_param, 0, sizeof(module_param));
80974+
80975+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
80976+
80977+ va_start(args, fmt);
80978+ ret = ____request_module(wait, module_param, fmt, args);
80979+ va_end(args);
80980+
80981+ return ret;
80982+ }
80983+#endif
80984+
80985+ va_start(args, fmt);
80986+ ret = ____request_module(wait, NULL, fmt, args);
80987+ va_end(args);
80988+
80989+ return ret;
80990+}
80991+
80992 EXPORT_SYMBOL(__request_module);
80993 #endif /* CONFIG_MODULES */
80994
80995@@ -303,7 +356,7 @@ static int wait_for_helper(void *data)
80996 *
80997 * Thus the __user pointer cast is valid here.
80998 */
80999- sys_wait4(pid, (int __user *)&ret, 0, NULL);
81000+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
81001
81002 /*
81003 * If ret is 0, either ____call_usermodehelper failed and the
81004@@ -650,7 +703,7 @@ EXPORT_SYMBOL(call_usermodehelper);
81005 static int proc_cap_handler(struct ctl_table *table, int write,
81006 void __user *buffer, size_t *lenp, loff_t *ppos)
81007 {
81008- struct ctl_table t;
81009+ ctl_table_no_const t;
81010 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
81011 kernel_cap_t new_cap;
81012 int err, i;
81013diff --git a/kernel/kprobes.c b/kernel/kprobes.c
81014index 6e33498..3133bd3 100644
81015--- a/kernel/kprobes.c
81016+++ b/kernel/kprobes.c
81017@@ -31,6 +31,9 @@
81018 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
81019 * <prasanna@in.ibm.com> added function-return probes.
81020 */
81021+#ifdef CONFIG_GRKERNSEC_HIDESYM
81022+#define __INCLUDED_BY_HIDESYM 1
81023+#endif
81024 #include <linux/kprobes.h>
81025 #include <linux/hash.h>
81026 #include <linux/init.h>
81027@@ -185,7 +188,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
81028 * kernel image and loaded module images reside. This is required
81029 * so x86_64 can correctly handle the %rip-relative fixups.
81030 */
81031- kip->insns = module_alloc(PAGE_SIZE);
81032+ kip->insns = module_alloc_exec(PAGE_SIZE);
81033 if (!kip->insns) {
81034 kfree(kip);
81035 return NULL;
81036@@ -225,7 +228,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
81037 */
81038 if (!list_is_singular(&kip->list)) {
81039 list_del(&kip->list);
81040- module_free(NULL, kip->insns);
81041+ module_free_exec(NULL, kip->insns);
81042 kfree(kip);
81043 }
81044 return 1;
81045@@ -2083,7 +2086,7 @@ static int __init init_kprobes(void)
81046 {
81047 int i, err = 0;
81048 unsigned long offset = 0, size = 0;
81049- char *modname, namebuf[128];
81050+ char *modname, namebuf[KSYM_NAME_LEN];
81051 const char *symbol_name;
81052 void *addr;
81053 struct kprobe_blackpoint *kb;
81054@@ -2168,11 +2171,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
81055 kprobe_type = "k";
81056
81057 if (sym)
81058- seq_printf(pi, "%p %s %s+0x%x %s ",
81059+ seq_printf(pi, "%pK %s %s+0x%x %s ",
81060 p->addr, kprobe_type, sym, offset,
81061 (modname ? modname : " "));
81062 else
81063- seq_printf(pi, "%p %s %p ",
81064+ seq_printf(pi, "%pK %s %pK ",
81065 p->addr, kprobe_type, p->addr);
81066
81067 if (!pp)
81068@@ -2209,7 +2212,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
81069 const char *sym = NULL;
81070 unsigned int i = *(loff_t *) v;
81071 unsigned long offset = 0;
81072- char *modname, namebuf[128];
81073+ char *modname, namebuf[KSYM_NAME_LEN];
81074
81075 head = &kprobe_table[i];
81076 preempt_disable();
81077diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
81078index 6ada93c..dce7d5d 100644
81079--- a/kernel/ksysfs.c
81080+++ b/kernel/ksysfs.c
81081@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
81082 {
81083 if (count+1 > UEVENT_HELPER_PATH_LEN)
81084 return -ENOENT;
81085+ if (!capable(CAP_SYS_ADMIN))
81086+ return -EPERM;
81087 memcpy(uevent_helper, buf, count);
81088 uevent_helper[count] = '\0';
81089 if (count && uevent_helper[count-1] == '\n')
81090@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
81091 return count;
81092 }
81093
81094-static struct bin_attribute notes_attr = {
81095+static bin_attribute_no_const notes_attr __read_only = {
81096 .attr = {
81097 .name = "notes",
81098 .mode = S_IRUGO,
81099diff --git a/kernel/lockdep.c b/kernel/lockdep.c
81100index e16c45b..6f49c48 100644
81101--- a/kernel/lockdep.c
81102+++ b/kernel/lockdep.c
81103@@ -596,6 +596,10 @@ static int static_obj(void *obj)
81104 end = (unsigned long) &_end,
81105 addr = (unsigned long) obj;
81106
81107+#ifdef CONFIG_PAX_KERNEXEC
81108+ start = ktla_ktva(start);
81109+#endif
81110+
81111 /*
81112 * static variable?
81113 */
81114@@ -736,6 +740,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
81115 if (!static_obj(lock->key)) {
81116 debug_locks_off();
81117 printk("INFO: trying to register non-static key.\n");
81118+ printk("lock:%pS key:%pS.\n", lock, lock->key);
81119 printk("the code is fine but needs lockdep annotation.\n");
81120 printk("turning off the locking correctness validator.\n");
81121 dump_stack();
81122@@ -3080,7 +3085,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
81123 if (!class)
81124 return 0;
81125 }
81126- atomic_inc((atomic_t *)&class->ops);
81127+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
81128 if (very_verbose(class)) {
81129 printk("\nacquire class [%p] %s", class->key, class->name);
81130 if (class->name_version > 1)
81131diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
81132index b2c71c5..7b88d63 100644
81133--- a/kernel/lockdep_proc.c
81134+++ b/kernel/lockdep_proc.c
81135@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
81136 return 0;
81137 }
81138
81139- seq_printf(m, "%p", class->key);
81140+ seq_printf(m, "%pK", class->key);
81141 #ifdef CONFIG_DEBUG_LOCKDEP
81142 seq_printf(m, " OPS:%8ld", class->ops);
81143 #endif
81144@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
81145
81146 list_for_each_entry(entry, &class->locks_after, entry) {
81147 if (entry->distance == 1) {
81148- seq_printf(m, " -> [%p] ", entry->class->key);
81149+ seq_printf(m, " -> [%pK] ", entry->class->key);
81150 print_name(m, entry->class);
81151 seq_puts(m, "\n");
81152 }
81153@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
81154 if (!class->key)
81155 continue;
81156
81157- seq_printf(m, "[%p] ", class->key);
81158+ seq_printf(m, "[%pK] ", class->key);
81159 print_name(m, class);
81160 seq_puts(m, "\n");
81161 }
81162@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
81163 if (!i)
81164 seq_line(m, '-', 40-namelen, namelen);
81165
81166- snprintf(ip, sizeof(ip), "[<%p>]",
81167+ snprintf(ip, sizeof(ip), "[<%pK>]",
81168 (void *)class->contention_point[i]);
81169 seq_printf(m, "%40s %14lu %29s %pS\n",
81170 name, stats->contention_point[i],
81171@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
81172 if (!i)
81173 seq_line(m, '-', 40-namelen, namelen);
81174
81175- snprintf(ip, sizeof(ip), "[<%p>]",
81176+ snprintf(ip, sizeof(ip), "[<%pK>]",
81177 (void *)class->contending_point[i]);
81178 seq_printf(m, "%40s %14lu %29s %pS\n",
81179 name, stats->contending_point[i],
81180diff --git a/kernel/module.c b/kernel/module.c
81181index 2069158..71101bb 100644
81182--- a/kernel/module.c
81183+++ b/kernel/module.c
81184@@ -61,6 +61,7 @@
81185 #include <linux/pfn.h>
81186 #include <linux/bsearch.h>
81187 #include <linux/fips.h>
81188+#include <linux/grsecurity.h>
81189 #include <uapi/linux/module.h>
81190 #include "module-internal.h"
81191
81192@@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
81193
81194 /* Bounds of module allocation, for speeding __module_address.
81195 * Protected by module_mutex. */
81196-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
81197+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
81198+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
81199
81200 int register_module_notifier(struct notifier_block * nb)
81201 {
81202@@ -323,7 +325,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
81203 return true;
81204
81205 list_for_each_entry_rcu(mod, &modules, list) {
81206- struct symsearch arr[] = {
81207+ struct symsearch modarr[] = {
81208 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
81209 NOT_GPL_ONLY, false },
81210 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
81211@@ -348,7 +350,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
81212 if (mod->state == MODULE_STATE_UNFORMED)
81213 continue;
81214
81215- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
81216+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
81217 return true;
81218 }
81219 return false;
81220@@ -490,7 +492,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
81221 if (!pcpusec->sh_size)
81222 return 0;
81223
81224- if (align > PAGE_SIZE) {
81225+ if (align-1 >= PAGE_SIZE) {
81226 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
81227 mod->name, align, PAGE_SIZE);
81228 align = PAGE_SIZE;
81229@@ -1096,7 +1098,7 @@ struct module_attribute module_uevent =
81230 static ssize_t show_coresize(struct module_attribute *mattr,
81231 struct module_kobject *mk, char *buffer)
81232 {
81233- return sprintf(buffer, "%u\n", mk->mod->core_size);
81234+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
81235 }
81236
81237 static struct module_attribute modinfo_coresize =
81238@@ -1105,7 +1107,7 @@ static struct module_attribute modinfo_coresize =
81239 static ssize_t show_initsize(struct module_attribute *mattr,
81240 struct module_kobject *mk, char *buffer)
81241 {
81242- return sprintf(buffer, "%u\n", mk->mod->init_size);
81243+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
81244 }
81245
81246 static struct module_attribute modinfo_initsize =
81247@@ -1320,7 +1322,7 @@ resolve_symbol_wait(struct module *mod,
81248 */
81249 #ifdef CONFIG_SYSFS
81250
81251-#ifdef CONFIG_KALLSYMS
81252+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
81253 static inline bool sect_empty(const Elf_Shdr *sect)
81254 {
81255 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
81256@@ -1460,7 +1462,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
81257 {
81258 unsigned int notes, loaded, i;
81259 struct module_notes_attrs *notes_attrs;
81260- struct bin_attribute *nattr;
81261+ bin_attribute_no_const *nattr;
81262
81263 /* failed to create section attributes, so can't create notes */
81264 if (!mod->sect_attrs)
81265@@ -1572,7 +1574,7 @@ static void del_usage_links(struct module *mod)
81266 static int module_add_modinfo_attrs(struct module *mod)
81267 {
81268 struct module_attribute *attr;
81269- struct module_attribute *temp_attr;
81270+ module_attribute_no_const *temp_attr;
81271 int error = 0;
81272 int i;
81273
81274@@ -1786,21 +1788,21 @@ static void set_section_ro_nx(void *base,
81275
81276 static void unset_module_core_ro_nx(struct module *mod)
81277 {
81278- set_page_attributes(mod->module_core + mod->core_text_size,
81279- mod->module_core + mod->core_size,
81280+ set_page_attributes(mod->module_core_rw,
81281+ mod->module_core_rw + mod->core_size_rw,
81282 set_memory_x);
81283- set_page_attributes(mod->module_core,
81284- mod->module_core + mod->core_ro_size,
81285+ set_page_attributes(mod->module_core_rx,
81286+ mod->module_core_rx + mod->core_size_rx,
81287 set_memory_rw);
81288 }
81289
81290 static void unset_module_init_ro_nx(struct module *mod)
81291 {
81292- set_page_attributes(mod->module_init + mod->init_text_size,
81293- mod->module_init + mod->init_size,
81294+ set_page_attributes(mod->module_init_rw,
81295+ mod->module_init_rw + mod->init_size_rw,
81296 set_memory_x);
81297- set_page_attributes(mod->module_init,
81298- mod->module_init + mod->init_ro_size,
81299+ set_page_attributes(mod->module_init_rx,
81300+ mod->module_init_rx + mod->init_size_rx,
81301 set_memory_rw);
81302 }
81303
81304@@ -1813,14 +1815,14 @@ void set_all_modules_text_rw(void)
81305 list_for_each_entry_rcu(mod, &modules, list) {
81306 if (mod->state == MODULE_STATE_UNFORMED)
81307 continue;
81308- if ((mod->module_core) && (mod->core_text_size)) {
81309- set_page_attributes(mod->module_core,
81310- mod->module_core + mod->core_text_size,
81311+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
81312+ set_page_attributes(mod->module_core_rx,
81313+ mod->module_core_rx + mod->core_size_rx,
81314 set_memory_rw);
81315 }
81316- if ((mod->module_init) && (mod->init_text_size)) {
81317- set_page_attributes(mod->module_init,
81318- mod->module_init + mod->init_text_size,
81319+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
81320+ set_page_attributes(mod->module_init_rx,
81321+ mod->module_init_rx + mod->init_size_rx,
81322 set_memory_rw);
81323 }
81324 }
81325@@ -1836,14 +1838,14 @@ void set_all_modules_text_ro(void)
81326 list_for_each_entry_rcu(mod, &modules, list) {
81327 if (mod->state == MODULE_STATE_UNFORMED)
81328 continue;
81329- if ((mod->module_core) && (mod->core_text_size)) {
81330- set_page_attributes(mod->module_core,
81331- mod->module_core + mod->core_text_size,
81332+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
81333+ set_page_attributes(mod->module_core_rx,
81334+ mod->module_core_rx + mod->core_size_rx,
81335 set_memory_ro);
81336 }
81337- if ((mod->module_init) && (mod->init_text_size)) {
81338- set_page_attributes(mod->module_init,
81339- mod->module_init + mod->init_text_size,
81340+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
81341+ set_page_attributes(mod->module_init_rx,
81342+ mod->module_init_rx + mod->init_size_rx,
81343 set_memory_ro);
81344 }
81345 }
81346@@ -1894,16 +1896,19 @@ static void free_module(struct module *mod)
81347
81348 /* This may be NULL, but that's OK */
81349 unset_module_init_ro_nx(mod);
81350- module_free(mod, mod->module_init);
81351+ module_free(mod, mod->module_init_rw);
81352+ module_free_exec(mod, mod->module_init_rx);
81353 kfree(mod->args);
81354 percpu_modfree(mod);
81355
81356 /* Free lock-classes: */
81357- lockdep_free_key_range(mod->module_core, mod->core_size);
81358+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
81359+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
81360
81361 /* Finally, free the core (containing the module structure) */
81362 unset_module_core_ro_nx(mod);
81363- module_free(mod, mod->module_core);
81364+ module_free_exec(mod, mod->module_core_rx);
81365+ module_free(mod, mod->module_core_rw);
81366
81367 #ifdef CONFIG_MPU
81368 update_protections(current->mm);
81369@@ -1973,9 +1978,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
81370 int ret = 0;
81371 const struct kernel_symbol *ksym;
81372
81373+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81374+ int is_fs_load = 0;
81375+ int register_filesystem_found = 0;
81376+ char *p;
81377+
81378+ p = strstr(mod->args, "grsec_modharden_fs");
81379+ if (p) {
81380+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
81381+ /* copy \0 as well */
81382+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
81383+ is_fs_load = 1;
81384+ }
81385+#endif
81386+
81387 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
81388 const char *name = info->strtab + sym[i].st_name;
81389
81390+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81391+ /* it's a real shame this will never get ripped and copied
81392+ upstream! ;(
81393+ */
81394+ if (is_fs_load && !strcmp(name, "register_filesystem"))
81395+ register_filesystem_found = 1;
81396+#endif
81397+
81398 switch (sym[i].st_shndx) {
81399 case SHN_COMMON:
81400 /* We compiled with -fno-common. These are not
81401@@ -1996,7 +2023,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
81402 ksym = resolve_symbol_wait(mod, info, name);
81403 /* Ok if resolved. */
81404 if (ksym && !IS_ERR(ksym)) {
81405+ pax_open_kernel();
81406 sym[i].st_value = ksym->value;
81407+ pax_close_kernel();
81408 break;
81409 }
81410
81411@@ -2015,11 +2044,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
81412 secbase = (unsigned long)mod_percpu(mod);
81413 else
81414 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
81415+ pax_open_kernel();
81416 sym[i].st_value += secbase;
81417+ pax_close_kernel();
81418 break;
81419 }
81420 }
81421
81422+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81423+ if (is_fs_load && !register_filesystem_found) {
81424+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
81425+ ret = -EPERM;
81426+ }
81427+#endif
81428+
81429 return ret;
81430 }
81431
81432@@ -2103,22 +2141,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
81433 || s->sh_entsize != ~0UL
81434 || strstarts(sname, ".init"))
81435 continue;
81436- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
81437+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
81438+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
81439+ else
81440+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
81441 pr_debug("\t%s\n", sname);
81442 }
81443- switch (m) {
81444- case 0: /* executable */
81445- mod->core_size = debug_align(mod->core_size);
81446- mod->core_text_size = mod->core_size;
81447- break;
81448- case 1: /* RO: text and ro-data */
81449- mod->core_size = debug_align(mod->core_size);
81450- mod->core_ro_size = mod->core_size;
81451- break;
81452- case 3: /* whole core */
81453- mod->core_size = debug_align(mod->core_size);
81454- break;
81455- }
81456 }
81457
81458 pr_debug("Init section allocation order:\n");
81459@@ -2132,23 +2160,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
81460 || s->sh_entsize != ~0UL
81461 || !strstarts(sname, ".init"))
81462 continue;
81463- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
81464- | INIT_OFFSET_MASK);
81465+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
81466+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
81467+ else
81468+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
81469+ s->sh_entsize |= INIT_OFFSET_MASK;
81470 pr_debug("\t%s\n", sname);
81471 }
81472- switch (m) {
81473- case 0: /* executable */
81474- mod->init_size = debug_align(mod->init_size);
81475- mod->init_text_size = mod->init_size;
81476- break;
81477- case 1: /* RO: text and ro-data */
81478- mod->init_size = debug_align(mod->init_size);
81479- mod->init_ro_size = mod->init_size;
81480- break;
81481- case 3: /* whole init */
81482- mod->init_size = debug_align(mod->init_size);
81483- break;
81484- }
81485 }
81486 }
81487
81488@@ -2321,7 +2339,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
81489
81490 /* Put symbol section at end of init part of module. */
81491 symsect->sh_flags |= SHF_ALLOC;
81492- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
81493+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
81494 info->index.sym) | INIT_OFFSET_MASK;
81495 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
81496
81497@@ -2338,13 +2356,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
81498 }
81499
81500 /* Append room for core symbols at end of core part. */
81501- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
81502- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
81503- mod->core_size += strtab_size;
81504+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
81505+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
81506+ mod->core_size_rx += strtab_size;
81507
81508 /* Put string table section at end of init part of module. */
81509 strsect->sh_flags |= SHF_ALLOC;
81510- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
81511+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
81512 info->index.str) | INIT_OFFSET_MASK;
81513 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
81514 }
81515@@ -2362,12 +2380,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
81516 /* Make sure we get permanent strtab: don't use info->strtab. */
81517 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
81518
81519+ pax_open_kernel();
81520+
81521 /* Set types up while we still have access to sections. */
81522 for (i = 0; i < mod->num_symtab; i++)
81523 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
81524
81525- mod->core_symtab = dst = mod->module_core + info->symoffs;
81526- mod->core_strtab = s = mod->module_core + info->stroffs;
81527+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
81528+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
81529 src = mod->symtab;
81530 for (ndst = i = 0; i < mod->num_symtab; i++) {
81531 if (i == 0 ||
81532@@ -2379,6 +2399,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
81533 }
81534 }
81535 mod->core_num_syms = ndst;
81536+
81537+ pax_close_kernel();
81538 }
81539 #else
81540 static inline void layout_symtab(struct module *mod, struct load_info *info)
81541@@ -2412,17 +2434,33 @@ void * __weak module_alloc(unsigned long size)
81542 return vmalloc_exec(size);
81543 }
81544
81545-static void *module_alloc_update_bounds(unsigned long size)
81546+static void *module_alloc_update_bounds_rw(unsigned long size)
81547 {
81548 void *ret = module_alloc(size);
81549
81550 if (ret) {
81551 mutex_lock(&module_mutex);
81552 /* Update module bounds. */
81553- if ((unsigned long)ret < module_addr_min)
81554- module_addr_min = (unsigned long)ret;
81555- if ((unsigned long)ret + size > module_addr_max)
81556- module_addr_max = (unsigned long)ret + size;
81557+ if ((unsigned long)ret < module_addr_min_rw)
81558+ module_addr_min_rw = (unsigned long)ret;
81559+ if ((unsigned long)ret + size > module_addr_max_rw)
81560+ module_addr_max_rw = (unsigned long)ret + size;
81561+ mutex_unlock(&module_mutex);
81562+ }
81563+ return ret;
81564+}
81565+
81566+static void *module_alloc_update_bounds_rx(unsigned long size)
81567+{
81568+ void *ret = module_alloc_exec(size);
81569+
81570+ if (ret) {
81571+ mutex_lock(&module_mutex);
81572+ /* Update module bounds. */
81573+ if ((unsigned long)ret < module_addr_min_rx)
81574+ module_addr_min_rx = (unsigned long)ret;
81575+ if ((unsigned long)ret + size > module_addr_max_rx)
81576+ module_addr_max_rx = (unsigned long)ret + size;
81577 mutex_unlock(&module_mutex);
81578 }
81579 return ret;
81580@@ -2698,8 +2736,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
81581 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
81582 {
81583 const char *modmagic = get_modinfo(info, "vermagic");
81584+ const char *license = get_modinfo(info, "license");
81585 int err;
81586
81587+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
81588+ if (!license || !license_is_gpl_compatible(license))
81589+ return -ENOEXEC;
81590+#endif
81591+
81592 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
81593 modmagic = NULL;
81594
81595@@ -2725,7 +2769,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
81596 }
81597
81598 /* Set up license info based on the info section */
81599- set_license(mod, get_modinfo(info, "license"));
81600+ set_license(mod, license);
81601
81602 return 0;
81603 }
81604@@ -2806,7 +2850,7 @@ static int move_module(struct module *mod, struct load_info *info)
81605 void *ptr;
81606
81607 /* Do the allocs. */
81608- ptr = module_alloc_update_bounds(mod->core_size);
81609+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
81610 /*
81611 * The pointer to this block is stored in the module structure
81612 * which is inside the block. Just mark it as not being a
81613@@ -2816,11 +2860,11 @@ static int move_module(struct module *mod, struct load_info *info)
81614 if (!ptr)
81615 return -ENOMEM;
81616
81617- memset(ptr, 0, mod->core_size);
81618- mod->module_core = ptr;
81619+ memset(ptr, 0, mod->core_size_rw);
81620+ mod->module_core_rw = ptr;
81621
81622- if (mod->init_size) {
81623- ptr = module_alloc_update_bounds(mod->init_size);
81624+ if (mod->init_size_rw) {
81625+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
81626 /*
81627 * The pointer to this block is stored in the module structure
81628 * which is inside the block. This block doesn't need to be
81629@@ -2829,13 +2873,45 @@ static int move_module(struct module *mod, struct load_info *info)
81630 */
81631 kmemleak_ignore(ptr);
81632 if (!ptr) {
81633- module_free(mod, mod->module_core);
81634+ module_free(mod, mod->module_core_rw);
81635 return -ENOMEM;
81636 }
81637- memset(ptr, 0, mod->init_size);
81638- mod->module_init = ptr;
81639+ memset(ptr, 0, mod->init_size_rw);
81640+ mod->module_init_rw = ptr;
81641 } else
81642- mod->module_init = NULL;
81643+ mod->module_init_rw = NULL;
81644+
81645+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
81646+ kmemleak_not_leak(ptr);
81647+ if (!ptr) {
81648+ if (mod->module_init_rw)
81649+ module_free(mod, mod->module_init_rw);
81650+ module_free(mod, mod->module_core_rw);
81651+ return -ENOMEM;
81652+ }
81653+
81654+ pax_open_kernel();
81655+ memset(ptr, 0, mod->core_size_rx);
81656+ pax_close_kernel();
81657+ mod->module_core_rx = ptr;
81658+
81659+ if (mod->init_size_rx) {
81660+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
81661+ kmemleak_ignore(ptr);
81662+ if (!ptr && mod->init_size_rx) {
81663+ module_free_exec(mod, mod->module_core_rx);
81664+ if (mod->module_init_rw)
81665+ module_free(mod, mod->module_init_rw);
81666+ module_free(mod, mod->module_core_rw);
81667+ return -ENOMEM;
81668+ }
81669+
81670+ pax_open_kernel();
81671+ memset(ptr, 0, mod->init_size_rx);
81672+ pax_close_kernel();
81673+ mod->module_init_rx = ptr;
81674+ } else
81675+ mod->module_init_rx = NULL;
81676
81677 /* Transfer each section which specifies SHF_ALLOC */
81678 pr_debug("final section addresses:\n");
81679@@ -2846,16 +2922,45 @@ static int move_module(struct module *mod, struct load_info *info)
81680 if (!(shdr->sh_flags & SHF_ALLOC))
81681 continue;
81682
81683- if (shdr->sh_entsize & INIT_OFFSET_MASK)
81684- dest = mod->module_init
81685- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
81686- else
81687- dest = mod->module_core + shdr->sh_entsize;
81688+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
81689+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
81690+ dest = mod->module_init_rw
81691+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
81692+ else
81693+ dest = mod->module_init_rx
81694+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
81695+ } else {
81696+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
81697+ dest = mod->module_core_rw + shdr->sh_entsize;
81698+ else
81699+ dest = mod->module_core_rx + shdr->sh_entsize;
81700+ }
81701+
81702+ if (shdr->sh_type != SHT_NOBITS) {
81703+
81704+#ifdef CONFIG_PAX_KERNEXEC
81705+#ifdef CONFIG_X86_64
81706+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
81707+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
81708+#endif
81709+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
81710+ pax_open_kernel();
81711+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
81712+ pax_close_kernel();
81713+ } else
81714+#endif
81715
81716- if (shdr->sh_type != SHT_NOBITS)
81717 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
81718+ }
81719 /* Update sh_addr to point to copy in image. */
81720- shdr->sh_addr = (unsigned long)dest;
81721+
81722+#ifdef CONFIG_PAX_KERNEXEC
81723+ if (shdr->sh_flags & SHF_EXECINSTR)
81724+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
81725+ else
81726+#endif
81727+
81728+ shdr->sh_addr = (unsigned long)dest;
81729 pr_debug("\t0x%lx %s\n",
81730 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
81731 }
81732@@ -2912,12 +3017,12 @@ static void flush_module_icache(const struct module *mod)
81733 * Do it before processing of module parameters, so the module
81734 * can provide parameter accessor functions of its own.
81735 */
81736- if (mod->module_init)
81737- flush_icache_range((unsigned long)mod->module_init,
81738- (unsigned long)mod->module_init
81739- + mod->init_size);
81740- flush_icache_range((unsigned long)mod->module_core,
81741- (unsigned long)mod->module_core + mod->core_size);
81742+ if (mod->module_init_rx)
81743+ flush_icache_range((unsigned long)mod->module_init_rx,
81744+ (unsigned long)mod->module_init_rx
81745+ + mod->init_size_rx);
81746+ flush_icache_range((unsigned long)mod->module_core_rx,
81747+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
81748
81749 set_fs(old_fs);
81750 }
81751@@ -2974,8 +3079,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
81752 static void module_deallocate(struct module *mod, struct load_info *info)
81753 {
81754 percpu_modfree(mod);
81755- module_free(mod, mod->module_init);
81756- module_free(mod, mod->module_core);
81757+ module_free_exec(mod, mod->module_init_rx);
81758+ module_free_exec(mod, mod->module_core_rx);
81759+ module_free(mod, mod->module_init_rw);
81760+ module_free(mod, mod->module_core_rw);
81761 }
81762
81763 int __weak module_finalize(const Elf_Ehdr *hdr,
81764@@ -2988,7 +3095,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
81765 static int post_relocation(struct module *mod, const struct load_info *info)
81766 {
81767 /* Sort exception table now relocations are done. */
81768+ pax_open_kernel();
81769 sort_extable(mod->extable, mod->extable + mod->num_exentries);
81770+ pax_close_kernel();
81771
81772 /* Copy relocated percpu area over. */
81773 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
81774@@ -3042,16 +3151,16 @@ static int do_init_module(struct module *mod)
81775 MODULE_STATE_COMING, mod);
81776
81777 /* Set RO and NX regions for core */
81778- set_section_ro_nx(mod->module_core,
81779- mod->core_text_size,
81780- mod->core_ro_size,
81781- mod->core_size);
81782+ set_section_ro_nx(mod->module_core_rx,
81783+ mod->core_size_rx,
81784+ mod->core_size_rx,
81785+ mod->core_size_rx);
81786
81787 /* Set RO and NX regions for init */
81788- set_section_ro_nx(mod->module_init,
81789- mod->init_text_size,
81790- mod->init_ro_size,
81791- mod->init_size);
81792+ set_section_ro_nx(mod->module_init_rx,
81793+ mod->init_size_rx,
81794+ mod->init_size_rx,
81795+ mod->init_size_rx);
81796
81797 do_mod_ctors(mod);
81798 /* Start the module */
81799@@ -3113,11 +3222,12 @@ static int do_init_module(struct module *mod)
81800 mod->strtab = mod->core_strtab;
81801 #endif
81802 unset_module_init_ro_nx(mod);
81803- module_free(mod, mod->module_init);
81804- mod->module_init = NULL;
81805- mod->init_size = 0;
81806- mod->init_ro_size = 0;
81807- mod->init_text_size = 0;
81808+ module_free(mod, mod->module_init_rw);
81809+ module_free_exec(mod, mod->module_init_rx);
81810+ mod->module_init_rw = NULL;
81811+ mod->module_init_rx = NULL;
81812+ mod->init_size_rw = 0;
81813+ mod->init_size_rx = 0;
81814 mutex_unlock(&module_mutex);
81815 wake_up_all(&module_wq);
81816
81817@@ -3261,9 +3371,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
81818 if (err)
81819 goto free_unload;
81820
81821+ /* Now copy in args */
81822+ mod->args = strndup_user(uargs, ~0UL >> 1);
81823+ if (IS_ERR(mod->args)) {
81824+ err = PTR_ERR(mod->args);
81825+ goto free_unload;
81826+ }
81827+
81828 /* Set up MODINFO_ATTR fields */
81829 setup_modinfo(mod, info);
81830
81831+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81832+ {
81833+ char *p, *p2;
81834+
81835+ if (strstr(mod->args, "grsec_modharden_netdev")) {
81836+ 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);
81837+ err = -EPERM;
81838+ goto free_modinfo;
81839+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
81840+ p += sizeof("grsec_modharden_normal") - 1;
81841+ p2 = strstr(p, "_");
81842+ if (p2) {
81843+ *p2 = '\0';
81844+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
81845+ *p2 = '_';
81846+ }
81847+ err = -EPERM;
81848+ goto free_modinfo;
81849+ }
81850+ }
81851+#endif
81852+
81853 /* Fix up syms, so that st_value is a pointer to location. */
81854 err = simplify_symbols(mod, info);
81855 if (err < 0)
81856@@ -3279,13 +3418,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
81857
81858 flush_module_icache(mod);
81859
81860- /* Now copy in args */
81861- mod->args = strndup_user(uargs, ~0UL >> 1);
81862- if (IS_ERR(mod->args)) {
81863- err = PTR_ERR(mod->args);
81864- goto free_arch_cleanup;
81865- }
81866-
81867 dynamic_debug_setup(info->debug, info->num_debug);
81868
81869 /* Finally it's fully formed, ready to start executing. */
81870@@ -3320,11 +3452,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
81871 ddebug_cleanup:
81872 dynamic_debug_remove(info->debug);
81873 synchronize_sched();
81874- kfree(mod->args);
81875- free_arch_cleanup:
81876 module_arch_cleanup(mod);
81877 free_modinfo:
81878 free_modinfo(mod);
81879+ kfree(mod->args);
81880 free_unload:
81881 module_unload_free(mod);
81882 unlink_mod:
81883@@ -3407,10 +3538,16 @@ static const char *get_ksymbol(struct module *mod,
81884 unsigned long nextval;
81885
81886 /* At worse, next value is at end of module */
81887- if (within_module_init(addr, mod))
81888- nextval = (unsigned long)mod->module_init+mod->init_text_size;
81889+ if (within_module_init_rx(addr, mod))
81890+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
81891+ else if (within_module_init_rw(addr, mod))
81892+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
81893+ else if (within_module_core_rx(addr, mod))
81894+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
81895+ else if (within_module_core_rw(addr, mod))
81896+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
81897 else
81898- nextval = (unsigned long)mod->module_core+mod->core_text_size;
81899+ return NULL;
81900
81901 /* Scan for closest preceding symbol, and next symbol. (ELF
81902 starts real symbols at 1). */
81903@@ -3661,7 +3798,7 @@ static int m_show(struct seq_file *m, void *p)
81904 return 0;
81905
81906 seq_printf(m, "%s %u",
81907- mod->name, mod->init_size + mod->core_size);
81908+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
81909 print_unload_info(m, mod);
81910
81911 /* Informative for users. */
81912@@ -3670,7 +3807,7 @@ static int m_show(struct seq_file *m, void *p)
81913 mod->state == MODULE_STATE_COMING ? "Loading":
81914 "Live");
81915 /* Used by oprofile and other similar tools. */
81916- seq_printf(m, " 0x%pK", mod->module_core);
81917+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
81918
81919 /* Taints info */
81920 if (mod->taints)
81921@@ -3706,7 +3843,17 @@ static const struct file_operations proc_modules_operations = {
81922
81923 static int __init proc_modules_init(void)
81924 {
81925+#ifndef CONFIG_GRKERNSEC_HIDESYM
81926+#ifdef CONFIG_GRKERNSEC_PROC_USER
81927+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
81928+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
81929+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
81930+#else
81931 proc_create("modules", 0, NULL, &proc_modules_operations);
81932+#endif
81933+#else
81934+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
81935+#endif
81936 return 0;
81937 }
81938 module_init(proc_modules_init);
81939@@ -3767,14 +3914,14 @@ struct module *__module_address(unsigned long addr)
81940 {
81941 struct module *mod;
81942
81943- if (addr < module_addr_min || addr > module_addr_max)
81944+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
81945+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
81946 return NULL;
81947
81948 list_for_each_entry_rcu(mod, &modules, list) {
81949 if (mod->state == MODULE_STATE_UNFORMED)
81950 continue;
81951- if (within_module_core(addr, mod)
81952- || within_module_init(addr, mod))
81953+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
81954 return mod;
81955 }
81956 return NULL;
81957@@ -3809,11 +3956,20 @@ bool is_module_text_address(unsigned long addr)
81958 */
81959 struct module *__module_text_address(unsigned long addr)
81960 {
81961- struct module *mod = __module_address(addr);
81962+ struct module *mod;
81963+
81964+#ifdef CONFIG_X86_32
81965+ addr = ktla_ktva(addr);
81966+#endif
81967+
81968+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
81969+ return NULL;
81970+
81971+ mod = __module_address(addr);
81972+
81973 if (mod) {
81974 /* Make sure it's within the text section. */
81975- if (!within(addr, mod->module_init, mod->init_text_size)
81976- && !within(addr, mod->module_core, mod->core_text_size))
81977+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
81978 mod = NULL;
81979 }
81980 return mod;
81981diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
81982index 7e3443f..b2a1e6b 100644
81983--- a/kernel/mutex-debug.c
81984+++ b/kernel/mutex-debug.c
81985@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
81986 }
81987
81988 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
81989- struct thread_info *ti)
81990+ struct task_struct *task)
81991 {
81992 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
81993
81994 /* Mark the current thread as blocked on the lock: */
81995- ti->task->blocked_on = waiter;
81996+ task->blocked_on = waiter;
81997 }
81998
81999 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
82000- struct thread_info *ti)
82001+ struct task_struct *task)
82002 {
82003 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
82004- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
82005- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
82006- ti->task->blocked_on = NULL;
82007+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
82008+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
82009+ task->blocked_on = NULL;
82010
82011 list_del_init(&waiter->list);
82012 waiter->task = NULL;
82013diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
82014index 0799fd3..d06ae3b 100644
82015--- a/kernel/mutex-debug.h
82016+++ b/kernel/mutex-debug.h
82017@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
82018 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
82019 extern void debug_mutex_add_waiter(struct mutex *lock,
82020 struct mutex_waiter *waiter,
82021- struct thread_info *ti);
82022+ struct task_struct *task);
82023 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
82024- struct thread_info *ti);
82025+ struct task_struct *task);
82026 extern void debug_mutex_unlock(struct mutex *lock);
82027 extern void debug_mutex_init(struct mutex *lock, const char *name,
82028 struct lock_class_key *key);
82029diff --git a/kernel/mutex.c b/kernel/mutex.c
82030index a52ee7bb..f361f16 100644
82031--- a/kernel/mutex.c
82032+++ b/kernel/mutex.c
82033@@ -135,7 +135,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
82034 node->locked = 1;
82035 return;
82036 }
82037- ACCESS_ONCE(prev->next) = node;
82038+ ACCESS_ONCE_RW(prev->next) = node;
82039 smp_wmb();
82040 /* Wait until the lock holder passes the lock down */
82041 while (!ACCESS_ONCE(node->locked))
82042@@ -156,7 +156,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
82043 while (!(next = ACCESS_ONCE(node->next)))
82044 arch_mutex_cpu_relax();
82045 }
82046- ACCESS_ONCE(next->locked) = 1;
82047+ ACCESS_ONCE_RW(next->locked) = 1;
82048 smp_wmb();
82049 }
82050
82051@@ -514,7 +514,7 @@ slowpath:
82052 spin_lock_mutex(&lock->wait_lock, flags);
82053
82054 debug_mutex_lock_common(lock, &waiter);
82055- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
82056+ debug_mutex_add_waiter(lock, &waiter, task);
82057
82058 /* add waiting tasks to the end of the waitqueue (FIFO): */
82059 list_add_tail(&waiter.list, &lock->wait_list);
82060@@ -565,7 +565,7 @@ slowpath:
82061 done:
82062 lock_acquired(&lock->dep_map, ip);
82063 /* got the lock - rejoice! */
82064- mutex_remove_waiter(lock, &waiter, current_thread_info());
82065+ mutex_remove_waiter(lock, &waiter, task);
82066 mutex_set_owner(lock);
82067
82068 if (!__builtin_constant_p(ww_ctx == NULL)) {
82069@@ -604,7 +604,7 @@ done:
82070 return 0;
82071
82072 err:
82073- mutex_remove_waiter(lock, &waiter, task_thread_info(task));
82074+ mutex_remove_waiter(lock, &waiter, task);
82075 spin_unlock_mutex(&lock->wait_lock, flags);
82076 debug_mutex_free_waiter(&waiter);
82077 mutex_release(&lock->dep_map, 1, ip);
82078diff --git a/kernel/notifier.c b/kernel/notifier.c
82079index 2d5cc4c..d9ea600 100644
82080--- a/kernel/notifier.c
82081+++ b/kernel/notifier.c
82082@@ -5,6 +5,7 @@
82083 #include <linux/rcupdate.h>
82084 #include <linux/vmalloc.h>
82085 #include <linux/reboot.h>
82086+#include <linux/mm.h>
82087
82088 /*
82089 * Notifier list for kernel code which wants to be called
82090@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
82091 while ((*nl) != NULL) {
82092 if (n->priority > (*nl)->priority)
82093 break;
82094- nl = &((*nl)->next);
82095+ nl = (struct notifier_block **)&((*nl)->next);
82096 }
82097- n->next = *nl;
82098+ pax_open_kernel();
82099+ *(const void **)&n->next = *nl;
82100 rcu_assign_pointer(*nl, n);
82101+ pax_close_kernel();
82102 return 0;
82103 }
82104
82105@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
82106 return 0;
82107 if (n->priority > (*nl)->priority)
82108 break;
82109- nl = &((*nl)->next);
82110+ nl = (struct notifier_block **)&((*nl)->next);
82111 }
82112- n->next = *nl;
82113+ pax_open_kernel();
82114+ *(const void **)&n->next = *nl;
82115 rcu_assign_pointer(*nl, n);
82116+ pax_close_kernel();
82117 return 0;
82118 }
82119
82120@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
82121 {
82122 while ((*nl) != NULL) {
82123 if ((*nl) == n) {
82124+ pax_open_kernel();
82125 rcu_assign_pointer(*nl, n->next);
82126+ pax_close_kernel();
82127 return 0;
82128 }
82129- nl = &((*nl)->next);
82130+ nl = (struct notifier_block **)&((*nl)->next);
82131 }
82132 return -ENOENT;
82133 }
82134diff --git a/kernel/panic.c b/kernel/panic.c
82135index 8018646..b6a5b4f 100644
82136--- a/kernel/panic.c
82137+++ b/kernel/panic.c
82138@@ -403,7 +403,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
82139 disable_trace_on_warning();
82140
82141 pr_warn("------------[ cut here ]------------\n");
82142- pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
82143+ pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
82144 raw_smp_processor_id(), current->pid, file, line, caller);
82145
82146 if (args)
82147@@ -457,7 +457,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
82148 */
82149 void __stack_chk_fail(void)
82150 {
82151- panic("stack-protector: Kernel stack is corrupted in: %p\n",
82152+ dump_stack();
82153+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
82154 __builtin_return_address(0));
82155 }
82156 EXPORT_SYMBOL(__stack_chk_fail);
82157diff --git a/kernel/pid.c b/kernel/pid.c
82158index ebe5e80..5d6d634 100644
82159--- a/kernel/pid.c
82160+++ b/kernel/pid.c
82161@@ -33,6 +33,7 @@
82162 #include <linux/rculist.h>
82163 #include <linux/bootmem.h>
82164 #include <linux/hash.h>
82165+#include <linux/security.h>
82166 #include <linux/pid_namespace.h>
82167 #include <linux/init_task.h>
82168 #include <linux/syscalls.h>
82169@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
82170
82171 int pid_max = PID_MAX_DEFAULT;
82172
82173-#define RESERVED_PIDS 300
82174+#define RESERVED_PIDS 500
82175
82176 int pid_max_min = RESERVED_PIDS + 1;
82177 int pid_max_max = PID_MAX_LIMIT;
82178@@ -440,10 +441,18 @@ EXPORT_SYMBOL(pid_task);
82179 */
82180 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
82181 {
82182+ struct task_struct *task;
82183+
82184 rcu_lockdep_assert(rcu_read_lock_held(),
82185 "find_task_by_pid_ns() needs rcu_read_lock()"
82186 " protection");
82187- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
82188+
82189+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
82190+
82191+ if (gr_pid_is_chrooted(task))
82192+ return NULL;
82193+
82194+ return task;
82195 }
82196
82197 struct task_struct *find_task_by_vpid(pid_t vnr)
82198@@ -451,6 +460,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
82199 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
82200 }
82201
82202+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
82203+{
82204+ rcu_lockdep_assert(rcu_read_lock_held(),
82205+ "find_task_by_pid_ns() needs rcu_read_lock()"
82206+ " protection");
82207+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
82208+}
82209+
82210 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
82211 {
82212 struct pid *pid;
82213diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
82214index 601bb36..f7e6f34 100644
82215--- a/kernel/pid_namespace.c
82216+++ b/kernel/pid_namespace.c
82217@@ -247,7 +247,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
82218 void __user *buffer, size_t *lenp, loff_t *ppos)
82219 {
82220 struct pid_namespace *pid_ns = task_active_pid_ns(current);
82221- struct ctl_table tmp = *table;
82222+ ctl_table_no_const tmp = *table;
82223
82224 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
82225 return -EPERM;
82226diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
82227index c7f31aa..2b44977 100644
82228--- a/kernel/posix-cpu-timers.c
82229+++ b/kernel/posix-cpu-timers.c
82230@@ -1521,14 +1521,14 @@ struct k_clock clock_posix_cpu = {
82231
82232 static __init int init_posix_cpu_timers(void)
82233 {
82234- struct k_clock process = {
82235+ static struct k_clock process = {
82236 .clock_getres = process_cpu_clock_getres,
82237 .clock_get = process_cpu_clock_get,
82238 .timer_create = process_cpu_timer_create,
82239 .nsleep = process_cpu_nsleep,
82240 .nsleep_restart = process_cpu_nsleep_restart,
82241 };
82242- struct k_clock thread = {
82243+ static struct k_clock thread = {
82244 .clock_getres = thread_cpu_clock_getres,
82245 .clock_get = thread_cpu_clock_get,
82246 .timer_create = thread_cpu_timer_create,
82247diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
82248index 424c2d4..679242f 100644
82249--- a/kernel/posix-timers.c
82250+++ b/kernel/posix-timers.c
82251@@ -43,6 +43,7 @@
82252 #include <linux/hash.h>
82253 #include <linux/posix-clock.h>
82254 #include <linux/posix-timers.h>
82255+#include <linux/grsecurity.h>
82256 #include <linux/syscalls.h>
82257 #include <linux/wait.h>
82258 #include <linux/workqueue.h>
82259@@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
82260 * which we beg off on and pass to do_sys_settimeofday().
82261 */
82262
82263-static struct k_clock posix_clocks[MAX_CLOCKS];
82264+static struct k_clock *posix_clocks[MAX_CLOCKS];
82265
82266 /*
82267 * These ones are defined below.
82268@@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
82269 */
82270 static __init int init_posix_timers(void)
82271 {
82272- struct k_clock clock_realtime = {
82273+ static struct k_clock clock_realtime = {
82274 .clock_getres = hrtimer_get_res,
82275 .clock_get = posix_clock_realtime_get,
82276 .clock_set = posix_clock_realtime_set,
82277@@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
82278 .timer_get = common_timer_get,
82279 .timer_del = common_timer_del,
82280 };
82281- struct k_clock clock_monotonic = {
82282+ static struct k_clock clock_monotonic = {
82283 .clock_getres = hrtimer_get_res,
82284 .clock_get = posix_ktime_get_ts,
82285 .nsleep = common_nsleep,
82286@@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
82287 .timer_get = common_timer_get,
82288 .timer_del = common_timer_del,
82289 };
82290- struct k_clock clock_monotonic_raw = {
82291+ static struct k_clock clock_monotonic_raw = {
82292 .clock_getres = hrtimer_get_res,
82293 .clock_get = posix_get_monotonic_raw,
82294 };
82295- struct k_clock clock_realtime_coarse = {
82296+ static struct k_clock clock_realtime_coarse = {
82297 .clock_getres = posix_get_coarse_res,
82298 .clock_get = posix_get_realtime_coarse,
82299 };
82300- struct k_clock clock_monotonic_coarse = {
82301+ static struct k_clock clock_monotonic_coarse = {
82302 .clock_getres = posix_get_coarse_res,
82303 .clock_get = posix_get_monotonic_coarse,
82304 };
82305- struct k_clock clock_tai = {
82306+ static struct k_clock clock_tai = {
82307 .clock_getres = hrtimer_get_res,
82308 .clock_get = posix_get_tai,
82309 .nsleep = common_nsleep,
82310@@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
82311 .timer_get = common_timer_get,
82312 .timer_del = common_timer_del,
82313 };
82314- struct k_clock clock_boottime = {
82315+ static struct k_clock clock_boottime = {
82316 .clock_getres = hrtimer_get_res,
82317 .clock_get = posix_get_boottime,
82318 .nsleep = common_nsleep,
82319@@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
82320 return;
82321 }
82322
82323- posix_clocks[clock_id] = *new_clock;
82324+ posix_clocks[clock_id] = new_clock;
82325 }
82326 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
82327
82328@@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
82329 return (id & CLOCKFD_MASK) == CLOCKFD ?
82330 &clock_posix_dynamic : &clock_posix_cpu;
82331
82332- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
82333+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
82334 return NULL;
82335- return &posix_clocks[id];
82336+ return posix_clocks[id];
82337 }
82338
82339 static int common_timer_create(struct k_itimer *new_timer)
82340@@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
82341 struct k_clock *kc = clockid_to_kclock(which_clock);
82342 struct k_itimer *new_timer;
82343 int error, new_timer_id;
82344- sigevent_t event;
82345+ sigevent_t event = { };
82346 int it_id_set = IT_ID_NOT_SET;
82347
82348 if (!kc)
82349@@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
82350 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
82351 return -EFAULT;
82352
82353+ /* only the CLOCK_REALTIME clock can be set, all other clocks
82354+ have their clock_set fptr set to a nosettime dummy function
82355+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
82356+ call common_clock_set, which calls do_sys_settimeofday, which
82357+ we hook
82358+ */
82359+
82360 return kc->clock_set(which_clock, &new_tp);
82361 }
82362
82363diff --git a/kernel/power/process.c b/kernel/power/process.c
82364index 06ec886..9dba35e 100644
82365--- a/kernel/power/process.c
82366+++ b/kernel/power/process.c
82367@@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
82368 unsigned int elapsed_msecs;
82369 bool wakeup = false;
82370 int sleep_usecs = USEC_PER_MSEC;
82371+ bool timedout = false;
82372
82373 do_gettimeofday(&start);
82374
82375@@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
82376
82377 while (true) {
82378 todo = 0;
82379+ if (time_after(jiffies, end_time))
82380+ timedout = true;
82381 read_lock(&tasklist_lock);
82382 do_each_thread(g, p) {
82383 if (p == current || !freeze_task(p))
82384 continue;
82385
82386- if (!freezer_should_skip(p))
82387+ if (!freezer_should_skip(p)) {
82388 todo++;
82389+ if (timedout) {
82390+ printk(KERN_ERR "Task refusing to freeze:\n");
82391+ sched_show_task(p);
82392+ }
82393+ }
82394 } while_each_thread(g, p);
82395 read_unlock(&tasklist_lock);
82396
82397@@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
82398 todo += wq_busy;
82399 }
82400
82401- if (!todo || time_after(jiffies, end_time))
82402+ if (!todo || timedout)
82403 break;
82404
82405 if (pm_wakeup_pending()) {
82406diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
82407index 5b5a708..ec7637e 100644
82408--- a/kernel/printk/printk.c
82409+++ b/kernel/printk/printk.c
82410@@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
82411 if (from_file && type != SYSLOG_ACTION_OPEN)
82412 return 0;
82413
82414+#ifdef CONFIG_GRKERNSEC_DMESG
82415+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
82416+ return -EPERM;
82417+#endif
82418+
82419 if (syslog_action_restricted(type)) {
82420 if (capable(CAP_SYSLOG))
82421 return 0;
82422diff --git a/kernel/profile.c b/kernel/profile.c
82423index 6631e1e..310c266 100644
82424--- a/kernel/profile.c
82425+++ b/kernel/profile.c
82426@@ -37,7 +37,7 @@ struct profile_hit {
82427 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
82428 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
82429
82430-static atomic_t *prof_buffer;
82431+static atomic_unchecked_t *prof_buffer;
82432 static unsigned long prof_len, prof_shift;
82433
82434 int prof_on __read_mostly;
82435@@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
82436 hits[i].pc = 0;
82437 continue;
82438 }
82439- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
82440+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
82441 hits[i].hits = hits[i].pc = 0;
82442 }
82443 }
82444@@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
82445 * Add the current hit(s) and flush the write-queue out
82446 * to the global buffer:
82447 */
82448- atomic_add(nr_hits, &prof_buffer[pc]);
82449+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
82450 for (i = 0; i < NR_PROFILE_HIT; ++i) {
82451- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
82452+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
82453 hits[i].pc = hits[i].hits = 0;
82454 }
82455 out:
82456@@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
82457 {
82458 unsigned long pc;
82459 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
82460- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
82461+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
82462 }
82463 #endif /* !CONFIG_SMP */
82464
82465@@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
82466 return -EFAULT;
82467 buf++; p++; count--; read++;
82468 }
82469- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
82470+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
82471 if (copy_to_user(buf, (void *)pnt, count))
82472 return -EFAULT;
82473 read += count;
82474@@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
82475 }
82476 #endif
82477 profile_discard_flip_buffers();
82478- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
82479+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
82480 return count;
82481 }
82482
82483diff --git a/kernel/ptrace.c b/kernel/ptrace.c
82484index a146ee3..ffed4c3 100644
82485--- a/kernel/ptrace.c
82486+++ b/kernel/ptrace.c
82487@@ -326,7 +326,7 @@ static int ptrace_attach(struct task_struct *task, long request,
82488 if (seize)
82489 flags |= PT_SEIZED;
82490 rcu_read_lock();
82491- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
82492+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
82493 flags |= PT_PTRACE_CAP;
82494 rcu_read_unlock();
82495 task->ptrace = flags;
82496@@ -537,7 +537,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
82497 break;
82498 return -EIO;
82499 }
82500- if (copy_to_user(dst, buf, retval))
82501+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
82502 return -EFAULT;
82503 copied += retval;
82504 src += retval;
82505@@ -805,7 +805,7 @@ int ptrace_request(struct task_struct *child, long request,
82506 bool seized = child->ptrace & PT_SEIZED;
82507 int ret = -EIO;
82508 siginfo_t siginfo, *si;
82509- void __user *datavp = (void __user *) data;
82510+ void __user *datavp = (__force void __user *) data;
82511 unsigned long __user *datalp = datavp;
82512 unsigned long flags;
82513
82514@@ -1051,14 +1051,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
82515 goto out;
82516 }
82517
82518+ if (gr_handle_ptrace(child, request)) {
82519+ ret = -EPERM;
82520+ goto out_put_task_struct;
82521+ }
82522+
82523 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
82524 ret = ptrace_attach(child, request, addr, data);
82525 /*
82526 * Some architectures need to do book-keeping after
82527 * a ptrace attach.
82528 */
82529- if (!ret)
82530+ if (!ret) {
82531 arch_ptrace_attach(child);
82532+ gr_audit_ptrace(child);
82533+ }
82534 goto out_put_task_struct;
82535 }
82536
82537@@ -1086,7 +1093,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
82538 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
82539 if (copied != sizeof(tmp))
82540 return -EIO;
82541- return put_user(tmp, (unsigned long __user *)data);
82542+ return put_user(tmp, (__force unsigned long __user *)data);
82543 }
82544
82545 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
82546@@ -1180,7 +1187,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
82547 }
82548
82549 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
82550- compat_long_t addr, compat_long_t data)
82551+ compat_ulong_t addr, compat_ulong_t data)
82552 {
82553 struct task_struct *child;
82554 long ret;
82555@@ -1196,14 +1203,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
82556 goto out;
82557 }
82558
82559+ if (gr_handle_ptrace(child, request)) {
82560+ ret = -EPERM;
82561+ goto out_put_task_struct;
82562+ }
82563+
82564 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
82565 ret = ptrace_attach(child, request, addr, data);
82566 /*
82567 * Some architectures need to do book-keeping after
82568 * a ptrace attach.
82569 */
82570- if (!ret)
82571+ if (!ret) {
82572 arch_ptrace_attach(child);
82573+ gr_audit_ptrace(child);
82574+ }
82575 goto out_put_task_struct;
82576 }
82577
82578diff --git a/kernel/rcupdate.c b/kernel/rcupdate.c
82579index cce6ba8..7c758b1f 100644
82580--- a/kernel/rcupdate.c
82581+++ b/kernel/rcupdate.c
82582@@ -412,10 +412,10 @@ int rcu_jiffies_till_stall_check(void)
82583 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
82584 */
82585 if (till_stall_check < 3) {
82586- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
82587+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
82588 till_stall_check = 3;
82589 } else if (till_stall_check > 300) {
82590- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
82591+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
82592 till_stall_check = 300;
82593 }
82594 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
82595diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
82596index aa34411..4832cd4 100644
82597--- a/kernel/rcutiny.c
82598+++ b/kernel/rcutiny.c
82599@@ -45,7 +45,7 @@
82600 /* Forward declarations for rcutiny_plugin.h. */
82601 struct rcu_ctrlblk;
82602 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
82603-static void rcu_process_callbacks(struct softirq_action *unused);
82604+static void rcu_process_callbacks(void);
82605 static void __call_rcu(struct rcu_head *head,
82606 void (*func)(struct rcu_head *rcu),
82607 struct rcu_ctrlblk *rcp);
82608@@ -309,7 +309,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
82609 false));
82610 }
82611
82612-static void rcu_process_callbacks(struct softirq_action *unused)
82613+static __latent_entropy void rcu_process_callbacks(void)
82614 {
82615 __rcu_process_callbacks(&rcu_sched_ctrlblk);
82616 __rcu_process_callbacks(&rcu_bh_ctrlblk);
82617diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
82618index f4871e5..8ef5741 100644
82619--- a/kernel/rcutorture.c
82620+++ b/kernel/rcutorture.c
82621@@ -164,12 +164,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
82622 { 0 };
82623 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
82624 { 0 };
82625-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
82626-static atomic_t n_rcu_torture_alloc;
82627-static atomic_t n_rcu_torture_alloc_fail;
82628-static atomic_t n_rcu_torture_free;
82629-static atomic_t n_rcu_torture_mberror;
82630-static atomic_t n_rcu_torture_error;
82631+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
82632+static atomic_unchecked_t n_rcu_torture_alloc;
82633+static atomic_unchecked_t n_rcu_torture_alloc_fail;
82634+static atomic_unchecked_t n_rcu_torture_free;
82635+static atomic_unchecked_t n_rcu_torture_mberror;
82636+static atomic_unchecked_t n_rcu_torture_error;
82637 static long n_rcu_torture_barrier_error;
82638 static long n_rcu_torture_boost_ktrerror;
82639 static long n_rcu_torture_boost_rterror;
82640@@ -287,11 +287,11 @@ rcu_torture_alloc(void)
82641
82642 spin_lock_bh(&rcu_torture_lock);
82643 if (list_empty(&rcu_torture_freelist)) {
82644- atomic_inc(&n_rcu_torture_alloc_fail);
82645+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
82646 spin_unlock_bh(&rcu_torture_lock);
82647 return NULL;
82648 }
82649- atomic_inc(&n_rcu_torture_alloc);
82650+ atomic_inc_unchecked(&n_rcu_torture_alloc);
82651 p = rcu_torture_freelist.next;
82652 list_del_init(p);
82653 spin_unlock_bh(&rcu_torture_lock);
82654@@ -304,7 +304,7 @@ rcu_torture_alloc(void)
82655 static void
82656 rcu_torture_free(struct rcu_torture *p)
82657 {
82658- atomic_inc(&n_rcu_torture_free);
82659+ atomic_inc_unchecked(&n_rcu_torture_free);
82660 spin_lock_bh(&rcu_torture_lock);
82661 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
82662 spin_unlock_bh(&rcu_torture_lock);
82663@@ -424,7 +424,7 @@ rcu_torture_cb(struct rcu_head *p)
82664 i = rp->rtort_pipe_count;
82665 if (i > RCU_TORTURE_PIPE_LEN)
82666 i = RCU_TORTURE_PIPE_LEN;
82667- atomic_inc(&rcu_torture_wcount[i]);
82668+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
82669 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
82670 rp->rtort_mbtest = 0;
82671 rcu_torture_free(rp);
82672@@ -472,7 +472,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
82673 i = rp->rtort_pipe_count;
82674 if (i > RCU_TORTURE_PIPE_LEN)
82675 i = RCU_TORTURE_PIPE_LEN;
82676- atomic_inc(&rcu_torture_wcount[i]);
82677+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
82678 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
82679 rp->rtort_mbtest = 0;
82680 list_del(&rp->rtort_free);
82681@@ -952,7 +952,7 @@ rcu_torture_writer(void *arg)
82682 i = old_rp->rtort_pipe_count;
82683 if (i > RCU_TORTURE_PIPE_LEN)
82684 i = RCU_TORTURE_PIPE_LEN;
82685- atomic_inc(&rcu_torture_wcount[i]);
82686+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
82687 old_rp->rtort_pipe_count++;
82688 cur_ops->deferred_free(old_rp);
82689 }
82690@@ -1038,7 +1038,7 @@ static void rcu_torture_timer(unsigned long unused)
82691 return;
82692 }
82693 if (p->rtort_mbtest == 0)
82694- atomic_inc(&n_rcu_torture_mberror);
82695+ atomic_inc_unchecked(&n_rcu_torture_mberror);
82696 spin_lock(&rand_lock);
82697 cur_ops->read_delay(&rand);
82698 n_rcu_torture_timers++;
82699@@ -1108,7 +1108,7 @@ rcu_torture_reader(void *arg)
82700 continue;
82701 }
82702 if (p->rtort_mbtest == 0)
82703- atomic_inc(&n_rcu_torture_mberror);
82704+ atomic_inc_unchecked(&n_rcu_torture_mberror);
82705 cur_ops->read_delay(&rand);
82706 preempt_disable();
82707 pipe_count = p->rtort_pipe_count;
82708@@ -1171,11 +1171,11 @@ rcu_torture_printk(char *page)
82709 rcu_torture_current,
82710 rcu_torture_current_version,
82711 list_empty(&rcu_torture_freelist),
82712- atomic_read(&n_rcu_torture_alloc),
82713- atomic_read(&n_rcu_torture_alloc_fail),
82714- atomic_read(&n_rcu_torture_free));
82715+ atomic_read_unchecked(&n_rcu_torture_alloc),
82716+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
82717+ atomic_read_unchecked(&n_rcu_torture_free));
82718 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
82719- atomic_read(&n_rcu_torture_mberror),
82720+ atomic_read_unchecked(&n_rcu_torture_mberror),
82721 n_rcu_torture_boost_ktrerror,
82722 n_rcu_torture_boost_rterror);
82723 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
82724@@ -1194,14 +1194,14 @@ rcu_torture_printk(char *page)
82725 n_barrier_attempts,
82726 n_rcu_torture_barrier_error);
82727 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
82728- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
82729+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
82730 n_rcu_torture_barrier_error != 0 ||
82731 n_rcu_torture_boost_ktrerror != 0 ||
82732 n_rcu_torture_boost_rterror != 0 ||
82733 n_rcu_torture_boost_failure != 0 ||
82734 i > 1) {
82735 cnt += sprintf(&page[cnt], "!!! ");
82736- atomic_inc(&n_rcu_torture_error);
82737+ atomic_inc_unchecked(&n_rcu_torture_error);
82738 WARN_ON_ONCE(1);
82739 }
82740 cnt += sprintf(&page[cnt], "Reader Pipe: ");
82741@@ -1215,7 +1215,7 @@ rcu_torture_printk(char *page)
82742 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
82743 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
82744 cnt += sprintf(&page[cnt], " %d",
82745- atomic_read(&rcu_torture_wcount[i]));
82746+ atomic_read_unchecked(&rcu_torture_wcount[i]));
82747 }
82748 cnt += sprintf(&page[cnt], "\n");
82749 if (cur_ops->stats)
82750@@ -1924,7 +1924,7 @@ rcu_torture_cleanup(void)
82751
82752 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
82753
82754- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
82755+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
82756 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
82757 else if (n_online_successes != n_online_attempts ||
82758 n_offline_successes != n_offline_attempts)
82759@@ -1992,18 +1992,18 @@ rcu_torture_init(void)
82760
82761 rcu_torture_current = NULL;
82762 rcu_torture_current_version = 0;
82763- atomic_set(&n_rcu_torture_alloc, 0);
82764- atomic_set(&n_rcu_torture_alloc_fail, 0);
82765- atomic_set(&n_rcu_torture_free, 0);
82766- atomic_set(&n_rcu_torture_mberror, 0);
82767- atomic_set(&n_rcu_torture_error, 0);
82768+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
82769+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
82770+ atomic_set_unchecked(&n_rcu_torture_free, 0);
82771+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
82772+ atomic_set_unchecked(&n_rcu_torture_error, 0);
82773 n_rcu_torture_barrier_error = 0;
82774 n_rcu_torture_boost_ktrerror = 0;
82775 n_rcu_torture_boost_rterror = 0;
82776 n_rcu_torture_boost_failure = 0;
82777 n_rcu_torture_boosts = 0;
82778 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
82779- atomic_set(&rcu_torture_wcount[i], 0);
82780+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
82781 for_each_possible_cpu(cpu) {
82782 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
82783 per_cpu(rcu_torture_count, cpu)[i] = 0;
82784diff --git a/kernel/rcutree.c b/kernel/rcutree.c
82785index 068de3a..5e7db2f 100644
82786--- a/kernel/rcutree.c
82787+++ b/kernel/rcutree.c
82788@@ -358,9 +358,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
82789 rcu_prepare_for_idle(smp_processor_id());
82790 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
82791 smp_mb__before_atomic_inc(); /* See above. */
82792- atomic_inc(&rdtp->dynticks);
82793+ atomic_inc_unchecked(&rdtp->dynticks);
82794 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
82795- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
82796+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
82797
82798 /*
82799 * It is illegal to enter an extended quiescent state while
82800@@ -496,10 +496,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
82801 int user)
82802 {
82803 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
82804- atomic_inc(&rdtp->dynticks);
82805+ atomic_inc_unchecked(&rdtp->dynticks);
82806 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
82807 smp_mb__after_atomic_inc(); /* See above. */
82808- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
82809+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
82810 rcu_cleanup_after_idle(smp_processor_id());
82811 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
82812 if (!user && !is_idle_task(current)) {
82813@@ -638,14 +638,14 @@ void rcu_nmi_enter(void)
82814 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
82815
82816 if (rdtp->dynticks_nmi_nesting == 0 &&
82817- (atomic_read(&rdtp->dynticks) & 0x1))
82818+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
82819 return;
82820 rdtp->dynticks_nmi_nesting++;
82821 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
82822- atomic_inc(&rdtp->dynticks);
82823+ atomic_inc_unchecked(&rdtp->dynticks);
82824 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
82825 smp_mb__after_atomic_inc(); /* See above. */
82826- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
82827+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
82828 }
82829
82830 /**
82831@@ -664,9 +664,9 @@ void rcu_nmi_exit(void)
82832 return;
82833 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
82834 smp_mb__before_atomic_inc(); /* See above. */
82835- atomic_inc(&rdtp->dynticks);
82836+ atomic_inc_unchecked(&rdtp->dynticks);
82837 smp_mb__after_atomic_inc(); /* Force delay to next write. */
82838- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
82839+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
82840 }
82841
82842 /**
82843@@ -680,7 +680,7 @@ int rcu_is_cpu_idle(void)
82844 int ret;
82845
82846 preempt_disable();
82847- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
82848+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
82849 preempt_enable();
82850 return ret;
82851 }
82852@@ -748,7 +748,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
82853 */
82854 static int dyntick_save_progress_counter(struct rcu_data *rdp)
82855 {
82856- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
82857+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
82858 return (rdp->dynticks_snap & 0x1) == 0;
82859 }
82860
82861@@ -763,7 +763,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
82862 unsigned int curr;
82863 unsigned int snap;
82864
82865- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
82866+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
82867 snap = (unsigned int)rdp->dynticks_snap;
82868
82869 /*
82870@@ -1351,9 +1351,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
82871 rdp = this_cpu_ptr(rsp->rda);
82872 rcu_preempt_check_blocked_tasks(rnp);
82873 rnp->qsmask = rnp->qsmaskinit;
82874- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
82875+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
82876 WARN_ON_ONCE(rnp->completed != rsp->completed);
82877- ACCESS_ONCE(rnp->completed) = rsp->completed;
82878+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
82879 if (rnp == rdp->mynode)
82880 __note_gp_changes(rsp, rnp, rdp);
82881 rcu_preempt_boost_start_gp(rnp);
82882@@ -1435,7 +1435,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
82883 */
82884 rcu_for_each_node_breadth_first(rsp, rnp) {
82885 raw_spin_lock_irq(&rnp->lock);
82886- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
82887+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
82888 rdp = this_cpu_ptr(rsp->rda);
82889 if (rnp == rdp->mynode)
82890 __note_gp_changes(rsp, rnp, rdp);
82891@@ -1765,7 +1765,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
82892 rsp->qlen += rdp->qlen;
82893 rdp->n_cbs_orphaned += rdp->qlen;
82894 rdp->qlen_lazy = 0;
82895- ACCESS_ONCE(rdp->qlen) = 0;
82896+ ACCESS_ONCE_RW(rdp->qlen) = 0;
82897 }
82898
82899 /*
82900@@ -2011,7 +2011,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
82901 }
82902 smp_mb(); /* List handling before counting for rcu_barrier(). */
82903 rdp->qlen_lazy -= count_lazy;
82904- ACCESS_ONCE(rdp->qlen) -= count;
82905+ ACCESS_ONCE_RW(rdp->qlen) -= count;
82906 rdp->n_cbs_invoked += count;
82907
82908 /* Reinstate batch limit if we have worked down the excess. */
82909@@ -2202,7 +2202,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
82910 /*
82911 * Do RCU core processing for the current CPU.
82912 */
82913-static void rcu_process_callbacks(struct softirq_action *unused)
82914+static __latent_entropy void rcu_process_callbacks(void)
82915 {
82916 struct rcu_state *rsp;
82917
82918@@ -2325,7 +2325,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
82919 local_irq_restore(flags);
82920 return;
82921 }
82922- ACCESS_ONCE(rdp->qlen)++;
82923+ ACCESS_ONCE_RW(rdp->qlen)++;
82924 if (lazy)
82925 rdp->qlen_lazy++;
82926 else
82927@@ -2534,11 +2534,11 @@ void synchronize_sched_expedited(void)
82928 * counter wrap on a 32-bit system. Quite a few more CPUs would of
82929 * course be required on a 64-bit system.
82930 */
82931- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
82932+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
82933 (ulong)atomic_long_read(&rsp->expedited_done) +
82934 ULONG_MAX / 8)) {
82935 synchronize_sched();
82936- atomic_long_inc(&rsp->expedited_wrap);
82937+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
82938 return;
82939 }
82940
82941@@ -2546,7 +2546,7 @@ void synchronize_sched_expedited(void)
82942 * Take a ticket. Note that atomic_inc_return() implies a
82943 * full memory barrier.
82944 */
82945- snap = atomic_long_inc_return(&rsp->expedited_start);
82946+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
82947 firstsnap = snap;
82948 get_online_cpus();
82949 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
82950@@ -2559,14 +2559,14 @@ void synchronize_sched_expedited(void)
82951 synchronize_sched_expedited_cpu_stop,
82952 NULL) == -EAGAIN) {
82953 put_online_cpus();
82954- atomic_long_inc(&rsp->expedited_tryfail);
82955+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
82956
82957 /* Check to see if someone else did our work for us. */
82958 s = atomic_long_read(&rsp->expedited_done);
82959 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
82960 /* ensure test happens before caller kfree */
82961 smp_mb__before_atomic_inc(); /* ^^^ */
82962- atomic_long_inc(&rsp->expedited_workdone1);
82963+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
82964 return;
82965 }
82966
82967@@ -2575,7 +2575,7 @@ void synchronize_sched_expedited(void)
82968 udelay(trycount * num_online_cpus());
82969 } else {
82970 wait_rcu_gp(call_rcu_sched);
82971- atomic_long_inc(&rsp->expedited_normal);
82972+ atomic_long_inc_unchecked(&rsp->expedited_normal);
82973 return;
82974 }
82975
82976@@ -2584,7 +2584,7 @@ void synchronize_sched_expedited(void)
82977 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
82978 /* ensure test happens before caller kfree */
82979 smp_mb__before_atomic_inc(); /* ^^^ */
82980- atomic_long_inc(&rsp->expedited_workdone2);
82981+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
82982 return;
82983 }
82984
82985@@ -2596,10 +2596,10 @@ void synchronize_sched_expedited(void)
82986 * period works for us.
82987 */
82988 get_online_cpus();
82989- snap = atomic_long_read(&rsp->expedited_start);
82990+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
82991 smp_mb(); /* ensure read is before try_stop_cpus(). */
82992 }
82993- atomic_long_inc(&rsp->expedited_stoppedcpus);
82994+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
82995
82996 /*
82997 * Everyone up to our most recent fetch is covered by our grace
82998@@ -2608,16 +2608,16 @@ void synchronize_sched_expedited(void)
82999 * than we did already did their update.
83000 */
83001 do {
83002- atomic_long_inc(&rsp->expedited_done_tries);
83003+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
83004 s = atomic_long_read(&rsp->expedited_done);
83005 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
83006 /* ensure test happens before caller kfree */
83007 smp_mb__before_atomic_inc(); /* ^^^ */
83008- atomic_long_inc(&rsp->expedited_done_lost);
83009+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
83010 break;
83011 }
83012 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
83013- atomic_long_inc(&rsp->expedited_done_exit);
83014+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
83015
83016 put_online_cpus();
83017 }
83018@@ -2799,7 +2799,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
83019 * ACCESS_ONCE() to prevent the compiler from speculating
83020 * the increment to precede the early-exit check.
83021 */
83022- ACCESS_ONCE(rsp->n_barrier_done)++;
83023+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
83024 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
83025 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
83026 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
83027@@ -2849,7 +2849,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
83028
83029 /* Increment ->n_barrier_done to prevent duplicate work. */
83030 smp_mb(); /* Keep increment after above mechanism. */
83031- ACCESS_ONCE(rsp->n_barrier_done)++;
83032+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
83033 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
83034 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
83035 smp_mb(); /* Keep increment before caller's subsequent code. */
83036@@ -2894,10 +2894,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
83037 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
83038 init_callback_list(rdp);
83039 rdp->qlen_lazy = 0;
83040- ACCESS_ONCE(rdp->qlen) = 0;
83041+ ACCESS_ONCE_RW(rdp->qlen) = 0;
83042 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
83043 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
83044- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
83045+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
83046 rdp->cpu = cpu;
83047 rdp->rsp = rsp;
83048 rcu_boot_init_nocb_percpu_data(rdp);
83049@@ -2930,8 +2930,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
83050 rdp->blimit = blimit;
83051 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
83052 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
83053- atomic_set(&rdp->dynticks->dynticks,
83054- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
83055+ atomic_set_unchecked(&rdp->dynticks->dynticks,
83056+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
83057 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
83058
83059 /* Add CPU to rcu_node bitmasks. */
83060diff --git a/kernel/rcutree.h b/kernel/rcutree.h
83061index b383258..2440c1e 100644
83062--- a/kernel/rcutree.h
83063+++ b/kernel/rcutree.h
83064@@ -87,7 +87,7 @@ struct rcu_dynticks {
83065 long long dynticks_nesting; /* Track irq/process nesting level. */
83066 /* Process level is worth LLONG_MAX/2. */
83067 int dynticks_nmi_nesting; /* Track NMI nesting level. */
83068- atomic_t dynticks; /* Even value for idle, else odd. */
83069+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
83070 #ifdef CONFIG_RCU_FAST_NO_HZ
83071 bool all_lazy; /* Are all CPU's CBs lazy? */
83072 unsigned long nonlazy_posted;
83073@@ -419,17 +419,17 @@ struct rcu_state {
83074 /* _rcu_barrier(). */
83075 /* End of fields guarded by barrier_mutex. */
83076
83077- atomic_long_t expedited_start; /* Starting ticket. */
83078- atomic_long_t expedited_done; /* Done ticket. */
83079- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
83080- atomic_long_t expedited_tryfail; /* # acquisition failures. */
83081- atomic_long_t expedited_workdone1; /* # done by others #1. */
83082- atomic_long_t expedited_workdone2; /* # done by others #2. */
83083- atomic_long_t expedited_normal; /* # fallbacks to normal. */
83084- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
83085- atomic_long_t expedited_done_tries; /* # tries to update _done. */
83086- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
83087- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
83088+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
83089+ atomic_long_t expedited_done; /* Done ticket. */
83090+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
83091+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
83092+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
83093+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
83094+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
83095+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
83096+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
83097+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
83098+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
83099
83100 unsigned long jiffies_force_qs; /* Time at which to invoke */
83101 /* force_quiescent_state(). */
83102diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
83103index 769e12e..7b2139b 100644
83104--- a/kernel/rcutree_plugin.h
83105+++ b/kernel/rcutree_plugin.h
83106@@ -902,7 +902,7 @@ void synchronize_rcu_expedited(void)
83107
83108 /* Clean up and exit. */
83109 smp_mb(); /* ensure expedited GP seen before counter increment. */
83110- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
83111+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
83112 unlock_mb_ret:
83113 mutex_unlock(&sync_rcu_preempt_exp_mutex);
83114 mb_ret:
83115@@ -1476,7 +1476,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
83116 free_cpumask_var(cm);
83117 }
83118
83119-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
83120+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
83121 .store = &rcu_cpu_kthread_task,
83122 .thread_should_run = rcu_cpu_kthread_should_run,
83123 .thread_fn = rcu_cpu_kthread,
83124@@ -1941,7 +1941,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
83125 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
83126 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
83127 cpu, ticks_value, ticks_title,
83128- atomic_read(&rdtp->dynticks) & 0xfff,
83129+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
83130 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
83131 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
83132 fast_no_hz);
83133@@ -2104,7 +2104,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
83134
83135 /* Enqueue the callback on the nocb list and update counts. */
83136 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
83137- ACCESS_ONCE(*old_rhpp) = rhp;
83138+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
83139 atomic_long_add(rhcount, &rdp->nocb_q_count);
83140 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
83141
83142@@ -2244,12 +2244,12 @@ static int rcu_nocb_kthread(void *arg)
83143 * Extract queued callbacks, update counts, and wait
83144 * for a grace period to elapse.
83145 */
83146- ACCESS_ONCE(rdp->nocb_head) = NULL;
83147+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
83148 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
83149 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
83150 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
83151- ACCESS_ONCE(rdp->nocb_p_count) += c;
83152- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
83153+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
83154+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
83155 rcu_nocb_wait_gp(rdp);
83156
83157 /* Each pass through the following loop invokes a callback. */
83158@@ -2271,8 +2271,8 @@ static int rcu_nocb_kthread(void *arg)
83159 list = next;
83160 }
83161 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
83162- ACCESS_ONCE(rdp->nocb_p_count) -= c;
83163- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
83164+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
83165+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
83166 rdp->n_nocbs_invoked += c;
83167 }
83168 return 0;
83169@@ -2299,7 +2299,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
83170 t = kthread_run(rcu_nocb_kthread, rdp,
83171 "rcuo%c/%d", rsp->abbr, cpu);
83172 BUG_ON(IS_ERR(t));
83173- ACCESS_ONCE(rdp->nocb_kthread) = t;
83174+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
83175 }
83176 }
83177
83178diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
83179index cf6c174..a8f4b50 100644
83180--- a/kernel/rcutree_trace.c
83181+++ b/kernel/rcutree_trace.c
83182@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
83183 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
83184 rdp->passed_quiesce, rdp->qs_pending);
83185 seq_printf(m, " dt=%d/%llx/%d df=%lu",
83186- atomic_read(&rdp->dynticks->dynticks),
83187+ atomic_read_unchecked(&rdp->dynticks->dynticks),
83188 rdp->dynticks->dynticks_nesting,
83189 rdp->dynticks->dynticks_nmi_nesting,
83190 rdp->dynticks_fqs);
83191@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
83192 struct rcu_state *rsp = (struct rcu_state *)m->private;
83193
83194 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",
83195- atomic_long_read(&rsp->expedited_start),
83196+ atomic_long_read_unchecked(&rsp->expedited_start),
83197 atomic_long_read(&rsp->expedited_done),
83198- atomic_long_read(&rsp->expedited_wrap),
83199- atomic_long_read(&rsp->expedited_tryfail),
83200- atomic_long_read(&rsp->expedited_workdone1),
83201- atomic_long_read(&rsp->expedited_workdone2),
83202- atomic_long_read(&rsp->expedited_normal),
83203- atomic_long_read(&rsp->expedited_stoppedcpus),
83204- atomic_long_read(&rsp->expedited_done_tries),
83205- atomic_long_read(&rsp->expedited_done_lost),
83206- atomic_long_read(&rsp->expedited_done_exit));
83207+ atomic_long_read_unchecked(&rsp->expedited_wrap),
83208+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
83209+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
83210+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
83211+ atomic_long_read_unchecked(&rsp->expedited_normal),
83212+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
83213+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
83214+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
83215+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
83216 return 0;
83217 }
83218
83219diff --git a/kernel/resource.c b/kernel/resource.c
83220index 3f285dc..5755f62 100644
83221--- a/kernel/resource.c
83222+++ b/kernel/resource.c
83223@@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
83224
83225 static int __init ioresources_init(void)
83226 {
83227+#ifdef CONFIG_GRKERNSEC_PROC_ADD
83228+#ifdef CONFIG_GRKERNSEC_PROC_USER
83229+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
83230+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
83231+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
83232+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
83233+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
83234+#endif
83235+#else
83236 proc_create("ioports", 0, NULL, &proc_ioports_operations);
83237 proc_create("iomem", 0, NULL, &proc_iomem_operations);
83238+#endif
83239 return 0;
83240 }
83241 __initcall(ioresources_init);
83242diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
83243index 1d96dd0..994ff19 100644
83244--- a/kernel/rtmutex-tester.c
83245+++ b/kernel/rtmutex-tester.c
83246@@ -22,7 +22,7 @@
83247 #define MAX_RT_TEST_MUTEXES 8
83248
83249 static spinlock_t rttest_lock;
83250-static atomic_t rttest_event;
83251+static atomic_unchecked_t rttest_event;
83252
83253 struct test_thread_data {
83254 int opcode;
83255@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83256
83257 case RTTEST_LOCKCONT:
83258 td->mutexes[td->opdata] = 1;
83259- td->event = atomic_add_return(1, &rttest_event);
83260+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83261 return 0;
83262
83263 case RTTEST_RESET:
83264@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83265 return 0;
83266
83267 case RTTEST_RESETEVENT:
83268- atomic_set(&rttest_event, 0);
83269+ atomic_set_unchecked(&rttest_event, 0);
83270 return 0;
83271
83272 default:
83273@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83274 return ret;
83275
83276 td->mutexes[id] = 1;
83277- td->event = atomic_add_return(1, &rttest_event);
83278+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83279 rt_mutex_lock(&mutexes[id]);
83280- td->event = atomic_add_return(1, &rttest_event);
83281+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83282 td->mutexes[id] = 4;
83283 return 0;
83284
83285@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83286 return ret;
83287
83288 td->mutexes[id] = 1;
83289- td->event = atomic_add_return(1, &rttest_event);
83290+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83291 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
83292- td->event = atomic_add_return(1, &rttest_event);
83293+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83294 td->mutexes[id] = ret ? 0 : 4;
83295 return ret ? -EINTR : 0;
83296
83297@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83298 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
83299 return ret;
83300
83301- td->event = atomic_add_return(1, &rttest_event);
83302+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83303 rt_mutex_unlock(&mutexes[id]);
83304- td->event = atomic_add_return(1, &rttest_event);
83305+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83306 td->mutexes[id] = 0;
83307 return 0;
83308
83309@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
83310 break;
83311
83312 td->mutexes[dat] = 2;
83313- td->event = atomic_add_return(1, &rttest_event);
83314+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83315 break;
83316
83317 default:
83318@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
83319 return;
83320
83321 td->mutexes[dat] = 3;
83322- td->event = atomic_add_return(1, &rttest_event);
83323+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83324 break;
83325
83326 case RTTEST_LOCKNOWAIT:
83327@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
83328 return;
83329
83330 td->mutexes[dat] = 1;
83331- td->event = atomic_add_return(1, &rttest_event);
83332+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83333 return;
83334
83335 default:
83336diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
83337index 4a07353..66b5291 100644
83338--- a/kernel/sched/auto_group.c
83339+++ b/kernel/sched/auto_group.c
83340@@ -11,7 +11,7 @@
83341
83342 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
83343 static struct autogroup autogroup_default;
83344-static atomic_t autogroup_seq_nr;
83345+static atomic_unchecked_t autogroup_seq_nr;
83346
83347 void __init autogroup_init(struct task_struct *init_task)
83348 {
83349@@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
83350
83351 kref_init(&ag->kref);
83352 init_rwsem(&ag->lock);
83353- ag->id = atomic_inc_return(&autogroup_seq_nr);
83354+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
83355 ag->tg = tg;
83356 #ifdef CONFIG_RT_GROUP_SCHED
83357 /*
83358diff --git a/kernel/sched/core.c b/kernel/sched/core.c
83359index 05c39f0..442e6fe 100644
83360--- a/kernel/sched/core.c
83361+++ b/kernel/sched/core.c
83362@@ -2885,7 +2885,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
83363 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
83364 * or number of jiffies left till timeout) if completed.
83365 */
83366-long __sched
83367+long __sched __intentional_overflow(-1)
83368 wait_for_completion_interruptible_timeout(struct completion *x,
83369 unsigned long timeout)
83370 {
83371@@ -2902,7 +2902,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
83372 *
83373 * Return: -ERESTARTSYS if interrupted, 0 if completed.
83374 */
83375-int __sched wait_for_completion_killable(struct completion *x)
83376+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
83377 {
83378 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
83379 if (t == -ERESTARTSYS)
83380@@ -2923,7 +2923,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
83381 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
83382 * or number of jiffies left till timeout) if completed.
83383 */
83384-long __sched
83385+long __sched __intentional_overflow(-1)
83386 wait_for_completion_killable_timeout(struct completion *x,
83387 unsigned long timeout)
83388 {
83389@@ -3149,6 +3149,8 @@ int can_nice(const struct task_struct *p, const int nice)
83390 /* convert nice value [19,-20] to rlimit style value [1,40] */
83391 int nice_rlim = 20 - nice;
83392
83393+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
83394+
83395 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
83396 capable(CAP_SYS_NICE));
83397 }
83398@@ -3182,7 +3184,8 @@ SYSCALL_DEFINE1(nice, int, increment)
83399 if (nice > 19)
83400 nice = 19;
83401
83402- if (increment < 0 && !can_nice(current, nice))
83403+ if (increment < 0 && (!can_nice(current, nice) ||
83404+ gr_handle_chroot_nice()))
83405 return -EPERM;
83406
83407 retval = security_task_setnice(current, nice);
83408@@ -3344,6 +3347,7 @@ recheck:
83409 unsigned long rlim_rtprio =
83410 task_rlimit(p, RLIMIT_RTPRIO);
83411
83412+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
83413 /* can't set/change the rt policy */
83414 if (policy != p->policy && !rlim_rtprio)
83415 return -EPERM;
83416@@ -4473,7 +4477,7 @@ static void migrate_tasks(unsigned int dead_cpu)
83417
83418 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
83419
83420-static struct ctl_table sd_ctl_dir[] = {
83421+static ctl_table_no_const sd_ctl_dir[] __read_only = {
83422 {
83423 .procname = "sched_domain",
83424 .mode = 0555,
83425@@ -4490,17 +4494,17 @@ static struct ctl_table sd_ctl_root[] = {
83426 {}
83427 };
83428
83429-static struct ctl_table *sd_alloc_ctl_entry(int n)
83430+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
83431 {
83432- struct ctl_table *entry =
83433+ ctl_table_no_const *entry =
83434 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
83435
83436 return entry;
83437 }
83438
83439-static void sd_free_ctl_entry(struct ctl_table **tablep)
83440+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
83441 {
83442- struct ctl_table *entry;
83443+ ctl_table_no_const *entry;
83444
83445 /*
83446 * In the intermediate directories, both the child directory and
83447@@ -4508,22 +4512,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
83448 * will always be set. In the lowest directory the names are
83449 * static strings and all have proc handlers.
83450 */
83451- for (entry = *tablep; entry->mode; entry++) {
83452- if (entry->child)
83453- sd_free_ctl_entry(&entry->child);
83454+ for (entry = tablep; entry->mode; entry++) {
83455+ if (entry->child) {
83456+ sd_free_ctl_entry(entry->child);
83457+ pax_open_kernel();
83458+ entry->child = NULL;
83459+ pax_close_kernel();
83460+ }
83461 if (entry->proc_handler == NULL)
83462 kfree(entry->procname);
83463 }
83464
83465- kfree(*tablep);
83466- *tablep = NULL;
83467+ kfree(tablep);
83468 }
83469
83470 static int min_load_idx = 0;
83471 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
83472
83473 static void
83474-set_table_entry(struct ctl_table *entry,
83475+set_table_entry(ctl_table_no_const *entry,
83476 const char *procname, void *data, int maxlen,
83477 umode_t mode, proc_handler *proc_handler,
83478 bool load_idx)
83479@@ -4543,7 +4550,7 @@ set_table_entry(struct ctl_table *entry,
83480 static struct ctl_table *
83481 sd_alloc_ctl_domain_table(struct sched_domain *sd)
83482 {
83483- struct ctl_table *table = sd_alloc_ctl_entry(13);
83484+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
83485
83486 if (table == NULL)
83487 return NULL;
83488@@ -4578,9 +4585,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
83489 return table;
83490 }
83491
83492-static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
83493+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
83494 {
83495- struct ctl_table *entry, *table;
83496+ ctl_table_no_const *entry, *table;
83497 struct sched_domain *sd;
83498 int domain_num = 0, i;
83499 char buf[32];
83500@@ -4607,11 +4614,13 @@ static struct ctl_table_header *sd_sysctl_header;
83501 static void register_sched_domain_sysctl(void)
83502 {
83503 int i, cpu_num = num_possible_cpus();
83504- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
83505+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
83506 char buf[32];
83507
83508 WARN_ON(sd_ctl_dir[0].child);
83509+ pax_open_kernel();
83510 sd_ctl_dir[0].child = entry;
83511+ pax_close_kernel();
83512
83513 if (entry == NULL)
83514 return;
83515@@ -4634,8 +4643,12 @@ static void unregister_sched_domain_sysctl(void)
83516 if (sd_sysctl_header)
83517 unregister_sysctl_table(sd_sysctl_header);
83518 sd_sysctl_header = NULL;
83519- if (sd_ctl_dir[0].child)
83520- sd_free_ctl_entry(&sd_ctl_dir[0].child);
83521+ if (sd_ctl_dir[0].child) {
83522+ sd_free_ctl_entry(sd_ctl_dir[0].child);
83523+ pax_open_kernel();
83524+ sd_ctl_dir[0].child = NULL;
83525+ pax_close_kernel();
83526+ }
83527 }
83528 #else
83529 static void register_sched_domain_sysctl(void)
83530diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
83531index 31cbc15..ba68c15 100644
83532--- a/kernel/sched/fair.c
83533+++ b/kernel/sched/fair.c
83534@@ -869,7 +869,7 @@ void task_numa_fault(int node, int pages, bool migrated)
83535
83536 static void reset_ptenuma_scan(struct task_struct *p)
83537 {
83538- ACCESS_ONCE(p->mm->numa_scan_seq)++;
83539+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
83540 p->mm->numa_scan_offset = 0;
83541 }
83542
83543@@ -5727,7 +5727,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
83544 * run_rebalance_domains is triggered when needed from the scheduler tick.
83545 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
83546 */
83547-static void run_rebalance_domains(struct softirq_action *h)
83548+static __latent_entropy void run_rebalance_domains(void)
83549 {
83550 int this_cpu = smp_processor_id();
83551 struct rq *this_rq = cpu_rq(this_cpu);
83552diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
83553index ef0a7b2..1b728c1 100644
83554--- a/kernel/sched/sched.h
83555+++ b/kernel/sched/sched.h
83556@@ -1004,7 +1004,7 @@ struct sched_class {
83557 #ifdef CONFIG_FAIR_GROUP_SCHED
83558 void (*task_move_group) (struct task_struct *p, int on_rq);
83559 #endif
83560-};
83561+} __do_const;
83562
83563 #define sched_class_highest (&stop_sched_class)
83564 #define for_each_class(class) \
83565diff --git a/kernel/signal.c b/kernel/signal.c
83566index 50e4107..9409983 100644
83567--- a/kernel/signal.c
83568+++ b/kernel/signal.c
83569@@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
83570
83571 int print_fatal_signals __read_mostly;
83572
83573-static void __user *sig_handler(struct task_struct *t, int sig)
83574+static __sighandler_t sig_handler(struct task_struct *t, int sig)
83575 {
83576 return t->sighand->action[sig - 1].sa.sa_handler;
83577 }
83578
83579-static int sig_handler_ignored(void __user *handler, int sig)
83580+static int sig_handler_ignored(__sighandler_t handler, int sig)
83581 {
83582 /* Is it explicitly or implicitly ignored? */
83583 return handler == SIG_IGN ||
83584@@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
83585
83586 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
83587 {
83588- void __user *handler;
83589+ __sighandler_t handler;
83590
83591 handler = sig_handler(t, sig);
83592
83593@@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
83594 atomic_inc(&user->sigpending);
83595 rcu_read_unlock();
83596
83597+ if (!override_rlimit)
83598+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
83599+
83600 if (override_rlimit ||
83601 atomic_read(&user->sigpending) <=
83602 task_rlimit(t, RLIMIT_SIGPENDING)) {
83603@@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
83604
83605 int unhandled_signal(struct task_struct *tsk, int sig)
83606 {
83607- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
83608+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
83609 if (is_global_init(tsk))
83610 return 1;
83611 if (handler != SIG_IGN && handler != SIG_DFL)
83612@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
83613 }
83614 }
83615
83616+ /* allow glibc communication via tgkill to other threads in our
83617+ thread group */
83618+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
83619+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
83620+ && gr_handle_signal(t, sig))
83621+ return -EPERM;
83622+
83623 return security_task_kill(t, info, sig, 0);
83624 }
83625
83626@@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
83627 return send_signal(sig, info, p, 1);
83628 }
83629
83630-static int
83631+int
83632 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
83633 {
83634 return send_signal(sig, info, t, 0);
83635@@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
83636 unsigned long int flags;
83637 int ret, blocked, ignored;
83638 struct k_sigaction *action;
83639+ int is_unhandled = 0;
83640
83641 spin_lock_irqsave(&t->sighand->siglock, flags);
83642 action = &t->sighand->action[sig-1];
83643@@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
83644 }
83645 if (action->sa.sa_handler == SIG_DFL)
83646 t->signal->flags &= ~SIGNAL_UNKILLABLE;
83647+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
83648+ is_unhandled = 1;
83649 ret = specific_send_sig_info(sig, info, t);
83650 spin_unlock_irqrestore(&t->sighand->siglock, flags);
83651
83652+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
83653+ normal operation */
83654+ if (is_unhandled) {
83655+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
83656+ gr_handle_crash(t, sig);
83657+ }
83658+
83659 return ret;
83660 }
83661
83662@@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
83663 ret = check_kill_permission(sig, info, p);
83664 rcu_read_unlock();
83665
83666- if (!ret && sig)
83667+ if (!ret && sig) {
83668 ret = do_send_sig_info(sig, info, p, true);
83669+ if (!ret)
83670+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
83671+ }
83672
83673 return ret;
83674 }
83675@@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
83676 int error = -ESRCH;
83677
83678 rcu_read_lock();
83679- p = find_task_by_vpid(pid);
83680+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
83681+ /* allow glibc communication via tgkill to other threads in our
83682+ thread group */
83683+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
83684+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
83685+ p = find_task_by_vpid_unrestricted(pid);
83686+ else
83687+#endif
83688+ p = find_task_by_vpid(pid);
83689 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
83690 error = check_kill_permission(sig, info, p);
83691 /*
83692@@ -3240,8 +3271,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
83693 }
83694 seg = get_fs();
83695 set_fs(KERNEL_DS);
83696- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
83697- (stack_t __force __user *) &uoss,
83698+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
83699+ (stack_t __force_user *) &uoss,
83700 compat_user_stack_pointer());
83701 set_fs(seg);
83702 if (ret >= 0 && uoss_ptr) {
83703diff --git a/kernel/smpboot.c b/kernel/smpboot.c
83704index eb89e18..a4e6792 100644
83705--- a/kernel/smpboot.c
83706+++ b/kernel/smpboot.c
83707@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
83708 }
83709 smpboot_unpark_thread(plug_thread, cpu);
83710 }
83711- list_add(&plug_thread->list, &hotplug_threads);
83712+ pax_list_add(&plug_thread->list, &hotplug_threads);
83713 out:
83714 mutex_unlock(&smpboot_threads_lock);
83715 return ret;
83716@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
83717 {
83718 get_online_cpus();
83719 mutex_lock(&smpboot_threads_lock);
83720- list_del(&plug_thread->list);
83721+ pax_list_del(&plug_thread->list);
83722 smpboot_destroy_threads(plug_thread);
83723 mutex_unlock(&smpboot_threads_lock);
83724 put_online_cpus();
83725diff --git a/kernel/softirq.c b/kernel/softirq.c
83726index adf6c00..5d89b73 100644
83727--- a/kernel/softirq.c
83728+++ b/kernel/softirq.c
83729@@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
83730 EXPORT_SYMBOL(irq_stat);
83731 #endif
83732
83733-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
83734+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
83735
83736 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
83737
83738-char *softirq_to_name[NR_SOFTIRQS] = {
83739+const char * const softirq_to_name[NR_SOFTIRQS] = {
83740 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
83741 "TASKLET", "SCHED", "HRTIMER", "RCU"
83742 };
83743@@ -248,7 +248,7 @@ restart:
83744 kstat_incr_softirqs_this_cpu(vec_nr);
83745
83746 trace_softirq_entry(vec_nr);
83747- h->action(h);
83748+ h->action();
83749 trace_softirq_exit(vec_nr);
83750 if (unlikely(prev_count != preempt_count())) {
83751 printk(KERN_ERR "huh, entered softirq %u %s %p"
83752@@ -412,7 +412,7 @@ void __raise_softirq_irqoff(unsigned int nr)
83753 or_softirq_pending(1UL << nr);
83754 }
83755
83756-void open_softirq(int nr, void (*action)(struct softirq_action *))
83757+void __init open_softirq(int nr, void (*action)(void))
83758 {
83759 softirq_vec[nr].action = action;
83760 }
83761@@ -468,7 +468,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
83762
83763 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
83764
83765-static void tasklet_action(struct softirq_action *a)
83766+static __latent_entropy void tasklet_action(void)
83767 {
83768 struct tasklet_struct *list;
83769
83770@@ -503,7 +503,7 @@ static void tasklet_action(struct softirq_action *a)
83771 }
83772 }
83773
83774-static void tasklet_hi_action(struct softirq_action *a)
83775+static __latent_entropy void tasklet_hi_action(void)
83776 {
83777 struct tasklet_struct *list;
83778
83779@@ -858,7 +858,7 @@ static struct notifier_block cpu_nfb = {
83780 .notifier_call = cpu_callback
83781 };
83782
83783-static struct smp_hotplug_thread softirq_threads = {
83784+static struct smp_hotplug_thread softirq_threads __read_only = {
83785 .store = &ksoftirqd,
83786 .thread_should_run = ksoftirqd_should_run,
83787 .thread_fn = run_ksoftirqd,
83788diff --git a/kernel/srcu.c b/kernel/srcu.c
83789index 01d5ccb..cdcbee6 100644
83790--- a/kernel/srcu.c
83791+++ b/kernel/srcu.c
83792@@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
83793
83794 idx = ACCESS_ONCE(sp->completed) & 0x1;
83795 preempt_disable();
83796- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
83797+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
83798 smp_mb(); /* B */ /* Avoid leaking the critical section. */
83799- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
83800+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
83801 preempt_enable();
83802 return idx;
83803 }
83804diff --git a/kernel/sys.c b/kernel/sys.c
83805index 771129b..dc0c7e3 100644
83806--- a/kernel/sys.c
83807+++ b/kernel/sys.c
83808@@ -149,6 +149,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
83809 error = -EACCES;
83810 goto out;
83811 }
83812+
83813+ if (gr_handle_chroot_setpriority(p, niceval)) {
83814+ error = -EACCES;
83815+ goto out;
83816+ }
83817+
83818 no_nice = security_task_setnice(p, niceval);
83819 if (no_nice) {
83820 error = no_nice;
83821@@ -352,6 +358,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
83822 goto error;
83823 }
83824
83825+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
83826+ goto error;
83827+
83828 if (rgid != (gid_t) -1 ||
83829 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
83830 new->sgid = new->egid;
83831@@ -387,6 +396,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
83832 old = current_cred();
83833
83834 retval = -EPERM;
83835+
83836+ if (gr_check_group_change(kgid, kgid, kgid))
83837+ goto error;
83838+
83839 if (nsown_capable(CAP_SETGID))
83840 new->gid = new->egid = new->sgid = new->fsgid = kgid;
83841 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
83842@@ -404,7 +417,7 @@ error:
83843 /*
83844 * change the user struct in a credentials set to match the new UID
83845 */
83846-static int set_user(struct cred *new)
83847+int set_user(struct cred *new)
83848 {
83849 struct user_struct *new_user;
83850
83851@@ -484,6 +497,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
83852 goto error;
83853 }
83854
83855+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
83856+ goto error;
83857+
83858 if (!uid_eq(new->uid, old->uid)) {
83859 retval = set_user(new);
83860 if (retval < 0)
83861@@ -534,6 +550,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
83862 old = current_cred();
83863
83864 retval = -EPERM;
83865+
83866+ if (gr_check_crash_uid(kuid))
83867+ goto error;
83868+ if (gr_check_user_change(kuid, kuid, kuid))
83869+ goto error;
83870+
83871 if (nsown_capable(CAP_SETUID)) {
83872 new->suid = new->uid = kuid;
83873 if (!uid_eq(kuid, old->uid)) {
83874@@ -603,6 +625,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
83875 goto error;
83876 }
83877
83878+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
83879+ goto error;
83880+
83881 if (ruid != (uid_t) -1) {
83882 new->uid = kruid;
83883 if (!uid_eq(kruid, old->uid)) {
83884@@ -685,6 +710,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
83885 goto error;
83886 }
83887
83888+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
83889+ goto error;
83890+
83891 if (rgid != (gid_t) -1)
83892 new->gid = krgid;
83893 if (egid != (gid_t) -1)
83894@@ -746,12 +774,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
83895 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
83896 nsown_capable(CAP_SETUID)) {
83897 if (!uid_eq(kuid, old->fsuid)) {
83898+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
83899+ goto error;
83900+
83901 new->fsuid = kuid;
83902 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
83903 goto change_okay;
83904 }
83905 }
83906
83907+error:
83908 abort_creds(new);
83909 return old_fsuid;
83910
83911@@ -784,12 +816,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
83912 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
83913 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
83914 nsown_capable(CAP_SETGID)) {
83915+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
83916+ goto error;
83917+
83918 if (!gid_eq(kgid, old->fsgid)) {
83919 new->fsgid = kgid;
83920 goto change_okay;
83921 }
83922 }
83923
83924+error:
83925 abort_creds(new);
83926 return old_fsgid;
83927
83928@@ -1169,19 +1205,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
83929 return -EFAULT;
83930
83931 down_read(&uts_sem);
83932- error = __copy_to_user(&name->sysname, &utsname()->sysname,
83933+ error = __copy_to_user(name->sysname, &utsname()->sysname,
83934 __OLD_UTS_LEN);
83935 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
83936- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
83937+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
83938 __OLD_UTS_LEN);
83939 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
83940- error |= __copy_to_user(&name->release, &utsname()->release,
83941+ error |= __copy_to_user(name->release, &utsname()->release,
83942 __OLD_UTS_LEN);
83943 error |= __put_user(0, name->release + __OLD_UTS_LEN);
83944- error |= __copy_to_user(&name->version, &utsname()->version,
83945+ error |= __copy_to_user(name->version, &utsname()->version,
83946 __OLD_UTS_LEN);
83947 error |= __put_user(0, name->version + __OLD_UTS_LEN);
83948- error |= __copy_to_user(&name->machine, &utsname()->machine,
83949+ error |= __copy_to_user(name->machine, &utsname()->machine,
83950 __OLD_UTS_LEN);
83951 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
83952 up_read(&uts_sem);
83953@@ -1383,6 +1419,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
83954 */
83955 new_rlim->rlim_cur = 1;
83956 }
83957+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
83958+ is changed to a lower value. Since tasks can be created by the same
83959+ user in between this limit change and an execve by this task, force
83960+ a recheck only for this task by setting PF_NPROC_EXCEEDED
83961+ */
83962+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
83963+ tsk->flags |= PF_NPROC_EXCEEDED;
83964 }
83965 if (!retval) {
83966 if (old_rlim)
83967diff --git a/kernel/sysctl.c b/kernel/sysctl.c
83968index 07f6fc4..65fb3d4 100644
83969--- a/kernel/sysctl.c
83970+++ b/kernel/sysctl.c
83971@@ -93,7 +93,6 @@
83972
83973
83974 #if defined(CONFIG_SYSCTL)
83975-
83976 /* External variables not in a header file. */
83977 extern int sysctl_overcommit_memory;
83978 extern int sysctl_overcommit_ratio;
83979@@ -119,17 +118,18 @@ extern int blk_iopoll_enabled;
83980
83981 /* Constants used for minimum and maximum */
83982 #ifdef CONFIG_LOCKUP_DETECTOR
83983-static int sixty = 60;
83984+static int sixty __read_only = 60;
83985 #endif
83986
83987-static int zero;
83988-static int __maybe_unused one = 1;
83989-static int __maybe_unused two = 2;
83990-static int __maybe_unused three = 3;
83991-static unsigned long one_ul = 1;
83992-static int one_hundred = 100;
83993+static int neg_one __read_only = -1;
83994+static int zero __read_only = 0;
83995+static int __maybe_unused one __read_only = 1;
83996+static int __maybe_unused two __read_only = 2;
83997+static int __maybe_unused three __read_only = 3;
83998+static unsigned long one_ul __read_only = 1;
83999+static int one_hundred __read_only = 100;
84000 #ifdef CONFIG_PRINTK
84001-static int ten_thousand = 10000;
84002+static int ten_thousand __read_only = 10000;
84003 #endif
84004
84005 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
84006@@ -176,10 +176,8 @@ static int proc_taint(struct ctl_table *table, int write,
84007 void __user *buffer, size_t *lenp, loff_t *ppos);
84008 #endif
84009
84010-#ifdef CONFIG_PRINTK
84011 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
84012 void __user *buffer, size_t *lenp, loff_t *ppos);
84013-#endif
84014
84015 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
84016 void __user *buffer, size_t *lenp, loff_t *ppos);
84017@@ -210,6 +208,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
84018
84019 #endif
84020
84021+extern struct ctl_table grsecurity_table[];
84022+
84023 static struct ctl_table kern_table[];
84024 static struct ctl_table vm_table[];
84025 static struct ctl_table fs_table[];
84026@@ -224,6 +224,20 @@ extern struct ctl_table epoll_table[];
84027 int sysctl_legacy_va_layout;
84028 #endif
84029
84030+#ifdef CONFIG_PAX_SOFTMODE
84031+static ctl_table pax_table[] = {
84032+ {
84033+ .procname = "softmode",
84034+ .data = &pax_softmode,
84035+ .maxlen = sizeof(unsigned int),
84036+ .mode = 0600,
84037+ .proc_handler = &proc_dointvec,
84038+ },
84039+
84040+ { }
84041+};
84042+#endif
84043+
84044 /* The default sysctl tables: */
84045
84046 static struct ctl_table sysctl_base_table[] = {
84047@@ -272,6 +286,22 @@ static int max_extfrag_threshold = 1000;
84048 #endif
84049
84050 static struct ctl_table kern_table[] = {
84051+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
84052+ {
84053+ .procname = "grsecurity",
84054+ .mode = 0500,
84055+ .child = grsecurity_table,
84056+ },
84057+#endif
84058+
84059+#ifdef CONFIG_PAX_SOFTMODE
84060+ {
84061+ .procname = "pax",
84062+ .mode = 0500,
84063+ .child = pax_table,
84064+ },
84065+#endif
84066+
84067 {
84068 .procname = "sched_child_runs_first",
84069 .data = &sysctl_sched_child_runs_first,
84070@@ -613,7 +643,7 @@ static struct ctl_table kern_table[] = {
84071 .data = &modprobe_path,
84072 .maxlen = KMOD_PATH_LEN,
84073 .mode = 0644,
84074- .proc_handler = proc_dostring,
84075+ .proc_handler = proc_dostring_modpriv,
84076 },
84077 {
84078 .procname = "modules_disabled",
84079@@ -780,16 +810,20 @@ static struct ctl_table kern_table[] = {
84080 .extra1 = &zero,
84081 .extra2 = &one,
84082 },
84083+#endif
84084 {
84085 .procname = "kptr_restrict",
84086 .data = &kptr_restrict,
84087 .maxlen = sizeof(int),
84088 .mode = 0644,
84089 .proc_handler = proc_dointvec_minmax_sysadmin,
84090+#ifdef CONFIG_GRKERNSEC_HIDESYM
84091+ .extra1 = &two,
84092+#else
84093 .extra1 = &zero,
84094+#endif
84095 .extra2 = &two,
84096 },
84097-#endif
84098 {
84099 .procname = "ngroups_max",
84100 .data = &ngroups_max,
84101@@ -1031,10 +1065,17 @@ static struct ctl_table kern_table[] = {
84102 */
84103 {
84104 .procname = "perf_event_paranoid",
84105- .data = &sysctl_perf_event_paranoid,
84106- .maxlen = sizeof(sysctl_perf_event_paranoid),
84107+ .data = &sysctl_perf_event_legitimately_concerned,
84108+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
84109 .mode = 0644,
84110- .proc_handler = proc_dointvec,
84111+ /* go ahead, be a hero */
84112+ .proc_handler = proc_dointvec_minmax_sysadmin,
84113+ .extra1 = &neg_one,
84114+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
84115+ .extra2 = &three,
84116+#else
84117+ .extra2 = &two,
84118+#endif
84119 },
84120 {
84121 .procname = "perf_event_mlock_kb",
84122@@ -1297,6 +1338,13 @@ static struct ctl_table vm_table[] = {
84123 .proc_handler = proc_dointvec_minmax,
84124 .extra1 = &zero,
84125 },
84126+ {
84127+ .procname = "heap_stack_gap",
84128+ .data = &sysctl_heap_stack_gap,
84129+ .maxlen = sizeof(sysctl_heap_stack_gap),
84130+ .mode = 0644,
84131+ .proc_handler = proc_doulongvec_minmax,
84132+ },
84133 #else
84134 {
84135 .procname = "nr_trim_pages",
84136@@ -1761,6 +1809,16 @@ int proc_dostring(struct ctl_table *table, int write,
84137 buffer, lenp, ppos);
84138 }
84139
84140+int proc_dostring_modpriv(struct ctl_table *table, int write,
84141+ void __user *buffer, size_t *lenp, loff_t *ppos)
84142+{
84143+ if (write && !capable(CAP_SYS_MODULE))
84144+ return -EPERM;
84145+
84146+ return _proc_do_string(table->data, table->maxlen, write,
84147+ buffer, lenp, ppos);
84148+}
84149+
84150 static size_t proc_skip_spaces(char **buf)
84151 {
84152 size_t ret;
84153@@ -1866,6 +1924,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
84154 len = strlen(tmp);
84155 if (len > *size)
84156 len = *size;
84157+ if (len > sizeof(tmp))
84158+ len = sizeof(tmp);
84159 if (copy_to_user(*buf, tmp, len))
84160 return -EFAULT;
84161 *size -= len;
84162@@ -2030,7 +2090,7 @@ int proc_dointvec(struct ctl_table *table, int write,
84163 static int proc_taint(struct ctl_table *table, int write,
84164 void __user *buffer, size_t *lenp, loff_t *ppos)
84165 {
84166- struct ctl_table t;
84167+ ctl_table_no_const t;
84168 unsigned long tmptaint = get_taint();
84169 int err;
84170
84171@@ -2058,7 +2118,6 @@ static int proc_taint(struct ctl_table *table, int write,
84172 return err;
84173 }
84174
84175-#ifdef CONFIG_PRINTK
84176 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
84177 void __user *buffer, size_t *lenp, loff_t *ppos)
84178 {
84179@@ -2067,7 +2126,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
84180
84181 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
84182 }
84183-#endif
84184
84185 struct do_proc_dointvec_minmax_conv_param {
84186 int *min;
84187@@ -2214,8 +2272,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
84188 *i = val;
84189 } else {
84190 val = convdiv * (*i) / convmul;
84191- if (!first)
84192+ if (!first) {
84193 err = proc_put_char(&buffer, &left, '\t');
84194+ if (err)
84195+ break;
84196+ }
84197 err = proc_put_long(&buffer, &left, val, false);
84198 if (err)
84199 break;
84200@@ -2611,6 +2672,12 @@ int proc_dostring(struct ctl_table *table, int write,
84201 return -ENOSYS;
84202 }
84203
84204+int proc_dostring_modpriv(struct ctl_table *table, int write,
84205+ void __user *buffer, size_t *lenp, loff_t *ppos)
84206+{
84207+ return -ENOSYS;
84208+}
84209+
84210 int proc_dointvec(struct ctl_table *table, int write,
84211 void __user *buffer, size_t *lenp, loff_t *ppos)
84212 {
84213@@ -2667,5 +2734,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
84214 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
84215 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
84216 EXPORT_SYMBOL(proc_dostring);
84217+EXPORT_SYMBOL(proc_dostring_modpriv);
84218 EXPORT_SYMBOL(proc_doulongvec_minmax);
84219 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
84220diff --git a/kernel/taskstats.c b/kernel/taskstats.c
84221index 145bb4d..b2aa969 100644
84222--- a/kernel/taskstats.c
84223+++ b/kernel/taskstats.c
84224@@ -28,9 +28,12 @@
84225 #include <linux/fs.h>
84226 #include <linux/file.h>
84227 #include <linux/pid_namespace.h>
84228+#include <linux/grsecurity.h>
84229 #include <net/genetlink.h>
84230 #include <linux/atomic.h>
84231
84232+extern int gr_is_taskstats_denied(int pid);
84233+
84234 /*
84235 * Maximum length of a cpumask that can be specified in
84236 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
84237@@ -570,6 +573,9 @@ err:
84238
84239 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
84240 {
84241+ if (gr_is_taskstats_denied(current->pid))
84242+ return -EACCES;
84243+
84244 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
84245 return cmd_attr_register_cpumask(info);
84246 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
84247diff --git a/kernel/time.c b/kernel/time.c
84248index 7c7964c..784a599 100644
84249--- a/kernel/time.c
84250+++ b/kernel/time.c
84251@@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
84252 return error;
84253
84254 if (tz) {
84255+ /* we log in do_settimeofday called below, so don't log twice
84256+ */
84257+ if (!tv)
84258+ gr_log_timechange();
84259+
84260 sys_tz = *tz;
84261 update_vsyscall_tz();
84262 if (firsttime) {
84263@@ -502,7 +507,7 @@ EXPORT_SYMBOL(usecs_to_jiffies);
84264 * The >> (NSEC_JIFFIE_SC - SEC_JIFFIE_SC) converts the scaled nsec
84265 * value to a scaled second value.
84266 */
84267-unsigned long
84268+unsigned long __intentional_overflow(-1)
84269 timespec_to_jiffies(const struct timespec *value)
84270 {
84271 unsigned long sec = value->tv_sec;
84272diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
84273index eec50fc..65e5df6 100644
84274--- a/kernel/time/alarmtimer.c
84275+++ b/kernel/time/alarmtimer.c
84276@@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
84277 struct platform_device *pdev;
84278 int error = 0;
84279 int i;
84280- struct k_clock alarm_clock = {
84281+ static struct k_clock alarm_clock = {
84282 .clock_getres = alarm_clock_getres,
84283 .clock_get = alarm_clock_get,
84284 .timer_create = alarm_timer_create,
84285diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
84286index 947ba25..20cbade 100644
84287--- a/kernel/time/timekeeping.c
84288+++ b/kernel/time/timekeeping.c
84289@@ -15,6 +15,7 @@
84290 #include <linux/init.h>
84291 #include <linux/mm.h>
84292 #include <linux/sched.h>
84293+#include <linux/grsecurity.h>
84294 #include <linux/syscore_ops.h>
84295 #include <linux/clocksource.h>
84296 #include <linux/jiffies.h>
84297@@ -500,6 +501,8 @@ int do_settimeofday(const struct timespec *tv)
84298 if (!timespec_valid_strict(tv))
84299 return -EINVAL;
84300
84301+ gr_log_timechange();
84302+
84303 raw_spin_lock_irqsave(&timekeeper_lock, flags);
84304 write_seqcount_begin(&timekeeper_seq);
84305
84306diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
84307index 61ed862..3b52c65 100644
84308--- a/kernel/time/timer_list.c
84309+++ b/kernel/time/timer_list.c
84310@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
84311
84312 static void print_name_offset(struct seq_file *m, void *sym)
84313 {
84314+#ifdef CONFIG_GRKERNSEC_HIDESYM
84315+ SEQ_printf(m, "<%p>", NULL);
84316+#else
84317 char symname[KSYM_NAME_LEN];
84318
84319 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
84320 SEQ_printf(m, "<%pK>", sym);
84321 else
84322 SEQ_printf(m, "%s", symname);
84323+#endif
84324 }
84325
84326 static void
84327@@ -119,7 +123,11 @@ next_one:
84328 static void
84329 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
84330 {
84331+#ifdef CONFIG_GRKERNSEC_HIDESYM
84332+ SEQ_printf(m, " .base: %p\n", NULL);
84333+#else
84334 SEQ_printf(m, " .base: %pK\n", base);
84335+#endif
84336 SEQ_printf(m, " .index: %d\n",
84337 base->index);
84338 SEQ_printf(m, " .resolution: %Lu nsecs\n",
84339@@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
84340 {
84341 struct proc_dir_entry *pe;
84342
84343+#ifdef CONFIG_GRKERNSEC_PROC_ADD
84344+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
84345+#else
84346 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
84347+#endif
84348 if (!pe)
84349 return -ENOMEM;
84350 return 0;
84351diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
84352index 0b537f2..40d6c20 100644
84353--- a/kernel/time/timer_stats.c
84354+++ b/kernel/time/timer_stats.c
84355@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
84356 static unsigned long nr_entries;
84357 static struct entry entries[MAX_ENTRIES];
84358
84359-static atomic_t overflow_count;
84360+static atomic_unchecked_t overflow_count;
84361
84362 /*
84363 * The entries are in a hash-table, for fast lookup:
84364@@ -140,7 +140,7 @@ static void reset_entries(void)
84365 nr_entries = 0;
84366 memset(entries, 0, sizeof(entries));
84367 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
84368- atomic_set(&overflow_count, 0);
84369+ atomic_set_unchecked(&overflow_count, 0);
84370 }
84371
84372 static struct entry *alloc_entry(void)
84373@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
84374 if (likely(entry))
84375 entry->count++;
84376 else
84377- atomic_inc(&overflow_count);
84378+ atomic_inc_unchecked(&overflow_count);
84379
84380 out_unlock:
84381 raw_spin_unlock_irqrestore(lock, flags);
84382@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
84383
84384 static void print_name_offset(struct seq_file *m, unsigned long addr)
84385 {
84386+#ifdef CONFIG_GRKERNSEC_HIDESYM
84387+ seq_printf(m, "<%p>", NULL);
84388+#else
84389 char symname[KSYM_NAME_LEN];
84390
84391 if (lookup_symbol_name(addr, symname) < 0)
84392- seq_printf(m, "<%p>", (void *)addr);
84393+ seq_printf(m, "<%pK>", (void *)addr);
84394 else
84395 seq_printf(m, "%s", symname);
84396+#endif
84397 }
84398
84399 static int tstats_show(struct seq_file *m, void *v)
84400@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
84401
84402 seq_puts(m, "Timer Stats Version: v0.2\n");
84403 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
84404- if (atomic_read(&overflow_count))
84405+ if (atomic_read_unchecked(&overflow_count))
84406 seq_printf(m, "Overflow: %d entries\n",
84407- atomic_read(&overflow_count));
84408+ atomic_read_unchecked(&overflow_count));
84409
84410 for (i = 0; i < nr_entries; i++) {
84411 entry = entries + i;
84412@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
84413 {
84414 struct proc_dir_entry *pe;
84415
84416+#ifdef CONFIG_GRKERNSEC_PROC_ADD
84417+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
84418+#else
84419 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
84420+#endif
84421 if (!pe)
84422 return -ENOMEM;
84423 return 0;
84424diff --git a/kernel/timer.c b/kernel/timer.c
84425index 4296d13..0164b04 100644
84426--- a/kernel/timer.c
84427+++ b/kernel/timer.c
84428@@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
84429 /*
84430 * This function runs timers and the timer-tq in bottom half context.
84431 */
84432-static void run_timer_softirq(struct softirq_action *h)
84433+static __latent_entropy void run_timer_softirq(void)
84434 {
84435 struct tvec_base *base = __this_cpu_read(tvec_bases);
84436
84437@@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
84438 *
84439 * In all cases the return value is guaranteed to be non-negative.
84440 */
84441-signed long __sched schedule_timeout(signed long timeout)
84442+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
84443 {
84444 struct timer_list timer;
84445 unsigned long expire;
84446diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
84447index b8b8560..75b1a09 100644
84448--- a/kernel/trace/blktrace.c
84449+++ b/kernel/trace/blktrace.c
84450@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
84451 struct blk_trace *bt = filp->private_data;
84452 char buf[16];
84453
84454- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
84455+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
84456
84457 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
84458 }
84459@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
84460 return 1;
84461
84462 bt = buf->chan->private_data;
84463- atomic_inc(&bt->dropped);
84464+ atomic_inc_unchecked(&bt->dropped);
84465 return 0;
84466 }
84467
84468@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
84469
84470 bt->dir = dir;
84471 bt->dev = dev;
84472- atomic_set(&bt->dropped, 0);
84473+ atomic_set_unchecked(&bt->dropped, 0);
84474
84475 ret = -EIO;
84476 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
84477diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
84478index a6d098c..bb8cf65 100644
84479--- a/kernel/trace/ftrace.c
84480+++ b/kernel/trace/ftrace.c
84481@@ -1950,12 +1950,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
84482 if (unlikely(ftrace_disabled))
84483 return 0;
84484
84485+ ret = ftrace_arch_code_modify_prepare();
84486+ FTRACE_WARN_ON(ret);
84487+ if (ret)
84488+ return 0;
84489+
84490 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
84491+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
84492 if (ret) {
84493 ftrace_bug(ret, ip);
84494- return 0;
84495 }
84496- return 1;
84497+ return ret ? 0 : 1;
84498 }
84499
84500 /*
84501@@ -4028,8 +4033,10 @@ static int ftrace_process_locs(struct module *mod,
84502 if (!count)
84503 return 0;
84504
84505+ pax_open_kernel();
84506 sort(start, count, sizeof(*start),
84507 ftrace_cmp_ips, ftrace_swap_ips);
84508+ pax_close_kernel();
84509
84510 start_pg = ftrace_allocate_pages(count);
84511 if (!start_pg)
84512@@ -4752,8 +4759,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
84513 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
84514
84515 static int ftrace_graph_active;
84516-static struct notifier_block ftrace_suspend_notifier;
84517-
84518 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
84519 {
84520 return 0;
84521@@ -4897,6 +4902,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
84522 return NOTIFY_DONE;
84523 }
84524
84525+static struct notifier_block ftrace_suspend_notifier = {
84526+ .notifier_call = ftrace_suspend_notifier_call
84527+};
84528+
84529 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
84530 trace_func_graph_ent_t entryfunc)
84531 {
84532@@ -4910,7 +4919,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
84533 goto out;
84534 }
84535
84536- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
84537 register_pm_notifier(&ftrace_suspend_notifier);
84538
84539 ftrace_graph_active++;
84540diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
84541index cc2f66f..05edd54 100644
84542--- a/kernel/trace/ring_buffer.c
84543+++ b/kernel/trace/ring_buffer.c
84544@@ -352,9 +352,9 @@ struct buffer_data_page {
84545 */
84546 struct buffer_page {
84547 struct list_head list; /* list of buffer pages */
84548- local_t write; /* index for next write */
84549+ local_unchecked_t write; /* index for next write */
84550 unsigned read; /* index for next read */
84551- local_t entries; /* entries on this page */
84552+ local_unchecked_t entries; /* entries on this page */
84553 unsigned long real_end; /* real end of data */
84554 struct buffer_data_page *page; /* Actual data page */
84555 };
84556@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
84557 unsigned long last_overrun;
84558 local_t entries_bytes;
84559 local_t entries;
84560- local_t overrun;
84561- local_t commit_overrun;
84562+ local_unchecked_t overrun;
84563+ local_unchecked_t commit_overrun;
84564 local_t dropped_events;
84565 local_t committing;
84566 local_t commits;
84567@@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
84568 *
84569 * We add a counter to the write field to denote this.
84570 */
84571- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
84572- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
84573+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
84574+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
84575
84576 /*
84577 * Just make sure we have seen our old_write and synchronize
84578@@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
84579 * cmpxchg to only update if an interrupt did not already
84580 * do it for us. If the cmpxchg fails, we don't care.
84581 */
84582- (void)local_cmpxchg(&next_page->write, old_write, val);
84583- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
84584+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
84585+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
84586
84587 /*
84588 * No need to worry about races with clearing out the commit.
84589@@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
84590
84591 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
84592 {
84593- return local_read(&bpage->entries) & RB_WRITE_MASK;
84594+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
84595 }
84596
84597 static inline unsigned long rb_page_write(struct buffer_page *bpage)
84598 {
84599- return local_read(&bpage->write) & RB_WRITE_MASK;
84600+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
84601 }
84602
84603 static int
84604@@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
84605 * bytes consumed in ring buffer from here.
84606 * Increment overrun to account for the lost events.
84607 */
84608- local_add(page_entries, &cpu_buffer->overrun);
84609+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
84610 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
84611 }
84612
84613@@ -2064,7 +2064,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
84614 * it is our responsibility to update
84615 * the counters.
84616 */
84617- local_add(entries, &cpu_buffer->overrun);
84618+ local_add_unchecked(entries, &cpu_buffer->overrun);
84619 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
84620
84621 /*
84622@@ -2214,7 +2214,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
84623 if (tail == BUF_PAGE_SIZE)
84624 tail_page->real_end = 0;
84625
84626- local_sub(length, &tail_page->write);
84627+ local_sub_unchecked(length, &tail_page->write);
84628 return;
84629 }
84630
84631@@ -2249,7 +2249,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
84632 rb_event_set_padding(event);
84633
84634 /* Set the write back to the previous setting */
84635- local_sub(length, &tail_page->write);
84636+ local_sub_unchecked(length, &tail_page->write);
84637 return;
84638 }
84639
84640@@ -2261,7 +2261,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
84641
84642 /* Set write to end of buffer */
84643 length = (tail + length) - BUF_PAGE_SIZE;
84644- local_sub(length, &tail_page->write);
84645+ local_sub_unchecked(length, &tail_page->write);
84646 }
84647
84648 /*
84649@@ -2287,7 +2287,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
84650 * about it.
84651 */
84652 if (unlikely(next_page == commit_page)) {
84653- local_inc(&cpu_buffer->commit_overrun);
84654+ local_inc_unchecked(&cpu_buffer->commit_overrun);
84655 goto out_reset;
84656 }
84657
84658@@ -2343,7 +2343,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
84659 cpu_buffer->tail_page) &&
84660 (cpu_buffer->commit_page ==
84661 cpu_buffer->reader_page))) {
84662- local_inc(&cpu_buffer->commit_overrun);
84663+ local_inc_unchecked(&cpu_buffer->commit_overrun);
84664 goto out_reset;
84665 }
84666 }
84667@@ -2391,7 +2391,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
84668 length += RB_LEN_TIME_EXTEND;
84669
84670 tail_page = cpu_buffer->tail_page;
84671- write = local_add_return(length, &tail_page->write);
84672+ write = local_add_return_unchecked(length, &tail_page->write);
84673
84674 /* set write to only the index of the write */
84675 write &= RB_WRITE_MASK;
84676@@ -2408,7 +2408,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
84677 kmemcheck_annotate_bitfield(event, bitfield);
84678 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
84679
84680- local_inc(&tail_page->entries);
84681+ local_inc_unchecked(&tail_page->entries);
84682
84683 /*
84684 * If this is the first commit on the page, then update
84685@@ -2441,7 +2441,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
84686
84687 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
84688 unsigned long write_mask =
84689- local_read(&bpage->write) & ~RB_WRITE_MASK;
84690+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
84691 unsigned long event_length = rb_event_length(event);
84692 /*
84693 * This is on the tail page. It is possible that
84694@@ -2451,7 +2451,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
84695 */
84696 old_index += write_mask;
84697 new_index += write_mask;
84698- index = local_cmpxchg(&bpage->write, old_index, new_index);
84699+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
84700 if (index == old_index) {
84701 /* update counters */
84702 local_sub(event_length, &cpu_buffer->entries_bytes);
84703@@ -2843,7 +2843,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
84704
84705 /* Do the likely case first */
84706 if (likely(bpage->page == (void *)addr)) {
84707- local_dec(&bpage->entries);
84708+ local_dec_unchecked(&bpage->entries);
84709 return;
84710 }
84711
84712@@ -2855,7 +2855,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
84713 start = bpage;
84714 do {
84715 if (bpage->page == (void *)addr) {
84716- local_dec(&bpage->entries);
84717+ local_dec_unchecked(&bpage->entries);
84718 return;
84719 }
84720 rb_inc_page(cpu_buffer, &bpage);
84721@@ -3139,7 +3139,7 @@ static inline unsigned long
84722 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
84723 {
84724 return local_read(&cpu_buffer->entries) -
84725- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
84726+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
84727 }
84728
84729 /**
84730@@ -3228,7 +3228,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
84731 return 0;
84732
84733 cpu_buffer = buffer->buffers[cpu];
84734- ret = local_read(&cpu_buffer->overrun);
84735+ ret = local_read_unchecked(&cpu_buffer->overrun);
84736
84737 return ret;
84738 }
84739@@ -3251,7 +3251,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
84740 return 0;
84741
84742 cpu_buffer = buffer->buffers[cpu];
84743- ret = local_read(&cpu_buffer->commit_overrun);
84744+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
84745
84746 return ret;
84747 }
84748@@ -3336,7 +3336,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
84749 /* if you care about this being correct, lock the buffer */
84750 for_each_buffer_cpu(buffer, cpu) {
84751 cpu_buffer = buffer->buffers[cpu];
84752- overruns += local_read(&cpu_buffer->overrun);
84753+ overruns += local_read_unchecked(&cpu_buffer->overrun);
84754 }
84755
84756 return overruns;
84757@@ -3512,8 +3512,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
84758 /*
84759 * Reset the reader page to size zero.
84760 */
84761- local_set(&cpu_buffer->reader_page->write, 0);
84762- local_set(&cpu_buffer->reader_page->entries, 0);
84763+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
84764+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
84765 local_set(&cpu_buffer->reader_page->page->commit, 0);
84766 cpu_buffer->reader_page->real_end = 0;
84767
84768@@ -3547,7 +3547,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
84769 * want to compare with the last_overrun.
84770 */
84771 smp_mb();
84772- overwrite = local_read(&(cpu_buffer->overrun));
84773+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
84774
84775 /*
84776 * Here's the tricky part.
84777@@ -4117,8 +4117,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
84778
84779 cpu_buffer->head_page
84780 = list_entry(cpu_buffer->pages, struct buffer_page, list);
84781- local_set(&cpu_buffer->head_page->write, 0);
84782- local_set(&cpu_buffer->head_page->entries, 0);
84783+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
84784+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
84785 local_set(&cpu_buffer->head_page->page->commit, 0);
84786
84787 cpu_buffer->head_page->read = 0;
84788@@ -4128,14 +4128,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
84789
84790 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
84791 INIT_LIST_HEAD(&cpu_buffer->new_pages);
84792- local_set(&cpu_buffer->reader_page->write, 0);
84793- local_set(&cpu_buffer->reader_page->entries, 0);
84794+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
84795+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
84796 local_set(&cpu_buffer->reader_page->page->commit, 0);
84797 cpu_buffer->reader_page->read = 0;
84798
84799 local_set(&cpu_buffer->entries_bytes, 0);
84800- local_set(&cpu_buffer->overrun, 0);
84801- local_set(&cpu_buffer->commit_overrun, 0);
84802+ local_set_unchecked(&cpu_buffer->overrun, 0);
84803+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
84804 local_set(&cpu_buffer->dropped_events, 0);
84805 local_set(&cpu_buffer->entries, 0);
84806 local_set(&cpu_buffer->committing, 0);
84807@@ -4540,8 +4540,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
84808 rb_init_page(bpage);
84809 bpage = reader->page;
84810 reader->page = *data_page;
84811- local_set(&reader->write, 0);
84812- local_set(&reader->entries, 0);
84813+ local_set_unchecked(&reader->write, 0);
84814+ local_set_unchecked(&reader->entries, 0);
84815 reader->read = 0;
84816 *data_page = bpage;
84817
84818diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
84819index 496f94d..754aeea 100644
84820--- a/kernel/trace/trace.c
84821+++ b/kernel/trace/trace.c
84822@@ -3335,7 +3335,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
84823 return 0;
84824 }
84825
84826-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
84827+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
84828 {
84829 /* do nothing if flag is already set */
84830 if (!!(trace_flags & mask) == !!enabled)
84831diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
84832index afaae41..64871f8 100644
84833--- a/kernel/trace/trace.h
84834+++ b/kernel/trace/trace.h
84835@@ -1025,7 +1025,7 @@ extern const char *__stop___trace_bprintk_fmt[];
84836 void trace_printk_init_buffers(void);
84837 void trace_printk_start_comm(void);
84838 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
84839-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
84840+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
84841
84842 /*
84843 * Normal trace_printk() and friends allocates special buffers
84844diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
84845index 26dc348..8708ca7 100644
84846--- a/kernel/trace/trace_clock.c
84847+++ b/kernel/trace/trace_clock.c
84848@@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
84849 return now;
84850 }
84851
84852-static atomic64_t trace_counter;
84853+static atomic64_unchecked_t trace_counter;
84854
84855 /*
84856 * trace_clock_counter(): simply an atomic counter.
84857@@ -132,5 +132,5 @@ static atomic64_t trace_counter;
84858 */
84859 u64 notrace trace_clock_counter(void)
84860 {
84861- return atomic64_add_return(1, &trace_counter);
84862+ return atomic64_inc_return_unchecked(&trace_counter);
84863 }
84864diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
84865index 29a7ebc..eb473cf 100644
84866--- a/kernel/trace/trace_events.c
84867+++ b/kernel/trace/trace_events.c
84868@@ -1778,10 +1778,6 @@ static LIST_HEAD(ftrace_module_file_list);
84869 struct ftrace_module_file_ops {
84870 struct list_head list;
84871 struct module *mod;
84872- struct file_operations id;
84873- struct file_operations enable;
84874- struct file_operations format;
84875- struct file_operations filter;
84876 };
84877
84878 static struct ftrace_module_file_ops *
84879@@ -1822,17 +1818,12 @@ trace_create_file_ops(struct module *mod)
84880
84881 file_ops->mod = mod;
84882
84883- file_ops->id = ftrace_event_id_fops;
84884- file_ops->id.owner = mod;
84885-
84886- file_ops->enable = ftrace_enable_fops;
84887- file_ops->enable.owner = mod;
84888-
84889- file_ops->filter = ftrace_event_filter_fops;
84890- file_ops->filter.owner = mod;
84891-
84892- file_ops->format = ftrace_event_format_fops;
84893- file_ops->format.owner = mod;
84894+ pax_open_kernel();
84895+ mod->trace_id.owner = mod;
84896+ mod->trace_enable.owner = mod;
84897+ mod->trace_filter.owner = mod;
84898+ mod->trace_format.owner = mod;
84899+ pax_close_kernel();
84900
84901 list_add(&file_ops->list, &ftrace_module_file_list);
84902
84903@@ -1925,8 +1916,8 @@ __trace_add_new_mod_event(struct ftrace_event_call *call,
84904 struct ftrace_module_file_ops *file_ops)
84905 {
84906 return __trace_add_new_event(call, tr,
84907- &file_ops->id, &file_ops->enable,
84908- &file_ops->filter, &file_ops->format);
84909+ &file_ops->mod->trace_id, &file_ops->mod->trace_enable,
84910+ &file_ops->mod->trace_filter, &file_ops->mod->trace_format);
84911 }
84912
84913 #else
84914diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
84915index b3dcfb2..ebee344 100644
84916--- a/kernel/trace/trace_mmiotrace.c
84917+++ b/kernel/trace/trace_mmiotrace.c
84918@@ -24,7 +24,7 @@ struct header_iter {
84919 static struct trace_array *mmio_trace_array;
84920 static bool overrun_detected;
84921 static unsigned long prev_overruns;
84922-static atomic_t dropped_count;
84923+static atomic_unchecked_t dropped_count;
84924
84925 static void mmio_reset_data(struct trace_array *tr)
84926 {
84927@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
84928
84929 static unsigned long count_overruns(struct trace_iterator *iter)
84930 {
84931- unsigned long cnt = atomic_xchg(&dropped_count, 0);
84932+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
84933 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
84934
84935 if (over > prev_overruns)
84936@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
84937 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
84938 sizeof(*entry), 0, pc);
84939 if (!event) {
84940- atomic_inc(&dropped_count);
84941+ atomic_inc_unchecked(&dropped_count);
84942 return;
84943 }
84944 entry = ring_buffer_event_data(event);
84945@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
84946 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
84947 sizeof(*entry), 0, pc);
84948 if (!event) {
84949- atomic_inc(&dropped_count);
84950+ atomic_inc_unchecked(&dropped_count);
84951 return;
84952 }
84953 entry = ring_buffer_event_data(event);
84954diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
84955index 34e7cba..6f9a729 100644
84956--- a/kernel/trace/trace_output.c
84957+++ b/kernel/trace/trace_output.c
84958@@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
84959
84960 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
84961 if (!IS_ERR(p)) {
84962- p = mangle_path(s->buffer + s->len, p, "\n");
84963+ p = mangle_path(s->buffer + s->len, p, "\n\\");
84964 if (p) {
84965 s->len = p - s->buffer;
84966 return 1;
84967@@ -893,14 +893,16 @@ int register_ftrace_event(struct trace_event *event)
84968 goto out;
84969 }
84970
84971+ pax_open_kernel();
84972 if (event->funcs->trace == NULL)
84973- event->funcs->trace = trace_nop_print;
84974+ *(void **)&event->funcs->trace = trace_nop_print;
84975 if (event->funcs->raw == NULL)
84976- event->funcs->raw = trace_nop_print;
84977+ *(void **)&event->funcs->raw = trace_nop_print;
84978 if (event->funcs->hex == NULL)
84979- event->funcs->hex = trace_nop_print;
84980+ *(void **)&event->funcs->hex = trace_nop_print;
84981 if (event->funcs->binary == NULL)
84982- event->funcs->binary = trace_nop_print;
84983+ *(void **)&event->funcs->binary = trace_nop_print;
84984+ pax_close_kernel();
84985
84986 key = event->type & (EVENT_HASHSIZE - 1);
84987
84988diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
84989index b20428c..4845a10 100644
84990--- a/kernel/trace/trace_stack.c
84991+++ b/kernel/trace/trace_stack.c
84992@@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
84993 return;
84994
84995 /* we do not handle interrupt stacks yet */
84996- if (!object_is_on_stack(stack))
84997+ if (!object_starts_on_stack(stack))
84998 return;
84999
85000 local_irq_save(flags);
85001diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
85002index 9064b91..1f5d2f8 100644
85003--- a/kernel/user_namespace.c
85004+++ b/kernel/user_namespace.c
85005@@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
85006 !kgid_has_mapping(parent_ns, group))
85007 return -EPERM;
85008
85009+#ifdef CONFIG_GRKERNSEC
85010+ /*
85011+ * This doesn't really inspire confidence:
85012+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
85013+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
85014+ * Increases kernel attack surface in areas developers
85015+ * previously cared little about ("low importance due
85016+ * to requiring "root" capability")
85017+ * To be removed when this code receives *proper* review
85018+ */
85019+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
85020+ !capable(CAP_SETGID))
85021+ return -EPERM;
85022+#endif
85023+
85024 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
85025 if (!ns)
85026 return -ENOMEM;
85027@@ -862,7 +877,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
85028 if (atomic_read(&current->mm->mm_users) > 1)
85029 return -EINVAL;
85030
85031- if (current->fs->users != 1)
85032+ if (atomic_read(&current->fs->users) != 1)
85033 return -EINVAL;
85034
85035 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
85036diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
85037index 4f69f9a..7c6f8f8 100644
85038--- a/kernel/utsname_sysctl.c
85039+++ b/kernel/utsname_sysctl.c
85040@@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
85041 static int proc_do_uts_string(ctl_table *table, int write,
85042 void __user *buffer, size_t *lenp, loff_t *ppos)
85043 {
85044- struct ctl_table uts_table;
85045+ ctl_table_no_const uts_table;
85046 int r;
85047 memcpy(&uts_table, table, sizeof(uts_table));
85048 uts_table.data = get_uts(table, write);
85049diff --git a/kernel/watchdog.c b/kernel/watchdog.c
85050index 1241d8c..d5cfc28 100644
85051--- a/kernel/watchdog.c
85052+++ b/kernel/watchdog.c
85053@@ -475,7 +475,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
85054 static void watchdog_nmi_disable(unsigned int cpu) { return; }
85055 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
85056
85057-static struct smp_hotplug_thread watchdog_threads = {
85058+static struct smp_hotplug_thread watchdog_threads __read_only = {
85059 .store = &softlockup_watchdog,
85060 .thread_should_run = watchdog_should_run,
85061 .thread_fn = watchdog,
85062diff --git a/kernel/workqueue.c b/kernel/workqueue.c
85063index e93f7b9..989fcd7 100644
85064--- a/kernel/workqueue.c
85065+++ b/kernel/workqueue.c
85066@@ -4627,7 +4627,7 @@ static void rebind_workers(struct worker_pool *pool)
85067 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
85068 worker_flags |= WORKER_REBOUND;
85069 worker_flags &= ~WORKER_UNBOUND;
85070- ACCESS_ONCE(worker->flags) = worker_flags;
85071+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
85072 }
85073
85074 spin_unlock_irq(&pool->lock);
85075diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
85076index 1501aa5..e771896 100644
85077--- a/lib/Kconfig.debug
85078+++ b/lib/Kconfig.debug
85079@@ -836,7 +836,7 @@ config DEBUG_MUTEXES
85080
85081 config DEBUG_WW_MUTEX_SLOWPATH
85082 bool "Wait/wound mutex debugging: Slowpath testing"
85083- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
85084+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
85085 select DEBUG_LOCK_ALLOC
85086 select DEBUG_SPINLOCK
85087 select DEBUG_MUTEXES
85088@@ -849,7 +849,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
85089
85090 config DEBUG_LOCK_ALLOC
85091 bool "Lock debugging: detect incorrect freeing of live locks"
85092- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
85093+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
85094 select DEBUG_SPINLOCK
85095 select DEBUG_MUTEXES
85096 select LOCKDEP
85097@@ -863,7 +863,7 @@ config DEBUG_LOCK_ALLOC
85098
85099 config PROVE_LOCKING
85100 bool "Lock debugging: prove locking correctness"
85101- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
85102+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
85103 select LOCKDEP
85104 select DEBUG_SPINLOCK
85105 select DEBUG_MUTEXES
85106@@ -914,7 +914,7 @@ config LOCKDEP
85107
85108 config LOCK_STAT
85109 bool "Lock usage statistics"
85110- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
85111+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
85112 select LOCKDEP
85113 select DEBUG_SPINLOCK
85114 select DEBUG_MUTEXES
85115@@ -1357,6 +1357,7 @@ config LATENCYTOP
85116 depends on DEBUG_KERNEL
85117 depends on STACKTRACE_SUPPORT
85118 depends on PROC_FS
85119+ depends on !GRKERNSEC_HIDESYM
85120 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
85121 select KALLSYMS
85122 select KALLSYMS_ALL
85123@@ -1373,7 +1374,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
85124 config DEBUG_STRICT_USER_COPY_CHECKS
85125 bool "Strict user copy size checks"
85126 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
85127- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
85128+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
85129 help
85130 Enabling this option turns a certain set of sanity checks for user
85131 copy operations into compile time failures.
85132@@ -1483,7 +1484,7 @@ endmenu # runtime tests
85133
85134 config PROVIDE_OHCI1394_DMA_INIT
85135 bool "Remote debugging over FireWire early on boot"
85136- depends on PCI && X86
85137+ depends on PCI && X86 && !GRKERNSEC
85138 help
85139 If you want to debug problems which hang or crash the kernel early
85140 on boot and the crashing machine has a FireWire port, you can use
85141@@ -1512,7 +1513,7 @@ config PROVIDE_OHCI1394_DMA_INIT
85142
85143 config FIREWIRE_OHCI_REMOTE_DMA
85144 bool "Remote debugging over FireWire with firewire-ohci"
85145- depends on FIREWIRE_OHCI
85146+ depends on FIREWIRE_OHCI && !GRKERNSEC
85147 help
85148 This option lets you use the FireWire bus for remote debugging
85149 with help of the firewire-ohci driver. It enables unfiltered
85150diff --git a/lib/Makefile b/lib/Makefile
85151index 7baccfd..3ceb95f 100644
85152--- a/lib/Makefile
85153+++ b/lib/Makefile
85154@@ -50,7 +50,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
85155
85156 obj-$(CONFIG_BTREE) += btree.o
85157 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
85158-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
85159+obj-y += list_debug.o
85160 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
85161
85162 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
85163diff --git a/lib/bitmap.c b/lib/bitmap.c
85164index 06f7e4f..f3cf2b0 100644
85165--- a/lib/bitmap.c
85166+++ b/lib/bitmap.c
85167@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
85168 {
85169 int c, old_c, totaldigits, ndigits, nchunks, nbits;
85170 u32 chunk;
85171- const char __user __force *ubuf = (const char __user __force *)buf;
85172+ const char __user *ubuf = (const char __force_user *)buf;
85173
85174 bitmap_zero(maskp, nmaskbits);
85175
85176@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
85177 {
85178 if (!access_ok(VERIFY_READ, ubuf, ulen))
85179 return -EFAULT;
85180- return __bitmap_parse((const char __force *)ubuf,
85181+ return __bitmap_parse((const char __force_kernel *)ubuf,
85182 ulen, 1, maskp, nmaskbits);
85183
85184 }
85185@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
85186 {
85187 unsigned a, b;
85188 int c, old_c, totaldigits;
85189- const char __user __force *ubuf = (const char __user __force *)buf;
85190+ const char __user *ubuf = (const char __force_user *)buf;
85191 int exp_digit, in_range;
85192
85193 totaldigits = c = 0;
85194@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
85195 {
85196 if (!access_ok(VERIFY_READ, ubuf, ulen))
85197 return -EFAULT;
85198- return __bitmap_parselist((const char __force *)ubuf,
85199+ return __bitmap_parselist((const char __force_kernel *)ubuf,
85200 ulen, 1, maskp, nmaskbits);
85201 }
85202 EXPORT_SYMBOL(bitmap_parselist_user);
85203diff --git a/lib/bug.c b/lib/bug.c
85204index 1686034..a9c00c8 100644
85205--- a/lib/bug.c
85206+++ b/lib/bug.c
85207@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
85208 return BUG_TRAP_TYPE_NONE;
85209
85210 bug = find_bug(bugaddr);
85211+ if (!bug)
85212+ return BUG_TRAP_TYPE_NONE;
85213
85214 file = NULL;
85215 line = 0;
85216diff --git a/lib/debugobjects.c b/lib/debugobjects.c
85217index 37061ed..da83f48 100644
85218--- a/lib/debugobjects.c
85219+++ b/lib/debugobjects.c
85220@@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
85221 if (limit > 4)
85222 return;
85223
85224- is_on_stack = object_is_on_stack(addr);
85225+ is_on_stack = object_starts_on_stack(addr);
85226 if (is_on_stack == onstack)
85227 return;
85228
85229diff --git a/lib/devres.c b/lib/devres.c
85230index 8235331..5881053 100644
85231--- a/lib/devres.c
85232+++ b/lib/devres.c
85233@@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
85234 void devm_iounmap(struct device *dev, void __iomem *addr)
85235 {
85236 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
85237- (void *)addr));
85238+ (void __force *)addr));
85239 iounmap(addr);
85240 }
85241 EXPORT_SYMBOL(devm_iounmap);
85242@@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
85243 {
85244 ioport_unmap(addr);
85245 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
85246- devm_ioport_map_match, (void *)addr));
85247+ devm_ioport_map_match, (void __force *)addr));
85248 }
85249 EXPORT_SYMBOL(devm_ioport_unmap);
85250 #endif /* CONFIG_HAS_IOPORT */
85251diff --git a/lib/div64.c b/lib/div64.c
85252index a163b6c..9618fa5 100644
85253--- a/lib/div64.c
85254+++ b/lib/div64.c
85255@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
85256 EXPORT_SYMBOL(__div64_32);
85257
85258 #ifndef div_s64_rem
85259-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
85260+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
85261 {
85262 u64 quotient;
85263
85264@@ -90,7 +90,7 @@ EXPORT_SYMBOL(div_s64_rem);
85265 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
85266 */
85267 #ifndef div64_u64
85268-u64 div64_u64(u64 dividend, u64 divisor)
85269+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
85270 {
85271 u32 high = divisor >> 32;
85272 u64 quot;
85273diff --git a/lib/dma-debug.c b/lib/dma-debug.c
85274index d87a17a..ac0d79a 100644
85275--- a/lib/dma-debug.c
85276+++ b/lib/dma-debug.c
85277@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
85278
85279 void dma_debug_add_bus(struct bus_type *bus)
85280 {
85281- struct notifier_block *nb;
85282+ notifier_block_no_const *nb;
85283
85284 if (global_disable)
85285 return;
85286@@ -945,7 +945,7 @@ static void check_unmap(struct dma_debug_entry *ref)
85287
85288 static void check_for_stack(struct device *dev, void *addr)
85289 {
85290- if (object_is_on_stack(addr))
85291+ if (object_starts_on_stack(addr))
85292 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
85293 "stack [addr=%p]\n", addr);
85294 }
85295diff --git a/lib/inflate.c b/lib/inflate.c
85296index 013a761..c28f3fc 100644
85297--- a/lib/inflate.c
85298+++ b/lib/inflate.c
85299@@ -269,7 +269,7 @@ static void free(void *where)
85300 malloc_ptr = free_mem_ptr;
85301 }
85302 #else
85303-#define malloc(a) kmalloc(a, GFP_KERNEL)
85304+#define malloc(a) kmalloc((a), GFP_KERNEL)
85305 #define free(a) kfree(a)
85306 #endif
85307
85308diff --git a/lib/ioremap.c b/lib/ioremap.c
85309index 0c9216c..863bd89 100644
85310--- a/lib/ioremap.c
85311+++ b/lib/ioremap.c
85312@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
85313 unsigned long next;
85314
85315 phys_addr -= addr;
85316- pmd = pmd_alloc(&init_mm, pud, addr);
85317+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
85318 if (!pmd)
85319 return -ENOMEM;
85320 do {
85321@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
85322 unsigned long next;
85323
85324 phys_addr -= addr;
85325- pud = pud_alloc(&init_mm, pgd, addr);
85326+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
85327 if (!pud)
85328 return -ENOMEM;
85329 do {
85330diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
85331index bd2bea9..6b3c95e 100644
85332--- a/lib/is_single_threaded.c
85333+++ b/lib/is_single_threaded.c
85334@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
85335 struct task_struct *p, *t;
85336 bool ret;
85337
85338+ if (!mm)
85339+ return true;
85340+
85341 if (atomic_read(&task->signal->live) != 1)
85342 return false;
85343
85344diff --git a/lib/kobject.c b/lib/kobject.c
85345index 4a1f33d..2f3ca75 100644
85346--- a/lib/kobject.c
85347+++ b/lib/kobject.c
85348@@ -859,9 +859,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
85349
85350
85351 static DEFINE_SPINLOCK(kobj_ns_type_lock);
85352-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
85353+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
85354
85355-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
85356+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
85357 {
85358 enum kobj_ns_type type = ops->type;
85359 int error;
85360diff --git a/lib/list_debug.c b/lib/list_debug.c
85361index c24c2f7..f0296f4 100644
85362--- a/lib/list_debug.c
85363+++ b/lib/list_debug.c
85364@@ -11,7 +11,9 @@
85365 #include <linux/bug.h>
85366 #include <linux/kernel.h>
85367 #include <linux/rculist.h>
85368+#include <linux/mm.h>
85369
85370+#ifdef CONFIG_DEBUG_LIST
85371 /*
85372 * Insert a new entry between two known consecutive entries.
85373 *
85374@@ -19,21 +21,40 @@
85375 * the prev/next entries already!
85376 */
85377
85378+static bool __list_add_debug(struct list_head *new,
85379+ struct list_head *prev,
85380+ struct list_head *next)
85381+{
85382+ if (unlikely(next->prev != prev)) {
85383+ printk(KERN_ERR "list_add corruption. next->prev should be "
85384+ "prev (%p), but was %p. (next=%p).\n",
85385+ prev, next->prev, next);
85386+ BUG();
85387+ return false;
85388+ }
85389+ if (unlikely(prev->next != next)) {
85390+ printk(KERN_ERR "list_add corruption. prev->next should be "
85391+ "next (%p), but was %p. (prev=%p).\n",
85392+ next, prev->next, prev);
85393+ BUG();
85394+ return false;
85395+ }
85396+ if (unlikely(new == prev || new == next)) {
85397+ printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
85398+ new, prev, next);
85399+ BUG();
85400+ return false;
85401+ }
85402+ return true;
85403+}
85404+
85405 void __list_add(struct list_head *new,
85406- struct list_head *prev,
85407- struct list_head *next)
85408+ struct list_head *prev,
85409+ struct list_head *next)
85410 {
85411- WARN(next->prev != prev,
85412- "list_add corruption. next->prev should be "
85413- "prev (%p), but was %p. (next=%p).\n",
85414- prev, next->prev, next);
85415- WARN(prev->next != next,
85416- "list_add corruption. prev->next should be "
85417- "next (%p), but was %p. (prev=%p).\n",
85418- next, prev->next, prev);
85419- WARN(new == prev || new == next,
85420- "list_add double add: new=%p, prev=%p, next=%p.\n",
85421- new, prev, next);
85422+ if (!__list_add_debug(new, prev, next))
85423+ return;
85424+
85425 next->prev = new;
85426 new->next = next;
85427 new->prev = prev;
85428@@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
85429 }
85430 EXPORT_SYMBOL(__list_add);
85431
85432-void __list_del_entry(struct list_head *entry)
85433+static bool __list_del_entry_debug(struct list_head *entry)
85434 {
85435 struct list_head *prev, *next;
85436
85437 prev = entry->prev;
85438 next = entry->next;
85439
85440- if (WARN(next == LIST_POISON1,
85441- "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
85442- entry, LIST_POISON1) ||
85443- WARN(prev == LIST_POISON2,
85444- "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
85445- entry, LIST_POISON2) ||
85446- WARN(prev->next != entry,
85447- "list_del corruption. prev->next should be %p, "
85448- "but was %p\n", entry, prev->next) ||
85449- WARN(next->prev != entry,
85450- "list_del corruption. next->prev should be %p, "
85451- "but was %p\n", entry, next->prev))
85452+ if (unlikely(next == LIST_POISON1)) {
85453+ printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
85454+ entry, LIST_POISON1);
85455+ BUG();
85456+ return false;
85457+ }
85458+ if (unlikely(prev == LIST_POISON2)) {
85459+ printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
85460+ entry, LIST_POISON2);
85461+ BUG();
85462+ return false;
85463+ }
85464+ if (unlikely(entry->prev->next != entry)) {
85465+ printk(KERN_ERR "list_del corruption. prev->next should be %p, "
85466+ "but was %p\n", entry, prev->next);
85467+ BUG();
85468+ return false;
85469+ }
85470+ if (unlikely(entry->next->prev != entry)) {
85471+ printk(KERN_ERR "list_del corruption. next->prev should be %p, "
85472+ "but was %p\n", entry, next->prev);
85473+ BUG();
85474+ return false;
85475+ }
85476+ return true;
85477+}
85478+
85479+void __list_del_entry(struct list_head *entry)
85480+{
85481+ if (!__list_del_entry_debug(entry))
85482 return;
85483
85484- __list_del(prev, next);
85485+ __list_del(entry->prev, entry->next);
85486 }
85487 EXPORT_SYMBOL(__list_del_entry);
85488
85489@@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
85490 void __list_add_rcu(struct list_head *new,
85491 struct list_head *prev, struct list_head *next)
85492 {
85493- WARN(next->prev != prev,
85494- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
85495- prev, next->prev, next);
85496- WARN(prev->next != next,
85497- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
85498- next, prev->next, prev);
85499+ if (!__list_add_debug(new, prev, next))
85500+ return;
85501+
85502 new->next = next;
85503 new->prev = prev;
85504 rcu_assign_pointer(list_next_rcu(prev), new);
85505 next->prev = new;
85506 }
85507 EXPORT_SYMBOL(__list_add_rcu);
85508+#endif
85509+
85510+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
85511+{
85512+#ifdef CONFIG_DEBUG_LIST
85513+ if (!__list_add_debug(new, prev, next))
85514+ return;
85515+#endif
85516+
85517+ pax_open_kernel();
85518+ next->prev = new;
85519+ new->next = next;
85520+ new->prev = prev;
85521+ prev->next = new;
85522+ pax_close_kernel();
85523+}
85524+EXPORT_SYMBOL(__pax_list_add);
85525+
85526+void pax_list_del(struct list_head *entry)
85527+{
85528+#ifdef CONFIG_DEBUG_LIST
85529+ if (!__list_del_entry_debug(entry))
85530+ return;
85531+#endif
85532+
85533+ pax_open_kernel();
85534+ __list_del(entry->prev, entry->next);
85535+ entry->next = LIST_POISON1;
85536+ entry->prev = LIST_POISON2;
85537+ pax_close_kernel();
85538+}
85539+EXPORT_SYMBOL(pax_list_del);
85540+
85541+void pax_list_del_init(struct list_head *entry)
85542+{
85543+ pax_open_kernel();
85544+ __list_del(entry->prev, entry->next);
85545+ INIT_LIST_HEAD(entry);
85546+ pax_close_kernel();
85547+}
85548+EXPORT_SYMBOL(pax_list_del_init);
85549+
85550+void __pax_list_add_rcu(struct list_head *new,
85551+ struct list_head *prev, struct list_head *next)
85552+{
85553+#ifdef CONFIG_DEBUG_LIST
85554+ if (!__list_add_debug(new, prev, next))
85555+ return;
85556+#endif
85557+
85558+ pax_open_kernel();
85559+ new->next = next;
85560+ new->prev = prev;
85561+ rcu_assign_pointer(list_next_rcu(prev), new);
85562+ next->prev = new;
85563+ pax_close_kernel();
85564+}
85565+EXPORT_SYMBOL(__pax_list_add_rcu);
85566+
85567+void pax_list_del_rcu(struct list_head *entry)
85568+{
85569+#ifdef CONFIG_DEBUG_LIST
85570+ if (!__list_del_entry_debug(entry))
85571+ return;
85572+#endif
85573+
85574+ pax_open_kernel();
85575+ __list_del(entry->prev, entry->next);
85576+ entry->next = LIST_POISON1;
85577+ entry->prev = LIST_POISON2;
85578+ pax_close_kernel();
85579+}
85580+EXPORT_SYMBOL(pax_list_del_rcu);
85581diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
85582index 7deeb62..144eb47 100644
85583--- a/lib/percpu-refcount.c
85584+++ b/lib/percpu-refcount.c
85585@@ -29,7 +29,7 @@
85586 * can't hit 0 before we've added up all the percpu refs.
85587 */
85588
85589-#define PCPU_COUNT_BIAS (1U << 31)
85590+#define PCPU_COUNT_BIAS (1U << 30)
85591
85592 /**
85593 * percpu_ref_init - initialize a percpu refcount
85594diff --git a/lib/radix-tree.c b/lib/radix-tree.c
85595index e796429..6e38f9f 100644
85596--- a/lib/radix-tree.c
85597+++ b/lib/radix-tree.c
85598@@ -92,7 +92,7 @@ struct radix_tree_preload {
85599 int nr;
85600 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
85601 };
85602-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
85603+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
85604
85605 static inline void *ptr_to_indirect(void *ptr)
85606 {
85607diff --git a/lib/scatterlist.c b/lib/scatterlist.c
85608index a685c8a..d16fa29 100644
85609--- a/lib/scatterlist.c
85610+++ b/lib/scatterlist.c
85611@@ -577,7 +577,8 @@ void sg_miter_stop(struct sg_mapping_iter *miter)
85612 miter->__offset += miter->consumed;
85613 miter->__remaining -= miter->consumed;
85614
85615- if (miter->__flags & SG_MITER_TO_SG)
85616+ if ((miter->__flags & SG_MITER_TO_SG) &&
85617+ !PageSlab(miter->page))
85618 flush_kernel_dcache_page(miter->page);
85619
85620 if (miter->__flags & SG_MITER_ATOMIC) {
85621diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
85622index bb2b201..46abaf9 100644
85623--- a/lib/strncpy_from_user.c
85624+++ b/lib/strncpy_from_user.c
85625@@ -21,7 +21,7 @@
85626 */
85627 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
85628 {
85629- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85630+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85631 long res = 0;
85632
85633 /*
85634diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
85635index a28df52..3d55877 100644
85636--- a/lib/strnlen_user.c
85637+++ b/lib/strnlen_user.c
85638@@ -26,7 +26,7 @@
85639 */
85640 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
85641 {
85642- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85643+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85644 long align, res = 0;
85645 unsigned long c;
85646
85647diff --git a/lib/swiotlb.c b/lib/swiotlb.c
85648index d23762e..e21eab2 100644
85649--- a/lib/swiotlb.c
85650+++ b/lib/swiotlb.c
85651@@ -664,7 +664,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
85652
85653 void
85654 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
85655- dma_addr_t dev_addr)
85656+ dma_addr_t dev_addr, struct dma_attrs *attrs)
85657 {
85658 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
85659
85660diff --git a/lib/usercopy.c b/lib/usercopy.c
85661index 4f5b1dd..7cab418 100644
85662--- a/lib/usercopy.c
85663+++ b/lib/usercopy.c
85664@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
85665 WARN(1, "Buffer overflow detected!\n");
85666 }
85667 EXPORT_SYMBOL(copy_from_user_overflow);
85668+
85669+void copy_to_user_overflow(void)
85670+{
85671+ WARN(1, "Buffer overflow detected!\n");
85672+}
85673+EXPORT_SYMBOL(copy_to_user_overflow);
85674diff --git a/lib/vsprintf.c b/lib/vsprintf.c
85675index 739a363..aa668d7 100644
85676--- a/lib/vsprintf.c
85677+++ b/lib/vsprintf.c
85678@@ -16,6 +16,9 @@
85679 * - scnprintf and vscnprintf
85680 */
85681
85682+#ifdef CONFIG_GRKERNSEC_HIDESYM
85683+#define __INCLUDED_BY_HIDESYM 1
85684+#endif
85685 #include <stdarg.h>
85686 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
85687 #include <linux/types.h>
85688@@ -1078,7 +1081,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
85689 return number(buf, end, *(const netdev_features_t *)addr, spec);
85690 }
85691
85692+#ifdef CONFIG_GRKERNSEC_HIDESYM
85693+int kptr_restrict __read_mostly = 2;
85694+#else
85695 int kptr_restrict __read_mostly;
85696+#endif
85697
85698 /*
85699 * Show a '%p' thing. A kernel extension is that the '%p' is followed
85700@@ -1091,6 +1098,7 @@ int kptr_restrict __read_mostly;
85701 * - 'f' For simple symbolic function names without offset
85702 * - 'S' For symbolic direct pointers with offset
85703 * - 's' For symbolic direct pointers without offset
85704+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
85705 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
85706 * - 'B' For backtraced symbolic direct pointers with offset
85707 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
85708@@ -1155,12 +1163,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85709
85710 if (!ptr && *fmt != 'K') {
85711 /*
85712- * Print (null) with the same width as a pointer so it makes
85713+ * Print (nil) with the same width as a pointer so it makes
85714 * tabular output look nice.
85715 */
85716 if (spec.field_width == -1)
85717 spec.field_width = default_width;
85718- return string(buf, end, "(null)", spec);
85719+ return string(buf, end, "(nil)", spec);
85720 }
85721
85722 switch (*fmt) {
85723@@ -1170,6 +1178,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85724 /* Fallthrough */
85725 case 'S':
85726 case 's':
85727+#ifdef CONFIG_GRKERNSEC_HIDESYM
85728+ break;
85729+#else
85730+ return symbol_string(buf, end, ptr, spec, fmt);
85731+#endif
85732+ case 'A':
85733 case 'B':
85734 return symbol_string(buf, end, ptr, spec, fmt);
85735 case 'R':
85736@@ -1225,6 +1239,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85737 va_end(va);
85738 return buf;
85739 }
85740+ case 'P':
85741+ break;
85742 case 'K':
85743 /*
85744 * %pK cannot be used in IRQ context because its test
85745@@ -1254,6 +1270,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85746 return number(buf, end,
85747 (unsigned long long) *((phys_addr_t *)ptr), spec);
85748 }
85749+
85750+#ifdef CONFIG_GRKERNSEC_HIDESYM
85751+ /* 'P' = approved pointers to copy to userland,
85752+ as in the /proc/kallsyms case, as we make it display nothing
85753+ for non-root users, and the real contents for root users
85754+ Also ignore 'K' pointers, since we force their NULLing for non-root users
85755+ above
85756+ */
85757+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
85758+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
85759+ dump_stack();
85760+ ptr = NULL;
85761+ }
85762+#endif
85763+
85764 spec.flags |= SMALL;
85765 if (spec.field_width == -1) {
85766 spec.field_width = default_width;
85767@@ -1977,11 +2008,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
85768 typeof(type) value; \
85769 if (sizeof(type) == 8) { \
85770 args = PTR_ALIGN(args, sizeof(u32)); \
85771- *(u32 *)&value = *(u32 *)args; \
85772- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
85773+ *(u32 *)&value = *(const u32 *)args; \
85774+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
85775 } else { \
85776 args = PTR_ALIGN(args, sizeof(type)); \
85777- value = *(typeof(type) *)args; \
85778+ value = *(const typeof(type) *)args; \
85779 } \
85780 args += sizeof(type); \
85781 value; \
85782@@ -2044,7 +2075,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
85783 case FORMAT_TYPE_STR: {
85784 const char *str_arg = args;
85785 args += strlen(str_arg) + 1;
85786- str = string(str, end, (char *)str_arg, spec);
85787+ str = string(str, end, str_arg, spec);
85788 break;
85789 }
85790
85791diff --git a/localversion-grsec b/localversion-grsec
85792new file mode 100644
85793index 0000000..7cd6065
85794--- /dev/null
85795+++ b/localversion-grsec
85796@@ -0,0 +1 @@
85797+-grsec
85798diff --git a/mm/Kconfig b/mm/Kconfig
85799index 6509d27..dbec5b8 100644
85800--- a/mm/Kconfig
85801+++ b/mm/Kconfig
85802@@ -317,10 +317,10 @@ config KSM
85803 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
85804
85805 config DEFAULT_MMAP_MIN_ADDR
85806- int "Low address space to protect from user allocation"
85807+ int "Low address space to protect from user allocation"
85808 depends on MMU
85809- default 4096
85810- help
85811+ default 65536
85812+ help
85813 This is the portion of low virtual memory which should be protected
85814 from userspace allocation. Keeping a user from writing to low pages
85815 can help reduce the impact of kernel NULL pointer bugs.
85816@@ -351,7 +351,7 @@ config MEMORY_FAILURE
85817
85818 config HWPOISON_INJECT
85819 tristate "HWPoison pages injector"
85820- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
85821+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
85822 select PROC_PAGE_MONITOR
85823
85824 config NOMMU_INITIAL_TRIM_EXCESS
85825diff --git a/mm/backing-dev.c b/mm/backing-dev.c
85826index e04454c..ca5be3e 100644
85827--- a/mm/backing-dev.c
85828+++ b/mm/backing-dev.c
85829@@ -12,7 +12,7 @@
85830 #include <linux/device.h>
85831 #include <trace/events/writeback.h>
85832
85833-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
85834+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
85835
85836 struct backing_dev_info default_backing_dev_info = {
85837 .name = "default",
85838@@ -522,7 +522,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
85839 return err;
85840
85841 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
85842- atomic_long_inc_return(&bdi_seq));
85843+ atomic_long_inc_return_unchecked(&bdi_seq));
85844 if (err) {
85845 bdi_destroy(bdi);
85846 return err;
85847diff --git a/mm/filemap.c b/mm/filemap.c
85848index 4b51ac1..5aa90ff 100644
85849--- a/mm/filemap.c
85850+++ b/mm/filemap.c
85851@@ -1766,7 +1766,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
85852 struct address_space *mapping = file->f_mapping;
85853
85854 if (!mapping->a_ops->readpage)
85855- return -ENOEXEC;
85856+ return -ENODEV;
85857 file_accessed(file);
85858 vma->vm_ops = &generic_file_vm_ops;
85859 return 0;
85860@@ -1948,7 +1948,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
85861
85862 while (bytes) {
85863 char __user *buf = iov->iov_base + base;
85864- int copy = min(bytes, iov->iov_len - base);
85865+ size_t copy = min(bytes, iov->iov_len - base);
85866
85867 base = 0;
85868 left = __copy_from_user_inatomic(vaddr, buf, copy);
85869@@ -1977,7 +1977,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
85870 BUG_ON(!in_atomic());
85871 kaddr = kmap_atomic(page);
85872 if (likely(i->nr_segs == 1)) {
85873- int left;
85874+ size_t left;
85875 char __user *buf = i->iov->iov_base + i->iov_offset;
85876 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
85877 copied = bytes - left;
85878@@ -2005,7 +2005,7 @@ size_t iov_iter_copy_from_user(struct page *page,
85879
85880 kaddr = kmap(page);
85881 if (likely(i->nr_segs == 1)) {
85882- int left;
85883+ size_t left;
85884 char __user *buf = i->iov->iov_base + i->iov_offset;
85885 left = __copy_from_user(kaddr + offset, buf, bytes);
85886 copied = bytes - left;
85887@@ -2035,7 +2035,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
85888 * zero-length segments (without overruning the iovec).
85889 */
85890 while (bytes || unlikely(i->count && !iov->iov_len)) {
85891- int copy;
85892+ size_t copy;
85893
85894 copy = min(bytes, iov->iov_len - base);
85895 BUG_ON(!i->count || i->count < copy);
85896@@ -2106,6 +2106,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
85897 *pos = i_size_read(inode);
85898
85899 if (limit != RLIM_INFINITY) {
85900+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
85901 if (*pos >= limit) {
85902 send_sig(SIGXFSZ, current, 0);
85903 return -EFBIG;
85904diff --git a/mm/fremap.c b/mm/fremap.c
85905index 5bff081..d8189a9 100644
85906--- a/mm/fremap.c
85907+++ b/mm/fremap.c
85908@@ -163,6 +163,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
85909 retry:
85910 vma = find_vma(mm, start);
85911
85912+#ifdef CONFIG_PAX_SEGMEXEC
85913+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
85914+ goto out;
85915+#endif
85916+
85917 /*
85918 * Make sure the vma is shared, that it supports prefaulting,
85919 * and that the remapped range is valid and fully within
85920diff --git a/mm/highmem.c b/mm/highmem.c
85921index b32b70c..e512eb0 100644
85922--- a/mm/highmem.c
85923+++ b/mm/highmem.c
85924@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
85925 * So no dangers, even with speculative execution.
85926 */
85927 page = pte_page(pkmap_page_table[i]);
85928+ pax_open_kernel();
85929 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
85930-
85931+ pax_close_kernel();
85932 set_page_address(page, NULL);
85933 need_flush = 1;
85934 }
85935@@ -198,9 +199,11 @@ start:
85936 }
85937 }
85938 vaddr = PKMAP_ADDR(last_pkmap_nr);
85939+
85940+ pax_open_kernel();
85941 set_pte_at(&init_mm, vaddr,
85942 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
85943-
85944+ pax_close_kernel();
85945 pkmap_count[last_pkmap_nr] = 1;
85946 set_page_address(page, (void *)vaddr);
85947
85948diff --git a/mm/hugetlb.c b/mm/hugetlb.c
85949index b60f330..ee7de7e 100644
85950--- a/mm/hugetlb.c
85951+++ b/mm/hugetlb.c
85952@@ -2022,15 +2022,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
85953 struct hstate *h = &default_hstate;
85954 unsigned long tmp;
85955 int ret;
85956+ ctl_table_no_const hugetlb_table;
85957
85958 tmp = h->max_huge_pages;
85959
85960 if (write && h->order >= MAX_ORDER)
85961 return -EINVAL;
85962
85963- table->data = &tmp;
85964- table->maxlen = sizeof(unsigned long);
85965- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
85966+ hugetlb_table = *table;
85967+ hugetlb_table.data = &tmp;
85968+ hugetlb_table.maxlen = sizeof(unsigned long);
85969+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
85970 if (ret)
85971 goto out;
85972
85973@@ -2087,15 +2089,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
85974 struct hstate *h = &default_hstate;
85975 unsigned long tmp;
85976 int ret;
85977+ ctl_table_no_const hugetlb_table;
85978
85979 tmp = h->nr_overcommit_huge_pages;
85980
85981 if (write && h->order >= MAX_ORDER)
85982 return -EINVAL;
85983
85984- table->data = &tmp;
85985- table->maxlen = sizeof(unsigned long);
85986- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
85987+ hugetlb_table = *table;
85988+ hugetlb_table.data = &tmp;
85989+ hugetlb_table.maxlen = sizeof(unsigned long);
85990+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
85991 if (ret)
85992 goto out;
85993
85994@@ -2545,6 +2549,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
85995 return 1;
85996 }
85997
85998+#ifdef CONFIG_PAX_SEGMEXEC
85999+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
86000+{
86001+ struct mm_struct *mm = vma->vm_mm;
86002+ struct vm_area_struct *vma_m;
86003+ unsigned long address_m;
86004+ pte_t *ptep_m;
86005+
86006+ vma_m = pax_find_mirror_vma(vma);
86007+ if (!vma_m)
86008+ return;
86009+
86010+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
86011+ address_m = address + SEGMEXEC_TASK_SIZE;
86012+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
86013+ get_page(page_m);
86014+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
86015+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
86016+}
86017+#endif
86018+
86019 /*
86020 * Hugetlb_cow() should be called with page lock of the original hugepage held.
86021 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
86022@@ -2663,6 +2688,11 @@ retry_avoidcopy:
86023 make_huge_pte(vma, new_page, 1));
86024 page_remove_rmap(old_page);
86025 hugepage_add_new_anon_rmap(new_page, vma, address);
86026+
86027+#ifdef CONFIG_PAX_SEGMEXEC
86028+ pax_mirror_huge_pte(vma, address, new_page);
86029+#endif
86030+
86031 /* Make the old page be freed below */
86032 new_page = old_page;
86033 }
86034@@ -2821,6 +2851,10 @@ retry:
86035 && (vma->vm_flags & VM_SHARED)));
86036 set_huge_pte_at(mm, address, ptep, new_pte);
86037
86038+#ifdef CONFIG_PAX_SEGMEXEC
86039+ pax_mirror_huge_pte(vma, address, page);
86040+#endif
86041+
86042 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
86043 /* Optimization, do the COW without a second fault */
86044 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
86045@@ -2850,6 +2884,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86046 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
86047 struct hstate *h = hstate_vma(vma);
86048
86049+#ifdef CONFIG_PAX_SEGMEXEC
86050+ struct vm_area_struct *vma_m;
86051+#endif
86052+
86053 address &= huge_page_mask(h);
86054
86055 ptep = huge_pte_offset(mm, address);
86056@@ -2863,6 +2901,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86057 VM_FAULT_SET_HINDEX(hstate_index(h));
86058 }
86059
86060+#ifdef CONFIG_PAX_SEGMEXEC
86061+ vma_m = pax_find_mirror_vma(vma);
86062+ if (vma_m) {
86063+ unsigned long address_m;
86064+
86065+ if (vma->vm_start > vma_m->vm_start) {
86066+ address_m = address;
86067+ address -= SEGMEXEC_TASK_SIZE;
86068+ vma = vma_m;
86069+ h = hstate_vma(vma);
86070+ } else
86071+ address_m = address + SEGMEXEC_TASK_SIZE;
86072+
86073+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
86074+ return VM_FAULT_OOM;
86075+ address_m &= HPAGE_MASK;
86076+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
86077+ }
86078+#endif
86079+
86080 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
86081 if (!ptep)
86082 return VM_FAULT_OOM;
86083diff --git a/mm/internal.h b/mm/internal.h
86084index 4390ac6..fc60373c 100644
86085--- a/mm/internal.h
86086+++ b/mm/internal.h
86087@@ -95,6 +95,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
86088 * in mm/page_alloc.c
86089 */
86090 extern void __free_pages_bootmem(struct page *page, unsigned int order);
86091+extern void free_compound_page(struct page *page);
86092 extern void prep_compound_page(struct page *page, unsigned long order);
86093 #ifdef CONFIG_MEMORY_FAILURE
86094 extern bool is_free_buddy_page(struct page *page);
86095@@ -350,7 +351,7 @@ extern u32 hwpoison_filter_enable;
86096
86097 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
86098 unsigned long, unsigned long,
86099- unsigned long, unsigned long);
86100+ unsigned long, unsigned long) __intentional_overflow(-1);
86101
86102 extern void set_pageblock_order(void);
86103 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
86104diff --git a/mm/kmemleak.c b/mm/kmemleak.c
86105index c8d7f31..2dbeffd 100644
86106--- a/mm/kmemleak.c
86107+++ b/mm/kmemleak.c
86108@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
86109
86110 for (i = 0; i < object->trace_len; i++) {
86111 void *ptr = (void *)object->trace[i];
86112- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
86113+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
86114 }
86115 }
86116
86117@@ -1851,7 +1851,7 @@ static int __init kmemleak_late_init(void)
86118 return -ENOMEM;
86119 }
86120
86121- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
86122+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
86123 &kmemleak_fops);
86124 if (!dentry)
86125 pr_warning("Failed to create the debugfs kmemleak file\n");
86126diff --git a/mm/maccess.c b/mm/maccess.c
86127index d53adf9..03a24bf 100644
86128--- a/mm/maccess.c
86129+++ b/mm/maccess.c
86130@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
86131 set_fs(KERNEL_DS);
86132 pagefault_disable();
86133 ret = __copy_from_user_inatomic(dst,
86134- (__force const void __user *)src, size);
86135+ (const void __force_user *)src, size);
86136 pagefault_enable();
86137 set_fs(old_fs);
86138
86139@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
86140
86141 set_fs(KERNEL_DS);
86142 pagefault_disable();
86143- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
86144+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
86145 pagefault_enable();
86146 set_fs(old_fs);
86147
86148diff --git a/mm/madvise.c b/mm/madvise.c
86149index 7055883..aafb1ed 100644
86150--- a/mm/madvise.c
86151+++ b/mm/madvise.c
86152@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
86153 pgoff_t pgoff;
86154 unsigned long new_flags = vma->vm_flags;
86155
86156+#ifdef CONFIG_PAX_SEGMEXEC
86157+ struct vm_area_struct *vma_m;
86158+#endif
86159+
86160 switch (behavior) {
86161 case MADV_NORMAL:
86162 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
86163@@ -126,6 +130,13 @@ success:
86164 /*
86165 * vm_flags is protected by the mmap_sem held in write mode.
86166 */
86167+
86168+#ifdef CONFIG_PAX_SEGMEXEC
86169+ vma_m = pax_find_mirror_vma(vma);
86170+ if (vma_m)
86171+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
86172+#endif
86173+
86174 vma->vm_flags = new_flags;
86175
86176 out:
86177@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
86178 struct vm_area_struct ** prev,
86179 unsigned long start, unsigned long end)
86180 {
86181+
86182+#ifdef CONFIG_PAX_SEGMEXEC
86183+ struct vm_area_struct *vma_m;
86184+#endif
86185+
86186 *prev = vma;
86187 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
86188 return -EINVAL;
86189@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
86190 zap_page_range(vma, start, end - start, &details);
86191 } else
86192 zap_page_range(vma, start, end - start, NULL);
86193+
86194+#ifdef CONFIG_PAX_SEGMEXEC
86195+ vma_m = pax_find_mirror_vma(vma);
86196+ if (vma_m) {
86197+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
86198+ struct zap_details details = {
86199+ .nonlinear_vma = vma_m,
86200+ .last_index = ULONG_MAX,
86201+ };
86202+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
86203+ } else
86204+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
86205+ }
86206+#endif
86207+
86208 return 0;
86209 }
86210
86211@@ -485,6 +516,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
86212 if (end < start)
86213 return error;
86214
86215+#ifdef CONFIG_PAX_SEGMEXEC
86216+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
86217+ if (end > SEGMEXEC_TASK_SIZE)
86218+ return error;
86219+ } else
86220+#endif
86221+
86222+ if (end > TASK_SIZE)
86223+ return error;
86224+
86225 error = 0;
86226 if (end == start)
86227 return error;
86228diff --git a/mm/memcontrol.c b/mm/memcontrol.c
86229index aa44621..99011b3 100644
86230--- a/mm/memcontrol.c
86231+++ b/mm/memcontrol.c
86232@@ -2772,6 +2772,8 @@ done:
86233 return 0;
86234 nomem:
86235 *ptr = NULL;
86236+ if (gfp_mask & __GFP_NOFAIL)
86237+ return 0;
86238 return -ENOMEM;
86239 bypass:
86240 *ptr = root_mem_cgroup;
86241diff --git a/mm/memory-failure.c b/mm/memory-failure.c
86242index 2c13aa7..64cbc3f 100644
86243--- a/mm/memory-failure.c
86244+++ b/mm/memory-failure.c
86245@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
86246
86247 int sysctl_memory_failure_recovery __read_mostly = 1;
86248
86249-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
86250+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
86251
86252 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
86253
86254@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
86255 pfn, t->comm, t->pid);
86256 si.si_signo = SIGBUS;
86257 si.si_errno = 0;
86258- si.si_addr = (void *)addr;
86259+ si.si_addr = (void __user *)addr;
86260 #ifdef __ARCH_SI_TRAPNO
86261 si.si_trapno = trapno;
86262 #endif
86263@@ -760,7 +760,7 @@ static struct page_state {
86264 unsigned long res;
86265 char *msg;
86266 int (*action)(struct page *p, unsigned long pfn);
86267-} error_states[] = {
86268+} __do_const error_states[] = {
86269 { reserved, reserved, "reserved kernel", me_kernel },
86270 /*
86271 * free pages are specially detected outside this table:
86272@@ -1051,7 +1051,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
86273 nr_pages = 1 << compound_order(hpage);
86274 else /* normal page or thp */
86275 nr_pages = 1;
86276- atomic_long_add(nr_pages, &num_poisoned_pages);
86277+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
86278
86279 /*
86280 * We need/can do nothing about count=0 pages.
86281@@ -1081,7 +1081,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
86282 if (!PageHWPoison(hpage)
86283 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
86284 || (p != hpage && TestSetPageHWPoison(hpage))) {
86285- atomic_long_sub(nr_pages, &num_poisoned_pages);
86286+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
86287 return 0;
86288 }
86289 set_page_hwpoison_huge_page(hpage);
86290@@ -1148,7 +1148,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
86291 }
86292 if (hwpoison_filter(p)) {
86293 if (TestClearPageHWPoison(p))
86294- atomic_long_sub(nr_pages, &num_poisoned_pages);
86295+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
86296 unlock_page(hpage);
86297 put_page(hpage);
86298 return 0;
86299@@ -1350,7 +1350,7 @@ int unpoison_memory(unsigned long pfn)
86300 return 0;
86301 }
86302 if (TestClearPageHWPoison(p))
86303- atomic_long_sub(nr_pages, &num_poisoned_pages);
86304+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
86305 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
86306 return 0;
86307 }
86308@@ -1364,7 +1364,7 @@ int unpoison_memory(unsigned long pfn)
86309 */
86310 if (TestClearPageHWPoison(page)) {
86311 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
86312- atomic_long_sub(nr_pages, &num_poisoned_pages);
86313+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
86314 freeit = 1;
86315 if (PageHuge(page))
86316 clear_page_hwpoison_huge_page(page);
86317@@ -1491,7 +1491,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
86318 } else {
86319 set_page_hwpoison_huge_page(hpage);
86320 dequeue_hwpoisoned_huge_page(hpage);
86321- atomic_long_add(1 << compound_trans_order(hpage),
86322+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
86323 &num_poisoned_pages);
86324 }
86325 return ret;
86326@@ -1551,11 +1551,11 @@ int soft_offline_page(struct page *page, int flags)
86327 if (PageHuge(page)) {
86328 set_page_hwpoison_huge_page(hpage);
86329 dequeue_hwpoisoned_huge_page(hpage);
86330- atomic_long_add(1 << compound_trans_order(hpage),
86331+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
86332 &num_poisoned_pages);
86333 } else {
86334 SetPageHWPoison(page);
86335- atomic_long_inc(&num_poisoned_pages);
86336+ atomic_long_inc_unchecked(&num_poisoned_pages);
86337 }
86338 }
86339 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
86340@@ -1595,7 +1595,7 @@ static int __soft_offline_page(struct page *page, int flags)
86341 put_page(page);
86342 pr_info("soft_offline: %#lx: invalidated\n", pfn);
86343 SetPageHWPoison(page);
86344- atomic_long_inc(&num_poisoned_pages);
86345+ atomic_long_inc_unchecked(&num_poisoned_pages);
86346 return 0;
86347 }
86348
86349@@ -1640,7 +1640,7 @@ static int __soft_offline_page(struct page *page, int flags)
86350 if (!is_free_buddy_page(page))
86351 pr_info("soft offline: %#lx: page leaked\n",
86352 pfn);
86353- atomic_long_inc(&num_poisoned_pages);
86354+ atomic_long_inc_unchecked(&num_poisoned_pages);
86355 }
86356 } else {
86357 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
86358diff --git a/mm/memory.c b/mm/memory.c
86359index 440986e..94b45d5 100644
86360--- a/mm/memory.c
86361+++ b/mm/memory.c
86362@@ -426,6 +426,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
86363 free_pte_range(tlb, pmd, addr);
86364 } while (pmd++, addr = next, addr != end);
86365
86366+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
86367 start &= PUD_MASK;
86368 if (start < floor)
86369 return;
86370@@ -440,6 +441,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
86371 pmd = pmd_offset(pud, start);
86372 pud_clear(pud);
86373 pmd_free_tlb(tlb, pmd, start);
86374+#endif
86375+
86376 }
86377
86378 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
86379@@ -459,6 +462,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
86380 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
86381 } while (pud++, addr = next, addr != end);
86382
86383+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
86384 start &= PGDIR_MASK;
86385 if (start < floor)
86386 return;
86387@@ -473,6 +477,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
86388 pud = pud_offset(pgd, start);
86389 pgd_clear(pgd);
86390 pud_free_tlb(tlb, pud, start);
86391+#endif
86392+
86393 }
86394
86395 /*
86396@@ -1647,12 +1653,6 @@ no_page_table:
86397 return page;
86398 }
86399
86400-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
86401-{
86402- return stack_guard_page_start(vma, addr) ||
86403- stack_guard_page_end(vma, addr+PAGE_SIZE);
86404-}
86405-
86406 /**
86407 * __get_user_pages() - pin user pages in memory
86408 * @tsk: task_struct of target task
86409@@ -1739,10 +1739,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
86410
86411 i = 0;
86412
86413- do {
86414+ while (nr_pages) {
86415 struct vm_area_struct *vma;
86416
86417- vma = find_extend_vma(mm, start);
86418+ vma = find_vma(mm, start);
86419 if (!vma && in_gate_area(mm, start)) {
86420 unsigned long pg = start & PAGE_MASK;
86421 pgd_t *pgd;
86422@@ -1791,7 +1791,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
86423 goto next_page;
86424 }
86425
86426- if (!vma ||
86427+ if (!vma || start < vma->vm_start ||
86428 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
86429 !(vm_flags & vma->vm_flags))
86430 return i ? : -EFAULT;
86431@@ -1820,11 +1820,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
86432 int ret;
86433 unsigned int fault_flags = 0;
86434
86435- /* For mlock, just skip the stack guard page. */
86436- if (foll_flags & FOLL_MLOCK) {
86437- if (stack_guard_page(vma, start))
86438- goto next_page;
86439- }
86440 if (foll_flags & FOLL_WRITE)
86441 fault_flags |= FAULT_FLAG_WRITE;
86442 if (nonblocking)
86443@@ -1904,7 +1899,7 @@ next_page:
86444 start += page_increm * PAGE_SIZE;
86445 nr_pages -= page_increm;
86446 } while (nr_pages && start < vma->vm_end);
86447- } while (nr_pages);
86448+ }
86449 return i;
86450 }
86451 EXPORT_SYMBOL(__get_user_pages);
86452@@ -2111,6 +2106,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
86453 page_add_file_rmap(page);
86454 set_pte_at(mm, addr, pte, mk_pte(page, prot));
86455
86456+#ifdef CONFIG_PAX_SEGMEXEC
86457+ pax_mirror_file_pte(vma, addr, page, ptl);
86458+#endif
86459+
86460 retval = 0;
86461 pte_unmap_unlock(pte, ptl);
86462 return retval;
86463@@ -2155,9 +2154,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
86464 if (!page_count(page))
86465 return -EINVAL;
86466 if (!(vma->vm_flags & VM_MIXEDMAP)) {
86467+
86468+#ifdef CONFIG_PAX_SEGMEXEC
86469+ struct vm_area_struct *vma_m;
86470+#endif
86471+
86472 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
86473 BUG_ON(vma->vm_flags & VM_PFNMAP);
86474 vma->vm_flags |= VM_MIXEDMAP;
86475+
86476+#ifdef CONFIG_PAX_SEGMEXEC
86477+ vma_m = pax_find_mirror_vma(vma);
86478+ if (vma_m)
86479+ vma_m->vm_flags |= VM_MIXEDMAP;
86480+#endif
86481+
86482 }
86483 return insert_page(vma, addr, page, vma->vm_page_prot);
86484 }
86485@@ -2240,6 +2251,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
86486 unsigned long pfn)
86487 {
86488 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
86489+ BUG_ON(vma->vm_mirror);
86490
86491 if (addr < vma->vm_start || addr >= vma->vm_end)
86492 return -EFAULT;
86493@@ -2487,7 +2499,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
86494
86495 BUG_ON(pud_huge(*pud));
86496
86497- pmd = pmd_alloc(mm, pud, addr);
86498+ pmd = (mm == &init_mm) ?
86499+ pmd_alloc_kernel(mm, pud, addr) :
86500+ pmd_alloc(mm, pud, addr);
86501 if (!pmd)
86502 return -ENOMEM;
86503 do {
86504@@ -2507,7 +2521,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
86505 unsigned long next;
86506 int err;
86507
86508- pud = pud_alloc(mm, pgd, addr);
86509+ pud = (mm == &init_mm) ?
86510+ pud_alloc_kernel(mm, pgd, addr) :
86511+ pud_alloc(mm, pgd, addr);
86512 if (!pud)
86513 return -ENOMEM;
86514 do {
86515@@ -2595,6 +2611,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
86516 copy_user_highpage(dst, src, va, vma);
86517 }
86518
86519+#ifdef CONFIG_PAX_SEGMEXEC
86520+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
86521+{
86522+ struct mm_struct *mm = vma->vm_mm;
86523+ spinlock_t *ptl;
86524+ pte_t *pte, entry;
86525+
86526+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
86527+ entry = *pte;
86528+ if (!pte_present(entry)) {
86529+ if (!pte_none(entry)) {
86530+ BUG_ON(pte_file(entry));
86531+ free_swap_and_cache(pte_to_swp_entry(entry));
86532+ pte_clear_not_present_full(mm, address, pte, 0);
86533+ }
86534+ } else {
86535+ struct page *page;
86536+
86537+ flush_cache_page(vma, address, pte_pfn(entry));
86538+ entry = ptep_clear_flush(vma, address, pte);
86539+ BUG_ON(pte_dirty(entry));
86540+ page = vm_normal_page(vma, address, entry);
86541+ if (page) {
86542+ update_hiwater_rss(mm);
86543+ if (PageAnon(page))
86544+ dec_mm_counter_fast(mm, MM_ANONPAGES);
86545+ else
86546+ dec_mm_counter_fast(mm, MM_FILEPAGES);
86547+ page_remove_rmap(page);
86548+ page_cache_release(page);
86549+ }
86550+ }
86551+ pte_unmap_unlock(pte, ptl);
86552+}
86553+
86554+/* PaX: if vma is mirrored, synchronize the mirror's PTE
86555+ *
86556+ * the ptl of the lower mapped page is held on entry and is not released on exit
86557+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
86558+ */
86559+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
86560+{
86561+ struct mm_struct *mm = vma->vm_mm;
86562+ unsigned long address_m;
86563+ spinlock_t *ptl_m;
86564+ struct vm_area_struct *vma_m;
86565+ pmd_t *pmd_m;
86566+ pte_t *pte_m, entry_m;
86567+
86568+ BUG_ON(!page_m || !PageAnon(page_m));
86569+
86570+ vma_m = pax_find_mirror_vma(vma);
86571+ if (!vma_m)
86572+ return;
86573+
86574+ BUG_ON(!PageLocked(page_m));
86575+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
86576+ address_m = address + SEGMEXEC_TASK_SIZE;
86577+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
86578+ pte_m = pte_offset_map(pmd_m, address_m);
86579+ ptl_m = pte_lockptr(mm, pmd_m);
86580+ if (ptl != ptl_m) {
86581+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
86582+ if (!pte_none(*pte_m))
86583+ goto out;
86584+ }
86585+
86586+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
86587+ page_cache_get(page_m);
86588+ page_add_anon_rmap(page_m, vma_m, address_m);
86589+ inc_mm_counter_fast(mm, MM_ANONPAGES);
86590+ set_pte_at(mm, address_m, pte_m, entry_m);
86591+ update_mmu_cache(vma_m, address_m, pte_m);
86592+out:
86593+ if (ptl != ptl_m)
86594+ spin_unlock(ptl_m);
86595+ pte_unmap(pte_m);
86596+ unlock_page(page_m);
86597+}
86598+
86599+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
86600+{
86601+ struct mm_struct *mm = vma->vm_mm;
86602+ unsigned long address_m;
86603+ spinlock_t *ptl_m;
86604+ struct vm_area_struct *vma_m;
86605+ pmd_t *pmd_m;
86606+ pte_t *pte_m, entry_m;
86607+
86608+ BUG_ON(!page_m || PageAnon(page_m));
86609+
86610+ vma_m = pax_find_mirror_vma(vma);
86611+ if (!vma_m)
86612+ return;
86613+
86614+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
86615+ address_m = address + SEGMEXEC_TASK_SIZE;
86616+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
86617+ pte_m = pte_offset_map(pmd_m, address_m);
86618+ ptl_m = pte_lockptr(mm, pmd_m);
86619+ if (ptl != ptl_m) {
86620+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
86621+ if (!pte_none(*pte_m))
86622+ goto out;
86623+ }
86624+
86625+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
86626+ page_cache_get(page_m);
86627+ page_add_file_rmap(page_m);
86628+ inc_mm_counter_fast(mm, MM_FILEPAGES);
86629+ set_pte_at(mm, address_m, pte_m, entry_m);
86630+ update_mmu_cache(vma_m, address_m, pte_m);
86631+out:
86632+ if (ptl != ptl_m)
86633+ spin_unlock(ptl_m);
86634+ pte_unmap(pte_m);
86635+}
86636+
86637+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
86638+{
86639+ struct mm_struct *mm = vma->vm_mm;
86640+ unsigned long address_m;
86641+ spinlock_t *ptl_m;
86642+ struct vm_area_struct *vma_m;
86643+ pmd_t *pmd_m;
86644+ pte_t *pte_m, entry_m;
86645+
86646+ vma_m = pax_find_mirror_vma(vma);
86647+ if (!vma_m)
86648+ return;
86649+
86650+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
86651+ address_m = address + SEGMEXEC_TASK_SIZE;
86652+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
86653+ pte_m = pte_offset_map(pmd_m, address_m);
86654+ ptl_m = pte_lockptr(mm, pmd_m);
86655+ if (ptl != ptl_m) {
86656+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
86657+ if (!pte_none(*pte_m))
86658+ goto out;
86659+ }
86660+
86661+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
86662+ set_pte_at(mm, address_m, pte_m, entry_m);
86663+out:
86664+ if (ptl != ptl_m)
86665+ spin_unlock(ptl_m);
86666+ pte_unmap(pte_m);
86667+}
86668+
86669+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
86670+{
86671+ struct page *page_m;
86672+ pte_t entry;
86673+
86674+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
86675+ goto out;
86676+
86677+ entry = *pte;
86678+ page_m = vm_normal_page(vma, address, entry);
86679+ if (!page_m)
86680+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
86681+ else if (PageAnon(page_m)) {
86682+ if (pax_find_mirror_vma(vma)) {
86683+ pte_unmap_unlock(pte, ptl);
86684+ lock_page(page_m);
86685+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
86686+ if (pte_same(entry, *pte))
86687+ pax_mirror_anon_pte(vma, address, page_m, ptl);
86688+ else
86689+ unlock_page(page_m);
86690+ }
86691+ } else
86692+ pax_mirror_file_pte(vma, address, page_m, ptl);
86693+
86694+out:
86695+ pte_unmap_unlock(pte, ptl);
86696+}
86697+#endif
86698+
86699 /*
86700 * This routine handles present pages, when users try to write
86701 * to a shared page. It is done by copying the page to a new address
86702@@ -2811,6 +3007,12 @@ gotten:
86703 */
86704 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
86705 if (likely(pte_same(*page_table, orig_pte))) {
86706+
86707+#ifdef CONFIG_PAX_SEGMEXEC
86708+ if (pax_find_mirror_vma(vma))
86709+ BUG_ON(!trylock_page(new_page));
86710+#endif
86711+
86712 if (old_page) {
86713 if (!PageAnon(old_page)) {
86714 dec_mm_counter_fast(mm, MM_FILEPAGES);
86715@@ -2862,6 +3064,10 @@ gotten:
86716 page_remove_rmap(old_page);
86717 }
86718
86719+#ifdef CONFIG_PAX_SEGMEXEC
86720+ pax_mirror_anon_pte(vma, address, new_page, ptl);
86721+#endif
86722+
86723 /* Free the old page.. */
86724 new_page = old_page;
86725 ret |= VM_FAULT_WRITE;
86726@@ -3139,6 +3345,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
86727 swap_free(entry);
86728 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
86729 try_to_free_swap(page);
86730+
86731+#ifdef CONFIG_PAX_SEGMEXEC
86732+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
86733+#endif
86734+
86735 unlock_page(page);
86736 if (page != swapcache) {
86737 /*
86738@@ -3162,6 +3373,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
86739
86740 /* No need to invalidate - it was non-present before */
86741 update_mmu_cache(vma, address, page_table);
86742+
86743+#ifdef CONFIG_PAX_SEGMEXEC
86744+ pax_mirror_anon_pte(vma, address, page, ptl);
86745+#endif
86746+
86747 unlock:
86748 pte_unmap_unlock(page_table, ptl);
86749 out:
86750@@ -3181,40 +3397,6 @@ out_release:
86751 }
86752
86753 /*
86754- * This is like a special single-page "expand_{down|up}wards()",
86755- * except we must first make sure that 'address{-|+}PAGE_SIZE'
86756- * doesn't hit another vma.
86757- */
86758-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
86759-{
86760- address &= PAGE_MASK;
86761- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
86762- struct vm_area_struct *prev = vma->vm_prev;
86763-
86764- /*
86765- * Is there a mapping abutting this one below?
86766- *
86767- * That's only ok if it's the same stack mapping
86768- * that has gotten split..
86769- */
86770- if (prev && prev->vm_end == address)
86771- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
86772-
86773- expand_downwards(vma, address - PAGE_SIZE);
86774- }
86775- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
86776- struct vm_area_struct *next = vma->vm_next;
86777-
86778- /* As VM_GROWSDOWN but s/below/above/ */
86779- if (next && next->vm_start == address + PAGE_SIZE)
86780- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
86781-
86782- expand_upwards(vma, address + PAGE_SIZE);
86783- }
86784- return 0;
86785-}
86786-
86787-/*
86788 * We enter with non-exclusive mmap_sem (to exclude vma changes,
86789 * but allow concurrent faults), and pte mapped but not yet locked.
86790 * We return with mmap_sem still held, but pte unmapped and unlocked.
86791@@ -3223,27 +3405,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
86792 unsigned long address, pte_t *page_table, pmd_t *pmd,
86793 unsigned int flags)
86794 {
86795- struct page *page;
86796+ struct page *page = NULL;
86797 spinlock_t *ptl;
86798 pte_t entry;
86799
86800- pte_unmap(page_table);
86801-
86802- /* Check if we need to add a guard page to the stack */
86803- if (check_stack_guard_page(vma, address) < 0)
86804- return VM_FAULT_SIGBUS;
86805-
86806- /* Use the zero-page for reads */
86807 if (!(flags & FAULT_FLAG_WRITE)) {
86808 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
86809 vma->vm_page_prot));
86810- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
86811+ ptl = pte_lockptr(mm, pmd);
86812+ spin_lock(ptl);
86813 if (!pte_none(*page_table))
86814 goto unlock;
86815 goto setpte;
86816 }
86817
86818 /* Allocate our own private page. */
86819+ pte_unmap(page_table);
86820+
86821 if (unlikely(anon_vma_prepare(vma)))
86822 goto oom;
86823 page = alloc_zeroed_user_highpage_movable(vma, address);
86824@@ -3267,6 +3445,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
86825 if (!pte_none(*page_table))
86826 goto release;
86827
86828+#ifdef CONFIG_PAX_SEGMEXEC
86829+ if (pax_find_mirror_vma(vma))
86830+ BUG_ON(!trylock_page(page));
86831+#endif
86832+
86833 inc_mm_counter_fast(mm, MM_ANONPAGES);
86834 page_add_new_anon_rmap(page, vma, address);
86835 setpte:
86836@@ -3274,6 +3457,12 @@ setpte:
86837
86838 /* No need to invalidate - it was non-present before */
86839 update_mmu_cache(vma, address, page_table);
86840+
86841+#ifdef CONFIG_PAX_SEGMEXEC
86842+ if (page)
86843+ pax_mirror_anon_pte(vma, address, page, ptl);
86844+#endif
86845+
86846 unlock:
86847 pte_unmap_unlock(page_table, ptl);
86848 return 0;
86849@@ -3417,6 +3606,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86850 */
86851 /* Only go through if we didn't race with anybody else... */
86852 if (likely(pte_same(*page_table, orig_pte))) {
86853+
86854+#ifdef CONFIG_PAX_SEGMEXEC
86855+ if (anon && pax_find_mirror_vma(vma))
86856+ BUG_ON(!trylock_page(page));
86857+#endif
86858+
86859 flush_icache_page(vma, page);
86860 entry = mk_pte(page, vma->vm_page_prot);
86861 if (flags & FAULT_FLAG_WRITE)
86862@@ -3438,6 +3633,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86863
86864 /* no need to invalidate: a not-present page won't be cached */
86865 update_mmu_cache(vma, address, page_table);
86866+
86867+#ifdef CONFIG_PAX_SEGMEXEC
86868+ if (anon)
86869+ pax_mirror_anon_pte(vma, address, page, ptl);
86870+ else
86871+ pax_mirror_file_pte(vma, address, page, ptl);
86872+#endif
86873+
86874 } else {
86875 if (cow_page)
86876 mem_cgroup_uncharge_page(cow_page);
86877@@ -3759,6 +3962,12 @@ int handle_pte_fault(struct mm_struct *mm,
86878 if (flags & FAULT_FLAG_WRITE)
86879 flush_tlb_fix_spurious_fault(vma, address);
86880 }
86881+
86882+#ifdef CONFIG_PAX_SEGMEXEC
86883+ pax_mirror_pte(vma, address, pte, pmd, ptl);
86884+ return 0;
86885+#endif
86886+
86887 unlock:
86888 pte_unmap_unlock(pte, ptl);
86889 return 0;
86890@@ -3775,6 +3984,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86891 pmd_t *pmd;
86892 pte_t *pte;
86893
86894+#ifdef CONFIG_PAX_SEGMEXEC
86895+ struct vm_area_struct *vma_m;
86896+#endif
86897+
86898 __set_current_state(TASK_RUNNING);
86899
86900 count_vm_event(PGFAULT);
86901@@ -3786,6 +3999,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86902 if (unlikely(is_vm_hugetlb_page(vma)))
86903 return hugetlb_fault(mm, vma, address, flags);
86904
86905+#ifdef CONFIG_PAX_SEGMEXEC
86906+ vma_m = pax_find_mirror_vma(vma);
86907+ if (vma_m) {
86908+ unsigned long address_m;
86909+ pgd_t *pgd_m;
86910+ pud_t *pud_m;
86911+ pmd_t *pmd_m;
86912+
86913+ if (vma->vm_start > vma_m->vm_start) {
86914+ address_m = address;
86915+ address -= SEGMEXEC_TASK_SIZE;
86916+ vma = vma_m;
86917+ } else
86918+ address_m = address + SEGMEXEC_TASK_SIZE;
86919+
86920+ pgd_m = pgd_offset(mm, address_m);
86921+ pud_m = pud_alloc(mm, pgd_m, address_m);
86922+ if (!pud_m)
86923+ return VM_FAULT_OOM;
86924+ pmd_m = pmd_alloc(mm, pud_m, address_m);
86925+ if (!pmd_m)
86926+ return VM_FAULT_OOM;
86927+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
86928+ return VM_FAULT_OOM;
86929+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
86930+ }
86931+#endif
86932+
86933 retry:
86934 pgd = pgd_offset(mm, address);
86935 pud = pud_alloc(mm, pgd, address);
86936@@ -3884,6 +4125,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
86937 spin_unlock(&mm->page_table_lock);
86938 return 0;
86939 }
86940+
86941+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
86942+{
86943+ pud_t *new = pud_alloc_one(mm, address);
86944+ if (!new)
86945+ return -ENOMEM;
86946+
86947+ smp_wmb(); /* See comment in __pte_alloc */
86948+
86949+ spin_lock(&mm->page_table_lock);
86950+ if (pgd_present(*pgd)) /* Another has populated it */
86951+ pud_free(mm, new);
86952+ else
86953+ pgd_populate_kernel(mm, pgd, new);
86954+ spin_unlock(&mm->page_table_lock);
86955+ return 0;
86956+}
86957 #endif /* __PAGETABLE_PUD_FOLDED */
86958
86959 #ifndef __PAGETABLE_PMD_FOLDED
86960@@ -3914,6 +4172,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
86961 spin_unlock(&mm->page_table_lock);
86962 return 0;
86963 }
86964+
86965+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
86966+{
86967+ pmd_t *new = pmd_alloc_one(mm, address);
86968+ if (!new)
86969+ return -ENOMEM;
86970+
86971+ smp_wmb(); /* See comment in __pte_alloc */
86972+
86973+ spin_lock(&mm->page_table_lock);
86974+#ifndef __ARCH_HAS_4LEVEL_HACK
86975+ if (pud_present(*pud)) /* Another has populated it */
86976+ pmd_free(mm, new);
86977+ else
86978+ pud_populate_kernel(mm, pud, new);
86979+#else
86980+ if (pgd_present(*pud)) /* Another has populated it */
86981+ pmd_free(mm, new);
86982+ else
86983+ pgd_populate_kernel(mm, pud, new);
86984+#endif /* __ARCH_HAS_4LEVEL_HACK */
86985+ spin_unlock(&mm->page_table_lock);
86986+ return 0;
86987+}
86988 #endif /* __PAGETABLE_PMD_FOLDED */
86989
86990 #if !defined(__HAVE_ARCH_GATE_AREA)
86991@@ -3927,7 +4209,7 @@ static int __init gate_vma_init(void)
86992 gate_vma.vm_start = FIXADDR_USER_START;
86993 gate_vma.vm_end = FIXADDR_USER_END;
86994 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
86995- gate_vma.vm_page_prot = __P101;
86996+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
86997
86998 return 0;
86999 }
87000@@ -4061,8 +4343,8 @@ out:
87001 return ret;
87002 }
87003
87004-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
87005- void *buf, int len, int write)
87006+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
87007+ void *buf, size_t len, int write)
87008 {
87009 resource_size_t phys_addr;
87010 unsigned long prot = 0;
87011@@ -4087,8 +4369,8 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
87012 * Access another process' address space as given in mm. If non-NULL, use the
87013 * given task for page fault accounting.
87014 */
87015-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
87016- unsigned long addr, void *buf, int len, int write)
87017+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
87018+ unsigned long addr, void *buf, size_t len, int write)
87019 {
87020 struct vm_area_struct *vma;
87021 void *old_buf = buf;
87022@@ -4096,7 +4378,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
87023 down_read(&mm->mmap_sem);
87024 /* ignore errors, just check how much was successfully transferred */
87025 while (len) {
87026- int bytes, ret, offset;
87027+ ssize_t bytes, ret, offset;
87028 void *maddr;
87029 struct page *page = NULL;
87030
87031@@ -4155,8 +4437,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
87032 *
87033 * The caller must hold a reference on @mm.
87034 */
87035-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
87036- void *buf, int len, int write)
87037+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
87038+ void *buf, size_t len, int write)
87039 {
87040 return __access_remote_vm(NULL, mm, addr, buf, len, write);
87041 }
87042@@ -4166,11 +4448,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
87043 * Source/target buffer must be kernel space,
87044 * Do not walk the page table directly, use get_user_pages
87045 */
87046-int access_process_vm(struct task_struct *tsk, unsigned long addr,
87047- void *buf, int len, int write)
87048+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
87049+ void *buf, size_t len, int write)
87050 {
87051 struct mm_struct *mm;
87052- int ret;
87053+ ssize_t ret;
87054
87055 mm = get_task_mm(tsk);
87056 if (!mm)
87057diff --git a/mm/mempolicy.c b/mm/mempolicy.c
87058index 4baf12e..5497066 100644
87059--- a/mm/mempolicy.c
87060+++ b/mm/mempolicy.c
87061@@ -708,6 +708,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
87062 unsigned long vmstart;
87063 unsigned long vmend;
87064
87065+#ifdef CONFIG_PAX_SEGMEXEC
87066+ struct vm_area_struct *vma_m;
87067+#endif
87068+
87069 vma = find_vma(mm, start);
87070 if (!vma || vma->vm_start > start)
87071 return -EFAULT;
87072@@ -751,6 +755,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
87073 err = vma_replace_policy(vma, new_pol);
87074 if (err)
87075 goto out;
87076+
87077+#ifdef CONFIG_PAX_SEGMEXEC
87078+ vma_m = pax_find_mirror_vma(vma);
87079+ if (vma_m) {
87080+ err = vma_replace_policy(vma_m, new_pol);
87081+ if (err)
87082+ goto out;
87083+ }
87084+#endif
87085+
87086 }
87087
87088 out:
87089@@ -1206,6 +1220,17 @@ static long do_mbind(unsigned long start, unsigned long len,
87090
87091 if (end < start)
87092 return -EINVAL;
87093+
87094+#ifdef CONFIG_PAX_SEGMEXEC
87095+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
87096+ if (end > SEGMEXEC_TASK_SIZE)
87097+ return -EINVAL;
87098+ } else
87099+#endif
87100+
87101+ if (end > TASK_SIZE)
87102+ return -EINVAL;
87103+
87104 if (end == start)
87105 return 0;
87106
87107@@ -1434,8 +1459,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
87108 */
87109 tcred = __task_cred(task);
87110 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
87111- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
87112- !capable(CAP_SYS_NICE)) {
87113+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
87114 rcu_read_unlock();
87115 err = -EPERM;
87116 goto out_put;
87117@@ -1466,6 +1490,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
87118 goto out;
87119 }
87120
87121+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
87122+ if (mm != current->mm &&
87123+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
87124+ mmput(mm);
87125+ err = -EPERM;
87126+ goto out;
87127+ }
87128+#endif
87129+
87130 err = do_migrate_pages(mm, old, new,
87131 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
87132
87133diff --git a/mm/migrate.c b/mm/migrate.c
87134index 81af4e6..2285307 100644
87135--- a/mm/migrate.c
87136+++ b/mm/migrate.c
87137@@ -1401,8 +1401,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
87138 */
87139 tcred = __task_cred(task);
87140 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
87141- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
87142- !capable(CAP_SYS_NICE)) {
87143+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
87144 rcu_read_unlock();
87145 err = -EPERM;
87146 goto out;
87147diff --git a/mm/mlock.c b/mm/mlock.c
87148index 79b7cf7..37472bf 100644
87149--- a/mm/mlock.c
87150+++ b/mm/mlock.c
87151@@ -13,6 +13,7 @@
87152 #include <linux/pagemap.h>
87153 #include <linux/mempolicy.h>
87154 #include <linux/syscalls.h>
87155+#include <linux/security.h>
87156 #include <linux/sched.h>
87157 #include <linux/export.h>
87158 #include <linux/rmap.h>
87159@@ -334,7 +335,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
87160 {
87161 unsigned long nstart, end, tmp;
87162 struct vm_area_struct * vma, * prev;
87163- int error;
87164+ int error = 0;
87165
87166 VM_BUG_ON(start & ~PAGE_MASK);
87167 VM_BUG_ON(len != PAGE_ALIGN(len));
87168@@ -343,6 +344,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
87169 return -EINVAL;
87170 if (end == start)
87171 return 0;
87172+ if (end > TASK_SIZE)
87173+ return -EINVAL;
87174+
87175 vma = find_vma(current->mm, start);
87176 if (!vma || vma->vm_start > start)
87177 return -ENOMEM;
87178@@ -354,6 +358,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
87179 for (nstart = start ; ; ) {
87180 vm_flags_t newflags;
87181
87182+#ifdef CONFIG_PAX_SEGMEXEC
87183+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
87184+ break;
87185+#endif
87186+
87187 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
87188
87189 newflags = vma->vm_flags & ~VM_LOCKED;
87190@@ -466,6 +475,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
87191 lock_limit >>= PAGE_SHIFT;
87192
87193 /* check against resource limits */
87194+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
87195 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
87196 error = do_mlock(start, len, 1);
87197 up_write(&current->mm->mmap_sem);
87198@@ -500,12 +510,18 @@ static int do_mlockall(int flags)
87199 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
87200 vm_flags_t newflags;
87201
87202+#ifdef CONFIG_PAX_SEGMEXEC
87203+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
87204+ break;
87205+#endif
87206+
87207 newflags = vma->vm_flags & ~VM_LOCKED;
87208 if (flags & MCL_CURRENT)
87209 newflags |= VM_LOCKED;
87210
87211 /* Ignore errors */
87212 mlock_fixup(vma, &prev, vma->vm_start, vma->vm_end, newflags);
87213+ cond_resched();
87214 }
87215 out:
87216 return 0;
87217@@ -532,6 +548,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
87218 lock_limit >>= PAGE_SHIFT;
87219
87220 ret = -ENOMEM;
87221+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
87222 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
87223 capable(CAP_IPC_LOCK))
87224 ret = do_mlockall(flags);
87225diff --git a/mm/mmap.c b/mm/mmap.c
87226index f9c97d1..3468d3b 100644
87227--- a/mm/mmap.c
87228+++ b/mm/mmap.c
87229@@ -36,6 +36,7 @@
87230 #include <linux/sched/sysctl.h>
87231 #include <linux/notifier.h>
87232 #include <linux/memory.h>
87233+#include <linux/random.h>
87234
87235 #include <asm/uaccess.h>
87236 #include <asm/cacheflush.h>
87237@@ -52,6 +53,16 @@
87238 #define arch_rebalance_pgtables(addr, len) (addr)
87239 #endif
87240
87241+static inline void verify_mm_writelocked(struct mm_struct *mm)
87242+{
87243+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
87244+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
87245+ up_read(&mm->mmap_sem);
87246+ BUG();
87247+ }
87248+#endif
87249+}
87250+
87251 static void unmap_region(struct mm_struct *mm,
87252 struct vm_area_struct *vma, struct vm_area_struct *prev,
87253 unsigned long start, unsigned long end);
87254@@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
87255 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
87256 *
87257 */
87258-pgprot_t protection_map[16] = {
87259+pgprot_t protection_map[16] __read_only = {
87260 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
87261 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
87262 };
87263
87264-pgprot_t vm_get_page_prot(unsigned long vm_flags)
87265+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
87266 {
87267- return __pgprot(pgprot_val(protection_map[vm_flags &
87268+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
87269 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
87270 pgprot_val(arch_vm_get_page_prot(vm_flags)));
87271+
87272+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
87273+ if (!(__supported_pte_mask & _PAGE_NX) &&
87274+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
87275+ (vm_flags & (VM_READ | VM_WRITE)))
87276+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
87277+#endif
87278+
87279+ return prot;
87280 }
87281 EXPORT_SYMBOL(vm_get_page_prot);
87282
87283@@ -89,6 +109,7 @@ int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
87284 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
87285 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
87286 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
87287+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
87288 /*
87289 * Make sure vm_committed_as in one cacheline and not cacheline shared with
87290 * other variables. It can be updated by several CPUs frequently.
87291@@ -247,6 +268,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
87292 struct vm_area_struct *next = vma->vm_next;
87293
87294 might_sleep();
87295+ BUG_ON(vma->vm_mirror);
87296 if (vma->vm_ops && vma->vm_ops->close)
87297 vma->vm_ops->close(vma);
87298 if (vma->vm_file)
87299@@ -291,6 +313,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
87300 * not page aligned -Ram Gupta
87301 */
87302 rlim = rlimit(RLIMIT_DATA);
87303+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
87304 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
87305 (mm->end_data - mm->start_data) > rlim)
87306 goto out;
87307@@ -933,6 +956,12 @@ static int
87308 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
87309 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
87310 {
87311+
87312+#ifdef CONFIG_PAX_SEGMEXEC
87313+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
87314+ return 0;
87315+#endif
87316+
87317 if (is_mergeable_vma(vma, file, vm_flags) &&
87318 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
87319 if (vma->vm_pgoff == vm_pgoff)
87320@@ -952,6 +981,12 @@ static int
87321 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
87322 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
87323 {
87324+
87325+#ifdef CONFIG_PAX_SEGMEXEC
87326+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
87327+ return 0;
87328+#endif
87329+
87330 if (is_mergeable_vma(vma, file, vm_flags) &&
87331 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
87332 pgoff_t vm_pglen;
87333@@ -994,13 +1029,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
87334 struct vm_area_struct *vma_merge(struct mm_struct *mm,
87335 struct vm_area_struct *prev, unsigned long addr,
87336 unsigned long end, unsigned long vm_flags,
87337- struct anon_vma *anon_vma, struct file *file,
87338+ struct anon_vma *anon_vma, struct file *file,
87339 pgoff_t pgoff, struct mempolicy *policy)
87340 {
87341 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
87342 struct vm_area_struct *area, *next;
87343 int err;
87344
87345+#ifdef CONFIG_PAX_SEGMEXEC
87346+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
87347+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
87348+
87349+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
87350+#endif
87351+
87352 /*
87353 * We later require that vma->vm_flags == vm_flags,
87354 * so this tests vma->vm_flags & VM_SPECIAL, too.
87355@@ -1016,6 +1058,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
87356 if (next && next->vm_end == end) /* cases 6, 7, 8 */
87357 next = next->vm_next;
87358
87359+#ifdef CONFIG_PAX_SEGMEXEC
87360+ if (prev)
87361+ prev_m = pax_find_mirror_vma(prev);
87362+ if (area)
87363+ area_m = pax_find_mirror_vma(area);
87364+ if (next)
87365+ next_m = pax_find_mirror_vma(next);
87366+#endif
87367+
87368 /*
87369 * Can it merge with the predecessor?
87370 */
87371@@ -1035,9 +1086,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
87372 /* cases 1, 6 */
87373 err = vma_adjust(prev, prev->vm_start,
87374 next->vm_end, prev->vm_pgoff, NULL);
87375- } else /* cases 2, 5, 7 */
87376+
87377+#ifdef CONFIG_PAX_SEGMEXEC
87378+ if (!err && prev_m)
87379+ err = vma_adjust(prev_m, prev_m->vm_start,
87380+ next_m->vm_end, prev_m->vm_pgoff, NULL);
87381+#endif
87382+
87383+ } else { /* cases 2, 5, 7 */
87384 err = vma_adjust(prev, prev->vm_start,
87385 end, prev->vm_pgoff, NULL);
87386+
87387+#ifdef CONFIG_PAX_SEGMEXEC
87388+ if (!err && prev_m)
87389+ err = vma_adjust(prev_m, prev_m->vm_start,
87390+ end_m, prev_m->vm_pgoff, NULL);
87391+#endif
87392+
87393+ }
87394 if (err)
87395 return NULL;
87396 khugepaged_enter_vma_merge(prev);
87397@@ -1051,12 +1117,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
87398 mpol_equal(policy, vma_policy(next)) &&
87399 can_vma_merge_before(next, vm_flags,
87400 anon_vma, file, pgoff+pglen)) {
87401- if (prev && addr < prev->vm_end) /* case 4 */
87402+ if (prev && addr < prev->vm_end) { /* case 4 */
87403 err = vma_adjust(prev, prev->vm_start,
87404 addr, prev->vm_pgoff, NULL);
87405- else /* cases 3, 8 */
87406+
87407+#ifdef CONFIG_PAX_SEGMEXEC
87408+ if (!err && prev_m)
87409+ err = vma_adjust(prev_m, prev_m->vm_start,
87410+ addr_m, prev_m->vm_pgoff, NULL);
87411+#endif
87412+
87413+ } else { /* cases 3, 8 */
87414 err = vma_adjust(area, addr, next->vm_end,
87415 next->vm_pgoff - pglen, NULL);
87416+
87417+#ifdef CONFIG_PAX_SEGMEXEC
87418+ if (!err && area_m)
87419+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
87420+ next_m->vm_pgoff - pglen, NULL);
87421+#endif
87422+
87423+ }
87424 if (err)
87425 return NULL;
87426 khugepaged_enter_vma_merge(area);
87427@@ -1165,8 +1246,10 @@ none:
87428 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
87429 struct file *file, long pages)
87430 {
87431- const unsigned long stack_flags
87432- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
87433+
87434+#ifdef CONFIG_PAX_RANDMMAP
87435+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
87436+#endif
87437
87438 mm->total_vm += pages;
87439
87440@@ -1174,7 +1257,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
87441 mm->shared_vm += pages;
87442 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
87443 mm->exec_vm += pages;
87444- } else if (flags & stack_flags)
87445+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
87446 mm->stack_vm += pages;
87447 }
87448 #endif /* CONFIG_PROC_FS */
87449@@ -1213,7 +1296,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87450 * (the exception is when the underlying filesystem is noexec
87451 * mounted, in which case we dont add PROT_EXEC.)
87452 */
87453- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
87454+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
87455 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
87456 prot |= PROT_EXEC;
87457
87458@@ -1239,7 +1322,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87459 /* Obtain the address to map to. we verify (or select) it and ensure
87460 * that it represents a valid section of the address space.
87461 */
87462- addr = get_unmapped_area(file, addr, len, pgoff, flags);
87463+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
87464 if (addr & ~PAGE_MASK)
87465 return addr;
87466
87467@@ -1250,6 +1333,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87468 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
87469 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
87470
87471+#ifdef CONFIG_PAX_MPROTECT
87472+ if (mm->pax_flags & MF_PAX_MPROTECT) {
87473+
87474+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
87475+ if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
87476+ mm->binfmt->handle_mmap)
87477+ mm->binfmt->handle_mmap(file);
87478+#endif
87479+
87480+#ifndef CONFIG_PAX_MPROTECT_COMPAT
87481+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
87482+ gr_log_rwxmmap(file);
87483+
87484+#ifdef CONFIG_PAX_EMUPLT
87485+ vm_flags &= ~VM_EXEC;
87486+#else
87487+ return -EPERM;
87488+#endif
87489+
87490+ }
87491+
87492+ if (!(vm_flags & VM_EXEC))
87493+ vm_flags &= ~VM_MAYEXEC;
87494+#else
87495+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
87496+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
87497+#endif
87498+ else
87499+ vm_flags &= ~VM_MAYWRITE;
87500+ }
87501+#endif
87502+
87503+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
87504+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
87505+ vm_flags &= ~VM_PAGEEXEC;
87506+#endif
87507+
87508 if (flags & MAP_LOCKED)
87509 if (!can_do_mlock())
87510 return -EPERM;
87511@@ -1261,6 +1381,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87512 locked += mm->locked_vm;
87513 lock_limit = rlimit(RLIMIT_MEMLOCK);
87514 lock_limit >>= PAGE_SHIFT;
87515+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
87516 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
87517 return -EAGAIN;
87518 }
87519@@ -1341,6 +1462,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87520 vm_flags |= VM_NORESERVE;
87521 }
87522
87523+ if (!gr_acl_handle_mmap(file, prot))
87524+ return -EACCES;
87525+
87526 addr = mmap_region(file, addr, len, vm_flags, pgoff);
87527 if (!IS_ERR_VALUE(addr) &&
87528 ((vm_flags & VM_LOCKED) ||
87529@@ -1434,7 +1558,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
87530 vm_flags_t vm_flags = vma->vm_flags;
87531
87532 /* If it was private or non-writable, the write bit is already clear */
87533- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
87534+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
87535 return 0;
87536
87537 /* The backer wishes to know when pages are first written to? */
87538@@ -1482,7 +1606,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
87539 unsigned long charged = 0;
87540 struct inode *inode = file ? file_inode(file) : NULL;
87541
87542+#ifdef CONFIG_PAX_SEGMEXEC
87543+ struct vm_area_struct *vma_m = NULL;
87544+#endif
87545+
87546+ /*
87547+ * mm->mmap_sem is required to protect against another thread
87548+ * changing the mappings in case we sleep.
87549+ */
87550+ verify_mm_writelocked(mm);
87551+
87552 /* Check against address space limit. */
87553+
87554+#ifdef CONFIG_PAX_RANDMMAP
87555+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
87556+#endif
87557+
87558 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
87559 unsigned long nr_pages;
87560
87561@@ -1501,11 +1640,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
87562
87563 /* Clear old maps */
87564 error = -ENOMEM;
87565-munmap_back:
87566 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
87567 if (do_munmap(mm, addr, len))
87568 return -ENOMEM;
87569- goto munmap_back;
87570+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
87571 }
87572
87573 /*
87574@@ -1536,6 +1674,16 @@ munmap_back:
87575 goto unacct_error;
87576 }
87577
87578+#ifdef CONFIG_PAX_SEGMEXEC
87579+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
87580+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
87581+ if (!vma_m) {
87582+ error = -ENOMEM;
87583+ goto free_vma;
87584+ }
87585+ }
87586+#endif
87587+
87588 vma->vm_mm = mm;
87589 vma->vm_start = addr;
87590 vma->vm_end = addr + len;
87591@@ -1560,6 +1708,13 @@ munmap_back:
87592 if (error)
87593 goto unmap_and_free_vma;
87594
87595+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
87596+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
87597+ vma->vm_flags |= VM_PAGEEXEC;
87598+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
87599+ }
87600+#endif
87601+
87602 /* Can addr have changed??
87603 *
87604 * Answer: Yes, several device drivers can do it in their
87605@@ -1598,6 +1753,11 @@ munmap_back:
87606 vma_link(mm, vma, prev, rb_link, rb_parent);
87607 file = vma->vm_file;
87608
87609+#ifdef CONFIG_PAX_SEGMEXEC
87610+ if (vma_m)
87611+ BUG_ON(pax_mirror_vma(vma_m, vma));
87612+#endif
87613+
87614 /* Once vma denies write, undo our temporary denial count */
87615 if (correct_wcount)
87616 atomic_inc(&inode->i_writecount);
87617@@ -1605,6 +1765,7 @@ out:
87618 perf_event_mmap(vma);
87619
87620 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
87621+ track_exec_limit(mm, addr, addr + len, vm_flags);
87622 if (vm_flags & VM_LOCKED) {
87623 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
87624 vma == get_gate_vma(current->mm)))
87625@@ -1628,6 +1789,12 @@ unmap_and_free_vma:
87626 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
87627 charged = 0;
87628 free_vma:
87629+
87630+#ifdef CONFIG_PAX_SEGMEXEC
87631+ if (vma_m)
87632+ kmem_cache_free(vm_area_cachep, vma_m);
87633+#endif
87634+
87635 kmem_cache_free(vm_area_cachep, vma);
87636 unacct_error:
87637 if (charged)
87638@@ -1635,7 +1802,63 @@ unacct_error:
87639 return error;
87640 }
87641
87642-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
87643+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
87644+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
87645+{
87646+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
87647+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
87648+
87649+ return 0;
87650+}
87651+#endif
87652+
87653+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
87654+{
87655+ if (!vma) {
87656+#ifdef CONFIG_STACK_GROWSUP
87657+ if (addr > sysctl_heap_stack_gap)
87658+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
87659+ else
87660+ vma = find_vma(current->mm, 0);
87661+ if (vma && (vma->vm_flags & VM_GROWSUP))
87662+ return false;
87663+#endif
87664+ return true;
87665+ }
87666+
87667+ if (addr + len > vma->vm_start)
87668+ return false;
87669+
87670+ if (vma->vm_flags & VM_GROWSDOWN)
87671+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
87672+#ifdef CONFIG_STACK_GROWSUP
87673+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
87674+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
87675+#endif
87676+ else if (offset)
87677+ return offset <= vma->vm_start - addr - len;
87678+
87679+ return true;
87680+}
87681+
87682+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
87683+{
87684+ if (vma->vm_start < len)
87685+ return -ENOMEM;
87686+
87687+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
87688+ if (offset <= vma->vm_start - len)
87689+ return vma->vm_start - len - offset;
87690+ else
87691+ return -ENOMEM;
87692+ }
87693+
87694+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
87695+ return vma->vm_start - len - sysctl_heap_stack_gap;
87696+ return -ENOMEM;
87697+}
87698+
87699+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
87700 {
87701 /*
87702 * We implement the search by looking for an rbtree node that
87703@@ -1683,11 +1906,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
87704 }
87705 }
87706
87707- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
87708+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
87709 check_current:
87710 /* Check if current node has a suitable gap */
87711 if (gap_start > high_limit)
87712 return -ENOMEM;
87713+
87714+ if (gap_end - gap_start > info->threadstack_offset)
87715+ gap_start += info->threadstack_offset;
87716+ else
87717+ gap_start = gap_end;
87718+
87719+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
87720+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87721+ gap_start += sysctl_heap_stack_gap;
87722+ else
87723+ gap_start = gap_end;
87724+ }
87725+ if (vma->vm_flags & VM_GROWSDOWN) {
87726+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87727+ gap_end -= sysctl_heap_stack_gap;
87728+ else
87729+ gap_end = gap_start;
87730+ }
87731 if (gap_end >= low_limit && gap_end - gap_start >= length)
87732 goto found;
87733
87734@@ -1737,7 +1978,7 @@ found:
87735 return gap_start;
87736 }
87737
87738-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
87739+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
87740 {
87741 struct mm_struct *mm = current->mm;
87742 struct vm_area_struct *vma;
87743@@ -1791,6 +2032,24 @@ check_current:
87744 gap_end = vma->vm_start;
87745 if (gap_end < low_limit)
87746 return -ENOMEM;
87747+
87748+ if (gap_end - gap_start > info->threadstack_offset)
87749+ gap_end -= info->threadstack_offset;
87750+ else
87751+ gap_end = gap_start;
87752+
87753+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
87754+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87755+ gap_start += sysctl_heap_stack_gap;
87756+ else
87757+ gap_start = gap_end;
87758+ }
87759+ if (vma->vm_flags & VM_GROWSDOWN) {
87760+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87761+ gap_end -= sysctl_heap_stack_gap;
87762+ else
87763+ gap_end = gap_start;
87764+ }
87765 if (gap_start <= high_limit && gap_end - gap_start >= length)
87766 goto found;
87767
87768@@ -1854,6 +2113,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
87769 struct mm_struct *mm = current->mm;
87770 struct vm_area_struct *vma;
87771 struct vm_unmapped_area_info info;
87772+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
87773
87774 if (len > TASK_SIZE)
87775 return -ENOMEM;
87776@@ -1861,19 +2121,29 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
87777 if (flags & MAP_FIXED)
87778 return addr;
87779
87780+#ifdef CONFIG_PAX_RANDMMAP
87781+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
87782+#endif
87783+
87784 if (addr) {
87785 addr = PAGE_ALIGN(addr);
87786 vma = find_vma(mm, addr);
87787- if (TASK_SIZE - len >= addr &&
87788- (!vma || addr + len <= vma->vm_start))
87789+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
87790 return addr;
87791 }
87792
87793 info.flags = 0;
87794 info.length = len;
87795 info.low_limit = TASK_UNMAPPED_BASE;
87796+
87797+#ifdef CONFIG_PAX_RANDMMAP
87798+ if (mm->pax_flags & MF_PAX_RANDMMAP)
87799+ info.low_limit += mm->delta_mmap;
87800+#endif
87801+
87802 info.high_limit = TASK_SIZE;
87803 info.align_mask = 0;
87804+ info.threadstack_offset = offset;
87805 return vm_unmapped_area(&info);
87806 }
87807 #endif
87808@@ -1892,6 +2162,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
87809 struct mm_struct *mm = current->mm;
87810 unsigned long addr = addr0;
87811 struct vm_unmapped_area_info info;
87812+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
87813
87814 /* requested length too big for entire address space */
87815 if (len > TASK_SIZE)
87816@@ -1900,12 +2171,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
87817 if (flags & MAP_FIXED)
87818 return addr;
87819
87820+#ifdef CONFIG_PAX_RANDMMAP
87821+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
87822+#endif
87823+
87824 /* requesting a specific address */
87825 if (addr) {
87826 addr = PAGE_ALIGN(addr);
87827 vma = find_vma(mm, addr);
87828- if (TASK_SIZE - len >= addr &&
87829- (!vma || addr + len <= vma->vm_start))
87830+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
87831 return addr;
87832 }
87833
87834@@ -1914,6 +2188,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
87835 info.low_limit = PAGE_SIZE;
87836 info.high_limit = mm->mmap_base;
87837 info.align_mask = 0;
87838+ info.threadstack_offset = offset;
87839 addr = vm_unmapped_area(&info);
87840
87841 /*
87842@@ -1926,6 +2201,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
87843 VM_BUG_ON(addr != -ENOMEM);
87844 info.flags = 0;
87845 info.low_limit = TASK_UNMAPPED_BASE;
87846+
87847+#ifdef CONFIG_PAX_RANDMMAP
87848+ if (mm->pax_flags & MF_PAX_RANDMMAP)
87849+ info.low_limit += mm->delta_mmap;
87850+#endif
87851+
87852 info.high_limit = TASK_SIZE;
87853 addr = vm_unmapped_area(&info);
87854 }
87855@@ -2027,6 +2308,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
87856 return vma;
87857 }
87858
87859+#ifdef CONFIG_PAX_SEGMEXEC
87860+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
87861+{
87862+ struct vm_area_struct *vma_m;
87863+
87864+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
87865+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
87866+ BUG_ON(vma->vm_mirror);
87867+ return NULL;
87868+ }
87869+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
87870+ vma_m = vma->vm_mirror;
87871+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
87872+ BUG_ON(vma->vm_file != vma_m->vm_file);
87873+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
87874+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
87875+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
87876+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
87877+ return vma_m;
87878+}
87879+#endif
87880+
87881 /*
87882 * Verify that the stack growth is acceptable and
87883 * update accounting. This is shared with both the
87884@@ -2043,6 +2346,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
87885 return -ENOMEM;
87886
87887 /* Stack limit test */
87888+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
87889 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
87890 return -ENOMEM;
87891
87892@@ -2053,6 +2357,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
87893 locked = mm->locked_vm + grow;
87894 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
87895 limit >>= PAGE_SHIFT;
87896+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
87897 if (locked > limit && !capable(CAP_IPC_LOCK))
87898 return -ENOMEM;
87899 }
87900@@ -2082,37 +2387,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
87901 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
87902 * vma is the last one with address > vma->vm_end. Have to extend vma.
87903 */
87904+#ifndef CONFIG_IA64
87905+static
87906+#endif
87907 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
87908 {
87909 int error;
87910+ bool locknext;
87911
87912 if (!(vma->vm_flags & VM_GROWSUP))
87913 return -EFAULT;
87914
87915+ /* Also guard against wrapping around to address 0. */
87916+ if (address < PAGE_ALIGN(address+1))
87917+ address = PAGE_ALIGN(address+1);
87918+ else
87919+ return -ENOMEM;
87920+
87921 /*
87922 * We must make sure the anon_vma is allocated
87923 * so that the anon_vma locking is not a noop.
87924 */
87925 if (unlikely(anon_vma_prepare(vma)))
87926 return -ENOMEM;
87927+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
87928+ if (locknext && anon_vma_prepare(vma->vm_next))
87929+ return -ENOMEM;
87930 vma_lock_anon_vma(vma);
87931+ if (locknext)
87932+ vma_lock_anon_vma(vma->vm_next);
87933
87934 /*
87935 * vma->vm_start/vm_end cannot change under us because the caller
87936 * is required to hold the mmap_sem in read mode. We need the
87937- * anon_vma lock to serialize against concurrent expand_stacks.
87938- * Also guard against wrapping around to address 0.
87939+ * anon_vma locks to serialize against concurrent expand_stacks
87940+ * and expand_upwards.
87941 */
87942- if (address < PAGE_ALIGN(address+4))
87943- address = PAGE_ALIGN(address+4);
87944- else {
87945- vma_unlock_anon_vma(vma);
87946- return -ENOMEM;
87947- }
87948 error = 0;
87949
87950 /* Somebody else might have raced and expanded it already */
87951- if (address > vma->vm_end) {
87952+ 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)
87953+ error = -ENOMEM;
87954+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
87955 unsigned long size, grow;
87956
87957 size = address - vma->vm_start;
87958@@ -2147,6 +2463,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
87959 }
87960 }
87961 }
87962+ if (locknext)
87963+ vma_unlock_anon_vma(vma->vm_next);
87964 vma_unlock_anon_vma(vma);
87965 khugepaged_enter_vma_merge(vma);
87966 validate_mm(vma->vm_mm);
87967@@ -2161,6 +2479,8 @@ int expand_downwards(struct vm_area_struct *vma,
87968 unsigned long address)
87969 {
87970 int error;
87971+ bool lockprev = false;
87972+ struct vm_area_struct *prev;
87973
87974 /*
87975 * We must make sure the anon_vma is allocated
87976@@ -2174,6 +2494,15 @@ int expand_downwards(struct vm_area_struct *vma,
87977 if (error)
87978 return error;
87979
87980+ prev = vma->vm_prev;
87981+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
87982+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
87983+#endif
87984+ if (lockprev && anon_vma_prepare(prev))
87985+ return -ENOMEM;
87986+ if (lockprev)
87987+ vma_lock_anon_vma(prev);
87988+
87989 vma_lock_anon_vma(vma);
87990
87991 /*
87992@@ -2183,9 +2512,17 @@ int expand_downwards(struct vm_area_struct *vma,
87993 */
87994
87995 /* Somebody else might have raced and expanded it already */
87996- if (address < vma->vm_start) {
87997+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
87998+ error = -ENOMEM;
87999+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
88000 unsigned long size, grow;
88001
88002+#ifdef CONFIG_PAX_SEGMEXEC
88003+ struct vm_area_struct *vma_m;
88004+
88005+ vma_m = pax_find_mirror_vma(vma);
88006+#endif
88007+
88008 size = vma->vm_end - address;
88009 grow = (vma->vm_start - address) >> PAGE_SHIFT;
88010
88011@@ -2210,13 +2547,27 @@ int expand_downwards(struct vm_area_struct *vma,
88012 vma->vm_pgoff -= grow;
88013 anon_vma_interval_tree_post_update_vma(vma);
88014 vma_gap_update(vma);
88015+
88016+#ifdef CONFIG_PAX_SEGMEXEC
88017+ if (vma_m) {
88018+ anon_vma_interval_tree_pre_update_vma(vma_m);
88019+ vma_m->vm_start -= grow << PAGE_SHIFT;
88020+ vma_m->vm_pgoff -= grow;
88021+ anon_vma_interval_tree_post_update_vma(vma_m);
88022+ vma_gap_update(vma_m);
88023+ }
88024+#endif
88025+
88026 spin_unlock(&vma->vm_mm->page_table_lock);
88027
88028+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
88029 perf_event_mmap(vma);
88030 }
88031 }
88032 }
88033 vma_unlock_anon_vma(vma);
88034+ if (lockprev)
88035+ vma_unlock_anon_vma(prev);
88036 khugepaged_enter_vma_merge(vma);
88037 validate_mm(vma->vm_mm);
88038 return error;
88039@@ -2314,6 +2665,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
88040 do {
88041 long nrpages = vma_pages(vma);
88042
88043+#ifdef CONFIG_PAX_SEGMEXEC
88044+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
88045+ vma = remove_vma(vma);
88046+ continue;
88047+ }
88048+#endif
88049+
88050 if (vma->vm_flags & VM_ACCOUNT)
88051 nr_accounted += nrpages;
88052 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
88053@@ -2358,6 +2716,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
88054 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
88055 vma->vm_prev = NULL;
88056 do {
88057+
88058+#ifdef CONFIG_PAX_SEGMEXEC
88059+ if (vma->vm_mirror) {
88060+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
88061+ vma->vm_mirror->vm_mirror = NULL;
88062+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
88063+ vma->vm_mirror = NULL;
88064+ }
88065+#endif
88066+
88067 vma_rb_erase(vma, &mm->mm_rb);
88068 mm->map_count--;
88069 tail_vma = vma;
88070@@ -2384,14 +2752,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88071 struct vm_area_struct *new;
88072 int err = -ENOMEM;
88073
88074+#ifdef CONFIG_PAX_SEGMEXEC
88075+ struct vm_area_struct *vma_m, *new_m = NULL;
88076+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
88077+#endif
88078+
88079 if (is_vm_hugetlb_page(vma) && (addr &
88080 ~(huge_page_mask(hstate_vma(vma)))))
88081 return -EINVAL;
88082
88083+#ifdef CONFIG_PAX_SEGMEXEC
88084+ vma_m = pax_find_mirror_vma(vma);
88085+#endif
88086+
88087 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
88088 if (!new)
88089 goto out_err;
88090
88091+#ifdef CONFIG_PAX_SEGMEXEC
88092+ if (vma_m) {
88093+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
88094+ if (!new_m) {
88095+ kmem_cache_free(vm_area_cachep, new);
88096+ goto out_err;
88097+ }
88098+ }
88099+#endif
88100+
88101 /* most fields are the same, copy all, and then fixup */
88102 *new = *vma;
88103
88104@@ -2404,6 +2791,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88105 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
88106 }
88107
88108+#ifdef CONFIG_PAX_SEGMEXEC
88109+ if (vma_m) {
88110+ *new_m = *vma_m;
88111+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
88112+ new_m->vm_mirror = new;
88113+ new->vm_mirror = new_m;
88114+
88115+ if (new_below)
88116+ new_m->vm_end = addr_m;
88117+ else {
88118+ new_m->vm_start = addr_m;
88119+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
88120+ }
88121+ }
88122+#endif
88123+
88124 pol = mpol_dup(vma_policy(vma));
88125 if (IS_ERR(pol)) {
88126 err = PTR_ERR(pol);
88127@@ -2426,6 +2829,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88128 else
88129 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
88130
88131+#ifdef CONFIG_PAX_SEGMEXEC
88132+ if (!err && vma_m) {
88133+ if (anon_vma_clone(new_m, vma_m))
88134+ goto out_free_mpol;
88135+
88136+ mpol_get(pol);
88137+ vma_set_policy(new_m, pol);
88138+
88139+ if (new_m->vm_file)
88140+ get_file(new_m->vm_file);
88141+
88142+ if (new_m->vm_ops && new_m->vm_ops->open)
88143+ new_m->vm_ops->open(new_m);
88144+
88145+ if (new_below)
88146+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
88147+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
88148+ else
88149+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
88150+
88151+ if (err) {
88152+ if (new_m->vm_ops && new_m->vm_ops->close)
88153+ new_m->vm_ops->close(new_m);
88154+ if (new_m->vm_file)
88155+ fput(new_m->vm_file);
88156+ mpol_put(pol);
88157+ }
88158+ }
88159+#endif
88160+
88161 /* Success. */
88162 if (!err)
88163 return 0;
88164@@ -2435,10 +2868,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88165 new->vm_ops->close(new);
88166 if (new->vm_file)
88167 fput(new->vm_file);
88168- unlink_anon_vmas(new);
88169 out_free_mpol:
88170 mpol_put(pol);
88171 out_free_vma:
88172+
88173+#ifdef CONFIG_PAX_SEGMEXEC
88174+ if (new_m) {
88175+ unlink_anon_vmas(new_m);
88176+ kmem_cache_free(vm_area_cachep, new_m);
88177+ }
88178+#endif
88179+
88180+ unlink_anon_vmas(new);
88181 kmem_cache_free(vm_area_cachep, new);
88182 out_err:
88183 return err;
88184@@ -2451,6 +2892,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88185 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
88186 unsigned long addr, int new_below)
88187 {
88188+
88189+#ifdef CONFIG_PAX_SEGMEXEC
88190+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
88191+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
88192+ if (mm->map_count >= sysctl_max_map_count-1)
88193+ return -ENOMEM;
88194+ } else
88195+#endif
88196+
88197 if (mm->map_count >= sysctl_max_map_count)
88198 return -ENOMEM;
88199
88200@@ -2462,11 +2912,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
88201 * work. This now handles partial unmappings.
88202 * Jeremy Fitzhardinge <jeremy@goop.org>
88203 */
88204+#ifdef CONFIG_PAX_SEGMEXEC
88205 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
88206 {
88207+ int ret = __do_munmap(mm, start, len);
88208+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
88209+ return ret;
88210+
88211+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
88212+}
88213+
88214+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
88215+#else
88216+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
88217+#endif
88218+{
88219 unsigned long end;
88220 struct vm_area_struct *vma, *prev, *last;
88221
88222+ /*
88223+ * mm->mmap_sem is required to protect against another thread
88224+ * changing the mappings in case we sleep.
88225+ */
88226+ verify_mm_writelocked(mm);
88227+
88228 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
88229 return -EINVAL;
88230
88231@@ -2541,6 +3010,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
88232 /* Fix up all other VM information */
88233 remove_vma_list(mm, vma);
88234
88235+ track_exec_limit(mm, start, end, 0UL);
88236+
88237 return 0;
88238 }
88239
88240@@ -2549,6 +3020,13 @@ int vm_munmap(unsigned long start, size_t len)
88241 int ret;
88242 struct mm_struct *mm = current->mm;
88243
88244+
88245+#ifdef CONFIG_PAX_SEGMEXEC
88246+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
88247+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
88248+ return -EINVAL;
88249+#endif
88250+
88251 down_write(&mm->mmap_sem);
88252 ret = do_munmap(mm, start, len);
88253 up_write(&mm->mmap_sem);
88254@@ -2562,16 +3040,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
88255 return vm_munmap(addr, len);
88256 }
88257
88258-static inline void verify_mm_writelocked(struct mm_struct *mm)
88259-{
88260-#ifdef CONFIG_DEBUG_VM
88261- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
88262- WARN_ON(1);
88263- up_read(&mm->mmap_sem);
88264- }
88265-#endif
88266-}
88267-
88268 /*
88269 * this is really a simplified "do_mmap". it only handles
88270 * anonymous maps. eventually we may be able to do some
88271@@ -2585,6 +3053,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88272 struct rb_node ** rb_link, * rb_parent;
88273 pgoff_t pgoff = addr >> PAGE_SHIFT;
88274 int error;
88275+ unsigned long charged;
88276
88277 len = PAGE_ALIGN(len);
88278 if (!len)
88279@@ -2592,16 +3061,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88280
88281 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
88282
88283+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
88284+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
88285+ flags &= ~VM_EXEC;
88286+
88287+#ifdef CONFIG_PAX_MPROTECT
88288+ if (mm->pax_flags & MF_PAX_MPROTECT)
88289+ flags &= ~VM_MAYEXEC;
88290+#endif
88291+
88292+ }
88293+#endif
88294+
88295 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
88296 if (error & ~PAGE_MASK)
88297 return error;
88298
88299+ charged = len >> PAGE_SHIFT;
88300+
88301 /*
88302 * mlock MCL_FUTURE?
88303 */
88304 if (mm->def_flags & VM_LOCKED) {
88305 unsigned long locked, lock_limit;
88306- locked = len >> PAGE_SHIFT;
88307+ locked = charged;
88308 locked += mm->locked_vm;
88309 lock_limit = rlimit(RLIMIT_MEMLOCK);
88310 lock_limit >>= PAGE_SHIFT;
88311@@ -2618,21 +3101,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88312 /*
88313 * Clear old maps. this also does some error checking for us
88314 */
88315- munmap_back:
88316 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
88317 if (do_munmap(mm, addr, len))
88318 return -ENOMEM;
88319- goto munmap_back;
88320+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
88321 }
88322
88323 /* Check against address space limits *after* clearing old maps... */
88324- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
88325+ if (!may_expand_vm(mm, charged))
88326 return -ENOMEM;
88327
88328 if (mm->map_count > sysctl_max_map_count)
88329 return -ENOMEM;
88330
88331- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
88332+ if (security_vm_enough_memory_mm(mm, charged))
88333 return -ENOMEM;
88334
88335 /* Can we just expand an old private anonymous mapping? */
88336@@ -2646,7 +3128,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88337 */
88338 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
88339 if (!vma) {
88340- vm_unacct_memory(len >> PAGE_SHIFT);
88341+ vm_unacct_memory(charged);
88342 return -ENOMEM;
88343 }
88344
88345@@ -2660,9 +3142,10 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88346 vma_link(mm, vma, prev, rb_link, rb_parent);
88347 out:
88348 perf_event_mmap(vma);
88349- mm->total_vm += len >> PAGE_SHIFT;
88350+ mm->total_vm += charged;
88351 if (flags & VM_LOCKED)
88352- mm->locked_vm += (len >> PAGE_SHIFT);
88353+ mm->locked_vm += charged;
88354+ track_exec_limit(mm, addr, addr + len, flags);
88355 return addr;
88356 }
88357
88358@@ -2724,6 +3207,7 @@ void exit_mmap(struct mm_struct *mm)
88359 while (vma) {
88360 if (vma->vm_flags & VM_ACCOUNT)
88361 nr_accounted += vma_pages(vma);
88362+ vma->vm_mirror = NULL;
88363 vma = remove_vma(vma);
88364 }
88365 vm_unacct_memory(nr_accounted);
88366@@ -2740,6 +3224,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
88367 struct vm_area_struct *prev;
88368 struct rb_node **rb_link, *rb_parent;
88369
88370+#ifdef CONFIG_PAX_SEGMEXEC
88371+ struct vm_area_struct *vma_m = NULL;
88372+#endif
88373+
88374+ if (security_mmap_addr(vma->vm_start))
88375+ return -EPERM;
88376+
88377 /*
88378 * The vm_pgoff of a purely anonymous vma should be irrelevant
88379 * until its first write fault, when page's anon_vma and index
88380@@ -2763,7 +3254,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
88381 security_vm_enough_memory_mm(mm, vma_pages(vma)))
88382 return -ENOMEM;
88383
88384+#ifdef CONFIG_PAX_SEGMEXEC
88385+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
88386+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
88387+ if (!vma_m)
88388+ return -ENOMEM;
88389+ }
88390+#endif
88391+
88392 vma_link(mm, vma, prev, rb_link, rb_parent);
88393+
88394+#ifdef CONFIG_PAX_SEGMEXEC
88395+ if (vma_m)
88396+ BUG_ON(pax_mirror_vma(vma_m, vma));
88397+#endif
88398+
88399 return 0;
88400 }
88401
88402@@ -2783,6 +3288,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
88403 struct mempolicy *pol;
88404 bool faulted_in_anon_vma = true;
88405
88406+ BUG_ON(vma->vm_mirror);
88407+
88408 /*
88409 * If anonymous vma has not yet been faulted, update new pgoff
88410 * to match new location, to increase its chance of merging.
88411@@ -2849,6 +3356,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
88412 return NULL;
88413 }
88414
88415+#ifdef CONFIG_PAX_SEGMEXEC
88416+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
88417+{
88418+ struct vm_area_struct *prev_m;
88419+ struct rb_node **rb_link_m, *rb_parent_m;
88420+ struct mempolicy *pol_m;
88421+
88422+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
88423+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
88424+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
88425+ *vma_m = *vma;
88426+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
88427+ if (anon_vma_clone(vma_m, vma))
88428+ return -ENOMEM;
88429+ pol_m = vma_policy(vma_m);
88430+ mpol_get(pol_m);
88431+ vma_set_policy(vma_m, pol_m);
88432+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
88433+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
88434+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
88435+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
88436+ if (vma_m->vm_file)
88437+ get_file(vma_m->vm_file);
88438+ if (vma_m->vm_ops && vma_m->vm_ops->open)
88439+ vma_m->vm_ops->open(vma_m);
88440+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
88441+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
88442+ vma_m->vm_mirror = vma;
88443+ vma->vm_mirror = vma_m;
88444+ return 0;
88445+}
88446+#endif
88447+
88448 /*
88449 * Return true if the calling process may expand its vm space by the passed
88450 * number of pages
88451@@ -2860,6 +3400,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
88452
88453 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
88454
88455+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
88456 if (cur + npages > lim)
88457 return 0;
88458 return 1;
88459@@ -2930,6 +3471,22 @@ int install_special_mapping(struct mm_struct *mm,
88460 vma->vm_start = addr;
88461 vma->vm_end = addr + len;
88462
88463+#ifdef CONFIG_PAX_MPROTECT
88464+ if (mm->pax_flags & MF_PAX_MPROTECT) {
88465+#ifndef CONFIG_PAX_MPROTECT_COMPAT
88466+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
88467+ return -EPERM;
88468+ if (!(vm_flags & VM_EXEC))
88469+ vm_flags &= ~VM_MAYEXEC;
88470+#else
88471+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
88472+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
88473+#endif
88474+ else
88475+ vm_flags &= ~VM_MAYWRITE;
88476+ }
88477+#endif
88478+
88479 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
88480 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
88481
88482diff --git a/mm/mprotect.c b/mm/mprotect.c
88483index a3af058..bc2cb14 100644
88484--- a/mm/mprotect.c
88485+++ b/mm/mprotect.c
88486@@ -23,10 +23,18 @@
88487 #include <linux/mmu_notifier.h>
88488 #include <linux/migrate.h>
88489 #include <linux/perf_event.h>
88490+#include <linux/sched/sysctl.h>
88491+
88492+#ifdef CONFIG_PAX_MPROTECT
88493+#include <linux/elf.h>
88494+#include <linux/binfmts.h>
88495+#endif
88496+
88497 #include <asm/uaccess.h>
88498 #include <asm/pgtable.h>
88499 #include <asm/cacheflush.h>
88500 #include <asm/tlbflush.h>
88501+#include <asm/mmu_context.h>
88502
88503 #ifndef pgprot_modify
88504 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
88505@@ -236,6 +244,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
88506 return pages;
88507 }
88508
88509+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
88510+/* called while holding the mmap semaphor for writing except stack expansion */
88511+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
88512+{
88513+ unsigned long oldlimit, newlimit = 0UL;
88514+
88515+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
88516+ return;
88517+
88518+ spin_lock(&mm->page_table_lock);
88519+ oldlimit = mm->context.user_cs_limit;
88520+ if ((prot & VM_EXEC) && oldlimit < end)
88521+ /* USER_CS limit moved up */
88522+ newlimit = end;
88523+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
88524+ /* USER_CS limit moved down */
88525+ newlimit = start;
88526+
88527+ if (newlimit) {
88528+ mm->context.user_cs_limit = newlimit;
88529+
88530+#ifdef CONFIG_SMP
88531+ wmb();
88532+ cpus_clear(mm->context.cpu_user_cs_mask);
88533+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
88534+#endif
88535+
88536+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
88537+ }
88538+ spin_unlock(&mm->page_table_lock);
88539+ if (newlimit == end) {
88540+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
88541+
88542+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
88543+ if (is_vm_hugetlb_page(vma))
88544+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
88545+ else
88546+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
88547+ }
88548+}
88549+#endif
88550+
88551 int
88552 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
88553 unsigned long start, unsigned long end, unsigned long newflags)
88554@@ -248,11 +298,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
88555 int error;
88556 int dirty_accountable = 0;
88557
88558+#ifdef CONFIG_PAX_SEGMEXEC
88559+ struct vm_area_struct *vma_m = NULL;
88560+ unsigned long start_m, end_m;
88561+
88562+ start_m = start + SEGMEXEC_TASK_SIZE;
88563+ end_m = end + SEGMEXEC_TASK_SIZE;
88564+#endif
88565+
88566 if (newflags == oldflags) {
88567 *pprev = vma;
88568 return 0;
88569 }
88570
88571+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
88572+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
88573+
88574+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
88575+ return -ENOMEM;
88576+
88577+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
88578+ return -ENOMEM;
88579+ }
88580+
88581 /*
88582 * If we make a private mapping writable we increase our commit;
88583 * but (without finer accounting) cannot reduce our commit if we
88584@@ -269,6 +337,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
88585 }
88586 }
88587
88588+#ifdef CONFIG_PAX_SEGMEXEC
88589+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
88590+ if (start != vma->vm_start) {
88591+ error = split_vma(mm, vma, start, 1);
88592+ if (error)
88593+ goto fail;
88594+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
88595+ *pprev = (*pprev)->vm_next;
88596+ }
88597+
88598+ if (end != vma->vm_end) {
88599+ error = split_vma(mm, vma, end, 0);
88600+ if (error)
88601+ goto fail;
88602+ }
88603+
88604+ if (pax_find_mirror_vma(vma)) {
88605+ error = __do_munmap(mm, start_m, end_m - start_m);
88606+ if (error)
88607+ goto fail;
88608+ } else {
88609+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
88610+ if (!vma_m) {
88611+ error = -ENOMEM;
88612+ goto fail;
88613+ }
88614+ vma->vm_flags = newflags;
88615+ error = pax_mirror_vma(vma_m, vma);
88616+ if (error) {
88617+ vma->vm_flags = oldflags;
88618+ goto fail;
88619+ }
88620+ }
88621+ }
88622+#endif
88623+
88624 /*
88625 * First try to merge with previous and/or next vma.
88626 */
88627@@ -299,9 +403,21 @@ success:
88628 * vm_flags and vm_page_prot are protected by the mmap_sem
88629 * held in write mode.
88630 */
88631+
88632+#ifdef CONFIG_PAX_SEGMEXEC
88633+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
88634+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
88635+#endif
88636+
88637 vma->vm_flags = newflags;
88638+
88639+#ifdef CONFIG_PAX_MPROTECT
88640+ if (mm->binfmt && mm->binfmt->handle_mprotect)
88641+ mm->binfmt->handle_mprotect(vma, newflags);
88642+#endif
88643+
88644 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
88645- vm_get_page_prot(newflags));
88646+ vm_get_page_prot(vma->vm_flags));
88647
88648 if (vma_wants_writenotify(vma)) {
88649 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
88650@@ -340,6 +456,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88651 end = start + len;
88652 if (end <= start)
88653 return -ENOMEM;
88654+
88655+#ifdef CONFIG_PAX_SEGMEXEC
88656+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
88657+ if (end > SEGMEXEC_TASK_SIZE)
88658+ return -EINVAL;
88659+ } else
88660+#endif
88661+
88662+ if (end > TASK_SIZE)
88663+ return -EINVAL;
88664+
88665 if (!arch_validate_prot(prot))
88666 return -EINVAL;
88667
88668@@ -347,7 +474,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88669 /*
88670 * Does the application expect PROT_READ to imply PROT_EXEC:
88671 */
88672- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
88673+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
88674 prot |= PROT_EXEC;
88675
88676 vm_flags = calc_vm_prot_bits(prot);
88677@@ -379,6 +506,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88678 if (start > vma->vm_start)
88679 prev = vma;
88680
88681+#ifdef CONFIG_PAX_MPROTECT
88682+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
88683+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
88684+#endif
88685+
88686 for (nstart = start ; ; ) {
88687 unsigned long newflags;
88688
88689@@ -389,6 +521,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88690
88691 /* newflags >> 4 shift VM_MAY% in place of VM_% */
88692 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
88693+ if (prot & (PROT_WRITE | PROT_EXEC))
88694+ gr_log_rwxmprotect(vma);
88695+
88696+ error = -EACCES;
88697+ goto out;
88698+ }
88699+
88700+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
88701 error = -EACCES;
88702 goto out;
88703 }
88704@@ -403,6 +543,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88705 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
88706 if (error)
88707 goto out;
88708+
88709+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
88710+
88711 nstart = tmp;
88712
88713 if (nstart < prev->vm_end)
88714diff --git a/mm/mremap.c b/mm/mremap.c
88715index 0843feb..4f5b2e6 100644
88716--- a/mm/mremap.c
88717+++ b/mm/mremap.c
88718@@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
88719 continue;
88720 pte = ptep_get_and_clear(mm, old_addr, old_pte);
88721 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
88722+
88723+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
88724+ if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
88725+ pte = pte_exprotect(pte);
88726+#endif
88727+
88728 pte = move_soft_dirty_pte(pte);
88729 set_pte_at(mm, new_addr, new_pte, pte);
88730 }
88731@@ -337,6 +343,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
88732 if (is_vm_hugetlb_page(vma))
88733 goto Einval;
88734
88735+#ifdef CONFIG_PAX_SEGMEXEC
88736+ if (pax_find_mirror_vma(vma))
88737+ goto Einval;
88738+#endif
88739+
88740 /* We can't remap across vm area boundaries */
88741 if (old_len > vma->vm_end - addr)
88742 goto Efault;
88743@@ -392,20 +403,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
88744 unsigned long ret = -EINVAL;
88745 unsigned long charged = 0;
88746 unsigned long map_flags;
88747+ unsigned long pax_task_size = TASK_SIZE;
88748
88749 if (new_addr & ~PAGE_MASK)
88750 goto out;
88751
88752- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
88753+#ifdef CONFIG_PAX_SEGMEXEC
88754+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
88755+ pax_task_size = SEGMEXEC_TASK_SIZE;
88756+#endif
88757+
88758+ pax_task_size -= PAGE_SIZE;
88759+
88760+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
88761 goto out;
88762
88763 /* Check if the location we're moving into overlaps the
88764 * old location at all, and fail if it does.
88765 */
88766- if ((new_addr <= addr) && (new_addr+new_len) > addr)
88767- goto out;
88768-
88769- if ((addr <= new_addr) && (addr+old_len) > new_addr)
88770+ if (addr + old_len > new_addr && new_addr + new_len > addr)
88771 goto out;
88772
88773 ret = do_munmap(mm, new_addr, new_len);
88774@@ -474,6 +490,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
88775 unsigned long ret = -EINVAL;
88776 unsigned long charged = 0;
88777 bool locked = false;
88778+ unsigned long pax_task_size = TASK_SIZE;
88779
88780 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
88781 return ret;
88782@@ -495,6 +512,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
88783 if (!new_len)
88784 return ret;
88785
88786+#ifdef CONFIG_PAX_SEGMEXEC
88787+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
88788+ pax_task_size = SEGMEXEC_TASK_SIZE;
88789+#endif
88790+
88791+ pax_task_size -= PAGE_SIZE;
88792+
88793+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
88794+ old_len > pax_task_size || addr > pax_task_size-old_len)
88795+ return ret;
88796+
88797 down_write(&current->mm->mmap_sem);
88798
88799 if (flags & MREMAP_FIXED) {
88800@@ -545,6 +573,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
88801 new_addr = addr;
88802 }
88803 ret = addr;
88804+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
88805 goto out;
88806 }
88807 }
88808@@ -568,7 +597,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
88809 goto out;
88810 }
88811
88812+ map_flags = vma->vm_flags;
88813 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
88814+ if (!(ret & ~PAGE_MASK)) {
88815+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
88816+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
88817+ }
88818 }
88819 out:
88820 if (ret & ~PAGE_MASK)
88821diff --git a/mm/nommu.c b/mm/nommu.c
88822index ecd1f15..77039bd 100644
88823--- a/mm/nommu.c
88824+++ b/mm/nommu.c
88825@@ -64,7 +64,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
88826 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
88827 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
88828 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
88829-int heap_stack_gap = 0;
88830
88831 atomic_long_t mmap_pages_allocated;
88832
88833@@ -844,15 +843,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
88834 EXPORT_SYMBOL(find_vma);
88835
88836 /*
88837- * find a VMA
88838- * - we don't extend stack VMAs under NOMMU conditions
88839- */
88840-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
88841-{
88842- return find_vma(mm, addr);
88843-}
88844-
88845-/*
88846 * expand a stack to a given address
88847 * - not supported under NOMMU conditions
88848 */
88849@@ -1563,6 +1553,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
88850
88851 /* most fields are the same, copy all, and then fixup */
88852 *new = *vma;
88853+ INIT_LIST_HEAD(&new->anon_vma_chain);
88854 *region = *vma->vm_region;
88855 new->vm_region = region;
88856
88857@@ -1993,8 +1984,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
88858 }
88859 EXPORT_SYMBOL(generic_file_remap_pages);
88860
88861-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
88862- unsigned long addr, void *buf, int len, int write)
88863+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
88864+ unsigned long addr, void *buf, size_t len, int write)
88865 {
88866 struct vm_area_struct *vma;
88867
88868@@ -2035,8 +2026,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
88869 *
88870 * The caller must hold a reference on @mm.
88871 */
88872-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
88873- void *buf, int len, int write)
88874+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
88875+ void *buf, size_t len, int write)
88876 {
88877 return __access_remote_vm(NULL, mm, addr, buf, len, write);
88878 }
88879@@ -2045,7 +2036,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
88880 * Access another process' address space.
88881 * - source/target buffer must be kernel space
88882 */
88883-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
88884+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
88885 {
88886 struct mm_struct *mm;
88887
88888diff --git a/mm/page-writeback.c b/mm/page-writeback.c
88889index 241a746..41cd05d 100644
88890--- a/mm/page-writeback.c
88891+++ b/mm/page-writeback.c
88892@@ -659,7 +659,7 @@ unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty)
88893 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
88894 * - the bdi dirty thresh drops quickly due to change of JBOD workload
88895 */
88896-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
88897+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
88898 unsigned long thresh,
88899 unsigned long bg_thresh,
88900 unsigned long dirty,
88901diff --git a/mm/page_alloc.c b/mm/page_alloc.c
88902index b100255..fba1254 100644
88903--- a/mm/page_alloc.c
88904+++ b/mm/page_alloc.c
88905@@ -60,6 +60,7 @@
88906 #include <linux/page-debug-flags.h>
88907 #include <linux/hugetlb.h>
88908 #include <linux/sched/rt.h>
88909+#include <linux/random.h>
88910
88911 #include <asm/sections.h>
88912 #include <asm/tlbflush.h>
88913@@ -353,7 +354,7 @@ out:
88914 * This usage means that zero-order pages may not be compound.
88915 */
88916
88917-static void free_compound_page(struct page *page)
88918+void free_compound_page(struct page *page)
88919 {
88920 __free_pages_ok(page, compound_order(page));
88921 }
88922@@ -710,6 +711,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
88923 int i;
88924 int bad = 0;
88925
88926+#ifdef CONFIG_PAX_MEMORY_SANITIZE
88927+ unsigned long index = 1UL << order;
88928+#endif
88929+
88930 trace_mm_page_free(page, order);
88931 kmemcheck_free_shadow(page, order);
88932
88933@@ -725,6 +730,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
88934 debug_check_no_obj_freed(page_address(page),
88935 PAGE_SIZE << order);
88936 }
88937+
88938+#ifdef CONFIG_PAX_MEMORY_SANITIZE
88939+ for (; index; --index)
88940+ sanitize_highpage(page + index - 1);
88941+#endif
88942+
88943 arch_free_page(page, order);
88944 kernel_map_pages(page, 1 << order, 0);
88945
88946@@ -747,6 +758,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
88947 local_irq_restore(flags);
88948 }
88949
88950+#ifdef CONFIG_PAX_LATENT_ENTROPY
88951+bool __meminitdata extra_latent_entropy;
88952+
88953+static int __init setup_pax_extra_latent_entropy(char *str)
88954+{
88955+ extra_latent_entropy = true;
88956+ return 0;
88957+}
88958+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
88959+
88960+volatile u64 latent_entropy;
88961+EXPORT_SYMBOL(latent_entropy);
88962+#endif
88963+
88964 void __init __free_pages_bootmem(struct page *page, unsigned int order)
88965 {
88966 unsigned int nr_pages = 1 << order;
88967@@ -762,6 +787,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
88968 set_page_count(p, 0);
88969 }
88970
88971+#ifdef CONFIG_PAX_LATENT_ENTROPY
88972+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
88973+ u64 hash = 0;
88974+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
88975+ const u64 *data = lowmem_page_address(page);
88976+
88977+ for (index = 0; index < end; index++)
88978+ hash ^= hash + data[index];
88979+ latent_entropy ^= hash;
88980+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
88981+ }
88982+#endif
88983+
88984 page_zone(page)->managed_pages += 1 << order;
88985 set_page_refcounted(page);
88986 __free_pages(page, order);
88987@@ -867,8 +905,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
88988 arch_alloc_page(page, order);
88989 kernel_map_pages(page, 1 << order, 1);
88990
88991+#ifndef CONFIG_PAX_MEMORY_SANITIZE
88992 if (gfp_flags & __GFP_ZERO)
88993 prep_zero_page(page, order, gfp_flags);
88994+#endif
88995
88996 if (order && (gfp_flags & __GFP_COMP))
88997 prep_compound_page(page, order);
88998diff --git a/mm/page_io.c b/mm/page_io.c
88999index ba05b64..ef2f314 100644
89000--- a/mm/page_io.c
89001+++ b/mm/page_io.c
89002@@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
89003 struct file *swap_file = sis->swap_file;
89004 struct address_space *mapping = swap_file->f_mapping;
89005 struct iovec iov = {
89006- .iov_base = kmap(page),
89007+ .iov_base = (void __force_user *)kmap(page),
89008 .iov_len = PAGE_SIZE,
89009 };
89010
89011diff --git a/mm/percpu.c b/mm/percpu.c
89012index 8c8e08f..73a5cda 100644
89013--- a/mm/percpu.c
89014+++ b/mm/percpu.c
89015@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
89016 static unsigned int pcpu_high_unit_cpu __read_mostly;
89017
89018 /* the address of the first chunk which starts with the kernel static area */
89019-void *pcpu_base_addr __read_mostly;
89020+void *pcpu_base_addr __read_only;
89021 EXPORT_SYMBOL_GPL(pcpu_base_addr);
89022
89023 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
89024diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
89025index fd26d04..0cea1b0 100644
89026--- a/mm/process_vm_access.c
89027+++ b/mm/process_vm_access.c
89028@@ -13,6 +13,7 @@
89029 #include <linux/uio.h>
89030 #include <linux/sched.h>
89031 #include <linux/highmem.h>
89032+#include <linux/security.h>
89033 #include <linux/ptrace.h>
89034 #include <linux/slab.h>
89035 #include <linux/syscalls.h>
89036@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
89037 size_t iov_l_curr_offset = 0;
89038 ssize_t iov_len;
89039
89040+ return -ENOSYS; // PaX: until properly audited
89041+
89042 /*
89043 * Work out how many pages of struct pages we're going to need
89044 * when eventually calling get_user_pages
89045 */
89046 for (i = 0; i < riovcnt; i++) {
89047 iov_len = rvec[i].iov_len;
89048- if (iov_len > 0) {
89049- nr_pages_iov = ((unsigned long)rvec[i].iov_base
89050- + iov_len)
89051- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
89052- / PAGE_SIZE + 1;
89053- nr_pages = max(nr_pages, nr_pages_iov);
89054- }
89055+ if (iov_len <= 0)
89056+ continue;
89057+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
89058+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
89059+ nr_pages = max(nr_pages, nr_pages_iov);
89060 }
89061
89062 if (nr_pages == 0)
89063@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
89064 goto free_proc_pages;
89065 }
89066
89067+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
89068+ rc = -EPERM;
89069+ goto put_task_struct;
89070+ }
89071+
89072 mm = mm_access(task, PTRACE_MODE_ATTACH);
89073 if (!mm || IS_ERR(mm)) {
89074 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
89075diff --git a/mm/rmap.c b/mm/rmap.c
89076index b2e29ac..4168491 100644
89077--- a/mm/rmap.c
89078+++ b/mm/rmap.c
89079@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
89080 struct anon_vma *anon_vma = vma->anon_vma;
89081 struct anon_vma_chain *avc;
89082
89083+#ifdef CONFIG_PAX_SEGMEXEC
89084+ struct anon_vma_chain *avc_m = NULL;
89085+#endif
89086+
89087 might_sleep();
89088 if (unlikely(!anon_vma)) {
89089 struct mm_struct *mm = vma->vm_mm;
89090@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
89091 if (!avc)
89092 goto out_enomem;
89093
89094+#ifdef CONFIG_PAX_SEGMEXEC
89095+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
89096+ if (!avc_m)
89097+ goto out_enomem_free_avc;
89098+#endif
89099+
89100 anon_vma = find_mergeable_anon_vma(vma);
89101 allocated = NULL;
89102 if (!anon_vma) {
89103@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
89104 /* page_table_lock to protect against threads */
89105 spin_lock(&mm->page_table_lock);
89106 if (likely(!vma->anon_vma)) {
89107+
89108+#ifdef CONFIG_PAX_SEGMEXEC
89109+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
89110+
89111+ if (vma_m) {
89112+ BUG_ON(vma_m->anon_vma);
89113+ vma_m->anon_vma = anon_vma;
89114+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
89115+ avc_m = NULL;
89116+ }
89117+#endif
89118+
89119 vma->anon_vma = anon_vma;
89120 anon_vma_chain_link(vma, avc, anon_vma);
89121 allocated = NULL;
89122@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
89123
89124 if (unlikely(allocated))
89125 put_anon_vma(allocated);
89126+
89127+#ifdef CONFIG_PAX_SEGMEXEC
89128+ if (unlikely(avc_m))
89129+ anon_vma_chain_free(avc_m);
89130+#endif
89131+
89132 if (unlikely(avc))
89133 anon_vma_chain_free(avc);
89134 }
89135 return 0;
89136
89137 out_enomem_free_avc:
89138+
89139+#ifdef CONFIG_PAX_SEGMEXEC
89140+ if (avc_m)
89141+ anon_vma_chain_free(avc_m);
89142+#endif
89143+
89144 anon_vma_chain_free(avc);
89145 out_enomem:
89146 return -ENOMEM;
89147@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
89148 * Attach the anon_vmas from src to dst.
89149 * Returns 0 on success, -ENOMEM on failure.
89150 */
89151-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
89152+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
89153 {
89154 struct anon_vma_chain *avc, *pavc;
89155 struct anon_vma *root = NULL;
89156@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
89157 * the corresponding VMA in the parent process is attached to.
89158 * Returns 0 on success, non-zero on failure.
89159 */
89160-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
89161+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
89162 {
89163 struct anon_vma_chain *avc;
89164 struct anon_vma *anon_vma;
89165@@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
89166 void __init anon_vma_init(void)
89167 {
89168 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
89169- 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
89170- anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
89171+ 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
89172+ anon_vma_ctor);
89173+ anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
89174+ SLAB_PANIC|SLAB_NO_SANITIZE);
89175 }
89176
89177 /*
89178diff --git a/mm/shmem.c b/mm/shmem.c
89179index e43dc55..930e3a2 100644
89180--- a/mm/shmem.c
89181+++ b/mm/shmem.c
89182@@ -33,7 +33,7 @@
89183 #include <linux/swap.h>
89184 #include <linux/aio.h>
89185
89186-static struct vfsmount *shm_mnt;
89187+struct vfsmount *shm_mnt;
89188
89189 #ifdef CONFIG_SHMEM
89190 /*
89191@@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
89192 #define BOGO_DIRENT_SIZE 20
89193
89194 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
89195-#define SHORT_SYMLINK_LEN 128
89196+#define SHORT_SYMLINK_LEN 64
89197
89198 /*
89199 * shmem_fallocate and shmem_writepage communicate via inode->i_private
89200@@ -2232,6 +2232,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
89201 static int shmem_xattr_validate(const char *name)
89202 {
89203 struct { const char *prefix; size_t len; } arr[] = {
89204+
89205+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
89206+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
89207+#endif
89208+
89209 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
89210 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
89211 };
89212@@ -2287,6 +2292,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
89213 if (err)
89214 return err;
89215
89216+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
89217+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
89218+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
89219+ return -EOPNOTSUPP;
89220+ if (size > 8)
89221+ return -EINVAL;
89222+ }
89223+#endif
89224+
89225 return simple_xattr_set(&info->xattrs, name, value, size, flags);
89226 }
89227
89228@@ -2599,8 +2613,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
89229 int err = -ENOMEM;
89230
89231 /* Round up to L1_CACHE_BYTES to resist false sharing */
89232- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
89233- L1_CACHE_BYTES), GFP_KERNEL);
89234+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
89235 if (!sbinfo)
89236 return -ENOMEM;
89237
89238diff --git a/mm/slab.c b/mm/slab.c
89239index 2580db0..0523956 100644
89240--- a/mm/slab.c
89241+++ b/mm/slab.c
89242@@ -366,10 +366,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
89243 if ((x)->max_freeable < i) \
89244 (x)->max_freeable = i; \
89245 } while (0)
89246-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
89247-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
89248-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
89249-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
89250+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
89251+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
89252+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
89253+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
89254+#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
89255+#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
89256 #else
89257 #define STATS_INC_ACTIVE(x) do { } while (0)
89258 #define STATS_DEC_ACTIVE(x) do { } while (0)
89259@@ -386,6 +388,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
89260 #define STATS_INC_ALLOCMISS(x) do { } while (0)
89261 #define STATS_INC_FREEHIT(x) do { } while (0)
89262 #define STATS_INC_FREEMISS(x) do { } while (0)
89263+#define STATS_INC_SANITIZED(x) do { } while (0)
89264+#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
89265 #endif
89266
89267 #if DEBUG
89268@@ -477,7 +481,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
89269 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
89270 */
89271 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
89272- const struct slab *slab, void *obj)
89273+ const struct slab *slab, const void *obj)
89274 {
89275 u32 offset = (obj - slab->s_mem);
89276 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
89277@@ -1571,12 +1575,12 @@ void __init kmem_cache_init(void)
89278 */
89279
89280 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
89281- kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
89282+ kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
89283
89284 if (INDEX_AC != INDEX_NODE)
89285 kmalloc_caches[INDEX_NODE] =
89286 create_kmalloc_cache("kmalloc-node",
89287- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
89288+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
89289
89290 slab_early_init = 0;
89291
89292@@ -3577,6 +3581,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
89293 struct array_cache *ac = cpu_cache_get(cachep);
89294
89295 check_irq_off();
89296+
89297+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89298+ if (pax_sanitize_slab) {
89299+ if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
89300+ memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
89301+
89302+ if (cachep->ctor)
89303+ cachep->ctor(objp);
89304+
89305+ STATS_INC_SANITIZED(cachep);
89306+ } else
89307+ STATS_INC_NOT_SANITIZED(cachep);
89308+ }
89309+#endif
89310+
89311 kmemleak_free_recursive(objp, cachep->flags);
89312 objp = cache_free_debugcheck(cachep, objp, caller);
89313
89314@@ -3805,6 +3824,7 @@ void kfree(const void *objp)
89315
89316 if (unlikely(ZERO_OR_NULL_PTR(objp)))
89317 return;
89318+ VM_BUG_ON(!virt_addr_valid(objp));
89319 local_irq_save(flags);
89320 kfree_debugcheck(objp);
89321 c = virt_to_cache(objp);
89322@@ -4246,14 +4266,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
89323 }
89324 /* cpu stats */
89325 {
89326- unsigned long allochit = atomic_read(&cachep->allochit);
89327- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
89328- unsigned long freehit = atomic_read(&cachep->freehit);
89329- unsigned long freemiss = atomic_read(&cachep->freemiss);
89330+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
89331+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
89332+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
89333+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
89334
89335 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
89336 allochit, allocmiss, freehit, freemiss);
89337 }
89338+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89339+ {
89340+ unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
89341+ unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
89342+
89343+ seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
89344+ }
89345+#endif
89346 #endif
89347 }
89348
89349@@ -4471,13 +4499,71 @@ static const struct file_operations proc_slabstats_operations = {
89350 static int __init slab_proc_init(void)
89351 {
89352 #ifdef CONFIG_DEBUG_SLAB_LEAK
89353- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
89354+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
89355 #endif
89356 return 0;
89357 }
89358 module_init(slab_proc_init);
89359 #endif
89360
89361+bool is_usercopy_object(const void *ptr)
89362+{
89363+ struct page *page;
89364+ struct kmem_cache *cachep;
89365+
89366+ if (ZERO_OR_NULL_PTR(ptr))
89367+ return false;
89368+
89369+ if (!slab_is_available())
89370+ return false;
89371+
89372+ if (!virt_addr_valid(ptr))
89373+ return false;
89374+
89375+ page = virt_to_head_page(ptr);
89376+
89377+ if (!PageSlab(page))
89378+ return false;
89379+
89380+ cachep = page->slab_cache;
89381+ return cachep->flags & SLAB_USERCOPY;
89382+}
89383+
89384+#ifdef CONFIG_PAX_USERCOPY
89385+const char *check_heap_object(const void *ptr, unsigned long n)
89386+{
89387+ struct page *page;
89388+ struct kmem_cache *cachep;
89389+ struct slab *slabp;
89390+ unsigned int objnr;
89391+ unsigned long offset;
89392+
89393+ if (ZERO_OR_NULL_PTR(ptr))
89394+ return "<null>";
89395+
89396+ if (!virt_addr_valid(ptr))
89397+ return NULL;
89398+
89399+ page = virt_to_head_page(ptr);
89400+
89401+ if (!PageSlab(page))
89402+ return NULL;
89403+
89404+ cachep = page->slab_cache;
89405+ if (!(cachep->flags & SLAB_USERCOPY))
89406+ return cachep->name;
89407+
89408+ slabp = page->slab_page;
89409+ objnr = obj_to_index(cachep, slabp, ptr);
89410+ BUG_ON(objnr >= cachep->num);
89411+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
89412+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
89413+ return NULL;
89414+
89415+ return cachep->name;
89416+}
89417+#endif
89418+
89419 /**
89420 * ksize - get the actual amount of memory allocated for a given object
89421 * @objp: Pointer to the object
89422diff --git a/mm/slab.h b/mm/slab.h
89423index a535033..2f98fe5 100644
89424--- a/mm/slab.h
89425+++ b/mm/slab.h
89426@@ -32,6 +32,15 @@ extern struct list_head slab_caches;
89427 /* The slab cache that manages slab cache information */
89428 extern struct kmem_cache *kmem_cache;
89429
89430+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89431+#ifdef CONFIG_X86_64
89432+#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
89433+#else
89434+#define PAX_MEMORY_SANITIZE_VALUE '\xff'
89435+#endif
89436+extern bool pax_sanitize_slab;
89437+#endif
89438+
89439 unsigned long calculate_alignment(unsigned long flags,
89440 unsigned long align, unsigned long size);
89441
89442@@ -67,7 +76,8 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
89443
89444 /* Legal flag mask for kmem_cache_create(), for various configurations */
89445 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
89446- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
89447+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
89448+ SLAB_USERCOPY | SLAB_NO_SANITIZE)
89449
89450 #if defined(CONFIG_DEBUG_SLAB)
89451 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
89452@@ -231,6 +241,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
89453 return s;
89454
89455 page = virt_to_head_page(x);
89456+
89457+ BUG_ON(!PageSlab(page));
89458+
89459 cachep = page->slab_cache;
89460 if (slab_equal_or_root(cachep, s))
89461 return cachep;
89462diff --git a/mm/slab_common.c b/mm/slab_common.c
89463index 538bade..36fed99 100644
89464--- a/mm/slab_common.c
89465+++ b/mm/slab_common.c
89466@@ -22,11 +22,22 @@
89467
89468 #include "slab.h"
89469
89470-enum slab_state slab_state;
89471+enum slab_state slab_state __read_only;
89472 LIST_HEAD(slab_caches);
89473 DEFINE_MUTEX(slab_mutex);
89474 struct kmem_cache *kmem_cache;
89475
89476+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89477+bool pax_sanitize_slab __read_only = true;
89478+static int __init pax_sanitize_slab_setup(char *str)
89479+{
89480+ pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
89481+ printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
89482+ return 1;
89483+}
89484+__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
89485+#endif
89486+
89487 #ifdef CONFIG_DEBUG_VM
89488 static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
89489 size_t size)
89490@@ -209,7 +220,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
89491
89492 err = __kmem_cache_create(s, flags);
89493 if (!err) {
89494- s->refcount = 1;
89495+ atomic_set(&s->refcount, 1);
89496 list_add(&s->list, &slab_caches);
89497 memcg_cache_list_add(memcg, s);
89498 } else {
89499@@ -255,8 +266,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
89500
89501 get_online_cpus();
89502 mutex_lock(&slab_mutex);
89503- s->refcount--;
89504- if (!s->refcount) {
89505+ if (atomic_dec_and_test(&s->refcount)) {
89506 list_del(&s->list);
89507
89508 if (!__kmem_cache_shutdown(s)) {
89509@@ -302,7 +312,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
89510 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
89511 name, size, err);
89512
89513- s->refcount = -1; /* Exempt from merging for now */
89514+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
89515 }
89516
89517 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
89518@@ -315,7 +325,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
89519
89520 create_boot_cache(s, name, size, flags);
89521 list_add(&s->list, &slab_caches);
89522- s->refcount = 1;
89523+ atomic_set(&s->refcount, 1);
89524 return s;
89525 }
89526
89527@@ -327,6 +337,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
89528 EXPORT_SYMBOL(kmalloc_dma_caches);
89529 #endif
89530
89531+#ifdef CONFIG_PAX_USERCOPY_SLABS
89532+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
89533+EXPORT_SYMBOL(kmalloc_usercopy_caches);
89534+#endif
89535+
89536 /*
89537 * Conversion table for small slabs sizes / 8 to the index in the
89538 * kmalloc array. This is necessary for slabs < 192 since we have non power
89539@@ -391,6 +406,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
89540 return kmalloc_dma_caches[index];
89541
89542 #endif
89543+
89544+#ifdef CONFIG_PAX_USERCOPY_SLABS
89545+ if (unlikely((flags & GFP_USERCOPY)))
89546+ return kmalloc_usercopy_caches[index];
89547+
89548+#endif
89549+
89550 return kmalloc_caches[index];
89551 }
89552
89553@@ -447,7 +469,7 @@ void __init create_kmalloc_caches(unsigned long flags)
89554 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
89555 if (!kmalloc_caches[i]) {
89556 kmalloc_caches[i] = create_kmalloc_cache(NULL,
89557- 1 << i, flags);
89558+ 1 << i, SLAB_USERCOPY | flags);
89559 }
89560
89561 /*
89562@@ -456,10 +478,10 @@ void __init create_kmalloc_caches(unsigned long flags)
89563 * earlier power of two caches
89564 */
89565 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
89566- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
89567+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
89568
89569 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
89570- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
89571+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
89572 }
89573
89574 /* Kmalloc array is now usable */
89575@@ -492,6 +514,23 @@ void __init create_kmalloc_caches(unsigned long flags)
89576 }
89577 }
89578 #endif
89579+
89580+#ifdef CONFIG_PAX_USERCOPY_SLABS
89581+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
89582+ struct kmem_cache *s = kmalloc_caches[i];
89583+
89584+ if (s) {
89585+ int size = kmalloc_size(i);
89586+ char *n = kasprintf(GFP_NOWAIT,
89587+ "usercopy-kmalloc-%d", size);
89588+
89589+ BUG_ON(!n);
89590+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
89591+ size, SLAB_USERCOPY | flags);
89592+ }
89593+ }
89594+#endif
89595+
89596 }
89597 #endif /* !CONFIG_SLOB */
89598
89599@@ -523,6 +562,9 @@ void print_slabinfo_header(struct seq_file *m)
89600 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
89601 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
89602 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
89603+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89604+ seq_puts(m, " : pax <sanitized> <not_sanitized>");
89605+#endif
89606 #endif
89607 seq_putc(m, '\n');
89608 }
89609diff --git a/mm/slob.c b/mm/slob.c
89610index 91bd3f2..e2f549e 100644
89611--- a/mm/slob.c
89612+++ b/mm/slob.c
89613@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
89614 /*
89615 * Return the size of a slob block.
89616 */
89617-static slobidx_t slob_units(slob_t *s)
89618+static slobidx_t slob_units(const slob_t *s)
89619 {
89620 if (s->units > 0)
89621 return s->units;
89622@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
89623 /*
89624 * Return the next free slob block pointer after this one.
89625 */
89626-static slob_t *slob_next(slob_t *s)
89627+static slob_t *slob_next(const slob_t *s)
89628 {
89629 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
89630 slobidx_t next;
89631@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
89632 /*
89633 * Returns true if s is the last free block in its page.
89634 */
89635-static int slob_last(slob_t *s)
89636+static int slob_last(const slob_t *s)
89637 {
89638 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
89639 }
89640
89641-static void *slob_new_pages(gfp_t gfp, int order, int node)
89642+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
89643 {
89644- void *page;
89645+ struct page *page;
89646
89647 #ifdef CONFIG_NUMA
89648 if (node != NUMA_NO_NODE)
89649@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
89650 if (!page)
89651 return NULL;
89652
89653- return page_address(page);
89654+ __SetPageSlab(page);
89655+ return page;
89656 }
89657
89658-static void slob_free_pages(void *b, int order)
89659+static void slob_free_pages(struct page *sp, int order)
89660 {
89661 if (current->reclaim_state)
89662 current->reclaim_state->reclaimed_slab += 1 << order;
89663- free_pages((unsigned long)b, order);
89664+ __ClearPageSlab(sp);
89665+ page_mapcount_reset(sp);
89666+ sp->private = 0;
89667+ __free_pages(sp, order);
89668 }
89669
89670 /*
89671@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
89672
89673 /* Not enough space: must allocate a new page */
89674 if (!b) {
89675- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
89676- if (!b)
89677+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
89678+ if (!sp)
89679 return NULL;
89680- sp = virt_to_page(b);
89681- __SetPageSlab(sp);
89682+ b = page_address(sp);
89683
89684 spin_lock_irqsave(&slob_lock, flags);
89685 sp->units = SLOB_UNITS(PAGE_SIZE);
89686 sp->freelist = b;
89687+ sp->private = 0;
89688 INIT_LIST_HEAD(&sp->list);
89689 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
89690 set_slob_page_free(sp, slob_list);
89691@@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
89692 if (slob_page_free(sp))
89693 clear_slob_page_free(sp);
89694 spin_unlock_irqrestore(&slob_lock, flags);
89695- __ClearPageSlab(sp);
89696- page_mapcount_reset(sp);
89697- slob_free_pages(b, 0);
89698+ slob_free_pages(sp, 0);
89699 return;
89700 }
89701
89702+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89703+ if (pax_sanitize_slab)
89704+ memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
89705+#endif
89706+
89707 if (!slob_page_free(sp)) {
89708 /* This slob page is about to become partially free. Easy! */
89709 sp->units = units;
89710@@ -424,11 +431,10 @@ out:
89711 */
89712
89713 static __always_inline void *
89714-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
89715+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
89716 {
89717- unsigned int *m;
89718- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
89719- void *ret;
89720+ slob_t *m;
89721+ void *ret = NULL;
89722
89723 gfp &= gfp_allowed_mask;
89724
89725@@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
89726
89727 if (!m)
89728 return NULL;
89729- *m = size;
89730+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
89731+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
89732+ m[0].units = size;
89733+ m[1].units = align;
89734 ret = (void *)m + align;
89735
89736 trace_kmalloc_node(caller, ret,
89737 size, size + align, gfp, node);
89738 } else {
89739 unsigned int order = get_order(size);
89740+ struct page *page;
89741
89742 if (likely(order))
89743 gfp |= __GFP_COMP;
89744- ret = slob_new_pages(gfp, order, node);
89745+ page = slob_new_pages(gfp, order, node);
89746+ if (page) {
89747+ ret = page_address(page);
89748+ page->private = size;
89749+ }
89750
89751 trace_kmalloc_node(caller, ret,
89752 size, PAGE_SIZE << order, gfp, node);
89753 }
89754
89755- kmemleak_alloc(ret, size, 1, gfp);
89756+ return ret;
89757+}
89758+
89759+static __always_inline void *
89760+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
89761+{
89762+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
89763+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
89764+
89765+ if (!ZERO_OR_NULL_PTR(ret))
89766+ kmemleak_alloc(ret, size, 1, gfp);
89767 return ret;
89768 }
89769
89770@@ -493,34 +517,112 @@ void kfree(const void *block)
89771 return;
89772 kmemleak_free(block);
89773
89774+ VM_BUG_ON(!virt_addr_valid(block));
89775 sp = virt_to_page(block);
89776- if (PageSlab(sp)) {
89777+ VM_BUG_ON(!PageSlab(sp));
89778+ if (!sp->private) {
89779 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
89780- unsigned int *m = (unsigned int *)(block - align);
89781- slob_free(m, *m + align);
89782- } else
89783+ slob_t *m = (slob_t *)(block - align);
89784+ slob_free(m, m[0].units + align);
89785+ } else {
89786+ __ClearPageSlab(sp);
89787+ page_mapcount_reset(sp);
89788+ sp->private = 0;
89789 __free_pages(sp, compound_order(sp));
89790+ }
89791 }
89792 EXPORT_SYMBOL(kfree);
89793
89794+bool is_usercopy_object(const void *ptr)
89795+{
89796+ if (!slab_is_available())
89797+ return false;
89798+
89799+ // PAX: TODO
89800+
89801+ return false;
89802+}
89803+
89804+#ifdef CONFIG_PAX_USERCOPY
89805+const char *check_heap_object(const void *ptr, unsigned long n)
89806+{
89807+ struct page *page;
89808+ const slob_t *free;
89809+ const void *base;
89810+ unsigned long flags;
89811+
89812+ if (ZERO_OR_NULL_PTR(ptr))
89813+ return "<null>";
89814+
89815+ if (!virt_addr_valid(ptr))
89816+ return NULL;
89817+
89818+ page = virt_to_head_page(ptr);
89819+ if (!PageSlab(page))
89820+ return NULL;
89821+
89822+ if (page->private) {
89823+ base = page;
89824+ if (base <= ptr && n <= page->private - (ptr - base))
89825+ return NULL;
89826+ return "<slob>";
89827+ }
89828+
89829+ /* some tricky double walking to find the chunk */
89830+ spin_lock_irqsave(&slob_lock, flags);
89831+ base = (void *)((unsigned long)ptr & PAGE_MASK);
89832+ free = page->freelist;
89833+
89834+ while (!slob_last(free) && (void *)free <= ptr) {
89835+ base = free + slob_units(free);
89836+ free = slob_next(free);
89837+ }
89838+
89839+ while (base < (void *)free) {
89840+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
89841+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
89842+ int offset;
89843+
89844+ if (ptr < base + align)
89845+ break;
89846+
89847+ offset = ptr - base - align;
89848+ if (offset >= m) {
89849+ base += size;
89850+ continue;
89851+ }
89852+
89853+ if (n > m - offset)
89854+ break;
89855+
89856+ spin_unlock_irqrestore(&slob_lock, flags);
89857+ return NULL;
89858+ }
89859+
89860+ spin_unlock_irqrestore(&slob_lock, flags);
89861+ return "<slob>";
89862+}
89863+#endif
89864+
89865 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
89866 size_t ksize(const void *block)
89867 {
89868 struct page *sp;
89869 int align;
89870- unsigned int *m;
89871+ slob_t *m;
89872
89873 BUG_ON(!block);
89874 if (unlikely(block == ZERO_SIZE_PTR))
89875 return 0;
89876
89877 sp = virt_to_page(block);
89878- if (unlikely(!PageSlab(sp)))
89879- return PAGE_SIZE << compound_order(sp);
89880+ VM_BUG_ON(!PageSlab(sp));
89881+ if (sp->private)
89882+ return sp->private;
89883
89884 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
89885- m = (unsigned int *)(block - align);
89886- return SLOB_UNITS(*m) * SLOB_UNIT;
89887+ m = (slob_t *)(block - align);
89888+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
89889 }
89890 EXPORT_SYMBOL(ksize);
89891
89892@@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
89893
89894 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
89895 {
89896- void *b;
89897+ void *b = NULL;
89898
89899 flags &= gfp_allowed_mask;
89900
89901 lockdep_trace_alloc(flags);
89902
89903+#ifdef CONFIG_PAX_USERCOPY_SLABS
89904+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
89905+#else
89906 if (c->size < PAGE_SIZE) {
89907 b = slob_alloc(c->size, flags, c->align, node);
89908 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
89909 SLOB_UNITS(c->size) * SLOB_UNIT,
89910 flags, node);
89911 } else {
89912- b = slob_new_pages(flags, get_order(c->size), node);
89913+ struct page *sp;
89914+
89915+ sp = slob_new_pages(flags, get_order(c->size), node);
89916+ if (sp) {
89917+ b = page_address(sp);
89918+ sp->private = c->size;
89919+ }
89920 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
89921 PAGE_SIZE << get_order(c->size),
89922 flags, node);
89923 }
89924+#endif
89925
89926 if (b && c->ctor)
89927 c->ctor(b);
89928@@ -564,10 +676,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
89929
89930 static void __kmem_cache_free(void *b, int size)
89931 {
89932- if (size < PAGE_SIZE)
89933+ struct page *sp;
89934+
89935+ sp = virt_to_page(b);
89936+ BUG_ON(!PageSlab(sp));
89937+ if (!sp->private)
89938 slob_free(b, size);
89939 else
89940- slob_free_pages(b, get_order(size));
89941+ slob_free_pages(sp, get_order(size));
89942 }
89943
89944 static void kmem_rcu_free(struct rcu_head *head)
89945@@ -580,17 +696,31 @@ static void kmem_rcu_free(struct rcu_head *head)
89946
89947 void kmem_cache_free(struct kmem_cache *c, void *b)
89948 {
89949+ int size = c->size;
89950+
89951+#ifdef CONFIG_PAX_USERCOPY_SLABS
89952+ if (size + c->align < PAGE_SIZE) {
89953+ size += c->align;
89954+ b -= c->align;
89955+ }
89956+#endif
89957+
89958 kmemleak_free_recursive(b, c->flags);
89959 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
89960 struct slob_rcu *slob_rcu;
89961- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
89962- slob_rcu->size = c->size;
89963+ slob_rcu = b + (size - sizeof(struct slob_rcu));
89964+ slob_rcu->size = size;
89965 call_rcu(&slob_rcu->head, kmem_rcu_free);
89966 } else {
89967- __kmem_cache_free(b, c->size);
89968+ __kmem_cache_free(b, size);
89969 }
89970
89971+#ifdef CONFIG_PAX_USERCOPY_SLABS
89972+ trace_kfree(_RET_IP_, b);
89973+#else
89974 trace_kmem_cache_free(_RET_IP_, b);
89975+#endif
89976+
89977 }
89978 EXPORT_SYMBOL(kmem_cache_free);
89979
89980diff --git a/mm/slub.c b/mm/slub.c
89981index e3ba1f2..bd45dac 100644
89982--- a/mm/slub.c
89983+++ b/mm/slub.c
89984@@ -207,7 +207,7 @@ struct track {
89985
89986 enum track_item { TRACK_ALLOC, TRACK_FREE };
89987
89988-#ifdef CONFIG_SYSFS
89989+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
89990 static int sysfs_slab_add(struct kmem_cache *);
89991 static int sysfs_slab_alias(struct kmem_cache *, const char *);
89992 static void sysfs_slab_remove(struct kmem_cache *);
89993@@ -528,7 +528,7 @@ static void print_track(const char *s, struct track *t)
89994 if (!t->addr)
89995 return;
89996
89997- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
89998+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
89999 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
90000 #ifdef CONFIG_STACKTRACE
90001 {
90002@@ -2609,6 +2609,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
90003
90004 slab_free_hook(s, x);
90005
90006+#ifdef CONFIG_PAX_MEMORY_SANITIZE
90007+ if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
90008+ memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
90009+ if (s->ctor)
90010+ s->ctor(x);
90011+ }
90012+#endif
90013+
90014 redo:
90015 /*
90016 * Determine the currently cpus per cpu slab.
90017@@ -2676,7 +2684,7 @@ static int slub_min_objects;
90018 * Merge control. If this is set then no merging of slab caches will occur.
90019 * (Could be removed. This was introduced to pacify the merge skeptics.)
90020 */
90021-static int slub_nomerge;
90022+static int slub_nomerge = 1;
90023
90024 /*
90025 * Calculate the order of allocation given an slab object size.
90026@@ -2953,6 +2961,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
90027 s->inuse = size;
90028
90029 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
90030+#ifdef CONFIG_PAX_MEMORY_SANITIZE
90031+ (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
90032+#endif
90033 s->ctor)) {
90034 /*
90035 * Relocate free pointer after the object if it is not
90036@@ -3298,6 +3309,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
90037 EXPORT_SYMBOL(__kmalloc_node);
90038 #endif
90039
90040+bool is_usercopy_object(const void *ptr)
90041+{
90042+ struct page *page;
90043+ struct kmem_cache *s;
90044+
90045+ if (ZERO_OR_NULL_PTR(ptr))
90046+ return false;
90047+
90048+ if (!slab_is_available())
90049+ return false;
90050+
90051+ if (!virt_addr_valid(ptr))
90052+ return false;
90053+
90054+ page = virt_to_head_page(ptr);
90055+
90056+ if (!PageSlab(page))
90057+ return false;
90058+
90059+ s = page->slab_cache;
90060+ return s->flags & SLAB_USERCOPY;
90061+}
90062+
90063+#ifdef CONFIG_PAX_USERCOPY
90064+const char *check_heap_object(const void *ptr, unsigned long n)
90065+{
90066+ struct page *page;
90067+ struct kmem_cache *s;
90068+ unsigned long offset;
90069+
90070+ if (ZERO_OR_NULL_PTR(ptr))
90071+ return "<null>";
90072+
90073+ if (!virt_addr_valid(ptr))
90074+ return NULL;
90075+
90076+ page = virt_to_head_page(ptr);
90077+
90078+ if (!PageSlab(page))
90079+ return NULL;
90080+
90081+ s = page->slab_cache;
90082+ if (!(s->flags & SLAB_USERCOPY))
90083+ return s->name;
90084+
90085+ offset = (ptr - page_address(page)) % s->size;
90086+ if (offset <= s->object_size && n <= s->object_size - offset)
90087+ return NULL;
90088+
90089+ return s->name;
90090+}
90091+#endif
90092+
90093 size_t ksize(const void *object)
90094 {
90095 struct page *page;
90096@@ -3362,6 +3426,7 @@ void kfree(const void *x)
90097 if (unlikely(ZERO_OR_NULL_PTR(x)))
90098 return;
90099
90100+ VM_BUG_ON(!virt_addr_valid(x));
90101 page = virt_to_head_page(x);
90102 if (unlikely(!PageSlab(page))) {
90103 BUG_ON(!PageCompound(page));
90104@@ -3667,7 +3732,7 @@ static int slab_unmergeable(struct kmem_cache *s)
90105 /*
90106 * We may have set a slab to be unmergeable during bootstrap.
90107 */
90108- if (s->refcount < 0)
90109+ if (atomic_read(&s->refcount) < 0)
90110 return 1;
90111
90112 return 0;
90113@@ -3725,7 +3790,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
90114
90115 s = find_mergeable(memcg, size, align, flags, name, ctor);
90116 if (s) {
90117- s->refcount++;
90118+ atomic_inc(&s->refcount);
90119 /*
90120 * Adjust the object sizes so that we clear
90121 * the complete object on kzalloc.
90122@@ -3734,7 +3799,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
90123 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
90124
90125 if (sysfs_slab_alias(s, name)) {
90126- s->refcount--;
90127+ atomic_dec(&s->refcount);
90128 s = NULL;
90129 }
90130 }
90131@@ -3854,7 +3919,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
90132 }
90133 #endif
90134
90135-#ifdef CONFIG_SYSFS
90136+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90137 static int count_inuse(struct page *page)
90138 {
90139 return page->inuse;
90140@@ -4241,12 +4306,12 @@ static void resiliency_test(void)
90141 validate_slab_cache(kmalloc_caches[9]);
90142 }
90143 #else
90144-#ifdef CONFIG_SYSFS
90145+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90146 static void resiliency_test(void) {};
90147 #endif
90148 #endif
90149
90150-#ifdef CONFIG_SYSFS
90151+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90152 enum slab_stat_type {
90153 SL_ALL, /* All slabs */
90154 SL_PARTIAL, /* Only partially allocated slabs */
90155@@ -4490,7 +4555,7 @@ SLAB_ATTR_RO(ctor);
90156
90157 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
90158 {
90159- return sprintf(buf, "%d\n", s->refcount - 1);
90160+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
90161 }
90162 SLAB_ATTR_RO(aliases);
90163
90164@@ -4578,6 +4643,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
90165 SLAB_ATTR_RO(cache_dma);
90166 #endif
90167
90168+#ifdef CONFIG_PAX_USERCOPY_SLABS
90169+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
90170+{
90171+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
90172+}
90173+SLAB_ATTR_RO(usercopy);
90174+#endif
90175+
90176 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
90177 {
90178 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
90179@@ -4912,6 +4985,9 @@ static struct attribute *slab_attrs[] = {
90180 #ifdef CONFIG_ZONE_DMA
90181 &cache_dma_attr.attr,
90182 #endif
90183+#ifdef CONFIG_PAX_USERCOPY_SLABS
90184+ &usercopy_attr.attr,
90185+#endif
90186 #ifdef CONFIG_NUMA
90187 &remote_node_defrag_ratio_attr.attr,
90188 #endif
90189@@ -5143,6 +5219,7 @@ static char *create_unique_id(struct kmem_cache *s)
90190 return name;
90191 }
90192
90193+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90194 static int sysfs_slab_add(struct kmem_cache *s)
90195 {
90196 int err;
90197@@ -5166,7 +5243,7 @@ static int sysfs_slab_add(struct kmem_cache *s)
90198 }
90199
90200 s->kobj.kset = slab_kset;
90201- err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, name);
90202+ err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
90203 if (err) {
90204 kobject_put(&s->kobj);
90205 return err;
90206@@ -5200,6 +5277,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
90207 kobject_del(&s->kobj);
90208 kobject_put(&s->kobj);
90209 }
90210+#endif
90211
90212 /*
90213 * Need to buffer aliases during bootup until sysfs becomes
90214@@ -5213,6 +5291,7 @@ struct saved_alias {
90215
90216 static struct saved_alias *alias_list;
90217
90218+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90219 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
90220 {
90221 struct saved_alias *al;
90222@@ -5235,6 +5314,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
90223 alias_list = al;
90224 return 0;
90225 }
90226+#endif
90227
90228 static int __init slab_sysfs_init(void)
90229 {
90230diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
90231index 27eeab3..7c3f7f2 100644
90232--- a/mm/sparse-vmemmap.c
90233+++ b/mm/sparse-vmemmap.c
90234@@ -130,7 +130,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
90235 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
90236 if (!p)
90237 return NULL;
90238- pud_populate(&init_mm, pud, p);
90239+ pud_populate_kernel(&init_mm, pud, p);
90240 }
90241 return pud;
90242 }
90243@@ -142,7 +142,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
90244 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
90245 if (!p)
90246 return NULL;
90247- pgd_populate(&init_mm, pgd, p);
90248+ pgd_populate_kernel(&init_mm, pgd, p);
90249 }
90250 return pgd;
90251 }
90252diff --git a/mm/sparse.c b/mm/sparse.c
90253index 308d503..3dbbd04 100644
90254--- a/mm/sparse.c
90255+++ b/mm/sparse.c
90256@@ -764,7 +764,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
90257
90258 for (i = 0; i < PAGES_PER_SECTION; i++) {
90259 if (PageHWPoison(&memmap[i])) {
90260- atomic_long_sub(1, &num_poisoned_pages);
90261+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
90262 ClearPageHWPoison(&memmap[i]);
90263 }
90264 }
90265diff --git a/mm/swap.c b/mm/swap.c
90266index c899502..d4dc2cd 100644
90267--- a/mm/swap.c
90268+++ b/mm/swap.c
90269@@ -77,6 +77,8 @@ static void __put_compound_page(struct page *page)
90270
90271 __page_cache_release(page);
90272 dtor = get_compound_page_dtor(page);
90273+ if (!PageHuge(page))
90274+ BUG_ON(dtor != free_compound_page);
90275 (*dtor)(page);
90276 }
90277
90278diff --git a/mm/swapfile.c b/mm/swapfile.c
90279index 6cf2e60..d204b3e 100644
90280--- a/mm/swapfile.c
90281+++ b/mm/swapfile.c
90282@@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
90283
90284 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
90285 /* Activity counter to indicate that a swapon or swapoff has occurred */
90286-static atomic_t proc_poll_event = ATOMIC_INIT(0);
90287+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
90288
90289 static inline unsigned char swap_count(unsigned char ent)
90290 {
90291@@ -1699,7 +1699,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
90292 }
90293 filp_close(swap_file, NULL);
90294 err = 0;
90295- atomic_inc(&proc_poll_event);
90296+ atomic_inc_unchecked(&proc_poll_event);
90297 wake_up_interruptible(&proc_poll_wait);
90298
90299 out_dput:
90300@@ -1716,8 +1716,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
90301
90302 poll_wait(file, &proc_poll_wait, wait);
90303
90304- if (seq->poll_event != atomic_read(&proc_poll_event)) {
90305- seq->poll_event = atomic_read(&proc_poll_event);
90306+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
90307+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
90308 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
90309 }
90310
90311@@ -1815,7 +1815,7 @@ static int swaps_open(struct inode *inode, struct file *file)
90312 return ret;
90313
90314 seq = file->private_data;
90315- seq->poll_event = atomic_read(&proc_poll_event);
90316+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
90317 return 0;
90318 }
90319
90320@@ -2203,7 +2203,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
90321 (frontswap_map) ? "FS" : "");
90322
90323 mutex_unlock(&swapon_mutex);
90324- atomic_inc(&proc_poll_event);
90325+ atomic_inc_unchecked(&proc_poll_event);
90326 wake_up_interruptible(&proc_poll_wait);
90327
90328 if (S_ISREG(inode->i_mode))
90329diff --git a/mm/util.c b/mm/util.c
90330index 7441c41..c3de793 100644
90331--- a/mm/util.c
90332+++ b/mm/util.c
90333@@ -294,6 +294,12 @@ done:
90334 void arch_pick_mmap_layout(struct mm_struct *mm)
90335 {
90336 mm->mmap_base = TASK_UNMAPPED_BASE;
90337+
90338+#ifdef CONFIG_PAX_RANDMMAP
90339+ if (mm->pax_flags & MF_PAX_RANDMMAP)
90340+ mm->mmap_base += mm->delta_mmap;
90341+#endif
90342+
90343 mm->get_unmapped_area = arch_get_unmapped_area;
90344 }
90345 #endif
90346diff --git a/mm/vmalloc.c b/mm/vmalloc.c
90347index 13a5495..6707d97 100644
90348--- a/mm/vmalloc.c
90349+++ b/mm/vmalloc.c
90350@@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
90351
90352 pte = pte_offset_kernel(pmd, addr);
90353 do {
90354- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
90355- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
90356+
90357+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90358+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
90359+ BUG_ON(!pte_exec(*pte));
90360+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
90361+ continue;
90362+ }
90363+#endif
90364+
90365+ {
90366+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
90367+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
90368+ }
90369 } while (pte++, addr += PAGE_SIZE, addr != end);
90370 }
90371
90372@@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
90373 pte = pte_alloc_kernel(pmd, addr);
90374 if (!pte)
90375 return -ENOMEM;
90376+
90377+ pax_open_kernel();
90378 do {
90379 struct page *page = pages[*nr];
90380
90381- if (WARN_ON(!pte_none(*pte)))
90382+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90383+ if (pgprot_val(prot) & _PAGE_NX)
90384+#endif
90385+
90386+ if (!pte_none(*pte)) {
90387+ pax_close_kernel();
90388+ WARN_ON(1);
90389 return -EBUSY;
90390- if (WARN_ON(!page))
90391+ }
90392+ if (!page) {
90393+ pax_close_kernel();
90394+ WARN_ON(1);
90395 return -ENOMEM;
90396+ }
90397 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
90398 (*nr)++;
90399 } while (pte++, addr += PAGE_SIZE, addr != end);
90400+ pax_close_kernel();
90401 return 0;
90402 }
90403
90404@@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
90405 pmd_t *pmd;
90406 unsigned long next;
90407
90408- pmd = pmd_alloc(&init_mm, pud, addr);
90409+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
90410 if (!pmd)
90411 return -ENOMEM;
90412 do {
90413@@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
90414 pud_t *pud;
90415 unsigned long next;
90416
90417- pud = pud_alloc(&init_mm, pgd, addr);
90418+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
90419 if (!pud)
90420 return -ENOMEM;
90421 do {
90422@@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
90423 if (addr >= MODULES_VADDR && addr < MODULES_END)
90424 return 1;
90425 #endif
90426+
90427+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90428+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
90429+ return 1;
90430+#endif
90431+
90432 return is_vmalloc_addr(x);
90433 }
90434
90435@@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
90436
90437 if (!pgd_none(*pgd)) {
90438 pud_t *pud = pud_offset(pgd, addr);
90439+#ifdef CONFIG_X86
90440+ if (!pud_large(*pud))
90441+#endif
90442 if (!pud_none(*pud)) {
90443 pmd_t *pmd = pmd_offset(pud, addr);
90444+#ifdef CONFIG_X86
90445+ if (!pmd_large(*pmd))
90446+#endif
90447 if (!pmd_none(*pmd)) {
90448 pte_t *ptep, pte;
90449
90450@@ -339,7 +375,7 @@ static void purge_vmap_area_lazy(void);
90451 * Allocate a region of KVA of the specified size and alignment, within the
90452 * vstart and vend.
90453 */
90454-static struct vmap_area *alloc_vmap_area(unsigned long size,
90455+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
90456 unsigned long align,
90457 unsigned long vstart, unsigned long vend,
90458 int node, gfp_t gfp_mask)
90459@@ -1308,6 +1344,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
90460 struct vm_struct *area;
90461
90462 BUG_ON(in_interrupt());
90463+
90464+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
90465+ if (flags & VM_KERNEXEC) {
90466+ if (start != VMALLOC_START || end != VMALLOC_END)
90467+ return NULL;
90468+ start = (unsigned long)MODULES_EXEC_VADDR;
90469+ end = (unsigned long)MODULES_EXEC_END;
90470+ }
90471+#endif
90472+
90473 if (flags & VM_IOREMAP)
90474 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
90475
90476@@ -1533,6 +1579,11 @@ void *vmap(struct page **pages, unsigned int count,
90477 if (count > totalram_pages)
90478 return NULL;
90479
90480+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
90481+ if (!(pgprot_val(prot) & _PAGE_NX))
90482+ flags |= VM_KERNEXEC;
90483+#endif
90484+
90485 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
90486 __builtin_return_address(0));
90487 if (!area)
90488@@ -1634,6 +1685,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
90489 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
90490 goto fail;
90491
90492+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
90493+ if (!(pgprot_val(prot) & _PAGE_NX))
90494+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
90495+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
90496+ else
90497+#endif
90498+
90499 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
90500 start, end, node, gfp_mask, caller);
90501 if (!area)
90502@@ -1810,10 +1868,9 @@ EXPORT_SYMBOL(vzalloc_node);
90503 * For tight control over page level allocator and protection flags
90504 * use __vmalloc() instead.
90505 */
90506-
90507 void *vmalloc_exec(unsigned long size)
90508 {
90509- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
90510+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
90511 NUMA_NO_NODE, __builtin_return_address(0));
90512 }
90513
90514@@ -2120,6 +2177,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
90515 {
90516 struct vm_struct *area;
90517
90518+ BUG_ON(vma->vm_mirror);
90519+
90520 size = PAGE_ALIGN(size);
90521
90522 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
90523@@ -2605,7 +2664,11 @@ static int s_show(struct seq_file *m, void *p)
90524 v->addr, v->addr + v->size, v->size);
90525
90526 if (v->caller)
90527+#ifdef CONFIG_GRKERNSEC_HIDESYM
90528+ seq_printf(m, " %pK", v->caller);
90529+#else
90530 seq_printf(m, " %pS", v->caller);
90531+#endif
90532
90533 if (v->nr_pages)
90534 seq_printf(m, " pages=%d", v->nr_pages);
90535diff --git a/mm/vmstat.c b/mm/vmstat.c
90536index 20c2ef4..15e7ab7 100644
90537--- a/mm/vmstat.c
90538+++ b/mm/vmstat.c
90539@@ -76,7 +76,7 @@ void vm_events_fold_cpu(int cpu)
90540 *
90541 * vm_stat contains the global counters
90542 */
90543-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
90544+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
90545 EXPORT_SYMBOL(vm_stat);
90546
90547 #ifdef CONFIG_SMP
90548@@ -452,7 +452,7 @@ void refresh_cpu_vm_stats(int cpu)
90549 v = p->vm_stat_diff[i];
90550 p->vm_stat_diff[i] = 0;
90551 local_irq_restore(flags);
90552- atomic_long_add(v, &zone->vm_stat[i]);
90553+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
90554 global_diff[i] += v;
90555 #ifdef CONFIG_NUMA
90556 /* 3 seconds idle till flush */
90557@@ -490,7 +490,7 @@ void refresh_cpu_vm_stats(int cpu)
90558
90559 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
90560 if (global_diff[i])
90561- atomic_long_add(global_diff[i], &vm_stat[i]);
90562+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
90563 }
90564
90565 /*
90566@@ -505,8 +505,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
90567 if (pset->vm_stat_diff[i]) {
90568 int v = pset->vm_stat_diff[i];
90569 pset->vm_stat_diff[i] = 0;
90570- atomic_long_add(v, &zone->vm_stat[i]);
90571- atomic_long_add(v, &vm_stat[i]);
90572+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
90573+ atomic_long_add_unchecked(v, &vm_stat[i]);
90574 }
90575 }
90576 #endif
90577@@ -1241,10 +1241,20 @@ static int __init setup_vmstat(void)
90578 start_cpu_timer(cpu);
90579 #endif
90580 #ifdef CONFIG_PROC_FS
90581- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
90582- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
90583- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
90584- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
90585+ {
90586+ mode_t gr_mode = S_IRUGO;
90587+#ifdef CONFIG_GRKERNSEC_PROC_ADD
90588+ gr_mode = S_IRUSR;
90589+#endif
90590+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
90591+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
90592+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
90593+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
90594+#else
90595+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
90596+#endif
90597+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
90598+ }
90599 #endif
90600 return 0;
90601 }
90602diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
90603index 2fb2d88..8c06e40 100644
90604--- a/net/8021q/vlan.c
90605+++ b/net/8021q/vlan.c
90606@@ -469,7 +469,7 @@ out:
90607 return NOTIFY_DONE;
90608 }
90609
90610-static struct notifier_block vlan_notifier_block __read_mostly = {
90611+static struct notifier_block vlan_notifier_block = {
90612 .notifier_call = vlan_device_event,
90613 };
90614
90615@@ -544,8 +544,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
90616 err = -EPERM;
90617 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
90618 break;
90619- if ((args.u.name_type >= 0) &&
90620- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
90621+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
90622 struct vlan_net *vn;
90623
90624 vn = net_generic(net, vlan_net_id);
90625diff --git a/net/9p/mod.c b/net/9p/mod.c
90626index 6ab36ae..6f1841b 100644
90627--- a/net/9p/mod.c
90628+++ b/net/9p/mod.c
90629@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
90630 void v9fs_register_trans(struct p9_trans_module *m)
90631 {
90632 spin_lock(&v9fs_trans_lock);
90633- list_add_tail(&m->list, &v9fs_trans_list);
90634+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
90635 spin_unlock(&v9fs_trans_lock);
90636 }
90637 EXPORT_SYMBOL(v9fs_register_trans);
90638@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
90639 void v9fs_unregister_trans(struct p9_trans_module *m)
90640 {
90641 spin_lock(&v9fs_trans_lock);
90642- list_del_init(&m->list);
90643+ pax_list_del_init((struct list_head *)&m->list);
90644 spin_unlock(&v9fs_trans_lock);
90645 }
90646 EXPORT_SYMBOL(v9fs_unregister_trans);
90647diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
90648index 3ffda1b..fceac96 100644
90649--- a/net/9p/trans_fd.c
90650+++ b/net/9p/trans_fd.c
90651@@ -432,7 +432,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
90652 oldfs = get_fs();
90653 set_fs(get_ds());
90654 /* The cast to a user pointer is valid due to the set_fs() */
90655- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
90656+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
90657 set_fs(oldfs);
90658
90659 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
90660diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
90661index 876fbe8..8bbea9f 100644
90662--- a/net/atm/atm_misc.c
90663+++ b/net/atm/atm_misc.c
90664@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
90665 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
90666 return 1;
90667 atm_return(vcc, truesize);
90668- atomic_inc(&vcc->stats->rx_drop);
90669+ atomic_inc_unchecked(&vcc->stats->rx_drop);
90670 return 0;
90671 }
90672 EXPORT_SYMBOL(atm_charge);
90673@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
90674 }
90675 }
90676 atm_return(vcc, guess);
90677- atomic_inc(&vcc->stats->rx_drop);
90678+ atomic_inc_unchecked(&vcc->stats->rx_drop);
90679 return NULL;
90680 }
90681 EXPORT_SYMBOL(atm_alloc_charge);
90682@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
90683
90684 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
90685 {
90686-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
90687+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
90688 __SONET_ITEMS
90689 #undef __HANDLE_ITEM
90690 }
90691@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
90692
90693 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
90694 {
90695-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
90696+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
90697 __SONET_ITEMS
90698 #undef __HANDLE_ITEM
90699 }
90700diff --git a/net/atm/lec.h b/net/atm/lec.h
90701index 4149db1..f2ab682 100644
90702--- a/net/atm/lec.h
90703+++ b/net/atm/lec.h
90704@@ -48,7 +48,7 @@ struct lane2_ops {
90705 const u8 *tlvs, u32 sizeoftlvs);
90706 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
90707 const u8 *tlvs, u32 sizeoftlvs);
90708-};
90709+} __no_const;
90710
90711 /*
90712 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
90713diff --git a/net/atm/proc.c b/net/atm/proc.c
90714index bbb6461..cf04016 100644
90715--- a/net/atm/proc.c
90716+++ b/net/atm/proc.c
90717@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
90718 const struct k_atm_aal_stats *stats)
90719 {
90720 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
90721- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
90722- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
90723- atomic_read(&stats->rx_drop));
90724+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
90725+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
90726+ atomic_read_unchecked(&stats->rx_drop));
90727 }
90728
90729 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
90730diff --git a/net/atm/resources.c b/net/atm/resources.c
90731index 0447d5d..3cf4728 100644
90732--- a/net/atm/resources.c
90733+++ b/net/atm/resources.c
90734@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
90735 static void copy_aal_stats(struct k_atm_aal_stats *from,
90736 struct atm_aal_stats *to)
90737 {
90738-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
90739+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
90740 __AAL_STAT_ITEMS
90741 #undef __HANDLE_ITEM
90742 }
90743@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
90744 static void subtract_aal_stats(struct k_atm_aal_stats *from,
90745 struct atm_aal_stats *to)
90746 {
90747-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
90748+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
90749 __AAL_STAT_ITEMS
90750 #undef __HANDLE_ITEM
90751 }
90752diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
90753index 919a5ce..cc6b444 100644
90754--- a/net/ax25/sysctl_net_ax25.c
90755+++ b/net/ax25/sysctl_net_ax25.c
90756@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
90757 {
90758 char path[sizeof("net/ax25/") + IFNAMSIZ];
90759 int k;
90760- struct ctl_table *table;
90761+ ctl_table_no_const *table;
90762
90763 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
90764 if (!table)
90765diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
90766index 62da527..aa27535 100644
90767--- a/net/batman-adv/bat_iv_ogm.c
90768+++ b/net/batman-adv/bat_iv_ogm.c
90769@@ -120,7 +120,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
90770
90771 /* randomize initial seqno to avoid collision */
90772 get_random_bytes(&random_seqno, sizeof(random_seqno));
90773- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
90774+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
90775
90776 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
90777 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
90778@@ -701,9 +701,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
90779 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
90780
90781 /* change sequence number to network order */
90782- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
90783+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
90784 batadv_ogm_packet->seqno = htonl(seqno);
90785- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
90786+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
90787
90788 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
90789 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
90790@@ -1109,7 +1109,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
90791 return;
90792
90793 /* could be changed by schedule_own_packet() */
90794- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
90795+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
90796
90797 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
90798 has_directlink_flag = 1;
90799diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
90800index c478e6b..469fd2f 100644
90801--- a/net/batman-adv/hard-interface.c
90802+++ b/net/batman-adv/hard-interface.c
90803@@ -453,7 +453,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
90804 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
90805 dev_add_pack(&hard_iface->batman_adv_ptype);
90806
90807- atomic_set(&hard_iface->frag_seqno, 1);
90808+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
90809 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
90810 hard_iface->net_dev->name);
90811
90812diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
90813index 33b6144..3212ac5 100644
90814--- a/net/batman-adv/soft-interface.c
90815+++ b/net/batman-adv/soft-interface.c
90816@@ -261,7 +261,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
90817 primary_if->net_dev->dev_addr, ETH_ALEN);
90818
90819 /* set broadcast sequence number */
90820- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
90821+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
90822 bcast_packet->seqno = htonl(seqno);
90823
90824 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
90825@@ -481,7 +481,7 @@ static int batadv_softif_init_late(struct net_device *dev)
90826 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
90827
90828 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
90829- atomic_set(&bat_priv->bcast_seqno, 1);
90830+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
90831 atomic_set(&bat_priv->tt.vn, 0);
90832 atomic_set(&bat_priv->tt.local_changes, 0);
90833 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
90834diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
90835index b2c94e1..3d47e07 100644
90836--- a/net/batman-adv/types.h
90837+++ b/net/batman-adv/types.h
90838@@ -51,7 +51,7 @@
90839 struct batadv_hard_iface_bat_iv {
90840 unsigned char *ogm_buff;
90841 int ogm_buff_len;
90842- atomic_t ogm_seqno;
90843+ atomic_unchecked_t ogm_seqno;
90844 };
90845
90846 /**
90847@@ -76,7 +76,7 @@ struct batadv_hard_iface {
90848 int16_t if_num;
90849 char if_status;
90850 struct net_device *net_dev;
90851- atomic_t frag_seqno;
90852+ atomic_unchecked_t frag_seqno;
90853 uint8_t num_bcasts;
90854 struct kobject *hardif_obj;
90855 atomic_t refcount;
90856@@ -560,7 +560,7 @@ struct batadv_priv {
90857 #ifdef CONFIG_BATMAN_ADV_DEBUG
90858 atomic_t log_level;
90859 #endif
90860- atomic_t bcast_seqno;
90861+ atomic_unchecked_t bcast_seqno;
90862 atomic_t bcast_queue_left;
90863 atomic_t batman_queue_left;
90864 char num_ifaces;
90865diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
90866index 857e1b8..5ad07b2 100644
90867--- a/net/batman-adv/unicast.c
90868+++ b/net/batman-adv/unicast.c
90869@@ -270,7 +270,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
90870 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
90871 frag2->flags = large_tail;
90872
90873- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
90874+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
90875 frag1->seqno = htons(seqno - 1);
90876 frag2->seqno = htons(seqno);
90877
90878diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
90879index 9bd7d95..6c4884f 100644
90880--- a/net/bluetooth/hci_sock.c
90881+++ b/net/bluetooth/hci_sock.c
90882@@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
90883 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
90884 }
90885
90886- len = min_t(unsigned int, len, sizeof(uf));
90887+ len = min((size_t)len, sizeof(uf));
90888 if (copy_from_user(&uf, optval, len)) {
90889 err = -EFAULT;
90890 break;
90891diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
90892index 8c3499b..2661c6a 100644
90893--- a/net/bluetooth/l2cap_core.c
90894+++ b/net/bluetooth/l2cap_core.c
90895@@ -3510,8 +3510,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
90896 break;
90897
90898 case L2CAP_CONF_RFC:
90899- if (olen == sizeof(rfc))
90900- memcpy(&rfc, (void *)val, olen);
90901+ if (olen != sizeof(rfc))
90902+ break;
90903+
90904+ memcpy(&rfc, (void *)val, olen);
90905
90906 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
90907 rfc.mode != chan->mode)
90908diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
90909index 0098af8..fb5a31f 100644
90910--- a/net/bluetooth/l2cap_sock.c
90911+++ b/net/bluetooth/l2cap_sock.c
90912@@ -485,7 +485,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
90913 struct sock *sk = sock->sk;
90914 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
90915 struct l2cap_options opts;
90916- int len, err = 0;
90917+ int err = 0;
90918+ size_t len = optlen;
90919 u32 opt;
90920
90921 BT_DBG("sk %p", sk);
90922@@ -507,7 +508,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
90923 opts.max_tx = chan->max_tx;
90924 opts.txwin_size = chan->tx_win;
90925
90926- len = min_t(unsigned int, sizeof(opts), optlen);
90927+ len = min(sizeof(opts), len);
90928 if (copy_from_user((char *) &opts, optval, len)) {
90929 err = -EFAULT;
90930 break;
90931@@ -587,7 +588,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
90932 struct bt_security sec;
90933 struct bt_power pwr;
90934 struct l2cap_conn *conn;
90935- int len, err = 0;
90936+ int err = 0;
90937+ size_t len = optlen;
90938 u32 opt;
90939
90940 BT_DBG("sk %p", sk);
90941@@ -610,7 +612,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
90942
90943 sec.level = BT_SECURITY_LOW;
90944
90945- len = min_t(unsigned int, sizeof(sec), optlen);
90946+ len = min(sizeof(sec), len);
90947 if (copy_from_user((char *) &sec, optval, len)) {
90948 err = -EFAULT;
90949 break;
90950@@ -707,7 +709,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
90951
90952 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
90953
90954- len = min_t(unsigned int, sizeof(pwr), optlen);
90955+ len = min(sizeof(pwr), len);
90956 if (copy_from_user((char *) &pwr, optval, len)) {
90957 err = -EFAULT;
90958 break;
90959diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
90960index 30b3721..c1bd0a0 100644
90961--- a/net/bluetooth/rfcomm/sock.c
90962+++ b/net/bluetooth/rfcomm/sock.c
90963@@ -666,7 +666,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
90964 struct sock *sk = sock->sk;
90965 struct bt_security sec;
90966 int err = 0;
90967- size_t len;
90968+ size_t len = optlen;
90969 u32 opt;
90970
90971 BT_DBG("sk %p", sk);
90972@@ -688,7 +688,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
90973
90974 sec.level = BT_SECURITY_LOW;
90975
90976- len = min_t(unsigned int, sizeof(sec), optlen);
90977+ len = min(sizeof(sec), len);
90978 if (copy_from_user((char *) &sec, optval, len)) {
90979 err = -EFAULT;
90980 break;
90981diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
90982index b6e44ad..5b0d514 100644
90983--- a/net/bluetooth/rfcomm/tty.c
90984+++ b/net/bluetooth/rfcomm/tty.c
90985@@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
90986 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
90987
90988 spin_lock_irqsave(&dev->port.lock, flags);
90989- if (dev->port.count > 0) {
90990+ if (atomic_read(&dev->port.count) > 0) {
90991 spin_unlock_irqrestore(&dev->port.lock, flags);
90992 return;
90993 }
90994@@ -659,10 +659,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
90995 return -ENODEV;
90996
90997 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
90998- dev->channel, dev->port.count);
90999+ dev->channel, atomic_read(&dev->port.count));
91000
91001 spin_lock_irqsave(&dev->port.lock, flags);
91002- if (++dev->port.count > 1) {
91003+ if (atomic_inc_return(&dev->port.count) > 1) {
91004 spin_unlock_irqrestore(&dev->port.lock, flags);
91005 return 0;
91006 }
91007@@ -727,10 +727,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
91008 return;
91009
91010 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
91011- dev->port.count);
91012+ atomic_read(&dev->port.count));
91013
91014 spin_lock_irqsave(&dev->port.lock, flags);
91015- if (!--dev->port.count) {
91016+ if (!atomic_dec_return(&dev->port.count)) {
91017 spin_unlock_irqrestore(&dev->port.lock, flags);
91018 if (dev->tty_dev->parent)
91019 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
91020diff --git a/net/bridge/netfilter/ebt_ulog.c b/net/bridge/netfilter/ebt_ulog.c
91021index 5180938..7c470c3 100644
91022--- a/net/bridge/netfilter/ebt_ulog.c
91023+++ b/net/bridge/netfilter/ebt_ulog.c
91024@@ -181,6 +181,7 @@ static void ebt_ulog_packet(struct net *net, unsigned int hooknr,
91025 ub->qlen++;
91026
91027 pm = nlmsg_data(nlh);
91028+ memset(pm, 0, sizeof(*pm));
91029
91030 /* Fill in the ulog data */
91031 pm->version = EBT_ULOG_VERSION;
91032@@ -193,8 +194,6 @@ static void ebt_ulog_packet(struct net *net, unsigned int hooknr,
91033 pm->hook = hooknr;
91034 if (uloginfo->prefix != NULL)
91035 strcpy(pm->prefix, uloginfo->prefix);
91036- else
91037- *(pm->prefix) = '\0';
91038
91039 if (in) {
91040 strcpy(pm->physindev, in->name);
91041@@ -204,16 +203,14 @@ static void ebt_ulog_packet(struct net *net, unsigned int hooknr,
91042 strcpy(pm->indev, br_port_get_rcu(in)->br->dev->name);
91043 else
91044 strcpy(pm->indev, in->name);
91045- } else
91046- pm->indev[0] = pm->physindev[0] = '\0';
91047+ }
91048
91049 if (out) {
91050 /* If out exists, then out is a bridge port */
91051 strcpy(pm->physoutdev, out->name);
91052 /* rcu_read_lock()ed by nf_hook_slow */
91053 strcpy(pm->outdev, br_port_get_rcu(out)->br->dev->name);
91054- } else
91055- pm->outdev[0] = pm->physoutdev[0] = '\0';
91056+ }
91057
91058 if (skb_copy_bits(skb, -ETH_HLEN, pm->data, copy_len) < 0)
91059 BUG();
91060diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
91061index ac78024..161a80c 100644
91062--- a/net/bridge/netfilter/ebtables.c
91063+++ b/net/bridge/netfilter/ebtables.c
91064@@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
91065 tmp.valid_hooks = t->table->valid_hooks;
91066 }
91067 mutex_unlock(&ebt_mutex);
91068- if (copy_to_user(user, &tmp, *len) != 0){
91069+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
91070 BUGPRINT("c2u Didn't work\n");
91071 ret = -EFAULT;
91072 break;
91073@@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
91074 goto out;
91075 tmp.valid_hooks = t->valid_hooks;
91076
91077- if (copy_to_user(user, &tmp, *len) != 0) {
91078+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
91079 ret = -EFAULT;
91080 break;
91081 }
91082@@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
91083 tmp.entries_size = t->table->entries_size;
91084 tmp.valid_hooks = t->table->valid_hooks;
91085
91086- if (copy_to_user(user, &tmp, *len) != 0) {
91087+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
91088 ret = -EFAULT;
91089 break;
91090 }
91091diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
91092index 0f45522..dab651f 100644
91093--- a/net/caif/cfctrl.c
91094+++ b/net/caif/cfctrl.c
91095@@ -10,6 +10,7 @@
91096 #include <linux/spinlock.h>
91097 #include <linux/slab.h>
91098 #include <linux/pkt_sched.h>
91099+#include <linux/sched.h>
91100 #include <net/caif/caif_layer.h>
91101 #include <net/caif/cfpkt.h>
91102 #include <net/caif/cfctrl.h>
91103@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
91104 memset(&dev_info, 0, sizeof(dev_info));
91105 dev_info.id = 0xff;
91106 cfsrvl_init(&this->serv, 0, &dev_info, false);
91107- atomic_set(&this->req_seq_no, 1);
91108- atomic_set(&this->rsp_seq_no, 1);
91109+ atomic_set_unchecked(&this->req_seq_no, 1);
91110+ atomic_set_unchecked(&this->rsp_seq_no, 1);
91111 this->serv.layer.receive = cfctrl_recv;
91112 sprintf(this->serv.layer.name, "ctrl");
91113 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
91114@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
91115 struct cfctrl_request_info *req)
91116 {
91117 spin_lock_bh(&ctrl->info_list_lock);
91118- atomic_inc(&ctrl->req_seq_no);
91119- req->sequence_no = atomic_read(&ctrl->req_seq_no);
91120+ atomic_inc_unchecked(&ctrl->req_seq_no);
91121+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
91122 list_add_tail(&req->list, &ctrl->list);
91123 spin_unlock_bh(&ctrl->info_list_lock);
91124 }
91125@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
91126 if (p != first)
91127 pr_warn("Requests are not received in order\n");
91128
91129- atomic_set(&ctrl->rsp_seq_no,
91130+ atomic_set_unchecked(&ctrl->rsp_seq_no,
91131 p->sequence_no);
91132 list_del(&p->list);
91133 goto out;
91134diff --git a/net/can/af_can.c b/net/can/af_can.c
91135index 3ab8dd2..b9aef13 100644
91136--- a/net/can/af_can.c
91137+++ b/net/can/af_can.c
91138@@ -862,7 +862,7 @@ static const struct net_proto_family can_family_ops = {
91139 };
91140
91141 /* notifier block for netdevice event */
91142-static struct notifier_block can_netdev_notifier __read_mostly = {
91143+static struct notifier_block can_netdev_notifier = {
91144 .notifier_call = can_notifier,
91145 };
91146
91147diff --git a/net/can/gw.c b/net/can/gw.c
91148index 2f291f9..98c986a 100644
91149--- a/net/can/gw.c
91150+++ b/net/can/gw.c
91151@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
91152 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
91153
91154 static HLIST_HEAD(cgw_list);
91155-static struct notifier_block notifier;
91156
91157 static struct kmem_cache *cgw_cache __read_mostly;
91158
91159@@ -927,6 +926,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
91160 return err;
91161 }
91162
91163+static struct notifier_block notifier = {
91164+ .notifier_call = cgw_notifier
91165+};
91166+
91167 static __init int cgw_module_init(void)
91168 {
91169 /* sanitize given module parameter */
91170@@ -942,7 +945,6 @@ static __init int cgw_module_init(void)
91171 return -ENOMEM;
91172
91173 /* set notifier */
91174- notifier.notifier_call = cgw_notifier;
91175 register_netdevice_notifier(&notifier);
91176
91177 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
91178diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
91179index eb0a46a..5f3bae8 100644
91180--- a/net/ceph/messenger.c
91181+++ b/net/ceph/messenger.c
91182@@ -186,7 +186,7 @@ static void con_fault(struct ceph_connection *con);
91183 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
91184
91185 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
91186-static atomic_t addr_str_seq = ATOMIC_INIT(0);
91187+static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
91188
91189 static struct page *zero_page; /* used in certain error cases */
91190
91191@@ -197,7 +197,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
91192 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
91193 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
91194
91195- i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
91196+ i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
91197 s = addr_str[i];
91198
91199 switch (ss->ss_family) {
91200diff --git a/net/compat.c b/net/compat.c
91201index 8903258..24e30e5 100644
91202--- a/net/compat.c
91203+++ b/net/compat.c
91204@@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
91205 return -EFAULT;
91206 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
91207 return -EINVAL;
91208- kmsg->msg_name = compat_ptr(tmp1);
91209- kmsg->msg_iov = compat_ptr(tmp2);
91210- kmsg->msg_control = compat_ptr(tmp3);
91211+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
91212+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
91213+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
91214 return 0;
91215 }
91216
91217@@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
91218
91219 if (kern_msg->msg_namelen) {
91220 if (mode == VERIFY_READ) {
91221- int err = move_addr_to_kernel(kern_msg->msg_name,
91222+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
91223 kern_msg->msg_namelen,
91224 kern_address);
91225 if (err < 0)
91226@@ -98,7 +98,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
91227 kern_msg->msg_name = NULL;
91228
91229 tot_len = iov_from_user_compat_to_kern(kern_iov,
91230- (struct compat_iovec __user *)kern_msg->msg_iov,
91231+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
91232 kern_msg->msg_iovlen);
91233 if (tot_len >= 0)
91234 kern_msg->msg_iov = kern_iov;
91235@@ -118,20 +118,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
91236
91237 #define CMSG_COMPAT_FIRSTHDR(msg) \
91238 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
91239- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
91240+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
91241 (struct compat_cmsghdr __user *)NULL)
91242
91243 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
91244 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
91245 (ucmlen) <= (unsigned long) \
91246 ((mhdr)->msg_controllen - \
91247- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
91248+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
91249
91250 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
91251 struct compat_cmsghdr __user *cmsg, int cmsg_len)
91252 {
91253 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
91254- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
91255+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
91256 msg->msg_controllen)
91257 return NULL;
91258 return (struct compat_cmsghdr __user *)ptr;
91259@@ -221,7 +221,7 @@ Efault:
91260
91261 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
91262 {
91263- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
91264+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
91265 struct compat_cmsghdr cmhdr;
91266 struct compat_timeval ctv;
91267 struct compat_timespec cts[3];
91268@@ -277,7 +277,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
91269
91270 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
91271 {
91272- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
91273+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
91274 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
91275 int fdnum = scm->fp->count;
91276 struct file **fp = scm->fp->fp;
91277@@ -365,7 +365,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
91278 return -EFAULT;
91279 old_fs = get_fs();
91280 set_fs(KERNEL_DS);
91281- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
91282+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
91283 set_fs(old_fs);
91284
91285 return err;
91286@@ -426,7 +426,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
91287 len = sizeof(ktime);
91288 old_fs = get_fs();
91289 set_fs(KERNEL_DS);
91290- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
91291+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
91292 set_fs(old_fs);
91293
91294 if (!err) {
91295@@ -569,7 +569,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
91296 case MCAST_JOIN_GROUP:
91297 case MCAST_LEAVE_GROUP:
91298 {
91299- struct compat_group_req __user *gr32 = (void *)optval;
91300+ struct compat_group_req __user *gr32 = (void __user *)optval;
91301 struct group_req __user *kgr =
91302 compat_alloc_user_space(sizeof(struct group_req));
91303 u32 interface;
91304@@ -590,7 +590,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
91305 case MCAST_BLOCK_SOURCE:
91306 case MCAST_UNBLOCK_SOURCE:
91307 {
91308- struct compat_group_source_req __user *gsr32 = (void *)optval;
91309+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
91310 struct group_source_req __user *kgsr = compat_alloc_user_space(
91311 sizeof(struct group_source_req));
91312 u32 interface;
91313@@ -611,7 +611,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
91314 }
91315 case MCAST_MSFILTER:
91316 {
91317- struct compat_group_filter __user *gf32 = (void *)optval;
91318+ struct compat_group_filter __user *gf32 = (void __user *)optval;
91319 struct group_filter __user *kgf;
91320 u32 interface, fmode, numsrc;
91321
91322@@ -649,7 +649,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
91323 char __user *optval, int __user *optlen,
91324 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
91325 {
91326- struct compat_group_filter __user *gf32 = (void *)optval;
91327+ struct compat_group_filter __user *gf32 = (void __user *)optval;
91328 struct group_filter __user *kgf;
91329 int __user *koptlen;
91330 u32 interface, fmode, numsrc;
91331@@ -807,7 +807,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
91332
91333 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
91334 return -EINVAL;
91335- if (copy_from_user(a, args, nas[call]))
91336+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
91337 return -EFAULT;
91338 a0 = a[0];
91339 a1 = a[1];
91340diff --git a/net/core/datagram.c b/net/core/datagram.c
91341index 8ab48cd..57b1a80 100644
91342--- a/net/core/datagram.c
91343+++ b/net/core/datagram.c
91344@@ -300,7 +300,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
91345 }
91346
91347 kfree_skb(skb);
91348- atomic_inc(&sk->sk_drops);
91349+ atomic_inc_unchecked(&sk->sk_drops);
91350 sk_mem_reclaim_partial(sk);
91351
91352 return err;
91353diff --git a/net/core/dev.c b/net/core/dev.c
91354index 26755dd..2a232de 100644
91355--- a/net/core/dev.c
91356+++ b/net/core/dev.c
91357@@ -1680,14 +1680,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
91358 {
91359 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
91360 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
91361- atomic_long_inc(&dev->rx_dropped);
91362+ atomic_long_inc_unchecked(&dev->rx_dropped);
91363 kfree_skb(skb);
91364 return NET_RX_DROP;
91365 }
91366 }
91367
91368 if (unlikely(!is_skb_forwardable(dev, skb))) {
91369- atomic_long_inc(&dev->rx_dropped);
91370+ atomic_long_inc_unchecked(&dev->rx_dropped);
91371 kfree_skb(skb);
91372 return NET_RX_DROP;
91373 }
91374@@ -2431,7 +2431,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
91375
91376 struct dev_gso_cb {
91377 void (*destructor)(struct sk_buff *skb);
91378-};
91379+} __no_const;
91380
91381 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
91382
91383@@ -3206,7 +3206,7 @@ enqueue:
91384
91385 local_irq_restore(flags);
91386
91387- atomic_long_inc(&skb->dev->rx_dropped);
91388+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
91389 kfree_skb(skb);
91390 return NET_RX_DROP;
91391 }
91392@@ -3278,7 +3278,7 @@ int netif_rx_ni(struct sk_buff *skb)
91393 }
91394 EXPORT_SYMBOL(netif_rx_ni);
91395
91396-static void net_tx_action(struct softirq_action *h)
91397+static __latent_entropy void net_tx_action(void)
91398 {
91399 struct softnet_data *sd = &__get_cpu_var(softnet_data);
91400
91401@@ -3612,7 +3612,7 @@ ncls:
91402 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
91403 } else {
91404 drop:
91405- atomic_long_inc(&skb->dev->rx_dropped);
91406+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
91407 kfree_skb(skb);
91408 /* Jamal, now you will not able to escape explaining
91409 * me how you were going to use this. :-)
91410@@ -4272,7 +4272,7 @@ void netif_napi_del(struct napi_struct *napi)
91411 }
91412 EXPORT_SYMBOL(netif_napi_del);
91413
91414-static void net_rx_action(struct softirq_action *h)
91415+static __latent_entropy void net_rx_action(void)
91416 {
91417 struct softnet_data *sd = &__get_cpu_var(softnet_data);
91418 unsigned long time_limit = jiffies + 2;
91419@@ -5730,7 +5730,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
91420 } else {
91421 netdev_stats_to_stats64(storage, &dev->stats);
91422 }
91423- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
91424+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
91425 return storage;
91426 }
91427 EXPORT_SYMBOL(dev_get_stats);
91428diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
91429index 5b7d0e1..cb960fc 100644
91430--- a/net/core/dev_ioctl.c
91431+++ b/net/core/dev_ioctl.c
91432@@ -365,9 +365,13 @@ void dev_load(struct net *net, const char *name)
91433 if (no_module && capable(CAP_NET_ADMIN))
91434 no_module = request_module("netdev-%s", name);
91435 if (no_module && capable(CAP_SYS_MODULE)) {
91436+#ifdef CONFIG_GRKERNSEC_MODHARDEN
91437+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
91438+#else
91439 if (!request_module("%s", name))
91440 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
91441 name);
91442+#endif
91443 }
91444 }
91445 EXPORT_SYMBOL(dev_load);
91446diff --git a/net/core/flow.c b/net/core/flow.c
91447index dfa602c..3103d88 100644
91448--- a/net/core/flow.c
91449+++ b/net/core/flow.c
91450@@ -61,7 +61,7 @@ struct flow_cache {
91451 struct timer_list rnd_timer;
91452 };
91453
91454-atomic_t flow_cache_genid = ATOMIC_INIT(0);
91455+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
91456 EXPORT_SYMBOL(flow_cache_genid);
91457 static struct flow_cache flow_cache_global;
91458 static struct kmem_cache *flow_cachep __read_mostly;
91459@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
91460
91461 static int flow_entry_valid(struct flow_cache_entry *fle)
91462 {
91463- if (atomic_read(&flow_cache_genid) != fle->genid)
91464+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
91465 return 0;
91466 if (fle->object && !fle->object->ops->check(fle->object))
91467 return 0;
91468@@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
91469 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
91470 fcp->hash_count++;
91471 }
91472- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
91473+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
91474 flo = fle->object;
91475 if (!flo)
91476 goto ret_object;
91477@@ -279,7 +279,7 @@ nocache:
91478 }
91479 flo = resolver(net, key, family, dir, flo, ctx);
91480 if (fle) {
91481- fle->genid = atomic_read(&flow_cache_genid);
91482+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
91483 if (!IS_ERR(flo))
91484 fle->object = flo;
91485 else
91486diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c
91487index 52d0f83..4a1d064 100644
91488--- a/net/core/flow_dissector.c
91489+++ b/net/core/flow_dissector.c
91490@@ -40,7 +40,7 @@ again:
91491 struct iphdr _iph;
91492 ip:
91493 iph = skb_header_pointer(skb, nhoff, sizeof(_iph), &_iph);
91494- if (!iph)
91495+ if (!iph || iph->ihl < 5)
91496 return false;
91497
91498 if (ip_is_fragment(iph))
91499diff --git a/net/core/iovec.c b/net/core/iovec.c
91500index de178e4..1dabd8b 100644
91501--- a/net/core/iovec.c
91502+++ b/net/core/iovec.c
91503@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
91504 if (m->msg_namelen) {
91505 if (mode == VERIFY_READ) {
91506 void __user *namep;
91507- namep = (void __user __force *) m->msg_name;
91508+ namep = (void __force_user *) m->msg_name;
91509 err = move_addr_to_kernel(namep, m->msg_namelen,
91510 address);
91511 if (err < 0)
91512@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
91513 }
91514
91515 size = m->msg_iovlen * sizeof(struct iovec);
91516- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
91517+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
91518 return -EFAULT;
91519
91520 m->msg_iov = iov;
91521diff --git a/net/core/neighbour.c b/net/core/neighbour.c
91522index 60533db..14842cc 100644
91523--- a/net/core/neighbour.c
91524+++ b/net/core/neighbour.c
91525@@ -2776,7 +2776,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
91526 void __user *buffer, size_t *lenp, loff_t *ppos)
91527 {
91528 int size, ret;
91529- struct ctl_table tmp = *ctl;
91530+ ctl_table_no_const tmp = *ctl;
91531
91532 tmp.extra1 = &zero;
91533 tmp.extra2 = &unres_qlen_max;
91534diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
91535index 2bf8329..7960607 100644
91536--- a/net/core/net-procfs.c
91537+++ b/net/core/net-procfs.c
91538@@ -283,8 +283,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
91539 else
91540 seq_printf(seq, "%04x", ntohs(pt->type));
91541
91542+#ifdef CONFIG_GRKERNSEC_HIDESYM
91543+ seq_printf(seq, " %-8s %pf\n",
91544+ pt->dev ? pt->dev->name : "", NULL);
91545+#else
91546 seq_printf(seq, " %-8s %pf\n",
91547 pt->dev ? pt->dev->name : "", pt->func);
91548+#endif
91549 }
91550
91551 return 0;
91552diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
91553index 981fed3..536af34 100644
91554--- a/net/core/net-sysfs.c
91555+++ b/net/core/net-sysfs.c
91556@@ -1311,7 +1311,7 @@ void netdev_class_remove_file(struct class_attribute *class_attr)
91557 }
91558 EXPORT_SYMBOL(netdev_class_remove_file);
91559
91560-int netdev_kobject_init(void)
91561+int __init netdev_kobject_init(void)
91562 {
91563 kobj_ns_type_register(&net_ns_type_operations);
91564 return class_register(&net_class);
91565diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
91566index f9765203..9feaef8 100644
91567--- a/net/core/net_namespace.c
91568+++ b/net/core/net_namespace.c
91569@@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
91570 int error;
91571 LIST_HEAD(net_exit_list);
91572
91573- list_add_tail(&ops->list, list);
91574+ pax_list_add_tail((struct list_head *)&ops->list, list);
91575 if (ops->init || (ops->id && ops->size)) {
91576 for_each_net(net) {
91577 error = ops_init(ops, net);
91578@@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
91579
91580 out_undo:
91581 /* If I have an error cleanup all namespaces I initialized */
91582- list_del(&ops->list);
91583+ pax_list_del((struct list_head *)&ops->list);
91584 ops_exit_list(ops, &net_exit_list);
91585 ops_free_list(ops, &net_exit_list);
91586 return error;
91587@@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
91588 struct net *net;
91589 LIST_HEAD(net_exit_list);
91590
91591- list_del(&ops->list);
91592+ pax_list_del((struct list_head *)&ops->list);
91593 for_each_net(net)
91594 list_add_tail(&net->exit_list, &net_exit_list);
91595 ops_exit_list(ops, &net_exit_list);
91596@@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
91597 mutex_lock(&net_mutex);
91598 error = register_pernet_operations(&pernet_list, ops);
91599 if (!error && (first_device == &pernet_list))
91600- first_device = &ops->list;
91601+ first_device = (struct list_head *)&ops->list;
91602 mutex_unlock(&net_mutex);
91603 return error;
91604 }
91605diff --git a/net/core/netpoll.c b/net/core/netpoll.c
91606index fc75c9e..8c8e9be 100644
91607--- a/net/core/netpoll.c
91608+++ b/net/core/netpoll.c
91609@@ -428,7 +428,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
91610 struct udphdr *udph;
91611 struct iphdr *iph;
91612 struct ethhdr *eth;
91613- static atomic_t ip_ident;
91614+ static atomic_unchecked_t ip_ident;
91615 struct ipv6hdr *ip6h;
91616
91617 udp_len = len + sizeof(*udph);
91618@@ -499,7 +499,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
91619 put_unaligned(0x45, (unsigned char *)iph);
91620 iph->tos = 0;
91621 put_unaligned(htons(ip_len), &(iph->tot_len));
91622- iph->id = htons(atomic_inc_return(&ip_ident));
91623+ iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
91624 iph->frag_off = 0;
91625 iph->ttl = 64;
91626 iph->protocol = IPPROTO_UDP;
91627diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
91628index ca198c1d1..125372f 100644
91629--- a/net/core/rtnetlink.c
91630+++ b/net/core/rtnetlink.c
91631@@ -58,7 +58,7 @@ struct rtnl_link {
91632 rtnl_doit_func doit;
91633 rtnl_dumpit_func dumpit;
91634 rtnl_calcit_func calcit;
91635-};
91636+} __no_const;
91637
91638 static DEFINE_MUTEX(rtnl_mutex);
91639
91640@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
91641 if (rtnl_link_ops_get(ops->kind))
91642 return -EEXIST;
91643
91644- if (!ops->dellink)
91645- ops->dellink = unregister_netdevice_queue;
91646+ if (!ops->dellink) {
91647+ pax_open_kernel();
91648+ *(void **)&ops->dellink = unregister_netdevice_queue;
91649+ pax_close_kernel();
91650+ }
91651
91652- list_add_tail(&ops->list, &link_ops);
91653+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
91654 return 0;
91655 }
91656 EXPORT_SYMBOL_GPL(__rtnl_link_register);
91657@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
91658 for_each_net(net) {
91659 __rtnl_kill_links(net, ops);
91660 }
91661- list_del(&ops->list);
91662+ pax_list_del((struct list_head *)&ops->list);
91663 }
91664 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
91665
91666diff --git a/net/core/scm.c b/net/core/scm.c
91667index b4da80b..98d6bdb 100644
91668--- a/net/core/scm.c
91669+++ b/net/core/scm.c
91670@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
91671 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
91672 {
91673 struct cmsghdr __user *cm
91674- = (__force struct cmsghdr __user *)msg->msg_control;
91675+ = (struct cmsghdr __force_user *)msg->msg_control;
91676 struct cmsghdr cmhdr;
91677 int cmlen = CMSG_LEN(len);
91678 int err;
91679@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
91680 err = -EFAULT;
91681 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
91682 goto out;
91683- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
91684+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
91685 goto out;
91686 cmlen = CMSG_SPACE(len);
91687 if (msg->msg_controllen < cmlen)
91688@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
91689 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
91690 {
91691 struct cmsghdr __user *cm
91692- = (__force struct cmsghdr __user*)msg->msg_control;
91693+ = (struct cmsghdr __force_user *)msg->msg_control;
91694
91695 int fdmax = 0;
91696 int fdnum = scm->fp->count;
91697@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
91698 if (fdnum < fdmax)
91699 fdmax = fdnum;
91700
91701- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
91702+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
91703 i++, cmfptr++)
91704 {
91705 struct socket *sock;
91706diff --git a/net/core/skbuff.c b/net/core/skbuff.c
91707index 2c3d0f5..f5a326f 100644
91708--- a/net/core/skbuff.c
91709+++ b/net/core/skbuff.c
91710@@ -3082,13 +3082,15 @@ void __init skb_init(void)
91711 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
91712 sizeof(struct sk_buff),
91713 0,
91714- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
91715+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
91716+ SLAB_NO_SANITIZE,
91717 NULL);
91718 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
91719 (2*sizeof(struct sk_buff)) +
91720 sizeof(atomic_t),
91721 0,
91722- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
91723+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
91724+ SLAB_NO_SANITIZE,
91725 NULL);
91726 }
91727
91728diff --git a/net/core/sock.c b/net/core/sock.c
91729index 8729d91..4a20427 100644
91730--- a/net/core/sock.c
91731+++ b/net/core/sock.c
91732@@ -392,7 +392,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
91733 struct sk_buff_head *list = &sk->sk_receive_queue;
91734
91735 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
91736- atomic_inc(&sk->sk_drops);
91737+ atomic_inc_unchecked(&sk->sk_drops);
91738 trace_sock_rcvqueue_full(sk, skb);
91739 return -ENOMEM;
91740 }
91741@@ -402,7 +402,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
91742 return err;
91743
91744 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
91745- atomic_inc(&sk->sk_drops);
91746+ atomic_inc_unchecked(&sk->sk_drops);
91747 return -ENOBUFS;
91748 }
91749
91750@@ -422,7 +422,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
91751 skb_dst_force(skb);
91752
91753 spin_lock_irqsave(&list->lock, flags);
91754- skb->dropcount = atomic_read(&sk->sk_drops);
91755+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
91756 __skb_queue_tail(list, skb);
91757 spin_unlock_irqrestore(&list->lock, flags);
91758
91759@@ -442,7 +442,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
91760 skb->dev = NULL;
91761
91762 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
91763- atomic_inc(&sk->sk_drops);
91764+ atomic_inc_unchecked(&sk->sk_drops);
91765 goto discard_and_relse;
91766 }
91767 if (nested)
91768@@ -460,7 +460,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
91769 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
91770 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
91771 bh_unlock_sock(sk);
91772- atomic_inc(&sk->sk_drops);
91773+ atomic_inc_unchecked(&sk->sk_drops);
91774 goto discard_and_relse;
91775 }
91776
91777@@ -948,12 +948,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
91778 struct timeval tm;
91779 } v;
91780
91781- int lv = sizeof(int);
91782- int len;
91783+ unsigned int lv = sizeof(int);
91784+ unsigned int len;
91785
91786 if (get_user(len, optlen))
91787 return -EFAULT;
91788- if (len < 0)
91789+ if (len > INT_MAX)
91790 return -EINVAL;
91791
91792 memset(&v, 0, sizeof(v));
91793@@ -1105,11 +1105,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
91794
91795 case SO_PEERNAME:
91796 {
91797- char address[128];
91798+ char address[_K_SS_MAXSIZE];
91799
91800 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
91801 return -ENOTCONN;
91802- if (lv < len)
91803+ if (lv < len || sizeof address < len)
91804 return -EINVAL;
91805 if (copy_to_user(optval, address, len))
91806 return -EFAULT;
91807@@ -1182,7 +1182,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
91808
91809 if (len > lv)
91810 len = lv;
91811- if (copy_to_user(optval, &v, len))
91812+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
91813 return -EFAULT;
91814 lenout:
91815 if (put_user(len, optlen))
91816@@ -2304,7 +2304,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
91817 */
91818 smp_wmb();
91819 atomic_set(&sk->sk_refcnt, 1);
91820- atomic_set(&sk->sk_drops, 0);
91821+ atomic_set_unchecked(&sk->sk_drops, 0);
91822 }
91823 EXPORT_SYMBOL(sock_init_data);
91824
91825diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
91826index a0e9cf6..ef7f9ed 100644
91827--- a/net/core/sock_diag.c
91828+++ b/net/core/sock_diag.c
91829@@ -9,26 +9,33 @@
91830 #include <linux/inet_diag.h>
91831 #include <linux/sock_diag.h>
91832
91833-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
91834+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
91835 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
91836 static DEFINE_MUTEX(sock_diag_table_mutex);
91837
91838 int sock_diag_check_cookie(void *sk, __u32 *cookie)
91839 {
91840+#ifndef CONFIG_GRKERNSEC_HIDESYM
91841 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
91842 cookie[1] != INET_DIAG_NOCOOKIE) &&
91843 ((u32)(unsigned long)sk != cookie[0] ||
91844 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
91845 return -ESTALE;
91846 else
91847+#endif
91848 return 0;
91849 }
91850 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
91851
91852 void sock_diag_save_cookie(void *sk, __u32 *cookie)
91853 {
91854+#ifdef CONFIG_GRKERNSEC_HIDESYM
91855+ cookie[0] = 0;
91856+ cookie[1] = 0;
91857+#else
91858 cookie[0] = (u32)(unsigned long)sk;
91859 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
91860+#endif
91861 }
91862 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
91863
91864@@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
91865 mutex_lock(&sock_diag_table_mutex);
91866 if (sock_diag_handlers[hndl->family])
91867 err = -EBUSY;
91868- else
91869+ else {
91870+ pax_open_kernel();
91871 sock_diag_handlers[hndl->family] = hndl;
91872+ pax_close_kernel();
91873+ }
91874 mutex_unlock(&sock_diag_table_mutex);
91875
91876 return err;
91877@@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
91878
91879 mutex_lock(&sock_diag_table_mutex);
91880 BUG_ON(sock_diag_handlers[family] != hnld);
91881+ pax_open_kernel();
91882 sock_diag_handlers[family] = NULL;
91883+ pax_close_kernel();
91884 mutex_unlock(&sock_diag_table_mutex);
91885 }
91886 EXPORT_SYMBOL_GPL(sock_diag_unregister);
91887diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
91888index 31107ab..ae03d5a 100644
91889--- a/net/core/sysctl_net_core.c
91890+++ b/net/core/sysctl_net_core.c
91891@@ -31,7 +31,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
91892 {
91893 unsigned int orig_size, size;
91894 int ret, i;
91895- struct ctl_table tmp = {
91896+ ctl_table_no_const tmp = {
91897 .data = &size,
91898 .maxlen = sizeof(size),
91899 .mode = table->mode
91900@@ -350,13 +350,12 @@ static struct ctl_table netns_core_table[] = {
91901
91902 static __net_init int sysctl_core_net_init(struct net *net)
91903 {
91904- struct ctl_table *tbl;
91905+ ctl_table_no_const *tbl = NULL;
91906
91907 net->core.sysctl_somaxconn = SOMAXCONN;
91908
91909- tbl = netns_core_table;
91910 if (!net_eq(net, &init_net)) {
91911- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
91912+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
91913 if (tbl == NULL)
91914 goto err_dup;
91915
91916@@ -366,17 +365,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
91917 if (net->user_ns != &init_user_ns) {
91918 tbl[0].procname = NULL;
91919 }
91920- }
91921-
91922- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
91923+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
91924+ } else
91925+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
91926 if (net->core.sysctl_hdr == NULL)
91927 goto err_reg;
91928
91929 return 0;
91930
91931 err_reg:
91932- if (tbl != netns_core_table)
91933- kfree(tbl);
91934+ kfree(tbl);
91935 err_dup:
91936 return -ENOMEM;
91937 }
91938@@ -391,7 +389,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
91939 kfree(tbl);
91940 }
91941
91942-static __net_initdata struct pernet_operations sysctl_core_ops = {
91943+static __net_initconst struct pernet_operations sysctl_core_ops = {
91944 .init = sysctl_core_net_init,
91945 .exit = sysctl_core_net_exit,
91946 };
91947diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
91948index dd4d506..fb2fb87 100644
91949--- a/net/decnet/af_decnet.c
91950+++ b/net/decnet/af_decnet.c
91951@@ -465,6 +465,7 @@ static struct proto dn_proto = {
91952 .sysctl_rmem = sysctl_decnet_rmem,
91953 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
91954 .obj_size = sizeof(struct dn_sock),
91955+ .slab_flags = SLAB_USERCOPY,
91956 };
91957
91958 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
91959diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
91960index 5325b54..a0d4d69 100644
91961--- a/net/decnet/sysctl_net_decnet.c
91962+++ b/net/decnet/sysctl_net_decnet.c
91963@@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
91964
91965 if (len > *lenp) len = *lenp;
91966
91967- if (copy_to_user(buffer, addr, len))
91968+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
91969 return -EFAULT;
91970
91971 *lenp = len;
91972@@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
91973
91974 if (len > *lenp) len = *lenp;
91975
91976- if (copy_to_user(buffer, devname, len))
91977+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
91978 return -EFAULT;
91979
91980 *lenp = len;
91981diff --git a/net/ieee802154/6lowpan.c b/net/ieee802154/6lowpan.c
91982index 3b9d5f2..d7015c6 100644
91983--- a/net/ieee802154/6lowpan.c
91984+++ b/net/ieee802154/6lowpan.c
91985@@ -459,7 +459,7 @@ static int lowpan_header_create(struct sk_buff *skb,
91986 hc06_ptr += 3;
91987 } else {
91988 /* compress nothing */
91989- memcpy(hc06_ptr, &hdr, 4);
91990+ memcpy(hc06_ptr, hdr, 4);
91991 /* replace the top byte with new ECN | DSCP format */
91992 *hc06_ptr = tmp;
91993 hc06_ptr += 4;
91994diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
91995index dd6b523..dfe558f 100644
91996--- a/net/ipv4/af_inet.c
91997+++ b/net/ipv4/af_inet.c
91998@@ -1687,13 +1687,9 @@ static int __init inet_init(void)
91999
92000 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
92001
92002- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
92003- if (!sysctl_local_reserved_ports)
92004- goto out;
92005-
92006 rc = proto_register(&tcp_prot, 1);
92007 if (rc)
92008- goto out_free_reserved_ports;
92009+ goto out;
92010
92011 rc = proto_register(&udp_prot, 1);
92012 if (rc)
92013@@ -1802,8 +1798,6 @@ out_unregister_udp_proto:
92014 proto_unregister(&udp_prot);
92015 out_unregister_tcp_proto:
92016 proto_unregister(&tcp_prot);
92017-out_free_reserved_ports:
92018- kfree(sysctl_local_reserved_ports);
92019 goto out;
92020 }
92021
92022diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
92023index 34ca6d5..b6421e8 100644
92024--- a/net/ipv4/devinet.c
92025+++ b/net/ipv4/devinet.c
92026@@ -1532,7 +1532,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
92027 idx = 0;
92028 head = &net->dev_index_head[h];
92029 rcu_read_lock();
92030- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
92031+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
92032 net->dev_base_seq;
92033 hlist_for_each_entry_rcu(dev, head, index_hlist) {
92034 if (idx < s_idx)
92035@@ -1843,7 +1843,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
92036 idx = 0;
92037 head = &net->dev_index_head[h];
92038 rcu_read_lock();
92039- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
92040+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
92041 net->dev_base_seq;
92042 hlist_for_each_entry_rcu(dev, head, index_hlist) {
92043 if (idx < s_idx)
92044@@ -2068,7 +2068,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
92045 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
92046 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
92047
92048-static struct devinet_sysctl_table {
92049+static const struct devinet_sysctl_table {
92050 struct ctl_table_header *sysctl_header;
92051 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
92052 } devinet_sysctl = {
92053@@ -2186,7 +2186,7 @@ static __net_init int devinet_init_net(struct net *net)
92054 int err;
92055 struct ipv4_devconf *all, *dflt;
92056 #ifdef CONFIG_SYSCTL
92057- struct ctl_table *tbl = ctl_forward_entry;
92058+ ctl_table_no_const *tbl = NULL;
92059 struct ctl_table_header *forw_hdr;
92060 #endif
92061
92062@@ -2204,7 +2204,7 @@ static __net_init int devinet_init_net(struct net *net)
92063 goto err_alloc_dflt;
92064
92065 #ifdef CONFIG_SYSCTL
92066- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
92067+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
92068 if (tbl == NULL)
92069 goto err_alloc_ctl;
92070
92071@@ -2224,7 +2224,10 @@ static __net_init int devinet_init_net(struct net *net)
92072 goto err_reg_dflt;
92073
92074 err = -ENOMEM;
92075- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
92076+ if (!net_eq(net, &init_net))
92077+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
92078+ else
92079+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
92080 if (forw_hdr == NULL)
92081 goto err_reg_ctl;
92082 net->ipv4.forw_hdr = forw_hdr;
92083@@ -2240,8 +2243,7 @@ err_reg_ctl:
92084 err_reg_dflt:
92085 __devinet_sysctl_unregister(all);
92086 err_reg_all:
92087- if (tbl != ctl_forward_entry)
92088- kfree(tbl);
92089+ kfree(tbl);
92090 err_alloc_ctl:
92091 #endif
92092 if (dflt != &ipv4_devconf_dflt)
92093diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
92094index b3f627a..b0f3e99 100644
92095--- a/net/ipv4/fib_frontend.c
92096+++ b/net/ipv4/fib_frontend.c
92097@@ -1017,12 +1017,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
92098 #ifdef CONFIG_IP_ROUTE_MULTIPATH
92099 fib_sync_up(dev);
92100 #endif
92101- atomic_inc(&net->ipv4.dev_addr_genid);
92102+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
92103 rt_cache_flush(dev_net(dev));
92104 break;
92105 case NETDEV_DOWN:
92106 fib_del_ifaddr(ifa, NULL);
92107- atomic_inc(&net->ipv4.dev_addr_genid);
92108+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
92109 if (ifa->ifa_dev->ifa_list == NULL) {
92110 /* Last address was deleted from this interface.
92111 * Disable IP.
92112@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
92113 #ifdef CONFIG_IP_ROUTE_MULTIPATH
92114 fib_sync_up(dev);
92115 #endif
92116- atomic_inc(&net->ipv4.dev_addr_genid);
92117+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
92118 rt_cache_flush(net);
92119 break;
92120 case NETDEV_DOWN:
92121diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
92122index d5dbca5..6251d5f 100644
92123--- a/net/ipv4/fib_semantics.c
92124+++ b/net/ipv4/fib_semantics.c
92125@@ -766,7 +766,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
92126 nh->nh_saddr = inet_select_addr(nh->nh_dev,
92127 nh->nh_gw,
92128 nh->nh_parent->fib_scope);
92129- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
92130+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
92131
92132 return nh->nh_saddr;
92133 }
92134diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
92135index 6acb541..9ea617d 100644
92136--- a/net/ipv4/inet_connection_sock.c
92137+++ b/net/ipv4/inet_connection_sock.c
92138@@ -37,7 +37,7 @@ struct local_ports sysctl_local_ports __read_mostly = {
92139 .range = { 32768, 61000 },
92140 };
92141
92142-unsigned long *sysctl_local_reserved_ports;
92143+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
92144 EXPORT_SYMBOL(sysctl_local_reserved_ports);
92145
92146 void inet_get_local_port_range(int *low, int *high)
92147diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
92148index 96da9c7..b956690 100644
92149--- a/net/ipv4/inet_hashtables.c
92150+++ b/net/ipv4/inet_hashtables.c
92151@@ -18,12 +18,15 @@
92152 #include <linux/sched.h>
92153 #include <linux/slab.h>
92154 #include <linux/wait.h>
92155+#include <linux/security.h>
92156
92157 #include <net/inet_connection_sock.h>
92158 #include <net/inet_hashtables.h>
92159 #include <net/secure_seq.h>
92160 #include <net/ip.h>
92161
92162+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
92163+
92164 /*
92165 * Allocate and initialize a new local port bind bucket.
92166 * The bindhash mutex for snum's hash chain must be held here.
92167@@ -554,6 +557,8 @@ ok:
92168 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
92169 spin_unlock(&head->lock);
92170
92171+ gr_update_task_in_ip_table(current, inet_sk(sk));
92172+
92173 if (tw) {
92174 inet_twsk_deschedule(tw, death_row);
92175 while (twrefcnt) {
92176diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
92177index 33d5537..da337a4 100644
92178--- a/net/ipv4/inetpeer.c
92179+++ b/net/ipv4/inetpeer.c
92180@@ -503,8 +503,8 @@ relookup:
92181 if (p) {
92182 p->daddr = *daddr;
92183 atomic_set(&p->refcnt, 1);
92184- atomic_set(&p->rid, 0);
92185- atomic_set(&p->ip_id_count,
92186+ atomic_set_unchecked(&p->rid, 0);
92187+ atomic_set_unchecked(&p->ip_id_count,
92188 (daddr->family == AF_INET) ?
92189 secure_ip_id(daddr->addr.a4) :
92190 secure_ipv6_id(daddr->addr.a6));
92191diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
92192index b66910a..cfe416e 100644
92193--- a/net/ipv4/ip_fragment.c
92194+++ b/net/ipv4/ip_fragment.c
92195@@ -282,7 +282,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
92196 return 0;
92197
92198 start = qp->rid;
92199- end = atomic_inc_return(&peer->rid);
92200+ end = atomic_inc_return_unchecked(&peer->rid);
92201 qp->rid = end;
92202
92203 rc = qp->q.fragments && (end - start) > max;
92204@@ -759,12 +759,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
92205
92206 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
92207 {
92208- struct ctl_table *table;
92209+ ctl_table_no_const *table = NULL;
92210 struct ctl_table_header *hdr;
92211
92212- table = ip4_frags_ns_ctl_table;
92213 if (!net_eq(net, &init_net)) {
92214- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
92215+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
92216 if (table == NULL)
92217 goto err_alloc;
92218
92219@@ -775,9 +774,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
92220 /* Don't export sysctls to unprivileged users */
92221 if (net->user_ns != &init_user_ns)
92222 table[0].procname = NULL;
92223- }
92224+ hdr = register_net_sysctl(net, "net/ipv4", table);
92225+ } else
92226+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
92227
92228- hdr = register_net_sysctl(net, "net/ipv4", table);
92229 if (hdr == NULL)
92230 goto err_reg;
92231
92232@@ -785,8 +785,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
92233 return 0;
92234
92235 err_reg:
92236- if (!net_eq(net, &init_net))
92237- kfree(table);
92238+ kfree(table);
92239 err_alloc:
92240 return -ENOMEM;
92241 }
92242diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
92243index 8d6939e..19d0a95 100644
92244--- a/net/ipv4/ip_gre.c
92245+++ b/net/ipv4/ip_gre.c
92246@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
92247 module_param(log_ecn_error, bool, 0644);
92248 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
92249
92250-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
92251+static struct rtnl_link_ops ipgre_link_ops;
92252 static int ipgre_tunnel_init(struct net_device *dev);
92253
92254 static int ipgre_net_id __read_mostly;
92255@@ -731,7 +731,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
92256 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
92257 };
92258
92259-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
92260+static struct rtnl_link_ops ipgre_link_ops = {
92261 .kind = "gre",
92262 .maxtype = IFLA_GRE_MAX,
92263 .policy = ipgre_policy,
92264@@ -745,7 +745,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
92265 .fill_info = ipgre_fill_info,
92266 };
92267
92268-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
92269+static struct rtnl_link_ops ipgre_tap_ops = {
92270 .kind = "gretap",
92271 .maxtype = IFLA_GRE_MAX,
92272 .policy = ipgre_policy,
92273diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
92274index d9c4f11..02b82dbc 100644
92275--- a/net/ipv4/ip_sockglue.c
92276+++ b/net/ipv4/ip_sockglue.c
92277@@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
92278 len = min_t(unsigned int, len, opt->optlen);
92279 if (put_user(len, optlen))
92280 return -EFAULT;
92281- if (copy_to_user(optval, opt->__data, len))
92282+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
92283+ copy_to_user(optval, opt->__data, len))
92284 return -EFAULT;
92285 return 0;
92286 }
92287@@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
92288 if (sk->sk_type != SOCK_STREAM)
92289 return -ENOPROTOOPT;
92290
92291- msg.msg_control = optval;
92292+ msg.msg_control = (void __force_kernel *)optval;
92293 msg.msg_controllen = len;
92294 msg.msg_flags = flags;
92295
92296diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
92297index 0656041..d6ecb60 100644
92298--- a/net/ipv4/ip_vti.c
92299+++ b/net/ipv4/ip_vti.c
92300@@ -47,7 +47,7 @@
92301 #define HASH_SIZE 16
92302 #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&(HASH_SIZE-1))
92303
92304-static struct rtnl_link_ops vti_link_ops __read_mostly;
92305+static struct rtnl_link_ops vti_link_ops;
92306
92307 static int vti_net_id __read_mostly;
92308 struct vti_net {
92309@@ -848,7 +848,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
92310 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
92311 };
92312
92313-static struct rtnl_link_ops vti_link_ops __read_mostly = {
92314+static struct rtnl_link_ops vti_link_ops = {
92315 .kind = "vti",
92316 .maxtype = IFLA_VTI_MAX,
92317 .policy = vti_policy,
92318diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
92319index efa1138..20dbba0 100644
92320--- a/net/ipv4/ipconfig.c
92321+++ b/net/ipv4/ipconfig.c
92322@@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
92323
92324 mm_segment_t oldfs = get_fs();
92325 set_fs(get_ds());
92326- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
92327+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
92328 set_fs(oldfs);
92329 return res;
92330 }
92331@@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
92332
92333 mm_segment_t oldfs = get_fs();
92334 set_fs(get_ds());
92335- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
92336+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
92337 set_fs(oldfs);
92338 return res;
92339 }
92340@@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
92341
92342 mm_segment_t oldfs = get_fs();
92343 set_fs(get_ds());
92344- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
92345+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
92346 set_fs(oldfs);
92347 return res;
92348 }
92349diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
92350index b3ac3c3..ec6bd95 100644
92351--- a/net/ipv4/ipip.c
92352+++ b/net/ipv4/ipip.c
92353@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
92354 static int ipip_net_id __read_mostly;
92355
92356 static int ipip_tunnel_init(struct net_device *dev);
92357-static struct rtnl_link_ops ipip_link_ops __read_mostly;
92358+static struct rtnl_link_ops ipip_link_ops;
92359
92360 static int ipip_err(struct sk_buff *skb, u32 info)
92361 {
92362@@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
92363 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
92364 };
92365
92366-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
92367+static struct rtnl_link_ops ipip_link_ops = {
92368 .kind = "ipip",
92369 .maxtype = IFLA_IPTUN_MAX,
92370 .policy = ipip_policy,
92371diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
92372index 85a4f21..1beb1f5 100644
92373--- a/net/ipv4/netfilter/arp_tables.c
92374+++ b/net/ipv4/netfilter/arp_tables.c
92375@@ -880,14 +880,14 @@ static int compat_table_info(const struct xt_table_info *info,
92376 #endif
92377
92378 static int get_info(struct net *net, void __user *user,
92379- const int *len, int compat)
92380+ int len, int compat)
92381 {
92382 char name[XT_TABLE_MAXNAMELEN];
92383 struct xt_table *t;
92384 int ret;
92385
92386- if (*len != sizeof(struct arpt_getinfo)) {
92387- duprintf("length %u != %Zu\n", *len,
92388+ if (len != sizeof(struct arpt_getinfo)) {
92389+ duprintf("length %u != %Zu\n", len,
92390 sizeof(struct arpt_getinfo));
92391 return -EINVAL;
92392 }
92393@@ -924,7 +924,7 @@ static int get_info(struct net *net, void __user *user,
92394 info.size = private->size;
92395 strcpy(info.name, name);
92396
92397- if (copy_to_user(user, &info, *len) != 0)
92398+ if (copy_to_user(user, &info, len) != 0)
92399 ret = -EFAULT;
92400 else
92401 ret = 0;
92402@@ -1683,7 +1683,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
92403
92404 switch (cmd) {
92405 case ARPT_SO_GET_INFO:
92406- ret = get_info(sock_net(sk), user, len, 1);
92407+ ret = get_info(sock_net(sk), user, *len, 1);
92408 break;
92409 case ARPT_SO_GET_ENTRIES:
92410 ret = compat_get_entries(sock_net(sk), user, len);
92411@@ -1728,7 +1728,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
92412
92413 switch (cmd) {
92414 case ARPT_SO_GET_INFO:
92415- ret = get_info(sock_net(sk), user, len, 0);
92416+ ret = get_info(sock_net(sk), user, *len, 0);
92417 break;
92418
92419 case ARPT_SO_GET_ENTRIES:
92420diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
92421index d23118d..6ad7277 100644
92422--- a/net/ipv4/netfilter/ip_tables.c
92423+++ b/net/ipv4/netfilter/ip_tables.c
92424@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
92425 #endif
92426
92427 static int get_info(struct net *net, void __user *user,
92428- const int *len, int compat)
92429+ int len, int compat)
92430 {
92431 char name[XT_TABLE_MAXNAMELEN];
92432 struct xt_table *t;
92433 int ret;
92434
92435- if (*len != sizeof(struct ipt_getinfo)) {
92436- duprintf("length %u != %zu\n", *len,
92437+ if (len != sizeof(struct ipt_getinfo)) {
92438+ duprintf("length %u != %zu\n", len,
92439 sizeof(struct ipt_getinfo));
92440 return -EINVAL;
92441 }
92442@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
92443 info.size = private->size;
92444 strcpy(info.name, name);
92445
92446- if (copy_to_user(user, &info, *len) != 0)
92447+ if (copy_to_user(user, &info, len) != 0)
92448 ret = -EFAULT;
92449 else
92450 ret = 0;
92451@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
92452
92453 switch (cmd) {
92454 case IPT_SO_GET_INFO:
92455- ret = get_info(sock_net(sk), user, len, 1);
92456+ ret = get_info(sock_net(sk), user, *len, 1);
92457 break;
92458 case IPT_SO_GET_ENTRIES:
92459 ret = compat_get_entries(sock_net(sk), user, len);
92460@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
92461
92462 switch (cmd) {
92463 case IPT_SO_GET_INFO:
92464- ret = get_info(sock_net(sk), user, len, 0);
92465+ ret = get_info(sock_net(sk), user, *len, 0);
92466 break;
92467
92468 case IPT_SO_GET_ENTRIES:
92469diff --git a/net/ipv4/netfilter/ipt_ULOG.c b/net/ipv4/netfilter/ipt_ULOG.c
92470index cbc2215..9cb993c 100644
92471--- a/net/ipv4/netfilter/ipt_ULOG.c
92472+++ b/net/ipv4/netfilter/ipt_ULOG.c
92473@@ -220,6 +220,7 @@ static void ipt_ulog_packet(struct net *net,
92474 ub->qlen++;
92475
92476 pm = nlmsg_data(nlh);
92477+ memset(pm, 0, sizeof(*pm));
92478
92479 /* We might not have a timestamp, get one */
92480 if (skb->tstamp.tv64 == 0)
92481@@ -238,8 +239,6 @@ static void ipt_ulog_packet(struct net *net,
92482 }
92483 else if (loginfo->prefix[0] != '\0')
92484 strncpy(pm->prefix, loginfo->prefix, sizeof(pm->prefix));
92485- else
92486- *(pm->prefix) = '\0';
92487
92488 if (in && in->hard_header_len > 0 &&
92489 skb->mac_header != skb->network_header &&
92490@@ -251,13 +250,9 @@ static void ipt_ulog_packet(struct net *net,
92491
92492 if (in)
92493 strncpy(pm->indev_name, in->name, sizeof(pm->indev_name));
92494- else
92495- pm->indev_name[0] = '\0';
92496
92497 if (out)
92498 strncpy(pm->outdev_name, out->name, sizeof(pm->outdev_name));
92499- else
92500- pm->outdev_name[0] = '\0';
92501
92502 /* copy_len <= skb->len, so can't fail. */
92503 if (skb_copy_bits(skb, 0, pm->payload, copy_len) < 0)
92504diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
92505index 746427c..80eab72 100644
92506--- a/net/ipv4/ping.c
92507+++ b/net/ipv4/ping.c
92508@@ -55,7 +55,7 @@
92509
92510
92511 struct ping_table ping_table;
92512-struct pingv6_ops pingv6_ops;
92513+struct pingv6_ops *pingv6_ops;
92514 EXPORT_SYMBOL_GPL(pingv6_ops);
92515
92516 static u16 ping_port_rover;
92517@@ -335,7 +335,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
92518 return -ENODEV;
92519 }
92520 }
92521- has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
92522+ has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
92523 scoped);
92524 rcu_read_unlock();
92525
92526@@ -541,7 +541,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
92527 }
92528 #if IS_ENABLED(CONFIG_IPV6)
92529 } else if (skb->protocol == htons(ETH_P_IPV6)) {
92530- harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
92531+ harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
92532 #endif
92533 }
92534
92535@@ -559,7 +559,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
92536 info, (u8 *)icmph);
92537 #if IS_ENABLED(CONFIG_IPV6)
92538 } else if (family == AF_INET6) {
92539- pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
92540+ pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
92541 info, (u8 *)icmph);
92542 #endif
92543 }
92544@@ -850,7 +850,7 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
92545 return ip_recv_error(sk, msg, len);
92546 #if IS_ENABLED(CONFIG_IPV6)
92547 } else if (family == AF_INET6) {
92548- return pingv6_ops.ipv6_recv_error(sk, msg, len);
92549+ return pingv6_ops->ipv6_recv_error(sk, msg, len);
92550 #endif
92551 }
92552 }
92553@@ -900,7 +900,7 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
92554 IP6CB(skb)->iif);
92555
92556 if (inet6_sk(sk)->rxopt.all)
92557- pingv6_ops.ip6_datagram_recv_ctl(sk, msg, skb);
92558+ pingv6_ops->ip6_datagram_recv_ctl(sk, msg, skb);
92559 #endif
92560 } else {
92561 BUG();
92562@@ -1090,7 +1090,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
92563 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
92564 0, sock_i_ino(sp),
92565 atomic_read(&sp->sk_refcnt), sp,
92566- atomic_read(&sp->sk_drops), len);
92567+ atomic_read_unchecked(&sp->sk_drops), len);
92568 }
92569
92570 static int ping_v4_seq_show(struct seq_file *seq, void *v)
92571diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
92572index 6fb2337..9cd6b20 100644
92573--- a/net/ipv4/raw.c
92574+++ b/net/ipv4/raw.c
92575@@ -309,7 +309,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
92576 int raw_rcv(struct sock *sk, struct sk_buff *skb)
92577 {
92578 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
92579- atomic_inc(&sk->sk_drops);
92580+ atomic_inc_unchecked(&sk->sk_drops);
92581 kfree_skb(skb);
92582 return NET_RX_DROP;
92583 }
92584@@ -746,16 +746,20 @@ static int raw_init(struct sock *sk)
92585
92586 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
92587 {
92588+ struct icmp_filter filter;
92589+
92590 if (optlen > sizeof(struct icmp_filter))
92591 optlen = sizeof(struct icmp_filter);
92592- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
92593+ if (copy_from_user(&filter, optval, optlen))
92594 return -EFAULT;
92595+ raw_sk(sk)->filter = filter;
92596 return 0;
92597 }
92598
92599 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
92600 {
92601 int len, ret = -EFAULT;
92602+ struct icmp_filter filter;
92603
92604 if (get_user(len, optlen))
92605 goto out;
92606@@ -765,8 +769,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
92607 if (len > sizeof(struct icmp_filter))
92608 len = sizeof(struct icmp_filter);
92609 ret = -EFAULT;
92610- if (put_user(len, optlen) ||
92611- copy_to_user(optval, &raw_sk(sk)->filter, len))
92612+ filter = raw_sk(sk)->filter;
92613+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
92614 goto out;
92615 ret = 0;
92616 out: return ret;
92617@@ -995,7 +999,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
92618 0, 0L, 0,
92619 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
92620 0, sock_i_ino(sp),
92621- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
92622+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
92623 }
92624
92625 static int raw_seq_show(struct seq_file *seq, void *v)
92626diff --git a/net/ipv4/route.c b/net/ipv4/route.c
92627index 2de16d9..da558c7 100644
92628--- a/net/ipv4/route.c
92629+++ b/net/ipv4/route.c
92630@@ -2615,34 +2615,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
92631 .maxlen = sizeof(int),
92632 .mode = 0200,
92633 .proc_handler = ipv4_sysctl_rtcache_flush,
92634+ .extra1 = &init_net,
92635 },
92636 { },
92637 };
92638
92639 static __net_init int sysctl_route_net_init(struct net *net)
92640 {
92641- struct ctl_table *tbl;
92642+ ctl_table_no_const *tbl = NULL;
92643
92644- tbl = ipv4_route_flush_table;
92645 if (!net_eq(net, &init_net)) {
92646- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
92647+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
92648 if (tbl == NULL)
92649 goto err_dup;
92650
92651 /* Don't export sysctls to unprivileged users */
92652 if (net->user_ns != &init_user_ns)
92653 tbl[0].procname = NULL;
92654- }
92655- tbl[0].extra1 = net;
92656+ tbl[0].extra1 = net;
92657+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
92658+ } else
92659+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
92660
92661- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
92662 if (net->ipv4.route_hdr == NULL)
92663 goto err_reg;
92664 return 0;
92665
92666 err_reg:
92667- if (tbl != ipv4_route_flush_table)
92668- kfree(tbl);
92669+ kfree(tbl);
92670 err_dup:
92671 return -ENOMEM;
92672 }
92673@@ -2665,8 +2665,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
92674
92675 static __net_init int rt_genid_init(struct net *net)
92676 {
92677- atomic_set(&net->rt_genid, 0);
92678- atomic_set(&net->fnhe_genid, 0);
92679+ atomic_set_unchecked(&net->rt_genid, 0);
92680+ atomic_set_unchecked(&net->fnhe_genid, 0);
92681 get_random_bytes(&net->ipv4.dev_addr_genid,
92682 sizeof(net->ipv4.dev_addr_genid));
92683 return 0;
92684diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
92685index 6900b8b..7832c6b 100644
92686--- a/net/ipv4/sysctl_net_ipv4.c
92687+++ b/net/ipv4/sysctl_net_ipv4.c
92688@@ -58,7 +58,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
92689 {
92690 int ret;
92691 int range[2];
92692- struct ctl_table tmp = {
92693+ ctl_table_no_const tmp = {
92694 .data = &range,
92695 .maxlen = sizeof(range),
92696 .mode = table->mode,
92697@@ -111,7 +111,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
92698 int ret;
92699 gid_t urange[2];
92700 kgid_t low, high;
92701- struct ctl_table tmp = {
92702+ ctl_table_no_const tmp = {
92703 .data = &urange,
92704 .maxlen = sizeof(urange),
92705 .mode = table->mode,
92706@@ -142,7 +142,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
92707 void __user *buffer, size_t *lenp, loff_t *ppos)
92708 {
92709 char val[TCP_CA_NAME_MAX];
92710- struct ctl_table tbl = {
92711+ ctl_table_no_const tbl = {
92712 .data = val,
92713 .maxlen = TCP_CA_NAME_MAX,
92714 };
92715@@ -161,7 +161,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
92716 void __user *buffer, size_t *lenp,
92717 loff_t *ppos)
92718 {
92719- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
92720+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
92721 int ret;
92722
92723 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
92724@@ -178,7 +178,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
92725 void __user *buffer, size_t *lenp,
92726 loff_t *ppos)
92727 {
92728- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
92729+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
92730 int ret;
92731
92732 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
92733@@ -204,15 +204,17 @@ static int ipv4_tcp_mem(struct ctl_table *ctl, int write,
92734 struct mem_cgroup *memcg;
92735 #endif
92736
92737- struct ctl_table tmp = {
92738+ ctl_table_no_const tmp = {
92739 .data = &vec,
92740 .maxlen = sizeof(vec),
92741 .mode = ctl->mode,
92742 };
92743
92744 if (!write) {
92745- ctl->data = &net->ipv4.sysctl_tcp_mem;
92746- return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
92747+ ctl_table_no_const tcp_mem = *ctl;
92748+
92749+ tcp_mem.data = &net->ipv4.sysctl_tcp_mem;
92750+ return proc_doulongvec_minmax(&tcp_mem, write, buffer, lenp, ppos);
92751 }
92752
92753 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
92754@@ -240,7 +242,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
92755 void __user *buffer, size_t *lenp,
92756 loff_t *ppos)
92757 {
92758- struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
92759+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
92760 struct tcp_fastopen_context *ctxt;
92761 int ret;
92762 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
92763@@ -483,7 +485,7 @@ static struct ctl_table ipv4_table[] = {
92764 },
92765 {
92766 .procname = "ip_local_reserved_ports",
92767- .data = NULL, /* initialized in sysctl_ipv4_init */
92768+ .data = sysctl_local_reserved_ports,
92769 .maxlen = 65536,
92770 .mode = 0644,
92771 .proc_handler = proc_do_large_bitmap,
92772@@ -857,11 +859,10 @@ static struct ctl_table ipv4_net_table[] = {
92773
92774 static __net_init int ipv4_sysctl_init_net(struct net *net)
92775 {
92776- struct ctl_table *table;
92777+ ctl_table_no_const *table = NULL;
92778
92779- table = ipv4_net_table;
92780 if (!net_eq(net, &init_net)) {
92781- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
92782+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
92783 if (table == NULL)
92784 goto err_alloc;
92785
92786@@ -896,15 +897,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
92787
92788 tcp_init_mem(net);
92789
92790- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
92791+ if (!net_eq(net, &init_net))
92792+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
92793+ else
92794+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
92795 if (net->ipv4.ipv4_hdr == NULL)
92796 goto err_reg;
92797
92798 return 0;
92799
92800 err_reg:
92801- if (!net_eq(net, &init_net))
92802- kfree(table);
92803+ kfree(table);
92804 err_alloc:
92805 return -ENOMEM;
92806 }
92807@@ -926,16 +929,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
92808 static __init int sysctl_ipv4_init(void)
92809 {
92810 struct ctl_table_header *hdr;
92811- struct ctl_table *i;
92812-
92813- for (i = ipv4_table; i->procname; i++) {
92814- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
92815- i->data = sysctl_local_reserved_ports;
92816- break;
92817- }
92818- }
92819- if (!i->procname)
92820- return -EINVAL;
92821
92822 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
92823 if (hdr == NULL)
92824diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
92825index 723951a..61cf1cc 100644
92826--- a/net/ipv4/tcp_input.c
92827+++ b/net/ipv4/tcp_input.c
92828@@ -4412,7 +4412,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
92829 * simplifies code)
92830 */
92831 static void
92832-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
92833+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
92834 struct sk_buff *head, struct sk_buff *tail,
92835 u32 start, u32 end)
92836 {
92837@@ -5498,6 +5498,7 @@ discard:
92838 tcp_paws_reject(&tp->rx_opt, 0))
92839 goto discard_and_undo;
92840
92841+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
92842 if (th->syn) {
92843 /* We see SYN without ACK. It is attempt of
92844 * simultaneous connect with crossed SYNs.
92845@@ -5548,6 +5549,7 @@ discard:
92846 goto discard;
92847 #endif
92848 }
92849+#endif
92850 /* "fifth, if neither of the SYN or RST bits is set then
92851 * drop the segment and return."
92852 */
92853@@ -5593,7 +5595,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
92854 goto discard;
92855
92856 if (th->syn) {
92857- if (th->fin)
92858+ if (th->fin || th->urg || th->psh)
92859 goto discard;
92860 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
92861 return 1;
92862diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
92863index b299da5..097db06 100644
92864--- a/net/ipv4/tcp_ipv4.c
92865+++ b/net/ipv4/tcp_ipv4.c
92866@@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
92867 EXPORT_SYMBOL(sysctl_tcp_low_latency);
92868
92869
92870+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92871+extern int grsec_enable_blackhole;
92872+#endif
92873+
92874 #ifdef CONFIG_TCP_MD5SIG
92875 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
92876 __be32 daddr, __be32 saddr, const struct tcphdr *th);
92877@@ -1830,6 +1834,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
92878 return 0;
92879
92880 reset:
92881+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92882+ if (!grsec_enable_blackhole)
92883+#endif
92884 tcp_v4_send_reset(rsk, skb);
92885 discard:
92886 kfree_skb(skb);
92887@@ -1975,12 +1982,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
92888 TCP_SKB_CB(skb)->sacked = 0;
92889
92890 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
92891- if (!sk)
92892+ if (!sk) {
92893+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92894+ ret = 1;
92895+#endif
92896 goto no_tcp_socket;
92897-
92898+ }
92899 process:
92900- if (sk->sk_state == TCP_TIME_WAIT)
92901+ if (sk->sk_state == TCP_TIME_WAIT) {
92902+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92903+ ret = 2;
92904+#endif
92905 goto do_time_wait;
92906+ }
92907
92908 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
92909 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
92910@@ -2034,6 +2048,10 @@ csum_error:
92911 bad_packet:
92912 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
92913 } else {
92914+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92915+ if (!grsec_enable_blackhole || (ret == 1 &&
92916+ (skb->dev->flags & IFF_LOOPBACK)))
92917+#endif
92918 tcp_v4_send_reset(NULL, skb);
92919 }
92920
92921diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
92922index ab1c086..2a8d76b 100644
92923--- a/net/ipv4/tcp_minisocks.c
92924+++ b/net/ipv4/tcp_minisocks.c
92925@@ -27,6 +27,10 @@
92926 #include <net/inet_common.h>
92927 #include <net/xfrm.h>
92928
92929+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92930+extern int grsec_enable_blackhole;
92931+#endif
92932+
92933 int sysctl_tcp_syncookies __read_mostly = 1;
92934 EXPORT_SYMBOL(sysctl_tcp_syncookies);
92935
92936@@ -715,7 +719,10 @@ embryonic_reset:
92937 * avoid becoming vulnerable to outside attack aiming at
92938 * resetting legit local connections.
92939 */
92940- req->rsk_ops->send_reset(sk, skb);
92941+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92942+ if (!grsec_enable_blackhole)
92943+#endif
92944+ req->rsk_ops->send_reset(sk, skb);
92945 } else if (fastopen) { /* received a valid RST pkt */
92946 reqsk_fastopen_remove(sk, req, true);
92947 tcp_reset(sk);
92948diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
92949index d4943f6..e7a74a5 100644
92950--- a/net/ipv4/tcp_probe.c
92951+++ b/net/ipv4/tcp_probe.c
92952@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
92953 if (cnt + width >= len)
92954 break;
92955
92956- if (copy_to_user(buf + cnt, tbuf, width))
92957+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
92958 return -EFAULT;
92959 cnt += width;
92960 }
92961diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
92962index 4b85e6f..22f9ac9 100644
92963--- a/net/ipv4/tcp_timer.c
92964+++ b/net/ipv4/tcp_timer.c
92965@@ -22,6 +22,10 @@
92966 #include <linux/gfp.h>
92967 #include <net/tcp.h>
92968
92969+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92970+extern int grsec_lastack_retries;
92971+#endif
92972+
92973 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
92974 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
92975 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
92976@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
92977 }
92978 }
92979
92980+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92981+ if ((sk->sk_state == TCP_LAST_ACK) &&
92982+ (grsec_lastack_retries > 0) &&
92983+ (grsec_lastack_retries < retry_until))
92984+ retry_until = grsec_lastack_retries;
92985+#endif
92986+
92987 if (retransmits_timed_out(sk, retry_until,
92988 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
92989 /* Has it gone just too far? */
92990diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
92991index 766e6ba..aff2f8d 100644
92992--- a/net/ipv4/udp.c
92993+++ b/net/ipv4/udp.c
92994@@ -87,6 +87,7 @@
92995 #include <linux/types.h>
92996 #include <linux/fcntl.h>
92997 #include <linux/module.h>
92998+#include <linux/security.h>
92999 #include <linux/socket.h>
93000 #include <linux/sockios.h>
93001 #include <linux/igmp.h>
93002@@ -112,6 +113,10 @@
93003 #include <net/busy_poll.h>
93004 #include "udp_impl.h"
93005
93006+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93007+extern int grsec_enable_blackhole;
93008+#endif
93009+
93010 struct udp_table udp_table __read_mostly;
93011 EXPORT_SYMBOL(udp_table);
93012
93013@@ -595,6 +600,9 @@ found:
93014 return s;
93015 }
93016
93017+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
93018+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
93019+
93020 /*
93021 * This routine is called by the ICMP module when it gets some
93022 * sort of error condition. If err < 0 then the socket should
93023@@ -891,9 +899,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
93024 dport = usin->sin_port;
93025 if (dport == 0)
93026 return -EINVAL;
93027+
93028+ err = gr_search_udp_sendmsg(sk, usin);
93029+ if (err)
93030+ return err;
93031 } else {
93032 if (sk->sk_state != TCP_ESTABLISHED)
93033 return -EDESTADDRREQ;
93034+
93035+ err = gr_search_udp_sendmsg(sk, NULL);
93036+ if (err)
93037+ return err;
93038+
93039 daddr = inet->inet_daddr;
93040 dport = inet->inet_dport;
93041 /* Open fast path for connected socket.
93042@@ -1137,7 +1154,7 @@ static unsigned int first_packet_length(struct sock *sk)
93043 IS_UDPLITE(sk));
93044 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
93045 IS_UDPLITE(sk));
93046- atomic_inc(&sk->sk_drops);
93047+ atomic_inc_unchecked(&sk->sk_drops);
93048 __skb_unlink(skb, rcvq);
93049 __skb_queue_tail(&list_kill, skb);
93050 }
93051@@ -1223,6 +1240,10 @@ try_again:
93052 if (!skb)
93053 goto out;
93054
93055+ err = gr_search_udp_recvmsg(sk, skb);
93056+ if (err)
93057+ goto out_free;
93058+
93059 ulen = skb->len - sizeof(struct udphdr);
93060 copied = len;
93061 if (copied > ulen)
93062@@ -1256,7 +1277,7 @@ try_again:
93063 if (unlikely(err)) {
93064 trace_kfree_skb(skb, udp_recvmsg);
93065 if (!peeked) {
93066- atomic_inc(&sk->sk_drops);
93067+ atomic_inc_unchecked(&sk->sk_drops);
93068 UDP_INC_STATS_USER(sock_net(sk),
93069 UDP_MIB_INERRORS, is_udplite);
93070 }
93071@@ -1543,7 +1564,7 @@ csum_error:
93072 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
93073 drop:
93074 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
93075- atomic_inc(&sk->sk_drops);
93076+ atomic_inc_unchecked(&sk->sk_drops);
93077 kfree_skb(skb);
93078 return -1;
93079 }
93080@@ -1562,7 +1583,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
93081 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
93082
93083 if (!skb1) {
93084- atomic_inc(&sk->sk_drops);
93085+ atomic_inc_unchecked(&sk->sk_drops);
93086 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
93087 IS_UDPLITE(sk));
93088 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
93089@@ -1734,6 +1755,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
93090 goto csum_error;
93091
93092 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
93093+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93094+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
93095+#endif
93096 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
93097
93098 /*
93099@@ -2166,7 +2190,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
93100 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
93101 0, sock_i_ino(sp),
93102 atomic_read(&sp->sk_refcnt), sp,
93103- atomic_read(&sp->sk_drops), len);
93104+ atomic_read_unchecked(&sp->sk_drops), len);
93105 }
93106
93107 int udp4_seq_show(struct seq_file *seq, void *v)
93108diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
93109index 9a459be..c7bc04c 100644
93110--- a/net/ipv4/xfrm4_policy.c
93111+++ b/net/ipv4/xfrm4_policy.c
93112@@ -181,11 +181,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
93113 fl4->flowi4_tos = iph->tos;
93114 }
93115
93116-static inline int xfrm4_garbage_collect(struct dst_ops *ops)
93117+static int xfrm4_garbage_collect(struct dst_ops *ops)
93118 {
93119 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
93120
93121- xfrm4_policy_afinfo.garbage_collect(net);
93122+ xfrm_garbage_collect_deferred(net);
93123 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
93124 }
93125
93126@@ -264,19 +264,18 @@ static struct ctl_table xfrm4_policy_table[] = {
93127
93128 static int __net_init xfrm4_net_init(struct net *net)
93129 {
93130- struct ctl_table *table;
93131+ ctl_table_no_const *table = NULL;
93132 struct ctl_table_header *hdr;
93133
93134- table = xfrm4_policy_table;
93135 if (!net_eq(net, &init_net)) {
93136- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
93137+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
93138 if (!table)
93139 goto err_alloc;
93140
93141 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
93142- }
93143-
93144- hdr = register_net_sysctl(net, "net/ipv4", table);
93145+ hdr = register_net_sysctl(net, "net/ipv4", table);
93146+ } else
93147+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
93148 if (!hdr)
93149 goto err_reg;
93150
93151@@ -284,8 +283,7 @@ static int __net_init xfrm4_net_init(struct net *net)
93152 return 0;
93153
93154 err_reg:
93155- if (!net_eq(net, &init_net))
93156- kfree(table);
93157+ kfree(table);
93158 err_alloc:
93159 return -ENOMEM;
93160 }
93161diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
93162index 0f99f7b..9375cf5 100644
93163--- a/net/ipv6/addrconf.c
93164+++ b/net/ipv6/addrconf.c
93165@@ -618,7 +618,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
93166 idx = 0;
93167 head = &net->dev_index_head[h];
93168 rcu_read_lock();
93169- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
93170+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
93171 net->dev_base_seq;
93172 hlist_for_each_entry_rcu(dev, head, index_hlist) {
93173 if (idx < s_idx)
93174@@ -2408,7 +2408,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
93175 p.iph.ihl = 5;
93176 p.iph.protocol = IPPROTO_IPV6;
93177 p.iph.ttl = 64;
93178- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
93179+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
93180
93181 if (ops->ndo_do_ioctl) {
93182 mm_segment_t oldfs = get_fs();
93183@@ -4057,7 +4057,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
93184 s_ip_idx = ip_idx = cb->args[2];
93185
93186 rcu_read_lock();
93187- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
93188+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
93189 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
93190 idx = 0;
93191 head = &net->dev_index_head[h];
93192@@ -4678,7 +4678,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
93193 dst_free(&ifp->rt->dst);
93194 break;
93195 }
93196- atomic_inc(&net->ipv6.dev_addr_genid);
93197+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
93198 }
93199
93200 static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
93201@@ -4698,7 +4698,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
93202 int *valp = ctl->data;
93203 int val = *valp;
93204 loff_t pos = *ppos;
93205- struct ctl_table lctl;
93206+ ctl_table_no_const lctl;
93207 int ret;
93208
93209 /*
93210@@ -4783,7 +4783,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
93211 int *valp = ctl->data;
93212 int val = *valp;
93213 loff_t pos = *ppos;
93214- struct ctl_table lctl;
93215+ ctl_table_no_const lctl;
93216 int ret;
93217
93218 /*
93219diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
93220index 197e6f4..16d8396 100644
93221--- a/net/ipv6/datagram.c
93222+++ b/net/ipv6/datagram.c
93223@@ -904,5 +904,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
93224 0,
93225 sock_i_ino(sp),
93226 atomic_read(&sp->sk_refcnt), sp,
93227- atomic_read(&sp->sk_drops));
93228+ atomic_read_unchecked(&sp->sk_drops));
93229 }
93230diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
93231index 7cfc8d2..c5394b6 100644
93232--- a/net/ipv6/icmp.c
93233+++ b/net/ipv6/icmp.c
93234@@ -989,7 +989,7 @@ struct ctl_table ipv6_icmp_table_template[] = {
93235
93236 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
93237 {
93238- struct ctl_table *table;
93239+ ctl_table_no_const *table;
93240
93241 table = kmemdup(ipv6_icmp_table_template,
93242 sizeof(ipv6_icmp_table_template),
93243diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
93244index 8bc717b..76fbb5d 100644
93245--- a/net/ipv6/ip6_gre.c
93246+++ b/net/ipv6/ip6_gre.c
93247@@ -74,7 +74,7 @@ struct ip6gre_net {
93248 struct net_device *fb_tunnel_dev;
93249 };
93250
93251-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
93252+static struct rtnl_link_ops ip6gre_link_ops;
93253 static int ip6gre_tunnel_init(struct net_device *dev);
93254 static void ip6gre_tunnel_setup(struct net_device *dev);
93255 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
93256@@ -1288,7 +1288,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
93257 }
93258
93259
93260-static struct inet6_protocol ip6gre_protocol __read_mostly = {
93261+static struct inet6_protocol ip6gre_protocol = {
93262 .handler = ip6gre_rcv,
93263 .err_handler = ip6gre_err,
93264 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
93265@@ -1622,7 +1622,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
93266 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
93267 };
93268
93269-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
93270+static struct rtnl_link_ops ip6gre_link_ops = {
93271 .kind = "ip6gre",
93272 .maxtype = IFLA_GRE_MAX,
93273 .policy = ip6gre_policy,
93274@@ -1635,7 +1635,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
93275 .fill_info = ip6gre_fill_info,
93276 };
93277
93278-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
93279+static struct rtnl_link_ops ip6gre_tap_ops = {
93280 .kind = "ip6gretap",
93281 .maxtype = IFLA_GRE_MAX,
93282 .policy = ip6gre_policy,
93283diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
93284index cf5d490..30946f0 100644
93285--- a/net/ipv6/ip6_tunnel.c
93286+++ b/net/ipv6/ip6_tunnel.c
93287@@ -88,7 +88,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
93288
93289 static int ip6_tnl_dev_init(struct net_device *dev);
93290 static void ip6_tnl_dev_setup(struct net_device *dev);
93291-static struct rtnl_link_ops ip6_link_ops __read_mostly;
93292+static struct rtnl_link_ops ip6_link_ops;
93293
93294 static int ip6_tnl_net_id __read_mostly;
93295 struct ip6_tnl_net {
93296@@ -1678,7 +1678,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
93297 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
93298 };
93299
93300-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
93301+static struct rtnl_link_ops ip6_link_ops = {
93302 .kind = "ip6tnl",
93303 .maxtype = IFLA_IPTUN_MAX,
93304 .policy = ip6_tnl_policy,
93305diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
93306index d1e2e8e..51c19ae 100644
93307--- a/net/ipv6/ipv6_sockglue.c
93308+++ b/net/ipv6/ipv6_sockglue.c
93309@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
93310 if (sk->sk_type != SOCK_STREAM)
93311 return -ENOPROTOOPT;
93312
93313- msg.msg_control = optval;
93314+ msg.msg_control = (void __force_kernel *)optval;
93315 msg.msg_controllen = len;
93316 msg.msg_flags = flags;
93317
93318diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
93319index 44400c2..8e11f52 100644
93320--- a/net/ipv6/netfilter/ip6_tables.c
93321+++ b/net/ipv6/netfilter/ip6_tables.c
93322@@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
93323 #endif
93324
93325 static int get_info(struct net *net, void __user *user,
93326- const int *len, int compat)
93327+ int len, int compat)
93328 {
93329 char name[XT_TABLE_MAXNAMELEN];
93330 struct xt_table *t;
93331 int ret;
93332
93333- if (*len != sizeof(struct ip6t_getinfo)) {
93334- duprintf("length %u != %zu\n", *len,
93335+ if (len != sizeof(struct ip6t_getinfo)) {
93336+ duprintf("length %u != %zu\n", len,
93337 sizeof(struct ip6t_getinfo));
93338 return -EINVAL;
93339 }
93340@@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
93341 info.size = private->size;
93342 strcpy(info.name, name);
93343
93344- if (copy_to_user(user, &info, *len) != 0)
93345+ if (copy_to_user(user, &info, len) != 0)
93346 ret = -EFAULT;
93347 else
93348 ret = 0;
93349@@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
93350
93351 switch (cmd) {
93352 case IP6T_SO_GET_INFO:
93353- ret = get_info(sock_net(sk), user, len, 1);
93354+ ret = get_info(sock_net(sk), user, *len, 1);
93355 break;
93356 case IP6T_SO_GET_ENTRIES:
93357 ret = compat_get_entries(sock_net(sk), user, len);
93358@@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
93359
93360 switch (cmd) {
93361 case IP6T_SO_GET_INFO:
93362- ret = get_info(sock_net(sk), user, len, 0);
93363+ ret = get_info(sock_net(sk), user, *len, 0);
93364 break;
93365
93366 case IP6T_SO_GET_ENTRIES:
93367diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
93368index dffdc1a..ccc6678 100644
93369--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
93370+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
93371@@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
93372
93373 static int nf_ct_frag6_sysctl_register(struct net *net)
93374 {
93375- struct ctl_table *table;
93376+ ctl_table_no_const *table = NULL;
93377 struct ctl_table_header *hdr;
93378
93379- table = nf_ct_frag6_sysctl_table;
93380 if (!net_eq(net, &init_net)) {
93381- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
93382+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
93383 GFP_KERNEL);
93384 if (table == NULL)
93385 goto err_alloc;
93386@@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
93387 table[0].data = &net->nf_frag.frags.timeout;
93388 table[1].data = &net->nf_frag.frags.low_thresh;
93389 table[2].data = &net->nf_frag.frags.high_thresh;
93390- }
93391-
93392- hdr = register_net_sysctl(net, "net/netfilter", table);
93393+ hdr = register_net_sysctl(net, "net/netfilter", table);
93394+ } else
93395+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
93396 if (hdr == NULL)
93397 goto err_reg;
93398
93399@@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
93400 return 0;
93401
93402 err_reg:
93403- if (!net_eq(net, &init_net))
93404- kfree(table);
93405+ kfree(table);
93406 err_alloc:
93407 return -ENOMEM;
93408 }
93409diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
93410index ab92a36..bb4a528 100644
93411--- a/net/ipv6/output_core.c
93412+++ b/net/ipv6/output_core.c
93413@@ -8,8 +8,8 @@
93414
93415 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
93416 {
93417- static atomic_t ipv6_fragmentation_id;
93418- int old, new;
93419+ static atomic_unchecked_t ipv6_fragmentation_id;
93420+ int id;
93421
93422 #if IS_ENABLED(CONFIG_IPV6)
93423 if (rt && !(rt->dst.flags & DST_NOPEER)) {
93424@@ -25,13 +25,10 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
93425 }
93426 }
93427 #endif
93428- do {
93429- old = atomic_read(&ipv6_fragmentation_id);
93430- new = old + 1;
93431- if (!new)
93432- new = 1;
93433- } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
93434- fhdr->identification = htonl(new);
93435+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
93436+ if (!id)
93437+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
93438+ fhdr->identification = htonl(id);
93439 }
93440 EXPORT_SYMBOL(ipv6_select_ident);
93441
93442diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
93443index 18f19df..b46ada1 100644
93444--- a/net/ipv6/ping.c
93445+++ b/net/ipv6/ping.c
93446@@ -245,6 +245,22 @@ static struct pernet_operations ping_v6_net_ops = {
93447 };
93448 #endif
93449
93450+static struct pingv6_ops real_pingv6_ops = {
93451+ .ipv6_recv_error = ipv6_recv_error,
93452+ .ip6_datagram_recv_ctl = ip6_datagram_recv_ctl,
93453+ .icmpv6_err_convert = icmpv6_err_convert,
93454+ .ipv6_icmp_error = ipv6_icmp_error,
93455+ .ipv6_chk_addr = ipv6_chk_addr,
93456+};
93457+
93458+static struct pingv6_ops dummy_pingv6_ops = {
93459+ .ipv6_recv_error = dummy_ipv6_recv_error,
93460+ .ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl,
93461+ .icmpv6_err_convert = dummy_icmpv6_err_convert,
93462+ .ipv6_icmp_error = dummy_ipv6_icmp_error,
93463+ .ipv6_chk_addr = dummy_ipv6_chk_addr,
93464+};
93465+
93466 int __init pingv6_init(void)
93467 {
93468 #ifdef CONFIG_PROC_FS
93469@@ -252,11 +268,7 @@ int __init pingv6_init(void)
93470 if (ret)
93471 return ret;
93472 #endif
93473- pingv6_ops.ipv6_recv_error = ipv6_recv_error;
93474- pingv6_ops.ip6_datagram_recv_ctl = ip6_datagram_recv_ctl;
93475- pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
93476- pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
93477- pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
93478+ pingv6_ops = &real_pingv6_ops;
93479 return inet6_register_protosw(&pingv6_protosw);
93480 }
93481
93482@@ -265,11 +277,7 @@ int __init pingv6_init(void)
93483 */
93484 void pingv6_exit(void)
93485 {
93486- pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
93487- pingv6_ops.ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl;
93488- pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
93489- pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
93490- pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
93491+ pingv6_ops = &dummy_pingv6_ops;
93492 #ifdef CONFIG_PROC_FS
93493 unregister_pernet_subsys(&ping_v6_net_ops);
93494 #endif
93495diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
93496index cdaed47..515edde9 100644
93497--- a/net/ipv6/raw.c
93498+++ b/net/ipv6/raw.c
93499@@ -108,7 +108,7 @@ found:
93500 */
93501 static int icmpv6_filter(const struct sock *sk, const struct sk_buff *skb)
93502 {
93503- struct icmp6hdr *_hdr;
93504+ struct icmp6hdr _hdr;
93505 const struct icmp6hdr *hdr;
93506
93507 hdr = skb_header_pointer(skb, skb_transport_offset(skb),
93508@@ -378,7 +378,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
93509 {
93510 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
93511 skb_checksum_complete(skb)) {
93512- atomic_inc(&sk->sk_drops);
93513+ atomic_inc_unchecked(&sk->sk_drops);
93514 kfree_skb(skb);
93515 return NET_RX_DROP;
93516 }
93517@@ -406,7 +406,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
93518 struct raw6_sock *rp = raw6_sk(sk);
93519
93520 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
93521- atomic_inc(&sk->sk_drops);
93522+ atomic_inc_unchecked(&sk->sk_drops);
93523 kfree_skb(skb);
93524 return NET_RX_DROP;
93525 }
93526@@ -430,7 +430,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
93527
93528 if (inet->hdrincl) {
93529 if (skb_checksum_complete(skb)) {
93530- atomic_inc(&sk->sk_drops);
93531+ atomic_inc_unchecked(&sk->sk_drops);
93532 kfree_skb(skb);
93533 return NET_RX_DROP;
93534 }
93535@@ -602,7 +602,7 @@ out:
93536 return err;
93537 }
93538
93539-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
93540+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
93541 struct flowi6 *fl6, struct dst_entry **dstp,
93542 unsigned int flags)
93543 {
93544@@ -915,12 +915,15 @@ do_confirm:
93545 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
93546 char __user *optval, int optlen)
93547 {
93548+ struct icmp6_filter filter;
93549+
93550 switch (optname) {
93551 case ICMPV6_FILTER:
93552 if (optlen > sizeof(struct icmp6_filter))
93553 optlen = sizeof(struct icmp6_filter);
93554- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
93555+ if (copy_from_user(&filter, optval, optlen))
93556 return -EFAULT;
93557+ raw6_sk(sk)->filter = filter;
93558 return 0;
93559 default:
93560 return -ENOPROTOOPT;
93561@@ -933,6 +936,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
93562 char __user *optval, int __user *optlen)
93563 {
93564 int len;
93565+ struct icmp6_filter filter;
93566
93567 switch (optname) {
93568 case ICMPV6_FILTER:
93569@@ -944,7 +948,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
93570 len = sizeof(struct icmp6_filter);
93571 if (put_user(len, optlen))
93572 return -EFAULT;
93573- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
93574+ filter = raw6_sk(sk)->filter;
93575+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
93576 return -EFAULT;
93577 return 0;
93578 default:
93579diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
93580index 1aeb473..bea761c 100644
93581--- a/net/ipv6/reassembly.c
93582+++ b/net/ipv6/reassembly.c
93583@@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
93584
93585 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
93586 {
93587- struct ctl_table *table;
93588+ ctl_table_no_const *table = NULL;
93589 struct ctl_table_header *hdr;
93590
93591- table = ip6_frags_ns_ctl_table;
93592 if (!net_eq(net, &init_net)) {
93593- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
93594+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
93595 if (table == NULL)
93596 goto err_alloc;
93597
93598@@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
93599 /* Don't export sysctls to unprivileged users */
93600 if (net->user_ns != &init_user_ns)
93601 table[0].procname = NULL;
93602- }
93603+ hdr = register_net_sysctl(net, "net/ipv6", table);
93604+ } else
93605+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
93606
93607- hdr = register_net_sysctl(net, "net/ipv6", table);
93608 if (hdr == NULL)
93609 goto err_reg;
93610
93611@@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
93612 return 0;
93613
93614 err_reg:
93615- if (!net_eq(net, &init_net))
93616- kfree(table);
93617+ kfree(table);
93618 err_alloc:
93619 return -ENOMEM;
93620 }
93621diff --git a/net/ipv6/route.c b/net/ipv6/route.c
93622index 1e32d5c..cbe3b46 100644
93623--- a/net/ipv6/route.c
93624+++ b/net/ipv6/route.c
93625@@ -2954,7 +2954,7 @@ struct ctl_table ipv6_route_table_template[] = {
93626
93627 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
93628 {
93629- struct ctl_table *table;
93630+ ctl_table_no_const *table;
93631
93632 table = kmemdup(ipv6_route_table_template,
93633 sizeof(ipv6_route_table_template),
93634diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
93635index a51ad07..a90bc19 100644
93636--- a/net/ipv6/sit.c
93637+++ b/net/ipv6/sit.c
93638@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
93639 static void ipip6_dev_free(struct net_device *dev);
93640 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
93641 __be32 *v4dst);
93642-static struct rtnl_link_ops sit_link_ops __read_mostly;
93643+static struct rtnl_link_ops sit_link_ops;
93644
93645 static int sit_net_id __read_mostly;
93646 struct sit_net {
93647@@ -1601,7 +1601,7 @@ static const struct nla_policy ipip6_policy[IFLA_IPTUN_MAX + 1] = {
93648 #endif
93649 };
93650
93651-static struct rtnl_link_ops sit_link_ops __read_mostly = {
93652+static struct rtnl_link_ops sit_link_ops = {
93653 .kind = "sit",
93654 .maxtype = IFLA_IPTUN_MAX,
93655 .policy = ipip6_policy,
93656diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
93657index 107b2f1..72741a9 100644
93658--- a/net/ipv6/sysctl_net_ipv6.c
93659+++ b/net/ipv6/sysctl_net_ipv6.c
93660@@ -40,7 +40,7 @@ static struct ctl_table ipv6_rotable[] = {
93661
93662 static int __net_init ipv6_sysctl_net_init(struct net *net)
93663 {
93664- struct ctl_table *ipv6_table;
93665+ ctl_table_no_const *ipv6_table;
93666 struct ctl_table *ipv6_route_table;
93667 struct ctl_table *ipv6_icmp_table;
93668 int err;
93669diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
93670index 6e1649d..75ddb4c 100644
93671--- a/net/ipv6/tcp_ipv6.c
93672+++ b/net/ipv6/tcp_ipv6.c
93673@@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
93674 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
93675 }
93676
93677+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93678+extern int grsec_enable_blackhole;
93679+#endif
93680+
93681 static void tcp_v6_hash(struct sock *sk)
93682 {
93683 if (sk->sk_state != TCP_CLOSE) {
93684@@ -1399,6 +1403,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
93685 return 0;
93686
93687 reset:
93688+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93689+ if (!grsec_enable_blackhole)
93690+#endif
93691 tcp_v6_send_reset(sk, skb);
93692 discard:
93693 if (opt_skb)
93694@@ -1427,7 +1434,7 @@ ipv6_pktoptions:
93695 if (np->rxopt.bits.rxhlim || np->rxopt.bits.rxohlim)
93696 np->mcast_hops = ipv6_hdr(opt_skb)->hop_limit;
93697 if (np->rxopt.bits.rxtclass)
93698- np->rcv_tclass = ipv6_get_dsfield(ipv6_hdr(skb));
93699+ np->rcv_tclass = ipv6_get_dsfield(ipv6_hdr(opt_skb));
93700 if (ipv6_opt_accepted(sk, opt_skb)) {
93701 skb_set_owner_r(opt_skb, sk);
93702 opt_skb = xchg(&np->pktoptions, opt_skb);
93703@@ -1481,12 +1488,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
93704 TCP_SKB_CB(skb)->sacked = 0;
93705
93706 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
93707- if (!sk)
93708+ if (!sk) {
93709+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93710+ ret = 1;
93711+#endif
93712 goto no_tcp_socket;
93713+ }
93714
93715 process:
93716- if (sk->sk_state == TCP_TIME_WAIT)
93717+ if (sk->sk_state == TCP_TIME_WAIT) {
93718+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93719+ ret = 2;
93720+#endif
93721 goto do_time_wait;
93722+ }
93723
93724 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
93725 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
93726@@ -1538,6 +1553,10 @@ csum_error:
93727 bad_packet:
93728 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
93729 } else {
93730+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93731+ if (!grsec_enable_blackhole || (ret == 1 &&
93732+ (skb->dev->flags & IFF_LOOPBACK)))
93733+#endif
93734 tcp_v6_send_reset(NULL, skb);
93735 }
93736
93737diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
93738index f405815..45a68a6 100644
93739--- a/net/ipv6/udp.c
93740+++ b/net/ipv6/udp.c
93741@@ -53,6 +53,10 @@
93742 #include <trace/events/skb.h>
93743 #include "udp_impl.h"
93744
93745+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93746+extern int grsec_enable_blackhole;
93747+#endif
93748+
93749 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
93750 {
93751 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
93752@@ -420,7 +424,7 @@ try_again:
93753 if (unlikely(err)) {
93754 trace_kfree_skb(skb, udpv6_recvmsg);
93755 if (!peeked) {
93756- atomic_inc(&sk->sk_drops);
93757+ atomic_inc_unchecked(&sk->sk_drops);
93758 if (is_udp4)
93759 UDP_INC_STATS_USER(sock_net(sk),
93760 UDP_MIB_INERRORS,
93761@@ -666,7 +670,7 @@ csum_error:
93762 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
93763 drop:
93764 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
93765- atomic_inc(&sk->sk_drops);
93766+ atomic_inc_unchecked(&sk->sk_drops);
93767 kfree_skb(skb);
93768 return -1;
93769 }
93770@@ -724,7 +728,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
93771 if (likely(skb1 == NULL))
93772 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
93773 if (!skb1) {
93774- atomic_inc(&sk->sk_drops);
93775+ atomic_inc_unchecked(&sk->sk_drops);
93776 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
93777 IS_UDPLITE(sk));
93778 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
93779@@ -864,6 +868,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
93780 goto csum_error;
93781
93782 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
93783+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93784+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
93785+#endif
93786 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
93787
93788 kfree_skb(skb);
93789diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
93790index 23ed03d..6532e67 100644
93791--- a/net/ipv6/xfrm6_policy.c
93792+++ b/net/ipv6/xfrm6_policy.c
93793@@ -207,11 +207,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
93794 }
93795 }
93796
93797-static inline int xfrm6_garbage_collect(struct dst_ops *ops)
93798+static int xfrm6_garbage_collect(struct dst_ops *ops)
93799 {
93800 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
93801
93802- xfrm6_policy_afinfo.garbage_collect(net);
93803+ xfrm_garbage_collect_deferred(net);
93804 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
93805 }
93806
93807@@ -324,19 +324,19 @@ static struct ctl_table xfrm6_policy_table[] = {
93808
93809 static int __net_init xfrm6_net_init(struct net *net)
93810 {
93811- struct ctl_table *table;
93812+ ctl_table_no_const *table = NULL;
93813 struct ctl_table_header *hdr;
93814
93815- table = xfrm6_policy_table;
93816 if (!net_eq(net, &init_net)) {
93817- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
93818+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
93819 if (!table)
93820 goto err_alloc;
93821
93822 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
93823- }
93824+ hdr = register_net_sysctl(net, "net/ipv6", table);
93825+ } else
93826+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
93827
93828- hdr = register_net_sysctl(net, "net/ipv6", table);
93829 if (!hdr)
93830 goto err_reg;
93831
93832@@ -344,8 +344,7 @@ static int __net_init xfrm6_net_init(struct net *net)
93833 return 0;
93834
93835 err_reg:
93836- if (!net_eq(net, &init_net))
93837- kfree(table);
93838+ kfree(table);
93839 err_alloc:
93840 return -ENOMEM;
93841 }
93842diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
93843index 41ac7938..75e3bb1 100644
93844--- a/net/irda/ircomm/ircomm_tty.c
93845+++ b/net/irda/ircomm/ircomm_tty.c
93846@@ -319,11 +319,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
93847 add_wait_queue(&port->open_wait, &wait);
93848
93849 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
93850- __FILE__, __LINE__, tty->driver->name, port->count);
93851+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
93852
93853 spin_lock_irqsave(&port->lock, flags);
93854 if (!tty_hung_up_p(filp))
93855- port->count--;
93856+ atomic_dec(&port->count);
93857 port->blocked_open++;
93858 spin_unlock_irqrestore(&port->lock, flags);
93859
93860@@ -358,7 +358,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
93861 }
93862
93863 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
93864- __FILE__, __LINE__, tty->driver->name, port->count);
93865+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
93866
93867 schedule();
93868 }
93869@@ -368,12 +368,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
93870
93871 spin_lock_irqsave(&port->lock, flags);
93872 if (!tty_hung_up_p(filp))
93873- port->count++;
93874+ atomic_inc(&port->count);
93875 port->blocked_open--;
93876 spin_unlock_irqrestore(&port->lock, flags);
93877
93878 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
93879- __FILE__, __LINE__, tty->driver->name, port->count);
93880+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
93881
93882 if (!retval)
93883 port->flags |= ASYNC_NORMAL_ACTIVE;
93884@@ -447,12 +447,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
93885
93886 /* ++ is not atomic, so this should be protected - Jean II */
93887 spin_lock_irqsave(&self->port.lock, flags);
93888- self->port.count++;
93889+ atomic_inc(&self->port.count);
93890 spin_unlock_irqrestore(&self->port.lock, flags);
93891 tty_port_tty_set(&self->port, tty);
93892
93893 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
93894- self->line, self->port.count);
93895+ self->line, atomic_read(&self->port.count));
93896
93897 /* Not really used by us, but lets do it anyway */
93898 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
93899@@ -989,7 +989,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
93900 tty_kref_put(port->tty);
93901 }
93902 port->tty = NULL;
93903- port->count = 0;
93904+ atomic_set(&port->count, 0);
93905 spin_unlock_irqrestore(&port->lock, flags);
93906
93907 wake_up_interruptible(&port->open_wait);
93908@@ -1346,7 +1346,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
93909 seq_putc(m, '\n');
93910
93911 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
93912- seq_printf(m, "Open count: %d\n", self->port.count);
93913+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
93914 seq_printf(m, "Max data size: %d\n", self->max_data_size);
93915 seq_printf(m, "Max header size: %d\n", self->max_header_size);
93916
93917diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
93918index 168aff5..9d43132 100644
93919--- a/net/iucv/af_iucv.c
93920+++ b/net/iucv/af_iucv.c
93921@@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
93922
93923 write_lock_bh(&iucv_sk_list.lock);
93924
93925- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
93926+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
93927 while (__iucv_get_sock_by_name(name)) {
93928 sprintf(name, "%08x",
93929- atomic_inc_return(&iucv_sk_list.autobind_name));
93930+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
93931 }
93932
93933 write_unlock_bh(&iucv_sk_list.lock);
93934diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
93935index cd5b8ec..f205e6b 100644
93936--- a/net/iucv/iucv.c
93937+++ b/net/iucv/iucv.c
93938@@ -690,7 +690,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
93939 return NOTIFY_OK;
93940 }
93941
93942-static struct notifier_block __refdata iucv_cpu_notifier = {
93943+static struct notifier_block iucv_cpu_notifier = {
93944 .notifier_call = iucv_cpu_notify,
93945 };
93946
93947diff --git a/net/key/af_key.c b/net/key/af_key.c
93948index ab8bd2c..3a3eb81 100644
93949--- a/net/key/af_key.c
93950+++ b/net/key/af_key.c
93951@@ -1098,7 +1098,8 @@ static struct xfrm_state * pfkey_msg2xfrm_state(struct net *net,
93952
93953 x->id.proto = proto;
93954 x->id.spi = sa->sadb_sa_spi;
93955- x->props.replay_window = sa->sadb_sa_replay;
93956+ x->props.replay_window = min_t(unsigned int, sa->sadb_sa_replay,
93957+ (sizeof(x->replay.bitmap) * 8));
93958 if (sa->sadb_sa_flags & SADB_SAFLAGS_NOECN)
93959 x->props.flags |= XFRM_STATE_NOECN;
93960 if (sa->sadb_sa_flags & SADB_SAFLAGS_DECAP_DSCP)
93961@@ -3048,10 +3049,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
93962 static u32 get_acqseq(void)
93963 {
93964 u32 res;
93965- static atomic_t acqseq;
93966+ static atomic_unchecked_t acqseq;
93967
93968 do {
93969- res = atomic_inc_return(&acqseq);
93970+ res = atomic_inc_return_unchecked(&acqseq);
93971 } while (!res);
93972 return res;
93973 }
93974diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c
93975index b076e83..793e6ff 100644
93976--- a/net/l2tp/l2tp_core.c
93977+++ b/net/l2tp/l2tp_core.c
93978@@ -501,6 +501,7 @@ out:
93979 static inline int l2tp_verify_udp_checksum(struct sock *sk,
93980 struct sk_buff *skb)
93981 {
93982+ struct l2tp_tunnel *tunnel = (struct l2tp_tunnel *)sk->sk_user_data;
93983 struct udphdr *uh = udp_hdr(skb);
93984 u16 ulen = ntohs(uh->len);
93985 __wsum psum;
93986diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
93987index 43dd752..63a23bc 100644
93988--- a/net/mac80211/cfg.c
93989+++ b/net/mac80211/cfg.c
93990@@ -820,7 +820,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
93991 ret = ieee80211_vif_use_channel(sdata, chandef,
93992 IEEE80211_CHANCTX_EXCLUSIVE);
93993 }
93994- } else if (local->open_count == local->monitors) {
93995+ } else if (local_read(&local->open_count) == local->monitors) {
93996 local->_oper_chandef = *chandef;
93997 ieee80211_hw_config(local, 0);
93998 }
93999@@ -2941,7 +2941,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
94000 else
94001 local->probe_req_reg--;
94002
94003- if (!local->open_count)
94004+ if (!local_read(&local->open_count))
94005 break;
94006
94007 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
94008@@ -3404,8 +3404,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
94009 if (chanctx_conf) {
94010 *chandef = chanctx_conf->def;
94011 ret = 0;
94012- } else if (local->open_count > 0 &&
94013- local->open_count == local->monitors &&
94014+ } else if (local_read(&local->open_count) > 0 &&
94015+ local_read(&local->open_count) == local->monitors &&
94016 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
94017 if (local->use_chanctx)
94018 *chandef = local->monitor_chandef;
94019diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
94020index 8412a30..6e00181 100644
94021--- a/net/mac80211/ieee80211_i.h
94022+++ b/net/mac80211/ieee80211_i.h
94023@@ -28,6 +28,7 @@
94024 #include <net/ieee80211_radiotap.h>
94025 #include <net/cfg80211.h>
94026 #include <net/mac80211.h>
94027+#include <asm/local.h>
94028 #include "key.h"
94029 #include "sta_info.h"
94030 #include "debug.h"
94031@@ -907,7 +908,7 @@ struct ieee80211_local {
94032 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
94033 spinlock_t queue_stop_reason_lock;
94034
94035- int open_count;
94036+ local_t open_count;
94037 int monitors, cooked_mntrs;
94038 /* number of interfaces with corresponding FIF_ flags */
94039 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
94040diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
94041index cc11759..11d5541 100644
94042--- a/net/mac80211/iface.c
94043+++ b/net/mac80211/iface.c
94044@@ -511,7 +511,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
94045 break;
94046 }
94047
94048- if (local->open_count == 0) {
94049+ if (local_read(&local->open_count) == 0) {
94050 res = drv_start(local);
94051 if (res)
94052 goto err_del_bss;
94053@@ -558,7 +558,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
94054 res = drv_add_interface(local, sdata);
94055 if (res)
94056 goto err_stop;
94057- } else if (local->monitors == 0 && local->open_count == 0) {
94058+ } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
94059 res = ieee80211_add_virtual_monitor(local);
94060 if (res)
94061 goto err_stop;
94062@@ -666,7 +666,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
94063 atomic_inc(&local->iff_promiscs);
94064
94065 if (coming_up)
94066- local->open_count++;
94067+ local_inc(&local->open_count);
94068
94069 if (hw_reconf_flags)
94070 ieee80211_hw_config(local, hw_reconf_flags);
94071@@ -704,7 +704,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
94072 err_del_interface:
94073 drv_remove_interface(local, sdata);
94074 err_stop:
94075- if (!local->open_count)
94076+ if (!local_read(&local->open_count))
94077 drv_stop(local);
94078 err_del_bss:
94079 sdata->bss = NULL;
94080@@ -841,7 +841,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
94081 }
94082
94083 if (going_down)
94084- local->open_count--;
94085+ local_dec(&local->open_count);
94086
94087 switch (sdata->vif.type) {
94088 case NL80211_IFTYPE_AP_VLAN:
94089@@ -908,7 +908,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
94090 }
94091 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
94092
94093- if (local->open_count == 0)
94094+ if (local_read(&local->open_count) == 0)
94095 ieee80211_clear_tx_pending(local);
94096
94097 /*
94098@@ -948,7 +948,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
94099
94100 ieee80211_recalc_ps(local, -1);
94101
94102- if (local->open_count == 0) {
94103+ if (local_read(&local->open_count) == 0) {
94104 ieee80211_stop_device(local);
94105
94106 /* no reconfiguring after stop! */
94107@@ -959,7 +959,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
94108 ieee80211_configure_filter(local);
94109 ieee80211_hw_config(local, hw_reconf_flags);
94110
94111- if (local->monitors == local->open_count)
94112+ if (local->monitors == local_read(&local->open_count))
94113 ieee80211_add_virtual_monitor(local);
94114 }
94115
94116diff --git a/net/mac80211/main.c b/net/mac80211/main.c
94117index 091088a..daf43c7 100644
94118--- a/net/mac80211/main.c
94119+++ b/net/mac80211/main.c
94120@@ -181,7 +181,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
94121 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
94122 IEEE80211_CONF_CHANGE_POWER);
94123
94124- if (changed && local->open_count) {
94125+ if (changed && local_read(&local->open_count)) {
94126 ret = drv_config(local, changed);
94127 /*
94128 * Goal:
94129diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
94130index 3401262..d5cd68d 100644
94131--- a/net/mac80211/pm.c
94132+++ b/net/mac80211/pm.c
94133@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
94134 struct ieee80211_sub_if_data *sdata;
94135 struct sta_info *sta;
94136
94137- if (!local->open_count)
94138+ if (!local_read(&local->open_count))
94139 goto suspend;
94140
94141 ieee80211_scan_cancel(local);
94142@@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
94143 cancel_work_sync(&local->dynamic_ps_enable_work);
94144 del_timer_sync(&local->dynamic_ps_timer);
94145
94146- local->wowlan = wowlan && local->open_count;
94147+ local->wowlan = wowlan && local_read(&local->open_count);
94148 if (local->wowlan) {
94149 int err = drv_suspend(local, wowlan);
94150 if (err < 0) {
94151@@ -116,7 +116,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
94152 WARN_ON(!list_empty(&local->chanctx_list));
94153
94154 /* stop hardware - this must stop RX */
94155- if (local->open_count)
94156+ if (local_read(&local->open_count))
94157 ieee80211_stop_device(local);
94158
94159 suspend:
94160diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
94161index 30d58d2..449ac8e 100644
94162--- a/net/mac80211/rate.c
94163+++ b/net/mac80211/rate.c
94164@@ -718,7 +718,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
94165
94166 ASSERT_RTNL();
94167
94168- if (local->open_count)
94169+ if (local_read(&local->open_count))
94170 return -EBUSY;
94171
94172 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
94173diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
94174index c97a065..ff61928 100644
94175--- a/net/mac80211/rc80211_pid_debugfs.c
94176+++ b/net/mac80211/rc80211_pid_debugfs.c
94177@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
94178
94179 spin_unlock_irqrestore(&events->lock, status);
94180
94181- if (copy_to_user(buf, pb, p))
94182+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
94183 return -EFAULT;
94184
94185 return p;
94186diff --git a/net/mac80211/util.c b/net/mac80211/util.c
94187index 2265445..ba14971 100644
94188--- a/net/mac80211/util.c
94189+++ b/net/mac80211/util.c
94190@@ -1452,7 +1452,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
94191 }
94192 #endif
94193 /* everything else happens only if HW was up & running */
94194- if (!local->open_count)
94195+ if (!local_read(&local->open_count))
94196 goto wake_up;
94197
94198 /*
94199@@ -1677,7 +1677,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
94200 local->in_reconfig = false;
94201 barrier();
94202
94203- if (local->monitors == local->open_count && local->monitors > 0)
94204+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
94205 ieee80211_add_virtual_monitor(local);
94206
94207 /*
94208diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
94209index 56d22ca..87c778f 100644
94210--- a/net/netfilter/Kconfig
94211+++ b/net/netfilter/Kconfig
94212@@ -958,6 +958,16 @@ config NETFILTER_XT_MATCH_ESP
94213
94214 To compile it as a module, choose M here. If unsure, say N.
94215
94216+config NETFILTER_XT_MATCH_GRADM
94217+ tristate '"gradm" match support'
94218+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
94219+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
94220+ ---help---
94221+ The gradm match allows to match on grsecurity RBAC being enabled.
94222+ It is useful when iptables rules are applied early on bootup to
94223+ prevent connections to the machine (except from a trusted host)
94224+ while the RBAC system is disabled.
94225+
94226 config NETFILTER_XT_MATCH_HASHLIMIT
94227 tristate '"hashlimit" match support'
94228 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
94229diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
94230index a1abf87..dbcb7ee 100644
94231--- a/net/netfilter/Makefile
94232+++ b/net/netfilter/Makefile
94233@@ -112,6 +112,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
94234 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
94235 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
94236 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
94237+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
94238 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
94239 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
94240 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
94241diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
94242index f771390..145b765 100644
94243--- a/net/netfilter/ipset/ip_set_core.c
94244+++ b/net/netfilter/ipset/ip_set_core.c
94245@@ -1820,7 +1820,7 @@ done:
94246 return ret;
94247 }
94248
94249-static struct nf_sockopt_ops so_set __read_mostly = {
94250+static struct nf_sockopt_ops so_set = {
94251 .pf = PF_INET,
94252 .get_optmin = SO_IP_SET,
94253 .get_optmax = SO_IP_SET + 1,
94254diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
94255index 4c8e5c0..5a79b4d 100644
94256--- a/net/netfilter/ipvs/ip_vs_conn.c
94257+++ b/net/netfilter/ipvs/ip_vs_conn.c
94258@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
94259 /* Increase the refcnt counter of the dest */
94260 ip_vs_dest_hold(dest);
94261
94262- conn_flags = atomic_read(&dest->conn_flags);
94263+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
94264 if (cp->protocol != IPPROTO_UDP)
94265 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
94266 flags = cp->flags;
94267@@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
94268
94269 cp->control = NULL;
94270 atomic_set(&cp->n_control, 0);
94271- atomic_set(&cp->in_pkts, 0);
94272+ atomic_set_unchecked(&cp->in_pkts, 0);
94273
94274 cp->packet_xmit = NULL;
94275 cp->app = NULL;
94276@@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
94277
94278 /* Don't drop the entry if its number of incoming packets is not
94279 located in [0, 8] */
94280- i = atomic_read(&cp->in_pkts);
94281+ i = atomic_read_unchecked(&cp->in_pkts);
94282 if (i > 8 || i < 0) return 0;
94283
94284 if (!todrop_rate[i]) return 0;
94285diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
94286index 4f69e83..da2d8bf 100644
94287--- a/net/netfilter/ipvs/ip_vs_core.c
94288+++ b/net/netfilter/ipvs/ip_vs_core.c
94289@@ -559,7 +559,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
94290 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
94291 /* do not touch skb anymore */
94292
94293- atomic_inc(&cp->in_pkts);
94294+ atomic_inc_unchecked(&cp->in_pkts);
94295 ip_vs_conn_put(cp);
94296 return ret;
94297 }
94298@@ -1711,7 +1711,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
94299 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
94300 pkts = sysctl_sync_threshold(ipvs);
94301 else
94302- pkts = atomic_add_return(1, &cp->in_pkts);
94303+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
94304
94305 if (ipvs->sync_state & IP_VS_STATE_MASTER)
94306 ip_vs_sync_conn(net, cp, pkts);
94307diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
94308index c8148e4..eff604f 100644
94309--- a/net/netfilter/ipvs/ip_vs_ctl.c
94310+++ b/net/netfilter/ipvs/ip_vs_ctl.c
94311@@ -789,7 +789,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
94312 */
94313 ip_vs_rs_hash(ipvs, dest);
94314 }
94315- atomic_set(&dest->conn_flags, conn_flags);
94316+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
94317
94318 /* bind the service */
94319 if (!dest->svc) {
94320@@ -1657,7 +1657,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
94321 * align with netns init in ip_vs_control_net_init()
94322 */
94323
94324-static struct ctl_table vs_vars[] = {
94325+static ctl_table_no_const vs_vars[] __read_only = {
94326 {
94327 .procname = "amemthresh",
94328 .maxlen = sizeof(int),
94329@@ -2078,7 +2078,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
94330 " %-7s %-6d %-10d %-10d\n",
94331 &dest->addr.in6,
94332 ntohs(dest->port),
94333- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
94334+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
94335 atomic_read(&dest->weight),
94336 atomic_read(&dest->activeconns),
94337 atomic_read(&dest->inactconns));
94338@@ -2089,7 +2089,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
94339 "%-7s %-6d %-10d %-10d\n",
94340 ntohl(dest->addr.ip),
94341 ntohs(dest->port),
94342- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
94343+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
94344 atomic_read(&dest->weight),
94345 atomic_read(&dest->activeconns),
94346 atomic_read(&dest->inactconns));
94347@@ -2567,7 +2567,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
94348
94349 entry.addr = dest->addr.ip;
94350 entry.port = dest->port;
94351- entry.conn_flags = atomic_read(&dest->conn_flags);
94352+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
94353 entry.weight = atomic_read(&dest->weight);
94354 entry.u_threshold = dest->u_threshold;
94355 entry.l_threshold = dest->l_threshold;
94356@@ -3110,7 +3110,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
94357 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
94358 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
94359 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
94360- (atomic_read(&dest->conn_flags) &
94361+ (atomic_read_unchecked(&dest->conn_flags) &
94362 IP_VS_CONN_F_FWD_MASK)) ||
94363 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
94364 atomic_read(&dest->weight)) ||
94365@@ -3700,7 +3700,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
94366 {
94367 int idx;
94368 struct netns_ipvs *ipvs = net_ipvs(net);
94369- struct ctl_table *tbl;
94370+ ctl_table_no_const *tbl;
94371
94372 atomic_set(&ipvs->dropentry, 0);
94373 spin_lock_init(&ipvs->dropentry_lock);
94374diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
94375index 1383b0e..a486da1 100644
94376--- a/net/netfilter/ipvs/ip_vs_lblc.c
94377+++ b/net/netfilter/ipvs/ip_vs_lblc.c
94378@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
94379 * IPVS LBLC sysctl table
94380 */
94381 #ifdef CONFIG_SYSCTL
94382-static struct ctl_table vs_vars_table[] = {
94383+static ctl_table_no_const vs_vars_table[] __read_only = {
94384 {
94385 .procname = "lblc_expiration",
94386 .data = NULL,
94387diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
94388index 3cd85b2..dfab2b8 100644
94389--- a/net/netfilter/ipvs/ip_vs_lblcr.c
94390+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
94391@@ -299,7 +299,7 @@ struct ip_vs_lblcr_table {
94392 * IPVS LBLCR sysctl table
94393 */
94394
94395-static struct ctl_table vs_vars_table[] = {
94396+static ctl_table_no_const vs_vars_table[] __read_only = {
94397 {
94398 .procname = "lblcr_expiration",
94399 .data = NULL,
94400diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
94401index f448471..995f131 100644
94402--- a/net/netfilter/ipvs/ip_vs_sync.c
94403+++ b/net/netfilter/ipvs/ip_vs_sync.c
94404@@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
94405 cp = cp->control;
94406 if (cp) {
94407 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
94408- pkts = atomic_add_return(1, &cp->in_pkts);
94409+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
94410 else
94411 pkts = sysctl_sync_threshold(ipvs);
94412 ip_vs_sync_conn(net, cp->control, pkts);
94413@@ -771,7 +771,7 @@ control:
94414 if (!cp)
94415 return;
94416 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
94417- pkts = atomic_add_return(1, &cp->in_pkts);
94418+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
94419 else
94420 pkts = sysctl_sync_threshold(ipvs);
94421 goto sloop;
94422@@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
94423
94424 if (opt)
94425 memcpy(&cp->in_seq, opt, sizeof(*opt));
94426- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
94427+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
94428 cp->state = state;
94429 cp->old_state = cp->state;
94430 /*
94431diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
94432index c47444e..b0961c6 100644
94433--- a/net/netfilter/ipvs/ip_vs_xmit.c
94434+++ b/net/netfilter/ipvs/ip_vs_xmit.c
94435@@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
94436 else
94437 rc = NF_ACCEPT;
94438 /* do not touch skb anymore */
94439- atomic_inc(&cp->in_pkts);
94440+ atomic_inc_unchecked(&cp->in_pkts);
94441 goto out;
94442 }
94443
94444@@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
94445 else
94446 rc = NF_ACCEPT;
94447 /* do not touch skb anymore */
94448- atomic_inc(&cp->in_pkts);
94449+ atomic_inc_unchecked(&cp->in_pkts);
94450 goto out;
94451 }
94452
94453diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
94454index 2d3030a..7ba1c0a 100644
94455--- a/net/netfilter/nf_conntrack_acct.c
94456+++ b/net/netfilter/nf_conntrack_acct.c
94457@@ -60,7 +60,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
94458 #ifdef CONFIG_SYSCTL
94459 static int nf_conntrack_acct_init_sysctl(struct net *net)
94460 {
94461- struct ctl_table *table;
94462+ ctl_table_no_const *table;
94463
94464 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
94465 GFP_KERNEL);
94466diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
94467index 0283bae..5febcb0 100644
94468--- a/net/netfilter/nf_conntrack_core.c
94469+++ b/net/netfilter/nf_conntrack_core.c
94470@@ -1614,6 +1614,10 @@ void nf_conntrack_init_end(void)
94471 #define DYING_NULLS_VAL ((1<<30)+1)
94472 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
94473
94474+#ifdef CONFIG_GRKERNSEC_HIDESYM
94475+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
94476+#endif
94477+
94478 int nf_conntrack_init_net(struct net *net)
94479 {
94480 int ret;
94481@@ -1628,7 +1632,11 @@ int nf_conntrack_init_net(struct net *net)
94482 goto err_stat;
94483 }
94484
94485+#ifdef CONFIG_GRKERNSEC_HIDESYM
94486+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
94487+#else
94488 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
94489+#endif
94490 if (!net->ct.slabname) {
94491 ret = -ENOMEM;
94492 goto err_slabname;
94493diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
94494index 1df1761..ce8b88a 100644
94495--- a/net/netfilter/nf_conntrack_ecache.c
94496+++ b/net/netfilter/nf_conntrack_ecache.c
94497@@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
94498 #ifdef CONFIG_SYSCTL
94499 static int nf_conntrack_event_init_sysctl(struct net *net)
94500 {
94501- struct ctl_table *table;
94502+ ctl_table_no_const *table;
94503
94504 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
94505 GFP_KERNEL);
94506diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
94507index 974a2a4..52cc6ff 100644
94508--- a/net/netfilter/nf_conntrack_helper.c
94509+++ b/net/netfilter/nf_conntrack_helper.c
94510@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
94511
94512 static int nf_conntrack_helper_init_sysctl(struct net *net)
94513 {
94514- struct ctl_table *table;
94515+ ctl_table_no_const *table;
94516
94517 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
94518 GFP_KERNEL);
94519diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
94520index 0ab9636..cea3c6a 100644
94521--- a/net/netfilter/nf_conntrack_proto.c
94522+++ b/net/netfilter/nf_conntrack_proto.c
94523@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
94524
94525 static void
94526 nf_ct_unregister_sysctl(struct ctl_table_header **header,
94527- struct ctl_table **table,
94528+ ctl_table_no_const **table,
94529 unsigned int users)
94530 {
94531 if (users > 0)
94532diff --git a/net/netfilter/nf_conntrack_proto_dccp.c b/net/netfilter/nf_conntrack_proto_dccp.c
94533index a99b6c3..cb372f9 100644
94534--- a/net/netfilter/nf_conntrack_proto_dccp.c
94535+++ b/net/netfilter/nf_conntrack_proto_dccp.c
94536@@ -428,7 +428,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
94537 const char *msg;
94538 u_int8_t state;
94539
94540- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
94541+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
94542 BUG_ON(dh == NULL);
94543
94544 state = dccp_state_table[CT_DCCP_ROLE_CLIENT][dh->dccph_type][CT_DCCP_NONE];
94545@@ -457,7 +457,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
94546 out_invalid:
94547 if (LOG_INVALID(net, IPPROTO_DCCP))
94548 nf_log_packet(net, nf_ct_l3num(ct), 0, skb, NULL, NULL,
94549- NULL, msg);
94550+ NULL, "%s", msg);
94551 return false;
94552 }
94553
94554@@ -486,7 +486,7 @@ static int dccp_packet(struct nf_conn *ct, const struct sk_buff *skb,
94555 u_int8_t type, old_state, new_state;
94556 enum ct_dccp_roles role;
94557
94558- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
94559+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
94560 BUG_ON(dh == NULL);
94561 type = dh->dccph_type;
94562
94563@@ -577,7 +577,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
94564 unsigned int cscov;
94565 const char *msg;
94566
94567- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
94568+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
94569 if (dh == NULL) {
94570 msg = "nf_ct_dccp: short packet ";
94571 goto out_invalid;
94572@@ -614,7 +614,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
94573
94574 out_invalid:
94575 if (LOG_INVALID(net, IPPROTO_DCCP))
94576- nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, msg);
94577+ nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, "%s", msg);
94578 return -NF_ACCEPT;
94579 }
94580
94581diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
94582index f641751..d3c5b51 100644
94583--- a/net/netfilter/nf_conntrack_standalone.c
94584+++ b/net/netfilter/nf_conntrack_standalone.c
94585@@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
94586
94587 static int nf_conntrack_standalone_init_sysctl(struct net *net)
94588 {
94589- struct ctl_table *table;
94590+ ctl_table_no_const *table;
94591
94592 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
94593 GFP_KERNEL);
94594diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
94595index 902fb0a..87f7fdb 100644
94596--- a/net/netfilter/nf_conntrack_timestamp.c
94597+++ b/net/netfilter/nf_conntrack_timestamp.c
94598@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
94599 #ifdef CONFIG_SYSCTL
94600 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
94601 {
94602- struct ctl_table *table;
94603+ ctl_table_no_const *table;
94604
94605 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
94606 GFP_KERNEL);
94607diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
94608index 85296d4..8becdec 100644
94609--- a/net/netfilter/nf_log.c
94610+++ b/net/netfilter/nf_log.c
94611@@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
94612
94613 #ifdef CONFIG_SYSCTL
94614 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
94615-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
94616+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
94617
94618 static int nf_log_proc_dostring(struct ctl_table *table, int write,
94619 void __user *buffer, size_t *lenp, loff_t *ppos)
94620@@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
94621 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
94622 mutex_unlock(&nf_log_mutex);
94623 } else {
94624+ ctl_table_no_const nf_log_table = *table;
94625+
94626 mutex_lock(&nf_log_mutex);
94627 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
94628 lockdep_is_held(&nf_log_mutex));
94629 if (!logger)
94630- table->data = "NONE";
94631+ nf_log_table.data = "NONE";
94632 else
94633- table->data = logger->name;
94634- r = proc_dostring(table, write, buffer, lenp, ppos);
94635+ nf_log_table.data = logger->name;
94636+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
94637 mutex_unlock(&nf_log_mutex);
94638 }
94639
94640diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
94641index f042ae5..30ea486 100644
94642--- a/net/netfilter/nf_sockopt.c
94643+++ b/net/netfilter/nf_sockopt.c
94644@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
94645 }
94646 }
94647
94648- list_add(&reg->list, &nf_sockopts);
94649+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
94650 out:
94651 mutex_unlock(&nf_sockopt_mutex);
94652 return ret;
94653@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
94654 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
94655 {
94656 mutex_lock(&nf_sockopt_mutex);
94657- list_del(&reg->list);
94658+ pax_list_del((struct list_head *)&reg->list);
94659 mutex_unlock(&nf_sockopt_mutex);
94660 }
94661 EXPORT_SYMBOL(nf_unregister_sockopt);
94662diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
94663index d92cc31..e46f350 100644
94664--- a/net/netfilter/nfnetlink_log.c
94665+++ b/net/netfilter/nfnetlink_log.c
94666@@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
94667 struct nfnl_log_net {
94668 spinlock_t instances_lock;
94669 struct hlist_head instance_table[INSTANCE_BUCKETS];
94670- atomic_t global_seq;
94671+ atomic_unchecked_t global_seq;
94672 };
94673
94674 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
94675@@ -563,7 +563,7 @@ __build_packet_message(struct nfnl_log_net *log,
94676 /* global sequence number */
94677 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
94678 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
94679- htonl(atomic_inc_return(&log->global_seq))))
94680+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
94681 goto nla_put_failure;
94682
94683 if (data_len) {
94684diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
94685new file mode 100644
94686index 0000000..c566332
94687--- /dev/null
94688+++ b/net/netfilter/xt_gradm.c
94689@@ -0,0 +1,51 @@
94690+/*
94691+ * gradm match for netfilter
94692